:root {
  --bg0: #12081f;
  --bg1: #241041;
  --bg2: #3a1a63;
  --gold: #e8c15a;
  --gold-2: #fff0b8;
  --royal: #6d28d9;
  --royal-2: #a855f7;
  --panel: #0e0a16;
  --muted: #a89bc0;
  --win: #34d399;
  --lose: #e11d48;
  --die-face: #f6f3ec;
  --die-pip: #14121a;

  /* Asset seam: app.js overwrites these at boot from its ASSETS map, so
     dropping raster art into /assets/ needs no CSS edits. Each one is a
     background layer, so a missing file simply falls back to the gradient
     underneath instead of showing a broken image. */
  --asset-die: url("/assets/die.svg");
  --asset-chip: url("/assets/chip.svg");
  --asset-dice-texture: url("/assets/dice-texture.svg");

  --track-h: 14px;
  --thumb-size: 28px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: #f3effa;
  background-color: var(--bg0);
  background-image:
    radial-gradient(circle at 50% -10%, rgba(109, 40, 217, 0.55), transparent 55%),
    linear-gradient(160deg, rgba(18, 8, 31, 0.72), rgba(58, 26, 99, 0.62)),
    var(--asset-dice-texture);
  background-size: auto, auto, 320px 320px;
  background-repeat: no-repeat, no-repeat, repeat;
  background-attachment: scroll;
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1080px, 96vw);
  margin: 1rem auto;
  padding: 1rem;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(109, 40, 217, 0.14), rgba(0, 0, 0, 0.36));
  border: 1px solid rgba(232, 193, 90, 0.22);
}

/* ---- topbar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.3rem 0 0.6rem;
  flex-wrap: wrap;
}

.logo-wrap { position: relative; display: flex; align-items: center; gap: 0.6rem; }

.die-mark {
  display: inline-block;
  width: 40px;
  height: 40px;
  background: var(--asset-die) center/contain no-repeat;
  filter: drop-shadow(0 2px 8px rgba(232, 193, 90, 0.55));
}

h1 {
  margin: 0;
  font-size: clamp(1.3rem, 3.6vw, 2.1rem);
  color: var(--gold);
  letter-spacing: 0.12em;
  text-shadow: 0 2px 0 #33124f, 0 0 18px rgba(232, 193, 90, 0.35);
}

h2 { margin: 0 0 0.5rem; color: var(--gold-2); font-size: 1rem; }

.topbar-right { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.pill {
  border: 1px solid rgba(232, 193, 90, 0.35);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  background: rgba(0, 0, 0, 0.34);
  font-weight: 700;
}

.mode-pill { color: var(--royal-2); font-size: 0.78rem; letter-spacing: 0.1em; }
.balance-pill { color: var(--gold-2); }

.demo-toggle { display: flex; align-items: center; gap: 0.35rem; color: var(--muted); font-size: 0.82rem; }
.demo-toggle input { accent-color: var(--royal-2); width: 1.05rem; height: 1.05rem; }

.sprinkle-zone { position: absolute; inset: -50% -30%; pointer-events: none; overflow: visible; }

.sprinkle-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  background: var(--asset-chip) center/contain no-repeat;
  filter: drop-shadow(0 0 8px rgba(232, 193, 90, 0.95));
  animation: sprinkle-fly 900ms ease-out forwards;
}

@keyframes sprinkle-fly {
  0% { transform: translate(0, 0) scale(0.3) rotate(0deg); opacity: 0; }
  18% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(var(--rot)); opacity: 0; }
}

/* ---- stage ---- */

.stage { margin-top: 0.4rem; }

.roll-stage {
  position: relative;
  border-radius: 18px;
  padding: 1.4rem 1.6rem 2.2rem;
  border: 2px solid rgba(232, 193, 90, 0.45);
  background:
    radial-gradient(circle at 50% 20%, rgba(168, 85, 247, 0.22), transparent 62%),
    linear-gradient(180deg, #2c1550, #170a29);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.55), 0 10px 30px rgba(0, 0, 0, 0.45);
}

.roll-readout {
  text-align: center;
  font-size: clamp(2.6rem, 10vw, 4.6rem);
  font-weight: 800;
  line-height: 1.05;
  color: var(--gold);
  text-shadow: 0 0 26px rgba(232, 193, 90, 0.45);
  font-variant-numeric: tabular-nums;
  transition: color 180ms ease;
}

.roll-readout.win { color: var(--win); text-shadow: 0 0 26px rgba(52, 211, 153, 0.5); }
.roll-readout.lose { color: var(--lose); text-shadow: 0 0 26px rgba(225, 29, 72, 0.5); }

.roll-track {
  position: relative;
  margin: 1.6rem 0 0;
  height: var(--track-h);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.6), rgba(58, 26, 99, 0.55));
  border: 1px solid rgba(232, 193, 90, 0.3);
}

