/* Plinko — all art is hand-authored CSS + inline SVG. No image files, no
   webfonts, no url() to any asset, no third-party CDN. */

* { box-sizing: border-box; }

:root {
  --bg-deep: #0d0819;
  --bg-card: rgba(20, 13, 36, 0.92);
  --line: rgba(185, 168, 255, 0.18);
  --text: #f1ecfc;
  --text-dim: #a89bc0;
  --gold: #ffd166;
  --gold-deep: #c98a1b;
  --accent: #8b7bff;
  --win: #4ade80;
  --lose: #fb7185;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(ellipse at 50% -10%, #3d2a70 0%, transparent 55%),
    radial-gradient(ellipse at 90% 110%, #1d1440 0%, transparent 50%),
    var(--bg-deep);
}

/* ---- Chrome ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 6, 20, 0.7);
}

.brand { display: flex; align-items: center; gap: 0.55rem; }
.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.24em;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 209, 102, 0.35);
}

/* The brand mark is a pure-CSS peg triangle. */
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background:
    radial-gradient(circle at 50% 22%, var(--gold) 0 3px, transparent 3.5px),
    radial-gradient(circle at 32% 55%, #7c6da8 0 2.4px, transparent 3px),
    radial-gradient(circle at 68% 55%, #7c6da8 0 2.4px, transparent 3px),
    radial-gradient(circle at 20% 82%, #7c6da8 0 2.4px, transparent 3px),
    radial-gradient(circle at 50% 82%, #7c6da8 0 2.4px, transparent 3px),
    radial-gradient(circle at 80% 82%, #7c6da8 0 2.4px, transparent 3px),
    linear-gradient(160deg, #241740, #140c26);
  border: 1px solid var(--line);
}

.topbar-right { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.34rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(30, 20, 52, 0.85);
  font-size: 0.82rem;
}
.pill-label { color: var(--text-dim); font-size: 0.68rem; letter-spacing: 0.1em; }
.mode-pill { color: var(--accent); font-weight: 800; letter-spacing: 0.12em; }
.mode-pill.real { color: var(--win); }
.balance-pill strong { color: var(--gold); }

.icon-btn {
  border: 1px solid var(--line);
  background: rgba(30, 20, 52, 0.85);
  color: var(--text);
  border-radius: 10px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.muted { opacity: 0.45; text-decoration: line-through; }

/* ---- Layout ---- */

.layout {
  max-width: 1060px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(240px, 1fr);
  gap: 1rem;
}
.stage { grid-column: 1; }
.controls { grid-column: 2; }
.readout, .panels { grid-column: 1 / -1; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .stage, .controls { grid-column: 1; }
}

/* ---- Board ---- */

#board {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 14px 34px rgba(0, 0, 0, 0.5));
}

.peg { fill: #9c8fd0; transition: fill 120ms ease; }
.peg.peg-hit { fill: #ffe9a8; }
.ball { filter: drop-shadow(0 2px 5px rgba(255, 209, 102, 0.55)); }

/* ---- Release chute + latch ---- */

.chute-wall {
  stroke: #6f5aa8;
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
}
.chute-ball {
  filter: drop-shadow(0 2px 5px rgba(255, 209, 102, 0.55));
  transition: opacity 90ms ease;
}
.chute-ball.spent { opacity: 0; }
.latch-pin { fill: #8f7ac9; }
.latch-door {
  fill: #b9a8ff;
  stroke: #4a3676;
  stroke-width: 0.8;
  /* view-box keeps transform-origin in the SVG's own coordinates, so the
     doors pivot on their hinge pins rather than their own bounding boxes. */
  transform-box: view-box;
  transition: transform 190ms cubic-bezier(0.34, 1.4, 0.64, 1);
}
#latchLeft { transform-origin: 223px 32px; }
#latchRight { transform-origin: 257px 32px; }
#board.latch-open #latchLeft { transform: rotate(80deg); }
#board.latch-open #latchRight { transform: rotate(-80deg); }

/* The paytable strip sits exactly under the SVG bins: the bins span
   (rows+1)*pitch = 440 of the 480 viewBox, i.e. 4.1667% padding per side. */
.bins {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0 4.1667%;
  display: grid;
  grid-template-columns: repeat(var(--bins, 9), 1fr);
  gap: 2px;
}

.bins li {
  --heat: 0;
  text-align: center;
  padding: 0.42rem 0.05rem;
  border-radius: 7px;
  font-size: clamp(0.5rem, 1.7vw, 0.78rem);
  font-weight: 800;
  color: #1c0f04;
  /* Single hue ramp: centre bins stay cool violet, the rare outer bins run
     hot to gold — all from oklch interpolation, no art files. */
  background: oklch(calc(0.52 + var(--heat) * 0.28) calc(0.06 + var(--heat) * 0.13) calc(300 - var(--heat) * 215));
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: transform 120ms ease;
}
.bins li.capped { outline: 2px dashed rgba(251, 113, 133, 0.8); }
.bins li.hit { animation: binHit 700ms ease; }

@keyframes binHit {
  0% { transform: translateY(0); box-shadow: none; }
  30% { transform: translateY(5px) scale(1.12); box-shadow: 0 0 22px rgba(255, 209, 102, 0.8); }
  100% { transform: translateY(0); }
}

.cap-note {
  margin-top: 0.45rem;
  font-size: 0.78rem;
  color: var(--lose);
}

/* ---- Controls ---- */

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  align-self: start;
}

.control-block > label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  color: var(--text-dim);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.3rem;
  background: rgba(12, 7, 24, 0.8);
}
.stepper strong { font-size: 1.05rem; color: var(--gold); }
.stepper button {
  width: 2.2rem; height: 2.2rem;
  border: 0; border-radius: 9px;
  background: #2b1d4e; color: var(--text);
  font-size: 1.2rem; cursor: pointer;
}
.stepper button:hover { background: #3a2a66; }

.chip-row { display: flex; gap: 0.3rem; margin-top: 0.45rem; flex-wrap: wrap; }
.chip-row button {
  flex: 1 1 3ch;
  padding: 0.32rem 0.2rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(30, 20, 52, 0.85);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
}
.chip-row button.active { border-color: var(--gold); color: var(--gold); }
.chip-row button:disabled { opacity: 0.32; cursor: not-allowed; }

.segment {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(12, 7, 24, 0.8);
}
.segment button {
  flex: 1;
  border: 0;
  padding: 0.55rem 0.2rem;
  background: transparent;
  color: var(--text-dim);
  font-weight: 700;
  cursor: pointer;
}
.segment button.active {
  background: linear-gradient(180deg, #4a3585, #33245e);
  color: var(--text);
}

.drop-block { display: flex; flex-direction: column; gap: 0.55rem; }

.primary {
  border: 0;
  border-radius: 13px;
  padding: 0.85rem;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  background: linear-gradient(180deg, #ffe9a8, var(--gold) 55%, var(--gold-deep));
  color: #3b2606;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(255, 209, 102, 0.25);
}
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.auto-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; color: var(--text-dim); }
.auto-row select {
  background: #1d1230; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 0.3rem 0.45rem;
}

.link-btn {
  border: 0; background: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.15rem 0;
}
.link-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Readout / history ---- */

.readout {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 1.2rem;
  align-items: start;
  padding: 0.8rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-card);
}
@media (max-width: 640px) { .readout { grid-template-columns: 1fr 1fr; } .history-wrap { grid-column: 1 / -1; } }

.hud-label {
  display: block;
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
}
.readout strong { font-size: 0.95rem; }
#lastResult.win { color: var(--win); }

.history-strip { display: flex; gap: 0.3rem; overflow-x: auto; padding-bottom: 0.2rem; }
.history-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(30, 20, 52, 0.85);
  color: var(--lose);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.28rem 0.6rem;
  cursor: pointer;
}
.history-chip.win { color: var(--win); }
.history-empty { color: var(--text-dim); font-size: 0.8rem; }

/* ---- Panels ---- */

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-card);
  padding: 0.9rem 1rem;
}
.panel h2 { margin: 0 0 0.6rem; font-size: 0.85rem; letter-spacing: 0.14em; color: var(--gold); }
.panel ul { margin: 0; padding-left: 1.1rem; color: var(--text-dim); font-size: 0.84rem; line-height: 1.55; }

.fair-grid { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.8rem; margin: 0; font-size: 0.82rem; }
.fair-grid dt { color: var(--text-dim); }
.fair-grid dd { margin: 0; overflow-wrap: anywhere; font-family: Consolas, monospace; font-size: 0.76rem; }
.fair-actions { display: flex; gap: 1rem; margin-top: 0.6rem; }

/* ---- Modal / toast ---- */

.modal-overlay {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(5, 2, 12, 0.72);
  z-index: 30;
}
/* Author `display` and the UA sheet's [hidden]{display:none} tie on specificity
   and author wins, so `hidden` alone would never hide this. */
.modal-overlay[hidden] { display: none; }
.modal-card {
  width: min(440px, 92vw);
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #170e2b;
  padding: 1.1rem 1.2rem;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { margin: 0 0 0.5rem; color: var(--gold); font-size: 1rem; }
.verify-details { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.8rem; font-size: 0.82rem; }
.verify-details dt { color: var(--text-dim); }
.verify-details dd { margin: 0; overflow-wrap: anywhere; font-family: Consolas, monospace; font-size: 0.78rem; }
.modal-card .primary { width: 100%; margin-top: 0.9rem; padding: 0.6rem; }

.toast {
  position: fixed;
  left: 50%; bottom: 1.4rem;
  transform: translateX(-50%);
  background: #2a1140;
  color: var(--text);
  border: 1px solid var(--lose);
  border-radius: 12px;
  padding: 0.6rem 1rem;
  font-size: 0.86rem;
  z-index: 40;
  max-width: min(480px, 90vw);
}

/* ---- Reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* ---- Profit practices (presentation only) ---- */
.practice-banner { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; z-index: 60; text-align: center; }
.practice-banner[hidden] { display: none; }
.practice-banner-title { font-size: clamp(28px, 7vw, 54px); font-weight: 900; letter-spacing: 2px; color: #ffd166; text-shadow: 0 2px 18px rgba(0,0,0,.65); animation: practice-pop 450ms ease-out; }
.practice-banner.win .practice-banner-title, .practice-banner.ldw .practice-banner-title { color: #9fe7b1; }
.practice-banner.big .practice-banner-title { color: #ffd166; }
.practice-banner.mega .practice-banner-title { color: #ffb703; font-size: clamp(34px, 8vw, 64px); }
.practice-banner.epic .practice-banner-title { color: #ff8fa3; font-size: clamp(38px, 9vw, 72px); }
.practice-banner.almost .practice-banner-title { color: #b9a8ff; font-size: clamp(22px, 5.5vw, 40px); }
.practice-banner-amount { font-size: clamp(20px, 5vw, 36px); font-weight: 800; color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,.6); }
@keyframes practice-pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
#lastResult.ldw { color: var(--win); }
.history-chip.ldw { color: var(--win); }
.bins li.almost { animation: binHit 700ms ease infinite; outline: 2px solid #b9a8ff; }
#board.anticipation { filter: drop-shadow(0 0 14px rgba(255,183,3,.55)); }
.chip-row button.anchor, #stakeGrid button.anchor { border-color: #ffd166; box-shadow: 0 0 0 1px #ffd166, 0 0 14px rgba(255,209,102,.45); transform: scale(1.12); font-weight: 800; }
.turbo-btn.active { color: #ffd166; border-color: #ffd166; font-weight: 800; }
.recent-wins { display: flex; align-items: center; gap: 12px; overflow: hidden; padding: 6px 2px; }
.recent-wins-strip { display: flex; gap: 14px; overflow: hidden; white-space: nowrap; }
.recent-win-row { font-size: 12px; color: #ffd166; animation: practice-pop 400ms ease-out; }
