/* BrookType tokens, from the brand sheet v1.0 (see docs/BRAND.md):
   Navy #0B162B, Sky #1765C4, Sky Light #3AA0FF, Ice #EAF4FF,
   Leaf #1E9A52, Slate #334155, Gray #94A3B8, White #FFFFFF. */
:root {
  color-scheme: light;
  --navy: #0B162B;
  --sky: #1765C4;        /* Sky: primary brand colour, caret, numbers, chart lines */
  --sky-light: #3AA0FF;  /* Sky Light: highlights and gradients */
  --lagoon: #3AA0FF;
  --ice: #EAF4FF;        /* Ice: backgrounds and sections */
  --mist: #EAF4FF;
  --leaf: #1E9A52;       /* Leaf: accents and success states */
  --fern: #9fd9b5;
  --ink: #0B162B;        /* Navy: primary text and UI */
  --ink-soft: #334155;   /* Slate: secondary text */
  --ink-faint: #94A3B8;  /* Gray: muted text and borders */
  --miss: #d23a31;
  --hit: #1E9A52;
  --brand-gradient: linear-gradient(90deg, #1765C4, #3AA0FF);

  --page: #F6FAFF;
  --surface: #fff;
  --field: rgba(255, 255, 255, 0.85);
  --shade: 11, 22, 43;   /* Navy as rgb: hairlines, wells and shadows */

  /* Glass on white: a cool, slightly grey body so light has somewhere to show,
     a bright top edge, a hairline, and a soft shadow underneath. */
  --glass-fill: linear-gradient(180deg, #fff 0%, #f6f7f9 55%, #eef0f4 100%);
  --glass-blur: blur(14px) saturate(180%);
  --glass-rim: 0 0 0 0 transparent;
  --glass-line: 0 0 0 1px rgba(var(--shade), 0.07);
  --glass-drop: 0 0 0 0 transparent;
  --glass-lift: 0 0 0 0 transparent;
  --pane-edge: rgba(var(--shade), 0.08);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: "Lexend", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 400;
  background: linear-gradient(180deg, var(--ice) 0%, var(--page) 340px) no-repeat, var(--page);
  -webkit-font-smoothing: antialiased;
  transition: background-color 200ms ease, color 200ms ease;
}
button { font: inherit; }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }

/* ---------- Stage ---------- */
.stage {
  max-width: 980px; margin: 0 auto; padding: 28px 16px 72px;
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 14px;
}
/* ---------- Brand: the primary logo (wave + wordmark + tagline) ---------- */
.brand { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 12px; padding: 0 6px 4px; }
.brand-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.brand-logo {
  display: inline-grid; justify-items: center; color: var(--ink); text-decoration: none;
  border-radius: 12px; padding: 0 4px;
}
.brand-wave { display: block; width: 4.6rem; height: auto; margin: 0 0 -0.55rem 2.2rem; overflow: visible; }
.brand-word { font-size: 2rem; font-weight: 700; letter-spacing: -0.035em; line-height: 1.1; color: var(--ink); }
.brand-word b {
  font-weight: 700; color: var(--sky);
  background: var(--brand-gradient); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand-tag { margin-top: 2px; color: var(--ink-soft); font-size: 0.74rem; font-weight: 300; letter-spacing: 0.32em; padding-left: 0.32em; }
/* The drop at the end of the wave settles in once, like a bead landing. */
.brand-dot { transform-origin: 110px 14px; animation: brand-drop 900ms var(--spring) both; }
@keyframes brand-drop { from { transform: translateY(-10px) scale(0.6); opacity: 0; } }

/* ---------- Window ---------- */
.window {
  position: relative; border-radius: 28px; background: var(--surface);
  box-shadow: 0 0 0 1px rgba(var(--shade), 0.06);
}
.titlebar {
  position: relative; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--pane-edge);
}
.titlebar-right { display: flex; align-items: center; gap: 8px; }

.pane { position: relative; padding: 28px 32px 26px; }

/* ---------- Controls ---------- */
.segmented {
  display: inline-flex; padding: 3px; border-radius: 999px;
  background: rgba(var(--shade), 0.05);
  box-shadow: none;
}
.segmented button {
  border: 0; background: none; color: var(--ink-soft); cursor: pointer;
  padding: 5px 14px; border-radius: 999px; font-size: 0.88rem; font-weight: 500;
}
.segmented button.active {
  color: var(--ink); background: var(--glass-fill);
  box-shadow: var(--glass-line);
}

.aero {
  color: var(--ink); cursor: pointer; padding: 8px 18px; border-radius: 999px; border: 0;
  background: var(--glass-fill);
  box-shadow: var(--glass-line);
}
.aero.icon { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; }
.aero.primary { font-weight: 600; padding: 12px 28px; box-shadow: 0 0 0 1px rgba(var(--shade), 0.1); }

.timer {
  min-width: 74px; height: 36px; padding: 0 14px; display: grid; place-items: center; border-radius: 999px;
  color: var(--ink); font-weight: 600; font-size: 1.05rem; font-variant-numeric: tabular-nums;
  background: rgba(var(--shade), 0.05);
  transition: color 200ms ease, background-color 200ms ease;
}
.timer.low { color: var(--miss); background: rgba(210, 58, 49, 0.08); }

/* ---------- Liquid hover ----------
   Like glass controls on a new iPhone: under the pointer a control swells,
   leans toward the pointer like a drop of water being pulled, and catches a
   light where the pointer is, shading the far side so it reads as a rounded
   drop. liquid.js feeds --mx/--my (light position), --dx/--dy (-1..1 from
   the centre), --px/--py (lean) and --sx/--sy (stretch). */
.aero, .segmented button, .ob-choice {
  --lift: 1; --grow: 0.05;
  --drop-shade: 0 0 0 0 transparent;
  position: relative; isolation: isolate;
  transform: translate(var(--px, 0px), var(--py, 0px))
    scale(calc(var(--lift) * var(--sx, 1)), calc(var(--lift) * var(--sy, 1)));
  transition: transform 520ms var(--spring), box-shadow 220ms ease, background-color 220ms ease, color 150ms ease;
}
.aero::after, .segmented button::after, .ob-choice::after {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  background: radial-gradient(90px circle at var(--mx, 50%) var(--my, 50%),
    #fff, rgba(255, 255, 255, 0.7) 35%, rgba(255, 255, 255, 0) 75%);
  opacity: 0; transition: opacity 220ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .aero:hover, .segmented button:hover, .ob-choice:hover { --lift: calc(1 + var(--grow)); }
  .aero:hover::after, .segmented button:hover::after, .ob-choice:hover::after { opacity: 1; }
  .aero:hover, .segmented button.active:hover { box-shadow: var(--glass-line); }
  .aero.primary:hover { box-shadow: 0 0 0 1px rgba(var(--shade), 0.1); }
  .segmented button:not(.active):hover { color: var(--ink); background: var(--glass-fill); box-shadow: var(--glass-line); }
}
/* Pressing swells the drop a little further, the way the glass does under a finger. */
.aero:active, .segmented button:active, .ob-choice:active { --lift: calc(1 + var(--grow) * 1.7); transition-duration: 260ms; }
.aero:active::after, .segmented button:active::after, .ob-choice:active::after { opacity: 1; }
.aero:disabled { --lift: 1; }

/* ---------- Words ---------- */
.words-wrap {
  --line: 3.3rem;
  position: relative; height: calc(var(--line) * 3); overflow: hidden;
  font-size: 1.85rem; line-height: var(--line); font-weight: 400; letter-spacing: 0.005em;
  cursor: text;
}
.words { position: relative; color: var(--ink-faint); transition: filter 150ms ease, opacity 150ms ease; }
.word { display: inline-block; margin-right: 0.55em; }
.word.bad { text-decoration: underline wavy var(--miss) 1.5px; text-underline-offset: 9px; }
.l.correct { color: var(--ink); }
.l.wrong { color: var(--miss); }
.l.extra { color: var(--miss); opacity: 0.65; }
.l.missed { color: rgba(196, 54, 47, 0.45); }
.l.caret, .l.caret-after { position: relative; }
.l.caret::before, .l.caret-after::after {
  content: ""; position: absolute; top: 18%; bottom: 18%; width: 2.5px; border-radius: 2px;
  background: var(--sky);
}
.l.caret::before { left: -1.5px; }
.l.caret-after::after { right: -2px; }
/* Blink only while idle; a steady caret while typing reads as responsive. */
.words-wrap:not(.typing) .l.caret::before,
.words-wrap:not(.typing) .l.caret-after::after { animation: blink 1.05s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.ghost-input {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1;
  opacity: 0; border: 0; padding: 0; font-size: 16px; cursor: text; caret-color: transparent;
}

.veil {
  position: absolute; inset: 0; z-index: 2; border: 0; cursor: pointer;
  display: grid; place-items: center; padding: 0 24px;
  color: var(--ink); font-size: 1.05rem; font-weight: 500;
  background: rgba(255, 255, 255, 0.35);
  opacity: 0; pointer-events: none; transition: opacity 150ms ease;
}
.words-wrap.unfocused .veil { opacity: 1; pointer-events: auto; }
.words-wrap.unfocused .words { filter: blur(5px); opacity: 0.6; }

.hint { margin: 18px 0 0; color: var(--ink-soft); font-size: 0.88rem; }
kbd {
  font-family: var(--font); font-size: 0.78rem; padding: 1px 7px; border-radius: 6px;
  background: linear-gradient(180deg, #fff, rgba(255,255,255,0.6));
  box-shadow: 0 0 0 0.5px rgba(var(--shade), 0.2);
}

/* ---------- Results ---------- */
.hidden { display: none !important; }
.summary { display: grid; grid-template-columns: auto 1fr; gap: 40px; align-items: center; }
.score { padding-right: 40px; border-right: 1px solid var(--pane-edge); }
.wpm {
  font-size: 5.2rem; font-weight: 600; line-height: 0.95; letter-spacing: -0.03em; color: var(--sky);
  font-variant-numeric: tabular-nums;
}
.wpm-label { color: var(--ink-soft); margin-top: 6px; }
.best { color: var(--ink-faint); font-size: 0.85rem; margin-top: 10px; }
.best.new { color: var(--leaf); font-weight: 500; }

.stats { margin: 0; display: grid; gap: 14px; }
.stats div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.stats dt { color: var(--ink-soft); }
.stats dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
#resAcc { font-size: 1.5rem; font-weight: 600; }
.ok { color: var(--hit); }
.bad { color: var(--miss); }

.analysis { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--pane-edge); }
.analysis h2, .word-lists h3 { margin: 0; font-weight: 600; }
.analysis h2 { font-size: 1.2rem; }
.sub { margin: 6px 0 14px; color: var(--ink-soft); font-size: 0.88rem; max-width: 64ch; }
.key-err { color: var(--miss); font-weight: 700; }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: rgba(70, 100, 127, 0.16); stroke-width: 1; }
.chart .axis text { fill: var(--ink-faint); font-size: 11px; font-family: var(--font); }
.chart .line { fill: none; stroke: var(--sky); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .err { stroke: var(--miss); stroke-width: 2; stroke-linecap: round; }
.chart .peak { fill: var(--surface); stroke: var(--sky); stroke-width: 2; }
.chart .peak-label {
  fill: var(--ink); font-size: 11.5px; font-weight: 500; font-family: var(--font);
  paint-order: stroke; stroke: var(--surface); stroke-width: 4px;
}
.chart .cross { stroke: rgba(var(--shade), 0.4); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hover-dot { fill: var(--sky); stroke: var(--surface); stroke-width: 2; }
/* The one orchestrated moment: the speed line draws itself in. */
.chart .line.draw { animation: draw 900ms var(--ease-out) forwards; }
.chart .fade-in { opacity: 0; animation: fade 300ms ease 600ms forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade { to { opacity: 1; } }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; opacity: 0;
  padding: 7px 12px; border-radius: 12px; font-size: 0.8rem; line-height: 1.45; color: var(--ink);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-line); transition: opacity 125ms ease;
}
.tooltip.show { opacity: 1; }
.tooltip b { font-variant-numeric: tabular-nums; font-weight: 600; }

.table-view { margin-top: 10px; font-size: 0.86rem; }
.table-view summary { cursor: pointer; color: var(--sky); width: fit-content; }
.table-scroll { max-height: 220px; overflow: auto; margin-top: 8px; }
.table-view table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 4px 10px; text-align: right; border-bottom: 1px solid rgba(var(--shade), 0.1); }
.table-view th { font-weight: 500; color: var(--ink-soft); }

.word-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 28px; }
.word-lists h3 { font-size: 0.98rem; margin-bottom: 10px; }
.word-lists ol { margin: 0; padding: 0; list-style: none; }
.word-lists li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid rgba(var(--shade), 0.1);
}
.word-lists li span { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.word-lists .empty { color: var(--ink-faint); border: 0; }
.actions { margin-top: 30px; display: flex; justify-content: center; }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .stage { justify-content: flex-start; padding-top: 16px; }
  .window { border-radius: 24px; }
  .titlebar { padding: 12px; }
  .pane { padding: 20px 16px; }
  .words-wrap { --line: 2.5rem; font-size: 1.35rem; }
  .summary { grid-template-columns: 1fr; gap: 20px; }
  .score { padding: 0 0 20px; border-right: 0; border-bottom: 1px solid var(--pane-edge); text-align: center; }
  .word-lists { grid-template-columns: 1fr; gap: 24px; }
  .segmented button { padding: 5px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .chart .line.draw { animation: none; stroke-dashoffset: 0 !important; }
  .chart .fade-in { animation: none; opacity: 1; }
  .l.caret::before, .l.caret-after::after { animation: none !important; }
  .aero, .segmented button, .ob-choice { transition: background-color 150ms ease, box-shadow 150ms ease; transform: none; }
}

/* ---------- Balloon tip (shown before a test starts) ---------- */
.balloon {
  position: relative; margin-top: 18px; max-width: 520px; padding: 14px 40px 14px 18px;
  border-radius: 22px; color: var(--ink);
  background: var(--mist);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.balloon h3 {
  margin: 0 0 4px; font-size: 0.92rem; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.balloon h3::before { /* small info glyph */
  content: "i"; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  font-size: 0.72rem; font-weight: 700; color: #fff; font-style: normal;
  background: radial-gradient(circle at 35% 30%, #8cc8f2, var(--sky));
}
.balloon p { margin: 0; font-size: 0.88rem; line-height: 1.5; color: var(--ink-soft); }
.balloon-close {
  position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 4px;
  border: 0; background: none; color: var(--ink-soft); cursor: pointer; display: grid; place-items: center;
}
.balloon-close:hover { background: rgba(196, 54, 47, 0.12); color: var(--miss); }
.balloon-next {
  margin-top: 8px; padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--sky); font-size: 0.84rem; text-decoration: underline; text-underline-offset: 3px;
}
.balloon.away { opacity: 0; transform: translateY(-4px); pointer-events: none; }
.balloon.gone { display: none; }

/* ---------- Coach notes ---------- */
.coach, .keyboard-section { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--pane-edge); }
.coach h2, .keyboard-section h2 { margin: 0 0 14px; font-size: 1.2rem; font-weight: 600; }
.keyboard-section h2 { margin-bottom: 0; }

.wins { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 6px; }
.wins li { display: flex; gap: 10px; align-items: baseline; color: var(--hit); font-weight: 500; }
.wins li::before { content: "✓"; font-weight: 700; }

.note h3 { margin: 0 0 6px; font-size: 1rem; font-weight: 600; }
.note p { margin: 0; line-height: 1.55; color: var(--ink-soft); max-width: 70ch; }
.note p b { color: var(--ink); font-weight: 600; }
.note ul { margin: 10px 0 0; padding-left: 1.1em; line-height: 1.55; }
.note li { margin-top: 4px; }
.note li::marker { color: var(--sky); }

.note.lead {
  padding: 18px 20px; border-radius: 18px;
  background: var(--mist);
}
.note.lead h3 { font-size: 1.18rem; }
.note-kicker { margin: 0 0 4px !important; font-size: 0.82rem; font-weight: 500; color: var(--sky) !important; }

.notes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 22px 28px; margin-top: 20px; }
.notes .note { padding-left: 14px; border-left: 2px solid rgba(var(--shade), 0.14); }
.coach-foot { margin: 18px 0 0; font-size: 0.86rem; color: var(--ink-soft); }

/* ---------- Keyboard map ---------- */
.keyboard-section { container-type: inline-size; }
/* 10 keys + 9 gaps + the 0.75-key stagger of the bottom row must fit the section. */
.keyboard { --k: min(52px, calc((100cqw - 54px) / 10.8)); display: grid; gap: 6px; margin: 16px 0 10px; width: fit-content; max-width: 100%; }
.kb-row { display: flex; gap: 6px; padding-left: calc(var(--offset) * var(--k)); }
.key {
  position: relative; width: var(--k); height: var(--k); border-radius: 7px;
  display: grid; place-items: center; font-weight: 500; font-size: clamp(0.72rem, calc(var(--k) * 0.36), 0.95rem); color: var(--ink);
  background-image: linear-gradient(180deg, rgba(255,255,255,0.65), rgba(255,255,255,0) 60%);
  box-shadow: 0 0 0 0.5px rgba(var(--shade), 0.18);
}
.key.bump span { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.key b {
  position: absolute; top: -7px; right: -7px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px; font-size: 0.7rem; font-weight: 600; color: #fff; background: var(--miss);
  display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface);
}
.key.miss { box-shadow: 0 0 0 2px rgba(210, 58, 49, var(--heat)); }
.f-pinky { background-color: #dbe9f8; }
.f-ring { background-color: #dcf0e0; }
.f-middle { background-color: #f6eccf; }
.f-index { background-color: #e8def6; }
.kb-space {
  margin-left: calc(2.2 * var(--k)); width: calc(5.6 * var(--k)); height: calc(var(--k) * 0.75);
  border-radius: 7px; display: grid; place-items: center; font-size: 0.8rem; color: var(--ink-soft);
  background: linear-gradient(180deg, #fff, rgba(255,255,255,0.6));
  box-shadow: 0 0 0 0.5px rgba(var(--shade), 0.18);
}
.finger-key { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 0.85rem; color: var(--ink-soft); }
.finger-key li { display: flex; align-items: center; gap: 7px; }
.finger-key i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(var(--shade), 0.2); }
.finger-key .miss-swatch { background: var(--surface); box-shadow: 0 0 0 2px var(--miss); border: 0; }

.actions { gap: 12px; flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) {
  .balloon { transition: opacity 150ms ease; }
  .balloon.away { transform: none; }
}

/* ---------- Brook ---------- */
.brook { display: flex; align-items: flex-start; gap: 14px; margin-top: 18px; transition: opacity 200ms var(--ease-out); }
.brook.away { opacity: 0; pointer-events: none; }
.brook.gone { display: none; }
.avatar-host {
  position: relative; flex: none; width: 104px; height: 120px;
  filter: none;
}
.avatar-host .avatar-canvas { width: 100%; height: 100%; display: block; }
.avatar-fallback { width: 100%; height: 100%; }
.avatar-host.live .avatar-fallback { display: none; }
/* The results host stays empty until the canvas moves in; show the fallback drop then. */
#avatarResults:not(.live)::before {
  content: ""; position: absolute; inset: 14px 18px;
  background: radial-gradient(circle at 38% 35%, #d9f0ff, #58b4ee 55%, #1765c4);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}

/* Brook's bubble sits beside Brook */
.brook .balloon { margin-top: 10px; flex: 1; border-top-left-radius: 8px; }
.brook .balloon h3::before { content: none; }
.speaker { margin: 0 0 2px !important; font-size: 0.78rem !important; font-weight: 600; color: var(--sky) !important; }

.name-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.name-form input {
  flex: 1 1 160px; min-width: 0; font: inherit; font-size: 0.95rem; padding: 8px 14px;
  border: 0; border-radius: 12px; color: var(--ink); background: var(--field);
  box-shadow: 0 0 0 0.5px rgba(var(--shade), 0.2);
}
.name-form input:focus { outline: none; box-shadow: 0 0 0 2px var(--sky); }
.linkish {
  border: 0; background: none; padding: 4px 2px; cursor: pointer; color: var(--sky);
  text-decoration: underline; text-underline-offset: 3px; font-size: 0.86rem;
}
.linkish.danger { color: var(--miss); }

/* ---------- Debrief at the top of results ---------- */
.debrief { display: flex; gap: 16px; align-items: center; margin-bottom: 22px; }
.debrief-speech h2 { margin: 0 0 4px; font-size: 1.25rem; font-weight: 600; }
.debrief-speech p { margin: 0; line-height: 1.55; color: var(--ink-soft); max-width: 66ch; }

/* ---------- What Brook knows ---------- */
.profile-section { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--pane-edge); }
.profile-section h2 { margin: 0 0 14px; font-size: 1.2rem; font-weight: 600; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.persona {
  padding: 18px 20px; border-radius: 18px;
  background: var(--mist);
}
.persona .note-kicker { color: var(--sky) !important; }
.persona h3 { margin: 0 0 6px; font-size: 1.3rem; font-weight: 600; }
.persona p { margin: 0; line-height: 1.55; color: var(--ink-soft); }
.persona ul { margin: 10px 0 0; padding-left: 1.1em; line-height: 1.5; font-size: 0.9rem; }
.persona li::marker { color: var(--sky); }
.facts { margin: 0; display: grid; gap: 10px; }
.facts div { display: grid; gap: 1px; }
.facts dt { font-size: 0.8rem; color: var(--ink-faint); }
.facts dd { margin: 0; font-weight: 500; }
.trend { margin-top: 14px; }
.trend span { display: block; font-size: 0.8rem; color: var(--ink-faint); margin-bottom: 4px; }
.spark { width: 100%; max-width: 280px; height: auto; overflow: visible; }
.spark path { fill: none; stroke: var(--sky); stroke-width: 2; stroke-linejoin: round; }
.spark circle { fill: var(--surface); stroke: var(--sky); stroke-width: 1.5; }
.spark circle:last-of-type { fill: var(--sky); }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 16px; }

@media (max-width: 640px) {
  .avatar-host { width: 76px; height: 88px; }
  .profile-grid { grid-template-columns: 1fr; }
  .debrief { align-items: flex-start; }
}

/* ---------- Profile button ---------- */
.profile-btn { height: 34px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; font-size: 0.88rem; font-weight: 500; }
.profile-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, rgba(255,255,255,0.97), rgba(255,255,255,0.8));
  box-shadow: 0 0 0 1px rgba(var(--shade), 0.28);
}
@media (max-width: 480px) { .profile-btn span { display: none; } .profile-btn { width: 36px; padding: 0; justify-content: center; } }

/* ---------- Results: short profile teaser ---------- */
.profile-teaser { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; }
.profile-teaser h3 { margin: 0 0 4px; font-size: 1.15rem; font-weight: 600; }
.profile-teaser p { margin: 0; color: var(--ink-soft); }
.profile-teaser .note-kicker { color: var(--sky) !important; margin-bottom: 2px !important; }

/* ---------- Profile view ---------- */
.pf-top { margin-bottom: 8px; }
.linkish.back { text-decoration: none; font-size: 0.9rem; padding-left: 0; }
.linkish.back:hover { text-decoration: underline; }

.pf-header { display: flex; align-items: center; gap: 16px; }
.pf-hello h2 { margin: 0 0 4px; font-size: 1.45rem; font-weight: 600; letter-spacing: -0.01em; }
.pf-hello p { margin: 0; color: var(--ink-soft); }
.pf-hello .linkish { margin-left: 6px; }
.pf-hello .name-form { margin-top: 4px; }

.pf-tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; margin-top: 22px;
  background: var(--pane-edge); border-radius: 18px; overflow: hidden;
  box-shadow: 0 0 0 0.5px rgba(var(--shade), 0.12); }
.pf-tile { background: var(--field); padding: 14px 14px; display: grid; gap: 2px; }
.pf-tile b { font-size: 1.6rem; font-weight: 600; color: var(--sky); font-variant-numeric: tabular-nums; line-height: 1.1; }
.pf-tile span { font-size: 0.8rem; color: var(--ink-soft); }

.pf-section { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--pane-edge); }
.pf-section h3 { margin: 0 0 4px; font-size: 1.08rem; font-weight: 600; }
.pf-section h4 { margin: 18px 0 8px; font-size: 0.92rem; font-weight: 600; }
.pf-section .sub { margin-bottom: 12px; }
.pf-two { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: start; }
.pf-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.pf-empty { color: var(--ink-faint); margin: 0; }

.segmented.small button { padding: 4px 10px; font-size: 0.8rem; }

.pf-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.pf-bars li { display: grid; grid-template-columns: minmax(120px, 1.2fr) 2fr auto; gap: 10px; align-items: center; font-size: 0.88rem; }
.pf-bar-track { height: 8px; border-radius: 4px; background: rgba(var(--shade), 0.08); overflow: hidden; }
.pf-bar-track i { display: block; height: 100%; border-radius: 4px; background: var(--sky); }
.pf-bar-val { color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }

.pf-chart { margin: 0 0 14px; }
.pf-chart figcaption { font-size: 0.82rem; color: var(--ink-soft); margin-bottom: 2px; }
.pf-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.pf-grid line { stroke: rgba(70, 100, 127, 0.16); }
.pf-grid text { fill: var(--ink-faint); font-size: 11px; font-family: var(--font); }
.pf-line { fill: none; stroke: var(--sky); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pf-dot { fill: var(--surface); stroke: var(--sky); stroke-width: 1.5; }
.pf-chart .cross { stroke: rgba(var(--shade), 0.4); stroke-dasharray: 3 3; }

.pf-section .keyboard-section { margin: 0; padding: 0; border: 0; }
.pf-section:has(#pfKeyboard) { container-type: inline-size; }

.pf-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.pf-chips li {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; border-radius: 999px;
  background: var(--glass-fill); font-size: 0.9rem;
  box-shadow: var(--glass-line);
}
.pf-chips button {
  width: 22px; height: 22px; border-radius: 50%; border: 0; background: none; cursor: pointer;
  color: var(--ink-faint); display: grid; place-items: center;
}
.pf-chips button:hover { color: var(--miss); background: rgba(196, 54, 47, 0.1); }

.pf-calendar { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; width: fit-content; }
.pf-calendar i, .pf-cal-key i { width: 13px; height: 13px; border-radius: 3px; display: block; }
.lvl0 { background: rgba(var(--shade), 0.07); }
.lvl1 { background: #b4d3f3; }
.lvl2 { background: #5b9be0; }
.lvl3 { background: #1765c4; }
.pf-cal-key { display: flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 0.78rem; color: var(--ink-faint); }
.pf-cal-key span { margin: 0 4px; }

.pf-table table { border-collapse: collapse; width: 100%; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.pf-table th, .pf-table td { padding: 7px 10px; text-align: left; border-bottom: 1px solid rgba(var(--shade), 0.1); }
.pf-table th { font-weight: 500; color: var(--ink-soft); }
.pf-table td:nth-child(n+2):nth-child(-n+4), .pf-table th:nth-child(n+2):nth-child(-n+4) { text-align: right; }
.pf-table { max-height: none; }

.pf-danger .pf-warn { margin: 0 0 12px; color: var(--miss); font-weight: 500; max-width: 64ch; }
.pf-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.aero.danger { color: var(--miss); font-weight: 600; }
.aero.danger-outline { color: var(--miss); }

@media (max-width: 760px) {
  .pf-tiles { grid-template-columns: repeat(3, 1fr); }
  .pf-two { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .pf-tiles { grid-template-columns: repeat(2, 1fr); }
  .pf-bars li { grid-template-columns: 1fr auto; }
  .pf-bars .pf-bar-track { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- Onboarding ---------- */
.ob { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: start; padding: 6px 0; }
.ob-avatar { width: 150px; height: 172px; }
.ob-main { min-width: 0; max-width: 620px; }
.ob-main h2 { margin: 0 0 6px; font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.ob-lead { margin: 0 0 10px; color: var(--ink-soft); line-height: 1.55; }
.ob-sub { margin: 0 0 12px; color: var(--ink-faint); font-size: 0.88rem; }
.ob-reaction {
  margin: 0 0 14px; padding: 12px 16px; border-radius: 16px; line-height: 1.5; color: var(--ink);
  background: var(--mist);
}
.ob-name { margin: 6px 0 8px; max-width: 440px; }

.ob-progress { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.ob-progress i { width: 26px; height: 6px; border-radius: 3px; background: rgba(var(--shade), 0.1); }
.ob-progress i.done { background: var(--ink); }
.ob-progress span { margin-left: 8px; font-size: 0.8rem; color: var(--ink-faint); }

.ob-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 6px; }
.ob-choice {
  display: flex; align-items: flex-start; gap: 12px; text-align: left; cursor: pointer;
  --grow: 0.015;
  padding: 13px 16px; border-radius: 16px; border: 0; color: var(--ink);
  background: var(--glass-fill);
  box-shadow: var(--glass-line);
}
@media (hover: hover) and (pointer: fine) {
  .ob-choice:hover { box-shadow: var(--glass-line); }
  .ob-choice.on:hover { box-shadow: 0 0 0 1.5px var(--ink); }
}
.ob-choice.on { box-shadow: 0 0 0 1.5px var(--ink); }
.ob-check {
  flex: none; width: 18px; height: 18px; margin-top: 2px; border-radius: 50%;
  border: 1.5px solid rgba(var(--shade), 0.35); background: var(--surface); display: grid; place-items: center;
}
.ob-choice[role="checkbox"] .ob-check { border-radius: 5px; }
.ob-choice.on .ob-check { border-color: var(--ink); background: var(--ink); }
.ob-choice.on .ob-check::after {
  content: ""; width: 5px; height: 9px; margin-top: -2px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.ob-text { display: grid; gap: 2px; }
.ob-text b { font-weight: 500; }
.ob-text small { font-size: 0.82rem; color: var(--ink-faint); }
.ob-choices.compact .ob-choice { padding: 11px 14px; align-items: center; }
.ob-choices.compact .ob-check { margin-top: 0; }

.ob-nav { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.ob-spacer { flex: 1; }
.aero:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ob-plan { margin: 6px 0 14px; padding-left: 1.2em; line-height: 1.6; }
.ob-plan li { margin-top: 4px; }
.ob-plan li::marker { color: var(--sky); }

/* Brook's offer buttons and the profile's About section */
.balloon-offer { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.balloon-offer .aero.primary { padding: 7px 16px; font-size: 0.9rem; }
.pf-about { margin: 6px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 24px; }
.pf-about dt { font-size: 0.8rem; color: var(--ink-faint); }
.pf-about dd { margin: 2px 0 0; font-weight: 500; }

@media (max-width: 640px) {
  .ob { grid-template-columns: 1fr; gap: 6px; }
  .ob-avatar { width: 96px; height: 110px; }
  .ob-choices { grid-template-columns: 1fr; }
  .ob-main h2 { font-size: 1.25rem; }
}

/* ---------- AI opt-in switch (Profile → Your data) ---------- */
.pf-switch { display: flex; align-items: flex-start; gap: 12px; margin: 4px 0 18px; cursor: pointer; max-width: 70ch; }
.pf-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pf-switch-ui {
  flex: none; position: relative; width: 42px; height: 24px; margin-top: 1px; border-radius: 12px;
  background: rgba(var(--shade), 0.16); box-shadow: none;
  transition: background 160ms ease;
}
.pf-switch-ui::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background:
    radial-gradient(ellipse 70% 45% at 50% 85%, #fff, rgba(255,255,255,0) 70%),
    linear-gradient(#fff, #eef2f6);
  box-shadow: 0 0 0 0.5px rgba(var(--shade), 0.12);
  transition: transform 300ms var(--spring);
}
.pf-switch input:checked + .pf-switch-ui { background: var(--leaf); }
.pf-switch input:checked + .pf-switch-ui::after { transform: translateX(18px); }
.pf-switch input:focus-visible + .pf-switch-ui { outline: 2px solid var(--sky); outline-offset: 2px; }
.pf-switch-text { display: grid; gap: 3px; }
.pf-switch-text b { font-weight: 500; }
.pf-switch-text small { color: var(--ink-soft); font-size: 0.84rem; line-height: 1.5; }

/* Brook writing an AI note on the results page */
.debrief-status { margin: 6px 0 0; font-size: 0.82rem; color: var(--ink-faint); }
.debrief-status.hidden { display: none; }
.debrief-speech.swapping p, .debrief-speech.swapping h2 { opacity: 0; }
.debrief-speech p, .debrief-speech h2 { transition: opacity 180ms ease; }
@media (prefers-reduced-motion: reduce) { .pf-switch-ui, .pf-switch-ui::after, .debrief-speech p, .debrief-speech h2 { transition: none; } }

/* ---------- Mode + length controls share the left of the title bar ---------- */
.titlebar { flex-wrap: wrap; row-gap: 8px; }
.titlebar-left { display: flex; flex-wrap: wrap; gap: 8px; }
.hint .source { color: var(--leaf); font-weight: 500; }
@media (max-width: 520px) {
  .titlebar-left .segmented button { padding: 5px 8px; font-size: 0.82rem; }
}

/* ---------- Shared helpers ---------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.aero.small { padding: 4px 12px; font-size: 0.84rem; }
.chip {
  font: inherit; font-size: 0.86rem; cursor: pointer; padding: 6px 12px; border-radius: 16px;
  color: var(--ink); background: var(--field); border: 1px solid rgba(62, 155, 219, 0.45);
  transition: transform 160ms var(--ease-out), border-color 150ms ease;
}
.chip:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .chip:hover { border-color: var(--sky); } }

/* Brook's bubble links and results-page link */
.balloon-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.ask-test { margin-top: 6px; padding-left: 0; }
.ask-btn { margin-top: 10px; }

/* ---------- Ask Brook ---------- */
.chat-head { display: flex; align-items: center; gap: 16px; }
.chat-head h2 { margin: 0 0 4px; font-size: 1.45rem; font-weight: 600; }
.chat-head .sub { margin: 0; }
.chat-avatar { width: 96px; height: 110px; }
.chat-log {
  margin-top: 18px; max-height: 52vh; min-height: 160px; overflow-y: auto; padding: 4px 4px 4px 0;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; line-height: 1.55; }
.chat-msg p { margin: 0; }
.chat-msg p + p, .chat-msg p + ul, .chat-msg ul + p { margin-top: 6px; }
.chat-msg ul { margin: 0; padding-left: 1.2em; }
.chat-msg.assistant {
  align-self: flex-start; color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #f1f8fe); border: 1px solid #a9c1d9;
  border-bottom-left-radius: 4px;
}
.chat-msg.user {
  align-self: flex-end; color: #fff;
  background: linear-gradient(180deg, #4b9fe3, #1f74c9); border: 1px solid var(--accent-dark, #11508f);
  border-bottom-right-radius: 4px;
}
.chat-msg.pending { color: var(--ink-faint); font-style: italic; }
.chat-msg.error { border-color: rgba(196, 54, 47, 0.5); color: var(--miss); }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chat-suggest:empty { display: none; }
.chat-form { display: flex; gap: 10px; align-items: flex-end; margin-top: 14px; }
.chat-form textarea {
  flex: 1; min-width: 0; resize: vertical; font: inherit; font-size: 1rem; padding: 10px 12px;
  color: var(--ink); background: var(--surface); border: 1px solid #8fb0d0; border-radius: 8px;
  box-shadow: none;
}
.chat-form textarea:focus { outline: none; border-color: var(--sky); box-shadow: 0 0 0 3px rgba(62,155,219,0.3); }
.chat-foot { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 8px; font-size: 0.8rem; color: var(--ink-faint); }
.chat-foot .linkish { margin-left: auto; font-size: 0.8rem; }
.chat-consent { margin-top: 18px; padding: 16px 18px; border-radius: 8px; background: rgba(62,155,219,0.08); border: 1px solid rgba(62,155,219,0.3); max-width: 70ch; }
.chat-consent p { margin: 0 0 12px; line-height: 1.55; color: var(--ink-soft); }
.chat-consent b { color: var(--ink); }

/* ---------- This week's plan ---------- */
.pf-plan-summary { margin: 4px 0 8px; line-height: 1.55; }
.pf-focus { list-style: none; margin: 8px 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.pf-focus li {
  padding: 4px 12px; border-radius: 14px; font-size: 0.86rem; font-weight: 500; color: var(--leaf);
  background: rgba(143, 208, 111, 0.18); border: 1px solid rgba(46, 148, 69, 0.35);
}
.pf-sessions { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pf-sessions li {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; border-radius: 8px; background: var(--field); border: 1px solid rgba(150,185,218,0.6);
}
.pf-sessions li.today { border-color: var(--sky); box-shadow: 0 0 0 2px rgba(62,155,219,0.18); }
.pf-sessions li.done { background: rgba(143, 208, 111, 0.12); }
.pf-day { font-weight: 600; display: grid; }
.pf-day small { font-weight: 500; font-size: 0.75rem; color: var(--sky); }
.pf-what { display: grid; gap: 2px; }
.pf-what b { font-weight: 500; }
.pf-what small { color: var(--ink-soft); font-size: 0.84rem; }
.pf-done { color: var(--leaf); font-weight: 600; font-size: 0.86rem; }
.pf-done::before { content: "✓ "; }
.pf-encourage { margin: 12px 0 2px; font-weight: 500; }

/* ---------- Brook's note ---------- */
.pf-memory {
  margin: 8px 0 6px; padding: 12px 16px; border-left: 3px solid var(--fern); border-radius: 0 8px 8px 0;
  background: var(--field); line-height: 1.6; color: var(--ink); max-width: 70ch;
}
.pf-memory-form textarea {
  width: 100%; max-width: 70ch; font: inherit; padding: 10px 12px; margin: 8px 0 10px; color: var(--ink);
  background: var(--surface); border: 1px solid #8fb0d0; border-radius: 8px; resize: vertical;
}
.pf-memory-form textarea:focus { outline: none; border-color: var(--sky); box-shadow: 0 0 0 3px rgba(62,155,219,0.3); }

@media (max-width: 640px) {
  .chat-msg { max-width: 95%; }
  .chat-avatar { width: 72px; height: 84px; }
  .pf-sessions li { grid-template-columns: 48px 1fr; }
  .pf-state { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) { .chip { transition: none; } }

/* =====================================================================
   BrookType brand layer: numbers in mono, the new title-bar tools,
   Daily Brook, sharing, signature motion and the Night Brook theme.
   See docs/BRAND.md.
   ===================================================================== */

/* Numbers and code read as a precision instrument. */
.timer, .wpm, #resAcc, .pf-tile b, .pf-record b { font-variant-numeric: tabular-nums; }
.wpm { font-weight: 700; letter-spacing: -0.04em; }
/* Code mode keeps a monospace face: symbols and indentation need fixed widths. */
.words-wrap.mode-code { font-family: var(--mono); font-size: 1.6rem; letter-spacing: 0; }
@media (max-width: 640px) { .words-wrap.mode-code { font-size: 1.15rem; } }

/* ---------- Primary buttons: Sky gradient ---------- */
.aero.primary {
  color: #fff; background: linear-gradient(180deg, #3AA0FF 0%, #1765C4 100%);
  box-shadow: 0 0 0 1px rgba(23, 101, 196, 0.5);
}
@media (hover: hover) and (pointer: fine) {
  .aero.primary:hover { box-shadow: 0 0 0 1px rgba(23, 101, 196, 0.5); }
}
.aero.primary::after { background: radial-gradient(90px circle at var(--mx, 50%) var(--my, 50%), rgba(255,255,255,0.45), rgba(255,255,255,0) 75%); }

/* ---------- Title-bar tools: sound + theme ---------- */
.aero.icon.tool-btn { width: auto; min-width: 36px; padding: 0 10px; gap: 6px; display: inline-flex; align-items: center; justify-content: center; }
.tool-label { font-size: 0.8rem; font-weight: 500; }
.tool-label:empty { display: none; }
#soundBtn .snd-on { display: none; }
#soundBtn.on .snd-on { display: inline; }
#soundBtn.on .snd-off { display: none; }
#soundBtn.on { color: var(--sky); }
#themeBtn .ico-sun { display: none; }
.night #themeBtn .ico-sun { display: block; }
.night #themeBtn .ico-moon { display: none; }
@media (max-width: 520px) { .tool-label { display: none; } }

/* ---------- Daily Brook ---------- */
.daily-btn { display: inline-flex; align-items: center; gap: 6px; height: 33px; padding: 0 14px; font-size: 0.86rem; font-weight: 500; }
.daily-btn svg { color: var(--sky); }
.daily-btn[aria-pressed="true"] { color: var(--sky); box-shadow: 0 0 0 1.5px var(--sky); }
.daily-btn.done svg { color: var(--leaf); }
.daily-streak {
  font-style: normal; font-variant-numeric: tabular-nums; font-size: 0.74rem; font-weight: 600;
  padding: 1px 7px; border-radius: 999px; color: var(--sky); background: var(--ice);
}
@media (max-width: 520px) { .daily-btn { padding: 0 10px; } .daily-btn span { display: none; } }

/* ---------- First keystroke: a ripple spreads from the caret ---------- */
.ripple {
  position: absolute; z-index: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  pointer-events: none; border: 2px solid var(--sky); opacity: 0;
  animation: ripple 700ms var(--ease-out) forwards;
}
.ripple.late { animation-delay: 140ms; border-width: 1.5px; }
@keyframes ripple { 0% { transform: scale(0.4); opacity: 0.55; } 100% { transform: scale(7); opacity: 0; } }

/* ---------- Personal best: Sunlit splash ---------- */
.score { position: relative; }
.score.pb .wpm { background: var(--brand-gradient); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; filter: none; }
.score.pb .best.new { color: var(--sky); font-weight: 600; }
.splash { position: absolute; left: 1.1em; top: 2.5rem; width: 0; height: 0; pointer-events: none; }
.splash i {
  position: absolute; left: -40px; top: -40px; width: 80px; height: 80px; border-radius: 50%;
  border: 2px solid var(--sky-light); opacity: 0; animation: splash 1100ms var(--ease-out) forwards;
}
.splash i:nth-child(2) { animation-delay: 160ms; border-color: var(--sky); }
.splash i:nth-child(3) { animation-delay: 320ms; }
@keyframes splash { 0% { transform: scale(0.2); opacity: 0.9; } 100% { transform: scale(2.6); opacity: 0; } }
@media (max-width: 640px) { .splash { left: 50%; } }

/* ---------- Share ---------- */
.share-btn { display: inline-flex; align-items: center; gap: 8px; }
.share-dialog {
  width: min(680px, calc(100vw - 32px)); padding: 20px; border: 0; border-radius: 24px;
  color: var(--ink); background: var(--surface);
  box-shadow: 0 0 0 1px rgba(var(--shade), 0.08);
}
.share-dialog::backdrop { background: rgba(8, 20, 34, 0.45); backdrop-filter: blur(4px); }
.share-dialog[open] { animation: pop 260ms var(--ease-out); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.share-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.share-head h2 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.share-preview { display: block; width: 100%; height: auto; aspect-ratio: 1200 / 630; border-radius: 14px; background: #0b1622; box-shadow: 0 0 0 1px rgba(var(--shade), 0.1); }
.share-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.share-status { min-height: 1.3em; margin: 10px 0 0; font-size: 0.86rem; color: var(--leaf); }

/* ---------- Records (Profile) ---------- */
.pf-records { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.pf-record { padding: 12px 14px; border-radius: 16px; background: var(--mist); display: grid; gap: 2px; }
.pf-record b { font-size: 1.45rem; font-weight: 700; color: var(--sky); letter-spacing: -0.03em; line-height: 1.1; }
.pf-record span { font-size: 0.8rem; color: var(--ink-soft); }
.pf-record.daily b { color: var(--sky-light); }

@media (prefers-reduced-motion: reduce) {
  .brand-dot, .share-dialog[open] { animation: none !important; }
  .ripple, .splash { display: none; }
  body { transition: none; }
}

/* ---------- Night Brook: deep water instead of white glass ----------
   app.js puts .night on <html> whenever the resolved theme is dark (the
   toggle, or the system setting when the user hasn't picked one). */
.night {
  color-scheme: dark;
  --sky: #3AA0FF; --sky-light: #7cc0ff; --lagoon: #7cc0ff; --leaf: #3cc47a; --fern: #2f7a52;
  --ink: #FFFFFF; --ink-soft: #c3cfdd; --ink-faint: #94A3B8; --miss: #ff6b62; --hit: #3cc47a;
  --ice: #13254A; --mist: #13254A; --page: #0B162B; --surface: #0F1D38; --field: rgba(255, 255, 255, 0.05);
  --shade: 148, 163, 184;
  --brand-gradient: linear-gradient(90deg, #3AA0FF, #7cc0ff);
  --glass-fill: linear-gradient(180deg, #1d3157 0%, #172a4b 60%, #142542 100%);
  --glass-rim: 0 0 0 0 transparent;
  --glass-line: 0 0 0 1px rgba(148, 163, 184, 0.14);
  --glass-drop: 0 0 0 0 transparent;
  --glass-lift: 0 0 0 0 transparent;
  --pane-edge: rgba(148, 163, 184, 0.14);
}
.night body { background: radial-gradient(120% 70% at 50% -10%, #16336a 0%, var(--page) 60%) fixed, var(--page); }
.night .window { box-shadow: 0 0 0 1px rgba(150, 185, 220, 0.1); }
.night .aero::after, .night .segmented button::after, .night .ob-choice::after {
  background: radial-gradient(90px circle at var(--mx, 50%) var(--my, 50%), rgba(140, 195, 250, 0.22), rgba(140, 195, 250, 0) 75%);
}
.night .veil { background: rgba(11, 22, 34, 0.45); }
.night kbd { background: linear-gradient(180deg, #23384f, #1a2c40); }
.night .tooltip { background: rgba(17, 31, 46, 0.88); }
.night .key { background-image: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0) 60%); box-shadow: 0 0 0 0.5px rgba(150, 185, 220, 0.25); }
.night .key.miss { box-shadow: 0 0 0 2px rgba(255, 107, 98, var(--heat)); }
.night .f-pinky { background-color: #1d3a5c; }
.night .f-ring { background-color: #1c4232; }
.night .f-middle { background-color: #4a3d1d; }
.night .f-index { background-color: #362a52; }
.night .kb-space { background: linear-gradient(180deg, #23384f, #1a2c40); }
.night .profile-btn[aria-pressed="true"] { background: var(--glass-fill); box-shadow: 0 0 0 1.5px var(--sky); }
.night .lvl1 { background: #1d4670; }
.night .lvl2 { background: #2f74bd; }
.night .lvl3 { background: #5aa2ec; }
.night .chat-msg.assistant { background: linear-gradient(180deg, #1a2c40, #16283a); border-color: rgba(150, 185, 220, 0.25); }
.night .chat-form textarea, .night .pf-memory-form textarea { border-color: rgba(150, 185, 220, 0.3); }
.night .pf-sessions li { border-color: rgba(150, 185, 220, 0.2); }
.night .avatar-host { filter: none; }
.night .brand-wave { filter: none; }

/* =====================================================================
   v1.1 features: flow mode, live stats, smooth caret, Pace Brook,
   Words extras, richer results, Quick actions, Preferences, footer.
   Ideas researched in docs/RESEARCH_MONKEYTYPE.md, built in our own style.
   ===================================================================== */

/* ---------- Words-mode extras (punctuation, numbers) ---------- */
.segmented.extras button { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.segmented.extras button.active { color: var(--sky); }

/* ---------- Live stats + Caps Lock warning, above the words ---------- */
.live-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 1.6rem; margin: -6px 0 8px; }
.live-stats { margin: 0; display: flex; gap: 18px; align-items: baseline; font-size: 0.9rem; color: var(--ink-faint); }
.live-stats b { font-size: 1.25rem; font-weight: 700; color: var(--sky); font-variant-numeric: tabular-nums; }
.live-num { display: none; }
.is-running .live-stats:not(.off) .live-num { display: inline; }
.live-pace { font-size: 0.82rem; }
.caps-warn {
  margin: 0 0 0 auto; padding: 3px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
  color: var(--miss); background: color-mix(in srgb, var(--miss) 12%, transparent);
}

/* ---------- Flow mode: everything but the words fades while you type ---------- */
.brand, .titlebar-left, .titlebar-right > *, .hint, .site-foot, .titlebar { transition: opacity 350ms ease, border-color 350ms ease; }
.flowing .brand, .flowing .titlebar-left, .flowing .titlebar-right > :not(.timer), .flowing .hint, .flowing .site-foot {
  opacity: 0; pointer-events: none;
}
.flowing .titlebar { border-bottom-color: transparent; }
.flowing .timer { background: transparent; color: var(--sky); }

/* ---------- Smooth caret and Pace Brook ---------- */
.smooth-caret, .pace-caret {
  position: absolute; left: 0; top: 0; z-index: 1; width: 2.5px; height: 1.6rem; border-radius: 2px;
  pointer-events: none; will-change: transform;
}
.smooth-caret { display: none; background: var(--sky); transition: transform 95ms ease-out; }
.caret-smooth .smooth-caret { display: block; }
.caret-smooth .l.caret::before, .caret-smooth .l.caret-after::after { display: none; }
.words-wrap.caret-smooth:not(.typing) .smooth-caret { animation: blink 1.05s steps(1) infinite; }
.unfocused .smooth-caret, .unfocused .pace-caret { opacity: 0; }
.pace-caret { background: var(--sky-light); opacity: 0.55; box-shadow: none; }
.pace-caret.hidden { display: none; }

/* ---------- Text size ---------- */
.words-wrap.size-s { --line: 2.7rem; font-size: 1.45rem; }
.words-wrap.size-l { --line: 3.9rem; font-size: 2.3rem; }
@media (max-width: 640px) {
  .words-wrap.size-s { --line: 2.2rem; font-size: 1.15rem; }
  .words-wrap.size-l { --line: 2.9rem; font-size: 1.6rem; }
}

/* ---------- Results: not counted, raw line, typed words ---------- */
.uncounted {
  display: inline-block; margin: 10px 0 0; padding: 3px 12px; border-radius: 999px; cursor: help;
  font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); background: var(--mist);
}
.chart .raw-line { fill: none; stroke: var(--ink-faint); stroke-width: 1.5; stroke-dasharray: 4 4; stroke-linejoin: round; }
.chart-key { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.8rem; color: var(--ink-soft); }
.chart-key li { display: flex; align-items: center; gap: 7px; }
.chart-key i { width: 18px; height: 0; border-top: 2px solid var(--sky); }
.chart-key .k-raw { border-top: 2px dashed var(--ink-faint); }

.typed-words { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--pane-edge); }
.typed-words summary { cursor: pointer; color: var(--sky); width: fit-content; font-weight: 500; }
.typed-words .sub { margin-top: 10px; }
.typed-list { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 1.05rem; line-height: 1.6; }
.tw { color: var(--ink-soft); }
.tw.bad { color: var(--ink); text-decoration: underline wavy var(--miss) 1.5px; text-underline-offset: 6px; cursor: help; }
.tw i { font-style: normal; }
.tw .w { color: var(--miss); font-weight: 600; }
.tw .x { color: var(--miss); opacity: 0.6; }
.tw .m { color: var(--ink-faint); text-decoration: underline; }

/* ---------- Footer ---------- */
.site-foot {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 20px;
  padding: 4px 8px 0; font-size: 0.8rem; color: var(--ink-faint);
}
.site-foot p { margin: 0; }
.foot-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; }
.foot-link { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.foot-link:hover { color: var(--sky); }
.site-foot kbd { font-size: 0.72rem; }

/* ---------- Dialogs shared look ---------- */
.bt-dialog {
  width: min(680px, calc(100vw - 32px)); padding: 20px; border: 0; border-radius: 24px;
  color: var(--ink); background: var(--surface);
  box-shadow: 0 0 0 1px rgba(var(--shade), 0.08);
}
.bt-dialog::backdrop { background: rgba(8, 20, 34, 0.45); backdrop-filter: blur(4px); }
.bt-dialog[open] { animation: pop 260ms var(--ease-out); }

/* ---------- Quick actions ---------- */
.palette { width: min(560px, calc(100vw - 32px)); padding: 0; margin-top: 12vh; overflow: hidden; }
.palette-search { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--pane-edge); color: var(--ink-faint); }
.palette-search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; font: inherit; font-size: 1.05rem; color: var(--ink); }
.palette-search input::placeholder { color: var(--ink-faint); }
.palette-list { list-style: none; margin: 0; padding: 6px; max-height: min(52vh, 440px); overflow-y: auto; }
.palette-group { padding: 10px 12px 4px; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.palette-list [role="option"] {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 12px; cursor: pointer;
}
.palette-list [role="option"].sel { background: var(--ice); color: var(--ink); }
.pa-label { display: grid; gap: 1px; }
.pa-label small { font-size: 0.78rem; color: var(--ink-faint); }
.pa-current { font-size: 0.74rem; font-weight: 600; color: var(--sky); }
.palette-empty { padding: 18px 12px; color: var(--ink-faint); }

/* ---------- Preferences ---------- */
.prefs { width: min(600px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto; }
.pref-group { padding: 14px 0 6px; border-top: 1px solid var(--pane-edge); }
.pref-group:first-child { border-top: 0; padding-top: 0; }
.pref-group h3 { margin: 0 0 10px; font-size: 0.98rem; font-weight: 600; }
.pref-group .sub { margin: -4px 0 10px; }
.pref-group .pf-switch { margin-bottom: 12px; }
.pref-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.pref-label { font-weight: 500; }
.pref-foot { margin: 8px 0 0; font-size: 0.82rem; color: var(--ink-faint); }

@media (prefers-reduced-motion: reduce) {
  .smooth-caret { transition: none; }
  .brand, .titlebar-left, .titlebar-right > *, .hint, .site-foot { transition: none; }
  .bt-dialog[open] { animation: none; }
}

/* =====================================================================
   Flat, futuristic surfaces: no shadows, no bevels, no glows.
   Depth comes from 1px hairlines and flat tints; interaction lights the
   hairline up in Sky instead of lifting the control.
   ===================================================================== */
:root {
  --glass-fill: #FFFFFF;
  --glass-line: 0 0 0 1px rgba(var(--shade), 0.12);
  --line-hover: 0 0 0 1px rgba(23, 101, 196, 0.45);
  --line-active: 0 0 0 1px rgba(23, 101, 196, 0.6);
}
.night {
  --glass-fill: rgba(255, 255, 255, 0.04);
  --glass-line: 0 0 0 1px rgba(148, 163, 184, 0.2);
  --line-hover: 0 0 0 1px rgba(58, 160, 255, 0.55);
  --line-active: 0 0 0 1px rgba(58, 160, 255, 0.7);
}

/* Panels: one crisp line instead of a floating shadow. */
.window, .night .window { box-shadow: 0 0 0 1px rgba(var(--shade), 0.1); }
.bt-dialog, .share-dialog { box-shadow: 0 0 0 1px rgba(var(--shade), 0.16); }

/* Pill tracks and controls. */
.segmented { background: rgba(var(--shade), 0.04); box-shadow: 0 0 0 1px rgba(var(--shade), 0.08); }
.segmented button.active { color: var(--sky); background: var(--glass-fill); box-shadow: var(--line-active); }
.daily-btn[aria-pressed="true"], .profile-btn[aria-pressed="true"], .night .profile-btn[aria-pressed="true"] {
  color: var(--sky); background: var(--ice); box-shadow: var(--line-active);
}
@media (hover: hover) and (pointer: fine) {
  .aero:hover, .segmented button.active:hover, .segmented button:not(.active):hover, .ob-choice:hover { box-shadow: var(--line-hover); }
  .ob-choice.on:hover { box-shadow: 0 0 0 1.5px var(--sky); }
  .aero.primary:hover { box-shadow: 0 0 0 1px rgba(23, 101, 196, 0.8); filter: brightness(1.06); }
}
.ob-choice.on { box-shadow: 0 0 0 1.5px var(--sky); }
.ob-choice.on .ob-check { border-color: var(--sky); background: var(--sky); }
.timer { box-shadow: 0 0 0 1px rgba(var(--shade), 0.06); }

/* Keys, keyboard map and switches: flat faces, hairline edges. */
kbd, .night kbd { background: var(--glass-fill); box-shadow: 0 0 0 1px rgba(var(--shade), 0.18); }
.key, .night .key { background-image: none; box-shadow: 0 0 0 1px rgba(var(--shade), 0.14); }
.kb-space, .night .kb-space { background: var(--glass-fill); box-shadow: 0 0 0 1px rgba(var(--shade), 0.14); }
.pf-switch-ui { box-shadow: 0 0 0 1px rgba(var(--shade), 0.1); }
.pf-switch-ui::after { background: #fff; box-shadow: 0 0 0 1px rgba(var(--shade), 0.14); }
.name-form input { box-shadow: 0 0 0 1px rgba(var(--shade), 0.16); }
.pf-tiles { box-shadow: 0 0 0 1px rgba(var(--shade), 0.1); }
.pf-chips li { box-shadow: var(--glass-line); }

/* Chat bubbles: flat tints. */
.chat-msg.assistant, .night .chat-msg.assistant { background: var(--ice); border-color: rgba(var(--shade), 0.12); }
.chat-msg.user { background: var(--sky); border-color: var(--sky); }
.chat-form textarea { box-shadow: none; }

/* The liquid hover light stays, but as a flat tint rather than a glossy highlight. */
.aero::after, .segmented button::after, .ob-choice::after {
  background: radial-gradient(90px circle at var(--mx, 50%) var(--my, 50%), rgba(58, 160, 255, 0.12), rgba(58, 160, 255, 0) 75%);
}
.aero.primary::after { background: radial-gradient(90px circle at var(--mx, 50%) var(--my, 50%), rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 75%); }

/* ---------- Hooks for feature modules: extra views, header buttons, notices ---------- */

.ext-view .ext-body { min-height: 240px; }
.test-extras:empty, .results-extras:empty { display: none; }
.test-extras { margin-bottom: 14px; }
.results-extras { display: grid; gap: 14px; margin: 26px 0 4px; }

.brand-tools .tool-ext { display: inline-flex; align-items: center; gap: 7px; }
.brand-tools .tool-ext svg { flex: none; }
@media (max-width: 900px) {
  .brand-tools .tool-ext span { display: none; }
  .brand-tools .tool-ext { padding-inline: 11px; }
}

.toasts {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: grid; gap: 8px; z-index: 60; pointer-events: none; width: min(420px, calc(100vw - 32px));
}
.toast {
  position: relative; overflow: hidden;
  display: grid; gap: 2px; padding: 12px 18px; border-radius: 16px;
  background: var(--navy); color: #fff; border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 14px; line-height: 1.4;
  animation: toast-in 0.28s ease-out both;
}
.toast b { font-weight: 600; }
.toast span { color: #cfe0f5; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.28s ease, transform 0.28s ease; }
html.night .toast { background: #EAF4FF; color: #0B162B; border-color: transparent; }
html.night .toast span { color: #334155; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } .toast.leaving { transition: none; } }

.name-dialog .name-form { display: grid; gap: 12px; }
.name-dialog input[type="text"] {
  font: inherit; font-size: 17px; padding: 11px 16px; border-radius: 999px;
  border: 1px solid var(--ink-faint); background: transparent; color: inherit; width: 100%;
}
.name-dialog input[type="text"]:focus-visible { outline: 2px solid var(--sky-light); outline-offset: 2px; border-color: transparent; }
.name-dialog .share-status:empty { display: none; }

.pf-streak-line { margin-top: 10px; }

.foot-pages { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin: 10px 0 6px; font-size: 0.82rem; color: var(--ink-soft); }
.foot-pages a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.foot-pages a:hover { color: var(--sky); }

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* No server behind the site (a plain static host): hide what needs other people. */
html:not(.has-backend) #leaderboardBtn,
html:not(.has-backend) #raceBtn,
html:not(.has-backend) #support,
html:not(.has-backend) #account,
html:not(.has-backend) #add-board,
html:not(.has-backend) #challenge-friend,
html:not(.has-backend) .friend-card { display: none !important; }
