/* Lagrange Points — one dark "instrument" theme. The arrows are the brightest
   thing on screen; everything else stays quiet. Tokens mirror js/theme.js. */

:root {
  --bg: #0b1120;
  --surface: rgba(18, 26, 43, 0.92);
  --surface-solid: #121a2b;
  --surface-2: #19233a;
  --border: #223049;
  --border-strong: #33425c;
  --guide: #33425c;
  --text: #e8edf5;
  --text-2: #9aa8bf;
  --text-3: #7385a0;
  --sun: #ffc24a;
  --earth: #4da8ff;
  --spin: #ff5e8a;
  --leftover: #ffffff;
  --coriolis: #2dd4bf;
  --radius: 14px;
  --gap: 16px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --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;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  isolation: isolate;
}

button,
input,
output {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- canvas */

#scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}

#scene:focus-visible {
  outline: 2px solid var(--border-strong);
  outline-offset: -2px;
}

body.dragging #scene {
  cursor: grabbing;
}

body.panning #scene {
  cursor: move;
}

/* -------------------------------------------------------------- masthead */

.masthead {
  position: absolute;
  top: calc(var(--gap) + var(--safe-top));
  left: calc(var(--gap) + var(--safe-left));
  max-width: 420px;
  pointer-events: none;
  z-index: 5;
}

.masthead h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.question {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 15px;
}

/* ---------------------------------------------------- top-right HUD block */

