/* breath — one token block for both themes; everything below reads it. The
   simulation is the colour; the chrome stays quiet and out of its way. */

:root {
  --bg: #05070e;
  --fg: #e8edf6;
  --dim: rgba(232, 237, 246, 0.6);
  --faint: rgba(232, 237, 246, 0.36);
  --line: rgba(232, 237, 246, 0.13);
  --wash: rgba(232, 237, 246, 0.07);
  --glass: rgba(8, 11, 20, 0.62);
  --sheet: #0c111d;
  --scrim: rgba(2, 3, 8, 0.55);
  --primary-bg: #e8edf6;
  --primary-fg: #05070e;
  --link: #9ccbff;
  /* Evidence levels: the one place colour carries meaning in the chrome. */
  --ev-moderate: #6ad6b0;
  --ev-limited: #e5bd68;
  --ev-weak: #ec8d7c;
  --ev-none: rgba(232, 237, 246, 0.4);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tap: 44px;
  --radius: 18px;
  --rail: 340px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --fade: 520ms;
  --vvh: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eef1f6;
  --fg: #111a2b;
  --dim: rgba(17, 26, 43, 0.62);
  --faint: rgba(17, 26, 43, 0.4);
  --line: rgba(17, 26, 43, 0.12);
  --wash: rgba(17, 26, 43, 0.05);
  --glass: rgba(246, 248, 252, 0.72);
  --sheet: #fbfcfe;
  --scrim: rgba(40, 50, 70, 0.25);
  --primary-bg: #111a2b;
  --primary-fg: #f4f6fa;
  --link: #1f5d99;
  --ev-moderate: #1d8a66;
  --ev-limited: #a87713;
  --ev-weak: #b84b39;
  --ev-none: rgba(17, 26, 43, 0.38);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: var(--vvh);
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:focus-visible, a:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: var(--vvh);
  display: block;
  /* The stage is a touch surface for the simulation, and the page never
     scrolls, so nothing is lost by taking every gesture here. */
  touch-action: none;
}

/* ---- chrome that fades out when a session starts ---- */
.chrome { transition: opacity var(--fade) var(--ease), visibility 0s linear 0s; }
body.in-session .chrome { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--fade) var(--ease), visibility 0s linear var(--fade); }

.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) calc(14px + var(--safe-right)) 10px calc(22px + var(--safe-left));
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { color: var(--fg); text-decoration: none; font-weight: 600; letter-spacing: 0.01em; opacity: 0.86; font-size: 17px; }
.tools { display: flex; gap: 2px; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: var(--dim);
  font-size: 18px;
  transition: color 160ms, background-color 160ms;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { color: var(--fg); background: var(--wash); }

.text-btn { color: var(--link); padding: 10px 2px; margin: -10px 0; }

/* ---- the dock: one technique on stage ---- */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 44px calc(20px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(20px + var(--safe-left));
  text-align: center;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--bg) 82%, transparent) 34%, var(--bg) 82%);
}
.tech-head { display: flex; align-items: center; justify-content: center; gap: 6px; max-width: 100%; }
.tech-name { margin: 0; font-size: 30px; font-weight: 500; letter-spacing: -0.012em; line-height: 1.15; min-width: 0; }
.step { color: var(--faint); }
.tech-summary { margin: 0; color: var(--dim); max-width: 36ch; text-wrap: balance; }
.tech-meta { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; font-size: 13.5px; color: var(--dim); }
.evidence { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 9px; border: 1px solid var(--line); border-radius: 999px; }
.evidence .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ev-none); }
.evidence[data-level="moderate"] .dot { background: var(--ev-moderate); }
.evidence[data-level="limited"] .dot { background: var(--ev-limited); }
.evidence[data-level="weak"] .dot { background: var(--ev-weak); }
.pattern { font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }

.glyph { width: min(240px, 70vw); height: 34px; overflow: visible; }
.glyph path { fill: none; stroke: var(--faint); stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; }

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg button {
  min-width: 52px;
  height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: background-color 180ms, color 180ms;
}
.seg button[aria-checked="true"] { background: var(--fg); color: var(--bg); }

.primary, .secondary {
  height: 54px;
  padding: 0 28px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.01em;
}
.primary { background: var(--primary-bg); color: var(--primary-fg); }
.secondary { border: 1px solid var(--line); color: var(--fg); }
.begin { width: min(100%, 380px); }

