:root {
  color-scheme: dark;
  --bg: #0b0820;
  --surface: #18113f;
  --surface-2: #231a55;
  --border: #352a7c;
  --border-strong: #6556c4;
  --text: #f3f0ff;
  --muted: #b8b0dd;
  --pink: #ff3ea5;
  --cyan: #35e0ff;
  --lime: #b6ff3b;
  --gold: #ffd23f;
  --danger: #ff8793;
  --grid: rgb(120 100 255 / 0.12);
  --cabinet: 0 5px 0 #070517, 0 10px 28px #00000030;
  --display: "Chakra Petch", "IBM Plex Sans Thai", system-ui, sans-serif;
  --body: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--text);
  font: 400 16px/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--display); font-weight: 700; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); letter-spacing: 0.01em; }
h2 { font-size: 1.2rem; letter-spacing: 0.02em; }
p { margin: 0; }
a { color: var(--cyan); }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px max(16px, env(safe-area-inset-left)) 14px;
  border-bottom: 1px solid var(--border);
  background: rgb(11 8 32 / 0.85);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 600; }
.brand-mark { width: 36px; height: 36px; display: block; filter: drop-shadow(0 0 8px #ff3ea560); }
.brand-name { font-size: 1.05rem; letter-spacing: 0.02em; }
.pill {
  font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  color: var(--bg); background: var(--gold);
}
.lang { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.lang a {
  padding: 5px 12px; color: var(--muted); text-decoration: none; font-family: var(--display); font-weight: 600;
  font-size: 0.9rem;
}
.lang a[aria-current] { background: var(--surface-2); color: var(--text); }

/* ---------- layout ---------- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 16px 64px; display: grid; gap: 20px; }
.intro { display: grid; gap: 6px; }
.intro p { color: var(--muted); max-width: 60ch; }
.grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.col-main, .col-side { display: grid; gap: 20px; align-content: start; }
@media (min-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr) 340px; }
}
@media (max-width: 899px) {
  /* Phones: the main wallet first, then the game, the session, and the player switcher. */
  .col-side { display: contents; }
  .wallet { order: -1; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--cabinet);
  display: grid; gap: 12px; align-content: start;
}
.muted { color: var(--muted); }
.flash {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
}
.flash-ok { border-color: color-mix(in srgb, var(--lime) 55%, transparent); color: var(--lime); }
.flash-error { border-color: color-mix(in srgb, var(--danger) 60%, transparent); color: var(--danger); }

/* ---------- forms & buttons ---------- */
.name-form { display: grid; gap: 6px; }
.name-form label { font-size: 0.9rem; color: var(--muted); }
.row { display: flex; gap: 8px; }
input {
  flex: 1; min-width: 0; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 12px;
}
input::placeholder { color: #7d74ad; }
.btn {
  font: 600 1rem/1 var(--display); letter-spacing: 0.02em; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text);
  box-shadow: 0 3px 0 #070517;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #070517; }
.btn-primary { background: var(--pink); border-color: var(--pink); color: #1a0010; box-shadow: 0 3px 0 #8a1459, 0 0 22px -7px #ff3ea5b0; }
.btn-primary:active { box-shadow: 0 1px 0 #8a1459; }
.btn-coin { width: 100%; background: transparent; border-color: var(--gold); color: var(--gold); box-shadow: 0 3px 0 #5c4a0e; }
.link {
  background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 0.9rem;
  text-decoration: underline; cursor: pointer; justify-self: start;
}

/* ---------- player pick ---------- */
.pick { max-width: 560px; }

/* ---------- marquee (game card) ---------- */
.marquee {
  border-radius: 16px; overflow: hidden; border: 1px solid var(--border-strong);
  background: var(--surface); box-shadow: var(--cabinet);
  display: grid;
}
.keyart { display: block; background: #120b35; }
.keyart img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; object-position: 50% 45%; }
@media (min-width: 900px) { .keyart img { aspect-ratio: 2 / 1; } }
/* Square cover art (owner 2026-11-23): shown whole, at its own shape, centred on the card. */
.keyart-square { background: radial-gradient(ellipse at center, #241a5c, #120b35 70%); }
.keyart-square img { aspect-ratio: 1 / 1; object-fit: contain; max-width: 560px; margin: 0 auto; }
@media (min-width: 900px) { .keyart-square img { aspect-ratio: 1 / 1; } }
.marquee-body { padding: 14px 20px 20px; display: grid; gap: 12px; }
.title-row { display: flex; align-items: center; gap: 12px; }
.badge { width: 64px; height: 64px; flex: none; filter: drop-shadow(0 3px 8px #000a); }
.marquee-body h2 { font-size: clamp(1.45rem, 3.2vw, 2rem); }
.marquee-body p { color: var(--muted); max-width: 62ch; }
.tiers { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-width: 420px; }
.tiers li {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; text-align: center;
  font-family: var(--display); font-size: 0.92rem; background: var(--bg);
}
.tier-low b { color: var(--cyan); }
.tier-mid b { color: var(--lime); }
.tier-high b { color: var(--gold); }
.btn-play { justify-self: start; min-width: 160px; font-size: 1.1rem; }

/* ---------- active session ---------- */
.session-row { display: grid; gap: 12px; }
.session-game { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-weight: 600; }
.pending {
  font-family: var(--body); font-weight: 500; font-size: 0.85rem; color: var(--gold);
  border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent); border-radius: 999px; padding: 1px 10px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 10px var(--lime); }
.figures { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 600px) { .figures { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.fig { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.fig dt { font-size: 0.8rem; color: var(--muted); }
.fig dd { margin: 0; font-family: var(--display); font-weight: 600; font-variant-numeric: tabular-nums; }
.fig-wallet { border-color: color-mix(in srgb, var(--cyan) 60%, transparent); }
.fig-wallet dd { color: var(--cyan); font-size: 1.15rem; }
.fig dd.pos { color: var(--lime); }
.fig dd.neg { color: var(--danger); }
.empty { padding: 4px 0; }

/* ---------- wallet readout ---------- */
.readout {
  font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums;
  font-size: clamp(2rem, 6vw, 2.5rem); color: var(--gold); line-height: 1;
  background: #0d0926; border: 1px solid #2a2166; border-radius: 12px; padding: 16px 14px;
  box-shadow: inset 0 2px 10px #000a;
  display: flex; align-items: baseline; gap: 6px; overflow-wrap: anywhere;
}
.readout .cur { font-size: 0.6em; color: #c9a52f; }
.changed { animation: bump 700ms ease-out; }
@keyframes bump {
  0% { text-shadow: 0 0 0 transparent; }
  25% { text-shadow: 0 0 18px currentColor; }
  100% { text-shadow: 0 0 0 transparent; }
}

/* ---------- player ---------- */
.current { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 600; font-size: 1.15rem; }
.avatar {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--cyan); text-transform: uppercase;
}

/* ---------- how to play ---------- */
h3 { font-family: var(--display); font-weight: 600; font-size: 1.02rem; margin: 0 0 8px; color: var(--muted); }
.how-grid { display: grid; gap: 22px; }
@media (min-width: 900px) { .how-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; } }
.steps { counter-reset: step; list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; max-width: 60ch; }
.steps li::before {
  content: counter(step); display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  font-family: var(--display); font-weight: 700; color: var(--bg); background: var(--cyan);
}
.rules { list-style: none; margin: 18px 0 0; padding: 14px 0 0; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.rules li { color: var(--muted); padding-left: 16px; position: relative; max-width: 62ch; font-size: 0.95rem; }
.rules li::before { content: ""; position: absolute; left: 0; top: 0.62em; width: 6px; height: 6px; background: var(--pink); transform: rotate(45deg); }
.rules li:first-child { color: var(--text); }
.paytable td { white-space: normal; vertical-align: middle; }
.paytable .z { display: flex; align-items: center; gap: 12px; }
.paytable .z img, .z-ph { width: 56px; height: 56px; flex: none; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.z-name { display: block; font-family: var(--display); font-weight: 600; }
.z-note { display: block; color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.paytable td.mult { font-family: var(--display); font-weight: 700; color: var(--gold); font-size: 1.05rem; white-space: nowrap; }
.paytable tr.boss td { background: color-mix(in srgb, var(--pink) 10%, transparent); }
.paytable tr.boss td:first-child { box-shadow: inset 3px 0 0 var(--pink); }
.paytable tr.boss .mult { color: var(--pink); }

/* ---------- history ---------- */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 9px 8px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.82rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { font-family: var(--display); font-weight: 500; }
td small { color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
.pos { color: var(--lime); }
.neg { color: var(--danger); }
.empty-table td { border: 0; padding: 4px 0; }

@media (max-width: 520px) {
  .col-game { display: none; }
  .row { flex-direction: column; }
  .btn-play { width: 100%; }
  .badge { width: 52px; height: 52px; }
}
@media (max-width: 520px) {
  /* Paytable rows become a small grid: thumbnail | name | multiplier, with the note full width below. */
  .paytable thead { display: none; }
  .paytable tr {
    display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 2px;
    align-items: center; padding: 10px 6px; border-bottom: 1px solid var(--border);
  }
  .paytable tbody tr:last-child { border-bottom: 0; }
  .paytable td, .paytable .z, .paytable .z > div { display: contents; }
  .paytable .z img, .paytable .z-ph { grid-column: 1; grid-row: 1 / span 2; width: 48px; height: 48px; align-self: start; }
  .paytable .z-name { grid-column: 2; grid-row: 1; }
  .paytable td.mult { grid-column: 3; grid-row: 1; }
  .paytable .z-note { grid-column: 2 / 4; grid-row: 2; }
  .paytable tr.boss { background: color-mix(in srgb, var(--pink) 10%, transparent); box-shadow: inset 3px 0 0 var(--pink); border-radius: 8px; }
  .paytable tr.boss td, .paytable tr.boss td:first-child { background: none; box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
  .changed { animation: none; }
  .btn { transition: none; }
}
