:root {
  color-scheme: dark;
  --ink: #fff9e8;
  --muted: #c9c1d5;
  --night: #130f1c;
  --panel: #241b36;
  --panel-2: #302145;
  --gold: #ffd166;
  --coral: #ff8066;
  --cyan: #65e7e0;
  --line: #655779;
  --focus: #fff2a8;
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--night); }

body {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, #422050 0, transparent 30rem),
    radial-gradient(circle at 85% 25%, #123e4a 0, transparent 28rem),
    var(--night);
  line-height: 1.55;
}

button, input { font: inherit; }
button { min-width: 44px; min-height: 44px; }

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 10;
  top: .5rem;
  left: .5rem;
  padding: .75rem;
  color: #16101e;
  background: var(--focus);
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.site-header {
  display: grid;
  gap: 1.25rem;
  max-width: 76rem;
  margin: auto;
  padding: clamp(1.25rem, 4vw, 3rem);
  align-items: end;
}

h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(2.5rem, 10vw, 6rem); line-height: .9; letter-spacing: -.06em; }
h2 { font-size: clamp(1.65rem, 4vw, 2.5rem); line-height: 1.05; margin: .25rem 0 1rem; }
h3 { line-height: 1.15; }
.eyebrow, .section-kicker { margin: 0; color: var(--cyan); font-size: .78rem; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }

.disclosure {
  max-width: 42rem;
  margin: 0;
  padding: 1rem 1.25rem;
  border: 2px solid var(--gold);
  border-radius: 1rem 1rem 1rem .2rem;
  color: #18111f;
  background: var(--gold);
  box-shadow: .45rem .45rem 0 #000;
}

.layout {
  display: grid;
  gap: 1rem;
  max-width: 76rem;
  margin: auto;
  padding: 0 1rem 2rem;
}
.loop-guide {
  display: grid;
  gap: 1rem;
  grid-column: 1 / -1;
  padding: clamp(1rem, 3vw, 1.5rem);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: #17121f;
}
.loop-guide h2 { margin-bottom: .5rem; }
.loop-guide p { margin-bottom: 0; }
.loop-steps { display: grid; gap: .45rem; margin: 0; padding-left: 1.4rem; }
.phase-status {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  border: 2px solid var(--cyan);
  border-radius: .75rem;
  font-weight: 800;
  background: #111a22;
}
.storage-notice { max-width: 38rem; }

.play-column { min-width: 0; }
.artifact-shell, .round-shell, .history-shell {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: 0 1rem 3rem #0005;
}
.artifact-shell { padding: clamp(1rem, 4vw, 2rem); border-radius: 2rem 2rem .4rem .4rem; }
.round-shell { padding: clamp(1rem, 4vw, 2rem); border-radius: .4rem .4rem 2rem 2rem; border-top: 0; }
.history-shell { padding: clamp(1rem, 3vw, 1.6rem); border-radius: 2rem .4rem 2rem 2rem; min-width: 0; }
.artifact-summary { font-size: 1.1rem; color: var(--muted); }

.rule-card, .context-disclosure, .vote-disclosure, .end-card, .result-card {
  padding: .9rem 1rem;
  border-left: .35rem solid var(--cyan);
  background: #151020;
}
.rule-card { display: grid; gap: .25rem; }
.instructions { color: var(--muted); font-size: .92rem; }