.visuals { display: flex; gap: 4px; }
.visuals button {
  height: var(--tap);
  padding: 0 14px;
  border-radius: 999px;
  color: var(--faint);
  font-size: 14.5px;
  transition: color 180ms;
}
.visuals button[aria-checked="true"] { color: var(--fg); }
.visuals button[aria-checked="true"]::after {
  content: "";
  display: block;
  width: 4px;
  height: 4px;
  margin: 3px auto 0;
  border-radius: 50%;
  background: currentColor;
}
.renderer-note { margin: -6px 0 0; font-size: 12.5px; color: var(--faint); max-width: 40ch; }

.custom { display: grid; grid-template-columns: repeat(4, auto); gap: 8px 14px; justify-content: center; max-width: 100%; }
@media (max-width: 520px) {
  .custom { grid-template-columns: repeat(2, auto); gap: 4px 28px; }
  /* The steppers draw the rhythm already; the glyph would push the dock into the form. */
  .dock.is-custom .glyph { display: none; }
}
.stepper { display: grid; grid-template-columns: 34px 3.2ch 34px; grid-template-rows: auto auto; align-items: center; justify-items: center; }
.stepper-label { grid-column: 1 / -1; font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.08em; }
.stepper output { font-variant-numeric: tabular-nums; font-size: 17px; }
.step-btn { width: 34px; height: 40px; color: var(--dim); font-size: 20px; border-radius: 10px; }
.step-btn:active { background: var(--wash); }

/* ---- the rail: wide screens list every technique ---- */
.rail { display: none; }

/* ---- the session ---- */
.session { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
.cue {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(19% + var(--safe-bottom));
  margin: 0;
  text-align: center;
  font-size: clamp(30px, 7.4vw, 46px);
  font-weight: 300;
  letter-spacing: 0.04em;
  opacity: 0.92;
  transition: opacity 420ms var(--ease);
}
.cue.swap { opacity: 0; transition-duration: 160ms; }
.count {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(19% - 30px + var(--safe-bottom));
  margin: 0;
  text-align: center;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  min-height: 1.4em;
}
.session-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(22px + var(--safe-bottom));
  display: grid;
  justify-items: center;
  gap: 2px;
  color: var(--faint);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.hint { transition: opacity 1.2s var(--ease); }
.hint.gone { opacity: 0; }
.paused {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 22px;
  background: var(--scrim);
  pointer-events: auto;
}
.paused-title { margin: 0; font-size: 22px; font-weight: 400; letter-spacing: 0.04em; }
.paused-actions { display: flex; gap: 12px; }

/* ---- the still pacer (reduced motion) ---- */
.still { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; padding-bottom: 30vh; }
.still-ring { width: min(62vw, 300px); height: auto; overflow: visible; }
.still-track { fill: none; stroke: var(--line); stroke-width: 1.5; }
.still-fill { fill: var(--link); opacity: 0.12; transform-origin: 100px 100px; }
.still-arc { fill: none; stroke: var(--fg); stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 0 100; transform: rotate(-90deg); transform-origin: 100px 100px; opacity: 0.8; }

/* ---- sheets ---- */
.sheet {
  border: 0;
  padding: 0;
  color: var(--fg);
  background: var(--sheet);
  width: 100%;
  max-width: 100%;
  max-height: min(86dvh, 760px);
  margin: auto 0 0;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  display: none;
  flex-direction: column;
}
.sheet[open] { display: flex; }
.sheet::backdrop { background: var(--scrim); }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 10px 6px 24px;
}
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.sheet-close { font-size: 26px; font-weight: 300; }
.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 24px calc(28px + var(--safe-bottom));
  -webkit-user-select: text;
  user-select: text;
}
.sheet-body h3 { margin: 22px 0 6px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); }
.sheet-body p { margin: 0 0 10px; max-width: 62ch; }
.sheet-body .lede { font-size: 17px; }
.sheet-body .muted { color: var(--dim); }
.sheet-body .caution { border-left: 2px solid var(--ev-limited); padding: 2px 0 2px 12px; color: var(--fg); }
.sheet-body a { color: var(--link); text-underline-offset: 2px; }
.studies { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.studies li { font-size: 14.5px; color: var(--dim); }
.studies .study-design { color: var(--fg); }
.studies .study-strength { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 18px; }
.stat { padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; }
.stat b { display: block; font-size: 26px; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--dim); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 92px; margin: 6px 0 4px; }
.week-bar { display: grid; gap: 6px; justify-items: center; height: 100%; align-content: end; }
.week-bar i { display: block; width: 100%; max-width: 26px; border-radius: 6px; background: var(--link); opacity: 0.75; min-height: 3px; }
.week-bar i.empty { background: var(--line); opacity: 1; }
.week-bar span { font-size: 12px; color: var(--faint); }
.sessions { list-style: none; margin: 0; padding: 0; }
.sessions li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; }
.sessions li span:last-child { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.setting:first-child { border-top: 0; }
.setting-label { display: grid; }
.setting-label small { color: var(--dim); font-size: 13.5px; }
.switch {
  width: 52px;
  height: 32px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  flex: none;
  transition: background-color 200ms;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 260ms var(--ease);
}
.switch[aria-checked="true"] { background: var(--ev-moderate); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.setting .seg { flex: none; }
.setting .seg button { min-width: 0; height: 36px; font-size: 14.5px; }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; margin: 4px 0 0; }
.keys dt { text-align: right; }
.keys kbd { display: inline-block; min-width: 28px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 7px; font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; }
.keys dd { margin: 0; color: var(--dim); align-self: center; }

.done-body { text-align: center; }
.done .sheet-body { padding-top: 26px; text-align: center; }
.done h2 { margin: 0 0 6px; font-size: 24px; font-weight: 500; }
.done .stats { text-align: left; }
.done-actions { display: flex; gap: 12px; justify-content: center; margin-top: 8px; }

.stats-overlay {
  position: fixed;
  left: calc(10px + var(--safe-left));
  bottom: calc(10px + var(--safe-bottom));
  z-index: 9;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--dim);
  background: var(--glass);
  padding: 6px 9px;
  border-radius: 8px;
  pointer-events: none;
  white-space: pre;
}

