:root {
  --ink: #F6E7C8;
  --muted: #D2BE98;
  --gold: #E9B44A;
  --gold-hi: #FFD979;
  --gold-lo: #8A5714;
  --night: #120818;
  --panel: rgba(22, 9, 28, 0.82);
  --panel-solid: #1E0D26;
  --line: rgba(233, 180, 74, 0.28);
  --velvet: #6C0E25;
  --cell: 140px;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: Manrope, system-ui, -apple-system, 'Segoe UI', sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold-hi); outline-offset: 2px; }

/* ---------------------------------------------------------------- background */
.bg { position: fixed; inset: 0; z-index: 0; }
.bg-layer { position: absolute; inset: 0; background-size: cover; background-position: center 70%; transition: opacity 1.2s ease; }
.bg-main { background-image: url(../assets/bg/main.svg); }
.bg-free { background-image: url(../assets/bg/free.svg); opacity: 0; }
body.fs .bg-free { opacity: 1; }
.bg::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 45%, transparent 35%, rgba(8, 3, 12, 0.6) 100%); }
.motes { position: absolute; inset: 0; overflow: hidden; opacity: 0; transition: opacity 1s; }
body.fs .motes { opacity: 1; }
.mote { position: absolute; top: -10px; width: 4px; height: 4px; border-radius: 50%; background: #FFE39A; box-shadow: 0 0 8px #FFC24E; animation: fall linear infinite; }
@keyframes fall { to { transform: translate3d(30px, 105vh, 0); } }

/* ---------------------------------------------------------------- layout */
.app { position: relative; z-index: 1; height: 100dvh; display: flex; flex-direction: column; padding: max(10px, env(safe-area-inset-top)) 16px max(8px, env(safe-area-inset-bottom)); gap: 8px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name {
  font-family: 'Cormorant SC', Georgia, serif; font-weight: 700; font-size: clamp(22px, 3.2vw, 34px); letter-spacing: .02em;
  background: linear-gradient(180deg, #FFF4C9 0%, #F8D978 35%, #D9A03A 70%, #8A5714 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.6));
}
.brand-sub { font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.session { display: flex; gap: 14px; font-size: 14px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; }
.session span { display: inline-flex; align-items: center; gap: 6px; }
.session b { color: var(--ink); font-variant-numeric: tabular-nums; }
.session b.neg { color: #FFB4A8; }
.session b.pos { color: #B8F5C8; }
.tools { display: flex; gap: 6px; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.icon-btn:hover { border-color: var(--gold); color: var(--gold-hi); }
.toggle .off { display: none; }
.toggle[aria-pressed="false"] { color: var(--muted); opacity: .75; }
.toggle[aria-pressed="false"] .off { display: inline; }
.toggle[aria-pressed="false"] .wave { display: none; }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.fs-banner { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; justify-content: center; background: linear-gradient(90deg, rgba(108,14,37,.0), rgba(108,14,37,.9) 20%, rgba(108,14,37,.9) 80%, rgba(108,14,37,0)); padding: 6px 40px; font-size: 15px; }
.fs-banner b { color: var(--gold-hi); font-variant-numeric: tabular-nums; }
.fs-title { font-family: 'Cormorant SC', Georgia, serif; font-weight: 700; font-size: 20px; color: var(--gold-hi); }
.fs-banner[hidden] { display: none; }

/* ---------------------------------------------------------------- reels */
.frame {
  position: relative; padding: 10px; border-radius: 20px;
  background: linear-gradient(180deg, #F8D978, #B9802A 40%, #6E400D 60%, #E9B44A);
  box-shadow: 0 20px 50px rgba(0,0,0,.6), 0 0 0 1px rgba(0,0,0,.5);
}
.frame::before { content: ""; position: absolute; inset: 4px; border-radius: 16px; border: 1px solid rgba(255,244,201,.5); pointer-events: none; }
.reels { position: relative; display: grid; grid-template-columns: repeat(5, var(--cell)); gap: 4px; border-radius: 12px; overflow: hidden; background: #120818; }
.reel { position: relative; height: calc(var(--cell) * 3); overflow: hidden; background: linear-gradient(180deg, rgba(48,20,58,.96), rgba(28,10,36,.96) 50%, rgba(48,20,58,.96)); }
.reel::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, rgba(0,0,0,.35), transparent 14%, transparent 86%, rgba(0,0,0,.35)); }
.reel.anticipate { box-shadow: inset 0 0 0 3px rgba(255,217,121,.85), inset 0 0 36px rgba(255,194,78,.55); animation: antglow .6s ease-in-out infinite alternate; }
@keyframes antglow { to { box-shadow: inset 0 0 0 3px rgba(255,240,184,1), inset 0 0 56px rgba(255,194,78,.85); } }
body.reduced .reel.anticipate { animation: none; }
.strip { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.strip.blur .cell img { filter: blur(.6px); }
.cell { width: var(--cell); height: var(--cell); display: grid; place-items: center; position: relative; }
.cell img { width: 92%; height: 92%; display: block; user-select: none; -webkit-user-drag: none; transition: transform .2s, filter .2s; }
.cell.win img { animation: pulse 0.9s ease-in-out infinite; }
.cell.win::before { content: ""; position: absolute; inset: 4px; border-radius: 12px; background: radial-gradient(circle, rgba(255,217,121,.35), transparent 70%); border: 2px solid rgba(255,217,121,.8); }
.cell.dim img { filter: brightness(.45) saturate(.6); }
.cell.plain::before { content: ""; position: absolute; inset: 6px; border-radius: 12px; border: 1px solid rgba(246,231,200,.35); }
@keyframes pulse { 50% { transform: scale(1.08); } }
.lines { position: absolute; left: 10px; top: 10px; z-index: 2; pointer-events: none; overflow: visible; }
.lines polyline { fill: none; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 4px rgba(0,0,0,.8)); }
.lines polyline.quiet { stroke-width: 2; opacity: .6; filter: none; }

.msg { margin: 0; min-height: 1.5em; font-size: 16px; text-align: center; color: var(--ink); text-shadow: 0 1px 3px #000; }
.msg b { color: var(--gold-hi); }

/* ---------------------------------------------------------------- panel */
.panel { display: grid; grid-template-columns: 1fr 1.2fr 1fr auto; gap: 10px; align-items: stretch; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 10px; max-width: 980px; width: 100%; margin: 0 auto; }
.meter { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; padding: 4px 6px; }
.meter .label { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.meter b { font-size: clamp(17px, 2.2vw, 22px); font-variant-numeric: tabular-nums; }
.meter.win-quiet b { color: var(--muted); }
.meter.win-hot b { color: var(--gold-hi); }
.bet-ctrl { display: flex; align-items: center; gap: 10px; }
.round-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.04); font-size: 22px; cursor: pointer; }
.round-btn:hover:not(:disabled) { border-color: var(--gold); }
.round-btn:disabled { opacity: .35; cursor: not-allowed; }
.spin {
  min-width: 132px; min-height: 64px; border-radius: 999px; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 22px;
  font-weight: 800; font-size: 17px; letter-spacing: .04em; color: #2A1300;
  background: linear-gradient(180deg, #FFF0B8, #F2C55A 45%, #C98A25);
  box-shadow: 0 6px 18px rgba(201,138,37,.35), inset 0 -3px 0 rgba(0,0,0,.25);
}
.spin svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.spin:hover:not(:disabled) { filter: brightness(1.06); }
.spin:disabled { filter: grayscale(.7) brightness(.7); cursor: not-allowed; }
.legal { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- big win */
.bigwin { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: radial-gradient(circle, rgba(60,20,10,.75), rgba(8,3,12,.9)); cursor: pointer; }
.bigwin[hidden] { display: none; }
.bigwin-inner { text-align: center; animation: pop .5s cubic-bezier(.2,1.4,.4,1); }
.bigwin-title { margin: 0; font-family: 'Cormorant SC', Georgia, serif; font-weight: 700; font-size: clamp(40px, 8vw, 88px); line-height: 1;
  background: linear-gradient(180deg, #FFF4C9, #F8D978 40%, #C98A25 75%, #8A5714); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.7)); }
.bigwin-amount { margin: 12px 0 0; font-size: clamp(34px, 6vw, 64px); font-weight: 800; font-variant-numeric: tabular-nums; color: #FFF4C9; text-shadow: 0 0 24px rgba(255,194,78,.6); }
.bigwin-hint { margin: 18px 0 0; color: var(--muted); font-size: 14px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.coin { position: fixed; z-index: 21; top: -40px; width: 34px; height: 34px; pointer-events: none; animation: coinfall linear forwards; }
@keyframes coinfall { to { transform: translate3d(var(--dx), 110vh, 0) rotate(720deg); } }

/* ---------------------------------------------------------------- dialogs */
.dlg { border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--panel-solid); color: var(--ink); width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.dlg.wide { width: min(900px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(5, 2, 8, .72); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; position: sticky; top: 0; background: var(--panel-solid); z-index: 1; padding-bottom: 8px; }
.dlg h2 { margin: 0; font-family: 'Cormorant SC', Georgia, serif; font-size: 30px; color: var(--gold-hi); }
.dlg h3 { margin: 18px 0 8px; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.dlg-body { padding: 8px 20px 20px; }
.dlg.center .dlg-body { text-align: center; }
.dlg.center h2 { margin: 8px 0; }
.note { color: var(--muted); font-size: 14px; line-height: 1.55; }
.paytable { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pt { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.pt img { width: 58px; height: 58px; flex: none; }
.pt dl { margin: 0; display: grid; grid-template-columns: auto auto; gap: 0 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.pt dt { color: var(--muted); }
.pt dd { margin: 0; font-weight: 700; text-align: right; }
.specials { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.specials > div { display: flex; gap: 10px; align-items: center; font-size: 14px; line-height: 1.5; }
.specials p { margin: 0; }
.linemap { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.linemap figure { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }
.linemap svg { width: 100%; height: auto; display: block; }
.facts { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.hist { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.hist th, .hist td { padding: 8px 10px; text-align: right; border-bottom: 1px solid rgba(233,180,74,.12); white-space: nowrap; }
.hist th:first-child, .hist td:first-child, .hist td:last-child, .hist th:last-child { text-align: left; }
.hist th { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.hist td.pos { color: #B8F5C8; }
.hist td.neg { color: #FFB4A8; }
.hist-sum { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
.hist-sum b { color: var(--ink); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form .row { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.form .row input { width: 20px; height: 20px; accent-color: var(--gold); }
.form .col { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.form select { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #2A1434; padding: 0 10px; color: var(--ink); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; justify-content: flex-end; }
.btn-row.center { justify-content: center; }
.btn { min-height: 44px; padding: 0 20px; border-radius: 999px; border: 0; cursor: pointer; font-weight: 700; color: #2A1300; background: linear-gradient(180deg, #FFF0B8, #E9B44A); }
.btn.ghost { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.btn.ghost:hover { border-color: var(--gold); }

/* ---------------------------------------------------------------- small screens */
@media (max-width: 720px) {
  .app { padding-left: 8px; padding-right: 8px; }
  .session { order: 3; width: 100%; justify-content: center; }
  .panel { grid-template-columns: 1fr 1fr; }
  .panel .bet { grid-column: span 2; order: -1; }
  .spin { grid-column: span 2; }
  .brand-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) { body:not(.motion-ok) .mote { display: none; } }
body.reduced .mote, body.reduced .coin { display: none; }
body.reduced .cell.win img { animation: none; }
