:root {
  color-scheme: dark;
  --bg: #161725;
  --surface: #202237;
  --stage: #24263f;
  --line: #414660;
  --ink: #faf4ef;
  --muted: #c0c3d8;
  --gold: #ffcf78;
  --pink: #fcafb2;
  --green: #93e4c1;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
a { color: var(--gold); }
button, input, select { font: inherit; }
button, select, .link-button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: #292c46;
  color: var(--ink);
  border-radius: .55rem;
  padding: .45rem .75rem;
}
button, select, input[type="range"] { cursor: pointer; }
button:disabled, select:disabled, input:disabled { opacity: .6; cursor: default; }
button:not(:disabled):hover, select:not(:disabled):hover { border-color: var(--gold); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1, .brand { font-family: Georgia, serif; letter-spacing: -.04em; }
h1 { font-size: clamp(2.4rem, 6vw, 4.4rem); line-height: 1.05; }
h2 { font-size: 1.3rem; line-height: 1.3; }
p { color: var(--muted); }
.shell { width: min(100% - 2rem, 68rem); margin-inline: auto; }
.site-header { border-bottom: 1px solid #35374e; }
.navigation, nav { display: flex; align-items: center; }
.navigation { justify-content: space-between; gap: .75rem; min-height: 4.25rem; }
.brand { color: var(--gold); font-size: clamp(1.3rem, 4vw, 1.85rem); font-weight: 700; line-height: 1.12; text-decoration: none; }
nav { flex-shrink: 0; gap: clamp(.4rem, 2vw, 1.25rem); }
nav a { color: var(--muted); text-decoration: none; padding-block: .6rem; }
nav a[aria-current] { color: var(--ink); text-decoration: underline; text-decoration-color: var(--gold); text-underline-offset: .4em; }
main { padding-block: clamp(1rem, 4vw, 2.6rem) 3.5rem; }
.stage {
  background: radial-gradient(ellipse at 50% 85%, #3c3255, transparent 70%), var(--stage);
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  padding: clamp(.85rem, 3.5vw, 2.5rem);
}
.stage-head { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.stage-head p { margin-top: .55rem; }
.door-settings, .auto-buttons, .round-controls { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.door-settings { font-size: .875rem; }
.primary, button[aria-pressed="true"] {
  background: var(--gold);
  color: #231a2a;
  font-weight: 700;
  border-color: var(--gold);
}
.primary:hover, button[aria-pressed="true"]:hover { background: #ffe1a9; }
.board { display: grid; gap: .65rem; margin: clamp(1rem, 3.5vw, 2.5rem) auto; padding-block-start: 1.5rem; }
.classic { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 40rem; gap: clamp(1.25rem, 5vw, 3.5rem); }
.many { grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr)); gap: 1.25rem .35rem; }
.door {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 1px solid #b696cf;
  border-radius: .45rem;
  background: #28283c;
  overflow: visible;
  position: relative;
  perspective: 750px;
  perspective-origin: left center;
}
.door-leaf, .door-face, .door-prize {
  grid-area: 1 / 1;
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
  width: 100%;
  min-height: 44px;
  color: #fff6ed;
  font-weight: 700;
  border-radius: inherit;
}
.door-leaf {
  --thickness: 3px;
  transform-style: preserve-3d;
  transform-origin: left center;
  pointer-events: none;
}
.door-leaf::before, .door-leaf::after {
  content: '';
  position: absolute;
}
.door-leaf::before {
  content: attr(data-number);
  display: grid;
  place-items: center;
  inset: 0;
  border-radius: inherit;
  backface-visibility: hidden;
  transform: rotateY(180deg);
  background: linear-gradient(110deg, #634e70, #382b45);
  box-shadow: inset 0 0 0 2px #9578a0;
}
.door-leaf::after {
  inset: 0 0 0 auto;
  width: var(--thickness);
  transform-origin: right center;
  transform: rotateY(90deg);
  background: #ac8fb3;
}
.door-face {
  background: linear-gradient(145deg, #735887, #4b365f 68%);
  transform: translateZ(var(--thickness));
  backface-visibility: hidden;
  border-inline-end: 2px solid #ac8fb3;
}
.door-prize {
  background: #2a2c42;
  box-shadow: inset .35rem .25rem .8rem #131325aa;
}
.door::before, .door::after {
  content: '';
  position: absolute;
  z-index: 1;
  left: 0;
  width: .22rem;
  height: 12%;
  border-radius: .1rem;
  background: #c2a979;
  pointer-events: none;
}
.door::before { top: 19%; }
.door::after { bottom: 19%; }
.door-marker {
  position: absolute;
  inset: auto auto calc(100% + .25rem) 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 1;
  padding: 0 .15rem;
  border-radius: .25rem;
  color: #231a2a;
  background: var(--gold);
  font: 750 .75rem/1.1 system-ui, sans-serif;
  text-align: center;
  pointer-events: none;
}
.door.final .door-marker { background: var(--green); }
.classic .door { aspect-ratio: .73; border-radius: .75rem .75rem .3rem .3rem; box-shadow: 0 .55rem 1rem #17132566; }
.classic .door-marker {
  padding: .15rem .45rem;
  font-size: clamp(.75rem, 1.8vw, .95rem);
}
.classic .door-face, .classic .door-leaf::before, .classic .door-prize { font: 700 clamp(1.55rem, 6vw, 3.2rem) Georgia, serif; }
.classic .door-face::before { content: ''; position: absolute; inset: 8%; border: 1px solid #cfadd880; border-radius: .45rem .45rem .2rem .2rem; }
.classic .door-face::after { content: ''; position: absolute; right: 14%; top: 58%; width: .36rem; aspect-ratio: 1; border-radius: 50%; background: var(--gold); }
button.door:hover .door-face, .door.pick .door-face, .door.other .door-face { background: linear-gradient(145deg, #86629d, #583b70); }
.door.pick, .door.other { border: 2px solid var(--gold); }
.door.other { border-color: var(--pink); }
.door.final, .choice.final { border-color: var(--green); box-shadow: 0 0 0 2px var(--green); }
.classic { --swing-angle: -106deg; }
.door.open .door-leaf {
  transform: rotateY(var(--swing-angle, -96deg));
  transition: transform var(--swing-time, 1200ms) cubic-bezier(.42, .02, .24, 1);
}
.board[data-autoplay] { --swing-time: var(--autoplay-swing-time); }
.door.open.final .door-prize { background: #304444; }
.decision { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; max-width: 35rem; margin: .85rem auto; }
.choice {
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: #27283f;
  text-align: left;
  padding: .65rem .8rem;
}
.choice span { display: block; color: var(--muted); font-size: .875rem; }
.round-controls:not(:empty) { justify-content: center; }
.round-controls p { color: var(--pink); }
.game-stage { padding-block-end: .75rem; }
.game-stage .stage-head {
  display: block;
  block-size: 7.5rem;
  text-align: center;
}
.game-stage h1 { font-size: clamp(2rem, 4.5vw, 3.5rem); }
.game-door-settings {
  justify-content: flex-end;
  margin-top: .25rem;
}
.game-stage .decision {
  block-size: 5.75rem;
  margin-block-end: .35rem;
  align-items: stretch;
}
.game-stage .decision[hidden] {
  display: grid !important;
  visibility: hidden;
}
.game-stage .round-controls {
  block-size: 3.25rem;
  flex-wrap: nowrap;
  text-align: center;
}
.game-stage .round-controls button { flex-shrink: 0; }
.game-stage .round-controls p { font-size: .875rem; }
.autoplay {
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) minmax(max-content, 1fr) minmax(8rem, 1.4fr);
  align-items: end;
  gap: 1rem;
  margin-block-start: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 1rem;
  border-radius: .8rem;
}
.autoplay h2 { margin-bottom: .45rem; }
.field { display: grid; gap: .3rem; }
.field label { color: var(--muted); font-size: .875rem; font-weight: 650; }
.speed label { display: flex; gap: .5rem; justify-content: space-between; }
input[type="range"] { accent-color: var(--gold); width: 100%; margin: 0; min-height: 44px; }
select { appearance: none; padding-right: 2rem; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: right .95rem center, right .65rem center; background-size: .3rem .3rem; background-repeat: no-repeat; }
.results { margin-top: 1.85rem; }
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.panel { border: 1px solid var(--line); border-radius: .8rem; padding: clamp(.7rem, 2vw, 1.25rem); background: var(--surface); }
.panel h2 { font-size: 1.15rem; }
.panel p { margin-top: .6rem; }
table { width: 100%; border-collapse: collapse; margin: .65rem 0; font-size: .875rem; }
th, td { text-align: left; padding: .55rem .3rem; border-bottom: 1px solid var(--line); }
thead th { color: var(--muted); }
td { font-variant-numeric: tabular-nums; }
.text-button { background: transparent; border-color: transparent; padding-inline: 0; color: var(--gold); }
.intro, .lesson { max-width: 45rem; }
.intro { margin-bottom: 1.5rem; }
.intro p, .lesson p { margin-top: .7rem; }
#walk-status { margin-top: 1rem; color: var(--gold); }
.lesson section { margin-top: 2rem; }
.probability-tree { margin: 1rem 0; padding: 1rem; background: var(--surface); border-radius: .8rem; }
.probability-tree figcaption { font-weight: 700; color: var(--gold); }
.proof { border-left: 2px solid var(--gold); padding-left: 1rem; }
.bayes-equation {
  margin-block: .85rem;
  padding: 1rem .6rem;
  overflow-x: auto;
  background: var(--surface);
  border-radius: .6rem;
}
.bayes-equation math {
  width: max-content;
  margin-inline: auto;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
}
.link-button { display: inline-flex; align-items: center; margin-top: .85rem; text-decoration: none; }
.problem-copy { max-width: 45rem; margin-block: 1.5rem; }
.host-example { margin: 0; }
.host-example figcaption { font-weight: 700; }
.explanation .stage {
  max-width: 45rem;
  padding: clamp(.85rem, 2vw, 1.5rem);
}
.explanation .classic {
  max-width: 27rem;
  gap: clamp(1rem, 4vw, 2.5rem);
  margin-block: 1rem;
}
@media (max-width: 46rem) {
  .panels { grid-template-columns: 1fr; }
  .autoplay { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .speed { grid-column: 1 / -1; }
}
@media (max-width: 34rem) {
  .navigation { flex-wrap: wrap; gap: 0; padding-top: .7rem; }
  .navigation nav { flex-basis: 100%; flex-wrap: wrap; column-gap: 1rem; }
}
@media (max-width: 26rem) {
  .game-stage .decision { block-size: 7rem; }
  .game-stage .round-controls { block-size: 4.25rem; }
  .autoplay { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .door.pick, .door.other, .door.final, .choice.final { border: 3px solid Highlight; }
}

#bracket-board, .bracket-row {
  --door-gap: clamp(1rem, 4vw, 2.5rem);
  gap: var(--door-gap);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: 27rem;
  margin-inline: auto;
}
#bracket-board { margin-bottom: .45rem; }
.bracket-row { display: grid; margin-bottom: 1rem; text-align: center; font-weight: 700; }
.bracket-row > div { grid-column: span 2; }
.bracket-row span { display: block; color: var(--gold); }
.bracket-row span::before {
  content: '';
  display: block;
  height: 1rem;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 16' preserveAspectRatio='none'%3E%3Cpath d='M1 1 Q1 7 7 7 H44 Q49 7 50 15 Q51 7 56 7 H93 Q99 7 99 1' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
.bracket-row > div span { width: 100%; margin-left: auto; transition: width 1.2s ease; color: var(--pink); }
.bracket-row.revealed > div span { width: calc((100% - var(--door-gap)) / 2); }
.hundred-example { margin-top: 1rem; }

.tree-viewport { overflow-x: auto; margin-top: .7rem; }
.tree-viewport svg { display: block; margin-inline: auto; }
.tree-viewport text { text-anchor: middle; fill: var(--ink); font: 600 13px system-ui, sans-serif; }
.tree-viewport .tree-heading { fill: var(--muted); font-size: 14px; }
.tree-link { fill: none; stroke: #8e83a4; stroke-width: 1.6; }
.tree-link.impossible { stroke-dasharray: 3 4; }
.tree-start { fill: var(--gold); }
.tree-node rect { fill: #33324a; stroke: #847a99; }
.tree-node .tree-probability { fill: var(--muted); font-weight: 400; }
.tree-node.switch rect { fill: #273e39; stroke: var(--green); }
.tree-node.stay rect { fill: #42382c; stroke: var(--gold); }
.tree-node.impossible rect { fill: var(--surface); stroke-dasharray: 3 3; }
