:root {
  --bg: #f5f3fa;
  --surface: #ffffff;
  --surface-2: #f0edf8;
  --text: #1d1730;
  --muted: #6a6582;
  --border: #e2ddef;
  --primary: #4c1d95;
  --primary-2: #6d28d9;
  --on-primary: #ffffff;
  --ball: #fbbf24;
  --ball-ink: #3b1d00;
  --ok: #166534;   --ok-bg: #dcfce7;
  --last: #92400e; --last-bg: #fef3c7;
  --due: #b91c1c;  --due-bg: #fee2e2;
  --late: #6d28d9; --late-bg: #ede9fe;
  --free: #8a85a3;
  --shadow: 0 1px 2px rgba(29, 23, 48, .06), 0 4px 16px rgba(29, 23, 48, .06);
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #110d1c;
    --surface: #1b1629;
    --surface-2: #251f37;
    --text: #efecf7;
    --muted: #a39dbb;
    --border: #2f2843;
    --primary: #8b5cf6;
    --primary-2: #a78bfa;
    --on-primary: #ffffff;
    --ok: #86efac;   --ok-bg: #12301f;
    --last: #fcd34d; --last-bg: #3a2c0b;
    --due: #fca5a5;  --due-bg: #3d1515;
    --late: #c4b5fd; --late-bg: #2b2152;
    --free: #6f6987;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #110d1c; --surface: #1b1629; --surface-2: #251f37; --text: #efecf7; --muted: #a39dbb; --border: #2f2843;
  --primary: #8b5cf6; --primary-2: #a78bfa; --on-primary: #fff;
  --ok: #86efac; --ok-bg: #12301f; --last: #fcd34d; --last-bg: #3a2c0b; --due: #fca5a5; --due-bg: #3d1515;
  --late: #c4b5fd; --late-bg: #2b2152; --free: #6f6987; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary-2); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar & tabs */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--primary); color: var(--on-primary);
}
.topbar h1 { flex: 1; font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .15); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--primary-2); }
.tabs a[aria-current="page"] svg { fill: color-mix(in srgb, var(--primary-2) 18%, transparent); }

.page { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); }
.page.narrow { max-width: 460px; padding-bottom: 32px; }
.loading { color: var(--muted); text-align: center; margin-top: 40px; }

/* Cards & sections */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card > h2, .section-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.section-title .count { margin-left: auto; color: var(--muted); font-weight: 600; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 10px; }

