:root {
  --felt: #0d4a24;
  --felt-dark: #082f17;
  --felt-light: #136332;
  --line: rgba(255, 255, 255, 0.55);
  --gold: #e6b94a;
  --gold-dark: #a87b22;
  --red: #c8102e;
  --black: #151515;
  --green: #1d9a3c;
  --text: #f4f4f4;
  --muted: rgba(255, 255, 255, 0.62);
  --panel: rgba(0, 0, 0, 0.35);
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; max-width: 100%; overflow-x: hidden; }
/* Nothing may make the page wider than the screen */
.topbar, .game, .controls, .board, .board-svg { max-width: 100%; }
.topbar > * { min-width: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 20%, var(--felt-light), var(--felt) 45%, var(--felt-dark));
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; word-break: break-all; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #062513;
  border-bottom: 1px solid rgba(230, 185, 74, 0.35);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-weight: 900;
  letter-spacing: 1px;
  font-size: 20px;
  color: #fff;
  margin-right: auto;
}
.logo span { color: var(--gold); }
.logo.big { font-size: 30px; text-align: center; margin: 0 0 14px; }

.mode-switch {
  display: flex;
  background: var(--panel);
  border-radius: 999px;
  padding: 3px;
}
.mode-switch button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.mode-switch button.active { background: var(--gold); color: #1b1200; }
body[data-mode="real"] .mode-switch button.active { background: #2ecc71; color: #062712; }

.balance { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.balance small { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.balance { min-width: 0; flex-shrink: 1; }
.balance strong {
  font-size: 15px;
  color: #7CFC9A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 34vw;
}
.mode-switch, .menu, #deposit-btn { flex-shrink: 0; }

.menu { position: relative; }
.menu summary {
  list-style: none;
  font-size: 20px;
  padding: 2px 8px;
  cursor: pointer;
  border-radius: 8px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute;
  right: 0;
  top: 36px;
  background: #0b2a16;
  border: 1px solid rgba(230, 185, 74, 0.4);
  border-radius: 12px;
  padding: 8px;
  min-width: 210px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.menu-panel > div { padding: 6px 10px; font-size: 13px; }
.menu-panel button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px;
  border-radius: 8px;
}
.menu-panel button:hover { background: rgba(255, 255, 255, 0.08); }

/* ---------- layout ---------- */
/* One screen: wheel, table and stake controls are all visible together. */
.game {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "wheel" "board" "controls";
  align-content: start;
  gap: 8px;
  padding: 8px 12px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}
.wheel-area { grid-area: wheel; }
.board-area { grid-area: board; }
.controls { grid-area: controls; }

@media (min-width: 900px) {
  .game {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    grid-template-areas: "wheel board" "wheel controls";
    align-content: center;
    align-items: center;
    gap: 16px 32px;
    padding-top: 16px;
  }
}

.wheel-area { position: relative; display: flex; justify-content: center; scroll-margin-top: 60px; }

.limits-line { margin: 4px 0 0; font-size: 11px; letter-spacing: 1px; color: var(--muted); text-align: center; }
.limits-line span { color: var(--text); font-weight: 700; letter-spacing: 0; margin-left: 4px; }

.wheel-wrap { position: relative; width: min(100% - 60px, 40dvh, 460px); aspect-ratio: 1; }
@media (min-width: 900px) {
  .wheel-wrap { width: min(100%, 62dvh, 460px); }
}
#wheel { width: 100%; height: 100%; display: block; filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.55)); }

.result-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.78);
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 10px 16px;
  text-align: center;
  animation: pop 0.35s ease-out;
  pointer-events: none;
  min-width: 140px;
}
.result-banner .big-num {
  width: 50px;
  height: 50px;
  margin: 0 auto 6px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 900;
  border: 3px solid #fff;
}
.result-banner.red .big-num { background: var(--red); }
.result-banner.black .big-num { background: var(--black); }
.result-banner.green .big-num { background: var(--green); }
.result-banner .msg { font-weight: 800; font-size: 13px; }
.result-banner.won .msg { color: #ffe27a; font-size: 15px; }
.result-banner.won { box-shadow: 0 0 40px rgba(255, 215, 90, 0.6); }

.result-banner .hurray {
  font-size: 18px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 1px;
  margin-bottom: 6px;
  white-space: nowrap;
  animation: hurray-bounce 0.5s ease-in-out infinite alternate;
}
@keyframes hurray-bounce { to { transform: scale(1.12); } }

.result-banner .oops {
  font-size: 18px;
  font-weight: 900;
  color: #ff9a9a;
  letter-spacing: 1px;
  margin-bottom: 6px;
  white-space: nowrap;
  animation: oops-shake 0.6s ease-in-out 2;
}
@keyframes oops-shake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg); }
}
.result-banner .sub { font-size: 11px; color: var(--muted); margin-top: 4px; max-width: 170px; margin-inline: auto; }