.hud {
  position: absolute;
  top: calc(var(--gap) + var(--safe-top));
  right: calc(var(--gap) + var(--safe-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.tracker-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tracker {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.slot {
  width: 36px;
  height: 28px;
  padding: 0;
  border: 1px dashed var(--text-3);
  border-radius: 8px;
  background: transparent;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: default;
  transition:
    background-color 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.slot.is-shown {
  border-style: solid;
  color: var(--text-2);
  cursor: pointer;
}

.slot.is-found {
  border: 1px solid var(--text);
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
}

.slot.is-active {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--text-2);
}

.slot.pop {
  animation: pop 420ms ease;
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

.tracker.pulse {
  animation: nudge 700ms ease;
}

@keyframes nudge {
  0%,
  100% {
    transform: none;
  }
  30% {
    transform: translateY(-2px);
  }
  60% {
    transform: translateY(1px);
  }
}

.text-btn {
  min-height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.text-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.icon-btn.small {
  width: 28px;
  height: 28px;
  font-size: 18px;
}

.status {
  margin: 2px 0 0;
  min-height: 26px;
  font-size: 19px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  text-align: right;
  white-space: nowrap;
}

.status .status-sub {
  color: var(--text-2);
  font-weight: 500;
}

.status.is-balanced {
  color: var(--leftover);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: 420px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.chip:hover,
.chip[aria-pressed="true"] {
  color: var(--text);
  border-color: var(--border-strong);
}

.sw {
  display: inline-block;
  width: 16px;
  height: 3px;
  border-radius: 2px;
}

.sw-sun {
  background: var(--sun);
}
.sw-earth {
  background: var(--earth);
}
.sw-spin {
  background: repeating-linear-gradient(90deg, var(--spin) 0 6px, transparent 6px 9px);
}
.sw-net {
  background: var(--leftover);
  height: 3.5px;
}

.legend-note {
  max-width: 300px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
}

.c-sun {
  color: var(--sun);
}
.c-earth {
  color: var(--earth);
}
.c-spin {
  color: var(--spin);
}

/* --------------------------------------------------------------- numbers */

.numbers {
  width: 260px;
  padding: 10px 12px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
}

.numbers-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.numbers h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
}

.numbers dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  margin: 0;
}

.numbers dt {
  color: var(--text-2);
}

.numbers dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.numbers-foot {
  margin: 8px 0 0;
  color: var(--text-3);
  font-size: 12px;
}

/* ------------------------------------------------------------------ dock */

.dock {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gap) + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(740px, calc(100vw - 2 * var(--gap) - 112px));
  padding: 10px 16px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
}

.coach {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  /* Two caption lines always fit, so the dock (and the framed scene) does
     not jump when the caption changes length. */
  min-height: 50px;
}

.chapters {
  display: flex;
  gap: 2px;
}

.chapters button {
  position: relative;
  width: 18px;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.chapters button::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background-color 160ms ease;
}

.chapters button:hover::before {
  background: var(--text-3);
}

.chapters button.is-done::before {
  background: var(--text-2);
}

.chapters button[aria-current="step"]::before {
  background: var(--text);
  box-shadow: 0 0 0 3px var(--surface-solid), 0 0 0 4px var(--text-2);
}

.coach-body {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.caption {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
  color: var(--text);
  text-wrap: pretty;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

.caption .muted,
.muted {
  color: var(--text-2);
}

.caption em {
  font-style: italic;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  flex: none;
  max-width: 64%;
}

.chips:empty {
  display: none;
}

.action {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.action:hover {
  background: rgba(255, 255, 255, 0.06);
}

.action.primary {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

.action.primary:hover {
  background: #fff;
}

.action[aria-pressed="true"] {
  border-color: var(--text);
}

.coach.enter .caption {
  animation: fade-in 260ms ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* -------------------------------------------------------------- mass row */

.mass-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.round-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.round-btn svg {
  width: 12px;
  height: 12px;
  fill: var(--text);
}

.round-btn .icon-pause,
.round-btn.is-playing .icon-play {
  display: none;
}

.round-btn.is-playing .icon-pause {
  display: block;
}

.round-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.mass-label {
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.rail {
  --thumb: 18px;
  position: relative;
  height: 44px;
  min-width: 0;
}

.rail input[type="range"] {
  position: absolute;
  inset: 0 0 auto 0;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  touch-action: pan-y;
}

.rail input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
}

.rail input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
}

.rail input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: -7px;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 1px var(--text-2);
}

.rail input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 1px var(--text-2);
}

.rail input[type="range"]:focus-visible {
  outline: none;
}

.rail input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text);
}

.ticks {
  position: absolute;
  left: calc(var(--thumb) / 2);
  right: calc(var(--thumb) / 2);
  top: 13px;
  height: 30px;
  pointer-events: none;
}

.tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 3px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
}

.tick::before {
  content: "";
  width: 1px;
  height: 7px;
  margin-bottom: 4px;
  background: var(--text-3);
}

.tick:hover,
.tick.is-current {
  color: var(--text);
}

.tick.is-current::before {
  background: var(--text);
}

.tick.routh {
  color: var(--text-3);
}

.tick.routh::before {
  width: 0;
  height: 9px;
  border-left: 1px dashed var(--spin);
  background: none;
}

.tick .tick-label[hidden] {
  display: none;
}

.mass-value {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 92px;
  line-height: 1.1;
}

.mass-value span {
  font-size: 19px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.mass-value small {
  margin-top: 2px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

/* ------------------------------------------------------------ menu, fit */

.menu-btn {
  position: absolute;
  left: calc(var(--gap) + var(--safe-left));
  bottom: calc(var(--gap) + var(--safe-bottom));
  width: 44px;
  height: 44px;
  font-size: 20px;
  z-index: 11;
}

.menu {
  position: absolute;
  left: calc(var(--gap) + var(--safe-left));
  bottom: calc(var(--gap) + var(--safe-bottom) + 52px);
  width: 250px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-solid);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 30;
}

.menu[hidden] {
  display: none;
}

.menu-title {
  margin: 4px 8px 6px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.menu hr {
  margin: 6px 4px;
  border: 0;
  border-top: 1px solid var(--border);
}

.menu > button,
.menu-layers label {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.menu > button:hover,
.menu-layers label:hover {
  background: rgba(255, 255, 255, 0.06);
}

.menu-layers input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--text);
}

.menu-layers label.is-locked {
  color: var(--text-3);
  cursor: not-allowed;
}

.fit-btn {
  position: absolute;
  right: calc(var(--gap) + var(--safe-right));
  bottom: calc(var(--gap) + var(--safe-bottom));
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  z-index: 11;
}

.toast {
  position: absolute;
  left: 50%;
  top: calc(var(--gap) + var(--safe-top) + 56px);
  transform: translateX(-50%);
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-solid);
  color: var(--text);
  font-size: 13px;
  z-index: 40;
}

/* -------------------------------------------------------------- note card */

.card {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gap) + var(--safe-bottom) + var(--dock-h, 120px) + 10px);
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  max-height: 45vh;
  overflow-y: auto;
  padding: 14px 44px 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-solid);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  font-size: 14px;
  line-height: 1.5;
  z-index: 20;
}

.card[hidden] {
  display: none;
}

.card-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

.card-body p {
  margin: 0 0 8px;
}

.card-body p:last-child {
  margin-bottom: 0;
}

.card-body .math {
  display: block;
  margin: 6px 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
}

.chip-hold {
  border-style: dashed;
}

.chip-hold.is-held {
  color: var(--bg);
  background: var(--text);
  border-color: var(--text);
}

/* ------------------------------------------------------------------ help */

