:root {
  color-scheme: light;
  --paper: #f2f3f1;
  --surface: #ffffff;
  --ink: #171a18;
  --muted: #676d69;
  --line: #c8cdca;
  --line-strong: #8f9691;
  --board: #202421;
  --floor: #aeb5b0;
  --floor-alt: #a7aea9;
  --wall: #3d443f;
  --wall-edge: #575f59;
  --player: #ed5b4d;
  --player-dark: #7e2923;
  --echo: #29a8c1;
  --echo-dark: #116474;
  --crate: #d8a33f;
  --crate-dark: #6e4d19;
  --goal: #3e9160;
  --door: #efcf61;
  --focus: #126e82;
  --shadow: rgba(22, 28, 24, 0.18);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-synthesis: none;
}

/* Final mechanism art: normalized canvases let the visible frames meet the
   tile boundary while preserving the floor beneath an open causal gate. */
html body[data-experience="yw01-v2"] .tile.sync-gate.closed::before,
html body[data-experience="yw01-v2"] .tile.sync-gate.open::before {
  inset: 0;
  z-index: 2;
  width: auto;
  height: auto;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

html body[data-experience="yw01-v2"] .tile.sync-gate.closed::before {
  background-image: url("assets/yw-mechanisms/causal-gate-closed-final.png");
}

html body[data-experience="yw01-v2"] .tile.sync-gate.open::before {
  background-image: url("assets/yw-mechanisms/causal-gate-open-final.png");
}

html body[data-experience="yw01-v2"] .tile.sync-gate::after {
  display: none;
}

html body[data-experience="yw01-v2"] .tile.exit.locked::before,
html body[data-experience="yw01-v2"] .tile.exit.ready::before {
  inset: -7% 0 0;
  z-index: 2;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

html body[data-experience="yw01-v2"] .tile.exit.locked::before {
  background-image: url("assets/yw-mechanisms/archive-exit-locked-v3.png");
}

html body[data-experience="yw01-v2"] .tile.exit.ready::before {
  background-image: url("assets/yw-mechanisms/archive-exit-ready-v4.png");
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

body {
  min-width: 320px;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(18, 110, 130, 0.45);
  outline-offset: 3px;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 76px;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: max-content;
}

.archive-code {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--door);
  font-size: 12px;
  font-weight: 800;
}

.brand h1,
.brand p,
.stage-heading h2,
.stage-heading p,
.time-heading h3,
.time-heading p,
.completion h3,
.completion p,
.statusbar p,
.rule-note p {
  margin: 0;
}

.brand h1 {
  font-size: 24px;
  line-height: 1.05;
  font-weight: 850;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.topbar-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.level-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.level-tab {
  position: relative;
  width: 36px;
  height: 34px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.level-tab:hover {
  background: #e2e5e2;
  color: var(--ink);
}

.level-tab.active {
  background: var(--ink);
  color: white;
}

.level-tab.completed::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--goal);
}

.level-tab.active.completed::after {
  background: var(--door);
}

.icon-button {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--ink);
  background: #e9ebe8;
}

.workspace {
  width: min(100%, 1480px);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
}

.stage-panel {
  min-width: 0;
  min-height: 0;
  padding: 22px 28px 20px;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  gap: 18px;
}

.stage-heading {
  min-width: 0;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.level-kicker {
  margin-bottom: 5px !important;
  color: var(--player-dark);
  font-size: 11px;
  font-weight: 800;
}

.stage-heading h2 {
  font-size: 28px;
  line-height: 1.1;
}

.objective {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  text-align: right;
}

.objective svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  color: var(--goal);
}

.board-frame {
  position: relative;
  min-height: 260px;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow: hidden;
  border: 1px solid #0f1210;
  border-radius: 6px;
  background: var(--board);
  box-shadow: 0 15px 40px var(--shadow);
}

.board-frame::before,
.board-frame::after {
  content: "";
  position: absolute;
  background: #515852;
  opacity: 0.45;
}

.board-frame::before {
  width: 1px;
  height: 100%;
  left: 14px;
  top: 0;
}

.board-frame::after {
  width: 100%;
  height: 1px;
  left: 0;
  bottom: 14px;
}

.board {
  --cols: 9;
  --rows: 5;
  --ratio: 1.8;
  position: relative;
  z-index: 1;
  width: min(100%, 600px);
  aspect-ratio: var(--ratio);
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  border: 2px solid #101310;
  border-radius: 3px;
  background: #111411;
  overflow: hidden;
  user-select: none;
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.tile.floor {
  background: var(--floor);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.tile.floor.alt {
  background: var(--floor-alt);
}

.tile.wall {
  background: var(--wall);
  border: 1px solid #2b302c;
  box-shadow: inset 0 4px 0 var(--wall-edge);
}

.tile.wall::after {
  content: "";
  position: absolute;
  right: 7%;
  bottom: 9%;
  width: 32%;
  height: 2px;
  background: #272c28;
}

.tile.goal::before {
  content: "";
  position: absolute;
  inset: 22%;
  border: 3px solid var(--goal);
  transform: rotate(45deg);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.3);
}

.tile.goal.active::before {
  background: rgba(62, 145, 96, 0.55);
  border-color: #d9f1e1;
}

.tile.plate::before,
.tile.plate::after {
  content: "";
  position: absolute;
  border-radius: 50%;
}

.tile.plate::before {
  inset: 21%;
  border: 3px solid #59615b;
  background: #7c847e;
  box-shadow: inset 0 0 0 4px #969e98;
}

.tile.plate::after {
  inset: 38%;
  background: #505751;
}

.tile.plate.active::before {
  border-color: #a34b39;
  background: var(--player);
  box-shadow: inset 0 0 0 4px #f6a097;
}

.tile.time-node::before,
.tile.time-node::after {
  content: "";
  position: absolute;
}

.tile.time-node::before {
  inset: 22%;
  border: 3px solid var(--echo-dark);
  background: #dff5f9;
  box-shadow: inset 0 0 0 4px rgba(41, 168, 193, 0.28);
  transform: rotate(45deg);
}

.tile.time-node::after {
  content: "↶";
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--echo-dark);
  font-size: 18px;
  font-weight: 900;
}

.tile.time-node.armed::before {
  animation: node-ready 900ms ease-in-out infinite alternate;
}

.tile.time-node.spent.inactive::before {
  border-style: dashed;
  animation: none;
}

.tile.time-node.active::before {
  border-color: #755e18;
  background: var(--door);
  box-shadow: inset 0 0 0 4px #fff0a6;
  animation: none;
}

.tile.time-node.active::after {
  content: "✓";
  color: #594712;
}

@keyframes node-ready {
  from { opacity: 0.62; }
  to { opacity: 1; }
}

.tile.door {
  background: #717a74;
}

.tile.door::before,
.tile.door::after {
  content: "";
  position: absolute;
  top: 3%;
  bottom: 3%;
  width: 23%;
  border: 2px solid #755e18;
  background: var(--door);
  transition: transform 160ms ease, opacity 160ms ease;
}

.tile.door::before {
  left: 14%;
}

.tile.door::after {
  right: 14%;
}

.tile.door.open::before {
  transform: translateX(-74%);
  opacity: 0.28;
}

.tile.door.open::after {
  transform: translateX(74%);
  opacity: 0.28;
}

.tile.exit::before {
  content: "↗";
  position: absolute;
  inset: 12%;
  display: grid;
  place-items: center;
  border: 2px solid #29342d;
  background: #e9eee9;
  color: #29342d;
  font-size: 12px;
  font-weight: 900;
}

.tile.exit.ready::before {
  border-color: #17552d;
  background: #d4edda;
  color: #17552d;
  box-shadow: inset 0 -5px 0 #8ec99d;
}

.entity,
.future-step {
  position: absolute;
  z-index: 4;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  display: grid;
  place-items: center;
  pointer-events: none;
}

.entity.box {
  z-index: 3;
}

.entity-inner {
  position: relative;
  display: grid;
  place-items: center;
}

.player .entity-inner,
.ghost .entity-inner {
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
}

.player .entity-inner {
  border: 3px solid white;
  background: var(--player);
  box-shadow: 0 3px 0 var(--player-dark), 0 5px 9px rgba(75, 25, 20, 0.3);
}

.player .entity-inner::before,
.ghost .entity-inner::before {
  content: "";
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 9px 0 4px currentColor;
}

.player .entity-inner::before {
  color: white;
}

.ghost .entity-inner {
  border: 2px dashed var(--echo);
  background: rgba(226, 250, 255, 0.78);
  color: var(--echo-dark);
  box-shadow: 0 0 0 2px rgba(41, 168, 193, 0.2);
}

.ghost.finished .entity-inner {
  background: rgba(226, 250, 255, 0.48);
  border-style: solid;
}

.ghost-id {
  position: absolute;
  right: -7px;
  top: -7px;
  min-width: 19px;
  height: 19px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  border: 2px solid #eafcff;
  border-radius: 50%;
  background: var(--echo-dark);
  color: white;
  font-size: 9px;
  font-weight: 850;
}

.box .entity-inner {
  width: 72%;
  aspect-ratio: 1;
  border: 3px solid var(--crate-dark);
  border-radius: 3px;
  background: var(--crate);
  color: var(--crate-dark);
  box-shadow: inset 0 0 0 4px #efc66e, 0 4px 0 rgba(66, 45, 12, 0.38);
}

.box .entity-inner::before,
.box .entity-inner::after {
  content: "";
  position: absolute;
  left: 14%;
  right: 14%;
  height: 3px;
  background: var(--crate-dark);
  transform-origin: center;
}

.box .entity-inner::before {
  transform: rotate(45deg);
}

.box .entity-inner::after {
  transform: rotate(-45deg);
}

.future-step {
  z-index: 2;
}

.future-step span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--echo-dark);
  border-radius: 50%;
  background: rgba(237, 252, 255, 0.82);
  color: var(--echo-dark);
  font-size: 10px;
  font-weight: 900;
}

.board.branching {
  animation: branch-flash 380ms ease;
}

@keyframes branch-flash {
  0% { opacity: 1; filter: none; }
  42% { opacity: 0.48; filter: saturate(0.3); }
  100% { opacity: 1; filter: none; }
}

.board-toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 26px;
  width: max-content;
  max-width: calc(100% - 48px);
  padding: 8px 12px;
  border-radius: 4px;
  background: rgba(20, 24, 21, 0.9);
  color: white;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 7px);
  transition: opacity 150ms ease, transform 150ms ease;
  pointer-events: none;
}

.board-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.completion[hidden] {
  display: none;
}

.completion {
  position: absolute;
  z-index: 12;
  width: min(410px, calc(100% - 36px));
  padding: 26px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 12px 12px 0 rgba(0, 0, 0, 0.22);
}

.completion > p {
  color: var(--goal);
  font-size: 11px;
  font-weight: 900;
}

.completion h3 {
  margin-top: 5px;
  font-size: 25px;
}

.completion-stats {
  margin: 20px 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.completion-stat {
  padding: 11px;
  background: white;
}

.completion-stat span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.completion-stat strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
}

.completion-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-command,
.secondary-command {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.secondary-command {
  border: 1px solid var(--line-strong);
  background: white;
}

.primary-command {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: white;
}

.control-deck {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 16px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 5px;
}

.move-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
}

.move-button:hover {
  border-color: var(--ink);
  background: #e2e5e2;
}

.move-button:active {
  transform: translateY(1px);
}

.move-up { grid-column: 2; grid-row: 1; }
.move-left { grid-column: 1; grid-row: 2; }
.move-wait { grid-column: 2; grid-row: 2; }
.move-right { grid-column: 3; grid-row: 2; }
.move-down { grid-column: 2; grid-row: 3; }

.move-down svg {
  transform: none;
}

.time-panel {
  min-width: 0;
  padding: 22px 22px 20px;
  border-left: 1px solid var(--line);
  background: #e6e9e6;
  overflow: auto;
}

.time-heading p {
  color: var(--echo-dark);
  font-size: 10px;
  font-weight: 900;
}

.time-heading h3 {
  margin-top: 4px;
  font-size: 21px;
}

.stability-strip {
  margin-top: 20px;
  padding: 13px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
}

.stability-strip span,
.stability-strip strong {
  display: block;
}

.stability-strip span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.stability-strip strong {
  margin-top: 3px;
  font-size: 15px;
}

.charge-meter {
  display: flex;
  gap: 5px;
}

.charge-pip {
  width: 27px;
  height: 9px;
  border: 1px solid #8c9490;
  border-radius: 2px;
  background: #bcc2be;
}

.charge-pip.filled {
  border-color: var(--echo-dark);
  background: var(--echo);
}

.charge-pip.node-charge.spent {
  border-color: #755e18;
  background: var(--door);
}

