:root {
  --bg: #1a1145;
  --bg2: #3a2a8f;
  --panel: rgba(18, 12, 54, 0.78);
  --line: rgba(255, 226, 140, 0.35);
  --gold: #f5c443;
  --gold2: #b8780a;
  --text: #f6f1ff;
  --muted: #b9addf;
  --cell: rgba(255, 255, 255, 0.06);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%) fixed, var(--bg);
  display: flex; flex-direction: column;
  min-height: 100dvh; overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body.in-feature { --bg2: #7a2a8f; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }

/* drifting clouds */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: -1; }
.sky i {
  position: absolute; width: 60vmax; height: 18vmax; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.12), transparent);
  animation: drift 60s linear infinite;
}
.sky i:nth-child(1) { top: 8%; left: -30%; }
.sky i:nth-child(2) { top: 45%; left: 20%; animation-duration: 90s; animation-delay: -30s; }
.sky i:nth-child(3) { top: 75%; left: -10%; animation-duration: 75s; animation-delay: -50s; }
@keyframes drift { to { transform: translateX(120vw); } }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.logo { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 22px; letter-spacing: 0.04em;
  background: linear-gradient(#fff3b8, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo img { width: 30px; height: 30px; }
.sync { margin-left: auto; color: var(--muted); font-size: 12px; text-align: right; }

.pill {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 7px 16px; font-weight: 600; white-space: nowrap;
}
.pill.gold { background: linear-gradient(#ffe07a, var(--gold2)); color: #2a1600; border-color: #ffe9a6; }
.round { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 18px; }

/* ---- stage ---- */
.stage { flex: 1; display: flex; gap: 16px; justify-content: center; align-items: center; padding: 8px 16px; }
.side { display: flex; flex-direction: column; gap: 12px; width: 170px; }
.buy {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 12px; border-radius: 16px;
  border: 2px solid #ffe9a6; background: linear-gradient(160deg, #ff9f5a, #c2185b); font-weight: 800; text-transform: uppercase; font-size: 13px;
  box-shadow: 0 6px 20px rgba(194, 24, 91, 0.4);
}
.buy strong { font-size: 18px; }
.ante { display: flex; gap: 8px; padding: 12px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; }
.ante small { display: block; color: var(--muted); font-size: 12px; }
.ante input { accent-color: var(--gold); width: 18px; height: 18px; }

.machine { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(640px, 100%, (100dvh - 250px) * 1.2); min-width: min(300px, 100%); }
.frame {
  position: relative; width: 100%; padding: 10px; border-radius: 22px;
  background: linear-gradient(var(--panel), var(--panel)) padding-box, linear-gradient(160deg, #fff3b8, var(--gold2), #fff3b8) border-box;
  border: 3px solid transparent; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 0 40px rgba(127, 231, 255, 0.08);
}
.board {
  position: relative; width: 100%; aspect-ratio: 6 / 5; overflow: hidden; border-radius: 14px;
  background:
    repeating-linear-gradient(90deg, var(--cell) 0 calc(100% / 6 - 2px), transparent calc(100% / 6 - 2px) calc(100% / 6)),
    rgba(255, 255, 255, 0.03);
}
.cell {
  position: absolute; width: calc(100% / 6); height: 20%; padding: 4%;
  display: grid; place-items: center;
  transition: top 0.38s cubic-bezier(0.3, 1.4, 0.6, 1), transform 0.25s, opacity 0.25s;
}
.turbo .cell { transition-duration: 0.18s; }
.cell.instant { transition: none; }
.cell.falling { transition: top 0.25s ease-in; }
.cell img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45)); pointer-events: none; }
.cell b {
  position: absolute; font-size: clamp(12px, 3.2vw, 22px); font-weight: 900; color: #fff;
  text-shadow: 0 0 6px #1b1f7a, 0 2px 0 #1b1f7a;
}
.cell.win { animation: glow 0.6s ease-in-out infinite alternate; z-index: 2; }
.cell.pop { transform: scale(0); opacity: 0; }
@keyframes glow {
  from { transform: scale(1); filter: drop-shadow(0 0 0 transparent); }
  to { transform: scale(1.12); filter: drop-shadow(0 0 12px #ffe27a); }
}

.toast {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 5;
  background: rgba(10, 6, 34, 0.88); border: 1px solid var(--line); border-radius: 12px; padding: 8px 16px;
  text-align: center; font-size: 14px; pointer-events: none; white-space: nowrap;
}
.toast b { color: var(--gold); }
.win { min-height: 34px; font-size: 26px; font-weight: 900; color: var(--gold); text-shadow: 0 2px 0 #4a2a00; }
.win span { font-size: 14px; color: var(--muted); text-shadow: none; letter-spacing: 0.1em; }

.fs { display: flex; gap: 10px; width: 100%; }
.fs div { flex: 1; text-align: center; padding: 6px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.fs small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.fs b { font-size: 22px; color: var(--gold); }

/* ---- bottom bar ---- */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 14px 22px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(8, 5, 28, 0.7); border-top: 1px solid var(--line);
}
.meter { text-align: center; min-width: 86px; }
.meter small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.meter b { font-size: 20px; }
.betbox { display: flex; align-items: center; gap: 8px; }
.spin {
  position: relative; width: 78px; height: 78px; border-radius: 50%; border: 3px solid #fff3b8;
  background: radial-gradient(circle at 35% 30%, #ffe9a6, var(--gold) 45%, var(--gold2));
  box-shadow: 0 6px 24px rgba(245, 196, 67, 0.45); display: grid; place-items: center;
}
.spin svg { width: 40px; height: 40px; fill: #3a2000; }
.spin:not(:disabled):active { transform: scale(0.94); }
.spin.stop { background: radial-gradient(circle at 35% 30%, #ffb3c1, #e5304f 50%, #7a0b22); }
.spin #auto-left { position: absolute; bottom: -6px; right: -6px; background: #e5304f; border-radius: 999px; padding: 0 7px; font-weight: 800; font-size: 13px; }
.spin #auto-left:empty { display: none; }
.tools { display: flex; align-items: center; gap: 8px; }
.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle input { accent-color: var(--gold); }
.topup { border: 2px solid #c4ffd9; background: linear-gradient(#5ee39a, #138a4a); border-radius: 999px; padding: 9px 18px; font-weight: 800; color: #032312; }
.broke { margin: 0; color: var(--muted); font-size: 13px; width: 100%; text-align: center; }

/* ---- overlays and dialogs ---- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(rgba(42, 20, 110, 0.75), rgba(5, 3, 20, 0.9));
}
.overlay[hidden] { display: none; }
.overlay > div { text-align: center; animation: zoom 0.4s cubic-bezier(0.3, 1.6, 0.6, 1); }
.overlay h2 { margin: 0; font-size: clamp(34px, 9vw, 64px); text-transform: uppercase; letter-spacing: 0.04em;
  background: linear-gradient(#fff3b8, var(--gold) 60%, var(--gold2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.overlay p { font-size: clamp(22px, 6vw, 40px); font-weight: 900; margin: 8px 0 20px; max-width: 520px; }
#banner p { font-size: 18px; font-weight: 500; }
@keyframes zoom { from { transform: scale(0.4); opacity: 0; } }

dialog {
  border: 1px solid var(--line); border-radius: 20px; background: #1d1450; color: var(--text);
  width: min(420px, calc(100% - 32px)); padding: 20px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
dialog.wide { width: min(620px, calc(100% - 32px)); max-height: 85dvh; }
dialog::backdrop { background: rgba(5, 3, 20, 0.7); }
dialog h2 { margin: 0 0 10px; color: var(--gold); }
dialog menu { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 0; margin: 16px 0 0; }
dialog menu.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 12px 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 700; text-align: right; }
.msg { color: #ffb3c1; }
.msg:empty { display: none; }
.fine { color: var(--muted); font-size: 13px; }
.paytable { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
.paytable th, .paytable td { padding: 4px 6px; text-align: right; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.paytable th:first-child, .paytable td:first-child { text-align: left; }
.paytable td:first-child { display: flex; align-items: center; gap: 8px; }
.paytable img, .row img { width: 32px; height: 32px; flex: none; }
.row { display: flex; gap: 10px; align-items: flex-start; }
kbd { border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

@media (max-width: 760px) {
  .machine { width: min(640px, 100%, (100dvh - 330px) * 1.2); }
  .stage { flex-direction: column-reverse; gap: 10px; padding: 4px 16px; }
  .side { flex-direction: row; width: 100%; }
  .side > * { flex: 1; }
  .buy { padding: 8px 10px; }
  .buy strong { font-size: 15px; }
  .ante { padding: 8px 10px; }
  .bar { gap: 10px 14px; }
  .sync { display: none; }
  .top .pill { margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .sky i { animation: none; }
  .cell.win { animation: none; outline: 2px solid var(--gold); border-radius: 12px; }
}
