/* Galton Board — bean machine simulator */

:root {
  --bg: #0d1117;
  --bg-panel: #151b24;
  --bg-card: #1a2230;
  --line: #2a3444;
  --text: #e6edf3;
  --text-dim: #92a0b3;
  --accent: #6ea8fe;
  --accent-2: #ffcf6e;
  --ball: #cfd8e3;
  --peg: #5b6779;
  --curve: #ff8fa3;
  --shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button, input, label { font-family: inherit; }
button, input[type="range"], input[type="checkbox"], label.toggle, .btn { cursor: pointer; }

/* ---------- header ---------- */

.topbar {
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #131a24, #0d1117);
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: .3px;
}

.tagline {
  margin: 4px 0 0;
  font-size: .82rem;
  color: var(--text-dim);
}

/* ---------- layout ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 16px;
  align-items: stretch;
  min-height: 0;
}

.board-panel {
  position: relative;
  background: radial-gradient(120% 90% at 50% 0%, #1b2534 0%, #10161f 60%, #0b1016 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 420px;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  min-height: 0;
}

/* ---------- cards ---------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 8px;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-dim);
  font-weight: 600;
}

.card-note {
  margin: 0 0 10px;
  font-size: .74rem;
  line-height: 1.45;
  color: var(--text-dim);
}

/* ---------- controls ---------- */

.btn-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.btn {
  flex: 1;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #212b3a;
  color: var(--text);
  font-size: .82rem;
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .05s;
}

.btn:hover { background: #2a3648; border-color: #3c4a5f; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1016;
}
.btn-primary:hover { background: #8ab9ff; border-color: #8ab9ff; }
.btn-primary[aria-pressed="true"] {
  background: var(--accent-2);
  border-color: var(--accent-2);
}
.btn-primary[aria-pressed="true"]:hover { background: #ffdc94; border-color: #ffdc94; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  font-weight: 500;
}
.btn-ghost:hover { color: var(--text); }

.ctl {
  display: block;
  margin: 12px 0;
}

.ctl-label {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.ctl-label b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 22px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 3px;
  background: #2f3b4d;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 3px;
  background: #2f3b4d;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--ball);
  border: 2px solid #8b98aa;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ball);
  border: 2px solid #8b98aa;
  cursor: pointer;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .76rem;
  color: var(--text-dim);
}
.toggle input { accent-color: var(--accent); }
.toggle:hover { color: var(--text); }

/* ---------- stats ---------- */

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

.stat {
  background: #131a25;
  border: 1px solid #232d3c;
  border-radius: 8px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: .68rem;
  color: var(--text-dim);
}

.stat-val {
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-note {
  margin: 10px 0 0;
  font-size: .73rem;
  line-height: 1.45;
  color: var(--text-dim);
}

/* ---------- pascal ---------- */

.pascal-wrap { overflow-x: auto; }

.pascal-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-variant-numeric: tabular-nums;
  min-width: min-content;
}

.p-row {
  display: flex;
  gap: 2px;
  justify-content: center;
  align-items: center;
}

.p-cell {
  min-width: 1.9em;
  padding: 1px 3px;
  text-align: center;
  border-radius: 4px;
  background: #131a25;
  color: var(--text-dim);
  line-height: 1.5;
}

.p-row.is-final .p-cell {
  background: rgba(110, 168, 254, .16);
  color: var(--text);
  font-weight: 600;
}

.pascal-legend {
  margin-top: 10px;
  font-size: .74rem;
  color: var(--text-dim);
  text-align: center;
}
.pascal-legend b { color: var(--accent-2); }

/* ---------- responsive ---------- */

/* Wide: a fixed-height app shell — the board fills the window, the side
   panel scrolls inside itself. */
@media (min-width: 901px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }
}

/* Narrow: board on top at a fixed slice of the viewport, controls below.
   align-content:start stops the auto-sized rows from absorbing free space and
   inflating the board to the full page height. */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    align-content: start;
    gap: 12px;
    padding: 12px;
  }
  .board-panel {
    height: 62vh;
    min-height: 320px;
    max-height: 620px;
  }
  .side-panel { overflow: visible; }
}

@media (max-width: 480px) {
  .topbar { padding: 10px 14px 8px; }
  .topbar h1 { font-size: 1.05rem; }
  .tagline { font-size: .75rem; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
