:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #65707c;
  --line: #d7dde6;
  --panel: #fff;
  --soft: #f5f7fb;
  --accent: #2368ad;
  --accent-ink: #143f73;
  --danger: #a02d2d;
  --danger-bg: #fff1f1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: #fff;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: none;
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1320px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 460px);
  gap: 24px;
  align-items: end;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: #8c6e39;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  color: #171b22;
  font-size: clamp(2.1rem, 4.4vw, 3.7rem);
  line-height: 1;
  text-shadow: 0 12px 34px rgba(112, 91, 61, 0.16);
}

.header-note {
  margin: 0;
  color: #5d6672;
  line-height: 1.5;
}

.header-side {
  display: grid;
  justify-items: start;
  gap: 8px;
}

.input-panel,
.viewer,
.panel,
.step-container,
.sidebar {
  background: var(--panel);
  border: 1px solid rgba(226, 218, 205, 0.86);
  border-radius: 8px;
  min-width: 0;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.82) inset,
    0 28px 80px rgba(82, 66, 43, 0.13);
}

.input-panel {
  padding: 18px;
  margin-bottom: 18px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font: 1rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--ink);
  background: #fff;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.random-controls {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.random-controls label {
  margin-bottom: 0;
}

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

.random-row input {
  width: 76px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--ink);
  font: 1rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.random-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

button {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

button.secondary,
.step-button {
  background: #fff;
  color: var(--accent-ink);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.math {
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-style: italic;
  font-weight: 500;
  letter-spacing: 0;
}

.math sub,
.math sup {
  font-size: 0.72em;
  line-height: 0;
}

.error {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #efb8b8;
  border-radius: 6px;
  color: var(--danger);
  background: var(--danger-bg);
}

.error.warning {
  border-color: #e3c16f;
  color: #6b4f00;
  background: #fff8df;
}

.viewer {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
}

.mode-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.mode-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(228, 220, 208, 0.88);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.96);
  box-shadow: 0 16px 42px rgba(82, 66, 43, 0.12);
}

.mode-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.mode-button.active {
  border-color: var(--accent);
  background: #eef5ff;
  color: var(--accent-ink);
}

.detail-view[hidden],
.story-view[hidden] {
  display: none;
}

.story-view {
  margin-bottom: 28px;
}

.story-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.story-sticky {
  position: sticky;
  top: 16px;
  min-width: 0;
  padding: 18px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #fff;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.86) inset,
    0 22px 54px rgba(15, 23, 42, 0.08);
}

.map-progress {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin: 0 0 18px;
  color: #64717f;
  font-size: 0.88rem;
  font-weight: 700;
}

.map-progress-token {
  display: inline-grid;
  place-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #334155;
  background: rgba(255, 255, 255, 0.46);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

.map-progress-token:hover,
.map-progress-token:focus-visible,
.map-progress-token.active {
  border-color: rgba(31, 111, 235, 0.42);
  background: #f5f9ff;
  color: #102a55;
  box-shadow: 0 8px 20px rgba(31, 111, 235, 0.09);
}

.map-progress-map {
  display: inline-grid;
  justify-items: center;
  align-items: center;
  gap: 0;
  min-width: 42px;
  min-height: 32px;
  padding: 1px 6px 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #64717f;
  font-size: inherit;
  font-weight: 800;
  cursor: default;
}

.map-progress-arrow {
  margin-top: -4px;
  color: #a8b3c0;
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-size: 1.15rem;
  line-height: 1;
}

.map-progress-map-label {
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-style: italic;
  font-size: 0.82rem;
  line-height: 1;
  letter-spacing: 0;
}

.story-jump-nav {
  position: fixed;
  right: 18px;
  top: 50%;
  z-index: 10;
  display: grid;
  gap: 8px;
  transform: translateY(-50%);
}

.story-jump-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(226, 218, 205, 0.78);
  border-radius: 999px;
  background: rgba(255, 254, 250, 0.92);
  color: #2b3440;
  box-shadow: 0 16px 34px rgba(82, 66, 43, 0.16);
}

.story-jump-button:hover,
.story-jump-button:focus-visible {
  border-color: rgba(31, 111, 235, 0.44);
  color: var(--accent-ink);
  background: #fff;
}