.roll-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(52, 211, 153, 0.75), rgba(52, 211, 153, 0.35));
  box-shadow: 0 0 14px rgba(52, 211, 153, 0.35);
  transition: left 160ms ease, width 160ms ease;
}

.roll-fill.win { background: linear-gradient(180deg, var(--win), rgba(52, 211, 153, 0.4)); }
.roll-fill.lose { background: linear-gradient(180deg, var(--lose), rgba(225, 29, 72, 0.4)); }

.roll-marker {
  position: absolute;
  top: 50%;
  left: 0;
  width: 6px;
  height: calc(var(--track-h) + 18px);
  margin-left: -3px;
  transform: translateY(-50%);
  border-radius: 3px;
  background: var(--gold-2);
  box-shadow: 0 0 12px rgba(255, 240, 184, 0.9);
}

.roll-ticks {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--track-h) + 12px);
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.72rem;
}

.die {
  position: absolute;
  right: 1.1rem;
  top: 1.1rem;
  width: 56px;
  height: 56px;
  background: var(--asset-die) center/contain no-repeat;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.55));
}

.die.rolling { animation: die-tumble 620ms linear infinite; }

@keyframes die-tumble {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.12); }
  100% { transform: rotate(360deg) scale(1); }
}

.roll-stage.flash-lose { animation: flash-lose 520ms ease-in-out 2; }

@keyframes flash-lose {
  0%, 100% { box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.55); transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { box-shadow: inset 0 0 60px rgba(225, 29, 72, 0.6), 0 0 30px rgba(225, 29, 72, 0.5); }
  75% { transform: translateX(6px); }
}

/* ---- HUD ---- */

.hud {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem;
  align-items: center;
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid rgba(232, 193, 90, 0.22);
}

.hud-label { display: block; color: var(--muted); font-size: 0.7rem; letter-spacing: 0.16em; }

.hud-mult {
  display: block;
  font-size: clamp(1.9rem, 6vw, 3rem);
  color: var(--gold);
  text-shadow: 0 0 22px rgba(232, 193, 90, 0.45);
  line-height: 1.05;
}

.hud-side { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.hud-side strong { display: block; margin-top: 0.2rem; color: var(--gold-2); font-size: 1rem; }

/* ---- controls ---- */

.controls {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(260px, 1.5fr) minmax(190px, 1fr) auto;
  gap: 0.6rem;
  align-items: stretch;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  color: #fff;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

.control-block { background: rgba(0, 0, 0, 0.36); border-radius: 10px; padding: 0.4rem 0.55rem; }
.control-block > label { display: block; color: var(--muted); font-size: 0.74rem; margin-bottom: 0.3rem; }
.control-block input[type="number"] {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 0.45rem;
  color: #f1f1f1;
  background: #2a1a3f;
}

.direction-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; }

.dir {
  padding: 0.55rem 0.4rem;
  font-size: 0.76rem;
  border: 1px solid rgba(232, 193, 90, 0.35);
  background: rgba(58, 26, 99, 0.65);
  color: var(--muted);
}

.dir.active {
  background: linear-gradient(180deg, rgba(109, 40, 217, 0.95), rgba(58, 26, 99, 0.95));
  color: var(--gold-2);
  box-shadow: 0 0 14px rgba(168, 85, 247, 0.45);
}

.target-slider {
  width: 100%;
  height: var(--track-h);
  margin: 0.15rem 0 0.5rem;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(52, 211, 153, 0.55), rgba(168, 85, 247, 0.55));
  outline-offset: 3px;
}

.target-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--thumb-size);
  height: var(--thumb-size);
  border-radius: 8px;
  background: var(--asset-die) center/contain no-repeat, linear-gradient(180deg, var(--gold-2), var(--gold));
  border: 1px solid #7a5c14;
  cursor: pointer;
}

.target-slider::-moz-range-thumb {
  width: var(--thumb-size);
  height: var(--thumb-size);
  border-radius: 8px;
  background: var(--asset-die) center/contain no-repeat, linear-gradient(180deg, var(--gold-2), var(--gold));
  border: 1px solid #7a5c14;
  cursor: pointer;
}