.hero {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--on-primary); border: 0;
}
.hero .label { opacity: .85; font-size: 14px; font-weight: 600; }
.hero .pot { font-size: 44px; font-weight: 800; letter-spacing: -1px; margin: 2px 0 2px; }
.hero .sub { opacity: .9; font-size: 14px; }
.hero .btn { background: rgba(255, 255, 255, .16); color: #fff; border-color: transparent; }
.hero .btn.whatsapp { background: #fff; color: #128c4b; }

.alert { border-color: color-mix(in srgb, var(--last) 40%, var(--border)); background: var(--last-bg); }
.alert h2 { color: var(--last); }

/* Ball */
.ball {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6d5 0 18%, var(--ball) 55%, #d97706 100%);
  color: var(--ball-ink); font-weight: 800; font-size: 18px;
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, .15);
}
.ball.big { width: 76px; height: 76px; font-size: 32px; }
.ball.empty { background: var(--surface-2); color: var(--muted); box-shadow: none; border: 2px dashed var(--border); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 2px; background: none; border: 0; text-align: left; cursor: pointer; color: inherit; text-decoration: none;
}
.item .main { flex: 1; min-width: 0; }
.item .title, .item .meta { display: block; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13.5px; color: var(--muted); }
.num {
  display: inline-grid; place-items: center; flex: none; min-width: 36px; height: 36px; padding: 0 6px;
  border-radius: 10px; background: var(--surface-2); font-weight: 800; font-variant-numeric: tabular-nums;
}
.chev { color: var(--muted); flex: none; }
.empty-note { color: var(--muted); font-size: 14px; padding: 4px 0; }

/* Pills */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
}
.st-ok   { background: var(--ok-bg);   color: var(--ok); }
.st-last { background: var(--last-bg); color: var(--last); }
.st-due  { background: var(--due-bg);  color: var(--due); }
.st-late { background: var(--late-bg); color: var(--late); }
.st-free { background: var(--surface-2); color: var(--free); }
.st-won  { background: var(--ok-bg);   color: var(--ok); }
.st-rollover { background: var(--last-bg); color: var(--last); }
.st-awaiting, .st-history, .st-next { background: var(--surface-2); color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 650; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.danger { color: var(--due); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }

/* Numbers grid */
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.search {
  width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); margin-bottom: 10px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  aspect-ratio: 1 / 1.05; border-radius: 14px; border: 1px solid transparent; cursor: pointer; padding: 4px; min-width: 0;
}
.tile b { font-size: 20px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { font-size: 11.5px; font-weight: 600; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.st-free { background: transparent; border: 1.5px dashed var(--border); }
.tile.dim { opacity: .25; }

/* Player */
.profile { display: flex; align-items: center; gap: 14px; }
.profile h2 { font-size: 22px; }
.weeks { list-style: none; margin: 0; padding: 0; }
.weeks li button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 2px; border: 0; background: none;
  border-top: 1px solid var(--border); cursor: pointer; text-align: left;
}
.weeks li:first-child button { border-top: 0; }
.weeks .date { flex: 1; font-variant-numeric: tabular-nums; }
.weeks .is-next .date { font-weight: 700; }
.weeks .result { font-size: 13px; color: var(--muted); }

/* Draw detail */
.breakdown { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.breakdown td { padding: 7px 0; border-top: 1px solid var(--border); }
.breakdown tr:first-child td { border-top: 0; }
.breakdown td:last-child { text-align: right; font-weight: 650; }
.breakdown tr.total td { font-weight: 800; font-size: 18px; }
.winner-row { background: var(--ok-bg); border-radius: 10px; }

/* Forms */
.form label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 12px; }
.form input:not([type=radio]):not([type=file]), .form select, .form textarea {
  display: block; width: 100%; margin-top: 6px; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-weight: 400;
}
.form textarea { min-height: 70px; resize: vertical; }
.form fieldset { border: 1px solid var(--border); border-radius: 12px; margin: 0 0 14px; padding: 10px 12px; }
.form .radio { display: flex; gap: 8px; align-items: center; font-weight: 500; flex-wrap: wrap; }
.error { color: var(--due); background: var(--due-bg); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks .ok { color: var(--ok); } .checks .bad { color: var(--due); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  min-width: 52px; min-height: 40px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 700; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.stepper { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.stepper input { width: 80px; text-align: center; font-size: 20px; font-weight: 700; min-height: 46px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.stepper button { width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-size: 22px; font-weight: 700; cursor: pointer; }
.preview { background: var(--surface-2); border-radius: 12px; padding: 12px; margin-bottom: 14px; font-size: 14.5px; }
.preview strong { font-size: 17px; }
.options { display: grid; gap: 8px; }
.options .btn { justify-content: flex-start; }

/* Sheet (dialog) */
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgba(10, 6, 20, .5); }
.sheet .sheet-head { display: flex; align-items: center; gap: 8px; padding: 16px 16px 8px; }
.sheet .sheet-head h2 { flex: 1; font-size: 18px; }
.sheet .sheet-head .icon-btn { color: var(--muted); }
.sheet .sheet-body { padding: 4px 16px calc(20px + env(safe-area-inset-bottom)); overflow: auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px;
  background: #1d1730; color: #fff; font-weight: 600; font-size: 14.5px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }

.amount { font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.in { color: var(--ok); }
.amount.out { color: var(--due); }
.diff-ok { color: var(--ok); }
.diff-bad { color: var(--due); }
.form .check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.form .check input { margin-top: 4px; width: 18px; height: 18px; }

.msg-preview { white-space: pre-wrap; background: var(--surface-2); border-radius: 12px; padding: 12px; font-size: 14px; max-height: 260px; overflow: auto; }
.log li { padding: 8px 0; font-size: 14px; }
.log .when { color: var(--muted); font-size: 12.5px; }
.login-logo { display: grid; place-items: center; margin: 24px 0 18px; }
.login-logo img { width: 84px; height: 84px; border-radius: 22px; }