.garden {
  display: grid;
  grid-template-columns: repeat(5, minmax(44px, 1fr));
  gap: .35rem;
  max-width: 31rem;
  margin: 1.25rem auto;
  padding: .75rem;
  border: 2px solid currentColor;
  border-radius: 1.25rem;
  background: #0d0b13;
  touch-action: manipulation;
  width: 100%;
}
.garden--gold, .garden--orange { color: var(--gold); }
.garden--coral, .garden--pink { color: var(--coral); }
.garden--cyan, .garden--lime, .garden--violet { color: var(--cyan); }
.garden-cell {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 1px solid #574d63;
  border-radius: .65rem;
  color: #bcb3c5;
  background: #211a29;
  cursor: pointer;
}
.garden-cell.is-spark { color: #17101d; background: currentColor; box-shadow: 0 0 1.25rem currentColor; font-size: 1.4rem; }
.garden-cell.is-pulse { border: 2px dashed currentColor; color: currentColor; font-weight: 900; }
.garden-cell.is-blocked { color: #ffac9c; background: repeating-linear-gradient(45deg, #3b2430, #3b2430 5px, #241923 5px, #241923 10px); }
.progress { font-weight: 900; }

.artifact-reset, .quiet-button, .danger-button, .compare-button, .vote-button {
  border: 1px solid #8b7c9f;
  border-radius: .75rem;
  color: var(--ink);
  background: #21192e;
  cursor: pointer;
}
.artifact-reset, .quiet-button, .danger-button, .compare-button { padding: .65rem 1rem; }
.danger-button { border-color: var(--coral); font-weight: 800; }

fieldset { display: grid; gap: .65rem; margin: 1rem 0; padding: 0; border: 0; }
legend { margin-bottom: .5rem; font-weight: 900; }
.constraint-card {
  display: flex;
  gap: .85rem;
  min-height: 64px;
  padding: .8rem;
  border: 1px solid var(--line);
  border-radius: .85rem;
  background: #1a1424;
  cursor: pointer;
}
.constraint-card:has(input:checked) { border: 3px solid var(--gold); background: #33243b; }
.constraint-card input { width: 1.25rem; min-width: 1.25rem; accent-color: var(--gold); }
.constraint-card span { display: grid; }
.constraint-card small { color: var(--muted); }

.primary-button {
  width: 100%;
  padding: .8rem 1rem;
  border: 2px solid #1b1320;
  border-radius: .9rem;
  color: #17101d;
  background: var(--gold);
  box-shadow: .3rem .3rem 0 #000;
  font-weight: 900;
  cursor: pointer;
}
button:disabled, button[aria-disabled="true"] { cursor: not-allowed; opacity: .5; }
button:disabled { border-style: dashed; }

.outcome-grid { display: grid; gap: .75rem; margin: 1rem 0; }
.outcome-card { position: relative; padding: 1rem; border: 2px solid var(--line); border-radius: 1.25rem; background: #17121f; }
.outcome-card::before { content: "◇"; position: absolute; top: .8rem; right: .8rem; font-size: 1.5rem; }
.branch-a { border-left-color: var(--coral); }
.branch-b { border-left-color: var(--cyan); }
.outcome-card.is-selected { border-width: 4px; }
.outcome-card.is-selected::before { content: "◆"; }
.outcome-card:not(.is-selected) { opacity: .86; }
.outcome-card:not(.is-selected) .compare-button::before { content: "◇ "; }
.outcome-card.is-selected .compare-button::before { content: "◆ "; }
.divergence-note { color: var(--muted); font-size: .9rem; }
.compare-button { width: 100%; }

.voting { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.vote-row { display: grid; grid-template-columns: 1fr 44px 44px; gap: .5rem; align-items: center; margin: .6rem 0; }
.vote-button { padding: 0; font-size: 1.35rem; }
.result-card { border-left-color: var(--gold); font-size: 1.08rem; font-weight: 800; }

#history-view ul { list-style: none; margin: .65rem 0; padding-left: 1rem; border-left: 1px dashed var(--line); }
#history-view > ul { padding-left: 0; border-left: 0; }
.history-node { margin: .65rem 0; }
.history-node-row { padding-left: .4rem; border-left: 3px solid transparent; }
.history-button { width: 100%; min-height: 44px; padding: .6rem .75rem; text-align: left; border: 1px solid var(--line); border-radius: .65rem; color: var(--ink); background: #1a1424; cursor: pointer; }
.history-button[aria-current] { border: 3px solid var(--gold); }
.node-meta { display: block; padding: .15rem .7rem; color: var(--muted); font-size: .78rem; }
.history-node.status-winner > .history-node-row > .node-meta { color: var(--gold); font-weight: 900; }
.history-node.status-not-selected > .history-node-row > .history-button { border-style: dashed; }
.history-node.is-lineage > .history-node-row { border-left-color: var(--ink); }
.history-node.is-inspected > .history-node-row > .node-meta { text-decoration: underline; text-underline-offset: .2em; }
.tree-legend { padding: .65rem .75rem; border: 1px dashed var(--line); font-size: .82rem; color: var(--muted); }

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  max-width: 76rem;
  margin: auto;
  padding: 1.25rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.site-links { flex-basis: 100%; font-size: .85rem; display: flex; gap: .6rem; align-items: baseline; }
.site-links a { color: var(--muted); text-underline-offset: .2em; }
.site-links a:hover, .site-links a:focus-visible { color: var(--ink, currentColor); }
.session-reset { position: relative; max-width: 30rem; }
.reset-confirmation {
  display: grid;
  gap: .75rem;
  margin-top: .75rem;
  padding: 1rem;
  border: 2px solid var(--coral);
  border-radius: .75rem;
  color: var(--ink);
  background: var(--panel);
}
.reset-confirmation[hidden] { display: none; }
.reset-confirmation p { margin: 0; }
.reset-actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.reset-actions > * { flex: 1 1 10rem; }

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

@media (min-width: 58rem) {
  .site-header { grid-template-columns: 1fr 1fr; }
  .layout { grid-template-columns: minmax(0, 1.7fr) minmax(17rem, .8fr); padding-inline: 2rem; }
  .history-shell { position: sticky; top: 1rem; align-self: start; max-height: calc(100vh - 2rem); overflow: auto; }
  .outcome-grid { grid-template-columns: 1fr 1fr; }
  .loop-guide { grid-template-columns: 1fr 1.3fr; align-items: center; }
  .loop-steps { grid-template-columns: repeat(5, minmax(0, 1fr)); padding-left: 1.2rem; }
}

@media (prefers-reduced-motion: no-preference) {
  button { transition: transform 120ms ease, border-color 120ms ease; }
  button:not(:disabled):active { transform: translateY(2px); }
  .outcome-card { transition: border-color 120ms ease, opacity 120ms ease; }
}

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

@media (max-width: 24rem) {
  .layout { padding-inline: .5rem; }
  .artifact-shell, .round-shell, .history-shell { padding: .85rem; border-radius: .75rem; }
  .outcome-card { padding: .85rem; }
  .phase-status { padding: .65rem .75rem; }
  .garden { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .2rem; padding: .4rem; border-radius: .75rem; }
  .vote-row { grid-template-columns: minmax(0, 1fr) 44px 44px; }
  #history-view ul { padding-left: .55rem; }
  footer { align-items: stretch; }
}

@media (pointer: coarse) {
  button, .history-button { min-height: 48px; }
  .constraint-card { min-height: 72px; padding-block: 1rem; }
  .garden-cell { touch-action: manipulation; }
}

@media (forced-colors: active) {
  * { box-shadow: none !important; }
  body, .artifact-shell, .round-shell, .history-shell, .loop-guide,
  .outcome-card, .constraint-card, .reset-confirmation { color: CanvasText; background: Canvas; }
  button, .history-button, .garden-cell { color: ButtonText; background: ButtonFace; border-color: ButtonText; forced-color-adjust: auto; }
  button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid Highlight; }
  .garden-cell.is-spark, .constraint-card:has(input:checked), .outcome-card.is-selected,
  .history-button[aria-current="true"] { border: 4px double Highlight; }
  .garden-cell.is-spark::after { content: " current"; }
  .garden-cell.is-pulse { border: 3px dashed LinkText; }
  .garden-cell.is-blocked { border: 3px solid GrayText; color: GrayText; background: Canvas; }
  .history-node.status-not-selected > .history-node-row > .history-button { border: 2px dashed GrayText; }
  .outcome-card:not(.is-selected) { opacity: 1; border-style: dashed; }
  .history-node.is-lineage > .history-node-row { border-left: 4px double Highlight; }
  .phase-status, .rule-card, .context-disclosure, .vote-disclosure, .result-card { border-color: LinkText; background: Canvas; }
}
