:root {
  --bg: #07090c; --felt: #0f3d2e; --felt-deep: #082a20;
  --surface: rgba(10, 14, 18, .72); --surface-2: rgba(255, 255, 255, .04); --line: rgba(212, 175, 55, .22); --line-strong: rgba(212, 175, 55, .55);
  --ink: #f4ecd8; --muted: #b3a88c; --muted-2: #7d735c;
  --gold: #d4af37; --gold-light: #f6e27a; --gold-dark: #8a6a1e; --red: #c1121f; --red-light: #e5383b; --green: #2fbf71;
  --gold-grad: linear-gradient(180deg, #f9eaa0 0%, #d4af37 48%, #a67c1e 100%);
  --radius: 14px; --ease: cubic-bezier(.2, .8, .2, 1);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink); font: 16px/1.5 Poppins, system-ui, sans-serif; background: var(--bg);
  background-image:
    radial-gradient(ellipse 120% 60% at 50% -10%, var(--felt) 0%, var(--felt-deep) 45%, transparent 75%),
    radial-gradient(ellipse 80% 50% at 50% 110%, rgba(212, 175, 55, .08), transparent 70%);
  background-attachment: fixed;
}
body::before { /* felt grain */
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .28; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
h1, h2, h3 { margin: 0; font-family: Cinzel, Georgia, serif; }
.gold { background: var(--gold-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; max-width: 1120px; margin: 0 auto; }
.top h1 { font-size: clamp(24px, 4vw, 32px); font-weight: 800; letter-spacing: .06em; line-height: 1.1; }
.top h1 small { display: block; font: 500 12px/1 Poppins, sans-serif; letter-spacing: .32em; color: var(--muted); margin-top: 6px; text-transform: uppercase; }
.credits {
  display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: 0 6px 20px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .06);
  font: 700 20px/1 Poppins, sans-serif; color: var(--gold-light); font-variant-numeric: tabular-nums;
}
.chip { /* poker chip */
  width: 30px; height: 30px; border-radius: 50%; flex: none; position: relative;
  background: repeating-conic-gradient(var(--gold) 0 22.5deg, #7a1420 22.5deg 45deg); box-shadow: 0 2px 4px rgba(0, 0, 0, .6);
}
.chip::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: #7a1420; border: 2px solid var(--gold-light); }

/* ---------- layout ---------- */
main { --head: 98px; display: grid; gap: 14px; padding: 6px 16px 16px; max-width: 1800px; margin: 0 auto;
  grid-template-areas: "board" "balls" "bets" "status"; }
.board-wrap { grid-area: board; position: relative; width: 100%; margin: 0 auto; aspect-ratio: 656 / 828; }
.balls-sec { grid-area: balls; } .bets-sec { grid-area: bets; } .status-sec { grid-area: status; }
canvas {
  display: block; width: 100%; height: 100%; touch-action: none; border-radius: 10px; user-select: none; -webkit-user-select: none; cursor: grab;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .7), 0 0 0 1px rgba(212, 175, 55, .25), 0 0 60px rgba(212, 175, 55, .08);
}
canvas:active { cursor: grabbing; }
.toast {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%); padding: 10px 18px; border-radius: 999px; pointer-events: none; white-space: nowrap;
  background: rgba(8, 10, 12, .92); border: 1px solid var(--gold); color: var(--gold-light); font: 600 15px Poppins, sans-serif;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .6); animation: pop .25s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, -8px) scale(.96); } }

/* ---------- panel ---------- */
.panel {
  display: grid; gap: 16px; padding: 16px; border-radius: var(--radius); position: relative; align-content: start;
  background: var(--surface); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); box-shadow: 0 24px 60px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .05);
  transition: box-shadow .4s var(--ease);
}
.panel.win { box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 0 1px var(--gold), 0 0 50px rgba(212, 175, 55, .35); }
.panel h2 { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; color: var(--gold); margin-bottom: 10px; }
.panel h2::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-strong), transparent); }
.bets { display: grid; gap: 16px; }
.panel .sub { font: 400 12px Poppins, sans-serif; letter-spacing: 0; text-transform: none; color: var(--muted); }