/* Falling money on a win */
.money-rain { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.money-rain span {
  position: absolute;
  top: -60px;
  animation-name: money-fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.4));
}
@keyframes money-fall { to { transform: translate(var(--drift), 110dvh) rotate(var(--rot)); } }

@keyframes pop {
  from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Recent results: a column down the right side of the wheel */
.history {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hist {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-weight: 800;
  font-size: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.hist:first-child { outline: 2px solid var(--gold); }
.hist.red { background: var(--red); }
.hist.black { background: var(--black); }
.hist.green { background: var(--green); }

/* ---------- board ---------- */
.board-area { display: flex; flex-direction: column; align-items: center; }
.board { width: 100%; max-width: 760px; }
.board-svg { width: 100%; height: auto; display: block; user-select: none; touch-action: manipulation; }

.cell { fill: transparent; stroke: var(--line); stroke-width: 1; transition: fill 0.12s; }
.num.hl .cell, .cell.hl { fill: rgba(255, 255, 255, 0.16); }
.pill { stroke: none; }
.pill.red { fill: var(--red); }
.pill.black { fill: var(--black); }
.pill.green { fill: var(--green); }
.num-text { fill: #fff; font-size: 16px; font-weight: 800; pointer-events: none; }
.label { fill: #fff; font-size: 13px; font-weight: 700; pointer-events: none; }
.dozen-sep { stroke: var(--gold); stroke-width: 3; stroke-linecap: round; pointer-events: none; filter: drop-shadow(0 0 2px rgba(230, 185, 74, 0.6)); }
.diamond.red { fill: var(--red); stroke: #fff; stroke-width: 1; }
.diamond.black { fill: var(--black); stroke: #fff; stroke-width: 1; }

.num.winner .pill { stroke: #ffd65a; stroke-width: 3; filter: drop-shadow(0 0 6px #ffd65a); }

.hot { fill: transparent; cursor: pointer; }
body.spinning .hot { cursor: default; }

.chips-layer { pointer-events: none; }
.chip-body { stroke: #fff; stroke-width: 2.2; stroke-dasharray: 4 3.2; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)); }
.chip-ring { fill: none; stroke: rgba(255, 255, 255, 0.55); stroke-width: 0.8; }
.chip-text { font-size: 8.5px; font-weight: 800; fill: #111; paint-order: stroke; stroke: rgba(255, 255, 255, 0.85); stroke-width: 2px; }
.chip.lose { opacity: 0.35; }
.chip.win .chip-body { stroke: #ffd65a; stroke-dasharray: none; stroke-width: 3; animation: glow 0.9s ease-in-out infinite alternate; }
@keyframes glow { to { filter: drop-shadow(0 0 6px #ffd65a); } }

/* ---------- controls ---------- */
.controls {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(230, 185, 74, 0.25);
  border-radius: var(--radius);
  padding: 10px 12px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip-btn {
  --chip: #c7e23a;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px dashed #fff;
  background: radial-gradient(circle, var(--chip) 55%, color-mix(in srgb, var(--chip), #000 25%) 56%);
  color: #111;
  font-weight: 900;
  font-size: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.12s;
}
.chip-btn { position: relative; }
.chip-btn.selected { transform: scale(1.18); box-shadow: 0 0 0 3px var(--gold), 0 4px 12px rgba(0, 0, 0, 0.6); }

.chips-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
}
.chips-label span { color: #7CFC9A; margin-left: 4px; }

.actions { display: flex; align-items: center; gap: 12px; }
.round {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(#2a3a30, #111a14);
  font-size: 18px;
  font-weight: 800;
}
.spin {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  background: radial-gradient(circle at 40% 35%, #3ad16a, #0e6d2d 70%);
  font-size: 30px;
  color: #062712;
  box-shadow: 0 0 20px rgba(58, 209, 106, 0.45);
}
.spin:not(:disabled):active { transform: scale(0.95); }

.total { font-weight: 800; color: #7CFC9A; letter-spacing: 0.5px; font-size: 15px; }
.rg { font-size: 11px; color: var(--muted); }

/* ---------- dialogs ---------- */
.dialog {
  border: 1px solid rgba(230, 185, 74, 0.5);
  border-radius: 18px;
  background: #0b2a16;
  color: var(--text);
  width: min(92vw, 420px);
  padding: 22px;
  max-height: 90dvh;
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(3px); }
.dialog h2 { margin: 0 0 8px; color: var(--gold); }
.dialog h3 { margin: 18px 0 8px; font-size: 15px; }
.dialog p { font-size: 14px; }
.dialog form { display: flex; flex-direction: column; gap: 12px; }
.dialog form[method="dialog"] { margin-top: 14px; }
.dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.dialog label.check { flex-direction: row; align-items: center; color: var(--text); }
.dialog input:not([type="checkbox"]) {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  min-width: 0;
}
.dialog input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

.tabs { display: flex; background: var(--panel); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tabs button.active { background: var(--gold); color: #1b1200; }

.form-error { color: #ff8a8a; min-height: 1em; margin: 0; }

.btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 700;
}
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn-gold { background: linear-gradient(#f3cf6d, var(--gold-dark)); border-color: var(--gold); color: #1b1200; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; font-size: 13px; align-items: center; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.inline { flex-direction: row !important; gap: 6px !important; }
.inline input { flex: 1; padding: 6px 8px !important; font-size: 13px !important; }
.revealed { background: var(--panel); border-radius: 10px; padding: 10px; margin-top: 10px; font-size: 13px; }
.revealed p { margin: 0 0 6px; font-size: 13px; }
.seed { color: #ffe27a; }
.verify input { font-size: 13px !important; }
.dev-note { color: #ffb347; font-size: 12px !important; margin: 8px 0 0; }

/* ---------- withdraw / invite / history ---------- */
.dialog h2 small { font-size: 12px; font-weight: 600; }
.dialog .small { font-size: 12px; margin: 0; }
.gold { color: var(--gold); }
.invited-note { color: var(--gold); font-size: 13px !important; margin: 0; }

.stat-row {
  display: flex;
  justify-content: space-between;
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 14px;
}
.stat-row strong { color: #7CFC9A; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.stat-grid > div { background: var(--panel); border-radius: 10px; padding: 8px 10px; }
.stat-grid small { display: block; font-size: 11px; color: var(--muted); }
.stat-grid strong { font-size: 15px; }
.pos { color: #7CFC9A; }
.neg { color: #ff8a8a; }

.copy-row { display: flex; gap: 8px; margin: 12px 0 8px; }
.copy-row input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(230, 185, 74, 0.5);
  border-radius: 10px;
  padding: 10px;
  color: var(--text);
  font-size: 13px;
}

.tx-list { list-style: none; margin: 0 0 4px; padding: 0; max-height: 45dvh; overflow-y: auto; }
.tx-list > li { padding: 10px 2px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-size: 14px; }
.tx { display: flex; align-items: center; gap: 10px; }
.tx-icon { font-size: 20px; width: 26px; text-align: center; }
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.tx-detail { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tx-amt { white-space: nowrap; font-size: 14px; }
.hist.mini { width: 22px; height: 22px; font-size: 11px; border-radius: 5px; outline: none; }

.toast {
  position: fixed;
  left: 50%;
  top: 45%;
  transform: translate(-50%, 20px);
  background: rgba(0, 0, 0, 0.88);
  border: 1px solid var(--gold);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Phones/tablets: the stake panel sits at the bottom of the screen as a sleek sheet */
@media (max-width: 899px) {
  .game { grid-template-rows: auto auto 1fr; padding-bottom: 0; }
  .controls {
    align-self: end;
    position: relative;
    margin: 10px -12px 0;
    border: 0;
    border-top: 1px solid rgba(230, 185, 74, 0.45);
    border-radius: 22px 22px 0 0;
    background: linear-gradient(180deg, #0d311a, #04170b);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
    padding: 16px 16px calc(10px + env(safe-area-inset-bottom));
    gap: 10px;
  }
  .controls::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(230, 185, 74, 0.45);
  }
  .chip-btn { width: 42px; height: 42px; font-size: 11px; border-width: 2px; }
  .chip-btn.selected { transform: scale(1.12); }
  .round { width: 42px; height: 42px; font-size: 16px; background: rgba(255, 255, 255, 0.06); }
  .spin { width: 60px; height: 60px; font-size: 24px; }
  .actions { gap: 14px; }
  .total { font-size: 14px; }
  .rg { font-size: 10px; }
}

@media (max-width: 420px) {
  .topbar { gap: 6px; padding: 8px 12px; }
  .logo { font-size: 16px; }
  .mode-switch button { padding: 5px 9px; font-size: 12px; }
  .balance strong { font-size: 13px; }
  .game { padding: 6px 8px 0; gap: 6px; }
  .controls { margin: 8px -8px 0; }
  .chips { gap: 7px; }
}

/* ---------- top bar on small phones: keep everything on one line, nothing overlapping ---------- */
.logo { flex-shrink: 0; white-space: nowrap; }
@media (max-width: 400px) {
  .topbar { gap: 6px; padding: 8px 10px; }
  .logo { font-size: 14px; letter-spacing: 0; }
  .mode-switch button { padding: 5px 8px; font-size: 11px; }
  .balance small { display: none; }
  .balance strong { font-size: 13px; max-width: 28vw; }
  .balance strong { max-width: 30vw; }
  .menu summary { padding: 2px 4px; }
}

/* Deposit button sits on top of the balance */
.balance #deposit-btn {
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 800;
  border-radius: 999px;
  margin-bottom: 3px;
  line-height: 1.3;
}
body[data-mode="real"] .bal-label { display: none; }
