/* ══════════════════════════════════════════════════════════════════════
   phosphenes.css

   Layout is a single column of fixed-height chrome with one flexible row
   (the data area) in the middle. Nothing scrolls except the transcript
   panel and the long-form overlays — the visualisation is a fixed viewport
   into a scrolling dataset, and a page that also scrolled would fight it.

   Colour values here are duplicated in js/config.js COLORS, because the
   canvas renderer cannot read CSS custom properties cheaply per frame.
   If you change one, change both.
   ══════════════════════════════════════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg:          #0b0b12;
    --bg-panel:    rgba(11, 11, 18, 0.92);
    --bg-raised:   #14141f;
    --text:        #e6e6f0;
    --dim:         #78788c;
    --dimmer:      #4a4a5a;
    --amber:       #ffc864;
    --soft-amber:  #c8a050;
    --user:        #78b4ff;
    --assistant:   #ffc864;
    --system:      #646478;
    --rule:        rgba(255, 200, 100, 0.14);
    --rule-cool:   rgba(120, 180, 255, 0.12);

    --mono: 'Menlo', 'SF Mono', 'Consolas', 'Monaco', ui-monospace, monospace;
}

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Crosshair only over the data area — a crosshair over buttons reads as
   "this is not clickable", which is the opposite of true. */
#canvas-wrapper { cursor: crosshair; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: var(--amber); text-decoration: none; border-bottom: 1px solid rgba(255,200,100,0.3); }
a:hover { border-bottom-color: var(--amber); }

/* ── Shared: focus visibility ─────────────────────────────────────────
   The app is keyboard-driven, so focus must be visible. Default outlines
   are suppressed by the reset above; put one back deliberately. */
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ══════════════════════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════════════════════ */

#app { display: flex; flex-direction: column; height: 100vh; width: 100vw; }

#header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; padding: 0 14px;
    height: 38px; min-height: 38px;
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
    z-index: 10;
}
#header-left  { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
#header-right { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); }

#header h1 {
    font-size: 13px; font-weight: 700; color: var(--amber);
    letter-spacing: 1.5px; white-space: nowrap;
}
#session-name {
    font-size: 11.5px; color: var(--dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#mode-display { color: var(--amber); min-width: 104px; font-size: 11px; }
#position-display { min-width: 92px; text-align: right; font-variant-numeric: tabular-nums; }

.hbtn {
    padding: 3px 9px; border-radius: 4px; font-size: 11px; color: var(--dim);
    border: 1px solid transparent; white-space: nowrap;
}
.hbtn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.hbtn.accent { color: var(--amber); border-color: var(--rule); }
.hbtn.accent:hover { background: rgba(255,200,100,0.1); }

/* ── Role bar: who is speaking, across the visible window ───────────── */
#role-bar { height: 13px; min-height: 13px; position: relative; background: transparent; }

/* ── Middle row: axis + canvas + transcript ─────────────────────────── */
#main-area { display: flex; flex: 1; min-height: 0; overflow: hidden; }

#plot-area {
    flex: 1; min-width: 0;
    display: grid;
    /* layer axis | canvas ; canvas row | token ruler */
    grid-template-columns: 34px 1fr;
    grid-template-rows: 1fr 18px;
}
#layer-axis  { grid-column: 1; grid-row: 1; position: relative; overflow: hidden; }
#canvas-wrapper { grid-column: 2; grid-row: 1; position: relative; overflow: hidden; }
#token-ruler { grid-column: 2; grid-row: 2; position: relative; overflow: hidden; }
#axis-corner { grid-column: 1; grid-row: 2; }

canvas#viz { display: block; width: 100%; height: 100%; }

.axis-tick {
    position: absolute; font-size: 9.5px; color: var(--dim);
    font-variant-numeric: tabular-nums; pointer-events: none;
    white-space: nowrap;
}
#layer-axis .axis-tick  { right: 6px; transform: translateY(-50%); }
#token-ruler .axis-tick { top: 3px; transform: translateX(-50%); }
.axis-label {
    position: absolute; font-size: 9px; color: var(--dimmer);
    letter-spacing: 0.5px; text-transform: uppercase; pointer-events: none;
}

