@font-face {
  font-family: 'Source Sans 3';
  src: url('fonts/source-sans-3.ttf') format('truetype');
  font-style: normal;
  font-weight: 200 900;
  font-display: block;
}
@font-face {
  font-family: 'Source Serif 4';
  src: url('fonts/source-serif-4.ttf') format('truetype');
  font-style: normal;
  font-weight: 200 900;
  font-display: block;
}

:root {
  color-scheme: light;
  font: 16px/1.5 'Source Sans 3', 'Segoe UI', sans-serif;
  color: #232c2d;
  background: #fff;
}

html { overflow-y: scroll; scrollbar-gutter: stable; }
* { box-sizing: border-box; }
main { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }
header { display: flex; gap: 24px; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; }
h1 { font-family: 'Source Serif 4', Georgia, serif; font-size: clamp(1.9rem, 3vw, 2.35rem); font-weight: 500; line-height: 1.15; letter-spacing: -.025em; margin: 0 0 10px; }
header p { color: #4e5b5e; margin: 0; max-width: 760px; }
.workspace { display: grid; grid-template-columns: 1.15fr 1fr; align-items: start; gap: 20px; }
.panel { background: white; border: 0; border-top: 1px solid #cbd4d1; border-radius: 0; padding: 20px 0; box-shadow: none; }
.sidebar { display: grid; gap: 20px; }
h2 { font-family: 'Source Serif 4', Georgia, serif; font-size: 1.3rem; font-weight: 550; line-height: 1.25; margin: 0 0 16px; }
button { font: inherit; font-size: .9rem; color: inherit; border: 1px solid #cbd5e1; background: white; border-radius: 3px; padding: 7px 11px; cursor: pointer; }
button:hover { background: #f1f5f9; }
button[aria-pressed="true"] { background: #254d67; color: white; border-color: #254d67; }
button:focus-visible, input:focus-visible { outline: 2px solid #2563eb; outline-offset: 3px; }
.modes, .presets { display: flex; flex-wrap: wrap; gap: 8px; }
.modes { margin-bottom: 20px; }
.diagram { border: 1px solid #dfe4e2; border-radius: 0; padding: 12px; }
svg { width: 100%; height: auto; display: block; }
[data-region][hidden] { display: none; }
.model-note { font-size: .85rem; color: #4e5b5e; margin: 15px 0 0; }
.controls label { display: flex; justify-content: space-between; gap: 12px; }
output { font-weight: 700; }
input[type="range"] { width: 100%; margin: 12px 0 23px; accent-color: #254d67; cursor: pointer; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats div { border: 0; border-left: 1px solid #cbd4d1; padding: 8px 12px; border-radius: 0; }
.stats span { display: block; color: #657276; font-size: .85rem; }
.stats strong { font-size: 1.1rem; }
.explanation { background: #f3f5f3; border-left: 2px solid #b7c5c2; border-radius: 0; padding: 10px 14px; font-size: .9rem; margin: 15px 0 0; }
.formulas { margin-top: 20px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.formulas h2 { font-size: 1rem; margin-bottom: 6px; }
.formulas p { color: #4e5b5e; font-size: .9rem; margin: 0; }
@media (max-width: 980px) {
  header { flex-direction: column; align-items: flex-start; gap: 12px; }
}
@media (max-width: 740px) {
  main { padding: 20px 14px; }
  .workspace, .formulas { grid-template-columns: 1fr; }
  .panel { padding: 16px 0; }
}
body { margin: 0; }
body > main { max-width: 1400px; margin-left: 220px; }
.site-nav { position: fixed; inset: 0 auto 0 0; width: 220px; padding: 30px 16px; background: #f5f7f5; border-right: 1px solid #dfe4e2; }
.brand { display: block; color: #203b49; font-family: 'Source Serif 4', Georgia, serif; font-size: 1.85rem; font-weight: 600; letter-spacing: -.035em; text-decoration: none; padding: 0 12px; margin-bottom: 28px; }
.site-nav nav { display: grid; gap: 6px; }
.site-nav nav a { padding: 9px 12px; border-radius: 0; border-left: 2px solid transparent; color: #4e5b5e; text-decoration: none; font-size: .95rem; }
.site-nav nav a:hover { background: #f1f5f9; }
.site-nav nav a[aria-current="page"] { color: #254d67; background: #e9eeeb; border-left-color: #254d67; font-weight: 650; }
a:focus-visible, select:focus-visible { outline: 2px solid #2563eb; outline-offset: 3px; }
.dice-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
#dice-form { display: grid; gap: 8px; }
#dice-form input, #dice-form select { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 3px; color: inherit; background: white; font: inherit; }
#dice-form label { font-weight: 600; }
.field-help { font-size: .8rem; color: #657276; margin: 0 0 12px; }
.primary { background: #254d67; color: white; border-color: #254d67; margin-top: 12px; padding: 10px; }
.primary:hover { background: #19394e; }
.error { color: #b91c1c; margin: 6px 0 0; font-size: .9rem; }
.error:empty { display: none; }
.last-roll { display: flex; gap: 14px; align-items: center; margin-top: 24px; color: #4e5b5e; }
[hidden] { display: none !important; }
.die-symbol { font-family: "Segoe UI Symbol", sans-serif; font-size: 4.5rem; line-height: 1; color: #254d67; }
.distribution-heading { margin: 24px 0 0; }
#chart-caption { margin: 4px 0 30px; }
.dice-chart { height: 115px; display: flex; gap: 12px; position: relative; border-bottom: 1px solid #94a3b8; margin: 0 28px 32px 0; }
.bar-column { flex: 1; position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; }
.bar { width: 70%; background: #cbd5e1; border-radius: 5px 5px 0 0; flex-shrink: 0; }
[data-selected] .bar { background: #2563eb; }
.bar-value { font-size: .75rem; white-space: nowrap; padding-bottom: 5px; }
.bar-face { position: absolute; bottom: -25px; font-weight: 650; font-size: .85rem; }
.theoretical-line { position: absolute; z-index: 1; bottom: var(--theoretical-height, 58%); width: 100%; border-top: 1px dashed #657276; pointer-events: none; }
.theoretical-line span { position: absolute; right: -29px; top: -12px; font-size: .75rem; color: #4e5b5e; background: white; }
@media (max-width: 1120px) {
  .workspace { grid-template-columns: 1fr; }
}
@media (max-width: 740px) {
  .site-nav { position: static; width: auto; padding: 16px 14px; border-right: 0; border-bottom: 1px solid #dfe4e2; }
  .brand { margin: 0 0 10px; padding: 0; }
  .site-nav nav { display: flex; flex-wrap: wrap; }
  body > main { margin-left: 0; }
  .dice-chart { gap: 6px; }
}

.playback { display: flex; gap: 8px; }
#simulation-state:empty { display: none; }
#roll-progress { width: 100%; height: 8px; accent-color: #254d67; }
.convergence { margin-top: 18px; }
.convergence .model-note { margin: 0 0 6px; font-size: .8rem; }
.convergence svg { height: auto; min-height: 260px; }
@media (prefers-reduced-motion: no-preference) {
  [data-running] .die-symbol { animation: rolling-die .45s ease-in-out infinite alternate; }
  .bar { transition: height .12s linear; }
}
@keyframes rolling-die {
  from { transform: rotate(-12deg) translateY(-3px); }
  to { transform: rotate(12deg) translateY(3px); }
}
.dice-results > h2 { margin-bottom: 6px; }
.dice-stats div { padding: 6px 10px; }
.dice-stats strong { font-size: 1rem; }
.dice-results .distribution-heading { margin-top: 16px; }
.dice-results #chart-caption { margin: 4px 0 18px; font-size: .8rem; }
.convergence h2 { margin-bottom: 4px; font-size: 1rem; }
@media (max-width: 960px) {
  .dice-layout { grid-template-columns: 1fr; }
}
@media (min-width: 1120px) {
  .dice-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.dice-results { font-variant-numeric: tabular-nums; }

.arrangement-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
#arrangement-form { display: grid; gap: 10px; }
#arrangement-form > label { font-weight: 600; }
#arrangement-form > input { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 3px; font: inherit; }
.repetition-choice { display: grid; gap: 10px; margin: 8px 0; padding: 12px; border: 1px solid #dfe4e2; border-radius: 4px; }
.repetition-choice label { font-size: .9rem; }
.repetition-choice input { accent-color: #254d67; }
.arrangement-formula { margin: 12px 0; font-size: 1.3rem; }
.arrangement-formula sub, .arrangement-formula sup { font-size: .7em; }
.arrangement-total { margin: 0; font-size: 1.6rem; font-weight: 600; color: #254d67; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.arrangement-result h3 { font-size: .9rem; color: #4e5b5e; margin: 28px 0 12px; font-weight: 600; }
.token-reserve { display: flex; flex-wrap: wrap; gap: 10px; min-height: 48px; }
.arrangement-token { display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; width: 46px; height: 46px; background: hsl(var(--token-hue) 75% 92%); border: 2px solid hsl(var(--token-hue) 55% 48%); border-radius: 6px; color: hsl(var(--token-hue) 65% 25%); font-weight: 750; font-size: 1.2rem; }
.token-used { visibility: hidden; }
.arrangement-slots { display: flex; gap: 12px; flex-wrap: wrap; }
.arrangement-position { width: 82px; text-align: center; }
.arrangement-slot { width: 64px; height: 64px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 2px dashed #cbd5e1; border-radius: 5px; color: #657276; font-size: 1.1rem; background: #f8fafc; }
.position-choices { display: block; margin-top: 8px; font-size: .8rem; color: #4e5b5e; min-height: 36px; }
.arrangement-product { min-height: 36px; margin: 24px 0 8px; font-size: 1.4rem; font-weight: 650; color: #254d67; }
.arrangement-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.arrangement-actions .primary { margin: 0; }
.arrangement-actions button:disabled { opacity: .6; cursor: default; }
.flying-token { position: fixed; z-index: 10; pointer-events: none; }
@media (max-width: 960px) { .arrangement-layout { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: no-preference) { .arrangement-slot .arrangement-token { animation: token-placed .25s ease-out; } }
@keyframes token-placed { from { transform: scale(.85); } to { transform: scale(1); } }

#combination-form { display: grid; gap: 10px; }
#combination-form > label { font-weight: 600; }
#combination-form > input { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 3px; font: inherit; }
.combination-basket { width: max(90px, calc(var(--selection-count, 1) * 58px + 32px)); max-width: 100%; display: flex; gap: 12px; flex-wrap: wrap; min-height: 90px; padding: 20px; border: 2px dashed #cbd5e1; border-radius: 5px; background: #f8fafc; }
.combination-placeholder { display: block; width: 46px; height: 46px; border-radius: 6px; border: 2px dashed #cbd5e1; }

.urn-form { display: grid; gap: 10px; }
.urn-form > label { font-weight: 600; }
.urn-form > input { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 3px; font: inherit; }
.urn { display: flex; align-content: flex-end; justify-content: center; gap: 7px; flex-wrap: wrap; min-height: 150px; border: 3px solid #94a3b8; border-top: 0; border-radius: 0 0 30px 30px; padding: 15px 10px; margin-top: 24px; background: linear-gradient(0deg, #eff6ff, white); }
.urn-ball { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; color: white; font-size: .8rem; font-weight: 700; box-shadow: inset -3px -3px 5px #0002; flex-shrink: 0; }
.urn-ball[data-color="R"] { background: #e11d48; }
.urn-ball[data-color="B"] { background: #2563eb; }
.urn-actions { display: grid; gap: 8px; margin-top: 14px; }
.urn-actions .primary { margin: 0; }
.drawn-balls { display: flex; gap: 20px; min-height: 44px; align-items: center; justify-content: center; margin-top: 18px; }
.draw-position { display: flex; align-items: center; justify-content: center; width: 42px; height: 42px; border: 1px dashed #94a3b8; border-radius: 50%; color: #657276; }
.flying-ball { position: fixed; z-index: 10; pointer-events: none; }
.tree-panel .model-note { margin: 0; }
#probability-tree { margin: 12px 0; }
.tree-branch { fill: none; stroke: #cbd5e1; stroke-width: 3; }
.tree-branch.impossible { stroke-dasharray: 5 5; opacity: .5; }
.tree-probability { font-size: 17px; fill: #4e5b5e; paint-order: stroke; stroke: white; stroke-width: 8px; stroke-linejoin: round; }
.tree-node-label { fill: white; font-size: 15px; font-weight: 700; text-anchor: middle; }
.tree-stage { fill: #657276; font-size: 15px; text-anchor: middle; }

.coin { width: 90px; height: 90px; margin: 26px auto 20px; border: 6px double #a16207; border-radius: 50%; background: radial-gradient(circle at 30% 25%, #fef3c7, #fbbf24); color: #854d0e; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 750; box-shadow: 0 7px 0 #a16207, 0 10px 18px #0f172a15; }
.coin[data-side="pile"] { background: radial-gradient(circle at 30% 25%, #f1f5f9, #94a3b8); color: #334155; border-color: #657276; box-shadow: 0 7px 0 #657276, 0 10px 18px #0f172a15; }
.coin-stats strong { font-variant-numeric: tabular-nums; }
.binomial-panel .model-note { margin: 0; }
.binomial-panel svg { margin-top: 12px; }
.binomial-product { min-height: 48px; margin: 8px 0 18px; font-weight: 650; color: #254d67; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.binomial-axis { stroke: #94a3b8; fill: none; }
.binomial-label { font-size: 13px; fill: #4e5b5e; }
.binomial-bar { fill: #cbd5e1; }
.binomial-bar[data-selected] { fill: #2563eb; }
.binomial-bar[data-observed] { fill: #d97706; }
.binomial-grid { stroke: #dfe4e2; }
@media (prefers-reduced-motion: no-preference) {
  .coin[data-running] { animation: coin-flip .4s linear infinite; }
  .binomial-bar { transition: y .2s, height .2s; }
}
@keyframes coin-flip { 0% { transform: rotateY(0deg) translateY(0); } 50% { transform: rotateY(180deg) translateY(-12px); } 100% { transform: rotateY(360deg) translateY(0); } }

.card-controls { display: grid; gap: 12px; }
.card-controls label { font-weight: 600; }
.card-controls select { width: 100%; padding: 10px 8px; border: 1px solid #cbd5e1; border-radius: 3px; background: white; color: inherit; font: inherit; font-size: .9rem; }
.card-controls .primary { margin-top: 8px; }
.card-controls .model-note { margin: 0; }
.card-deck { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 6px; padding: 16px; background: #f3f5f3; border: 1px solid #dfe4e2; border-radius: 5px; min-height: 100px; align-content: start; }
.playing-card { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 76px; background: white; border: 1px solid #cbd5e1; border-radius: 6px; color: #0f172a; opacity: .22; font-size: .85rem; font-weight: 650; }
.playing-card[data-red] { color: #be123c; }
.playing-card[data-favorable] { opacity: 1; border-color: #2563eb; box-shadow: 0 0 0 1px #2563eb; }
.card-suit { font-size: 1.35rem; line-height: 1.2; }
.playing-card[data-drawn] { opacity: 1; outline: 3px solid #d97706; outline-offset: 2px; z-index: 1; }
.card-stats { grid-template-columns: repeat(3, 1fr); margin-top: 20px; }
.card-probability { margin: 20px 0 0; font-size: 1.3rem; color: #254d67; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 1120px) and (min-width: 961px) { .card-deck { grid-template-columns: repeat(7, minmax(0, 1fr)); } }
@media (max-width: 600px) { .card-deck { grid-template-columns: repeat(7, minmax(0, 1fr)); padding: 10px; gap: 5px; } .playing-card { min-height: 60px; } .card-stats { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: no-preference) { .playing-card { transition: opacity .3s, border-color .3s; } }

.urn-ball[data-color="G"] { background: #16a34a; }

.site-nav .brand { margin-bottom: 2px; }
.brand-author { display: block; padding: 0 12px; margin-bottom: 28px; font-size: .7rem; color: #657276; letter-spacing: .035em; }
@media (max-width: 740px) { .brand-author { padding: 0; margin-bottom: 12px; } }

.tree-panel #probability-tree { height: 340px; margin: 12px 0; }
.tree-panel .tree-probability { font-size: 22px; }
.tree-panel .tree-stage { font-size: 20px; }
.tree-panel .tree-node-label { font-size: 18px; }
@media (max-width: 600px) { .tree-panel #probability-tree { height: auto; } }

.tree-paths { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tree-paths button { display: grid; gap: 3px; font-variant-numeric: tabular-nums; }
.tree-paths button span { font-weight: 700; }
.path-product { min-height: 55px; margin: 22px 0 0; font-size: 1.15rem; font-weight: 650; color: #254d67; font-variant-numeric: tabular-nums; }
@media (max-width: 740px) { .tree-paths { grid-template-columns: repeat(2, 1fr); } }

.conditional-comparison { margin-top: 16px; }
.conditional-formula { color: #254d67; font-weight: 650; line-height: 1.8; overflow-wrap: anywhere; }
.tree-branch.denominator { stroke: #d97706; stroke-width: 5; }
.tree-branch.active { stroke: #2563eb; stroke-width: 5; }

.binomial-observation { color: #92400e; margin: 0 0 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

.arrangement-formula, .arrangement-product, .card-probability, .path-product, .conditional-formula, .binomial-product {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 500;
}

.path-product:empty { display: none; }
