:root {
  --bg: #0a0920;
  --surface: rgba(255, 255, 255, .055);
  --surface2: rgba(255, 255, 255, .09);
  --line: rgba(255, 255, 255, .12);
  --text: #f4f1ff;
  --muted: #a9a3cc;
  --gold: #ffcf5a;
  --gold2: #ff9f43;
  --pink: #ff5fa2;
  --violet: #8b6cff;
  --cyan: #3ee0d0;
  --danger: #ff7b7b;
  --gold-ink: #ffcf5a;              /* gold used as text on the page */
  --field: rgba(0, 0, 0, .28);      /* inputs, summary, result groups */
  --track: rgba(255, 255, 255, .15);
  --hover: rgba(255, 255, 255, .15);
  --thumb: rgba(255, 255, 255, .14);
  --card-shadow: 0 20px 50px -30px rgba(0, 0, 0, .6);
  --font: 'Prompt', system-ui, sans-serif;
  --display: 'Kanit', 'Prompt', sans-serif;
  color-scheme: dark;
}
:root[data-theme=light] {
  --bg: #f6f4fd;
  --surface: #ffffff;
  --surface2: rgba(60, 40, 140, .07);
  --line: rgba(60, 40, 140, .13);
  --text: #1e1842;
  --muted: #645d8a;
  --danger: #d3383f;
  --gold-ink: #a26a00;
  --field: #f4f2fb;
  --track: rgba(60, 40, 140, .16);
  --hover: rgba(60, 40, 140, .12);
  --thumb: rgba(60, 40, 140, .2);
  --card-shadow: 0 16px 40px -24px rgba(60, 40, 140, .35);
  color-scheme: light;
}
/* the stage stays a dark "screen" in both themes */
.stage {
  --surface: rgba(255, 255, 255, .055);
  --surface2: rgba(255, 255, 255, .09);
  --line: rgba(255, 255, 255, .12);
  --text: #f4f1ff;
  --muted: #a9a3cc;
  --hover: rgba(255, 255, 255, .15);
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
kbd {
  font: 500 12px var(--font);
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
}

/* ---------- background ---------- */
.bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background:
    radial-gradient(1100px 600px at 10% -10%, #2a1b6b 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #4a1450 0%, transparent 55%),
    linear-gradient(180deg, #0a0920, #0b0a1c);
}
.blob {
  position: absolute; width: 460px; height: 460px; border-radius: 50%;
  filter: blur(90px); opacity: .32; will-change: transform;
  animation: float 22s ease-in-out infinite alternate;
}
.b1 { background: var(--violet); top: -120px; left: -80px; }
.b2 { background: var(--pink); top: 30%; right: -160px; animation-duration: 26s; }
.b3 { background: #1d6bff; bottom: -200px; left: 30%; animation-duration: 30s; opacity: .22; }
@keyframes float {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(80px, 60px, 0) scale(1.15); }
}
.stars {
  position: absolute; inset: 0; opacity: .5;
  background-image:
    radial-gradient(1px 1px at 20% 30%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 20%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 40% 80%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 65%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 10% 90%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 55% 45%, #fff 50%, transparent 51%);
  background-size: 420px 420px;
}
:root[data-theme=light] .bg {
  background:
    radial-gradient(1100px 600px at 10% -10%, #e2d9ff 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #ffd8ea 0%, transparent 55%),
    linear-gradient(180deg, #f8f6ff, #f2eefb);
}
:root[data-theme=light] .blob { opacity: .16; }
:root[data-theme=light] .b3 { opacity: .1; }
:root[data-theme=light] .stars { display: none; }

/* ---------- hero ---------- */
.hero {
  max-width: 1280px; margin: 0 auto;
  padding: 56px 20px 32px; text-align: center;
}
.hero h1 {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(38px, 7vw, 76px); line-height: 1.1;
  margin: 0; letter-spacing: -.5px;
}
.grad {
  background: linear-gradient(100deg, var(--gold) 10%, var(--gold2) 45%, var(--pink) 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  padding-left: .15em;
}
:lang(en) .grad { padding-left: .28em; }
.hero { position: relative; }
.top-tools {
  position: absolute; top: 16px; right: 20px; z-index: 5;
  display: flex; align-items: center; gap: 8px;
}
.theme-toggle {
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; padding: 0;
  background: var(--surface); border: 1px solid var(--line); color: var(--gold-ink);
  transition: background .2s, transform .3s;
}
.theme-toggle:hover { background: var(--surface2); }
.theme-toggle:active { transform: scale(.92); }
.theme-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.theme-toggle svg { width: 19px; height: 19px; animation: spinIn .45s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes spinIn { from { transform: rotate(-90deg) scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.lang-switch {
  display: inline-flex; padding: 3px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line);
}
.lang-switch button {
  border: 0; cursor: pointer; background: transparent; color: var(--muted);
  font: 600 13px var(--font); padding: 5px 12px; border-radius: 99px;
  transition: background .2s, color .2s;
}
.lang-switch button:hover { color: var(--text); }
.lang-switch button[aria-pressed=true] { background: linear-gradient(135deg, var(--gold), var(--gold2)); color: #2a1700; }
.lang-switch button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (max-width: 640px) { .top-tools { top: 12px; right: 16px; } .hero { padding-top: 64px; } }
.hero-stats {
  list-style: none; padding: 0; margin: 28px auto 0;
  display: flex; justify-content: center; gap: 12px; flex-wrap: wrap;
}
.hero-stats li {
  min-width: 140px; padding: 12px 18px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.hero-stats b { font-family: var(--display); font-size: 26px; color: var(--gold-ink); line-height: 1.2; font-variant-numeric: tabular-nums; }
.hero-stats span { font-size: 12px; color: var(--muted); }

/* ---------- layout ---------- */
.layout {
  max-width: 1280px; margin: 0 auto; padding: 0 20px 40px;
  display: grid; grid-template-columns: 370px minmax(0, 1fr); gap: 20px; align-items: start;
}
.panel { display: flex; flex-direction: column; gap: 20px; }
.results { grid-column: 1 / -1; }
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 0 16px 32px; }
  .stage-col { order: -1; }
  .hero { padding: 40px 16px 24px; }
}

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 20px;
  box-shadow: var(--card-shadow);
}
.card h2 { font-size: 17px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--pink)); font-size: 13px; font-weight: 700;
}
.pill {
  font-size: 12px; padding: 3px 10px; border-radius: 99px;
  background: var(--surface2); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.pill.gold { background: rgba(255, 207, 90, .15); color: var(--gold-ink); }

textarea {
  width: 100%; height: 230px; resize: vertical;
  background: var(--field); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; font: 400 14px/1.6 var(--font);
  outline: none; transition: border-color .2s, box-shadow .2s;
}
textarea:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(139, 108, 255, .25); }
textarea[readonly] { opacity: .65; cursor: not-allowed; }

.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; min-height: 1em; }
.lock-note { margin-top: 10px; font-size: 13px; padding: 8px 12px; border-radius: 10px; background: rgba(255, 207, 90, .1); color: var(--gold-ink); }

/* ---------- buttons ---------- */
.btn {
  border: 0; cursor: pointer; border-radius: 12px; padding: 10px 16px;
  font-weight: 500; background: var(--surface2);
  transition: transform .15s, background .2s, opacity .2s;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.sm { font-size: 13px; padding: 7px 12px; border-radius: 10px; }
.btn.danger { color: var(--danger); }
.btn.primary {
  background: linear-gradient(135deg, var(--gold), var(--gold2));
  color: #2a1700; font-weight: 700;
  box-shadow: 0 12px 30px -10px rgba(255, 170, 60, .7);
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(135deg, #ffe08a, #ffb25e); }
.btn.primary.restart {
  background: linear-gradient(135deg, var(--violet), var(--pink)); color: #fff;
  box-shadow: 0 12px 30px -10px rgba(255, 95, 162, .7);
}
.btn.primary.restart:hover:not(:disabled) { background: linear-gradient(135deg, #9d82ff, #ff7bb3); }
.btn.xl { font-family: var(--display); font-size: 21px; padding: 16px 30px; border-radius: 16px; }
.btn.primary:not(:disabled)::after { content: ''; }
.btn.primary.ready { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 12px 30px -10px rgba(255, 170, 60, .7), 0 0 0 0 rgba(255, 207, 90, .45); }
  50% { box-shadow: 0 12px 30px -10px rgba(255, 170, 60, .7), 0 0 0 12px rgba(255, 207, 90, 0); }
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, .35); cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); }

/* ---------- form ---------- */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.field label { font-size: 13px; color: var(--muted); }
.field label b { color: var(--gold-ink); }
.num { display: flex; align-items: stretch; background: var(--field); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.num:focus-within { border-color: var(--violet); }
.num button { width: 38px; border: 0; background: transparent; cursor: pointer; font-size: 18px; color: var(--muted); }
.num button:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.num input {
  flex: 1; min-width: 0; width: 100%; text-align: center; border: 0; outline: none; background: transparent;
  color: var(--text); font: 600 18px var(--font); padding: 8px 0; -moz-appearance: textfield;
}
.num input::-webkit-outer-spin-button, .num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.summary { font-size: 13px; color: var(--muted); margin: 12px 0 14px; padding: 10px 12px; border-radius: 12px; background: var(--field); }
.summary b { color: var(--text); }
.summary .warn { display: block; color: var(--gold-ink); margin-top: 4px; }

.check, .switch { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; margin-top: 12px; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--violet); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  flex: none; width: 42px; height: 24px; border-radius: 99px; background: var(--track);
  position: relative; transition: background .2s;
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .2s cubic-bezier(.3, 1.4, .5, 1);
}
.switch input:checked + .track { background: linear-gradient(135deg, var(--violet), var(--pink)); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--gold); outline-offset: 2px; }
.switch input:disabled ~ * { opacity: .5; }
input[type=range] { width: 100%; accent-color: var(--gold); }

/* ---------- modes ---------- */
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 640px) { .modes { grid-template-columns: repeat(2, 1fr); } }
.mode {
  position: relative; text-align: left; cursor: pointer;
  padding: 12px 14px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center;
  transition: border-color .2s, background .2s, transform .15s;
}
.mode:hover:not(:disabled) { background: var(--surface2); }
.mode:disabled { cursor: not-allowed; opacity: .55; }
.mode .ico { grid-row: span 2; font-size: 26px; }
.mode .m-name { font-weight: 600; font-size: 15px; }
.mode small { color: var(--muted); font-size: 11px; line-height: 1.3; }
.mode.active {
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(255, 207, 90, .14), rgba(255, 95, 162, .1));
  box-shadow: 0 0 0 1px var(--gold) inset;
}
.mode.rec::after {
  content: var(--rec-label, 'แนะนำ'); position: absolute; top: -8px; right: 10px;
  font-size: 10px; font-weight: 600; padding: 1px 8px; border-radius: 99px;
  background: var(--cyan); color: #032622;
}

/* ---------- stage ---------- */
.stage {
  position: relative; height: clamp(420px, 62vh, 660px);
  border-radius: 24px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, #2b2170 0%, #120f33 60%, #0b0920 100%);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .8);
}
.stage:fullscreen { height: 100vh; border-radius: 0; border: 0; }
.stage-inner { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; }
.stage-top {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; pointer-events: none;
}
.stage-top > * { pointer-events: auto; }
.stage-label {
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 99px;
  background: rgba(0, 0, 0, .4); border: 1px solid var(--line); color: var(--gold);
}
.stage-empty {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  color: var(--muted); padding: 20px;
}
.stage-empty .big { font-size: 54px; }

.controls { display: flex; gap: 16px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.controls .btn.xl { flex: 0 1 auto; min-width: 260px; }
.progress { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 6px; }
.progress .bar { height: 10px; border-radius: 99px; background: var(--track); overflow: hidden; }
.progress .bar i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--violet), var(--pink), var(--gold));
  transition: width .6s cubic-bezier(.2, .8, .2, 1);
}
.progress span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kbd-hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
@media (max-width: 640px) {
  .controls .btn.xl { width: 100%; min-width: 0; }
  .kbd-hint { display: none; }
}

/* ---------- wheel ---------- */
.wheel-wrap { position: absolute; inset: 0; display: grid; place-items: center; }
.wheel-canvas { display: block; border-radius: 50%; box-shadow: 0 25px 60px -10px rgba(0, 0, 0, .7), 0 0 80px -10px rgba(139, 108, 255, .5); }
.wheel-pointer {
  position: absolute; left: 50%; top: calc(50% - var(--ws, 300px) / 2 - 10px);
  transform: translateX(-50%); z-index: 3;
  width: 0; height: 0;
  border-left: 18px solid transparent; border-right: 18px solid transparent;
  border-top: 36px solid #fff;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .5));
}
.wheel-pointer.tick { animation: nudge .12s ease-out; }
@keyframes nudge { 50% { transform: translateX(-50%) rotate(-12deg); } }
.wheel-hub {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: calc(var(--ws, 300px) * .22); height: calc(var(--ws, 300px) * .22); min-width: 70px; min-height: 70px;
  border-radius: 50%; display: grid; place-content: center; text-align: center;
  background: radial-gradient(circle at 35% 30%, #fff3c4, var(--gold) 45%, #c97a10);
  color: #3a2200; box-shadow: 0 6px 20px rgba(0, 0, 0, .5), inset 0 -4px 10px rgba(0, 0, 0, .2);
}
.wheel-hub b { font-family: var(--display); font-size: clamp(14px, calc(var(--ws, 300px) * .05), 26px); line-height: 1.1; }
.wheel-hub small { font-size: 11px; font-weight: 500; }
.wheel-current {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 6px 16px; border-radius: 99px; background: rgba(0, 0, 0, .5); border: 1px solid var(--line);
  font-weight: 600; font-size: 15px; opacity: 0; transition: opacity .3s;
}
.wheel-current.on { opacity: 1; }

/* shared winner popup */
.popup {
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; padding: 20px;
  background: rgba(6, 4, 22, .55); pointer-events: none;
}
.popup-card {
  pointer-events: auto; max-width: min(640px, 100%); text-align: center;
  padding: 26px 34px; border-radius: 24px;
  background: linear-gradient(160deg, rgba(43, 33, 112, .95), rgba(74, 20, 80, .95));
  border: 1px solid rgba(255, 207, 90, .55);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 60px rgba(255, 207, 90, .25);
  animation: popIn .6s cubic-bezier(.2, 1.5, .4, 1) both;
}
.popup-card .lbl { color: var(--gold); font-weight: 600; font-size: 14px; letter-spacing: .5px; }
.popup-card .nm {
  font-family: var(--display); font-weight: 700; font-size: clamp(28px, 5.5vw, 54px); line-height: 1.2;
  margin-top: 6px; word-break: break-word;
  background: linear-gradient(100deg, #fff, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.popup-card .no { color: var(--muted); font-size: 13px; margin-top: 6px; }
@keyframes popIn {
  from { opacity: 0; transform: scale(.6) translateY(20px); }
  to { opacity: 1; transform: none; }
}

/* ---------- slot ---------- */
.slot-grid {
  --ih: 48px;
  display: grid; gap: 16px 14px; padding: 64px 20px 24px; min-height: 100%;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); align-content: center;
}
.slot-grid[data-size=xl] { --ih: 92px; grid-template-columns: minmax(0, 620px); justify-content: center; }
.slot-grid[data-size=lg] { --ih: 66px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.slot-grid[data-size=sm] { --ih: 38px; gap: 12px 10px; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.reel {
  position: relative; padding: 6px; border-radius: 16px;
  background: linear-gradient(180deg, #17133d, #241d5c 50%, #17133d);
  border: 1px solid rgba(255, 207, 90, .25);
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, .6);
  transition: border-color .3s, box-shadow .3s;
}
.reel::before {
  content: ''; position: absolute; left: 6px; right: 6px; z-index: 1; pointer-events: none;
  top: calc(6px + var(--ih)); height: var(--ih);
  border-top: 1px solid rgba(255, 207, 90, .45); border-bottom: 1px solid rgba(255, 207, 90, .45);
  background: rgba(255, 207, 90, .06);
}
.reel-no {
  position: absolute; top: -9px; left: 12px; z-index: 2;
  font-size: 11px; font-weight: 700; padding: 0 8px; border-radius: 99px;
  background: var(--gold); color: #2a1700; line-height: 18px;
}
.reel-window {
  height: calc(var(--ih) * 3); overflow: hidden; border-radius: 12px;
  -webkit-mask-image: linear-gradient(transparent, #000 28%, #000 72%, transparent);
  mask-image: linear-gradient(transparent, #000 28%, #000 72%, transparent);
}
.reel-strip { will-change: transform; }
.reel.spinning .reel-strip { filter: blur(1.4px); }
.reel-item {
  height: var(--ih); line-height: var(--ih); padding: 0 12px; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500; font-size: calc(var(--ih) * .36); color: #d9d3ff;
}
.reel.idle .reel-item:nth-child(2) { color: var(--gold); font-family: var(--display); font-size: calc(var(--ih) * .5); }
.reel.won { border-color: var(--gold); box-shadow: inset 0 2px 12px rgba(0, 0, 0, .6), 0 0 26px -4px rgba(255, 207, 90, .6); }
.reel.won .reel-item.win {
  color: var(--gold); font-weight: 700; animation: glowText 1s ease-out;
  /* full name: wrap up to the row height instead of truncating */
  white-space: normal; text-overflow: clip; line-height: 1.12;
  display: flex; align-items: center; justify-content: center;
  overflow-wrap: anywhere; padding: 2px 8px;
}
@keyframes glowText { from { text-shadow: 0 0 24px #fff; transform: scale(1.12); } to { text-shadow: none; transform: none; } }

/* ---------- cards ---------- */
.cards-wrap { min-height: 100%; display: flex; flex-direction: column; justify-content: safe center; gap: 18px; padding: 64px 20px 24px; }
.cards-ticker {
  text-align: center; font-family: var(--display); font-weight: 700;
  font-size: clamp(22px, 4vw, 38px); min-height: 1.3em; color: var(--gold);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 0 24px rgba(255, 207, 90, .5);
}
.card-grid { --ch: 104px; display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card-grid[data-size=xl] { --ch: 220px; grid-template-columns: minmax(0, 420px); justify-content: center; }
.card-grid[data-size=lg] { --ch: 150px; grid-template-columns: repeat(auto-fit, minmax(200px, 260px)); justify-content: center; }
.card-grid[data-size=sm] { --ch: 78px; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.flip { height: var(--ch); perspective: 900px; }
.flip-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform .75s cubic-bezier(.2, .8, .2, 1);
}
.flip.open .flip-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 10px; text-align: center; overflow: hidden;
}
.face.back {
  background: repeating-linear-gradient(45deg, #5536d0 0 10px, #6446e3 10px 20px);
  border: 2px solid rgba(255, 207, 90, .65);
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, .15), 0 10px 24px -10px rgba(0, 0, 0, .7);
}
.face.back .card-mark {
  width: calc(var(--ch) * .42); height: calc(var(--ch) * .42); border-radius: 50%;
  display: grid; place-items: center; font-size: calc(var(--ch) * .22);
  background: rgba(10, 8, 30, .55); color: var(--gold); border: 2px solid rgba(255, 207, 90, .6);
}
.face.front {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, #fffaf0, #ffe39a 60%, #ffcf5a);
  color: #2a1700; border: 2px solid #fff;
  box-shadow: 0 0 30px -6px rgba(255, 207, 90, .8);
}
.card-no { font-size: 11px; font-weight: 700; opacity: .7; }
.face.back .card-no { position: absolute; top: 6px; left: 10px; color: #fff; }
.card-name {
  font-weight: 700; font-size: clamp(13px, calc(var(--ch) * .15), 30px); line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
}
.card-grid.shuffling .flip { animation: wobble .42s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes wobble {
  from { transform: translate3d(0, 0, 0) rotate(-2.5deg); }
  to { transform: translate3d(0, -7px, 0) rotate(2.5deg); }
}

/* fullscreen: flex rows so every row (including a partial last row) is centered */
.stage:fullscreen .slot-grid,
.stage:fullscreen .card-grid {
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center;
  max-width: 1600px; margin: 0 auto; width: 100%;
}
.stage:fullscreen .slot-grid { --ih: 56px; padding: 72px 32px 32px; }
.stage:fullscreen .slot-grid .reel { flex: 0 1 280px; }
.stage:fullscreen .slot-grid[data-size=sm] { --ih: 44px; }
.stage:fullscreen .slot-grid[data-size=sm] .reel { flex-basis: 210px; }
.stage:fullscreen .slot-grid[data-size=lg] { --ih: 84px; }
.stage:fullscreen .slot-grid[data-size=lg] .reel { flex-basis: 380px; }
.stage:fullscreen .slot-grid[data-size=xl] { --ih: 110px; }
.stage:fullscreen .slot-grid[data-size=xl] .reel { flex-basis: 760px; }
.stage:fullscreen .cards-wrap { padding: 72px 32px 32px; }
.stage:fullscreen .card-grid { --ch: 130px; }
.stage:fullscreen .card-grid .flip { flex: 0 1 220px; }
.stage:fullscreen .card-grid[data-size=sm] { --ch: 96px; }
.stage:fullscreen .card-grid[data-size=sm] .flip { flex-basis: 170px; }
.stage:fullscreen .card-grid[data-size=lg] { --ch: 190px; }
.stage:fullscreen .card-grid[data-size=lg] .flip { flex-basis: 320px; }
.stage:fullscreen .card-grid[data-size=xl] { --ch: 280px; }
.stage:fullscreen .card-grid[data-size=xl] .flip { flex-basis: 520px; }

/* ---------- warp ---------- */
.warp-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.warp-center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 700 clamp(28px, 5vw, 58px)/1.25 var(--display); color: #fff;
  text-shadow: 0 0 30px rgba(139, 108, 255, .95), 0 0 6px rgba(255, 255, 255, .8);
  pointer-events: none; opacity: 0; transition: opacity .3s;
  padding: 6px 28px; border-radius: 20px; background: rgba(8, 6, 26, .72);
  box-shadow: 0 0 60px 30px rgba(8, 6, 26, .6);
}
.warp-center.on { opacity: 1; }
.warp-flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(circle, #fff 0%, rgba(255, 240, 200, .6) 35%, transparent 70%); }
.warp-flash.on { animation: flash 1s ease-out; }
@keyframes flash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
.warp-result {
  position: absolute; inset: 0; overflow: auto; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 18px;
  padding: 64px 20px 24px; background: radial-gradient(ellipse at center, rgba(8, 6, 26, .88), rgba(8, 6, 26, .7));
}
.warp-result h3 { margin: 0; font-family: var(--display); color: var(--gold); font-size: clamp(20px, 3vw, 28px); font-weight: 700; }
.w-chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 1100px; }
.w-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 8px 14px 8px 8px; border-radius: 99px;
  background: linear-gradient(135deg, #3a2a6e, #4a1f5c);
  border: 1px solid rgba(255, 207, 90, .55); font-weight: 600;
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, .7);
  animation: chipIn .55s cubic-bezier(.2, 1.5, .4, 1) both; animation-delay: var(--d, 0s);
}
.w-chip i {
  font-style: normal; font-size: 11px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 99px;
  display: grid; place-items: center; background: var(--gold); color: #2a1700; font-weight: 700;
}
.w-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-big {
  font-family: var(--display); font-weight: 800; text-align: center; word-break: break-word;
  font-size: clamp(36px, 7vw, 84px); line-height: 1.15;
  background: linear-gradient(100deg, #fff, var(--gold) 50%, var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: popIn .7s cubic-bezier(.2, 1.5, .4, 1) both;
}
@keyframes chipIn { from { opacity: 0; transform: scale(.4) translateY(16px); } to { opacity: 1; transform: none; } }

/* ---------- results ---------- */
.results-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.results-head .row-btns { margin-top: 0; }
.result-list { max-height: 520px; overflow: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 4px; }
.result-empty { text-align: center; color: var(--muted); padding: 34px 10px; font-size: 14px; }
.r-group { border: 1px solid var(--line); border-radius: 16px; padding: 12px; background: var(--field); }
.r-group.fresh { border-color: rgba(255, 207, 90, .5); animation: fadeUp .5s ease-out both; }
.r-head { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.r-round { color: var(--gold-ink); font-weight: 600; font-size: 14px; }
.r-time { margin-left: auto; }
.r-items { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px; }
.r-items li {
  display: flex; gap: 10px; align-items: center; padding: 6px 10px; border-radius: 10px;
  background: var(--surface); font-size: 14px; min-width: 0;
}
.r-group.fresh li { animation: fadeUp .4s ease-out both; animation-delay: var(--d, 0s); }
.r-no { flex: none; min-width: 32px; text-align: center; font-size: 12px; font-weight: 700; color: var(--gold-ink); font-variant-numeric: tabular-nums; }
.r-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 32px; }

/* ---------- overlays ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; }
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 101;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 12px; font-size: 14px;
  background: #fff; color: #1a1440; font-weight: 500; box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  transition: opacity .25s, transform .25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--thumb); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  .blob, .btn.primary.ready { animation: none; }
}