/* ── Transcript panel ──────────────────────────────────────────────── */
#text-panel {
    width: 300px; min-width: 300px;
    background: var(--bg-panel);
    border-left: 1px solid var(--rule-cool);
    overflow-y: auto; overflow-wrap: break-word;
    padding: 10px 12px 40vh 12px;   /* deep bottom pad so the last token can centre */
    font-size: 12.5px; line-height: 1.55;
    scrollbar-width: thin; scrollbar-color: rgba(255,200,100,0.2) transparent;
}
#text-panel.hidden { display: none; width: 0; min-width: 0; }
#text-panel::-webkit-scrollbar { width: 4px; }
#text-panel::-webkit-scrollbar-thumb { background: rgba(255,200,100,0.2); border-radius: 2px; }

.token-span.current {
    color: #fff !important; background: rgba(255,200,100,0.18);
    border-radius: 2px; box-shadow: 0 0 0 1px rgba(255,200,100,0.4);
}
.token-span.user      { color: var(--user); }
.token-span.assistant { color: var(--assistant); }
.token-span.system    { color: var(--system); }
.token-span.default   { color: #b4b4c8; }
/* Chat special tokens: present, but should not shout. */
.token-span.special   { color: var(--dimmer); font-size: 11px; }

/* ── Token strip (shown when paused) ───────────────────────────────── */
#token-strip {
    height: 28px; min-height: 28px;
    background: var(--bg-panel); border-top: 1px solid var(--rule);
    display: flex; align-items: center; padding: 0 14px;
    font-size: 11.5px; overflow: hidden; white-space: pre;
}
#token-strip.hidden { display: none; }
#token-strip .cur { color: var(--amber); font-weight: 700; background: rgba(255,200,100,0.15); }

/* ══════════════════════════════════════════════════════════════════════
   CONTROL BAR
   The app was keyboard-only. Every shortcut now has a visible control,
   because a viewer who does not already know the shortcuts is exactly
   the viewer this needs to work for.
   ══════════════════════════════════════════════════════════════════════ */

#controls {
    display: flex; align-items: center; gap: 10px;
    height: 46px; min-height: 46px; padding: 0 14px;
    background: var(--bg-raised); border-top: 1px solid var(--rule);
    z-index: 10;
}

.cbtn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 30px; height: 26px; padding: 0 8px;
    border: 1px solid rgba(255,255,255,0.1); border-radius: 4px;
    color: var(--dim); font-size: 12px; white-space: nowrap;
}
.cbtn:hover { color: var(--text); border-color: rgba(255,255,255,0.25); background: rgba(255,255,255,0.04); }
.cbtn.on { color: var(--bg); background: var(--amber); border-color: var(--amber); font-weight: 600; }
.cbtn.wide { min-width: 62px; }

.cgroup { display: flex; align-items: center; gap: 4px; }
.cgroup + .cgroup { margin-left: 4px; padding-left: 10px; border-left: 1px solid rgba(255,255,255,0.08); }
.clabel { font-size: 9.5px; color: var(--dimmer); text-transform: uppercase; letter-spacing: 0.6px; }

#speed-display {
    min-width: 46px; text-align: center; font-size: 11px;
    color: var(--amber); font-variant-numeric: tabular-nums;
}

/* ── Scrubber: turn structure + seam spikes + playhead ─────────────── */
#scrubber {
    flex: 1; min-width: 90px; height: 26px; position: relative;
    cursor: pointer; border-radius: 3px; overflow: hidden;
    background: rgba(0,0,0,0.35);
}
#scrub-canvas { display: block; width: 100%; height: 100%; }
#scrub-head {
    position: absolute; top: 0; bottom: 0; width: 2px;
    background: var(--amber); pointer-events: none;
    box-shadow: 0 0 5px rgba(255,200,100,0.8);
}
#scrub-tip {
    position: absolute; bottom: 34px; transform: translateX(-50%);
    background: rgba(15,15,25,0.97); border: 1px solid var(--amber);
    border-radius: 4px; padding: 5px 9px; font-size: 11px;
    pointer-events: none; display: none; z-index: 60; max-width: 320px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ══════════════════════════════════════════════════════════════════════
   LEGEND
   ══════════════════════════════════════════════════════════════════════ */

