@font-face { font-family: "Space Grotesk"; src: url("fonts/SpaceGrotesk.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("fonts/PublicSans-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("fonts/PublicSans-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("fonts/PublicSans-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("fonts/PublicSans-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --field: #0c1f33;
  --field-line: #17324f;
  --steel: #dde3e8;
  --steel-2: #cdd5dc;
  --rule: #b4bfc9;
  --ink: #1b2631;
  --muted: #56636f;
  --probe: #f0a23a;
  --probe-ink: #6b3f00;
  --display: "Space Grotesk", "Bahnschrift", "Arial Narrow", sans-serif;
  --body: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--body); color: var(--ink); background: var(--steel-2); }

.app {
  display: grid;
  grid-template-columns: 250px 1fr 300px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "bar bar bar" "tools scope inspector";
  height: 100vh;
}

/* ------------------------------------------------ header */
.bar {
  grid-area: bar;
  display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--steel);
  border-bottom: 1px solid var(--rule);
}
.bar h1 {
  font: 600 26px/1 var(--display);
  letter-spacing: 0.01em; margin: 0;
}
.tagline { margin: 0; color: var(--muted); }
.pages { display: flex; gap: 4px; }
.pages a {
  color: var(--ink); text-decoration: none; padding: 5px 10px; border-radius: 3px; font-size: 13px;
}
.pages a:hover { background: #fff; }
.pages a[aria-current=page] { background: var(--ink); color: var(--steel); }
.legend { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,0.3); }
.dot-o { background: #d9472b; } .dot-h { background: #f2f4f6; }
.dot-ice { background: #0c1f33; border: 3px solid #8fd3ff; }
.dash { width: 18px; border-top: 2px dashed #8fd3ff; flex: none; }
.phase { font: 600 20px/1.2 var(--display); margin: 0 0 4px; }
.readout { display: flex; gap: 22px; margin: 0 0 0 auto; }
.readout div { display: flex; flex-direction: column; }
.readout dt { font-size: 11px; color: var(--muted); }
.readout dd { margin: 0; font: 600 16px/1.2 var(--display); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------ panels */
.panel { background: var(--steel); overflow-y: auto; padding: 4px 16px 20px; }
.tools { grid-area: tools; border-right: 1px solid var(--rule); }
.inspector { grid-area: inspector; border-left: 1px solid var(--rule); }
.panel section { padding: 12px 0 14px; border-bottom: 1px solid var(--rule); }
.panel section:last-child { border-bottom: 0; }
h2 { font: 600 17px/1.2 var(--display); margin: 0 0 10px; }
h3 { font: 600 15px/1.2 var(--display); margin: 14px 0 6px; }

.field { display: block; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.field output { float: right; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.field input[type=range], .field select, .field input[type=text], .field input[type=password] { display: block; width: 100%; margin-top: 4px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 2px 0 12px; font-size: 13px; }
input[type=range] { accent-color: var(--probe); }
select, input[type=text], input[type=password] {
  font: inherit; padding: 5px 7px; border: 1px solid var(--rule); border-radius: 3px; background: #f4f6f8; color: var(--ink);
}
.hint { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }

button {
  font: 500 13px/1 var(--body); color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--rule); border-radius: 3px;
  background: #eef1f4; cursor: pointer;
}
button:hover { background: #fff; }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--probe); outline-offset: 2px;
}
.wide { width: 100%; }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row > * { flex: 1; }

.toolset { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool[aria-pressed=true] { background: var(--probe); border-color: #c97f1f; color: #2a1800; font-weight: 600; }

/* ------------------------------------------------ specimen field */
.scope { grid-area: scope; position: relative; background: var(--field); overflow: hidden; min-height: 320px; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }

.ladder {
  position: absolute; right: 12px; top: 12px;
  display: flex; flex-direction: column; gap: 2px;
  border-left: 2px solid #3d5a78; padding-left: 0;
}
.ladder button {
  display: flex; justify-content: space-between; gap: 14px; text-align: left;
  background: rgba(12, 31, 51, 0.82); color: #c9d8e6; border: 0; border-radius: 0;
  padding: 6px 10px 6px 12px; font-size: 12.5px; min-width: 190px;
  position: relative;
}
.ladder button::before {
  content: ""; position: absolute; left: -6px; top: 50%; width: 10px; height: 2px; background: #3d5a78;
}
.ladder button span { color: #7f9ab4; font-variant-numeric: tabular-nums; }
.ladder button:hover, .ladder button.here { background: rgba(240, 162, 58, 0.18); color: #fff; }
.ladder button.here::before { background: var(--probe); width: 14px; left: -8px; }

.scalebar { position: absolute; left: 16px; bottom: 16px; color: #e8eef4; font: 600 13px var(--display); }
#scalebar-line { height: 6px; border: 2px solid #e8eef4; border-top: 0; width: 100px; margin-bottom: 4px; }

/* ------------------------------------------------ inspector */
.vial-wrap { display: grid; grid-template-columns: 58px 1fr; column-gap: 14px; align-items: end; }
.vial-wrap h2 { grid-column: 1 / -1; }
.vial {
  width: 46px; height: 120px; border: 2px solid #8f9ba6; border-top: 0;
  border-radius: 0 0 23px 23px; background: #f6f8fa; position: relative; overflow: hidden;
}
#vial-liquid { position: absolute; left: 0; right: 0; bottom: 0; height: 78%; background: #eaf3f9; transition: background 0.6s; }
.vial-wrap .hint { margin: 0; }

.empty p { color: var(--muted); margin: 0; }
.sample { display: flex; align-items: center; gap: 10px; font: 600 18px/1.2 var(--display); margin: 0 0 8px; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.25); flex: none; }
.data { width: 100%; border-collapse: collapse; font-size: 13px; }
.data th { text-align: left; font-weight: 400; color: var(--muted); padding: 4px 8px 4px 0; vertical-align: top; }
.data td { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; padding: 4px 0; }
.data tr + tr th, .data tr + tr td { border-top: 1px solid #cbd3da; }
.curve { margin: 12px 0 0; }
.curve canvas { width: 100%; height: auto; background: #f4f6f8; border: 1px solid var(--rule); }
.curve figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.notes { padding-left: 18px; margin: 0 0 12px; max-width: 70ch; }
.notes li { margin-bottom: 7px; }

/* ------------------------------------------------ small screens */
@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vh auto auto;
    grid-template-areas: "bar" "scope" "tools" "inspector";
    height: auto;
  }
  .readout { margin-left: 0; width: 100%; }
  .tools, .inspector { border: 0; border-top: 1px solid var(--rule); }
  .ladder button { min-width: 0; font-size: 11.5px; padding: 5px 8px; }
  .ladder button span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #vial-liquid { transition: none; }
}

/* ================================================ accounts */
.account { display: flex; align-items: center; gap: 8px; }
.account form { margin: 0; }
.account-name { font-weight: 600; }
.account button { padding: 6px 9px; font-size: 12.5px; }

.auth { background: var(--field); min-height: 100vh; }
.auth-wrap { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.auth-wrap.single { grid-template-columns: 1fr; place-items: center; }
.auth-hero { position: relative; overflow: hidden; display: grid; place-items: center; padding: 40px; }
.auth-field { position: absolute; inset: 0; width: 100%; height: 100%; }
.auth-pip { position: relative; display: flex; flex-direction: column; align-items: center; gap: 18px; max-width: 420px; }
.pip-big { width: min(300px, 60vw); height: auto; animation: bob 3.2s ease-in-out infinite; }
.bubble {
  position: relative; margin: 0; padding: 16px 18px; background: #fffdf4; color: var(--ink);
  border-radius: 18px; font-size: 17px; line-height: 1.45; box-shadow: 0 4px 0 #c9b98a;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -14px; border: 8px solid transparent;
  border-top: 8px solid #fffdf4; transform: translateX(-50%);
}
@keyframes bob { 50% { transform: translateY(-10px) rotate(-2deg); } }

.auth-card { background: var(--steel); padding: 48px clamp(24px, 6vw, 72px); overflow-y: auto; }
.auth-card h1 { font: 600 40px/1 var(--display); margin: 0 0 22px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--rule); }
.auth-tabs a { padding: 10px 14px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.auth-tabs a[aria-current=page] { color: var(--ink); border-bottom-color: var(--probe); }
.auth-card form { max-width: 420px; }
.auth-card .field input { font-size: 16px; padding: 9px 10px; }
.auth-card a { color: #8a4b00; }
.auth-error { background: #fbe3dc; border-left: 4px solid #c2410c; padding: 10px 12px; margin: 0 0 16px; color: #6e1d05; max-width: 420px; }
.hint.warn { color: #8a4b00; margin: -4px 0 12px; }
button.primary { background: var(--probe); border-color: #c97f1f; color: #2a1800; font-weight: 700; font-size: 15px; padding: 12px; margin-top: 8px; }
button.primary:hover { background: #f6b354; }

.choices { border: 0; padding: 0; margin: 6px 0 14px; }
.choices legend { font-weight: 600; margin-bottom: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 6px; margin-bottom: 6px; background: #eef1f4; cursor: pointer; }
.choice span { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); }
.choice strong { color: var(--ink); font-size: 14px; }
.choice:has(input:checked) { border-color: var(--probe); background: #fff7ea; }
.avatars { display: flex; flex-wrap: wrap; gap: 8px; }
.avatars legend { width: 100%; }
.avatar-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; border: 2px solid transparent; border-radius: 10px; cursor: pointer; font-size: 12px; min-width: 84px; }
.avatar-pick input { position: absolute; opacity: 0; }
.avatar-pick:has(input:checked) { border-color: var(--probe); background: #fff7ea; }
.avatar-pick:has(input:focus-visible) { outline: 2px solid var(--probe); outline-offset: 2px; }

/* ================================================ Pip guide (kid mode) */
.pip { position: absolute; right: 14px; bottom: 14px; display: flex; align-items: flex-end; gap: 6px; max-width: min(420px, 80%); }
.pip-face { background: none; border: 0; padding: 0; width: 104px; flex: none; }
.pip-face:hover { background: none; }
.pip-face svg { width: 100%; height: auto; display: block; }
.pip.cheer .pip-face svg { animation: hop 0.5s ease-out 3; }
@keyframes hop { 40% { transform: translateY(-14px) rotate(4deg); } }
.pip-wave { transform-origin: 108px 82px; animation: wave 2.4s ease-in-out infinite; }
@keyframes wave { 0%, 60%, 100% { transform: rotate(0); } 70% { transform: rotate(-14deg); } 85% { transform: rotate(10deg); } }
.pip-bubble { background: #fffdf4; border-radius: 16px; padding: 12px 14px; box-shadow: 0 4px 0 #c9b98a; margin-bottom: 40px; }
.pip-bubble[hidden] { display: none; }
.pip-stars { margin: 0 0 4px; color: #b07a0c; font-size: 13px; letter-spacing: 1px; }
.pip-title { margin: 0 0 4px; font: 600 16px/1.25 var(--display); }
.pip-text { margin: 0 0 8px; font-size: 14px; }
.pip .row button { flex: 0 1 auto; }

@media (max-width: 980px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { min-height: 360px; }
  .account { width: 100%; }
  .pip-face { width: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  .pip-big, .pip-wave, .pip.cheer .pip-face svg { animation: none; }
}

.privacy { max-width: 760px; }
.privacy h2 { margin-top: 22px; }
.privacy p, .privacy li { font-size: 15px; line-height: 1.55; }

/* ================================================ guests */
button.ghost { background: transparent; border: 1px dashed var(--rule); color: var(--muted); margin-top: 6px; }
button.ghost:hover { background: #fff; color: var(--ink); }
.guest-form { max-width: 420px; margin-top: 18px; }
.keep-link {
  font-size: 13px; font-weight: 600; color: #2a1800; background: var(--probe);
  padding: 6px 10px; border-radius: 3px; text-decoration: none;
}
.keep-title { font-size: 24px; margin: 0 0 8px; }
.lead-small { max-width: 420px; color: var(--muted); margin: 0 0 16px; }

/* brand mark in headers */
h1.brand { display: flex; align-items: center; gap: 10px; }
h1.brand img { border-radius: 50%; flex: none; }
.pip-photo { border-radius: 50%; box-shadow: 0 12px 40px rgba(240, 162, 58, 0.35); }
.brand-link { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