.target-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.mini { display: block; color: var(--muted); font-size: 0.7rem; }
.mini input { margin-top: 0.2rem; }

.quick-bets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.25rem; margin-top: 0.4rem; }
.quick-bets button {
  padding: 0.4rem 0.2rem;
  font-size: 0.72rem;
  background: rgba(58, 26, 99, 0.75);
  border: 1px solid rgba(232, 193, 90, 0.3);
  color: var(--gold-2);
}

.primary {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: #3b2606;
  min-width: 140px;
  font-size: 1.05rem;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.collect { background: linear-gradient(180deg, #2e7d32, #1b5e20); min-width: 130px; }

/* ---- history ---- */

.history-wrap { margin-top: 0.8rem; }
.history-strip { display: flex; gap: 0.35rem; overflow-x: auto; padding: 0.4rem 0; }
.history-empty { color: var(--muted); font-size: 0.82rem; }

.history-chip {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.76rem;
  font-weight: 700;
  border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}

.history-chip.win { background: rgba(52, 211, 153, 0.18); border-color: var(--win); color: #bbf7d0; }
.history-chip.lose { background: rgba(225, 29, 72, 0.18); border-color: var(--lose); color: #ffc9d4; }

/* ---- results / panels ---- */

.results {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.results div {
  background: linear-gradient(180deg, rgba(58, 26, 99, 0.6), rgba(0, 0, 0, 0.5));
  border: 1px solid rgba(232, 193, 90, 0.28);
  border-radius: 10px;
  padding: 0.55rem;
}

.results span { display: block; color: var(--muted); font-size: 0.74rem; }
.results strong { display: block; margin-top: 0.25rem; font-size: 0.92rem; color: var(--gold-2); overflow-wrap: anywhere; }

.verify-link {
  display: block;
  margin: 0.7rem auto 0;
  background: none;
  border: 1px solid rgba(232, 193, 90, 0.4);
  color: var(--gold-2);
  padding: 0.4rem 1rem;
  font-size: 0.78rem;
  border-radius: 8px;
}

.panels {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem;
}

.panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.panel table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.panel th, .panel td { text-align: left; padding: 0.25rem 0.4rem; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.panel th { color: var(--muted); font-weight: 600; }
.panel ul { margin: 0; padding-left: 1.1rem; color: #e9e3f5; }
.panel ul li { margin: 0.2rem 0; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.stat-grid strong { display: block; margin-top: 0.2rem; color: var(--gold-2); font-size: 1rem; }

/* ---- toast / modal ---- */

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(46, 16, 78, 0.96);
  color: #fff6e0;
  border: 1px solid rgba(232, 193, 90, 0.45);
  border-radius: 10px;
  padding: 0.6rem 1.1rem;
  z-index: 60;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 4, 16, 0.76);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
  overflow: auto;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  margin: auto;
  background: linear-gradient(180deg, #2a1546, #170b28);
  border: 3px solid var(--gold);
  border-radius: 16px;
  padding: 1.3rem 1.5rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 30px rgba(168, 85, 247, 0.3);
}

.modal-card h2 { margin-bottom: 0.4rem; }
.modal-card p { margin: 0.2rem 0 0.6rem; color: var(--muted); }

.verify-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.7rem;
  text-align: left;
  margin: 0 0 0.9rem;
  font-size: 0.8rem;
}

.verify-details dt { color: var(--muted); }
.verify-details dd { margin: 0; color: var(--gold-2); overflow-wrap: anywhere; }

/* ---- ambience ---- */

.sparks { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }

.sparks span {
  position: absolute;
  bottom: -20px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--gold-2), var(--royal-2) 70%, transparent);
  box-shadow: 0 0 6px 2px rgba(168, 85, 247, 0.55);
  animation: spark-rise linear infinite;
  opacity: 0;
}

.sparks span:nth-child(1) { left: 6%; animation-duration: 11s; animation-delay: 0s; }
.sparks span:nth-child(2) { left: 18%; animation-duration: 13s; animation-delay: 1.5s; }
.sparks span:nth-child(3) { left: 31%; animation-duration: 9s; animation-delay: 3s; }
.sparks span:nth-child(4) { left: 46%; animation-duration: 12s; animation-delay: 0.8s; }
.sparks span:nth-child(5) { left: 60%; animation-duration: 10s; animation-delay: 2.4s; }
.sparks span:nth-child(6) { left: 73%; animation-duration: 14s; animation-delay: 4s; }
.sparks span:nth-child(7) { left: 86%; animation-duration: 10.5s; animation-delay: 1s; }
.sparks span:nth-child(8) { left: 94%; animation-duration: 12.5s; animation-delay: 3.6s; }

@keyframes spark-rise {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  12% { opacity: 0.9; }
  100% { transform: translateY(-108vh) scale(1.1); opacity: 0; }
}

@media (max-width: 900px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .results { grid-template-columns: 1fr 1fr; }
  .panels { grid-template-columns: 1fr; }
  .hud { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .sparks span,
  .die.rolling,
  .sprinkle-icon,
  .roll-stage.flash-lose { animation: none; }
  .roll-fill { transition: none; }
}

/* ---- profit practices (presentation only) ---- */
.stake-chips { display:flex; flex-wrap:wrap; gap:.3rem; margin-top:.45rem; }
.stake-chip { padding:.38rem .6rem; font-size:.74rem; background:rgba(58,26,99,.75); border:1px solid rgba(232,193,90,.3); color:var(--gold-2); border-radius:999px; }
.stake-chip.active { background:linear-gradient(180deg,var(--gold-2),var(--gold)); color:#3b2606; }
.stake-chip.chip-high { font-size:.92rem; padding:.55rem .9rem; background:linear-gradient(180deg,var(--gold-2),var(--gold)); color:#3b2606; box-shadow:0 0 16px rgba(232,193,90,.65); border-color:var(--gold-2); }
.speed-bar { margin-top:.7rem; display:flex; gap:.6rem; align-items:center; justify-content:space-between; }
.turbo-toggle { display:flex; align-items:center; gap:.4rem; font-weight:800; letter-spacing:.08em; color:var(--gold-2); }
.turbo-toggle input { accent-color:var(--gold); width:1.15rem; height:1.15rem; }
.rebet { background:linear-gradient(180deg,var(--royal-2),var(--royal)); min-width:170px; }
.celebration-banner { position:absolute; left:50%; top:38%; transform:translate(-50%,-50%); z-index:5; text-align:center; padding:.7rem 1.4rem; border-radius:14px; background:rgba(14,10,22,.92); border:2px solid var(--win); box-shadow:0 0 30px rgba(52,211,153,.55); animation:banner-pop .45s ease-out; }
.celebration-banner span { display:block; color:var(--win); font-weight:800; letter-spacing:.14em; }
.celebration-banner strong { display:block; color:var(--gold-2); font-size:1.7rem; font-variant-numeric:tabular-nums; }
.celebration-banner.tier-big { border-color:var(--gold); box-shadow:0 0 36px rgba(232,193,90,.7); }
.celebration-banner.tier-big span { color:var(--gold); font-size:1.15rem; }
.celebration-banner.tier-mega { border-color:var(--gold); box-shadow:0 0 48px rgba(232,193,90,.9); }
.celebration-banner.tier-mega span { color:var(--gold); font-size:1.45rem; }
.celebration-banner.tier-mega strong { font-size:2.1rem; }
.celebration-banner.tier-epic { border-color:#fff; box-shadow:0 0 64px rgba(168,85,247,.95); }
.celebration-banner.tier-epic span { color:var(--royal-2); font-size:1.8rem; }
.celebration-banner.tier-epic strong { font-size:2.6rem; }
@keyframes banner-pop { 0%{transform:translate(-50%,-50%) scale(.6);opacity:0} 100%{transform:translate(-50%,-50%) scale(1);opacity:1} }
.near-miss-banner { position:absolute; left:50%; bottom:12%; transform:translateX(-50%); z-index:5; padding:.5rem 1.1rem; border-radius:999px; background:rgba(225,29,72,.18); border:2px solid var(--lose); color:#ffc9d4; font-weight:800; letter-spacing:.1em; animation:banner-pop .35s ease-out; }
.recent-wins-wrap { margin-top:.8rem; }
.recent-wins { list-style:none; margin:.35rem 0 0; padding:0; display:flex; gap:.4rem; flex-wrap:wrap; }
.recent-wins li { padding:.32rem .7rem; border-radius:999px; background:rgba(52,211,153,.14); border:1px solid rgba(52,211,153,.5); color:#bbf7d0; font-size:.76rem; font-weight:700; }
@media (prefers-reduced-motion: reduce) { .celebration-banner, .near-miss-banner { animation:none; } }
.lang-btn { cursor: pointer; font: inherit; }