/* Bottom-left, not bottom-right: the playhead lives at the right edge and the
   most recent tokens are always the ones being looked at. */
#legend {
    position: fixed; left: 44px; bottom: 58px; z-index: 40;
    width: 268px; padding: 12px 14px;
    background: rgba(15, 15, 25, 0.95); backdrop-filter: blur(6px);
    border: 1px solid var(--rule); border-radius: 6px;
    font-size: 11px; line-height: 1.5;
}
#legend.hidden { display: none; }
#legend h3 {
    font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--amber); margin-bottom: 8px; font-weight: 600;
}
#legend dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 9px; }
#legend dt { color: var(--amber); white-space: nowrap; }
#legend dd { color: var(--dim); }
#legend .close { position: absolute; top: 7px; right: 9px; color: var(--dimmer); font-size: 13px; }
#legend .close:hover { color: var(--text); }
.swatch {
    display: inline-block; width: 26px; height: 9px; border-radius: 2px;
    vertical-align: middle; margin-right: 4px;
}

/* ══════════════════════════════════════════════════════════════════════
   INSPECTOR TOOLTIP
   ══════════════════════════════════════════════════════════════════════ */

#inspector {
    position: fixed; z-index: 100; display: none;
    background: rgba(15, 15, 25, 0.95); backdrop-filter: blur(4px);
    border: 1px solid var(--amber); border-radius: 4px;
    padding: 8px 10px; font-size: 11px; line-height: 1.5;
    pointer-events: none; min-width: 178px;
}
#inspector .label { color: var(--amber); font-weight: 600; }
#inspector .piece { color: var(--text); word-break: break-all; }
#inspector table { border-collapse: collapse; margin-top: 5px; }
#inspector td { padding: 0 0 0 0; color: var(--dim); font-variant-numeric: tabular-nums; }
#inspector td.k { padding-right: 9px; }
#inspector td.v { color: var(--text); text-align: right; }

/* ══════════════════════════════════════════════════════════════════════
   TRANSIENT STATUS (colour-basis workflow etc.)
   ══════════════════════════════════════════════════════════════════════ */

#status-bar {
    position: fixed; bottom: 58px; left: 50%; transform: translateX(-50%);
    z-index: 50; display: none; max-width: min(760px, 92vw);
    background: rgba(15,15,25,0.96); backdrop-filter: blur(4px);
    border: 1px solid var(--amber); border-radius: 6px;
    padding: 9px 18px; font-size: 12px; color: var(--amber); text-align: center;
}
#status-bar .hint { color: var(--dim); font-size: 11px; display: block; margin-top: 3px; }

/* ══════════════════════════════════════════════════════════════════════
   OVERLAYS — shared scaffolding
   ══════════════════════════════════════════════════════════════════════ */

.overlay {
    position: fixed; inset: 0; z-index: 150;
    background: rgba(9, 9, 15, 0.97);
    /* align-items:flex-start + margin:auto on the card, rather than
       align-items:center. Centring a flex item taller than its container
       clips it at BOTH ends and makes the overflow unreachable; auto margins
       centre when there is room and fall back to the start when there is not. */
    display: flex; align-items: flex-start; justify-content: center;
    padding: 4vh 4vw; overflow-y: auto;
}
.overlay.hidden { display: none; }
.overlay-card { max-width: 720px; width: 100%; margin: auto; }
.overlay h2 {
    font-size: 15px; color: var(--amber); letter-spacing: 1.2px;
    text-transform: uppercase; margin-bottom: 14px; font-weight: 600;
}
.overlay .dismiss {
    position: fixed; top: 14px; right: 18px; z-index: 5;
    color: var(--dim); font-size: 12px; padding: 4px 10px;
    border: 1px solid rgba(255,255,255,0.12); border-radius: 4px;
}
.overlay .dismiss:hover { color: var(--text); border-color: var(--dim); }