.story-title {
  margin: 0 0 8px;
  font-size: 1.45rem;
}

.story-subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

.story-subtitle[hidden] {
  display: none;
}

.story-rule {
  width: fit-content;
  max-width: 100%;
  margin: -4px 0 14px;
  padding: 8px 10px;
  border: 1px solid #b7c8df;
  border-radius: 6px;
  background: #f8fbff;
  color: #334155;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
}

.story-rule[hidden] {
  display: none;
}

.story-stage {
  position: relative;
  height: 620px;
  overflow: hidden;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.92),
    inset 0 -1px 0 rgba(226, 232, 240, 0.66);
}

.story-fact-tray {
  display: grid;
  justify-content: end;
  gap: 5px;
  min-height: 0;
  margin-top: 10px;
  padding-right: 2px;
}

.story-fact-tray[hidden] {
  display: none;
}

.story-fact-line {
  justify-self: end;
  max-width: min(520px, 100%);
  padding: 4px 9px;
  border: 1px solid rgba(183, 200, 223, 0.38);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.48);
  color: #526071;
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-style: italic;
  font-size: 0.93rem;
  font-weight: 800;
  line-height: 1.2;
  box-shadow: 0 8px 18px rgba(82, 66, 43, 0.045);
}

.story-fact-line.ok {
  color: #365f96;
  border-color: rgba(140, 188, 255, 0.34);
}

.story-fact-line.fail {
  color: #8a5a00;
  border-color: rgba(214, 166, 77, 0.48);
}

.story-fact-line.result {
  background: rgba(255, 255, 255, 0.68);
}

.story-fact-line.result.in-set {
  color: #2f7135;
  border-color: rgba(136, 185, 137, 0.5);
}

.story-fact-line.result.out-set {
  color: #8a5a00;
  border-color: rgba(214, 166, 77, 0.5);
}