.timeline-section,
.echo-section {
  padding-top: 18px;
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.section-label strong {
  font-size: 11px;
}

.timeline {
  max-height: 270px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.timeline-item {
  position: relative;
  width: 100%;
  min-height: 43px;
  padding: 7px 8px 7px 33px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  width: 9px;
  height: 9px;
  border: 2px solid #7f8782;
  border-radius: 50%;
  background: #e6e9e6;
  transform: translateY(-50%);
}

.timeline-item:hover {
  background: rgba(255, 255, 255, 0.52);
}

.timeline-item.current {
  cursor: default;
}

.timeline-item.current::before {
  border-color: var(--player-dark);
  background: var(--player);
}

.timeline-item.selected {
  background: #d7f0f5;
  color: #064d5b;
}

.timeline-item.selected::before {
  border-color: var(--echo-dark);
  background: var(--echo);
}

.timeline-item.locked {
  color: #8a918d;
}

.timeline-main {
  min-width: 0;
}

.timeline-main strong,
.timeline-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-main strong {
  font-size: 11px;
}

.timeline-main span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.timeline-action {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  font-weight: 900;
}

.echo-list {
  min-height: 68px;
  border-top: 1px solid var(--line);
}

.echo-empty {
  min-height: 68px;
  display: grid;
  place-items: center;
  color: #8b928e;
  font-size: 11px;
}

.echo-row {
  padding: 10px 0;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 9px;
  border-bottom: 1px solid var(--line);
}

.echo-badge {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 2px solid var(--echo-dark);
  border-radius: 50%;
  background: #e2f8fc;
  color: var(--echo-dark);
  font-size: 10px;
  font-weight: 900;
}

.echo-meta {
  min-width: 0;
}

.echo-meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.echo-meta-line strong,
.echo-meta-line span {
  font-size: 9px;
}

.echo-meta-line span {
  color: var(--muted);
}

.action-lane {
  display: flex;
  gap: 3px;
  overflow: hidden;
}

.action-chip {
  flex: 0 0 auto;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  border: 1px solid #9acbd5;
  border-radius: 2px;
  background: #eaf9fc;
  color: var(--echo-dark);
  font-size: 10px;
  font-weight: 900;
}

.action-chip.done {
  border-color: #c8cdca;
  background: transparent;
  color: #a1a7a3;
}

.rule-note {
  margin-top: 18px;
  padding-top: 14px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 10px;
  border-top: 2px solid var(--ink);
}

.rule-note svg {
  width: 21px;
  height: 21px;
  color: var(--player-dark);
}

.rule-note p {
  color: #3d433f;
  font-size: 11px;
  line-height: 1.55;
  font-weight: 600;
}

.statusbar {
  min-height: 43px;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.legend-mark {
  width: 11px;
  height: 11px;
  display: inline-block;
}

.player-mark {
  border-radius: 50%;
  background: var(--player);
}

.echo-mark {
  border: 2px dashed var(--echo-dark);
  border-radius: 50%;
  background: #e2f8fc;
}

.box-mark {
  border: 2px solid var(--crate-dark);
  border-radius: 2px;
  background: var(--crate);
}

.plate-mark {
  border: 2px solid #59615b;
  border-radius: 50%;
  background: #8e9690;
}

.node-mark {
  border: 2px solid var(--echo-dark);
  background: #dff5f9;
  transform: rotate(45deg);
}

.statusbar p {
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .topbar-tools {
    width: 100%;
    justify-content: space-between;
  }

  .workspace {
    display: block;
  }

  .stage-panel {
    min-height: auto;
  }

  .time-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .timeline {
    max-height: 220px;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 10px 14px;
    gap: 10px;
  }

  .archive-code {
    width: 42px;
    height: 42px;
  }

  .brand h1 {
    font-size: 21px;
  }

  .level-tabs {
    min-width: 0;
    overflow-x: auto;
  }

  .level-tab {
    flex: 0 0 auto;
    width: 34px;
  }

  .stage-panel {
    padding: 17px 14px;
    grid-template-rows: auto auto auto;
    gap: 14px;
  }

  .stage-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .stage-heading h2 {
    font-size: 24px;
  }

  .objective {
    justify-content: flex-start;
    text-align: left;
  }

  .board-frame {
    min-height: 220px;
    padding: 10px;
  }

  .board-toast {
    bottom: 7px;
  }

  .tile.exit::before {
    font-size: 8px;
  }

  .ghost-id {
    right: -5px;
    top: -5px;
    min-width: 15px;
    height: 15px;
    border-width: 1px;
    font-size: 7px;
  }

  .future-step span {
    width: 19px;
    height: 19px;
    font-size: 8px;
  }

  .control-deck {
    align-items: stretch;
  }

  .dpad {
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
    gap: 4px;
  }

  .time-panel {
    padding: 20px 14px;
  }

  .statusbar {
    padding: 10px 14px;
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .statusbar p {
    text-align: left;
  }

  .completion {
    padding: 20px;
  }
}

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

/*
 * On-board movement coach
 *
 * The first six rooms are deliberately read at a glance.  A guide arrow is
 * positioned with the same left/top values as an entity (one tile per
 * `--cols`/`--rows` unit), so it remains aligned when the board is resized on
 * mobile.  Keep it above the floor and future-step preview, but below boxes
 * and actors so the route cue never hides a puzzle state.
 */
.guide-arrow,
.move-guide,
.path-arrow {
  position: absolute;
  z-index: 3;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  display: grid;
  place-items: center;
  pointer-events: none;
  user-select: none;
  color: #fffdf4;
  filter: drop-shadow(0 2px 0 rgba(14, 28, 20, 0.52));
  animation: guide-arrow-in 220ms ease-out both, guide-arrow-pulse 1300ms ease-in-out 220ms infinite;
}

/* A circular badge is easier to parse than a bare glyph on the small board. */
.guide-arrow > span,
.guide-arrow::before,
.move-guide > span,
.move-guide::before,
.path-arrow > span,
.path-arrow::before {
  width: clamp(20px, 58%, 34px);
  height: clamp(20px, 58%, 34px);
  display: grid;
  place-items: center;
  border: 2px solid #f6f0d4;
  border-radius: 50%;
  background: rgba(44, 91, 69, 0.94);
  box-shadow: 0 0 0 2px rgba(214, 191, 105, 0.48), inset 0 -3px 0 rgba(8, 34, 22, 0.4);
  color: #fffdf4;
  font-family: var(--font-display, system-ui, sans-serif);
  font-size: clamp(13px, 3.4vmin, 20px);
  font-weight: 900;
  line-height: 1;
}

/* When the route cue is authored as data-direction, no extra span is needed. */
.guide-arrow[data-direction]::before,
.move-guide[data-direction]::before,
.path-arrow[data-direction]::before {
  content: attr(data-arrow);
}

.guide-arrow[data-direction] > span,
.move-guide[data-direction] > span,
.path-arrow[data-direction] > span {
  display: none;
}

/* Directional classes also work without a data attribute. */
.guide-arrow.is-up > span,
.guide-arrow.is-down > span,
.guide-arrow.is-left > span,
.guide-arrow.is-right > span,
.guide-arrow.is-wait > span,
.guide-arrow.is-blocked > span,
.guide-arrow.is-current > span,
.move-guide.is-up > span,
.move-guide.is-down > span,
.move-guide.is-left > span,
.move-guide.is-right > span,
.move-guide.is-wait > span,
.move-guide.is-blocked > span,
.move-guide.is-current > span,
.path-arrow.is-up > span,
.path-arrow.is-down > span,
.path-arrow.is-left > span,
.path-arrow.is-right > span,
.path-arrow.is-wait > span,
.path-arrow.is-blocked > span,
.path-arrow.is-current > span,
.guide-arrow.is-echo > span,
.move-guide.is-echo > span,
.path-arrow.is-echo > span,
.guide-arrow.is-player > span,
.move-guide.is-player > span,
.path-arrow.is-player > span {
  display: none;
}

.guide-arrow.is-up::before,
.move-guide.is-up::before,
.path-arrow.is-up::before,
.guide-arrow[data-direction="up"]::before,
.move-guide[data-direction="up"]::before,
.path-arrow[data-direction="up"]::before {
  content: "↑";
}

.guide-arrow.is-down::before,
.move-guide.is-down::before,
.path-arrow.is-down::before,
.guide-arrow[data-direction="down"]::before,
.move-guide[data-direction="down"]::before,
.path-arrow[data-direction="down"]::before {
  content: "↓";
}

.guide-arrow.is-left::before,
.move-guide.is-left::before,
.path-arrow.is-left::before,
.guide-arrow[data-direction="left"]::before,
.move-guide[data-direction="left"]::before,
.path-arrow[data-direction="left"]::before {
  content: "←";
}

.guide-arrow.is-right::before,
.move-guide.is-right::before,
.path-arrow.is-right::before,
.guide-arrow[data-direction="right"]::before,
.move-guide[data-direction="right"]::before,
.path-arrow[data-direction="right"]::before {
  content: "→";
}

.guide-arrow.is-wait::before,
.move-guide.is-wait::before,
.path-arrow.is-wait::before,
.guide-arrow[data-direction="wait"]::before,
.move-guide[data-direction="wait"]::before,
.path-arrow[data-direction="wait"]::before {
  content: "·";
  font-size: 22px;
}

/* One-letter action codes are accepted as well, which keeps the guide coupled
 * to the same U/D/L/R/W vocabulary used by the keyboard and replay log. */
.guide-arrow[data-direction="U"]::before,
.move-guide[data-direction="U"]::before,
.path-arrow[data-direction="U"]::before { content: "↑"; }

.guide-arrow[data-direction="D"]::before,
.move-guide[data-direction="D"]::before,
.path-arrow[data-direction="D"]::before { content: "↓"; }

.guide-arrow[data-direction="L"]::before,
.move-guide[data-direction="L"]::before,
.path-arrow[data-direction="L"]::before { content: "←"; }

.guide-arrow[data-direction="R"]::before,
.move-guide[data-direction="R"]::before,
.path-arrow[data-direction="R"]::before { content: "→"; }

.guide-arrow[data-direction="W"]::before,
.move-guide[data-direction="W"]::before,
.path-arrow[data-direction="W"]::before {
  content: "·";
  font-size: 22px;
}

/* The optional label gives a short, local instruction without covering the HUD. */
.guide-arrow > small,
.move-guide > small,
.path-arrow > small {
  position: absolute;
  top: calc(50% + clamp(12px, 32%, 20px));
  max-width: 7ch;
  padding: 2px 4px;
  border: 1px solid rgba(246, 240, 212, 0.86);
  border-radius: 3px;
  background: rgba(14, 32, 23, 0.88);
  color: #f6f0d4;
  font-family: var(--font-code, ui-monospace, monospace);
  font-size: clamp(7px, 1.25vmin, 9px);
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
}

.guide-arrow.is-blocked::before,
.move-guide.is-blocked::before,
.path-arrow.is-blocked::before {
  content: "×";
  border-color: #ffd4ca;
  background: rgba(122, 47, 40, 0.94);
  color: #fff2ed;
}

.guide-arrow.is-current::before,
.move-guide.is-current::before,
.path-arrow.is-current::before {
  border-color: #fff4a3;
  background: var(--now-dark, #7e2923);
  box-shadow: 0 0 0 3px rgba(255, 242, 155, 0.28), inset 0 -3px 0 rgba(38, 20, 16, 0.45);
}

/* Route ownership stays visible after a rewind: gold is the current turn,
 * cyan is yesterday's replay. */
.guide-arrow.is-echo::before,
.move-guide.is-echo::before,
.path-arrow.is-echo::before {
  border-color: #dff8fc;
  background: var(--rewind-dark, #116474);
  box-shadow: 0 0 0 2px rgba(104, 221, 232, 0.34), inset 0 -3px 0 rgba(8, 43, 53, 0.46);
}

.guide-arrow.is-player::before,
.move-guide.is-player::before,
.path-arrow.is-player::before {
  border-color: #fff4a3;
  background: var(--brass-dark, #8a6d22);
}

/* Keep the cue on the actor's tile, but nudge the badge toward its intended
 * destination so the player sprite never hides the direction marker. */
.guide-arrow.is-up::before,
.move-guide.is-up::before,
.path-arrow.is-up::before { transform: translateY(-20%); }

.guide-arrow.is-down::before,
.move-guide.is-down::before,
.path-arrow.is-down::before { transform: translateY(20%); }

.guide-arrow.is-left::before,
.move-guide.is-left::before,
.path-arrow.is-left::before { transform: translateX(-20%); }

.guide-arrow.is-right::before,
.move-guide.is-right::before,
.path-arrow.is-right::before { transform: translateX(20%); }

/* Orientation rules provide the pseudo-element content; turn the badge back
 * on after the generic `::before` fallback hides it for span-authored cues. */
.guide-arrow.is-up::before,
.guide-arrow.is-down::before,
.guide-arrow.is-left::before,
.guide-arrow.is-right::before,
.guide-arrow.is-wait::before,
.guide-arrow.is-blocked::before,
.guide-arrow.is-current::before,
.guide-arrow.is-echo::before,
.guide-arrow.is-player::before,
.move-guide.is-up::before,
.move-guide.is-down::before,
.move-guide.is-left::before,
.move-guide.is-right::before,
.move-guide.is-wait::before,
.move-guide.is-blocked::before,
.move-guide.is-current::before,
.move-guide.is-echo::before,
.move-guide.is-player::before,
.path-arrow.is-up::before,
.path-arrow.is-down::before,
.path-arrow.is-left::before,
.path-arrow.is-right::before,
.path-arrow.is-wait::before,
.path-arrow.is-blocked::before,
.path-arrow.is-current::before,
.path-arrow.is-echo::before,
.path-arrow.is-player::before,
.guide-arrow[data-direction]::before,
.move-guide[data-direction]::before,
.path-arrow[data-direction]::before {
  display: grid;
}

@keyframes guide-arrow-in {
  from { opacity: 0; transform: scale(0.72); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes guide-arrow-pulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.06); }
}

@media (max-width: 620px) {
  .guide-arrow > span,
  .guide-arrow::before,
  .move-guide > span,
  .move-guide::before,
  .path-arrow > span,
  .path-arrow::before {
    width: clamp(16px, 66%, 25px);
    height: clamp(16px, 66%, 25px);
    border-width: 1px;
    box-shadow: 0 0 0 1px rgba(214, 191, 105, 0.42), inset 0 -2px 0 rgba(8, 34, 22, 0.4);
    font-size: clamp(11px, 3.8vmin, 16px);
  }

  .guide-arrow > small,
  .move-guide > small,
  .path-arrow > small {
    top: calc(50% + 14px);
    font-size: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .guide-arrow,
  .move-guide,
  .path-arrow {
    animation: none;
  }
}

/* The active guide sits on the actor's tile edge, above the actor but inside
 * the cell. This keeps directions and the level-five wait cue readable. */
.guide-arrow {
  z-index: 5;
  overflow: visible;
  filter: none;
  animation: guide-arrow-in 180ms ease-out both;
}

.guide-arrow::before {
  display: none !important;
  content: none !important;
}

.guide-arrow > small {
  display: none;
}

.guide-arrow > .guide-arrow__badge {
  position: absolute;
  top: 50%;
  left: 50%;
  width: clamp(20px, 38%, 30px);
  height: auto;
  aspect-ratio: 1;
  display: grid !important;
  place-items: center;
  border: 2px solid #fff4a3;
  border-radius: 50%;
  background: #8a6d22;
  box-shadow: 0 0 0 2px rgba(20, 34, 26, 0.7), 0 2px 0 rgba(20, 34, 26, 0.55);
  color: #fffdf4;
  transform: translate(-50%, -50%);
  animation: guide-badge-pulse 1200ms ease-in-out 180ms infinite;
}

.guide-arrow__badge svg {
  width: 64%;
  height: 64%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.guide-arrow.is-echo > .guide-arrow__badge {
  border-color: #dff8fc;
  background: #116474;
  color: #f1fdff;
  box-shadow: 0 0 0 2px rgba(20, 34, 26, 0.66), 0 0 0 4px rgba(104, 221, 232, 0.28);
}

.guide-arrow.is-up > .guide-arrow__badge {
  top: 2px;
  transform: translateX(-50%);
}

.guide-arrow.is-down > .guide-arrow__badge {
  top: auto;
  bottom: 2px;
  transform: translateX(-50%);
}

.guide-arrow.is-left > .guide-arrow__badge {
  left: 2px;
  transform: translateY(-50%);
}

.guide-arrow.is-right > .guide-arrow__badge {
  right: 2px;
  left: auto;
  transform: translateY(-50%);
}

.guide-arrow.is-wait > .guide-arrow__badge {
  top: 2px;
  right: 2px;
  left: auto;
  transform: none;
}

@keyframes guide-badge-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.28); }
}

#reset-button.guide-recovery {
  border-color: #e2bc55;
  color: #fff4a3;
  box-shadow: inset 0 0 0 1px rgba(226, 188, 85, 0.35);
  animation: guide-reset-pulse 1400ms ease-in-out infinite;
}

@keyframes guide-reset-pulse {
  0%, 100% { background-color: transparent; }
  50% { background-color: rgba(226, 188, 85, 0.16); }
}

@media (max-width: 620px) {
  .guide-arrow > .guide-arrow__badge {
    width: clamp(18px, 42%, 24px);
    height: auto;
    border-width: 1px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .guide-arrow,
  .guide-arrow > .guide-arrow__badge,
  #reset-button.guide-recovery {
    animation: none;
  }
}

/* Six-room calibration chapter */
body[data-chapter="6"] {
  --chapter-accent: #b45e68;
  --chapter-mark: "06";
}

.level-tab.locked,
.level-tab:disabled {
  cursor: not-allowed;
  border-color: #35463d;
  background: #19261f;
  color: #6f7d75;
  box-shadow: inset 0 -3px 0 #101a14;
  opacity: 0.58;
}

.level-tab.locked:hover,
.level-tab:disabled:hover {
  border-color: #35463d;
  background: #19261f;
  color: #6f7d75;
}

.phase-rail.single-line {
  grid-template-columns: minmax(0, 1fr);
}

.phase-rail.single-line li[data-phase="branch"],
.phase-rail.single-line li[data-phase="sync"],
.single-line-level .recording-section,
.single-line-level .echo-section,
.single-line-level .node-signal {
  display: none;
}

.tutorial-key {
  min-width: 76px;
  max-width: 190px;
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
}

.tutorial-skip[hidden] {
  display: none !important;
}

@media (max-width: 620px) {
  .app-shell,
  .workspace,
  .stage-panel,
  .time-panel,
  .statusbar {
    max-width: 100%;
    overflow-x: clip;
  }

  .tutorial-key {
    max-width: 105px;
    padding-inline: 7px;
    font-size: 9px;
  }
}

/* Automatic branch status */
.phase-card {
  position: relative;
  min-width: 230px;
  min-height: 142px;
  padding: 17px 38px 17px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid #8bbcc5;
  border-radius: 6px;
  background: #e8f7f9;
  color: #104e5b;
  overflow: hidden;
}

.phase-card::after {
  content: "";
  position: absolute;
  right: -22px;
  bottom: -28px;
  width: 94px;
  height: 94px;
  border: 1px solid rgba(17, 100, 116, 0.22);
  border-radius: 50%;
}

.phase-card.is-sync {
  border-color: #2a94a7;
  background: #d9f2f5;
}

.phase-card.is-complete {
  border-color: #6c9b7a;
  background: #e6f1e8;
  color: #245b35;
}

.phase-card-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.phase-card-icon svg {
  width: 20px;
  height: 20px;
}

.phase-card-copy {
  min-width: 0;
  display: block;
}

.phase-card-copy small,
.phase-card-copy strong,
.phase-card-copy > span {
  display: block;
}

.phase-card-copy small {
  color: currentColor;
  opacity: 0.72;
  font-size: 10px;
  font-weight: 750;
}

.phase-card-copy strong {
  margin-top: 3px;
  color: currentColor;
  font-size: 17px;
  line-height: 1.15;
}

.phase-card-copy > span {
  margin-top: 6px;
  color: currentColor;
  opacity: 0.78;
  font-size: 10px;
  line-height: 1.4;
  font-weight: 650;
}

.node-signal {
  position: absolute;
  right: 17px;
  top: 17px;
  width: 10px;
  height: 10px;
  border: 2px solid #116474;
  border-radius: 50%;
  background: #dff5f9;
}

.node-signal.armed {
  animation: node-ready 900ms ease-in-out infinite alternate;
}

.node-signal.spent {
  border-color: #8a741d;
  background: #efcf61;
  animation: none;
}

.node-signal.powered {
  border-color: #24733f;
  background: #63b879;
  box-shadow: 0 0 0 4px rgba(99, 184, 121, 0.2);
  animation: none;
}

.phase-rail {
  margin: 19px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  list-style: none;
}

.phase-rail li {
  min-width: 0;
  min-height: 58px;
  padding: 8px 7px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  border-top: 2px solid #c1c8c3;
  color: #7b837e;
}

.phase-rail li.active {
  border-color: var(--echo-dark);
  color: var(--echo-dark);
  background: rgba(217, 242, 245, 0.6);
}

.phase-rail li.complete {
  border-color: var(--goal);
  color: #2f7048;
}

.phase-index {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 900;
}

.phase-rail strong,
.phase-rail small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phase-rail strong {
  font-size: 10px;
  font-weight: 850;
}

.phase-rail small {
  margin-top: 3px;
  color: currentColor;
  opacity: 0.72;
  font-size: 9px;
  font-weight: 650;
}

.recording-section {
  padding-top: 18px;
}

.recording-lane {
  min-height: 54px;
  padding: 9px 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.record-chip {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid #b9c8c1;
  border-radius: 3px;
  background: #f7faf7;
  color: #43514a;
  font-size: 12px;
  font-weight: 900;
}

.record-chip.trigger {
  border-color: #b68c2a;
  background: #fff1b7;
  color: #765b16;
  box-shadow: 0 0 0 2px rgba(239, 207, 97, 0.24);
}

.recording-empty {
  align-self: center;
  color: #89918c;
  font-size: 10px;
  font-weight: 650;
}

.action-chip.current {
  border-color: var(--echo-dark);
  background: #c9f1f6;
  color: var(--echo-dark);
  box-shadow: 0 0 0 2px rgba(41, 168, 193, 0.16);
}

.tile.sync-gate::before,
.tile.sync-gate::after {
  border-color: #176d7b;
  background: #55c0cb;
}

.tile.sync-gate.open::before,
.tile.sync-gate.open::after {
  background: #b6e8e9;
}

.tile.node-door::before,
.tile.node-door::after {
  border-color: #755e18;
  background: var(--door);
}

.door-code {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  color: #38433d;
  font-size: 7px;
  font-weight: 950;
  opacity: 0.76;
  pointer-events: none;
}

.tile.door.open .door-code {
  opacity: 0.42;
}

.ghost.overlapping .entity-inner {
  transform: translate(-15%, -15%);
}

@media (max-width: 620px) {
  .phase-card {
    min-width: 0;
    min-height: 128px;
    flex: 1;
    padding: 13px 30px 13px 12px;
  }

  .phase-card-copy strong {
    font-size: 15px;
  }

  .phase-rail {
    gap: 4px;
  }

  .phase-rail li {
    min-height: 54px;
    grid-template-columns: 20px minmax(0, 1fr);
    padding: 7px 4px;
    gap: 4px;
  }

  .phase-index {
    width: 20px;
    height: 20px;
    font-size: 8px;
  }

  .phase-rail strong {
    font-size: 9px;
  }

  .phase-rail small {
    font-size: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .node-signal.armed {
    animation: none;
  }
}

/* Formal game UI layer */
:root {
  --time: #168da4;
  --time-dark: #0c5868;
  --time-soft: #dff3f6;
  --sync: #efc94f;
  --sync-dark: #6b5310;
  --sync-soft: #fff3bd;
  --success: #347e50;
  --success-dark: #1d5432;
  --success-soft: #dcecdf;
  --scrim: rgba(11, 14, 12, 0.72);
  --font-code: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

.archive-progress {
  width: 94px;
  min-width: 94px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: var(--font-code);
  font-size: 10px;
  font-weight: 800;
}

.archive-progress i,
.tutorial-index i {
  position: relative;
  height: 5px;
  display: block;
  overflow: hidden;
  border: 1px solid #aeb5b0;
  border-radius: 1px;
  background: #d9ddda;
}

.archive-progress i b,
.tutorial-index i b {
  position: absolute;
  inset: -1px auto -1px -1px;
  width: 0;
  max-width: calc(100% + 2px);
  border: 1px solid var(--success-dark);
  background: var(--success);
  transition: width 220ms ease;
}

.level-meta-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 5px;
}

.level-meta-row .level-kicker {
  margin: 0 !important;
}

.level-concept {
  min-height: 20px;
  padding: 3px 7px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #98a19b;
  border-radius: 3px;
  background: #f8f9f7;
  color: #4c554f;
  font-size: 9px;
  line-height: 1;
  font-weight: 800;
}

.mission-card {
  margin-top: 18px;
  padding: 12px 12px 13px;
  border-top: 1px solid #98a19b;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-left: 4px solid var(--player);
  background: rgba(255, 255, 255, 0.58);
}

.mission-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.mission-heading span {
  color: var(--player-dark);
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 800;
}

.mission-heading strong {
  font-size: 13px;
}

.mission-card p {
  margin: 7px 0 0;
  color: #465049;
  font-size: 10px;
  line-height: 1.55;
  font-weight: 650;
}

.mechanic-section {
  padding-top: 18px;
}

.mechanic-list {
  border-top: 1px solid var(--line-strong);
}

.mechanic-row {
  --mechanic: #69736d;
  --mechanic-dark: #323a35;
  --mechanic-soft: #edf0ed;
  min-height: 58px;
  padding: 8px 0;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--line);
}

.tone-time {
  --mechanic: var(--time);
  --mechanic-dark: var(--time-dark);
  --mechanic-soft: var(--time-soft);
}

.tone-sync {
  --mechanic: var(--sync);
  --mechanic-dark: var(--sync-dark);
  --mechanic-soft: var(--sync-soft);
}

.tone-goal,
.tone-exit {
  --mechanic: var(--success);
  --mechanic-dark: var(--success-dark);
  --mechanic-soft: var(--success-soft);
}

.mechanic-row.active {
  margin-inline: -8px;
  padding-inline: 8px;
  background: var(--mechanic-soft);
  box-shadow: inset 3px 0 0 var(--mechanic);
}

.mechanic-symbol,
.help-mechanic-symbol {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 2px solid var(--mechanic-dark);
  border-radius: 3px;
  background: var(--mechanic);
  color: #fff;
  font-family: var(--font-code);
  font-size: 11px;
  font-weight: 900;
}

.tone-time .mechanic-symbol,
.tone-time .help-mechanic-symbol {
  clip-path: polygon(16% 0, 84% 0, 100% 16%, 100% 84%, 84% 100%, 16% 100%, 0 84%, 0 16%);
}

.tone-sync .mechanic-symbol,
.tone-sync .help-mechanic-symbol {
  border-radius: 50%;
  color: #302600;
}

.mechanic-copy {
  min-width: 0;
}

.mechanic-copy strong,
.mechanic-copy small {
  display: block;
}

.mechanic-copy strong {
  font-size: 10px;
  font-weight: 850;
}

.mechanic-copy small {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mechanic-state {
  max-width: 92px;
  padding: 4px 6px;
  border: 1px solid color-mix(in srgb, var(--mechanic) 62%, #737b76);
  border-radius: 3px;
  background: var(--mechanic-soft);
  color: var(--mechanic-dark);
  font-size: 8px;
  line-height: 1.25;
  font-weight: 850;
  text-align: center;
}

.tutorial-strip[hidden],
.completion-scrim[hidden],
.help-overlay[hidden] {
  display: none !important;
}

.tutorial-key[hidden],
.tutorial-continue[hidden] {
  display: none !important;
}

.tutorial-strip {
  position: relative;
  min-height: 80px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  border: 2px solid var(--ink);
  border-left: 7px solid var(--sync);
  border-radius: 5px;
  background: #fffdf4;
  box-shadow: 6px 6px 0 rgba(21, 25, 22, 0.12);
  animation: tutorial-enter 180ms ease-out;
}

.tutorial-index {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  color: var(--sync-dark);
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 900;
}

.tutorial-index i {
  border-color: #c5a63f;
  background: #eee4b8;
}

.tutorial-index i b {
  border-color: var(--sync-dark);
  background: var(--sync);
}

.tutorial-copy {
  min-width: 0;
}

.tutorial-copy strong,
.tutorial-copy p {
  display: block;
  margin: 0;
}

.tutorial-copy strong {
  font-size: 15px;
}

.tutorial-copy p {
  margin-top: 4px;
  color: #4d514d;
  font-size: 10px;
  line-height: 1.5;
  font-weight: 650;
}

.tutorial-key {
  min-width: 42px;
  min-height: 42px;
  padding: 6px 9px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: white;
  box-shadow: inset 0 -3px 0 #d4d8d4;
  color: var(--ink);
  font-family: var(--font-code);
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
}

.tutorial-continue,
.tutorial-skip {
  min-height: 38px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
}

.tutorial-continue {
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: white;
}

.tutorial-continue svg {
  width: 15px;
  height: 15px;
}

.tutorial-skip {
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

@keyframes tutorial-enter {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Completion is viewport-sized so the dialog is never clipped by the board. */
.completion-scrim {
  position: fixed;
  z-index: 90;
  inset: 0;
  padding: 24px;
  display: grid;
  place-items: center;
  background: var(--scrim);
}

.completion-scrim .completion {
  position: relative;
  width: min(470px, 100%);
  max-height: calc(100dvh - 48px);
  padding: 30px;
  overflow: auto;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 12px 12px 0 rgba(0, 0, 0, 0.34);
}

.completion-seal {
  position: absolute;
  right: 24px;
  top: 24px;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 3px double var(--success);
  border-radius: 50%;
  color: var(--success);
  transform: rotate(-7deg);
}

.completion-seal svg {
  width: 24px;
  height: 24px;
  stroke-width: 3;
}

.completion-scrim .completion > p:first-of-type {
  padding-right: 58px;
}

.completion-scrim .completion h3 {
  max-width: calc(100% - 58px);
}

.completion-scrim .completion-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.completion-scrim .completion > .completion-note {
  margin: -8px 0 18px !important;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
  font-weight: 650;
}

.completion-scrim .primary-command,
.completion-scrim .secondary-command {
  min-height: 46px;
}

.board-frame.completed {
  overflow: visible;
}

/* Help manual */
body.help-open {
  overflow: hidden;
}

.help-overlay {
  position: fixed;
  z-index: 110;
  inset: 0;
  padding: 24px;
  display: grid;
  place-items: center;
  background: var(--scrim);
}

.help-dialog {
  width: min(900px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--paper);
  box-shadow: 14px 14px 0 rgba(0, 0, 0, 0.3);
}

.help-header {
  position: sticky;
  z-index: 4;
  top: 0;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 2px solid var(--ink);
  background: var(--surface);
}

.help-header p,
.help-header h2,
.help-controls h3,
.help-atlas h3,
.help-controls p {
  margin: 0;
}

.help-header p {
  color: var(--time-dark);
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 900;
}

.help-header h2 {
  margin-top: 3px;
  font-size: 23px;
}

.help-close {
  width: 40px;
  height: 40px;
}

.help-rule-flow {
  padding: 18px 20px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr) auto);
  align-items: center;
  border-bottom: 1px solid var(--line-strong);
  background: #e7ebE8;
}

.help-rule-flow > span {
  min-width: 0;
  min-height: 66px;
  padding: 10px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-content: center;
  column-gap: 8px;
  border-top: 2px solid var(--time);
}

.help-rule-flow > span b {
  grid-row: span 2;
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border: 1px solid var(--time-dark);
  border-radius: 50%;
  color: var(--time-dark);
  font-family: var(--font-code);
  font-size: 9px;
}

.help-rule-flow > span strong,
.help-rule-flow > span small {
  display: block;
}

.help-rule-flow > span strong {
  font-size: 11px;
}

.help-rule-flow > span small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
}

.help-rule-flow > i {
  width: 24px;
  color: var(--time-dark);
  font-style: normal;
  font-weight: 900;
  text-align: center;
}

.help-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.72fr) minmax(0, 1.28fr);
}

.help-controls,
.help-atlas {
  min-width: 0;
  padding: 20px;
}

.help-controls {
  border-right: 1px solid var(--line-strong);
  background: var(--surface);
}

.help-controls h3,
.help-atlas h3 {
  margin-bottom: 13px;
  font-size: 14px;
}

.control-manual {
  display: grid;
  gap: 10px;
}

.control-manual > span {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.control-manual kbd {
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  border: 1px solid #7e8781;
  border-radius: 3px;
  background: #f7f8f6;
  box-shadow: inset 0 -3px 0 #d2d6d2;
  font-family: var(--font-code);
  font-size: 10px;
  font-weight: 900;
}

.control-manual em {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
  font-weight: 750;
}

.help-controls > p {
  margin-top: 18px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.help-mechanics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.help-mechanic-row {
  --mechanic: #69736d;
  --mechanic-dark: #323a35;
  --mechanic-soft: #edf0ed;
  min-width: 0;
  min-height: 70px;
  padding: 10px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid color-mix(in srgb, var(--mechanic) 55%, #a9afab);
  border-radius: 4px;
  background: var(--mechanic-soft);
}

.help-mechanic-row.tone-time {
  --mechanic: var(--time);
  --mechanic-dark: var(--time-dark);
  --mechanic-soft: var(--time-soft);
}

.help-mechanic-row.tone-sync {
  --mechanic: var(--sync);
  --mechanic-dark: var(--sync-dark);
  --mechanic-soft: var(--sync-soft);
}

.help-mechanic-row.tone-goal,
.help-mechanic-row.tone-exit {
  --mechanic: var(--success);
  --mechanic-dark: var(--success-dark);
  --mechanic-soft: var(--success-soft);
}

.help-mechanic-row strong,
.help-mechanic-row small {
  display: block;
}

.help-mechanic-row strong {
  font-size: 10px;
}

.help-mechanic-row small {
  margin-top: 4px;
  color: #555e58;
  font-size: 9px;
  line-height: 1.4;
}

.help-actions {
  position: sticky;
  z-index: 4;
  bottom: 0;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  border-top: 2px solid var(--ink);
  background: var(--surface);
}

.help-actions .primary-command,
.help-actions .secondary-command {
  min-width: 140px;
  min-height: 44px;
  padding: 0 16px;
}

/* Mechanism codes are readable stamps, not miniature prose. */
.tile-code,
.legend-code {
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  color: #fff;
  font-family: var(--font-code);
  font-style: normal;
  font-weight: 950;
  line-height: 1;
}

.tile[data-mechanic] {
  cursor: help;
}

.tile-code {
  position: absolute;
  z-index: 2;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-width: 2px;
  border-radius: 2px;
  font-size: 9px;
  pointer-events: none;
}

.legend-code {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  border-radius: 2px;
  font-size: 9px;
}

.code-time,
.legend-code.time-code {
  border-color: var(--time-dark);
  background: var(--time);
  clip-path: polygon(16% 0, 84% 0, 100% 16%, 100% 84%, 84% 100%, 16% 100%, 0 84%, 0 16%);
}

.code-sync,
.legend-code.sync-code {
  border-color: var(--sync-dark);
  border-radius: 50%;
  background: var(--sync);
  color: #302600;
}

.code-goal,
.code-exit,
.legend-code.goal-code,
.legend-code.exit-code {
  border-color: var(--success-dark);
  background: var(--success);
}

.door-code {
  display: none !important;
}

.tile[data-mechanic] {
  cursor: help;
}

@media (hover: hover) {
  .tile[data-mechanic]:hover {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.72);
  }
}

/* T and D share the cyan rewind system. */
.tile.time-node::before {
  inset: 20%;
  border-color: var(--time-dark);
  background: var(--time-soft);
  box-shadow: inset 0 0 0 4px rgba(22, 141, 164, 0.26);
}

.tile.time-node::after,
.tile.time-node.active::after {
  content: "↶";
  color: var(--time-dark);
  font-size: 19px;
}

.tile.time-node.active::before {
  border-color: #e6fbff;
  background: var(--time);
  box-shadow: inset 0 0 0 4px #8ad8e3, 0 0 0 2px rgba(22, 141, 164, 0.28);
}

.tile.time-node.active::after {
  color: white;
}

.tile.time-node.spent.inactive::before {
  border-color: var(--time-dark);
  background: #bdd5d8;
  opacity: 0.76;
}

.tile.time-door {
  background: #426f78;
}

.tile.time-door::before,
.tile.time-door::after,
.tile.node-door::before,
.tile.node-door::after {
  border-color: var(--time-dark);
  background: #42b4c7;
  box-shadow: inset 0 0 0 2px rgba(225, 250, 253, 0.25);
}

.tile.time-door.open::before,
.tile.time-door.open::after {
  background: #a8e0e7;
}

.tile.time-door .tile-code {
  inset: 0;
  width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
  clip-path: none;
}

.tile.time-door .tile-code::before {
  content: "↶";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #073f4a;
  font-size: 18px;
}

.tile.time-door .tile-code::after {
  content: "D";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border: 2px solid var(--time-dark);
  border-radius: 2px;
  background: var(--time);
  color: white;
  font-family: var(--font-code);
  font-size: 9px;
  clip-path: polygon(16% 0, 84% 0, 100% 16%, 100% 84%, 84% 100%, 16% 100%, 0 84%, 0 16%);
}

.tile.time-door.open .tile-code::before {
  opacity: 0.44;
}

/* P and A share the yellow pressure-system dot. */
.tile.plate::before {
  inset: 20%;
  border-color: var(--sync-dark);
  background: #d8bb51;
  box-shadow: inset 0 0 0 4px #f7dc72, 0 3px 0 #67551d;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.tile.plate::after {
  inset: 39%;
  background: #5c490a;
}

.tile.plate.active::before {
  border-color: #4d3b04;
  background: var(--sync);
  box-shadow: inset 0 0 0 4px #fff0a0;
  transform: scale(0.88);
}

.tile.sync-gate {
  background: #746b42;
}

.tile.sync-gate::before,
.tile.sync-gate::after {
  border-color: var(--sync-dark);
  background: var(--sync);
  box-shadow: inset 0 0 0 2px rgba(255, 247, 196, 0.42);
}

.tile.sync-gate.open::before,
.tile.sync-gate.open::after {
  background: #f4df88;
}

.tile.sync-gate .tile-code {
  border-color: var(--sync-dark);
  border-radius: 50%;
  background: var(--sync);
  color: #302600;
}

/* G is a four-corner crate locator. */
.tile.goal::before,
.tile.goal.active::before {
  content: "";
  position: absolute;
  inset: 16%;
  border: 0;
  background:
    linear-gradient(var(--success), var(--success)) left top / 38% 3px no-repeat,
    linear-gradient(var(--success), var(--success)) left top / 3px 38% no-repeat,
    linear-gradient(var(--success), var(--success)) right top / 38% 3px no-repeat,
    linear-gradient(var(--success), var(--success)) right top / 3px 38% no-repeat,
    linear-gradient(var(--success), var(--success)) left bottom / 38% 3px no-repeat,
    linear-gradient(var(--success), var(--success)) left bottom / 3px 38% no-repeat,
    linear-gradient(var(--success), var(--success)) right bottom / 38% 3px no-repeat,
    linear-gradient(var(--success), var(--success)) right bottom / 3px 38% no-repeat;
  box-shadow: none;
  transform: none;
}

.tile.goal::after {
  content: "";
  position: absolute;
  inset: 35%;
  border: 2px dashed rgba(29, 84, 50, 0.64);
}

.tile.goal.active::before {
  z-index: 5;
  background:
    linear-gradient(#e7f7eb, #e7f7eb) left top / 38% 3px no-repeat,
    linear-gradient(#e7f7eb, #e7f7eb) left top / 3px 38% no-repeat,
    linear-gradient(#e7f7eb, #e7f7eb) right top / 38% 3px no-repeat,
    linear-gradient(#e7f7eb, #e7f7eb) right top / 3px 38% no-repeat,
    linear-gradient(#e7f7eb, #e7f7eb) left bottom / 38% 3px no-repeat,
    linear-gradient(#e7f7eb, #e7f7eb) left bottom / 3px 38% no-repeat,
    linear-gradient(#e7f7eb, #e7f7eb) right bottom / 38% 3px no-repeat,
    linear-gradient(#e7f7eb, #e7f7eb) right bottom / 3px 38% no-repeat;
}

.tile.goal.active::after {
  border-color: #e7f7eb;
  background: rgba(52, 126, 80, 0.44);
}

/* E is a wayfinding threshold, with the arrow carrying at small sizes. */
.tile.exit::before {
  content: "↗";
  inset: 10%;
  border: 2px solid var(--success-dark);
  background: #d5e6d9;
  color: var(--success-dark);
  box-shadow: inset 0 -5px 0 #8fbd9c;
  font-size: 19px;
  line-height: 1;
}

.tile.exit.locked::before {
  border-style: dashed;
  background: #c7d1c9;
  color: #5b6b60;
  box-shadow: inset 0 -4px 0 #9aa89e;
}

.tile.exit.ready::before {
  border-color: var(--success-dark);
  background: var(--success-soft);
  color: var(--success-dark);
  box-shadow: inset 0 -5px 0 #79b58b, 0 0 0 2px rgba(52, 126, 80, 0.2);
}

.phase-card::after {
  display: none;
}

.board.branching {
  animation: branch-flash 720ms ease;
}

.board.branching::before {
  content: "";
  position: absolute;
  z-index: 10;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 0, rgba(181, 242, 250, 0.16) 35%, rgba(222, 251, 255, 0.82) 50%, rgba(181, 242, 250, 0.16) 65%, transparent 100%);
  transform: translateX(110%);
  animation: rewind-scan 720ms ease-out;
}

.board-frame.branching-event {
  animation: branch-frame 820ms ease-out;
}

@keyframes branch-frame {
  0%, 100% { box-shadow: 0 15px 40px var(--shadow); }
  38% { box-shadow: 0 0 0 3px rgba(96, 210, 227, 0.7), 0 15px 40px var(--shadow); }
}

.future-step small {
  position: absolute;
  right: 7%;
  top: 5%;
  min-width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border: 1px solid #dff8fc;
  border-radius: 50%;
  background: var(--time-dark);
  color: white;
  font-size: 7px;
  font-weight: 900;
}

.future-step.blocked span,
.record-chip.blocked,
.action-chip.blocked {
  border-color: #9b392f;
  background: #f7d8d3;
  color: #7b2922;
}

.future-step.blocked small {
  border-color: #ffe4df;
  background: #8a3028;
}

.future-step.waiting span {
  border-style: solid;
  background: #dff5f8;
}

@keyframes rewind-scan {
  0% { transform: translateX(110%); opacity: 0; }
  20% { opacity: 1; }
  75% { opacity: 0.9; }
  100% { transform: translateX(-110%); opacity: 0; }
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 320px;
  }

  .stage-panel {
    padding-inline: 20px;
  }

  .tutorial-strip {
    grid-template-columns: 92px minmax(0, 1fr) auto auto;
  }
}

@media (max-width: 980px) {
  .archive-progress {
    margin-left: auto;
  }

  .tutorial-strip {
    grid-template-columns: 96px minmax(0, 1fr) auto auto;
  }

  .help-grid {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .help-mechanics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar-tools {
    gap: 6px;
  }

  .level-tabs {
    flex: 1 1 150px;
    width: auto;
  }

  .archive-progress {
    width: 40px;
    min-width: 40px;
    margin-left: 0;
    display: block;
    text-align: center;
  }

  .archive-progress i {
    display: none;
  }

  .topbar .icon-button {
    width: 40px;
    height: 40px;
  }

  .stage-panel {
    padding: 15px 8px 17px;
    gap: 13px;
  }

  .stage-heading {
    padding-inline: 5px;
  }

  .level-meta-row {
    gap: 7px;
  }

  .level-concept {
    min-height: 19px;
    font-size: 8px;
  }

  .board-frame {
    width: calc(100% + 16px);
    min-height: 230px;
    margin-inline: -8px;
    padding: 8px 4px;
    border-radius: 0;
  }

  .board {
    gap: 1px;
    padding: 2px;
  }

  .tile-code {
    left: 2px;
    top: 2px;
    width: 14px;
    height: 14px;
    border-width: 1px;
    font-size: 8px;
  }

  .tile.time-node::after,
  .tile.time-node.active::after,
  .tile.time-door .tile-code::before,
  .tile.exit::before {
    font-size: 16px;
  }

  .tile.time-door .tile-code::after {
    left: 2px;
    top: 2px;
    width: 14px;
    height: 14px;
    border-width: 1px;
    font-size: 8px;
  }

  .tutorial-strip {
    min-height: 0;
    padding: 11px;
    grid-template-columns: 80px minmax(0, 1fr) auto;
    gap: 9px;
    border-left-width: 5px;
    box-shadow: 4px 4px 0 rgba(21, 25, 22, 0.1);
  }

  .tutorial-index {
    gap: 6px;
    font-size: 8px;
  }

  .tutorial-copy strong {
    font-size: 13px;
  }

  .tutorial-copy p {
    font-size: 9px;
  }

  .tutorial-key {
    min-width: 38px;
    min-height: 38px;
    font-size: 12px;
  }

  .tutorial-continue {
    grid-column: 1 / -1;
    width: 100%;
  }

  .tutorial-skip {
    grid-column: 1 / -1;
    justify-self: end;
    min-height: 26px;
  }

  .control-deck {
    gap: 10px;
  }

  .dpad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 4px;
  }

  .phase-card {
    min-width: 0;
    min-height: 140px;
    padding: 12px 27px 12px 11px;
    flex: 1;
    gap: 9px;
  }

  .phase-card-icon {
    width: 32px;
    height: 32px;
  }

  .phase-card-copy strong {
    font-size: 14px;
  }

  .phase-card-copy > span {
    font-size: 9px;
  }

  .time-panel {
    padding: 18px 12px 20px;
  }

  .mission-card {
    margin-top: 15px;
  }

  .mechanic-row {
    grid-template-columns: 30px minmax(0, 1fr) auto;
  }

  .mechanic-state {
    max-width: 84px;
  }

  .statusbar {
    display: none;
  }

  .completion-scrim {
    padding: 12px;
  }

  .completion-scrim .completion {
    width: 100%;
    max-height: calc(100dvh - 24px);
    padding: 23px 18px 18px;
    box-shadow: 7px 7px 0 rgba(0, 0, 0, 0.3);
  }

  .completion-seal {
    right: 18px;
    top: 18px;
    width: 40px;
    height: 40px;
  }

  .completion-scrim .completion-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .completion-stat {
    padding: 9px 7px;
  }

  .completion-stat strong {
    font-size: 18px;
  }

  .help-overlay {
    padding: 0;
    place-items: end stretch;
  }

  .help-dialog {
    width: 100%;
    max-height: 94dvh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 7px 7px 0 0;
    box-shadow: 0 -8px 0 rgba(0, 0, 0, 0.18);
  }

  .help-header {
    padding: 14px;
  }

  .help-header h2 {
    font-size: 20px;
  }

  .help-rule-flow {
    padding: 10px 14px;
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .help-rule-flow > span {
    min-height: 54px;
    padding: 7px 8px;
  }

  .help-rule-flow > i {
    width: auto;
    transform: rotate(90deg);
  }

  .help-grid {
    display: block;
  }

  .help-controls,
  .help-atlas {
    padding: 16px 14px;
  }

  .help-controls {
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
  }

  .help-mechanics {
    grid-template-columns: 1fr;
  }

  .help-actions {
    padding: 10px 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .help-actions .primary-command,
  .help-actions .secondary-command {
    min-width: 0;
    padding-inline: 8px;
  }
}

@media (max-width: 360px) {
  .topbar {
    padding-inline: 10px;
  }

  .archive-progress {
    display: none;
  }

  .stage-heading h2 {
    font-size: 22px;
  }

  .control-deck {
    gap: 7px;
  }

  .dpad {
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
  }

  .phase-card-icon {
    display: none;
  }

  .completion-actions {
    grid-template-columns: 1fr;
  }

  .help-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tutorial-strip,
  .board.branching,
  .board.branching::before,
  .board-frame.branching-event {
    animation: none;
  }
}

/* Chronicle Archive: miniature museum stage */
:root {
  --gallery: #17231e;
  --gallery-deep: #0d1511;
  --gallery-mid: #22332b;
  --gallery-raised: #2b3d34;
  --archive-paper: #e3e8e4;
  --archive-paper-2: #d8dfda;
  --archive-ink: #17201b;
  --archive-muted: #667169;
  --metal: #77847c;
  --metal-dark: #343e38;
  --brass: #bc963d;
  --brass-bright: #e2bc55;
  --brass-dark: #5c460e;
  --now: #f06455;
  --now-dark: #782f29;
  --rewind: #27b8c7;
  --rewind-dark: #075866;
  --anchor: #b99138;
  --anchor-dark: #523e0e;
  --paradox: #c04d88;
  --paradox-dark: #59203d;
  --success: #3e8a5d;
  --success-dark: #1e5334;
  --paper: var(--archive-paper);
  --surface: #f1f3f0;
  --ink: var(--archive-ink);
  --muted: var(--archive-muted);
  --line: #b7c0ba;
  --line-strong: #7d8981;
  --board: #111914;
  --floor: #a8b3ac;
  --floor-alt: #9faaA3;
  --wall: #34433b;
  --wall-edge: #627269;
  --player: var(--now);
  --player-dark: var(--now-dark);
  --echo: var(--rewind);
  --echo-dark: var(--rewind-dark);
  --goal: var(--success);
  --door: var(--brass-bright);
  --focus: var(--rewind);
  --shadow: rgba(5, 9, 7, 0.38);
  --scrim: rgba(6, 10, 8, 0.82);
  --chapter-accent: var(--now);
  --chapter-mark: "01";
  --font-display: "Songti SC", "STSong", "SimSun", serif;
}

body[data-chapter="1"] { --chapter-accent: var(--now); --chapter-mark: "01"; }
body[data-chapter="2"] { --chapter-accent: var(--rewind); --chapter-mark: "02"; }
body[data-chapter="3"] { --chapter-accent: var(--brass-bright); --chapter-mark: "03"; }
body[data-chapter="4"] { --chapter-accent: var(--paradox); --chapter-mark: "04"; }
body[data-chapter="5"] { --chapter-accent: var(--success); --chapter-mark: "05"; }
body[data-chapter="warehouse-1"] { --chapter-accent: #e2bc55; --chapter-mark: "01"; }

html,
body {
  background: var(--gallery-deep);
  color: var(--archive-ink);
}

body {
  background-color: var(--gallery);
  background-image:
    linear-gradient(90deg, rgba(188, 150, 61, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 96px 100%, 100% 32px;
}

body.help-open,
body.briefing-open {
  overflow: hidden;
}

.app-shell {
  position: relative;
  min-height: 100dvh;
  background: transparent;
}

.topbar {
  min-height: 88px;
  padding: 10px 22px;
  display: grid;
  grid-template-columns: auto minmax(150px, 0.7fr) auto;
  align-items: center;
  gap: 22px;
  border-bottom: 2px solid var(--brass);
  background: var(--gallery-deep);
  color: var(--archive-paper);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.08), 0 5px 0 rgba(4, 8, 6, 0.38);
}

.brand {
  gap: 11px;
}

.archive-code {
  position: relative;
  width: 50px;
  height: 50px;
  border: 2px solid var(--brass-bright);
  border-radius: 3px;
  background: #26372e;
  color: var(--brass-bright);
  box-shadow: inset 0 0 0 2px var(--gallery-deep), 3px 3px 0 rgba(0, 0, 0, 0.35);
}

.archive-code svg {
  width: 24px;
  height: 24px;
  transform: translateY(-4px);
}

.archive-code small {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-family: var(--font-code);
  font-size: 7px;
  font-weight: 900;
}

.brand h1 {
  color: #f2f4f1;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 800;
}

.brand p {
  color: #aab6ae;
  font-family: var(--font-code);
  font-size: 8px;
}

.chapter-heading {
  min-width: 0;
  padding-left: 14px;
  border-left: 2px solid var(--chapter-accent);
}

.chapter-heading span,
.chapter-heading strong,
.chapter-heading small {
  display: block;
}

.chapter-heading span {
  color: var(--chapter-accent);
  font-family: var(--font-code);
  font-size: 8px;
  font-weight: 900;
}

.chapter-heading strong {
  margin-top: 2px;
  overflow: hidden;
  color: #f0f3f0;
  font-family: var(--font-display);
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-heading small {
  margin-top: 3px;
  overflow: hidden;
  color: #95a39a;
  font-size: 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-tools {
  gap: 8px;
}

.level-tabs {
  position: relative;
  gap: 4px;
  padding: 3px 3px 7px;
  overflow-x: auto;
  border: 0;
  border-bottom: 1px solid #5f704f;
  border-radius: 0;
  background: transparent;
  scrollbar-width: thin;
  scrollbar-color: var(--brass) transparent;
}

.level-tabs::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -2px;
  left: 0;
  height: 3px;
  border-top: 1px solid var(--brass-dark);
  border-bottom: 1px solid rgba(226, 188, 85, 0.24);
  pointer-events: none;
}

.level-tab {
  position: relative;
  flex: 0 0 78px;
  width: 78px;
  height: 52px;
  padding: 5px 7px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  grid-template-rows: 1fr 1fr;
  align-items: center;
  column-gap: 6px;
  border: 1px solid #4b5d53;
  border-radius: 3px;
  background: #213129;
  color: #aeb9b2;
  text-align: left;
  box-shadow: inset 0 -3px 0 #14201a;
}

.level-tab:hover {
  border-color: var(--brass);
  background: #2a3b32;
  color: white;
}

.level-tab span {
  grid-row: 1 / 3;
  color: #7f9086;
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 900;
}

.level-tab strong,
.level-tab small {
  min-width: 0;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-tab strong {
  align-self: end;
  font-size: 9px;
  font-weight: 850;
}

.level-tab small {
  align-self: start;
  color: #819188;
  font-family: var(--font-code);
  font-size: 7px;
}

.level-tab.active {
  border-color: var(--chapter-accent);
  background: #eef1ed;
  color: var(--archive-ink);
  box-shadow: inset 0 -4px 0 var(--chapter-accent), 0 3px 0 rgba(0, 0, 0, 0.28);
}

.level-tab.active span,
.level-tab.active small {
  color: color-mix(in srgb, var(--chapter-accent) 72%, var(--archive-ink));
}

.level-tab.kind-archive {
  margin-left: 12px;
  border-color: #a98638;
  background: #302f27;
  box-shadow: inset 0 -3px 0 #191a16;
}

.level-tab.kind-archive::before {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: -9px;
  width: 1px;
  border-left: 1px solid #718078;
  border-right: 1px solid rgba(226, 188, 85, 0.32);
}

.level-tab.kind-archive:not(.active) span,
.level-tab.kind-archive:not(.active) small {
  color: #d2b968;
}

.level-tab.kind-archive.active {
  border-color: var(--chapter-accent);
  background: #f3f0e4;
}

.level-tab.completed::after {
  content: "✓";
  right: 3px;
  bottom: 3px;
  width: 14px;
  height: 14px;
  display: grid;
  place-items: center;
  border: 1px solid #d7eddd;
  border-radius: 50%;
  background: var(--success);
  color: white;
  font-size: 8px;
  font-weight: 900;
}

.level-tab.active.completed::after {
  background: var(--success);
}

.archive-progress {
  width: 72px;
  min-width: 72px;
  color: #b8c2bc;
}

.archive-progress i {
  border-color: #516158;
  background: #23332b;
}

.archive-progress i b {
  border-color: var(--brass-dark);
  background: var(--brass-bright);
}

.topbar .icon-button {
  width: 40px;
  height: 40px;
  border-color: #66766d;
  border-radius: 3px;
  background: #23332b;
  color: #dce2de;
  box-shadow: inset 0 -3px 0 #111b16;
}

.topbar .icon-button:hover {
  border-color: var(--brass-bright);
  background: #30443a;
  color: white;
}

#audio-button {
  position: relative;
}

#audio-button .audio-on-icon {
  display: none;
}

#audio-button .audio-off-icon {
  display: block;
}

#audio-button.is-active {
  border-color: var(--brass-bright);
  color: var(--brass-bright);
}

#audio-button.is-active .audio-on-icon {
  display: block;
}

#audio-button.is-active .audio-off-icon {
  display: none;
}

#audio-button.is-active::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border: 1px solid #26311b;
  border-radius: 50%;
  background: var(--brass-bright);
}

#audio-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.workspace {
  width: min(100%, 1600px);
  grid-template-columns: minmax(0, 1fr) 360px;
  border-right: 1px solid rgba(188, 150, 61, 0.28);
  border-left: 1px solid rgba(188, 150, 61, 0.28);
  background: var(--gallery-mid);
  box-shadow: 0 0 0 7px rgba(4, 8, 6, 0.18);
}

.stage-panel {
  position: relative;
  padding: 20px 26px 18px;
  grid-template-rows: auto minmax(330px, 1fr) auto;
  gap: 16px;
  background-color: var(--gallery-mid);
  background-image:
    linear-gradient(90deg, rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.08) 1px, transparent 1px);
  background-size: 72px 100%, 100% 24px;
}

.stage-panel > * {
  position: relative;
  z-index: 1;
}

.stage-heading {
  position: relative;
  min-height: 66px;
  padding: 8px 100px 10px 12px;
  align-items: center;
  border-top: 1px solid rgba(226, 188, 85, 0.6);
  border-bottom: 1px solid rgba(226, 188, 85, 0.32);
  background: #1b2a23;
  overflow: hidden;
}

.stage-heading::before {
  content: var(--chapter-mark);
  position: absolute;
  right: 14px;
  top: 50%;
  color: color-mix(in srgb, var(--chapter-accent) 32%, transparent);
  font-family: var(--font-code);
  font-size: 58px;
  line-height: 1;
  font-weight: 900;
  transform: translateY(-50%);
}

.level-kicker {
  color: var(--chapter-accent);
  font-family: var(--font-code);
  font-size: 9px;
}

.level-concept,
.archive-time {
  min-height: 19px;
  padding: 3px 7px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #607168;
  border-radius: 2px;
  background: #26372f;
  color: #ced6d1;
  font-family: var(--font-code);
  font-size: 8px;
  font-style: normal;
  font-weight: 800;
}

.archive-time {
  border-color: var(--chapter-accent);
  color: var(--chapter-accent);
}

.stage-heading h2 {
  color: #f0f3f0;
  font-family: var(--font-display);
  font-size: 29px;
  font-weight: 800;
}

.objective {
  position: relative;
  z-index: 2;
  max-width: 420px;
  padding: 8px 10px;
  justify-content: flex-start;
  border-left: 3px solid var(--success);
  background: #26372f;
  color: #d5ddd7;
  font-size: 11px;
  line-height: 1.45;
  text-align: left;
}

.objective svg {
  color: #75ba8b;
}

/* The board is a museum display case, not a generic card. */
.board-frame {
  position: relative;
  min-height: 360px;
  padding: 30px 16px 28px;
  overflow: hidden;
  border: 9px solid #0a100d;
  border-radius: 3px;
  background: #111a15;
  box-shadow:
    0 9px 0 #070b09,
    0 13px 0 rgba(188, 150, 61, 0.42),
    0 23px 32px rgba(2, 5, 3, 0.5),
    inset 0 0 0 2px #3d4a43;
}

.board-frame::before {
  inset: 5px;
  width: auto;
  height: auto;
  left: 5px;
  top: 5px;
  z-index: 3;
  border: 1px solid var(--brass);
  background: transparent;
  opacity: 0.72;
  pointer-events: none;
}

.board-frame::after {
  inset: 10px;
  width: auto;
  height: auto;
  left: 10px;
  top: 10px;
  z-index: 2;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  background: transparent;
  opacity: 1;
  pointer-events: none;
}

.cabinet-plaque,
.cabinet-footer {
  position: absolute;
  z-index: 6;
  right: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  color: #aab6af;
  font-family: var(--font-code);
  font-size: 8px;
  font-weight: 850;
  pointer-events: none;
}

.cabinet-plaque {
  top: 5px;
  height: 24px;
  gap: 10px;
}

.cabinet-plaque i {
  min-width: 20px;
  height: 1px;
  flex: 1;
  background: #526158;
}

.cabinet-plaque span:first-child {
  color: var(--brass-bright);
}

.cabinet-footer {
  bottom: 4px;
  height: 23px;
  justify-content: space-between;
  border-top: 1px solid #46554d;
}

.cabinet-footer span {
  color: #6f8076;
  font-size: 7px;
}

.cabinet-footer b {
  color: var(--chapter-accent);
  font-size: 8px;
}

.board {
  z-index: 4;
  gap: 2px;
  padding: 3px;
  border: 3px solid #050806;
  border-radius: 2px;
  background: #050806;
  box-shadow: 0 7px 0 #050806, 0 9px 0 rgba(188, 150, 61, 0.5);
}

.tile.floor {
  background: var(--floor);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -4px 0 rgba(32, 47, 39, 0.18);
}

.tile.floor.alt {
  background: var(--floor-alt);
}

.tile.wall {
  border-color: #1f2b25;
  background: var(--wall);
  box-shadow:
    inset 0 5px 0 var(--wall-edge),
    inset 0 -5px 0 #26332c,
    inset 1px 0 0 rgba(255, 255, 255, 0.07);
}

.tile.wall::after {
  right: 9%;
  bottom: 10%;
  width: 38%;
  height: 2px;
  background: #1d2923;
}

.entity-inner {
  filter: drop-shadow(0 4px 0 rgba(11, 17, 14, 0.42));
}

.player .entity-inner {
  border-color: #fff1ee;
  background: var(--now);
  box-shadow: 0 3px 0 var(--now-dark), 0 0 0 2px rgba(240, 100, 85, 0.2);
}

.player-id,
.crate-mark {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 900;
  pointer-events: none;
}

.player-id {
  right: -5px;
  bottom: -5px;
  width: 18px;
  height: 18px;
  border: 2px solid #fff1ee;
  border-radius: 50%;
  background: var(--now-dark);
  color: white;
  font-size: 8px;
}

.ghost .entity-inner {
  border: 2px dashed var(--rewind);
  background: rgba(217, 247, 250, 0.82);
  color: var(--rewind-dark);
  box-shadow: 0 0 0 2px rgba(39, 184, 199, 0.25);
  filter: drop-shadow(0 0 4px rgba(39, 184, 199, 0.35));
}

.ghost.finished .entity-inner {
  background: rgba(217, 247, 250, 0.55);
  filter: none;
}

.ghost-id {
  border-color: #e5fbfd;
  background: var(--rewind-dark);
}

.box .entity-inner {
  border-color: #4d3913;
  background: #c9983e;
  box-shadow: inset 0 0 0 4px #e7bd66, 0 4px 0 rgba(39, 27, 8, 0.55);
}

.box.echo-crate .entity-inner {
  border-color: var(--rewind-dark);
  background: #76cbd4;
  box-shadow: inset 0 0 0 4px #b6e9ed, 0 4px 0 #174e55;
}

.box.record-crate .entity-inner {
  border-color: var(--success-dark);
  background: #67a879;
  box-shadow: inset 0 0 0 4px #a9d1b4, 0 4px 0 #254f31;
}

.crate-mark {
  inset: 25%;
  border: 1px solid rgba(54, 38, 8, 0.48);
  background: rgba(248, 232, 181, 0.72);
  color: #4a3510;
  font-size: 9px;
}

.echo-crate .crate-mark {
  border-color: rgba(7, 88, 102, 0.5);
  background: rgba(224, 250, 252, 0.75);
  color: var(--rewind-dark);
}

.record-crate .crate-mark {
  border-color: rgba(30, 83, 52, 0.5);
  background: rgba(226, 244, 231, 0.76);
  color: var(--success-dark);
}

.box .entity-inner::before,
.box .entity-inner::after {
  z-index: 1;
  opacity: 0.42;
}

.control-deck {
  align-items: center;
  gap: 18px;
}

.dpad {
  padding: 7px;
  border: 1px solid #53635a;
  background: #19271f;
  box-shadow: 0 5px 0 #0b120e;
}

.move-button {
  border: 1px solid #73827a;
  border-radius: 3px;
  background: #d6ddd8;
  color: #1c2822;
  box-shadow: inset 0 -4px 0 #9da9a1;
}

.move-button:hover {
  border-color: var(--brass-bright);
  background: #f0f2ef;
}

.move-button:active {
  box-shadow: inset 0 -1px 0 #9da9a1;
  transform: translateY(2px);
}

.move-wait {
  border-color: var(--brass-dark);
  background: var(--brass-bright);
  color: #392b06;
  box-shadow: inset 0 -4px 0 #9e7928;
}

.phase-card {
  min-width: 250px;
  min-height: 120px;
  border: 1px solid var(--brass);
  border-radius: 3px;
  background: #1b2b23;
  color: #e5ebe7;
  box-shadow: 0 5px 0 #0b120e, inset 4px 0 0 var(--now);
}

.phase-card.is-sync {
  border-color: var(--rewind);
  background: #173037;
  color: #e4fbfd;
  box-shadow: 0 5px 0 #081417, inset 4px 0 0 var(--rewind);
}

.phase-card.is-complete {
  border-color: var(--success);
  background: #1e3527;
  color: #e2f1e6;
  box-shadow: 0 5px 0 #0c1710, inset 4px 0 0 var(--success);
}

.phase-card-icon {
  border-color: currentColor;
  border-radius: 3px;
}

.node-signal {
  border-color: #b9c8bf;
  background: #54645b;
}

.node-signal.armed {
  border-color: var(--rewind-dark);
  background: var(--rewind);
}

.node-signal.spent {
  border-color: var(--brass-dark);
  background: var(--brass-bright);
}

.node-signal.powered {
  border-color: #b9e0c4;
  background: var(--success);
}

.tutorial-strip {
  border-color: #0e1712;
  border-left-color: var(--brass-bright);
  border-radius: 3px;
  background: var(--archive-paper);
  box-shadow: 6px 6px 0 #0b120e;
}

.tutorial-copy p {
  color: #4e5952;
}

.tutorial-key {
  border-color: #39453e;
  border-radius: 3px;
  background: #f3f5f2;
}

/* Calibration desk and archive ledger */
.time-panel {
  padding: 20px 20px 18px;
  border-left: 4px solid var(--brass);
  background-color: var(--archive-paper);
  background-image:
    linear-gradient(rgba(50, 66, 57, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, transparent 27px, rgba(166, 77, 72, 0.12) 28px, transparent 29px);
  background-size: 100% 23px, 100% 100%;
  color: var(--archive-ink);
  box-shadow: inset 5px 0 0 rgba(255, 255, 255, 0.32);
}

.time-heading {
  padding-bottom: 12px;
  border-bottom: 2px solid var(--archive-ink);
}

.time-heading p {
  color: var(--rewind-dark);
  font-family: var(--font-code);
  font-size: 8px;
}

.time-heading h3 {
  color: var(--archive-ink);
  font-family: var(--font-display);
  font-size: 23px;
}

.archive-dossier {
  position: relative;
  margin-top: 14px;
  padding: 13px 12px 11px 15px;
  border-top: 1px solid #78857d;
  border-right: 1px solid #a4aea7;
  border-bottom: 1px solid #a4aea7;
  border-left: 4px solid var(--chapter-accent);
  background: rgba(245, 247, 244, 0.72);
  box-shadow: 3px 3px 0 rgba(51, 63, 56, 0.12);
}

.archive-dossier::after {
  content: "ARCHIVE COPY";
  position: absolute;
  right: 8px;
  bottom: 6px;
  color: rgba(50, 65, 57, 0.18);
  font-family: var(--font-code);
  font-size: 7px;
  font-weight: 900;
  pointer-events: none;
}

.dossier-head,
.dossier-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dossier-head span {
  color: #4e5b53;
  font-size: 9px;
  font-weight: 850;
}

.dossier-head strong {
  padding: 3px 7px;
  border: 2px solid #873f3a;
  color: #873f3a;
  font-family: var(--font-code);
  font-size: 8px;
  transform: rotate(-2deg);
}

.archive-dossier > p {
  margin: 8px 0 0;
}

#archive-location {
  color: var(--chapter-accent);
  font-family: var(--font-code);
  font-size: 8px;
  font-weight: 900;
}

.dossier-story {
  color: #3f4943;
  font-size: 10px;
  line-height: 1.55;
  font-weight: 650;
}

.dossier-foot {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px dashed #869189;
  color: #657169;
  font-size: 8px;
}

.dossier-foot strong {
  max-width: 170px;
  overflow: hidden;
  color: #39453e;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phase-rail {
  margin-top: 16px;
  gap: 5px;
}

.phase-rail li {
  min-height: 58px;
  border-top-color: #a4aea7;
  color: #657169;
}

.phase-rail li.active {
  border-color: var(--chapter-accent);
  background: rgba(255, 255, 255, 0.56);
  color: color-mix(in srgb, var(--chapter-accent) 70%, var(--archive-ink));
  box-shadow: inset 0 -2px 0 rgba(23, 32, 27, 0.06);
}

.phase-rail li.complete {
  border-color: var(--success);
  color: var(--success-dark);
}

.phase-index {
  border-radius: 3px;
  font-family: var(--font-code);
}

.mission-card {
  margin-top: 14px;
  border-top-color: #849087;
  border-right-color: #a5afa8;
  border-bottom-color: #a5afa8;
  border-left-color: var(--now);
  background: rgba(249, 250, 248, 0.68);
  box-shadow: 3px 3px 0 rgba(51, 63, 56, 0.1);
}

.mission-heading span {
  color: var(--now-dark);
}

.mechanic-list {
  border-top-color: #87938b;
}

.mechanic-row {
  min-height: 56px;
  border-bottom-color: #b5beb8;
}

.mechanic-row.active {
  background: var(--mechanic-soft);
  box-shadow: inset 4px 0 0 var(--mechanic);
}

.mechanic-symbol,
.help-mechanic-symbol {
  border-radius: 2px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.mechanic-copy small {
  color: #657169;
}

.mechanic-state {
  border-radius: 2px;
  font-size: 8px;
}

.recording-lane,
.echo-list {
  border-color: #aeb8b1;
}

.record-chip,
.action-chip {
  border-radius: 2px;
  background: #eff2ef;
  box-shadow: inset 0 -2px 0 rgba(68, 81, 73, 0.12);
}

.record-chip.trigger {
  border-color: var(--rewind-dark);
  background: #d4f1f4;
  color: var(--rewind-dark);
  box-shadow: inset 0 -2px 0 #8bcfd6;
}

.echo-badge {
  border-color: var(--rewind-dark);
  background: #d9f4f6;
  color: var(--rewind-dark);
}

.action-chip.current {
  border-color: var(--rewind-dark);
  background: #c4edf1;
}

.rule-note {
  border-color: var(--archive-ink);
}

.statusbar {
  min-height: 46px;
  border-top: 2px solid var(--brass);
  background: var(--gallery-deep);
  color: #cbd4ce;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.legend span,
.statusbar p {
  color: #9eaba3;
}

.legend-code {
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}

/* Help manual and material atlas */
.help-overlay,
.briefing-overlay,
.completion-scrim {
  background-color: var(--scrim);
  background-image: repeating-linear-gradient(90deg, rgba(226, 188, 85, 0.035) 0 1px, transparent 1px 72px);
}

.help-dialog {
  border: 2px solid var(--brass);
  border-radius: 3px;
  background: var(--archive-paper);
  box-shadow: 12px 12px 0 #050806, 15px 15px 0 rgba(188, 150, 61, 0.38);
}

.help-header {
  border-bottom: 2px solid var(--brass);
  background: var(--gallery-deep);
  color: #eff2ef;
}

.help-header p {
  color: var(--brass-bright);
}

.help-header h2 {
  color: white;
  font-family: var(--font-display);
}

.help-header .icon-button {
  border-color: #708078;
  border-radius: 3px;
  background: #26372f;
  color: white;
}

.help-rule-flow {
  border-bottom-color: #77857c;
  background: var(--archive-paper-2);
}

.help-rule-flow > span {
  border-top-color: var(--rewind);
}

.help-rule-flow > span b {
  border-color: var(--rewind-dark);
  border-radius: 3px;
  color: var(--rewind-dark);
}

.help-rule-flow > i {
  color: var(--rewind-dark);
}

.help-lore {
  padding: 13px 20px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #929e96;
  background: #1f3028;
  color: #dbe2dd;
}

.help-lore svg {
  width: 28px;
  height: 28px;
  color: var(--brass-bright);
}

.help-lore p,
.help-lore strong,
.help-lore span {
  display: block;
  margin: 0;
}

.help-lore strong {
  color: var(--brass-bright);
  font-family: var(--font-code);
  font-size: 8px;
}

.help-lore span {
  margin-top: 3px;
  color: #bdc8c1;
  font-size: 9px;
  line-height: 1.45;
}

.help-controls {
  background: #edf0ed;
}

.help-atlas {
  background-color: #dde3df;
  background-image: linear-gradient(rgba(65, 79, 71, 0.055) 1px, transparent 1px);
  background-size: 100% 22px;
}

.help-mechanics {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.help-mechanic-row {
  min-height: 68px;
  border-radius: 2px;
  box-shadow: inset 0 -3px 0 rgba(37, 48, 42, 0.08);
}

.help-atlas-divider {
  grid-column: 1 / -1;
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #4f5c54;
  font-family: var(--font-code);
  font-size: 8px;
  font-weight: 900;
}

.help-atlas-divider::before,
.help-atlas-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: #87938b;
}

.help-material-row {
  --material: #89938d;
  --material-dark: #3c4741;
  --material-soft: #e4e8e5;
  min-width: 0;
  min-height: 66px;
  padding: 9px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  border: 1px dashed var(--material-dark);
  background: var(--material-soft);
}

.help-material-row.tone-ordinary {
  --material: #c99a42;
  --material-dark: #624814;
  --material-soft: #efe3c7;
}

.help-material-row.tone-echo {
  --material: var(--rewind);
  --material-dark: var(--rewind-dark);
  --material-soft: #d7f0f3;
}

.help-material-row.tone-archive {
  --material: var(--success);
  --material-dark: var(--success-dark);
  --material-soft: #dcebe0;
}

.help-material-row.tone-anchor {
  --material: var(--anchor);
  --material-dark: var(--anchor-dark);
  --material-soft: #eee3c5;
}

.help-material-row.tone-decay {
  --material: #a04b42;
  --material-dark: #57231f;
  --material-soft: #efd8d4;
}

.help-material-row.tone-blank {
  --material: #a7b0aa;
  --material-dark: #4e5a53;
  --material-soft: #edf0ee;
}

.help-material-row.tone-paradox {
  --material: var(--paradox);
  --material-dark: var(--paradox-dark);
  --material-soft: #f0d7e4;
}

.help-material-row.is-locked {
  --material: #9da59f;
  --material-dark: #566159;
  --material-soft: #ecefec;
}

.help-material-row.is-locked .help-material-code {
  border-style: dashed;
  box-shadow: none;
}

.help-material-code {
  width: 44px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 2px solid var(--material-dark);
  background: var(--material);
  color: white;
  font-family: var(--font-code);
  font-size: 7px;
  font-weight: 900;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.tone-anchor .help-material-code {
  clip-path: polygon(0 0, 32% 0, 32% 12%, 68% 12%, 68% 0, 100% 0, 100% 32%, 88% 32%, 88% 68%, 100% 68%, 100% 100%, 68% 100%, 68% 88%, 32% 88%, 32% 100%, 0 100%, 0 68%, 12% 68%, 12% 32%, 0 32%);
}

.tone-paradox .help-material-code {
  background-color: var(--paradox);
  background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.35) 0 3px, transparent 3px 7px);
}

.help-material-row strong,
.help-material-row small {
  display: block;
}

.help-material-row strong {
  color: var(--material-dark);
  font-size: 9px;
}

.help-material-row small {
  margin-top: 3px;
  color: #5e6962;
  font-size: 8px;
  line-height: 1.35;
}

.help-actions {
  grid-template-columns: repeat(3, auto);
  border-top-color: var(--brass);
  background: var(--gallery-deep);
}

.help-actions .secondary-command {
  border-color: #6c7b73;
  background: #26372f;
  color: #e2e8e4;
}

.help-actions .primary-command {
  border-color: var(--brass-bright);
  background: var(--brass-bright);
  color: #2c2105;
}

/* Prologue briefing */
.briefing-overlay[hidden] {
  display: none !important;
}

.briefing-overlay {
  position: fixed;
  z-index: 120;
  inset: 0;
  padding: 24px;
  display: grid;
  place-items: center;
}

.briefing-dialog {
  width: min(980px, 100%);
  max-height: calc(100dvh - 48px);
  display: grid;
  grid-template-columns: minmax(300px, 0.85fr) minmax(0, 1.15fr);
  overflow: auto;
  border: 2px solid var(--brass);
  border-radius: 3px;
  background: var(--archive-paper);
  box-shadow: 14px 14px 0 #050806, 18px 18px 0 rgba(188, 150, 61, 0.34);
}

.briefing-visual {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  border-right: 2px solid var(--brass);
  background-color: #132019;
  background-image:
    linear-gradient(90deg, rgba(226, 188, 85, 0.09) 1px, transparent 1px),
    linear-gradient(rgba(226, 188, 85, 0.07) 1px, transparent 1px);
  background-size: 44px 44px;
}

.briefing-visual::before,
.briefing-visual::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.briefing-visual::before {
  inset: 18px;
  border: 1px solid rgba(226, 188, 85, 0.64);
}

.briefing-visual::after {
  right: 28px;
  bottom: 24px;
  left: 28px;
  height: 46px;
  border-top: 2px solid #56675d;
  border-bottom: 8px solid #080d0a;
  background: #25372e;
  box-shadow: 0 7px 0 rgba(188, 150, 61, 0.42);
}

.briefing-ring {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 44%;
  border: 2px solid var(--rewind);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 4px rgba(39, 184, 199, 0.08);
}

.briefing-ring::before,
.briefing-ring::after {
  content: "";
  position: absolute;
  background: var(--rewind);
}

.briefing-ring::before {
  left: 50%;
  top: -8px;
  width: 2px;
  height: calc(100% + 16px);
}

.briefing-ring::after {
  left: -8px;
  top: 50%;
  width: calc(100% + 16px);
  height: 2px;
}

.briefing-ring.ring-one {
  width: 230px;
  height: 230px;
  opacity: 0.66;
}

.briefing-ring.ring-two {
  width: 146px;
  height: 146px;
  border-style: dashed;
  opacity: 0.42;
  transform: translate(-50%, -50%) rotate(22deg);
}

.briefing-box {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 44%;
  width: 82px;
  height: 82px;
  border: 5px solid #654915;
  background: #ce9d43;
  box-shadow: inset 0 0 0 8px #edc46d, 0 9px 0 #241a07;
  transform: translate(-50%, -50%) rotate(-3deg);
}

.briefing-box::before,
.briefing-box::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 50%;
  height: 4px;
  background: #654915;
}

.briefing-box::before { transform: rotate(45deg); }
.briefing-box::after { transform: rotate(-45deg); }

.briefing-echo {
  position: absolute;
  z-index: 4;
  left: calc(50% + 75px);
  top: calc(44% - 82px);
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--rewind);
  border-radius: 50%;
  background: #d9f3f5;
  color: var(--rewind-dark);
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 900;
  box-shadow: 0 0 0 4px rgba(39, 184, 199, 0.12);
}

.briefing-content {
  min-width: 0;
  padding: 34px 36px 30px;
  background-color: var(--archive-paper);
  background-image: linear-gradient(rgba(45, 61, 52, 0.055) 1px, transparent 1px);
  background-size: 100% 24px;
}

.briefing-kicker,
.briefing-content h2,
.briefing-content > p,
.briefing-content blockquote {
  margin: 0;
}

.briefing-kicker {
  color: var(--rewind-dark);
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 900;
}

.briefing-content h2 {
  margin-top: 8px;
  color: var(--archive-ink);
  font-family: var(--font-display);
  font-size: 38px;
  line-height: 1.05;
}

.briefing-content > p {
  margin-top: 20px;
  color: #3e4942;
  font-size: 13px;
  line-height: 1.8;
}

.briefing-content > p strong {
  color: #765310;
}

.briefing-copy-secondary {
  padding-left: 12px;
  border-left: 3px solid var(--brass);
}

.briefing-ledger {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid #87938b;
  background: #87938b;
  gap: 1px;
}

.briefing-ledger span {
  min-width: 0;
  padding: 9px;
  display: block;
  background: #eef1ee;
}

.briefing-ledger b,
.briefing-ledger strong {
  display: block;
}

.briefing-ledger b {
  color: #69756d;
  font-size: 8px;
}

.briefing-ledger strong {
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 10px;
}

.briefing-content blockquote {
  margin-top: 22px;
  padding: 12px 14px;
  border-top: 1px solid #8b968f;
  border-bottom: 1px solid #8b968f;
  color: var(--paradox-dark);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
}

.briefing-actions {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.briefing-actions .primary-command,
.briefing-actions .secondary-command {
  min-height: 48px;
  padding: 0 14px;
}

.briefing-actions .primary-command {
  border-color: var(--brass-dark);
  background: var(--brass-bright);
  color: #2d2105;
}

/* Restored archive result */
.completion-scrim .completion {
  border-color: var(--brass);
  border-radius: 3px;
  background-color: var(--archive-paper);
  background-image: linear-gradient(rgba(48, 63, 55, 0.055) 1px, transparent 1px);
  background-size: 100% 24px;
  box-shadow: 12px 12px 0 #050806, 16px 16px 0 rgba(188, 150, 61, 0.36);
}

.completion-seal {
  border-color: var(--success);
  color: var(--success);
}

.completion-scrim .completion > p:first-of-type {
  color: var(--success-dark);
  font-family: var(--font-code);
  font-weight: 900;
}

.completion-scrim .completion h3 {
  color: var(--archive-ink);
  font-family: var(--font-display);
  font-size: 27px;
}

.completion-scrim .completion-stats {
  border-color: #87938b;
  background: #87938b;
}

.completion-stat {
  background: #eff2ef;
}

.completion-scrim .secondary-command {
  border-color: #69776f;
  background: #eff2ef;
}

.completion-scrim .primary-command {
  border-color: var(--brass-dark);
  background: var(--brass-bright);
  color: #2b2005;
}

/* Final presentation and responsive pass */
:root {
  --time: var(--rewind);
  --time-dark: var(--rewind-dark);
  --time-soft: #d9f4f6;
  --sync: #f1cc55;
  --sync-dark: #604910;
  --sync-soft: #fff3bd;
}

/* The prologue illustration stays legible and carries the visual narrative. */
.briefing-visual > img {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: 50% 50%;
  filter: saturate(0.96) contrast(1.03);
}

.briefing-visual::before {
  z-index: 2;
  box-shadow: inset 0 0 0 1px rgba(10, 19, 14, 0.72);
}

.briefing-visual::after {
  z-index: 2;
  height: 26px;
  border-top-color: rgba(226, 188, 85, 0.74);
  border-bottom-width: 4px;
  background: rgba(20, 33, 26, 0.7);
}

.briefing-ring,
.briefing-box,
.briefing-echo {
  display: none;
}

/* Mechanism explanations are gameplay information, so never truncate them. */
.mechanic-row {
  height: auto;
  padding-block: 9px;
}

.mechanic-copy {
  min-width: 0;
}

.mechanic-copy small {
  display: block;
  overflow: visible;
  color: #59665e;
  font-size: 10px;
  line-height: 1.4;
  text-overflow: clip;
  white-space: normal;
}

.mechanic-state {
  line-height: 1.25;
  white-space: normal;
}

/* A strong automatic rewind exposure without moving surrounding layout. */
.board.branching {
  transform-origin: 50% 50%;
  will-change: transform, opacity;
  animation: archive-rewind-exposure 780ms cubic-bezier(0.3, 0, 0.2, 1);
}

.board.branching::before {
  inset: -8%;
  background: linear-gradient(
    90deg,
    transparent 18%,
    rgba(39, 184, 199, 0.08) 34%,
    rgba(224, 252, 255, 0.94) 49%,
    rgba(39, 184, 199, 0.24) 57%,
    transparent 76%
  );
  transform: translateX(120%);
  opacity: 0;
  will-change: transform, opacity;
  animation: archive-rewind-scan 780ms cubic-bezier(0.22, 0.72, 0.24, 1);
}

.board-frame.branching-event {
  box-shadow:
    0 0 0 3px rgba(39, 184, 199, 0.72),
    0 0 22px rgba(39, 184, 199, 0.34),
    0 9px 0 #070b09,
    0 13px 0 rgba(188, 150, 61, 0.42),
    0 23px 32px rgba(2, 5, 3, 0.5),
    inset 0 0 0 2px #3d4a43;
  transform-origin: 50% 50%;
  will-change: transform;
  animation: archive-case-response 900ms cubic-bezier(0.25, 0.8, 0.25, 1);
}

@keyframes archive-rewind-exposure {
  0%, 100% { transform: translateX(0) scale(1); opacity: 1; }
  16% { transform: translateX(3px) scale(0.996); opacity: 0.78; }
  31% { transform: translateX(-4px) scale(1.006); opacity: 0.5; }
  48% { transform: translateX(2px) scale(1.002); opacity: 0.92; }
  68% { transform: translateX(-1px) scale(1); opacity: 0.7; }
}

@keyframes archive-rewind-scan {
  0% { transform: translateX(120%); opacity: 0; }
  12% { opacity: 0.18; }
  42% { opacity: 1; }
  100% { transform: translateX(-120%); opacity: 0; }
}

@keyframes archive-case-response {
  0%, 100% { transform: scale(1); }
  34% { transform: scale(0.997); }
  58% { transform: scale(1.003); }
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "brand chapter"
      "tools tools";
    gap: 10px 18px;
  }

  .brand { grid-area: brand; }
  .chapter-heading { grid-area: chapter; }

  .topbar-tools {
    grid-area: tools;
    width: 100%;
  }

  .level-tabs {
    flex: 1 1 auto;
    width: 0;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 326px;
  }

  .stage-panel {
    padding-inline: 20px;
  }

  .briefing-dialog {
    width: min(940px, 100%);
    grid-template-columns: minmax(390px, 1fr) minmax(0, 1fr);
  }
}

@media (max-width: 980px) {
  .workspace {
    display: block;
  }

  .time-panel {
    border-top: 4px solid var(--brass);
    border-left: 0;
    box-shadow: inset 0 5px 0 rgba(255, 255, 255, 0.32);
  }

  .help-grid {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .help-mechanics {
    grid-template-columns: 1fr;
  }

  .briefing-dialog {
    grid-template-columns: minmax(330px, 0.9fr) minmax(0, 1.1fr);
  }

  .briefing-content {
    padding: 28px 26px 26px;
  }
}

@media (max-width: 760px) {
  .briefing-overlay {
    padding: 10px;
    place-items: center;
  }

  .briefing-dialog {
    width: min(620px, 100%);
    max-height: calc(100dvh - 20px);
    grid-template-columns: 1fr;
  }

  .briefing-visual {
    min-height: 0;
    aspect-ratio: 16 / 9;
    border-right: 0;
    border-bottom: 2px solid var(--brass);
  }

  .briefing-visual > img {
    object-position: 50% 49%;
  }

  .briefing-visual::after {
    right: 20px;
    bottom: 14px;
    left: 20px;
  }
}

@media (max-width: 620px) {
  .topbar {
    min-height: 0;
    padding: 9px 10px 11px;
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "chapter"
      "tools";
    gap: 8px;
  }

  .brand {
    min-width: 0;
  }

  .archive-code {
    width: 42px;
    height: 42px;
  }

  .archive-code svg {
    width: 20px;
    height: 20px;
  }

  .brand h1 {
    font-size: 21px;
  }

  .chapter-heading {
    padding: 6px 8px 6px 10px;
    border-top: 1px solid #394a40;
    border-right: 1px solid #394a40;
    border-bottom: 1px solid #394a40;
  }

  .chapter-heading strong {
    font-size: 14px;
  }

  .topbar-tools {
    display: grid;
    grid-template-columns: minmax(0, 1fr) repeat(3, 40px);
    align-items: center;
    gap: 5px;
  }

  .level-tabs {
    width: 100%;
    min-width: 0;
    scroll-snap-type: x proximity;
  }

  .level-tab {
    flex: 0 0 72px;
    width: 72px;
    height: 48px;
    scroll-snap-align: start;
  }

  .archive-progress {
    display: none;
  }

  .topbar .icon-button {
    width: 40px;
    height: 40px;
  }

  .stage-panel {
    padding: 14px 8px 16px;
    grid-template-rows: auto auto auto auto;
    gap: 13px;
  }

  .stage-heading {
    min-height: 0;
    padding: 9px 54px 10px 9px;
    align-items: flex-start;
    gap: 8px;
  }

  .stage-heading::before {
    right: 7px;
    font-size: 46px;
  }

  .stage-heading h2 {
    font-size: 24px;
  }

  .objective {
    width: 100%;
    max-width: none;
    padding: 7px 8px;
    font-size: 10px;
  }

  .board-frame {
    width: calc(100% + 16px);
    min-height: 238px;
    margin-inline: -8px;
    padding: 28px 4px 27px;
    border-width: 6px;
    border-radius: 0;
    box-shadow:
      0 6px 0 #070b09,
      0 9px 0 rgba(188, 150, 61, 0.42),
      0 16px 22px rgba(2, 5, 3, 0.42),
      inset 0 0 0 2px #3d4a43;
  }

  .board-frame::before {
    inset: 3px;
  }

  .board-frame::after {
    inset: 7px;
  }

  .cabinet-plaque,
  .cabinet-footer {
    right: 10px;
    left: 10px;
    font-size: 7px;
  }

  .board {
    width: 100%;
    gap: 1px;
    padding: 2px;
    border-width: 2px;
  }

  .control-deck {
    align-items: stretch;
    gap: 8px;
  }

  .dpad {
    flex: 0 0 auto;
    padding: 5px;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
    gap: 3px;
  }

  .phase-card {
    min-width: 0;
    min-height: 134px;
    padding: 11px 24px 11px 10px;
    flex: 1 1 0;
    gap: 8px;
  }

  .phase-card-icon {
    width: 30px;
    height: 30px;
  }

  .phase-card-copy strong {
    font-size: 13px;
  }

  .phase-card-copy > span {
    font-size: 8px;
    line-height: 1.4;
  }

  .tutorial-strip {
    grid-template-columns: 78px minmax(0, 1fr) auto;
    padding: 10px;
    gap: 8px;
  }

  .tutorial-continue,
  .tutorial-skip {
    grid-column: 1 / -1;
  }

  .time-panel {
    padding: 18px 14px 20px;
  }

  .help-overlay {
    padding: 0;
    place-items: end stretch;
  }

  .help-dialog {
    width: 100%;
    max-height: 96dvh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 3px 3px 0 0;
    box-shadow: 0 -7px 0 rgba(0, 0, 0, 0.25);
  }

  .help-header {
    padding: 13px 14px;
  }

  .help-header h2 {
    font-size: 20px;
  }

  .help-rule-flow {
    padding: 10px 14px;
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .help-rule-flow > span {
    min-height: 52px;
  }

  .help-rule-flow > i {
    width: auto;
    transform: rotate(90deg);
  }

  .help-lore {
    padding: 11px 14px;
  }

  .help-grid {
    display: block;
  }

  .help-controls,
  .help-atlas {
    padding: 15px 14px;
  }

  .help-controls {
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
  }

  .help-mechanics {
    grid-template-columns: 1fr;
  }

  .help-actions {
    padding: 9px 10px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .help-actions .primary-command,
  .help-actions .secondary-command {
    min-width: 0;
    min-height: 48px;
    padding: 5px;
    font-size: 10px;
    line-height: 1.25;
    white-space: normal;
  }

  .help-actions svg {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
  }

  .briefing-overlay {
    padding: 0;
    place-items: stretch;
  }

  .briefing-dialog {
    width: 100%;
    max-height: 100dvh;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .briefing-visual {
    min-height: 190px;
    aspect-ratio: 16 / 9;
  }

  .briefing-visual::before {
    inset: 10px;
  }

  .briefing-content {
    padding: 20px 16px 22px;
  }

  .briefing-content h2 {
    font-size: 30px;
  }

  .briefing-content > p {
    margin-top: 14px;
    font-size: 12px;
    line-height: 1.65;
  }

  .briefing-ledger,
  .briefing-content blockquote,
  .briefing-actions {
    margin-top: 15px;
  }

  .briefing-ledger span {
    padding: 7px;
  }

  .briefing-ledger strong {
    font-size: 9px;
  }

  .briefing-content blockquote {
    padding: 9px 10px;
    font-size: 12px;
  }

  .briefing-actions .primary-command,
  .briefing-actions .secondary-command {
    min-width: 0;
    min-height: 46px;
    padding-inline: 7px;
    font-size: 11px;
  }

  .completion-scrim {
    padding: 10px;
  }

  .completion-scrim .completion {
    width: 100%;
    max-height: calc(100dvh - 20px);
    padding: 22px 17px 17px;
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.32);
  }

  .completion-seal {
    right: 16px;
    top: 16px;
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 390px) {
  .brand p,
  .chapter-heading small {
    display: none;
  }

  .chapter-heading {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }

  .chapter-heading strong {
    margin-top: 0;
  }

  .level-tab {
    flex-basis: 68px;
    width: 68px;
  }

  .stage-heading {
    padding-right: 48px;
  }

  .control-deck {
    gap: 6px;
  }

  .dpad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
  }

  .phase-card-icon {
    display: none;
  }

  .briefing-visual {
    min-height: 176px;
  }

  .briefing-ledger {
    grid-template-columns: 1fr;
  }

  .briefing-ledger span {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }

  .briefing-ledger strong {
    margin-top: 0;
  }

  .help-actions {
    gap: 3px;
  }

  .help-actions .primary-command,
  .help-actions .secondary-command {
    font-size: 9px;
  }

  .help-actions svg {
    display: none;
  }

  .completion-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 620px) and (min-width: 700px) {
  .topbar {
    min-height: 62px;
    padding: 6px 14px;
    grid-template-columns: auto minmax(120px, 0.55fr) minmax(0, 1.45fr);
    grid-template-areas: "brand chapter tools";
    gap: 12px;
  }

  .archive-code {
    width: 40px;
    height: 40px;
  }

  .archive-code svg {
    width: 19px;
    height: 19px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .brand p,
  .chapter-heading small {
    display: none;
  }

  .chapter-heading strong {
    font-size: 14px;
  }

  .level-tab {
    height: 42px;
  }

  .level-tabs {
    height: 50px;
    padding: 3px;
  }

  .archive-progress {
    display: none;
  }

  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 286px;
    align-items: start;
  }

  .stage-panel {
    min-height: 0;
    align-self: start;
    padding: 10px 14px 14px;
    grid-template-columns: minmax(0, 1fr) 176px;
    grid-template-rows: 58px 230px auto;
    grid-template-areas:
      "heading heading"
      "board controls"
      "tutorial tutorial";
    gap: 10px;
  }

  .stage-heading {
    grid-area: heading;
    min-height: 58px;
    height: 58px;
    padding: 6px 48px 6px 10px;
    flex-direction: row;
    align-items: center;
    overflow: hidden;
  }

  .stage-heading h2 {
    font-size: 22px;
  }

  .stage-heading .objective {
    width: min(54%, 250px);
    max-width: 250px;
    padding: 6px 7px;
    font-size: 9px;
    line-height: 1.3;
  }

  .board-frame {
    grid-area: board;
    width: 100%;
    height: 230px;
    min-height: 230px;
    padding: 25px 6px 23px;
  }

  .control-deck {
    grid-area: controls;
    min-width: 0;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
  }

  .control-deck .dpad {
    align-self: center;
  }

  .control-deck .phase-card {
    width: 100%;
    min-width: 0;
    min-height: 64px;
    height: 64px;
    padding: 8px 20px 8px 9px;
    gap: 6px;
  }

  .control-deck .phase-card-icon {
    display: none;
  }

  .control-deck .phase-card-copy small {
    font-size: 7px;
  }

  .control-deck .phase-card-copy strong {
    font-size: 11px;
  }

  .control-deck .phase-card-copy > span {
    font-size: 7px;
    line-height: 1.25;
  }

  .tutorial-strip {
    grid-area: tutorial;
  }

  .time-panel {
    padding: 14px;
    border-top: 0;
    border-left: 4px solid var(--brass);
  }

  .briefing-overlay,
  .help-overlay,
  .completion-scrim {
    padding: 8px;
  }

  .briefing-dialog {
    width: min(940px, 100%);
    max-height: calc(100dvh - 16px);
    grid-template-columns: minmax(350px, 0.95fr) minmax(0, 1.05fr);
  }

  .briefing-visual {
    min-height: 360px;
    aspect-ratio: auto;
    border-right: 2px solid var(--brass);
    border-bottom: 0;
  }

  .briefing-content {
    padding: 22px 24px;
  }

  .briefing-content > p {
    margin-top: 12px;
    line-height: 1.55;
  }

  .briefing-ledger,
  .briefing-content blockquote,
  .briefing-actions {
    margin-top: 13px;
  }

  .help-dialog {
    max-height: calc(100dvh - 16px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .board.branching,
  .board.branching::before,
  .board-frame.branching-event {
    animation: none !important;
    transform: none !important;
  }

  .board.branching {
    opacity: 1;
  }

  .board.branching::before {
    opacity: 0;
  }
}

/* Shared result report ---------------------------------------------------- */

.completion-stamp-report {
  margin: 0 0 18px;
}

.completion-stamp-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.completion-stamp-header p,
.completion-stamp-header h4,
.completion-first-teaching-highlight p {
  margin: 0;
}

.completion-stamp-header p {
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 900;
}

.completion-stamp-header h4 {
  margin-top: 3px;
  font-family: var(--font-display);
  font-size: 16px;
}

.completion-stamp-header > strong {
  flex: 0 0 auto;
  font-family: var(--font-code);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.completion-stamp-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.completion-stamp-slot {
  --stamp-color: #744b3a;
  min-width: 0;
  min-height: 76px;
  padding: 9px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 1px solid currentColor;
  color: #6f756f;
  opacity: 0.48;
}

.completion-stamp-slot[data-stamp="timing"] {
  --stamp-color: #287b82;
}

.completion-stamp-slot[data-stamp="case"] {
  --stamp-color: #a67622;
}

.completion-stamp-slot.is-earned,
.completion-stamp-slot[data-earned="true"] {
  color: var(--stamp-color);
  opacity: 1;
}

.completion-stamp-mark {
  position: relative;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 900;
  transform: rotate(-7deg);
}

.completion-stamp-mark::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px dashed currentColor;
  border-radius: inherit;
}

.completion-stamp-slot div {
  min-width: 0;
}

.completion-stamp-slot div > strong,
.completion-stamp-slot div > small {
  display: block;
}

.completion-stamp-slot div > strong {
  font-size: 12px;
}

.completion-stamp-slot div > small {
  margin-top: 3px;
  overflow-wrap: anywhere;
  font-size: 9px;
  line-height: 1.35;
}

.completion-first-teaching-highlight[hidden] {
  display: none !important;
}

.completion-first-teaching-highlight {
  margin: 0 0 18px;
  padding: 11px 13px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid #b58a35;
}

.completion-first-teaching-badge {
  padding: 5px 7px;
  border: 1px solid currentColor;
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 900;
}

.completion-first-teaching-highlight div > strong {
  display: block;
  font-size: 12px;
}

.completion-first-teaching-highlight div > p {
  margin-top: 3px;
  font-size: 10px;
  line-height: 1.45;
}

.completion-first-teaching-highlight > button {
  min-width: 104px;
  min-height: 38px;
  padding-inline: 11px;
}

/* Reusable lesson focus layer ------------------------------------------- */

.tutorial-spotlight[hidden] {
  display: none !important;
}

.tutorial-spotlight {
  position: fixed;
  z-index: 108;
  inset: 0;
  display: block;
  background: rgba(2, 8, 5, 0.78);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.move-button.is-tutorial-spotlight {
  position: relative;
  z-index: 110;
  border-color: #f2cb67;
  background: #f5df9b;
  color: #241b09;
  box-shadow:
    inset 0 -4px 0 #ad7d26,
    0 0 0 4px #f2cb67,
    0 0 0 8px rgba(3, 10, 7, 0.72),
    0 0 26px rgba(242, 203, 103, 0.86);
}

.lesson-object-bubble[hidden],
.lesson-control-cue[hidden] {
  display: none !important;
}

.lesson-object-bubble {
  position: fixed;
  z-index: 122;
  left: clamp(16px, calc(var(--tutorial-anchor-x, 50vw) + 42px), calc(100vw - 286px));
  top: clamp(76px, calc(var(--tutorial-anchor-y, 50vh) - 62px), calc(100dvh - 190px));
  width: min(270px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 2px solid #b98a32;
  border-radius: 4px;
  background: #eee9d9;
  color: #17231d;
  box-shadow: 6px 7px 0 rgba(0, 0, 0, 0.36);
}

.lesson-object-bubble > span,
.lesson-object-bubble > strong,
.lesson-object-bubble > p,
.lesson-object-bubble > button {
  display: block;
  margin: 0;
}

.lesson-object-bubble > span {
  color: #8b651f;
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 900;
}

.lesson-object-bubble > strong {
  margin-top: 4px;
  font-size: 14px;
}

.lesson-object-bubble > p {
  margin-top: 5px;
  font-size: 11px;
  line-height: 1.55;
}

.lesson-object-bubble > button {
  min-width: 76px;
  min-height: 34px;
  margin-top: 10px;
  margin-left: auto;
  padding: 0 12px;
  border: 1px solid #493716;
  border-radius: 3px;
  background: #d7ad4e;
  color: #231b0c;
  font: inherit;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  pointer-events: auto;
  box-shadow: inset 0 -3px 0 #a27622;
}

.lesson-dialog {
  z-index: 2;
}

.lesson-control-cue {
  position: relative;
  z-index: 1;
  padding: 14px 0 2px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.lesson-control-cue > span {
  font-size: 12px;
  font-weight: 850;
}

.lesson-key-cluster {
  display: grid;
  grid-template-columns: repeat(3, 36px);
  grid-template-rows: repeat(3, 32px);
  gap: 4px;
}

.lesson-key-cluster kbd {
  min-width: 0;
  min-height: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  place-items: center;
  border: 1px solid #657269;
  border-radius: 3px;
  background: #d8ddd5;
  color: #26342d;
  font-family: var(--font-code);
  font-size: 11px;
  font-weight: 900;
  box-shadow: inset 0 -3px 0 #aeb7af;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease, transform 120ms ease;
}

.lesson-key-cluster kbd small {
  padding-right: 3px;
  font-size: 8px;
  font-weight: 800;
}

.lesson-key-cluster [data-lesson-key="W"] { grid-column: 2; grid-row: 1; }
.lesson-key-cluster [data-lesson-key="A"] { grid-column: 1; grid-row: 2; }
.lesson-key-cluster [data-lesson-key="S"] { grid-column: 2; grid-row: 2; }
.lesson-key-cluster [data-lesson-key="D"] { grid-column: 3; grid-row: 2; }

.lesson-key-cluster .lesson-key-space {
  grid-column: 1 / -1;
  grid-row: 3;
  grid-template-columns: 1fr auto;
  padding-inline: 8px;
}

.lesson-key-cluster kbd.is-active,
.lesson-key-cluster kbd[data-active="true"] {
  border-color: #6e4b0d;
  background: #f0c760;
  color: #2c2109;
  box-shadow: inset 0 -2px 0 #ad7b24, 0 0 0 3px rgba(222, 171, 60, 0.24);
  transform: translateY(1px);
}

@media (max-width: 620px) {
  .completion-stamp-list {
    grid-template-columns: 1fr;
  }

  .completion-stamp-slot {
    min-height: 58px;
  }

  .completion-first-teaching-highlight {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .completion-first-teaching-highlight > button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .lesson-control-cue {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .lesson-object-bubble {
    z-index: 122;
    left: 16px;
    right: 16px;
    top: auto;
    width: calc(100vw - 32px);
    bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .lesson-key-cluster kbd {
    transition: none;
  }
}