/* ── Loading ───────────────────────────────────────────────────────── */
#loading { z-index: 200; flex-direction: column; gap: 14px; }
#loading h2 { font-size: 20px; letter-spacing: 4px; margin: 0; }
#loading-status { color: var(--dim); font-size: 12px; }
#loading-bar { width: 220px; height: 2px; background: rgba(255,255,255,0.1); overflow: hidden; }
#loading-bar i {
    display: block; height: 100%; width: 40%;
    background: var(--amber); animation: sweep 1.1s ease-in-out infinite;
}
@keyframes sweep { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

/* ── Cold open ─────────────────────────────────────────────────────── */
#cold-open { z-index: 190; background: var(--bg); }
#cold-open .overlay-card { max-width: 680px; }
#cold-open .eyebrow {
    font-size: 10px; letter-spacing: 2.5px; text-transform: uppercase;
    color: var(--dim); margin-bottom: 18px;
}
#cold-open h1 {
    font-size: 34px; letter-spacing: 6px; color: var(--amber);
    font-weight: 400; margin-bottom: 6px;
}
#cold-open .tagline { font-size: 13px; color: var(--dim); margin-bottom: 26px; font-style: italic; }
#cold-open p { font-size: 13.5px; line-height: 1.75; color: var(--text); margin-bottom: 15px; }
#cold-open p.muted { color: var(--dim); font-size: 12.5px; }
#cold-open .figure {
    margin: 22px 0; padding: 15px 18px;
    border-left: 2px solid var(--amber); background: rgba(255,200,100,0.04);
}
#cold-open .figure .big {
    font-size: 25px; color: var(--amber); letter-spacing: 0.5px;
    font-variant-numeric: tabular-nums; display: block; margin-bottom: 5px;
}
#cold-open .figure .cap { font-size: 11.5px; color: var(--dim); line-height: 1.6; }
#cold-open .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 30px; align-items: center; }
.pbtn {
    padding: 9px 20px; border-radius: 5px; font-size: 12.5px;
    border: 1px solid var(--rule); color: var(--amber);
}
.pbtn:hover { background: rgba(255,200,100,0.1); }
.pbtn.primary { background: var(--amber); color: var(--bg); font-weight: 600; border-color: var(--amber); }
.pbtn.primary:hover { background: #ffd68a; }
.pbtn.ghost { border-color: transparent; color: var(--dim); }
.pbtn.ghost:hover { color: var(--text); background: rgba(255,255,255,0.05); }

/* ── Tour card: sits beside the live visualisation, not over it ─────── */
#tour {
    position: fixed; z-index: 120;
    left: 24px; bottom: 66px; width: 384px; max-width: calc(100vw - 48px);
    background: rgba(13, 13, 21, 0.96); backdrop-filter: blur(8px);
    border: 1px solid var(--rule); border-radius: 8px;
    padding: 16px 18px 14px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
#tour.hidden { display: none; }
#tour .step-of {
    font-size: 9.5px; letter-spacing: 1.6px; text-transform: uppercase;
    color: var(--dim); margin-bottom: 7px;
}
#tour h3 { font-size: 14px; color: var(--amber); margin-bottom: 9px; font-weight: 600; line-height: 1.35; }
#tour .body { font-size: 12.5px; line-height: 1.6; color: var(--text); }
#tour .body b { color: #fff; font-weight: 600; }
#tour .look {
    margin-top: 11px; padding: 9px 11px; border-radius: 4px;
    background: rgba(255,200,100,0.07); border-left: 2px solid var(--amber);
    font-size: 12px; line-height: 1.55; color: var(--amber);
}
#tour .look::before { content: 'Look for '; font-weight: 600; text-transform: none; }
#tour details { margin-top: 10px; }
#tour summary {
    font-size: 10.5px; color: var(--dim); cursor: pointer;
    letter-spacing: 0.4px; list-style: none;
}
#tour summary::-webkit-details-marker { display: none; }
#tour summary::before { content: '▸ '; }
#tour details[open] summary::before { content: '▾ '; }
#tour summary:hover { color: var(--text); }
#tour .evidence {
    margin-top: 7px; padding: 9px 11px; border-radius: 4px;
    background: rgba(255,255,255,0.03); font-size: 10.5px;
    line-height: 1.62; color: var(--dim);
}
#tour .nav { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
#tour .nav .spacer { flex: 1; }
#tour .dots { display: flex; gap: 4px; }
#tour .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--dimmer); }
#tour .dot.on { background: var(--amber); }

