:root {
  --bg: #15111E;
  --bg-deep: #0D0A13;
  --surface: #211A2E;
  --surface-2: #2C2340;
  --line: #3A3052;
  --text: #F4EFE6;
  --muted: #B3A9C4;
  --faint: #8E84A3;
  --gold: #F5B83D;
  --gold-deep: #D9982A;
  --ink: #1A1204;
  --teal: #3CCFB6;
  --teal-ink: #0E2420;
  --teal-soft: #1F2A2A;
  --coral: #FF9B85;
  --display: "Bricolage Grotesque", "DM Sans", system-ui, sans-serif;
  --body: "DM Sans", system-ui, -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
a { color: var(--teal); }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.1; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
h2 { font-size: 22px; font-weight: 800; }
h3 { font-size: 18px; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 12px;
  background: var(--bg);
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo img { width: 34px; height: 34px; }
.logo span { font-family: var(--display); font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.logo b { color: var(--gold); font-weight: 800; }
.top-right { display: flex; align-items: center; gap: 8px; }
.tokens {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px 6px 8px; font-weight: 700;
}
.coin { width: 20px; height: 20px; border-radius: 50%; background: var(--gold); box-shadow: inset 0 0 0 4px var(--gold), inset 0 0 0 6px var(--ink); flex: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; }

main { flex: 1; padding: 4px 18px 28px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.bottomnav {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  border-top: 1px solid var(--surface-2); background: var(--bg);
  padding: 6px 10px calc(8px + var(--safe-bottom));
}
.bottomnav a {
  min-height: 48px; padding: 0 14px; display: flex; align-items: center;
  color: var(--faint); text-decoration: none; font-weight: 700; font-size: 15px; border-radius: 12px;
}
.bottomnav a.on { color: var(--gold); }

/* ---------- controls ---------- */
.btn {
  min-height: 52px; border-radius: 14px; border: none; padding: 0 20px;
  font-weight: 700; font-size: 16px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.teal { background: var(--teal); color: var(--teal-ink); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.dashed { background: transparent; color: var(--text); border: 1px dashed #5A4D78; }
.btn.danger { background: transparent; color: var(--coral); border: 1px solid #5C3A3A; }
.btn.small { min-height: 44px; font-size: 14px; padding: 0 14px; border-radius: 12px; }
.btn.block { width: 100%; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  min-height: 52px; padding: 12px 16px; color: var(--text); font-size: 16px;
}
textarea.input { min-height: 160px; resize: vertical; line-height: 1.4; }
.input::placeholder { color: var(--faint); }
.code-input { letter-spacing: 3px; text-transform: uppercase; font-size: 18px; font-weight: 700; }

.tabs { display: flex; gap: 8px; }
.tab {
  flex: 1; min-height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-weight: 700; font-size: 14px;
}
.tab.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  min-height: 60px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); text-align: left; padding: 10px 14px; display: flex; flex-direction: column; justify-content: center;
}
.seg button strong { font-size: 15px; }
.seg button span { font-size: 12px; color: var(--muted); }
.seg button.on { border-color: var(--gold); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--gold); }

.error { color: var(--coral); font-size: 14px; }

.pw { position: relative; display: block; }
.pw .input { padding-right: 84px; }
.pw button {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  min-height: 42px; min-width: 64px; padding: 0 12px; border-radius: 10px; border: none;
  background: var(--surface-2); color: var(--text); font-weight: 700; font-size: 14px;
}

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.claim { background: var(--teal-soft); border: 1px solid #2E4A45; border-radius: 16px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.claim small { color: #B3E9DF; display: block; font-size: 13px; }

.room-card {
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px; color: var(--text); display: flex; flex-direction: column; gap: 8px; text-decoration: none;
}
.room-card .when { font-size: 13px; color: var(--muted); }
.room-card .title { font-family: var(--display); font-size: 20px; font-weight: 700; line-height: 1.15; }
.room-card .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.room-card .meta b { color: var(--gold); }
.tag { font-size: 12px; font-weight: 700; color: var(--teal); }
.tag.gold { color: var(--gold); }
.tag.lilac { color: #C9A7FF; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); border: 1px dashed var(--line); border-radius: 18px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--surface-2);
}
.list-row.me { background: var(--surface-2); border-color: var(--gold); }
.list-row .place { font-family: var(--display); font-weight: 800; font-size: 18px; min-width: 40px; }
.list-row .amt { font-weight: 700; color: var(--gold); }

/* ---------- pack picker ---------- */
.cat { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.cat > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 700; display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); min-height: 52px;
}
.cat > summary::-webkit-details-marker { display: none; }
.cat[open] > summary { border-bottom: 1px solid var(--line); }
.pack-opt { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px; cursor: pointer; }
.pack-opt + .pack-opt { border-top: 1px solid var(--surface-2); }
.pack-opt input { width: 22px; height: 22px; accent-color: var(--gold); flex: none; }
.pack-opt .count { margin-left: auto; color: var(--faint); font-size: 13px; }
.phrase-total { position: sticky; bottom: 70px; z-index: 5; }

/* ---------- game ---------- */
.game-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.live-tag { font-size: 13px; font-weight: 700; color: var(--teal); }
.pot { text-align: right; }
.pot small { display: block; font-size: 12px; color: var(--muted); }
.pot strong { font-family: var(--display); font-size: 24px; font-weight: 800; color: var(--gold); }
.countdown { font-variant-numeric: tabular-nums; }

.board { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.cell {
  aspect-ratio: 1 / 1; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 11px; line-height: 1.15; font-weight: 700; padding: 4px;
  display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden;
  overflow-wrap: normal; word-break: normal; transition: transform .12s ease;
}
.cell.long { font-size: 9.5px; letter-spacing: -.2px; }
.cell.xlong { font-size: 8.5px; letter-spacing: -.3px; }
.cell:active { transform: scale(.94); }
.cell.on { background: var(--gold); color: var(--ink); border-color: var(--gold); }
.cell.win { box-shadow: inset 0 0 0 2px #FFF3D6; }
.cell.free { background: var(--teal); color: var(--teal-ink); border: none; font-family: var(--display); font-size: 16px; font-weight: 800; }
.cell.stamp { animation: stamp .28s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes stamp { from { transform: scale(.7); } to { transform: scale(1); } }
@media (min-width: 420px) { .cell { font-size: 12px; } .cell.long { font-size: 11px; } .cell.xlong { font-size: 10px; } }

.reactions { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.reactions::-webkit-scrollbar { display: none; }
.reactions button {
  flex: none; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 700;
}
.feed { min-height: 20px; text-align: center; font-size: 14px; color: var(--muted); }
.feed b { color: var(--text); }

.bingo {
  flex: 1; height: 62px; border: none; border-radius: 16px; font-family: var(--display); font-weight: 800;
  background: var(--surface-2); color: var(--faint); font-size: 16px;
}
.bingo.ready { background: var(--gold); color: var(--ink); font-size: 26px; animation: pulse 1.1s ease-in-out infinite; }
.bingo.called { background: var(--teal); color: var(--teal-ink); font-size: 18px; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(245, 184, 61, .55); } 50% { box-shadow: 0 0 0 10px rgba(245, 184, 61, 0); } }

.code-box { text-align: center; padding: 22px 16px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); }
.code-box .code { font-family: var(--display); font-size: 44px; font-weight: 800; letter-spacing: 6px; color: var(--gold); margin: 6px 0 14px; }

.result-hero { background: var(--gold); color: var(--ink); border-radius: 22px; padding: 22px; display: flex; flex-direction: column; gap: 4px; }
.result-hero h1 { font-size: 38px; }
.result-hero.plain { background: var(--surface-2); color: var(--text); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

/* ---------- overlays ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 6, 12, .72);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 26px 26px 0 0; padding: 22px 20px calc(24px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px;
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.toast-wrap { position: fixed; left: 0; right: 0; top: calc(12px + var(--safe-top)); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-weight: 700; font-size: 14px;
  max-width: 440px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); animation: rise .2s ease-out;
}
.toast.bad { background: var(--coral); color: #2A0F08; }

.onboard { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; justify-content: center; }
.onboard-inner { width: 100%; max-width: 480px; padding: calc(40px + var(--safe-top)) 24px calc(28px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 22px; }
.onboard-inner h1 { font-size: 40px; }
.onboard-art { flex: 1; display: grid; place-items: center; }
.dots { display: flex; gap: 8px; justify-content: center; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots span.on { background: var(--gold); width: 24px; border-radius: 8px; }

.auth { min-height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 22px; padding: 32px 22px; }
.auth .brand { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.auth .brand img { width: 96px; height: 96px; }
.auth .brand h1 { font-size: 40px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