/* ---- wide screens: the rail lists every technique, the dock sits under the form ---- */
@media (min-width: 960px) and (min-height: 560px) {
  .rail {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--rail);
    z-index: 2;
    padding: calc(76px + var(--safe-top)) 16px 24px calc(16px + var(--safe-left));
    background: var(--glass);
    -webkit-backdrop-filter: blur(22px);
    backdrop-filter: blur(22px);
    border-right: 1px solid var(--line);
  }
  .top { width: var(--rail); right: auto; }
  .top .tools { position: fixed; right: calc(14px + var(--safe-right)); top: calc(10px + var(--safe-top)); }
  .rail-title { margin: 0 12px 10px; font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.12em; color: var(--faint); }
  .rail-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; overflow-y: auto; }
  .rail-item {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 3px 10px;
    padding: 12px 12px;
    border-radius: 14px;
    text-align: left;
    transition: background-color 160ms;
  }
  .rail-item[aria-current="true"] { background: var(--wash); }
  .rail-item b { font-weight: 500; }
  .rail-item small { grid-column: 1; color: var(--dim); font-size: 13.5px; font-variant-numeric: tabular-nums; }
  .rail-item .evidence { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 12px; padding: 3px 9px 3px 8px; color: var(--dim); }
  .rail-about { margin: 14px 12px 0; justify-self: start; text-align: left; }
  .dock {
    left: var(--rail);
    background: none;
    padding-bottom: calc(30px + var(--safe-bottom));
  }
  .dock .step { visibility: hidden; }
  .sheet {
    margin: auto;
    width: min(620px, calc(100vw - 48px));
    border-radius: 22px;
    max-height: min(82vh, 780px);
  }
  .still { left: var(--rail); }
  body.in-session .still { left: 0; }
}
@media (hover: hover) {
  .icon-btn:hover { color: var(--fg); }
  .rail-item:hover { background: var(--wash); }
  .visuals button:hover { color: var(--dim); }
  .seg button:hover:not([aria-checked="true"]) { color: var(--fg); }
}

/* Short phones: the dock gives up the glyph before it crowds the form. */
@media (max-height: 700px) and (max-width: 959px) {
  .glyph { display: none; }
  .tech-name { font-size: 26px; }
  .dock { gap: 11px; }
}
@media (max-height: 600px) and (max-width: 959px) {
  .tech-meta { display: none; }
}

/* Coarse pointers: every control at least the touch size. This block stays
   LAST so it outranks the base rules above (equal specificity, source order). */
@media (pointer: coarse) {
  .seg button { height: var(--tap); }
  .step-btn { height: var(--tap); width: var(--tap); }
  .stepper { grid-template-columns: var(--tap) 3.2ch var(--tap); }
  .setting .seg button { height: var(--tap); }
  .text-btn { padding: 12px 4px; margin: -12px 0; }
}
