:root {
  --bg: #f6f4ff;
  --surface: #ffffff;
  --surface-2: #efecfb;
  --text: #1d1a33;
  --muted: #6b6788;
  --line: #e0dcf2;
  --accent: #5b4bdb;
  --accent-ink: #ffffff;
  --accent-soft: #e6e2ff;
  --gold: #f4b400;
  --good: #1f9d55;
  --good-soft: #dcf5e6;
  --warn: #b7791f;
  --warn-soft: #fdf1d6;
  --bad: #d64545;
  --bad-soft: #fde2e2;
  --shadow: 0 1px 2px rgba(30, 20, 80, .06), 0 4px 16px rgba(30, 20, 80, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14121f;
    --surface: #1e1b2e;
    --surface-2: #29253d;
    --text: #eeebff;
    --muted: #a39fc0;
    --line: #353050;
    --accent: #8b7dff;
    --accent-ink: #14121f;
    --accent-soft: #2f2a52;
    --good-soft: #173826;
    --warn-soft: #3a2f14;
    --bad-soft: #3d1c1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14121f; --surface: #1e1b2e; --surface-2: #29253d; --text: #eeebff; --muted: #a39fc0; --line: #353050;
  --accent: #8b7dff; --accent-ink: #14121f; --accent-soft: #2f2a52; --good-soft: #173826; --warn-soft: #3a2f14; --bad-soft: #3d1c1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; margin-top: 1.4em; }
h3 { font-size: 1.05rem; }
p { margin: .4em 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--text); white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 8px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); white-space: nowrap; font-weight: 600; font-size: .95rem;
}
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav .badge { margin-left: 4px; }

.page { max-width: 960px; margin: 0 auto; padding: 20px 16px 80px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.list > * + * { margin-top: 10px; }

.btn {
  appearance: none; border: 1px solid transparent; border-radius: 12px; padding: 10px 16px; font: inherit; font-weight: 650;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; justify-content: center;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.good { background: var(--good); color: #fff; }
.btn.bad { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 6px 10px; min-height: 36px; font-size: .9rem; }
.btn.big { font-size: 1.1rem; padding: 14px 22px; }
.icon-btn { border: 0; background: none; font-size: 1.4rem; color: var(--text); cursor: pointer; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--accent); }
textarea { min-height: 80px; }
.fields { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; margin: 8px 0; }
.hint { font-size: .85rem; color: var(--muted); font-weight: 400; margin-top: 4px; }
.error { color: var(--bad); }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 650;
  background: var(--surface-2); color: var(--muted);
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 7px; font-size: .75rem; }

.emoji { font-size: 1.8rem; line-height: 1; }
.avatar { font-size: 2rem; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); flex: none; }
.pts { font-weight: 800; color: var(--warn); white-space: nowrap; }
.balance { font-size: 3rem; font-weight: 900; line-height: 1; }
.hero { text-align: center; padding: 24px 16px; background: linear-gradient(135deg, var(--accent-soft), var(--surface)); }

.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--good); border-radius: 999px; transition: width .3s; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.choice-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.choice {
  border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 14px; cursor: pointer; text-align: left;
  font: inherit; color: var(--text);
}
.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.choice .emoji { display: block; margin-bottom: 6px; }

.wait-options { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.wait-options .choice { text-align: center; }
.wait-options .bonus { color: var(--good); font-weight: 800; }
.nudge { background: var(--warn-soft); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }

.pin-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 10px; justify-content: center; margin-top: 12px; }
.pin-pad button { height: 64px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 1.5rem; font-weight: 700; cursor: pointer; }
.pin-dots { text-align: center; font-size: 2rem; letter-spacing: .3em; min-height: 2.6rem; }

dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(20, 15, 50, .45); }
dialog .dlg-body { padding: 20px; overflow-y: auto; max-height: calc(100dvh - 120px); }
dialog .dlg-actions { padding: 12px 20px 20px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(150%); background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-weight: 600; transition: transform .25s; max-width: calc(100vw - 32px); z-index: 50;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); color: #fff; }

table { width: 100%; border-collapse: collapse; }
td, th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; font-size: .95rem; }
.table-wrap { overflow-x: auto; }
.code { font-family: ui-monospace, monospace; font-size: 1.3rem; font-weight: 800; letter-spacing: .1em; }

@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .brand span { display: none; }
  .balance { font-size: 2.4rem; }
  .pin-pad { grid-template-columns: repeat(3, 64px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
