:root {
  --bg: #121419;
  --bg-2: #1b1e26;
  --card: #22262f;
  --card-2: #2a2f3a;
  --text: #f3f4f7;
  --muted: #9aa1b1;
  --accent: #ff6b57;
  --accent-text: #1b0f0d;
  --ok: #3ddc84;
  --bad: #ff5252;
  --warn: #ffc857;
  --line: #333845;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f3ee;
    --bg-2: #ffffff;
    --card: #ffffff;
    --card-2: #f0ece4;
    --text: #1c1b1a;
    --muted: #6b6760;
    --line: #e2ddd3;
    --shadow: 0 8px 24px rgba(0,0,0,.10);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
  user-select: none;
  -webkit-user-select: none;
}
input, select, textarea { user-select: text; -webkit-user-select: text; }

.screen {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }

h1 { font-size: 36px; margin: 8px 0 0; letter-spacing: -0.5px; }
h2 { font-size: 22px; margin: 0; }
h3 { font-size: 18px; margin: 0 0 6px; }
p { margin: 0; }
b { font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.sub { color: var(--muted); margin-top: 4px; }
.fineprint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 24px; }
.error { color: var(--bad); font-size: 15px; }
.center { text-align: center; align-items: center; }

.hero { text-align: center; padding: 32px 0 24px; }
.logo {
  width: 92px; height: 92px; margin: 0 auto; border-radius: 26px;
  background: radial-gradient(circle at 50% 50%, #fff 0 14%, var(--accent) 15% 32%, #fff 33% 44%, var(--accent) 45%);
  box-shadow: var(--shadow);
}
.logo.small { width: 56px; height: 56px; border-radius: 16px; margin-bottom: 16px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; justify-content: center; }
.row > input { flex: 1; min-width: 0; }

.bar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; min-height: 44px; }
.bar h2 { flex: 1; }
.wallet-bar { justify-content: space-between; }
.w-name { font-size: 22px; font-weight: 700; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-weight: 600; border-radius: var(--radius);
  padding: 14px 18px; min-height: 48px; cursor: pointer; text-align: center;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.98); background: var(--card-2); }
.btn.big { font-size: 18px; min-height: 56px; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.light { background: #fff; color: #111; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.ok { color: var(--ok); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.icon { width: 44px; min-height: 44px; padding: 0; font-size: 24px; line-height: 1; border-radius: 12px; }
.btn.sheet-btn { width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center; }
.hint-inline { display: block; font-size: 13px; font-weight: 400; opacity: .8; }
.btn.sheet-btn .hint { color: var(--muted); font-weight: 400; font-size: 14px; }

input[type=text], input[type=number], select {
  appearance: none; -webkit-appearance: none;
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.code-input { font-size: 28px; letter-spacing: 4px; text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }

.label { font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; }
.field small { display: block; color: var(--muted); font-weight: 400; font-size: 13px; }
.field.check { flex-direction: row; align-items: flex-start; gap: 12px; }
.field.check input { width: 24px; height: 24px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }

.settings { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.settings summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; gap: 6px; }
.settings > .stack { margin-top: 12px; }

.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; min-height: 8px; }
.chips li {
  display: inline-flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 8px 8px 14px; font-weight: 600;
}
.chips li .seat { color: var(--muted); font-weight: 400; font-size: 13px; }
.chips li button { appearance: none; border: 0; background: var(--card-2); color: var(--text); width: 28px; height: 28px; border-radius: 50%; font-size: 16px; cursor: pointer; }

.qr { background: #fff; padding: 12px; border-radius: 16px; width: min(78vw, 320px); box-shadow: var(--shadow); }
.qr svg { display: block; width: 100%; height: auto; }
.code-display { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 34px; letter-spacing: 5px; font-weight: 700; margin-top: 4px; }

.roster { width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.roster .r { display: flex; justify-content: space-between; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.roster .r .seat { color: var(--muted); }

.score { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; font-weight: 600; }
.dots { display: flex; gap: 8px; }
.dots span { width: 18px; height: 18px; border-radius: 50%; background: var(--card-2); border: 2px solid var(--line); }
.dots span.on { background: var(--ok); border-color: var(--ok); }

.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; text-align: left; border-radius: var(--radius); padding: 16px 16px 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px; width: 100%;
  transition: transform .08s ease;
}
.card:active { transform: scale(.985); }
.card .card-text { font-size: 19px; line-height: 1.35; font-weight: 600; }
.card .card-tag { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.card.guess { border-color: var(--warn); }
.card.guess .card-tag { color: var(--warn); }
.card.done { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--card)); }
.card.done .card-tag { color: var(--ok); }
.card.failed { opacity: .55; }
.card.failed .card-text { text-decoration: line-through; }
.card.failed .card-tag { color: var(--bad); }
.card.swapped { opacity: .4; }
.card.swapped .card-text { text-decoration: line-through; }

/* overlays */
.cover {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: 18px;
}
.cover-inner { width: min(100%, 320px); padding: 0 16px; }
.cover-inner form { width: 100%; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 520px; background: var(--bg-2); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
  max-height: 88vh; overflow-y: auto; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.sheet .mission-quote { font-size: 18px; font-weight: 600; line-height: 1.35; margin-bottom: 14px; }
.sheet .stack { gap: 10px; }
.sheet h3 { margin-bottom: 10px; }
.rules p, .rules li { margin-bottom: 8px; line-height: 1.45; }
.rules ol, .rules ul { padding-left: 20px; margin: 0 0 8px; }

.reveal, .win {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; color: #fff;
}
.reveal { background: var(--accent); }
.win { background: #1f8f5a; }
.reveal-inner { max-width: 420px; display: flex; flex-direction: column; gap: 18px; align-items: center; }
.reveal-title { font-size: 44px; font-weight: 900; letter-spacing: -1px; line-height: 1; }
.reveal-emoji { font-size: 72px; line-height: 1; }
.reveal-text { font-size: 22px; font-weight: 600; line-height: 1.35; }
.reveal-by { opacity: .85; }
.win .muted { color: rgba(255,255,255,.8); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 600; z-index: 70;
  box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}

.notice { width: 100%; text-align: left; background: color-mix(in srgb, var(--warn) 14%, var(--card)); border: 1px solid var(--warn); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.notice code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.game-tile { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left; }
.game-tile .meta { color: var(--muted); font-weight: 400; font-size: 14px; }