.seg { display: grid; gap: 8px; grid-template-columns: repeat(4, 1fr); }
#digits { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
.seg button {
  min-width: 0; height: 46px; border-radius: 12px; cursor: pointer; position: relative;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: 600 17px Poppins, sans-serif; transition: transform .15s var(--ease), background .2s, border-color .2s, box-shadow .2s;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
}
#digits button { border-radius: 50%; aspect-ratio: 1; height: auto; }
.seg button:hover:not(:disabled) { border-color: var(--line-strong); background: rgba(212, 175, 55, .08); }
.seg button:active:not(:disabled) { transform: scale(.96); }
.seg button.on { background: var(--gold-grad); color: #1c1407; border-color: var(--gold-light); box-shadow: 0 4px 14px rgba(212, 175, 55, .35), inset 0 1px 0 rgba(255, 255, 255, .5); }
.seg button:disabled { opacity: .4; cursor: default; }
.seg button:focus-visible, .card:focus-visible, .btn:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 2px; }
#balls button { display: flex; align-items: center; justify-content: center; gap: 3px; }
#balls .b { width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff, #b9bec6 40%, #3a3e45 90%); box-shadow: 0 1px 2px rgba(0, 0, 0, .6); }

/* tombola cards */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; padding: 5px; position: relative; cursor: pointer;
  border-radius: 8px; background: var(--c); color: #1a1208; border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(0, 0, 0, .25), inset 0 0 0 3px rgba(255, 255, 255, .12);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), filter .18s;
}
.card::before { /* paper grain */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: .18; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.card:hover:not(.locked) { transform: translateY(-2px); filter: brightness(1.08); }
.card.on { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0, 0, 0, .5), 0 0 0 2px var(--gold-light), 0 0 24px rgba(212, 175, 55, .45), inset 0 0 0 3px rgba(255, 255, 255, .12); }
.card.locked { cursor: default; }
.card.locked:not(.on) { filter: saturate(.6) brightness(.8); }
.card span { aspect-ratio: 1.15; display: grid; place-items: center; border-radius: 3px; font: 600 clamp(11px, 2.4vw, 15px) Poppins, sans-serif; font-variant-numeric: tabular-nums; }
.card span.n { background: #f7efdb; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .12); }
.card span.hit { background: var(--gold-grad); color: #1c1407; box-shadow: 0 0 10px rgba(212, 175, 55, .8); }
.card i { position: absolute; right: -1px; top: -1px; padding: 1px 7px; border-radius: 0 8px 0 8px; background: rgba(0, 0, 0, .55); color: var(--gold-light); font: 700 10px Cinzel, serif; font-style: normal; letter-spacing: .05em; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }
.cost { color: var(--muted); font-size: 14px; }
.cost b { color: var(--gold-light); font-size: 18px; font-variant-numeric: tabular-nums; }
.btn { border: 0; cursor: pointer; border-radius: 12px; font: 700 15px Poppins, sans-serif; transition: transform .15s var(--ease), filter .2s; }
.btn:active { transform: scale(.97); }
.btn.next { background: var(--gold-grad); color: #1c1407; padding: 10px 18px; box-shadow: 0 6px 18px rgba(212, 175, 55, .3); }
.btn.shoot { /* lives on the board, over the painted strip under the numbers */
  --p: 0; position: absolute; left: 47%; bottom: 6.4%; transform: translateX(-50%); width: 38%; height: 5.4%; min-height: 44px; border-radius: 12px; overflow: hidden; z-index: 2; touch-action: none; user-select: none; -webkit-user-select: none;
  font: 800 clamp(14px, 2.6vh, 20px)/1 Cinzel, Georgia, serif; letter-spacing: .22em; color: #fff7e0; text-shadow: 0 2px 4px rgba(0, 0, 0, .6);
  background: linear-gradient(180deg, #e0303c 0%, #b30f1c 55%, #7a0a12 100%); border: 1px solid var(--gold);
  box-shadow: 0 10px 28px rgba(193, 18, 31, .35), inset 0 1px 0 rgba(255, 255, 255, .35), inset 0 -3px 0 rgba(0, 0, 0, .35);
}
.btn.shoot::before { /* charge meter */
  content: ""; position: absolute; inset: 0; transform-origin: left; transform: scaleX(var(--p)); background: var(--gold-grad); opacity: .9;
}
.btn.shoot::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 255, 255, .22), transparent 50%); pointer-events: none; }
.btn.shoot span { position: relative; }
.btn.shoot:disabled { filter: grayscale(.6) brightness(.6); cursor: default; }
@media (max-width: 899px) { .btn.shoot { bottom: -20px; width: 60%; height: 52px; } .board-wrap { margin-bottom: 22px; } }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint b { color: var(--ink); }

/* results */
.result[hidden] { display: none; }
.result { display: grid; gap: 8px; padding: 14px; border-radius: 12px; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); animation: rise .3s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.result .r { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.result .num, .win-why .num { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; flex: none; background: radial-gradient(circle at 35% 30%, #fff, #c5cad1 38%, #4a4f57 92%); color: #111; font: 700 16px Poppins, sans-serif; box-shadow: 0 3px 8px rgba(0, 0, 0, .6), inset 0 -2px 3px rgba(0, 0, 0, .3); }
.result .win { color: var(--gold-light); font-weight: 600; }
.result .lose { color: var(--muted-2); }
.result .total { font: 800 20px Cinzel, Georgia, serif; letter-spacing: .04em; padding-top: 6px; border-top: 1px solid var(--line); }
.result .total.yes { background: var(--gold-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result .total.no { color: var(--muted); }

/* win popup */
.win-dlg { border: 1px solid var(--gold); border-radius: 18px; padding: 28px 24px 22px; width: min(92vw, 400px); color: var(--ink); text-align: center; overflow: hidden;
  background: radial-gradient(ellipse at 50% 0%, #1a3d2f, #0b0f12 65%); box-shadow: 0 30px 80px rgba(0, 0, 0, .8), 0 0 60px rgba(212, 175, 55, .35); animation: burst .4s var(--ease); }
.win-dlg::backdrop { background: rgba(3, 5, 8, .7); backdrop-filter: blur(4px); }
@keyframes burst { from { opacity: 0; transform: scale(.85); } }
.win-rays { position: absolute; inset: -60%; pointer-events: none; opacity: .18; animation: spin 30s linear infinite;
  background: repeating-conic-gradient(from 0deg, var(--gold) 0 6deg, transparent 6deg 18deg); mask: radial-gradient(circle, #000 0%, transparent 55%); -webkit-mask: radial-gradient(circle, #000 0%, transparent 55%); }
@keyframes spin { to { transform: rotate(360deg); } }
.win-dlg > * { position: relative; }
.win-kicker { margin: 0; font: 600 12px Poppins, sans-serif; letter-spacing: .4em; text-transform: uppercase; color: var(--muted); }
.win-dlg h2 { font-size: 40px; font-weight: 800; letter-spacing: .06em; margin: 4px 0 0; }
.win-total { margin: 2px 0 16px; font: 700 26px Poppins, sans-serif; color: var(--gold-light); font-variant-numeric: tabular-nums; }
.win-why { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 8px; text-align: left; }
.win-why li { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, .05); border: 1px solid var(--line); font-size: 14px; }
.win-why li > span:nth-child(2) { flex: 1; }
.win-why b { color: var(--gold-light); }
.win-why em { font-style: normal; font-weight: 700; color: var(--gold-light); }
.win-actions { display: flex; gap: 10px; justify-content: center; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line-strong); padding: 10px 16px; }
.btn.next { padding: 10px 18px; }

details.rules { font-size: 13px; color: var(--muted); }
details.rules summary { cursor: pointer; color: var(--gold); font-weight: 600; letter-spacing: .04em; }
details.rules p { margin: 6px 0 0; }

.foot { margin: 0; text-align: center; color: var(--muted-2); font-size: 12px; letter-spacing: .04em; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- desktop: board centre stage, leverage left, bets right, nothing scrolls ---------- */
@media (min-width: 900px) {
  main { height: calc(100dvh - var(--head) + 22px); grid-template-columns: minmax(180px, 1fr) auto minmax(300px, 1.7fr); grid-template-rows: auto minmax(0, 1fr); justify-content: center; align-items: start; gap: 24px;
    grid-template-areas: "balls board bets" "status board bets"; }
  /* as tall as the viewport allows, but never so wide that the side columns can't fit */
  .board-wrap { height: min(calc(100dvh - var(--head)), calc((100vw - 560px) * 828 / 656)); width: auto; max-width: 100%; }
  .bets-sec { max-height: calc(100dvh - var(--head)); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
  .status-sec { align-self: end; max-height: 100%; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
  .result .r { font-size: 13px; } .result .num { width: 34px; height: 34px; font-size: 14px; }
  #balls { grid-template-columns: 1fr; }
  #balls button { height: 56px; font-size: 20px; gap: 6px; }
  #balls .b { width: 14px; height: 14px; }
  #digits { grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); }
  .cards { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
  .card span { font-size: clamp(11px, .95vw, 15px); }
  #digits { grid-template-columns: repeat(9, 1fr); }
}
@media (min-width: 900px) and (max-height: 760px) { .panel { gap: 12px; padding: 12px; } #balls button { height: 46px; } }
