:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1d1b16;
  --muted: #6b665a;
  --border: #ddd7ca;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --warn-bg: #fff3bf;
  --warn-text: #5c4400;
  --ok-bg: #d3f9d8;
  --ok-text: #1b4d22;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --surface: #211f19;
    --surface-2: #2b2921;
    --text: #f1eee6;
    --muted: #a8a294;
    --border: #3a372e;
    --accent: #ff7a3d;
    --accent-text: #1a0d05;
    --danger: #ff6b6b;
    --warn-bg: #3d3210;
    --warn-text: #ffe7a0;
    --ok-bg: #173a1d;
    --ok-text: #c3f0c9;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 16px; border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); margin-right: auto; }
.topbar a, .topbar button.link { font-size: .95rem; }
.topbar form { margin: 0; }

main { max-width: 960px; margin: 0 auto; padding: 1.25rem 16px 4rem; }
.narrow { max-width: 420px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}

label { display: block; font-weight: 600; margin: .75rem 0 .3rem; font-size: .95rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search] {
  width: 100%; padding: .7rem .8rem; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input.invalid { border-color: var(--danger); outline: 2px solid var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1.1rem; font-size: 1rem; font-weight: 600;
  border-radius: 10px; border: 1px solid var(--border); cursor: pointer;
  background: var(--surface-2); color: var(--text); text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.flash { padding: .7rem 1rem; border-radius: 10px; background: var(--ok-bg); color: var(--ok-text); margin-bottom: 1rem; }
.error { padding: .7rem 1rem; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); margin: .75rem 0; }

/* Wheel list */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin-top: 1rem; }
.wheel-card { display: flex; flex-direction: column; gap: .5rem; }
.wheel-card h3 { margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
.wheel-card .row { margin-top: auto; }

/* Spin screen */
.tabs { display: flex; gap: .25rem; margin: .5rem 0 1rem; flex-wrap: wrap; }
.tabs a { padding: .45rem .9rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a.on { background: var(--surface-2); color: var(--text); }

.stage { display: flex; flex-direction: column; align-items: center; gap: 1.25rem; }
.wheel-wrap { position: relative; width: min(92vw, 560px, 58vh); aspect-ratio: 1; }
.wheel-wrap canvas { width: 100%; height: 100%; display: block; }
.pointer {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; border-left: 18px solid transparent; border-right: 18px solid transparent;
  border-top: 34px solid var(--text); filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); z-index: 2;
}
.stepper { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; justify-content: center; }
.stepper .btn { width: 44px; padding: 0; font-size: 1.3rem; }
.stepper output { min-width: 2ch; text-align: center; font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
#series-so-far { margin-top: .75rem; }
.medal { font-size: 1.4rem; width: 2rem; display: inline-block; text-align: center; }
.tipper-row { display: grid; grid-template-columns: 2rem 1fr 1fr; align-items: center; gap: .5rem; margin: .5rem 0; }
@media (max-width: 560px) { .tipper-row { grid-template-columns: 2rem 1fr; } .tipper-row .t-prize { grid-column: 2; } }
.add-tippers { margin-bottom: 1rem; }
.add-tippers summary { cursor: pointer; min-height: 32px; list-style-position: inside; }
.add-tippers form { margin-top: .5rem; max-width: 640px; }
input[type=date] { padding: .6rem .8rem; font-size: 1rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); }
.check-inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0; font-weight: 600; min-height: 44px; }
.check-inline input, .delivered { width: 22px; height: 22px; accent-color: var(--accent); }
table.winners .c-check { width: 1%; text-align: center; white-space: nowrap; }
table.winners tr.day th { background: var(--surface-2); color: var(--text); font-size: .95rem; text-transform: none; letter-spacing: 0; padding: .6rem .5rem; }
table.winners tr.is-delivered td.name, table.winners tr.is-delivered td:nth-child(3) { color: var(--muted); text-decoration: line-through; }
.spin-btn { min-width: 220px; min-height: 60px; font-size: 1.35rem; letter-spacing: .06em; border-radius: 999px; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem;
  width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.prize-won { font-size: 1.6rem; font-weight: 800; margin: .25rem 0 .5rem; overflow-wrap: anywhere; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: .35rem; }

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

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
td.name { font-weight: 600; overflow-wrap: anywhere; }

/* Setup */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text); padding: .55rem 1rem; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.prize-row { display: grid; grid-template-columns: 44px 1fr auto auto; gap: .5rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.prize-row.custom { grid-template-columns: 44px 1fr 90px 64px auto; }
.prize-row input[type=color] { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 10px; padding: 2px; background: var(--surface); }
.pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.setup-grid { display: grid; grid-template-columns: 1fr 280px; gap: 1.5rem; align-items: start; }
.preview { width: 100%; aspect-ratio: 1; }
@media (max-width: 720px) {
  .setup-grid { grid-template-columns: 1fr; }
  .preview-col { order: -1; max-width: 240px; margin: 0 auto; }
  .prize-row.custom { grid-template-columns: 44px 1fr 72px; }
  .prize-row.custom .pct { grid-column: 2; text-align: left; }
}
.link-box { display: flex; gap: .5rem; margin-top: .5rem; }
.link-box input { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
.badge { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.badge.off { background: var(--warn-bg); color: var(--warn-text); }
