:root {
  --bg: #07070b;
  --panel: #111119;
  --panel-2: #171722;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f3f3f8;
  --muted: #8a8a9c;
  --gold: #f5c451;
  --gold-2: #d9a12c;
  --green: #33d17f;
  --red: #ff5c61;
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 80% -120px, rgba(245, 196, 81, 0.10), transparent 70%),
    radial-gradient(700px 400px at 10% 0%, rgba(120, 80, 255, 0.10), transparent 70%),
    var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------------- top bar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(7, 7, 11, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; direction: ltr; }
.logo { width: 28px; height: 28px; flex: none; filter: drop-shadow(0 2px 8px rgba(245, 196, 81, 0.35)); }
.brand-text { display: flex; align-items: baseline; gap: 4px; font-weight: 800; letter-spacing: 0.06em; direction: ltr; }
.brand-text .b1 {
  font-size: 17px;
  background: linear-gradient(180deg, #ffe9a8, #d9a12c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-text .b2 { font-size: 12px; color: #fff; opacity: 0.75; }

.wallet {
  margin-inline-start: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.15;
  background: linear-gradient(180deg, rgba(245, 196, 81, 0.14), rgba(245, 196, 81, 0.04));
  border: 1px solid rgba(245, 196, 81, 0.28);
  border-radius: 12px;
  padding: 5px 10px;
}
.wallet-label { font-size: 10px; color: var(--gold); opacity: 0.85; letter-spacing: 0.04em; }
.wallet-amount { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.wallet-amount small { font-size: 10px; font-weight: 600; opacity: 0.7; margin-inline-start: 3px; }

.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:active { transform: scale(0.96); }

/* ---------------- tabs ---------------- */

.tabs {
  display: flex;
  gap: 8px;
  padding: 10px 12px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.tab.active {
  color: #1b1405;
  background: linear-gradient(180deg, #ffe08a, #e0aa35);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(245, 196, 81, 0.22);
}

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

main { padding: 8px 12px 24px; max-width: 1180px; margin: 0 auto; }

.game { display: none; gap: 12px; }
.game.active { display: grid; grid-template-columns: 1fr; }
.game .stage { order: 1; }
.game .side { order: 2; }

@media (min-width: 900px) {
  .game.active { grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
  .game .side { order: 1; }
  .game .stage { order: 2; }
}

.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.side { display: flex; flex-direction: column; gap: 12px; }

/* ---------------- bet block ---------------- */

.bet-block { display: flex; flex-direction: column; gap: 8px; }
.row-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.bet-row { display: flex; gap: 8px; align-items: stretch; }
.bet-row input {
  flex: 1;
  min-width: 0;
  height: 44px;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.mini {
  width: 44px;
  flex: none;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 800;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chip {
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.chip:active, .mini:active { background: rgba(245, 196, 81, 0.14); color: var(--gold); }

input[type="number"], input[type="text"], select {
  width: 100%;
  height: 42px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #0c0c13;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  outline: none;
}
input:focus, select:focus { border-color: rgba(245, 196, 81, 0.55); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 19px, calc(100% - 13px) 19px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.field b { color: var(--text); }

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(245, 196, 81, 0.8), rgba(245, 196, 81, 0.25));
  outline: none;
  margin: 12px 0 4px;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--gold-2);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
.range::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--gold-2); cursor: pointer;
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: #0c0c13;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.seg button {
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.seg button.active { background: rgba(245, 196, 81, 0.16); color: var(--gold); }

.settings { display: flex; flex-direction: column; gap: 10px; }

.stats { display: flex; flex-direction: column; gap: 6px; }
.stats > div {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 7px 10px;
}
.stats b { color: var(--text); font-variant-numeric: tabular-nums; font-size: 13px; }

.play-btn {
  height: 50px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(180deg, #ffe08a, #e0aa35);
  color: #1b1405;
  font-size: 17px;
  font-weight: 900;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(224, 170, 53, 0.22);
}
.play-btn:active { transform: translateY(1px); }
.play-btn:disabled { opacity: 0.5; box-shadow: none; }
.play-btn.cashout { background: linear-gradient(180deg, #6ef0ab, #22b06a); color: #04180e; }

.ghost-btn {
  height: 42px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn.wide { width: 100%; }

/* ---------------- stage ---------------- */

.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 300px; gap: 12px; }

.dice-stage { gap: 8px; }
.dice-value {
  font-size: 58px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff, #b9b9c9);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.1;
  margin-top: 6px;
}
.dice-value.win { background: none; color: #33d17f; -webkit-text-fill-color: #33d17f; }
.dice-value.lose { background: none; color: #ff5c61; -webkit-text-fill-color: #ff5c61; }

.dice-bar {
  position: relative;
  direction: ltr;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #1b1b26;
  overflow: hidden;
  margin: 6px 0;
}
.dice-fill {
  position: absolute;
  top: 0; bottom: 0;
  background: linear-gradient(90deg, rgba(51, 209, 127, 0.55), rgba(51, 209, 127, 0.95));
  transition: left 0.12s linear, width 0.12s linear;
}
.dice-target-line { position: absolute; top: -4px; bottom: -4px; width: 2px; background: #fff; opacity: 0.9; }
.dice-last {
  position: absolute;
  top: 50%;
  width: 18px; height: 18px;
  margin-left: -9px;
  margin-top: -9px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #0a0a0f;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
  opacity: 0;
  transition: left 0.35s cubic-bezier(0.2, 0.9, 0.2, 1), opacity 0.2s;
}
.dice-scale { display: flex; justify-content: space-between; width: 100%; font-size: 10px; color: var(--muted); direction: ltr; }

.recent { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; min-height: 26px; }
.pill {
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border: 1px solid var(--line);
}
.pill.win { color: #8bf0b9; border-color: rgba(51, 209, 127, 0.35); background: rgba(51, 209, 127, 0.10); }
.pill.lose { color: #ffa3a6; border-color: rgba(255, 92, 97, 0.3); background: rgba(255, 92, 97, 0.08); }

.stage-note { font-size: 11.5px; color: var(--muted); text-align: center; margin: 4px 0 0; line-height: 1.6; }
.stage-note b { color: var(--text); }

/* mines */

.mines-stage { padding: 12px; }
.mines-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 440px;
}
.tile {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #1d1d2a, #14141d);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  user-select: none;
}
.tile:active { transform: scale(0.97); }
.tile.gem { color: #8bf0b9; background: linear-gradient(180deg, rgba(51, 209, 127, 0.28), rgba(51, 209, 127, 0.10)); border-color: rgba(51, 209, 127, 0.5); }
.tile.mine { color: #ff9a9d; background: linear-gradient(180deg, rgba(255, 92, 97, 0.32), rgba(255, 92, 97, 0.12)); border-color: rgba(255, 92, 97, 0.55); }
.tile.dim { opacity: 0.45; }

/* limbo */

.limbo-stage { gap: 16px; }
.limbo-value {
  font-size: 64px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, #fff, #b9b9c9);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.limbo-value.win { background: none; color: #33d17f; -webkit-text-fill-color: #33d17f; }
.limbo-value.lose { background: none; color: #ff5c61; -webkit-text-fill-color: #ff5c61; }

/* plinko */

.plinko-stage { padding: 8px; }
#plinko-canvas { width: 100%; height: 380px; display: block; border-radius: 12px; }
@media (min-width: 900px) { #plinko-canvas { height: 440px; } }

/* keno */

.keno-stage { gap: 10px; }
.keno-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 520px;
}
@media (min-width: 900px) { .keno-grid { grid-template-columns: repeat(10, 1fr); } }
.knum {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #1d1d2a, #14141d);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
}
.knum:active { transform: scale(0.96); }
.knum.picked { background: linear-gradient(180deg, rgba(245, 196, 81, 0.35), rgba(245, 196, 81, 0.12)); border-color: rgba(245, 196, 81, 0.7); color: #ffe9a8; }
.knum.hit { background: linear-gradient(180deg, rgba(51, 209, 127, 0.4), rgba(51, 209, 127, 0.16)); border-color: rgba(51, 209, 127, 0.75); color: #c6ffe0; }
.knum.drawn-miss { opacity: 0.4; }
.keno-result { min-height: 22px; font-size: 13px; font-weight: 800; color: var(--gold); text-align: center; }

/* ---------------- history ---------------- */

.history-panel { margin-top: 14px; padding: 12px 14px; }
.history-head { display: flex; align-items: baseline; justify-content: space-between; }
.history-head h2 { font-size: 14px; margin: 0 0 8px; }
.history-wrap { max-height: 210px; overflow-y: auto; }
.history { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.history th { text-align: start; color: #a6a6b8; font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.history td { padding: 7px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.04); font-variant-numeric: tabular-nums; }
.history td.pos { color: #7fe9ae; }
.history td.neg { color: #ffa3a6; }

.muted { color: var(--muted); }
.small { font-size: 11px; }

/* ---------------- footer ---------------- */

.foot { max-width: 1180px; margin: 0 auto; padding: 8px 16px 28px; text-align: center; }
.foot p { margin: 4px 0; font-size: 12px; color: #b9b9c9; }
.foot a { color: var(--gold); text-decoration: none; }

/* ---------------- modal ---------------- */

.modal {
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: linear-gradient(180deg, #16161f, #0e0e15);
  color: var(--text);
  padding: 0;
  width: min(480px, 92vw);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(3px); }
.modal-inner { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 16px; margin: 0; }
.modal h3 { font-size: 13px; margin: 6px 0 0; color: var(--gold); }
.modal hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.kv { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); }
.kv code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10.5px;
  color: #dfe0ea;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 8px;
  border-radius: 7px;
  max-width: 62%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
}
.modal-actions { display: flex; gap: 8px; }
.modal-actions .ghost-btn { flex: 1; }
.verify-out { font-size: 12.5px; font-weight: 800; text-align: center; margin: 4px 0 0; }
.verify-out.ok { color: #7fe9ae; }
.verify-out.bad { color: #ffa3a6; }

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #1d1d2a;
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  max-width: 88vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
