/* Palette: surgical-drape teal (chosen in theatres because it sits opposite tissue red),
   a pale steel tray for reading surfaces, fluorescein amber for "this is active". */
@font-face { font-family: "Instrument Sans"; src: url("../fonts/instrument-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Instrument Sans"; src: url("../fonts/instrument-sans-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Instrument Sans"; src: url("../fonts/instrument-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Instrument Serif"; src: url("../fonts/instrument-serif-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Instrument Serif"; src: url("../fonts/instrument-serif-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --drape-900: #050d0f; --drape-800: #0a1a1d; --drape-600: #14353a; --drape-400: #3d7d86;
  --tray: #edf1ee; --tray-2: #dfe6e2; --ink: #0d1f20; --ink-2: #48605f;
  --amber: #f3b63f; --amber-ink: #5a3b00;
  --sans: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --rail: 304px; --info: 348px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 400 15px/1.5 var(--sans); color: var(--ink); background: var(--drape-900); overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

#app { position: fixed; inset: 0; display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); overflow: hidden; }

/* ---------- rail ---------- */
#rail { background: var(--tray); display: flex; flex-direction: column; min-height: 0; z-index: 3; }
.brand { padding: 18px 22px 8px; }
.brand h1 { font: 400 31px/1.02 var(--serif); margin: 0; letter-spacing: -0.01em; }
.brand h1 em { display: block; font-style: italic; }
.lede { margin: 10px 0 0; color: var(--ink-2); max-width: 30ch; }
#fnlist { flex: 1; overflow-y: auto; padding: 4px 10px 12px; scrollbar-width: thin; }
.fngroup { margin: 7px 0 0; }
.fngroup > span { display: block; padding: 0 12px 1px; font-size: 12px; color: var(--ink-2); }
.fn { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 5px 12px; border-radius: 6px; font-weight: 500; font-size: 15.5px; line-height: 1.25; }
.fn small { display: block; font-weight: 400; font-size: 12.5px; color: var(--ink-2); }
.fn:hover { background: var(--tray-2); }
.fn[aria-pressed="true"] { background: var(--ink); color: var(--tray); box-shadow: inset 4px 0 0 var(--amber); }
.fn[aria-pressed="true"] small { color: #a9bdb9; }
.railfoot { padding: 10px 22px 16px; border-top: 1px solid var(--tray-2); font-size: 13px; color: var(--ink-2); }
.railfoot p { margin: 0 0 4px; }
.link { border: 0; background: none; padding: 0; text-decoration: underline; text-underline-offset: 3px; color: inherit; }

/* ---------- stage ---------- */
#stage { position: relative; min-width: 0; min-height: 0; background: radial-gradient(120% 90% at 50% 38%, var(--drape-600) 0%, var(--drape-800) 55%, var(--drape-900) 100%); }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#leaders, #labels { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: hidden; }
#leaders line { stroke: rgba(237, 241, 238, .7); stroke-width: 1; }
#leaders circle { fill: var(--amber); }
.lab { position: absolute; transform: translate(0, -50%); font: italic 400 19px/1.1 var(--serif); color: var(--tray); white-space: nowrap; text-shadow: 0 1px 6px rgba(6, 22, 25, .9), 0 0 2px rgba(6, 22, 25, .9); }
.lab.right { transform: translate(-100%, -50%); }
.lab small { display: block; font: 500 12px/1.25 var(--sans); color: var(--amber); font-style: normal; }
.lab.dim { opacity: .45; }

#layers { position: absolute; top: 14px; right: 14px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: min(560px, calc(100% - 28px)); z-index: 2; }
#layers button { border: 1px solid rgba(237, 241, 238, .28); background: rgba(12, 35, 39, .55); color: var(--tray); padding: 5px 11px; border-radius: 999px; font-size: 13px; backdrop-filter: blur(6px); }
#layers button[aria-pressed="true"] { background: var(--tray); color: var(--ink); border-color: var(--tray); }
#layers button i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

#pick { position: absolute; left: 22px; bottom: 22px; color: var(--tray); max-width: 60%; z-index: 2; pointer-events: none; text-shadow: 0 1px 8px rgba(6, 22, 25, .9); }
#pickName { display: block; font: italic 400 30px/1.05 var(--serif); }
#pickMeta { display: block; font-size: 13px; color: #b9cdc9; margin-top: 3px; }

#transport { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; width: min(560px, calc(100% - 28px)); padding: 9px 12px; background: rgba(12, 35, 39, .72); border: 1px solid rgba(237, 241, 238, .18); border-radius: 12px; color: var(--tray); backdrop-filter: blur(8px); z-index: 2; }
#transport button { border: 1px solid rgba(237, 241, 238, .3); background: none; border-radius: 8px; padding: 5px 10px; font-size: 13px; min-width: 58px; }
#btnSpeed { min-width: 44px !important; }
.phasewrap { flex: 1; min-width: 0; position: relative; }
#phase { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 20px; }
#scrub { width: 100%; margin: 2px 0 0; accent-color: var(--amber); height: 16px; }
#ticks { position: absolute; left: 0; right: 0; bottom: -1px; height: 4px; pointer-events: none; }
#ticks i { position: absolute; width: 1px; height: 4px; background: rgba(237, 241, 238, .55); }
#app[data-mode="fn"] #pick { bottom: 92px; }

#hint { position: absolute; left: 22px; top: 14px; margin: 0; font-size: 13px; color: #a9c2be; max-width: 34ch; z-index: 1; }
#app[data-mode="fn"] #hint { display: none; }

#loading { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; color: var(--tray); text-align: center; z-index: 5; background: var(--drape-800); }
#loading .bar { width: 220px; height: 3px; background: rgba(237, 241, 238, .2); }
#loading .bar i { display: block; height: 100%; width: 0; background: var(--amber); transition: width .2s; }
#loading p { margin: 0; font: italic 20px var(--serif); }

/* ---------- info column ---------- */
#app[data-mode="fn"] { grid-template-columns: var(--rail) minmax(0, 1fr) var(--info); }
#info { grid-column: 3; grid-row: 1; overflow-y: auto; background: var(--tray); border-left: 1px solid var(--tray-2); padding: 18px 22px 22px; z-index: 3; scrollbar-width: thin; min-height: 0; }
#info h2 { font: 400 30px/1.05 var(--serif); margin: 8px 0 8px; }
#info h3 { font: 600 13px/1.3 var(--sans); margin: 14px 0 4px; color: var(--ink-2); }
#info p { margin: 0 0 8px; }
#infoBody p { max-width: 62ch; }
#info ul { margin: 0; padding: 0; list-style: none; }
#info li { padding: 3px 0 3px 16px; position: relative; font-size: 14px; line-height: 1.35; }
#info li::before { content: ""; position: absolute; left: 0; top: .62em; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--ink-2)); opacity: .35; transition: opacity .12s, box-shadow .12s; }
#info li.on::before { opacity: 1; box-shadow: 0 0 0 3px rgba(243, 182, 63, .45); background: var(--amber); }
#info li b { font-weight: 600; }
#info .note { font-size: 12.5px; color: var(--ink-2); border-top: 1px solid var(--tray-2); padding-top: 8px; margin-top: 12px; }
#info .link { font-size: 13px; color: var(--ink-2); }
#infoExtra:empty { display: none; }
.now { margin: 6px 0 2px; padding: 9px 12px; background: var(--ink); color: var(--tray); border-radius: 8px; font-size: 14px; line-height: 1.35; }
.now strong { font: italic 400 24px/1 var(--serif); color: var(--amber); display: block; margin-bottom: 2px; }
.keyrow { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 6px 0 2px; font-size: 13px; }
.keyrow span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--c); margin-right: 5px; }

dialog { border: 0; border-radius: 12px; padding: 22px 26px; max-width: min(640px, calc(100vw - 32px)); background: var(--tray); color: var(--ink); font-size: 14.5px; }
dialog::backdrop { background: rgba(6, 20, 22, .6); }
dialog h2 { font: 400 30px/1.05 var(--serif); margin: 0 0 10px; }
dialog p { margin: 0 0 10px; }
dialog button { border: 1px solid var(--ink); background: var(--ink); color: var(--tray); border-radius: 8px; padding: 6px 16px; }

/* ---------- phone ---------- */
@media (max-width: 860px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  #rail, #info, #stage { min-width: 0; max-width: 100vw; }
  #stage { grid-row: 1; }
  #rail { grid-row: 2; max-height: 46dvh; border-radius: 14px 14px 0 0; margin-top: -12px; }
  .brand { padding: 12px 16px 2px; }
  .brand h1 { font-size: 22px; } .brand h1 em { display: inline; }
  .lede { display: none; }
  #fnlist { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 8px 12px 10px; flex: none; scroll-snap-type: x proximity; }
  .fngroup { display: contents; } .fngroup > span { display: none; }
  .fn { width: auto; flex: none; white-space: nowrap; background: var(--tray-2); border-radius: 999px; padding: 7px 13px; font-size: 14.5px; scroll-snap-align: start; }
  .fn small { display: none; }
  .fn[aria-pressed="true"] { box-shadow: none; }
  .railfoot { padding: 6px 16px 10px; display: flex; gap: 14px; justify-content: space-between; font-size: 12px; }
  #info { grid-column: 1; grid-row: 3; max-height: 34dvh; padding: 4px 16px 14px; border-left: 0; border-top: 1px solid var(--tray-2); }
  #app[data-mode="fn"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto auto; }
  #app[data-mode="fn"] .brand, #app[data-mode="fn"] .railfoot { display: none; }
  #app[data-mode="fn"] #rail { margin-top: 0; border-radius: 0; }
  #info h2 { font-size: 24px; margin-top: 4px; }
  #layers { top: 8px; right: 8px; gap: 4px; flex-wrap: nowrap; overflow-x: auto; max-width: calc(100% - 16px); justify-content: flex-start; scrollbar-width: none; }
  #layers button { padding: 4px 9px; font-size: 12px; flex: none; }
  #hint { top: 44px; left: 12px; font-size: 12px; }
  #transport { bottom: 8px; padding: 6px 8px; gap: 8px; }
  #pick { left: 12px; bottom: 12px; max-width: 90%; } #pickName { font-size: 22px; }
  #app[data-mode="fn"] #pick { bottom: 70px; }
  .lab { font-size: 15px; } .lab small { font-size: 10.5px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- instrument strip, pills, sliders ---------- */
#instr { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 1px; background: rgba(4, 12, 14, .82); border-bottom: 1px solid rgba(237, 241, 238, .14); z-index: 2; overflow-x: auto; scrollbar-width: none; backdrop-filter: blur(8px); }
.tile { flex: 1 1 0; min-width: 132px; padding: 8px 14px 7px; color: var(--tray); border-right: 1px solid rgba(237, 241, 238, .1); position: relative; }
.tile b { display: block; font: 500 11.5px/1.2 var(--sans); color: #9db6b2; white-space: nowrap; }
.tile .v { font: 400 27px/1.05 var(--serif); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile .v small { font: 500 12px var(--sans); color: #9db6b2; margin-left: 3px; }
.tile .v.txt { font-size: 19px; line-height: 1.45; }
.tile svg { display: block; width: 100%; height: 20px; margin-top: 2px; overflow: visible; }
.tile svg path { fill: none; stroke: var(--amber); stroke-width: 1.4; vector-effect: non-scaling-stroke; }
.tile svg line { stroke: var(--tray); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tile .bar { height: 4px; background: rgba(237, 241, 238, .16); margin-top: 7px; border-radius: 2px; }
.tile .bar i { display: block; height: 100%; background: var(--amber); border-radius: 2px; }
.tile em { display: block; font: 400 11px/1.25 var(--sans); color: #86a09c; margin-top: 3px; font-style: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#app[data-mode="fn"] #layers { top: 96px; }
.lab .pill { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font: 600 11.5px/1.5 var(--sans); font-variant-numeric: tabular-nums; background: rgba(8, 20, 22, .8); border: 1px solid currentColor; vertical-align: 3px; text-shadow: none; }
.lab .pill.short { color: #ffb45e; } .lab .pill.long { color: #6fd3f2; }
#zoomwrap span { text-shadow: 0 1px 4px #000; }
#zoomwrap { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); z-index: 2; color: #9db6b2; font-size: 11.5px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
#zoomwrap input { writing-mode: vertical-lr; direction: rtl; height: 170px; width: 18px; accent-color: var(--amber); }
#app[data-mode="fn"] #scale { bottom: 92px; }
#scale { position: absolute; right: 18px; bottom: 26px; z-index: 2; color: var(--tray); font-size: 11.5px; text-align: center; pointer-events: none; }
#scale i { display: block; height: 5px; border: 1px solid var(--tray); border-top: 0; margin-bottom: 3px; min-width: 8px; }
#transport .amt { display: flex; flex-direction: column; font-size: 11px; color: #9db6b2; gap: 1px; } #transport .amt input { width: 84px; accent-color: var(--amber); height: 14px; margin: 0; }
#transport { width: min(760px, calc(100% - 150px)); }
#btnTour[aria-pressed="true"] { background: var(--tray); color: var(--ink); }
#gfx { }
@media (max-width: 860px) {
  .tile { min-width: 112px; padding: 5px 9px; } .tile .v { font-size: 20px; } .tile .v.txt { font-size: 15px; } .tile em { display: none; }
  #app[data-mode="fn"] #layers { top: 66px; }
  #zoomwrap, #transport .amt, #btnTour { display: none; }
  #transport { width: calc(100% - 16px); } #scale { bottom: 62px; right: 10px; }
}

#layersToggle { display: none; }
#app[data-mode="fn"] #layersToggle { display: inline-block; }
#app[data-mode="fn"] #layers:not(.open) button[data-layer] { display: none; }

/* bare stage for plate renders */
body.bare #app { grid-template-columns: minmax(0, 1fr) !important; }
body.bare #rail, body.bare #info, body.bare #instr, body.bare #layers, body.bare #transport, body.bare #labels, body.bare #leaders, body.bare #pick, body.bare #hint, body.bare #scale, body.bare #zoomwrap { display: none !important; }
body.bare #stage { background: radial-gradient(120% 90% at 50% 40%, #0d1618 0%, #030607 100%); }
body.maskmode #stage { background: #000; }

/* ---------- specimen view ---------- */
#spec { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
#app[data-view="specimen"] #gl { z-index: 1; pointer-events: none; }
#specpills { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
#specpills .spill { transform: translate(8px, -50%); font-size: 18px; }
.specnote { z-index: 2; position: absolute; left: 50%; bottom: 89px; transform: translateX(-50%); width: min(760px, calc(100% - 150px)); margin: 0; font-size: 11.5px; line-height: 1.35; color: #9db6b2; text-align: center; text-wrap: pretty; pointer-events: none; }
#btnView { position: absolute; left: 14px; top: 100px; z-index: 3; border: 1px solid var(--amber); background: rgba(8, 20, 22, .8); color: var(--amber); border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600; }
#btnView[aria-pressed="true"] { background: var(--amber); color: var(--amber-ink); }
#app[data-view="specimen"] #zoomwrap, #app[data-view="specimen"] #btnTour, #app[data-view="specimen"] #layers, #app[data-view="specimen"] #scale, #app[data-view="specimen"] #pick { display: none !important; }
@media (max-width: 860px) { #btnView { top: 68px; left: 8px; padding: 4px 10px; font-size: 12px; } .specnote { left: 8px; right: 8px; bottom: 71px; width: auto; transform: none; font-size: 10.5px; line-height: 1.3; } #app[data-view="specimen"] #info { max-height: 24dvh; } }
/* read-out strip on narrow screens: every tile is readable; if they still do not fit the strip scrolls sideways, snaps to tiles and shows an amber edge while more lies to the right */
@media (max-width: 860px) {
  #instr { scroll-snap-type: x proximity; overscroll-behavior-x: contain; background: linear-gradient(to left, #040c0e 55%, rgba(4, 12, 14, 0)) right / 44px 100% no-repeat local, linear-gradient(to left, rgba(245, 184, 65, .6), rgba(245, 184, 65, 0)) right / 20px 100% no-repeat scroll, rgba(4, 12, 14, .82); }
  .tile { scroll-snap-align: start; overflow: hidden; } .tile b { overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 600px) {
  /* the strip keeps its 68px height here (the view button, the layer pills and the module insets sit just under it): a three-line label takes the room from its plot */
  #instr { max-height: 68px; overflow-y: hidden; }
  .tile { flex: 1 0 0; min-width: min-content; padding: 4px 5px 3px 6px; display: flex; flex-direction: column; }
  .tile b { flex: none; min-width: 52px; white-space: normal; text-wrap: balance; font-size: 10px; line-height: 1.1; min-height: 2.2em; max-height: 3.3em; letter-spacing: -.01em; }
  .tile .v { flex: none; font-size: 18px; line-height: 1; } .tile .v small { font-size: 10.5px; margin-left: 2px; }
  .tile .v.txt { font-size: 12px; line-height: 1.05; white-space: normal; min-width: 64px; margin-top: 1px; min-height: 2.1em; max-height: 3.15em; overflow: hidden; }
  .tile svg { flex: 1 1 16px; height: auto; max-height: 16px; min-height: 5px; } .tile .bar { flex: none; margin-top: 4px; }
}
}
body.bare #btnView { display: none !important; }

/* ---------- Phonation specimen view: the scope renderer in a frame (js/scopeview.js) ---------- */
#scopeview { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; z-index: 0; background: #000; }
#scopeview[hidden] { display: none; }
#stage.scope #gl, #stage.scope #labels, #stage.scope #leaders { visibility: hidden; }