.help {
  width: min(560px, calc(100vw - 32px));
  max-height: min(80vh, 760px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.help::backdrop {
  background: rgba(5, 8, 16, 0.6);
}

.help-inner {
  padding: 18px 20px 20px;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.help h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}

.help h3 {
  margin: 18px 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.help p {
  margin: 10px 0 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.help p.muted {
  color: var(--text-2);
}

.keys {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 13px;
}

.keys dt {
  white-space: nowrap;
}

.keys dd {
  margin: 0;
  color: var(--text-2);
}

kbd {
  display: inline-block;
  min-width: 22px;
  margin-right: 2px;
  padding: 2px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
}

.noscript {
  position: absolute;
  inset: 40% 0 auto;
  text-align: center;
  color: var(--text-2);
}

.phone-only {
  display: none;
}

/* --------------------------------------------------------------- tablets */

@media (max-width: 1023px) {
  .dock {
    width: calc(100vw - 2 * var(--gap) - 112px);
  }

  .masthead {
    max-width: 320px;
  }

  .question {
    font-size: 14px;
  }
}

/* ----------------------------------------------------------------- phone */

body.is-phone {
  --gap: 10px;
}

body.is-phone .masthead {
  top: calc(8px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  max-width: calc(100vw - 230px);
}

body.is-phone .masthead h1 {
  font-size: 17px;
}

body.is-phone .question {
  display: none;
}

body.is-phone .hud {
  top: calc(8px + var(--safe-top));
  right: calc(8px + var(--safe-right));
  gap: 4px;
}

body.is-phone .tracker-row {
  gap: 4px;
}

body.is-phone .tracker {
  gap: 4px;
}

body.is-phone .slot {
  width: 30px;
  height: 26px;
  font-size: 12px;
}

body.is-phone #show-all,
body.is-phone #help-btn,
body.is-phone .legend,
body.is-phone .desktop-only {
  display: none;
}

body.is-phone .phone-only {
  display: inline-grid;
}

body.is-phone #menu-btn-top {
  width: 36px;
  height: 36px;
  font-size: 18px;
}

body.is-phone .status {
  position: fixed;
  top: calc(34px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  font-size: 15px;
  min-height: 20px;
  text-align: left;
}

body.is-phone .numbers {
  width: min(280px, calc(100vw - 20px));
}

body.is-phone .dock {
  left: 0;
  right: 0;
  bottom: 0;
  transform: none;
  width: auto;
  padding: 8px 14px calc(8px + var(--safe-bottom));
  border-width: 1px 0 0;
  border-radius: 16px 16px 0 0;
}

body.is-phone .coach {
  grid-template-columns: 1fr;
  gap: 4px;
}

body.is-phone .chapters {
  justify-content: center;
  height: 16px;
  align-items: center;
}

body.is-phone .chapters button {
  height: 16px;
  width: 20px;
}

body.is-phone .coach-body {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-height: 40px;
}

body.is-phone .caption {
  font-size: 14px;
}

body.is-phone .chips {
  max-width: none;
  justify-content: flex-start;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

body.is-phone .chips::-webkit-scrollbar {
  display: none;
}

body.is-phone .action {
  height: 36px;
  padding: 0 12px;
}

body.is-phone .mass-row {
  grid-template-columns: auto 1fr auto;
  gap: 10px;
}

body.is-phone .mass-label {
  display: none;
}

body.is-phone .round-btn {
  width: 40px;
  height: 40px;
}

body.is-phone .rail {
  height: 46px;
}

body.is-phone .rail input[type="range"] {
  height: 30px;
}

body.is-phone .ticks {
  top: 17px;
}

body.is-phone .mass-value {
  min-width: 76px;
}

body.is-phone .mass-value span {
  font-size: 17px;
}

body.is-phone .menu {
  left: auto;
  right: calc(8px + var(--safe-right));
  top: calc(48px + var(--safe-top));
  bottom: auto;
}

body.is-phone .fit-btn {
  bottom: auto;
  top: calc(60px + var(--safe-top));
  right: calc(10px + var(--safe-right));
  height: 32px;
}

body.is-phone .toast {
  top: calc(64px + var(--safe-top));
}

/* Phone landscape: short screens keep the dock compact. */
@media (max-height: 480px) {
  .masthead .question {
    display: none;
  }

  .dock {
    padding: 6px 12px;
  }

  .coach {
    min-height: 36px;
  }

  .caption {
    font-size: 13px;
  }
}

/* --------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* ------------------------------------------------------------- language */

.lang-btn {
  min-width: 32px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ------------------------------------------------------ chapter dots, names */

.chapters button {
  width: 24px;
  height: 28px;
}

.chapters button::before {
  background: var(--text-3);
  opacity: 0.55;
}

.chapters button.is-done::before {
  opacity: 1;
}

.chapters button[aria-current="step"]::before {
  opacity: 1;
}

.chapter-name {
  display: none;
  margin: 0;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

@media (pointer: coarse) {
  .chapters button {
    width: 34px;
    height: 36px;
  }

  .tick {
    min-width: 32px;
    min-height: 32px;
  }
}

body.is-phone .chapter-name {
  display: block;
}

/* ------------------------------------------------------------- focus, misc */

#scene:focus-visible {
  outline: 2px solid var(--text-3);
  outline-offset: -2px;
}

.toast {
  max-width: calc(100vw - 32px);
  overflow-wrap: anywhere;
  text-align: center;
}

.tick.routh::before {
  border-left-color: var(--text-3);
}

.help-head {
  position: sticky;
  top: -18px;
  z-index: 1;
  margin: -18px -20px 0;
  padding: 18px 20px 8px;
  background: var(--surface-solid);
}

.numbers {
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}

/* The explanation card sits on the empty left side on wide screens, so it
   never covers the loop it explains. */
@media (min-width: 1024px) {
  body:not(.is-phone):not(.is-compact) .card {
    left: calc(var(--gap) + var(--safe-left));
    top: 96px;
    bottom: auto;
    transform: none;
    width: 380px;
    max-height: calc(100vh - 96px - var(--dock-h, 120px) - 40px);
  }
}

/* ------------------------------------------- compact desktop (small / 200%) */

body.is-compact .question,
body.is-compact .legend,
body.is-compact .legend-note {
  display: none;
}

body.is-compact .hud {
  top: calc(10px + var(--safe-top));
  gap: 4px;
}

body.is-compact .masthead {
  top: calc(10px + var(--safe-top));
}

body.is-compact .masthead h1 {
  font-size: 17px;
}

body.is-compact .status {
  position: fixed;
  top: calc(36px + var(--safe-top));
  left: calc(16px + var(--safe-left));
  min-height: 20px;
  font-size: 15px;
  text-align: left;
}

/* ------------------------------------------------ phone: numbers panel */

body.is-phone .numbers {
  position: fixed;
  top: calc(58px + var(--safe-top));
  right: calc(8px + var(--safe-right));
  max-height: 42vh;
}

/* ---------------------------- phone landscape: dock as a right-hand column */

body.is-landscape {
  --col: min(300px, 40vw);
}

body.is-landscape .dock {
  transform: none;
  top: calc(6px + var(--safe-top));
  bottom: calc(6px + var(--safe-bottom));
  right: calc(6px + var(--safe-right));
  left: auto;
  width: var(--col);
  padding: 8px 12px;
  border-width: 1px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  overflow-y: auto;
}

body.is-landscape .coach {
  min-height: 0;
}

body.is-landscape .caption {
  font-size: 13px;
  -webkit-line-clamp: 5;
  line-clamp: 5;
}

body.is-landscape .chips {
  flex-wrap: wrap;
  overflow: visible;
}

body.is-landscape .mass-row {
  grid-template-columns: auto 1fr;
  margin-top: 0;
}

body.is-landscape .mass-value {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

body.is-landscape .hud,
body.is-landscape .menu,
body.is-landscape .numbers {
  right: calc(var(--col) + 14px + var(--safe-right));
}

body.is-landscape .fit-btn {
  top: auto;
  bottom: calc(10px + var(--safe-bottom));
  right: calc(var(--col) + 14px + var(--safe-right));
}

body.is-landscape .card {
  left: calc(8px + var(--safe-left));
  right: auto;
  bottom: auto;
  top: calc(52px + var(--safe-top));
  transform: none;
  width: calc(100vw - var(--col) - 36px);
  max-height: calc(100vh - 64px);
}

body.is-landscape .coach {
  grid-template-columns: 1fr;
  gap: 6px;
}

body.is-landscape .chapters {
  justify-content: center;
}

body.is-landscape .chapter-name {
  display: block;
}

body.is-landscape .coach-body {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

body.is-landscape .chips {
  max-width: none;
  justify-content: flex-start;
}

body.is-landscape .mass-label,
body.is-landscape .masthead h1,
body.is-landscape #show-all,
body.is-landscape #help-btn,
body.is-landscape #lang-btn {
  display: none;
}

body.is-landscape .status {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: calc(16px + var(--safe-left));
  min-height: 20px;
  font-size: 15px;
  text-align: left;
}

body.is-landscape .hud {
  top: calc(8px + var(--safe-top));
}