.story-canvas {
  position: absolute;
  transform-origin: 0 0;
  transition:
    left 260ms cubic-bezier(0.16, 1, 0.3, 1),
    top 260ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.story-canvas-content {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.story-region-layer,
.story-arrow-layer,
.story-object-layer,
.story-callout-layer {
  position: absolute;
  inset: 0;
}

.story-region-layer {
  z-index: 1;
}

.story-arrow-layer {
  z-index: 4;
  pointer-events: none;
}

.story-object-layer {
  z-index: 3;
}

.story-callout-layer {
  z-index: 5;
  pointer-events: none;
}

.story-arrow-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.story-theta-arrow {
  stroke: #111827;
  stroke-width: 2.35;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  opacity: 0.86;
}

.story-theta-arrow-halo {
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 4.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  opacity: 0.95;
}

.story-theta-arrow.muted {
  opacity: 0.22;
  stroke-width: 1.7;
}

.story-theta-arrow.chain-1 {
  stroke: #111827;
}

.story-theta-arrow.chain-2 {
  stroke: #111827;
}

.story-theta-arrow.chain-3 {
  stroke: #111827;
}

.story-theta-arrow.chain-4 {
  stroke: #111827;
}

.story-theta-arrow.chain-closed {
  stroke: #4b5563;
  stroke-dasharray: 4 5;
  opacity: 0.68;
}

.story-callout {
  position: absolute;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid rgba(188, 198, 211, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  box-shadow: 0 14px 34px rgba(24, 32, 42, 0.07);
}

.story-callout-main {
  font-size: 1.03rem;
  font-weight: 900;
}

.story-callout-line {
  color: #475569;
  font-weight: 800;
  line-height: 1.35;
}

.story-callout.spin,
.story-callout.parity {
  border-color: #9fb8d6;
  background: #f8fbff;
}

.story-callout.conclusion.in-set {
  border-color: #88b989;
  background: #f1fbf1;
}

.story-callout.conclusion.out-set {
  border-color: #d6a64d;
  background: #fff8e7;
}

.story-callout.formula-callout {
  align-content: center;
  justify-items: center;
  gap: 0;
  padding: 8px 14px;
  border-color: rgba(183, 200, 223, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 22px rgba(24, 32, 42, 0.06);
}

.story-callout.formula-step {
  animation: formula-fade 340ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes formula-fade {
  from {
    opacity: 0.72;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.formula-line {
  color: #111827;
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-style: italic;
  font-size: 1.18rem;
  font-weight: 900;
  line-height: 1.22;
  text-align: center;
}

.formula-line + .formula-line {
  color: #334155;
}

.formula-result {
  width: 100%;
  margin-top: 6px;
  padding-top: 0;
  border-top: 0;
}

.story-callout.conclusion.formula-callout {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.story-callout.conclusion.in-set .formula-result {
  color: #1e6b2a;
}

.story-callout.conclusion.out-set .formula-result {
  color: #8a5a00;
}

.story-region {
  position: absolute;
  border: 1px solid rgba(188, 198, 211, 0.7);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
  transition: opacity 200ms ease;
}

.story-region.u {
  border-color: #8cbcff;
  background: rgba(232, 242, 255, 0.52);
}

.story-region.s {
  border-color: #f0b563;
  background: rgba(255, 240, 216, 0.44);
}

.story-region.switch {
  border-color: #b9d5c2;
  background: rgba(244, 250, 245, 0.78);
}

.story-region.second-switch {
  border-color: #c9c5ea;
  background: rgba(246, 244, 255, 0.78);
}

.story-region.omega {
  border-color: #b7c8df;
  background: rgba(249, 251, 255, 0.82);
}

.story-region.dmap {
  border-color: #b7c8df;
  background: rgba(255, 255, 255, 0.82);
}

.story-region.theta {
  border-color: #b7c8df;
  background: rgba(255, 255, 255, 0.84);
}

.story-region-label {
  position: absolute;
  left: 12px;
  top: 8px;
  color: var(--muted);
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-style: italic;
  font-size: 0.95rem;
  font-weight: 700;
}

.story-cell {
  position: absolute;
  z-index: 2;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #c6d0dc;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.88) inset,
    0 8px 18px rgba(24, 32, 42, 0.07);
  transition:
    transform 640ms cubic-bezier(0.16, 1, 0.3, 1),
    width 640ms cubic-bezier(0.16, 1, 0.3, 1),
    height 640ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 320ms ease,
    background 320ms ease,
    border-color 320ms ease,
    box-shadow 320ms ease;
}

.story-formula {
  position: absolute;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border: 1px solid rgba(183, 200, 223, 0.86);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: #111827;
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-style: italic;
  font-size: 1.16rem;
  font-weight: 900;
  line-height: 1.18;
  text-align: center;
  box-shadow: 0 8px 22px rgba(24, 32, 42, 0.06);
  transition:
    transform 640ms cubic-bezier(0.16, 1, 0.3, 1),
    width 640ms cubic-bezier(0.16, 1, 0.3, 1),
    height 640ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 320ms ease,
    color 320ms ease,
    border-color 320ms ease,
    background 320ms ease,
    box-shadow 320ms ease;
}

.story-formula.ghost {
  color: #64748b;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: none;
}

.story-formula.fragment {
  justify-content: flex-start;
  padding: 0;
  border-color: transparent;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  white-space: nowrap;
}

.story-formula.fragment.core {
  color: #111827;
}

.story-formula.fragment.ok {
  color: #1f3f7a;
}

.story-formula.fragment.fail {
  color: #8a5a00;
}

.story-formula.fact {
  justify-content: center;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 26px rgba(82, 66, 43, 0.1);
  font-size: 1.04rem;
}

.story-formula.fact.major {
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 7px 18px rgba(82, 66, 43, 0.06);
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-size: 0.95rem;
  font-style: italic;
  font-weight: 700;
  white-space: nowrap;
}

.story-formula.fact.major .math {
  font: inherit;
}

.story-formula.fact.ok {
  color: #1f3f7a;
  border-color: rgba(140, 188, 255, 0.52);
}

.story-formula.fact.fail {
  color: #8a5a00;
  border-color: rgba(214, 166, 77, 0.68);
}

.story-formula.fragment.condition {
  justify-content: center;
  color: #334155;
}

.story-formula.fragment.condition.ok {
  color: #1f3f7a;
}

.story-formula.fragment.condition.fail {
  color: #8a5a00;
}

.story-formula.implies {
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: #7a8796;
  box-shadow: none;
  font-size: 1.34rem;
}

.story-formula.check {
  background: rgba(255, 255, 255, 0.86);
}

.story-formula.check.ok {
  color: #1f3f7a;
  border-color: rgba(140, 188, 255, 0.58);
}

.story-formula.check.fail {
  color: #8a5a00;
  border-color: rgba(214, 166, 77, 0.72);
}

.story-formula.result {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
}

.story-formula.result.in-set {
  color: #1e6b2a;
  border-color: rgba(136, 185, 137, 0.82);
}

.story-formula.result.out-set {
  color: #8a5a00;
  border-color: rgba(214, 166, 77, 0.82);
}

.story-shell:not(.story-ready) .story-cell,
.story-shell:not(.story-ready) .story-formula,
.story-shell:not(.story-ready) .story-canvas,
.story-shell:not(.story-ready) .story-canvas-content {
  transition: none;
}

.story-cell.u {
  border-color: #8cbcff;
  background: #e8f2ff;
}

.story-cell.s,
.story-cell.outer {
  border-color: #f0b563;
  background: #fff0d8;
}

.story-cell.inner {
  border-color: #4f9f64;
  background: #e8f7ec;
}

.story-cell.unit {
  border-color: #9d8be2;
  background: #f0edff;
}

.story-cell.lower {
  border-color: #64748b;
  background: #f1f5f9;
}

.story-cell.omega-lower {
  border-color: #8cbcff;
  background: #e8f2ff;
}

.story-cell.omega-upper {
  border-color: #f0b563;
  background: #fff0d8;
}

.story-cell.domino-lower {
  border-color: #76a9e8;
  background: #dceeff;
  border-radius: 6px;
}

.story-cell.domino-upper {
  border-color: #d99a38;
  background: #ffe6bb;
  border-radius: 6px;
}

.story-cell.domino-open {
  border-color: #111827;
  box-shadow:
    0 0 0 2px rgba(17, 24, 39, 0.42),
    0 10px 24px rgba(17, 24, 39, 0.12);
}

.story-cell.domino-closed {
  border-color: #6b7280;
  filter: saturate(0.78);
  box-shadow:
    0 0 0 1px rgba(107, 114, 128, 0.28),
    0 8px 18px rgba(17, 24, 39, 0.08);
}

.story-cell.domino-spin-vertical {
  border-color: #111827;
  background: #fff7c7;
  box-shadow:
    0 0 0 2px rgba(17, 24, 39, 0.5),
    0 8px 22px rgba(17, 24, 39, 0.12);
}

.story-cell.domino-in-chain {
  box-shadow: 0 8px 20px rgba(17, 24, 39, 0.1);
}

.story-cell.domino-muted {
  opacity: 0.45;
  filter: saturate(0.72);
}

.story-cell.input {
  border-color: #8f9baa;
  background: #fff;
}

.story-scroll {
  position: relative;
  min-width: 0;
  padding: 0 0 70vh;
}

.story-card {
  display: grid;
  align-content: center;
  padding: 18px;
  border: 1px solid rgba(188, 198, 211, 0.74);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 40px rgba(24, 32, 42, 0.055);
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.story-guide {
  position: sticky;
  top: 16px;
  min-height: 220px;
}

.story-guide {
  border-color: rgba(188, 198, 211, 0.66);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 42px rgba(24, 32, 42, 0.06);
}

.story-scroll-marker {
  height: calc(58vh * var(--story-marker-weight, 1));
  min-height: calc(360px * var(--story-marker-weight, 1));
}

.story-card h3 {
  margin: 0 0 10px;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.story-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.story-card-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 0;
  color: var(--muted);
  line-height: 1.48;
  list-style: none;
}

.story-card-list li {
  position: relative;
  padding-left: 14px;
}

.story-card-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #9aa6b2;
}

.story-empty {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.sidebar {
  border-width: 0 1px 0 0;
  border-radius: 8px 0 0 8px;
  padding: 14px;
  background: #fbfcfe;
}

.meta {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.step-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin: 16px 0;
}

#step-counter {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.step-list {
  display: grid;
  gap: 6px;
}

.step-phase {
  margin: 12px 0 4px;
  padding: 5px 8px;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: #f1f6ff;
  color: var(--accent-ink);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.step-button {
  width: 100%;
  min-height: 36px;
  text-align: left;
  border-color: var(--line);
  font-weight: 600;
}

.step-button.active {
  border-color: var(--accent);
  background: #eef5ff;
}

.step-container {
  min-height: 560px;
  border: 0;
  border-radius: 0 8px 8px 0;
  padding: 22px;
  overflow: auto;
}

.step-explanation {
  margin-bottom: 14px;
}

.step-explanation h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.description {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.construction-board {
  display: grid;
  gap: 16px;
  min-height: 260px;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, #fbfcfe);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.construction-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-start;
}

.input-board-row {
  justify-content: flex-start;
}

.construction-board-block {
  min-width: 0;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.construction-board-block:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.rows-pre {
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.5;
  white-space: pre;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  align-items: start;
}

.panel-grid.two {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.panel {
  padding: 12px;
  overflow: auto;
}

.panel-title,
.panel-subtitle {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
}

.panel-subtitle {
  margin-top: 12px;
}

.tableau,
.domino-tableau {
  display: inline-grid;
  gap: 0;
  padding: 2px;
}

.tableau .tableau-cell {
  margin: 0;
}

.split-view {
  display: grid;
  gap: 14px;
}

.split-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.split-replay-button {
  min-height: 34px;
}

.split-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.split-stage {
  display: grid;
  grid-template-columns: minmax(180px, max-content) 46px minmax(220px, 1fr);
  gap: 12px;
  align-items: center;
}

.split-stage .panel {
  transition: opacity 280ms ease, transform 420ms ease, box-shadow 420ms ease;
}

.split-targets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, max-content));
  gap: 12px;
  align-items: start;
}

.split-arrow {
  color: var(--accent-ink);
  font-size: 1.8rem;
  font-weight: 900;
  text-align: center;
  opacity: 0.45;
  transform: scaleX(0.75);
  transition: opacity 300ms ease, transform 420ms ease;
}

.split-target-panel {
  opacity: 0.28;
  transform: translateX(-18px);
}

.split-stage.played .split-target-panel {
  opacity: 1;
  transform: translateX(0);
}

.split-stage.played .split-arrow {
  opacity: 1;
  transform: scaleX(1);
}

.split-stage.played .split-source-panel {
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.1);
}

.split-source-panel .split-u-cell,
.split-source-panel .split-s-cell {
  transition: transform 420ms ease, opacity 420ms ease, background 420ms ease;
}

.split-stage.played .split-source-panel .split-u-cell {
  transform: translateX(-7px);
}

.split-stage.played .split-source-panel .split-s-cell {
  transform: translateX(7px);
}

.domino-grid {
  position: relative;
  padding: 0;
  overflow: visible;
}

.domino-grid .tableau-cell {
  margin: 0;
}

.omega-tableau {
  display: inline-grid;
  gap: 0;
  padding: 2px;
}

.omega-tableau .tableau-cell {
  margin: 0;
}

.tableau-row {
  display: flex;
}

.tableau-cell {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #2f3b48;
  margin-left: -1px;
  margin-top: -1px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tableau-cell.blank {
  border-color: transparent;
  background: transparent;
}

.tableau-cell.inner {
  background: #fff;
  border-color: #cfd7e3;
  border-style: dashed;
}

.tableau-cell.switched-cell {
  outline: 3px solid #1f6feb;
  outline-offset: -4px;
}

.tableau-cell.split-u-cell {
  background: #e8f2ff;
  border-color: #8cbcff;
}

.tableau-cell.split-s-cell {
  background: #fff0d8;
  border-color: #f0b563;
}

.omega-lower-cell {
  background: #f1f8ff;
  border-color: #8bb4e5;
}

.omega-upper-cell {
  background: #fff8e7;
  border-color: #d6a64d;
}

.d-map-wrapper {
  display: grid;
  gap: 14px;
}

.d-map-view {
  display: grid;
  grid-template-columns: minmax(220px, max-content) auto minmax(220px, 1fr);
  gap: 14px;
  align-items: center;
}

.d-map-arrow {
  color: var(--accent-ink);
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-style: italic;
  font-size: 2.2rem;
  font-weight: 800;
  text-align: center;
}

.d-map-arrow::after {
  content: "→";
  margin-left: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1.8rem;
  font-weight: 900;
}

.d-map-legend {
  display: grid;
  gap: 8px;
  width: min(560px, 100%);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.d-map-legend-row {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) 28px minmax(150px, 1fr);
  gap: 10px;
  align-items: center;
}

.component,
.sample-domino {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid currentColor;
  border-radius: 6px;
  font-weight: 800;
}

.component.lower,
.domino-tile.source-lower {
  border-color: #8bb4e5;
}

.component.upper,
.domino-tile.source-upper {
  border-color: #d6a64d;
}

.component.lower {
  background: #f1f8ff;
  color: #285f9d;
}

.component.upper {
  background: #fff8e7;
  color: #7b5a16;
}

.sample-domino {
  justify-content: center;
  background: #fff;
  color: var(--ink);
}

.sample-domino.vertical::before,
.sample-domino.horizontal::before {
  content: "";
  display: inline-block;
  margin-right: 8px;
  border: 2px solid #1f2937;
  border-radius: 4px;
  background: #fff;
}

.sample-domino.vertical::before {
  width: 14px;
  height: 26px;
}

.sample-domino.horizontal::before {
  width: 28px;
  height: 14px;
}

.d-map-small-arrow {
  color: var(--accent-ink);
  font-size: 1.2rem;
  font-weight: 900;
  text-align: center;
}

.omega-build {
  display: grid;
  gap: 12px;
}

.omega-build-text {
  margin: 0;
  color: var(--ink);
  line-height: 1.5;
}

.omega-count-table {
  width: max-content;
  max-width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.omega-count-table th,
.omega-count-table td {
  min-width: 72px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  text-align: center;
}

.omega-count-table th {
  background: #f8fafc;
  font-weight: 800;
}

.omega-m-rows {
  display: grid;
  gap: 6px;
}

.omega-m-row {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  line-height: 1.4;
}

.final-info {
  display: grid;
  gap: 10px;
}

.final-status {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.final-status.in-set {
  border-color: #88b989;
  background: #f1fbf1;
}

.final-status.out-set {
  border-color: #d6a64d;
  background: #fff8e7;
}

.final-status-main {
  font-size: 1.05rem;
  font-weight: 900;
}

.final-status-sub {
  color: var(--muted);
  line-height: 1.45;
}

.final-parity-rows {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.final-parity-row {
  padding: 8px 10px;
  border: 1px solid rgba(100, 116, 139, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.62);
  font-weight: 800;
}

.final-note {
  margin: 0;
  color: var(--ink);
  line-height: 1.5;
}

.domino-tile {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #1f2937;
  border-radius: 5px;
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.domino-label {
  position: relative;
  z-index: 2;
}

.chain-order-badge {
  position: absolute;
  top: 2px;
  left: 3px;
  z-index: 3;
  min-width: 2.15em;
  padding: 2px 5px;
  border: 1px solid #111827;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #111827;
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-size: 0.76rem;
  font-style: italic;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
}

.domino-tile.moved {
  outline: 3px solid #111827;
  outline-offset: -5px;
}

.domino-tile.selected {
  opacity: 1;
  outline: 4px solid #111827;
  outline-offset: -6px;
}

.domino-tile.faded {
  opacity: 0.23;
}

.arrow-blank {
  position: relative;
  border-color: #b9c2d0;
  border-style: dashed;
  background: rgba(255, 255, 255, 0.55);
}

.arrow-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: visible;
}

.theta-arrow {
  stroke: #111827;
  stroke-width: 2.4;
  stroke-linecap: round;
  opacity: 0.88;
}

.arrow-box {
  color: var(--ink);
}

.compact-list {
  margin: 0;
  padding-left: 18px;
  line-height: 1.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
}

.muted {
  color: var(--muted);
}

.theta-info {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.chain-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.chain-button {
  display: grid;
  grid-template-columns: minmax(4.8em, max-content) minmax(0, 1fr);
  column-gap: 8px;
  row-gap: 2px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  font-weight: 700;
}

.chain-button.open::before,
.chain-button.closed::before {
  display: inline-block;
  grid-row: 1 / span 2;
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.chain-button.all {
  grid-template-columns: minmax(0, 1fr);
}

.chain-button.open .chain-main,
.chain-button.closed .chain-main,
.chain-button.open .chain-sequence,
.chain-button.closed .chain-sequence {
  grid-column: 2;
}

.chain-main {
  line-height: 1.2;
}

.chain-sequence {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.25;
}

.chain-button.open::before {
  content: "open";
}

.chain-button.closed::before {
  content: "closed";
}

.chain-button:hover,
.chain-button:focus-visible {
  border-color: #111827;
  background: #f5f7fa;
}

.chain-button.active {
  border-color: var(--accent);
  background: #eef5ff;
  color: var(--accent-ink);
}

.chain-button.active::before {
  color: var(--accent-ink);
}

.chain-button.active .chain-sequence {
  color: #496174;
}

.switch-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.switch-setup {
  display: grid;
  grid-template-columns: max-content 24px max-content 36px max-content;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 4px;
}

.switch-setup-panel {
  min-width: max-content;
  transition: opacity 280ms ease, transform 360ms ease;
}

.switch-setup-symbol {
  color: var(--accent-ink);
  font-size: 1.35rem;
  font-weight: 900;
  text-align: center;
}

.switch-target-panel {
  box-shadow: inset 0 0 0 1px rgba(31, 111, 235, 0.12);
}

.switch-player {
  display: grid;
  gap: 12px;
  max-width: 100%;
}

.switch-controls {
  display: grid;
  grid-template-columns: minmax(140px, max-content) auto minmax(140px, max-content);
  gap: 10px;
  align-items: center;
  justify-content: start;
}

.switch-counter {
  color: var(--muted);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.switch-slider {
  width: min(520px, 100%);
  accent-color: var(--accent);
}

.switch-frame-host {
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 4px;
}

.switch-frame {
  display: inline-block;
  min-width: min(430px, 88vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.frame-title {
  font-weight: 800;
  margin-bottom: 4px;
}

.move-caption {
  min-height: 1.4em;
  margin-bottom: 10px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
}

.switch-combined {
  position: relative;
  display: inline-grid;
  gap: 0;
  overflow: visible;
}

.switch-combined .tableau-cell {
  margin: 0;
}

.switch-inner-cell {
  background: #eaf3ff;
  border-color: #1f6feb;
}

.switch-outer-cell {
  background: #fff2cf;
  border-color: #b7791f;
}

.switch-target-cell {
  background: #eef8ed;
  border-color: #75a66f;
}

.switch-combined.animating-switch .tableau-cell.switched-cell {
  color: transparent;
}

.switch-flying-cell {
  position: absolute;
  z-index: 5;
  margin: 0;
  pointer-events: none;
  box-shadow: 0 8px 18px rgba(24, 32, 42, 0.18);
  transition: transform 480ms cubic-bezier(0.2, 0.8, 0.22, 1), opacity 480ms ease;
}

.switch-flying-cell.moving {
  opacity: 0.82;
  transform: translate(var(--switch-dx), var(--switch-dy));
}

.switch-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.switch-connector {
  stroke: #1f6feb;
  stroke-width: 3;
  stroke-linecap: round;
  opacity: 0.9;
}

.switch-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.legend-item::before {
  content: "";
  width: 13px;
  height: 13px;
  border: 1px solid currentColor;
  border-radius: 3px;
}

.legend-item.inner::before {
  background: #eaf3ff;
  border-color: #1f6feb;
}

.legend-item.outer::before {
  background: #fff2cf;
  border-color: #b7791f;
}

.switch-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  align-items: start;
}

@media (max-width: 840px) {
  .header,
  .viewer,
  .story-shell {
    grid-template-columns: 1fr;
  }

  .mode-bar {
    display: block;
    justify-content: stretch;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: min(100%, calc(100vw - 20px));
    min-width: 0;
  }

  .mode-button {
    flex: 1;
    min-width: 0;
  }

  .story-sticky {
    top: 8px;
    z-index: 4;
    padding: 14px;
  }

  .story-scroll {
    padding: 8px 0 38vh;
  }

  .story-guide {
    display: none;
  }

  .story-scroll-marker {
    height: calc(36vh * var(--story-marker-weight, 1));
    min-height: calc(220px * var(--story-marker-weight, 1));
  }

  .sidebar {
    border-width: 0 0 1px 0;
    border-radius: 8px 8px 0 0;
  }

  .step-container {
    border-radius: 0 0 8px 8px;
  }

  .d-map-view {
    grid-template-columns: 1fr;
  }

  .d-map-arrow::after {
    content: "↓";
    display: block;
    margin: 4px 0 0;
  }

  .d-map-legend-row {
    grid-template-columns: 1fr 24px 1fr;
  }
}

@media (max-width: 560px) {
  .layout {
    width: 100%;
    padding: 16px 10px 32px;
  }

  .header {
    gap: 12px;
    margin-bottom: 12px;
  }

  .eyebrow {
    font-size: 0.74rem;
  }

  h1 {
    font-size: 2.05rem;
  }

  .header-note {
    font-size: 0.9rem;
  }

  .header-side {
    display: none;
  }

  textarea {
    min-height: 82px;
  }

  .input-panel,
  .sidebar,
  .step-container,
  .story-sticky {
    padding: 12px;
  }

  .input-panel {
    margin-bottom: 12px;
  }

  .actions button {
    width: 100%;
  }

  .random-row {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .random-row button {
    width: 100%;
  }

  .random-note,
  .hint {
    font-size: 0.86rem;
    overflow-wrap: anywhere;
  }

  .random-note {
    display: none;
  }

  .mode-bar {
    margin-bottom: 10px;
  }

  .mode-tabs {
    grid-template-columns: 1fr;
    width: 100%;
    border-radius: 7px;
  }

  .mode-button {
    padding: 8px 8px;
    min-width: 0;
    overflow: hidden;
    font-size: 0.86rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #detail-mode-button {
    font-size: 0;
  }

  #detail-mode-button::after {
    content: "Step";
    font-size: 0.86rem;
  }

  .story-jump-nav {
    top: auto;
    right: 12px;
    bottom: 14px;
    transform: none;
  }

  .story-jump-button {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.96);
  }

  .map-progress {
    gap: 5px;
    margin-bottom: 10px;
    font-size: 0.76rem;
  }

  .map-progress-token {
    min-height: 24px;
    padding: 2px 6px;
  }

  .map-progress-map {
    min-width: 30px;
    min-height: 26px;
    padding: 0 3px 1px;
  }

  .map-progress-arrow {
    font-size: 0.95rem;
  }

  .story-title {
    margin-bottom: 5px;
    font-size: 1.18rem;
  }

  .story-subtitle {
    margin-bottom: 9px;
    font-size: 0.88rem;
    line-height: 1.34;
  }

  .story-rule {
    margin: -1px 0 9px;
    padding: 6px 8px;
    font-size: 0.8rem;
  }

  .story-fact-tray {
    justify-content: stretch;
    margin-top: 8px;
  }

  .story-fact-line {
    justify-self: stretch;
    max-width: 100%;
    font-size: 0.84rem;
    text-align: right;
  }

  .story-stage {
    min-height: 340px;
    border-radius: 7px;
  }

  .step-nav {
    grid-template-columns: 1fr 1fr;
  }

  #step-counter {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
  }

  #prev-step {
    grid-column: 1;
    grid-row: 2;
  }

  #next-step {
    grid-column: 2;
    grid-row: 2;
  }

  .panel-grid,
  .panel-grid.two,
  .theta-info,
  .switch-overview,
  .switch-pair {
    grid-template-columns: 1fr;
  }

  .switch-controls {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .d-map-legend-row {
    grid-template-columns: 1fr;
  }

  .d-map-small-arrow {
    text-align: left;
  }
}
