:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --text: #151826;
  --muted: #5d6479;
  --border: #dde1ec;
  --accent: #5b4cf0;
  --accent-text: #ffffff;
  --accent-soft: #ecebfe;
  --ok: #117a4f;
  --ok-soft: #e3f5ec;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --danger: #b4232f;
  --danger-soft: #fde8ea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 8px 24px rgba(20, 24, 40, 0.05);
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1018;
    --surface: #171a26;
    --surface-2: #1f2332;
    --text: #e9ebf3;
    --muted: #9aa1b8;
    --border: #2a2f42;
    --accent: #8479ff;
    --accent-text: #0e1018;
    --accent-soft: #252346;
    --ok: #4fd39a;
    --ok-soft: #13291f;
    --warn: #f1bf57;
    --warn-soft: #2d2412;
    --danger: #ff7b86;
    --danger-soft: #34171b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.9rem; line-height: 1.2; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 0 0 0.5rem; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 6px; }
[hidden] { display: none !important; }

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 28px; padding-bottom: 48px; min-height: 70vh; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.6rem 0 0; }
.mono { font-family: var(--mono); }
.small { font-size: 0.8rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.big { font-size: 1.8rem; font-weight: 700; margin: 0.25rem 0; font-variant-numeric: tabular-nums; }

/* ---------- top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar__inner { display: flex; align-items: center; gap: 24px; min-height: 64px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 999px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.wallet__account { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 0.9rem; }
.wallet__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover:not(:disabled) { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn--primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn--danger { color: var(--danger); border-color: var(--danger); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 5px 11px; font-size: 0.875rem; }
.btn--block { width: 100%; }

/* ---------- cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card--warn { border-color: var(--warn); background: var(--warn-soft); }
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
.grid > .card { margin-bottom: 0; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.empty { text-align: center; padding: 48px 22px; }

/* ---------- hero */
.hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; margin-bottom: 20px; }
.hero__main {
  border-radius: var(--radius); padding: 28px;
  background: linear-gradient(135deg, var(--accent) 0%, #8b45d6 100%); color: #fff;
}
.hero__main .muted { color: rgba(255, 255, 255, 0.8); }
.hero__side { margin-bottom: 0; }
.eyebrow { margin: 0; font-weight: 600; opacity: 0.9; }
.pot { font-size: clamp(2.4rem, 7vw, 3.8rem); margin: 0.3rem 0 0; font-variant-numeric: tabular-nums; }
.pot small { font-size: 0.4em; font-weight: 600; opacity: 0.85; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 24px 0 0; }
.facts div { background: rgba(255, 255, 255, 0.14); border-radius: 10px; padding: 10px 12px; }
.facts dt { font-size: 0.8rem; opacity: 0.85; }
.facts dd { margin: 0; font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.hero .state { background: rgba(255, 255, 255, 0.2); color: #fff; }

.buy label { font-weight: 600; display: block; margin-bottom: 8px; }
.stepper { display: flex; gap: 8px; }
.stepper input { flex: 1; min-width: 0; text-align: center; font: inherit; font-size: 1.2rem; font-weight: 700; padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.buy__total { margin: 14px 0; font-size: 1.05rem; }
.draw-actions { margin-top: 14px; display: grid; gap: 8px; }

/* ---------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; }
.stat__value { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat__label { color: var(--muted); font-size: 0.875rem; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: 0; }
tr.is-winner td { background: var(--ok-soft); }
td.args { white-space: normal; word-break: break-all; max-width: 420px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ---------- states, alerts, toasts */
.state { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; text-transform: capitalize; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.state--open { background: var(--accent-soft); color: var(--accent); }
.state--drawing { background: var(--warn-soft); color: var(--warn); }
.state--completed { background: var(--ok-soft); color: var(--ok); }
.state--cancelled { background: var(--danger-soft); color: var(--danger); }
.state--refunded { background: var(--warn-soft); color: var(--warn); }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; border: 1px solid transparent; }
.alert--info { background: var(--accent-soft); }
.alert--success { background: var(--ok-soft); color: var(--ok); }
.alert--error { background: var(--danger-soft); color: var(--danger); }
.alert--warn { background: var(--warn-soft); color: var(--warn); }

.banner--warn { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--warn); padding: 10px 0; }
.banner .container { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15); }
.toast--success { border-left: 4px solid var(--ok); }
.toast--error { border-left: 4px solid var(--danger); }
.toast--warn { border-left: 4px solid var(--warn); }
.toast--info { border-left: 4px solid var(--accent); }

/* ---------- modal */
.modal { position: fixed; inset: 0; background: rgba(8, 10, 20, 0.55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal__card { background: var(--surface); border-radius: var(--radius); padding: 24px; width: min(420px, 100%); }
.wallet-list { display: grid; gap: 8px; margin: 16px 0; }
.wallet-option { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.wallet-option:hover { border-color: var(--accent); }

/* ---------- forms, misc */
.form-grid { display: grid; gap: 10px; max-width: 420px; }
.form-grid label, .filters label { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.form-grid input, .filters select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.owner-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; }
.filters { display: flex; gap: 10px; align-items: end; margin-bottom: 16px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; }
.refunds { padding-left: 1.2rem; }
.refunds li { margin-bottom: 8px; }

.footer { border-top: 1px solid var(--border); padding: 20px 0; color: var(--muted); font-size: 0.85rem; }
.footer__inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; }
  .topbar__inner { gap: 10px; padding: 10px 16px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .wallet { margin-left: auto; }
}

/* ---------- lotteries (home) */
.intro { margin-bottom: 20px; }
.intro h1 { margin-bottom: 0.4rem; }
.intro p { max-width: 760px; margin: 0; }

.wallet-bar { display: flex; flex-wrap: wrap; gap: 12px 32px; align-items: center; padding: 14px 22px; }
.wallet-bar > div:not(.wallet-bar__actions) { display: flex; flex-direction: column; }
.wallet-bar strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.wallet-bar__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.lotteries { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; margin-bottom: 20px; }
.lotteries > .card { margin-bottom: 0; }
.lottery { display: flex; flex-direction: column; gap: 10px; border-top: 4px solid var(--accent); }
.lottery--jackpot { border-top-color: #d99a00; }
.lottery__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.lottery__head h2 { margin: 0; font-size: 1.35rem; }
.lottery__head p { margin: 2px 0 0; }
.lottery__label { margin: 6px 0 0; color: var(--muted); font-size: 0.85rem; }
.lottery .pot { font-size: clamp(2rem, 6vw, 2.8rem); margin: 0; font-weight: 800; }
.lottery .facts { margin: 4px 0 0; }
.lottery .facts div { background: var(--surface-2); }
.lottery .facts dd { font-size: 1rem; }
.lottery .draw-actions { margin: 0; }

.progress { width: 100%; height: 10px; appearance: none; border: 0; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
.progress::-webkit-progress-value { background: linear-gradient(90deg, #d99a00, #f5c542); border-radius: 999px; }
.progress::-moz-progress-bar { background: linear-gradient(90deg, #d99a00, #f5c542); border-radius: 999px; }
.lottery .progress + p { margin: 0; }

.stake label { display: grid; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.stake__row { display: flex; gap: 8px; }
.stake__row input { flex: 1; min-width: 0; font: inherit; font-size: 1.15rem; font-weight: 700; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.stake__preview { margin: 8px 0 0; color: var(--text); font-weight: 500; min-height: 1.5em; }
.stake .hint { margin-top: 4px; }
.my-stake { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--accent-soft); }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.example { background: var(--surface-2); border-radius: 10px; padding: 12px 16px; }
.example p { margin: 0 0 6px; }
.example ul { margin: 0; }

.state--empty { background: var(--surface-2); color: var(--muted); }
.owner-actions .form-grid { border: 1px solid var(--border); border-radius: 12px; padding: 16px; }

/* ---------- stack */
.lottery--stack { border-top-color: #13a37a; }
.prize-ladder { list-style: none; margin: 4px 0 2px; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.prize-ladder li { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; }
.prize-ladder__place { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.prize-ladder strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.lottery--stack .progress::-webkit-progress-value { background: linear-gradient(90deg, #13a37a, #3fd3a6); }
.lottery--stack .progress::-moz-progress-bar { background: linear-gradient(90deg, #13a37a, #3fd3a6); }
.state--expired { background: var(--warn-soft); color: var(--warn); }
.prize-inputs { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 8px; }
.prize-inputs legend { font-size: 0.85rem; color: var(--muted); padding: 0 4px; }

/* ---------- admin: earnings */
.earnings { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
#earnings-panel .kv { margin-top: 16px; }