/* ── Session picker ────────────────────────────────────────────────── */
#session-picker .overlay-card { max-width: 620px; }
.session-item {
    display: flex; align-items: baseline; gap: 13px;
    padding: 9px 12px; margin: 3px 0; border-radius: 5px;
    border: 1px solid transparent; width: 100%; text-align: left;
}
.session-item:hover { background: rgba(255,200,100,0.07); }
.session-item.active { background: rgba(255,200,100,0.13); border-color: var(--rule); }
.session-item .num { color: var(--amber); font-weight: 700; min-width: 15px; }
.session-item .name { color: var(--text); font-size: 13px; }
.session-item .desc { color: var(--dim); font-size: 11px; margin-top: 2px; }
.session-item .info { color: var(--dimmer); font-size: 10.5px; margin-left: auto; white-space: nowrap; }
.picker-note { color: var(--dim); font-size: 11px; margin-top: 16px; line-height: 1.6; }

/* ── Help ──────────────────────────────────────────────────────────── */
#help .overlay-card { max-width: 660px; }
#help .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 34px; }
#help .section {
    grid-column: 1 / -1; margin-top: 15px; margin-bottom: 3px;
    color: var(--user); font-size: 10px; text-transform: uppercase; letter-spacing: 1.3px;
}
#help .section:first-child { margin-top: 0; }
#help .row { display: flex; gap: 12px; font-size: 12px; line-height: 1.75; }
#help kbd {
    display: inline-block; min-width: 62px; color: var(--amber);
    font-family: var(--mono); font-size: 11px;
}
#help .note {
    grid-column: 1 / -1; margin-top: 20px; color: var(--dim);
    font-size: 11px; line-height: 1.65; font-style: italic;
}

/* ══════════════════════════════════════════════════════════════════════
   SMALL SCREENS
   This is a keyboard-and-pointer instrument. Rather than degrade quietly
   into something that looks broken, it says so and still lets you watch.
   ══════════════════════════════════════════════════════════════════════ */

#small-screen-note {
    display: none;
    padding: 9px 14px; font-size: 11.5px; line-height: 1.5;
    color: var(--amber); background: rgba(255,200,100,0.08);
    border-bottom: 1px solid var(--rule);
}

@media (max-width: 900px), (max-height: 520px) {
    #small-screen-note { display: block; }
    #text-panel { display: none; width: 0; min-width: 0; }
    #legend { display: none; }
    #tour { left: 8px; right: 8px; width: auto; bottom: 58px; }
    #controls { gap: 6px; padding: 0 8px; }
    .cgroup.optional { display: none; }
    #cold-open h1 { font-size: 26px; letter-spacing: 4px; }
    #cold-open .figure .big { font-size: 21px; }
    #help .cols { grid-template-columns: 1fr; }
}

/* Users who ask for less motion get the data without the animated carrier.
   The shimmer is a rendering channel, not a measurement, so removing it
   costs no information — see js/config.js on TURBULENCE_AMP. */
@media (prefers-reduced-motion: reduce) {
    #loading-bar i { animation: none; width: 100%; }
}
