/* Empira — 3D Laboratory prototype (S4)
   Follows HOME_DESIGN_RULES.md (locked) + EMPIRA_DESIGN_SYSTEM.md. Prototype only, not production code. */

:root {
  --blue-500: #3B4CFF;  --blue-600: #2F3DE0;  --blue-700: #2632C2;
  --blue-100: #DDE1FF;  --blue-50:  #EEF0FF;
  --amber-500: #FFB21E;
  --ink-900: #0B1026;  --ink-700: #3A4166;  --ink-500: #5A6285;
  --line: #D9DCE8;  --mist: #EEF0F5;  --paper: #F6F7FB;  --white: #FFFFFF;

  --font: "Sora", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-s: 8px; --r-m: 12px; --r-l: 20px; --r-full: 999px;
  --shadow-float: 0 1px 2px rgba(11,16,38,.06), 0 8px 24px rgba(11,16,38,.08);
  --ease: cubic-bezier(.2,.8,.2,1); --t-fast: 150ms;

  --bar-h: 56px;
  --pad: var(--s4);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper); color: var(--ink-900);
  font-family: var(--font); font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; font: inherit; }
ol { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }

.icon {
  width: 24px; height: 24px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Top: back + names ---------- */
.labbar {
  position: sticky; top: 0; z-index: 10;
  height: var(--bar-h);
  display: flex; align-items: center; gap: var(--s2);
  padding: 0 var(--pad) 0 calc(var(--pad) - 10px);
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px;
  border-radius: var(--r-m); color: var(--ink-900);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.labbar__text { min-width: 0; display: flex; flex-direction: column; }
.labbar__title {
  font-size: 17px; line-height: 1.25; font-weight: 700; letter-spacing: -0.015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.labbar__meta {
  font-size: 13px; line-height: 1.3; font-weight: 500; color: var(--ink-500);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.labbar__fs { margin-left: auto; display: none; }

/* ---------- Stage: the experiment ---------- */
.lab { display: flex; flex-direction: column; }
.stage {
  position: relative;
  height: clamp(260px, 44vh, 380px);
  overflow: hidden;
  background: var(--paper);
  touch-action: none;
}
.stage__canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.readouts {
  position: absolute; top: var(--s3); left: var(--s3); right: var(--s3);
  display: flex; flex-wrap: wrap; gap: var(--s2);
  pointer-events: none;
}
.pill {
  display: inline-flex; align-items: baseline; gap: 6px;
  height: 34px; padding: 0 var(--s3);
  align-items: center;
  background: var(--white);
  border-radius: var(--r-s);
  box-shadow: var(--shadow-float);
  font-size: 15px; font-weight: 600; line-height: 1; color: var(--ink-900);
  font-variant-numeric: tabular-nums;
}
.pill__k { font-weight: 500; color: var(--ink-500); }
.pill--key { color: var(--blue-500); box-shadow: var(--shadow-float), inset 0 0 0 1.5px var(--blue-500); }

.stage__hint {
  position: absolute; left: var(--s3); bottom: var(--s3);
  font-size: 13px; font-weight: 500; color: var(--ink-500);
  pointer-events: none;
}
.stage__reset {
  position: absolute; right: var(--s3); bottom: var(--s3);
  background: var(--white); box-shadow: var(--shadow-float);
}
.stage__reset .icon { width: 20px; height: 20px; }
.stage__loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s3);
  font-size: 15px; font-weight: 500; color: var(--ink-500);
  background: var(--paper);
}
.stage__loading[hidden] { display: none; }
.spinner {
  width: 40px; height: 40px; border-radius: var(--r-full);
  border: 3px solid var(--blue-100); border-top-color: var(--blue-500);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.stage__fallback {
  position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s5);
  text-align: center; font-size: 16px; font-weight: 500; color: var(--ink-700);
}

/* ---------- Panel: only what the experiment needs ---------- */
.panel {
  display: flex; flex-direction: column;
  padding: 0 var(--pad) calc(var(--s5) + env(safe-area-inset-bottom));
  background: var(--white);
  border-top: 1px solid var(--line);
}
.block { padding: 20px 0; border-top: 1px solid var(--mist); }
/* mobile: controls come first, right under the scene (the visually first block has no divider) */
.panel .block--controls { order: -1; border-top: 0; }

.block__title { font-size: 17px; line-height: 1.3; font-weight: 700; letter-spacing: -0.01em; margin-bottom: var(--s3); }
.label { font-size: 13px; line-height: 1.3; font-weight: 600; color: var(--ink-500); }
.question { margin-top: var(--s1); font-size: 18px; line-height: 1.4; font-weight: 600; letter-spacing: -0.01em; }

/* Controls */
.field + .field { margin-top: var(--s3); }
.field__row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); }
.field label { font-size: 15px; font-weight: 500; color: var(--ink-700); }
.field output { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

.field__label { font-size: 15px; font-weight: 500; color: var(--ink-700); }

/* Choice control (e.g. "Voltmetr ulangan: R₁ / R₂ / Umumiy") — same selected state as tiles and subject pills */
.choice { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s2) 0 var(--s1); }
.choice__opt {
  min-height: 40px; padding: 0 14px;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-m);
  font-size: 14px; font-weight: 600; color: var(--ink-700); line-height: 1.2;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.choice__opt[aria-checked="true"] { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-500); box-shadow: inset 0 0 0 1px var(--blue-500); }
.choice__opt:disabled { cursor: default; opacity: .55; }
@media (hover: hover) { .choice__opt:not([aria-checked="true"]):not(:disabled):hover { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-500); } }

.range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 44px; margin: 0;
  background: transparent; cursor: pointer;
  --fill: 0%;
}
.range::-webkit-slider-runnable-track { height: 6px; border-radius: var(--r-full); background: linear-gradient(var(--blue-500), var(--blue-500)) 0 / var(--fill) 100% no-repeat, var(--line); }
.range::-moz-range-track { height: 6px; border-radius: var(--r-full); background: var(--line); }
.range::-moz-range-progress { height: 6px; border-radius: var(--r-full); background: var(--blue-500); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; margin-top: -9px; border-radius: var(--r-full);
  background: var(--white); border: 1.5px solid var(--blue-500); box-shadow: var(--shadow-float);
}
.range::-moz-range-thumb { width: 24px; height: 24px; border-radius: var(--r-full); background: var(--white); border: 1.5px solid var(--blue-500); box-shadow: var(--shadow-float); }
.range:disabled { cursor: default; opacity: .55; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 48px; padding: 0 20px;
  border-radius: var(--r-m);
  font-size: 16px; font-weight: 600; line-height: 1; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn--large { height: 56px; padding: 0 var(--s5); }
.btn--primary { background: var(--blue-500); color: var(--white); }
.btn--primary:disabled { background: var(--mist); color: var(--ink-500); cursor: default; }
.block--controls .btn { margin-top: var(--s4); width: 100%; }

/* Steps */
.step { display: flex; align-items: flex-start; gap: var(--s3); padding: 6px 0; }
.step__n {
  flex: none; display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: var(--r-full);
  background: var(--mist); color: var(--ink-500);
  font-size: 13px; font-weight: 600; line-height: 1;
}
.step__text { padding-top: 3px; font-size: 15px; line-height: 1.4; font-weight: 500; color: var(--ink-700); }
.step.is-current .step__n { background: var(--blue-50); color: var(--blue-500); box-shadow: inset 0 0 0 1.5px var(--blue-500); }
.step.is-current .step__text { color: var(--ink-900); font-weight: 600; }
.step.is-done .step__n {
  background: var(--mist) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233A4166' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.step.is-done .step__text { color: var(--ink-500); }

/* Measurements */
.runs__empty { font-size: 15px; color: var(--ink-500); }
.runs { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.runs th { text-align: left; font-size: 13px; font-weight: 600; color: var(--ink-500); padding: 0 0 6px; }
.runs td { padding: 8px 0; border-top: 1px solid var(--mist); font-size: 15px; font-weight: 500; color: var(--ink-700); }
.runs td:last-child { font-weight: 600; color: var(--ink-900); }

/* Next topic: quiet tile, same pattern as the Topic page pager */
.next-link {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line); border-radius: var(--r-m);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.next-link__label { display: inline-flex; align-items: center; gap: var(--s1); font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--ink-500); }
.next-link__label .icon { width: 16px; height: 16px; }
.next-link__title { font-size: 16px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; transition: color var(--t-fast) var(--ease); }
.next-link__meta { font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--ink-500); }

/* ---------- Interaction states ---------- */
@media (hover: hover) {
  .icon-btn:hover { background: var(--blue-50); color: var(--blue-500); }
  .stage__reset:hover { background: var(--blue-50); }
  .btn--primary:not(:disabled):hover { background: var(--blue-600); }
  .next-link:hover { background: var(--blue-50); border-color: var(--blue-500); }
  .next-link:hover .next-link__title { color: var(--blue-500); }
}
.btn--primary:not(:disabled):active { background: var(--blue-700); }
.icon-btn:active { background: var(--blue-50); }
.next-link:active { background: var(--blue-50); border-color: var(--blue-600); }

/* ---------- Tablet ≥ 640: scene on top, panel in two columns ---------- */
@media (min-width: 640px) {
  :root { --pad: var(--s5); }
  .labbar__title { font-size: 18px; }
  .stage { height: clamp(320px, 52vh, 560px); }
  .readouts { top: var(--s4); left: var(--s4); }
  .stage__hint { left: var(--s4); bottom: var(--s4); }
  .stage__reset { right: var(--s4); bottom: var(--s4); }

  .panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "controls question" "controls steps" "controls runs" "controls next";
    column-gap: var(--s6);
    align-content: start;
  }
  .block--controls { grid-area: controls; }
  .panel .block--question { grid-area: question; border-top: 0; }
  .block--steps { grid-area: steps; }
  .block--runs { grid-area: runs; }
  .block--next { grid-area: next; }
}

/* ---------- Desktop ≥ 1024: scene fills the screen, narrow panel on the right ---------- */
@media (min-width: 1024px) {
  :root { --bar-h: 64px; }
  .labbar__title { font-size: 20px; }
  .labbar__meta { font-size: 14px; }
  .labbar__fs { display: grid; }

  .lab {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    height: calc(100vh - var(--bar-h));
    height: calc(100dvh - var(--bar-h));
  }
  .stage { height: auto; }
  .readouts { top: var(--s5); left: var(--s5); }
  .pill { height: 40px; font-size: 17px; padding: 0 14px; }
  .stage__hint { left: var(--s5); bottom: var(--s5); }
  .stage__reset { right: var(--s5); bottom: var(--s5); }

  .panel {
    display: flex; flex-direction: column;
    padding: 0 var(--s5) var(--s5);
    border-top: 0; border-left: 1px solid var(--line);
    overflow-y: auto;
  }
  /* desktop reading order: question → controls → steps → measurements */
  .panel .block--question { order: -2; border-top: 0; }
  .panel .block--controls { order: -1; border-top: 1px solid var(--mist); }
}

@media (min-width: 1440px) {
  .lab { grid-template-columns: minmax(0, 1fr) 400px; }
}

/* ---------- Short desktop screens (≤ 900 px tall: 1280×720 / 1280×800 / 1440×900 laptops, projectors) ----------
   QA fix: keep the measurements and "Keyingi mavzu" visible without scrolling the panel.
   Same components, tighter vertical rhythm; completed steps step aside (the measurements show the progress). */
@media (min-width: 1024px) and (max-height: 900px) {
  .block { padding: 12px 0; }
  .block__title { margin-bottom: var(--s2); }
  .question { font-size: 17px; }
  .field + .field { margin-top: 0; }
  .field__label { font-size: 15px; font-weight: 500; color: var(--ink-700); }

/* Choice control (e.g. "Voltmetr ulangan: R₁ / R₂ / Umumiy") — same selected state as tiles and subject pills */
.choice { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s2) 0 var(--s1); }
.choice__opt {
  min-height: 40px; padding: 0 14px;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-m);
  font-size: 14px; font-weight: 600; color: var(--ink-700); line-height: 1.2;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.choice__opt[aria-checked="true"] { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-500); box-shadow: inset 0 0 0 1px var(--blue-500); }
.choice__opt:disabled { cursor: default; opacity: .55; }
@media (hover: hover) { .choice__opt:not([aria-checked="true"]):not(:disabled):hover { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-500); } }

.range { height: 36px; }
  .block--controls .btn { margin-top: var(--s3); height: 48px; }
  .step { padding: 3px 0; }
  .step.is-done { display: none; }
  .panel .block--steps:not(:has(.step:not(.is-done))) { display: none; }
  .runs td { padding: 6px 0; }
  .next-link { padding: 10px var(--s4); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .spinner { animation-duration: 3s; }
}


/* =====================================================================
   Live feedback in the ready lab (same look as Build Mode; components from build/build.css)
   ===================================================================== */
.panel .block--feedback { order: -1; padding-top: 0; border-top: 0; }
.pill.is-changed { animation: fb-pop 420ms var(--ease); box-shadow: var(--shadow-float), inset 0 0 0 2px var(--amber-500); }
.runs tr.is-new td { animation: row-glow 1600ms ease-out; }
@keyframes row-glow { 0% { background: rgba(255, 178, 30, .45); } 100% { background: transparent; } }
.step.is-just-done .step__n { animation: fb-pop 520ms cubic-bezier(.2, 1.6, .4, 1); }
@media (min-width: 640px) and (max-width: 1023px) {
  .panel { grid-template-areas: "controls question" "feedback steps" "feedback runs" "feedback next"; }
  .panel .block--feedback { grid-area: feedback; }
}
@media (prefers-reduced-motion: reduce) { .pill.is-changed, .runs tr.is-new td, .step.is-just-done .step__n { animation: none !important; } }
