:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --text: #1c1d2b;
  --muted: #6b6f85;
  --border: #e2e4ee;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --gold: #f59e0b;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(20, 20, 50, .05), 0 8px 24px rgba(20, 20, 50, .06);
  --radius: 14px;
  --team-1: #eef0ff; --team-2: #fff5e6; --team-3: #e9f9f1; --team-4: #fdeef3;
  --team-5: #eaf6fd; --team-6: #f4eefe;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131a;
    --surface: #1b1c26;
    --surface-2: #242633;
    --text: #ebecf3;
    --muted: #9a9db3;
    --border: #2e3040;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #262a4a;
    --gold: #fbbf24;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --team-1: #23264a; --team-2: #3a2d18; --team-3: #183327; --team-4: #3a1d29;
    --team-5: #172d3a; --team-6: #2c2140;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

/* 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; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 19px; }
.brand b { color: var(--accent); }
.topnav { display: flex; gap: 22px; }
.topnav a { color: var(--muted); text-decoration: none; font-size: 15px; }
.topnav a:hover { color: var(--text); }

/* Hero */
.hero { text-align: center; padding-top: 48px; padding-bottom: 28px; }
.hero h1 { font-size: clamp(28px, 4.5vw, 42px); letter-spacing: -.02em; }
.lead { color: var(--muted); max-width: 620px; margin: 14px auto 0; font-size: 17px; }

/* App layout */
.app { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.panel-head h2 { font-size: 18px; }
.count { color: var(--muted); font-size: 14px; }
textarea {
  width: 100%; min-height: 320px; resize: vertical;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  background: var(--surface-2); color: var(--text);
  font: 15px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace;
}
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.list-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

/* Buttons */
.btn {
  border: 1px solid transparent; border-radius: 10px; cursor: pointer;
  font: inherit; font-weight: 600; padding: 10px 18px; transition: background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 6px 12px; font-size: 13px; font-weight: 500; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; margin-top: 6px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; }

@media (prefers-color-scheme: dark) { .btn.primary { color: #12131a; } }

/* Tabs */
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 11px; overflow-x: auto; margin-bottom: 18px; }
.tab {
  flex: 1 0 auto; border: 0; background: transparent; color: var(--muted);
  padding: 9px 14px; border-radius: 8px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tab-body { display: none; }
.tab-body.active { display: block; }
.desc { color: var(--muted); margin: 0 0 12px; }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; margin-bottom: 12px; }
.controls label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.controls label.check { color: var(--text); cursor: pointer; }
input[type=number], select {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px;
}
input[type=number] { width: 80px; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }

/* Pick stage */
.stage {
  margin-top: 18px; min-height: 160px; border-radius: 12px; background: var(--accent-soft);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; padding: 20px; text-align: center;
}
.stage .rolling { font-size: clamp(24px, 4vw, 34px); font-weight: 700; color: var(--muted); }
.winner {
  background: var(--surface); border: 2px solid var(--gold); border-radius: 12px;
  padding: 12px 20px; font-size: clamp(20px, 3.5vw, 30px); font-weight: 700;
  animation: pop .35s ease-out both; overflow-wrap: anywhere;
}
.winner small { display: block; font-size: 12px; color: var(--gold); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.history { margin-top: 18px; }
.history-head { display: flex; justify-content: space-between; align-items: baseline; }
.history h3 { font-size: 15px; }
.history ol { margin: 8px 0 0; padding-left: 22px; color: var(--muted); font-size: 14px; max-height: 180px; overflow: auto; }

/* Teams */
.grid-out { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-top: 18px; }
.team { border-radius: 12px; padding: 14px 16px; animation: pop .3s ease-out both; }
.team h3 { font-size: 15px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.team h3 span { color: var(--muted); font-weight: 500; font-size: 13px; }
.team ul { margin: 0; padding-left: 18px; }
.team li { overflow-wrap: anywhere; }
.copy { margin-top: 14px; }

/* Order */
.order-out { margin: 18px 0 0; padding: 0; list-style: none; counter-reset: ord; columns: 2 220px; column-gap: 12px; }
.order-out li {
  counter-increment: ord; break-inside: avoid; display: flex; gap: 10px; align-items: center;
  padding: 8px 12px; margin-bottom: 8px; background: var(--surface-2); border-radius: 9px; animation: pop .25s ease-out both;
  overflow-wrap: anywhere;
}
.order-out li::before {
  content: counter(ord); min-width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700; display: grid; place-items: center; flex-shrink: 0;
}
@media (prefers-color-scheme: dark) { .order-out li::before { color: #12131a; } }

/* Santa */
.santa-out { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 8px; }
.santa-out li { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface-2); border-radius: 9px; flex-wrap: wrap; }
.santa-out .arrow { color: var(--muted); }
.santa-out .to { font-weight: 700; }
.santa-out .to.hidden { filter: blur(6px); cursor: pointer; user-select: none; }

/* Quick */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.quick-card { background: var(--surface-2); border-radius: 12px; padding: 18px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.quick-card h3 { font-size: 15px; }
.coin {
  width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fde68a, #f59e0b); color: #78350f; font-weight: 800; font-size: 18px;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.15);
}
.coin.flip { animation: flip .7s ease-in-out; }
@keyframes flip { 0% { transform: rotateY(0); } 100% { transform: rotateY(1440deg); } }
.dice-row { font-size: 44px; min-height: 96px; display: flex; align-items: center; gap: 6px; }
.dice-row.roll { animation: shake .45s; }
@keyframes shake { 25% { transform: rotate(-12deg); } 50% { transform: rotate(10deg); } 75% { transform: rotate(-6deg); } }
.number { font-size: 48px; font-weight: 800; min-height: 96px; display: grid; place-items: center; color: var(--accent); }
.inline { display: flex; align-items: center; gap: 8px; justify-content: center; }
.inline input[type=number] { width: 76px; }

/* Info sections */
.info { margin-top: 64px; }
.info > h2 { font-size: 26px; margin-bottom: 18px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card h3 { font-size: 17px; margin: 10px 0 6px; }
.card p { margin: 0; color: var(--muted); }
.num-badge { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; margin-bottom: 10px; }
summary { cursor: pointer; font-weight: 600; }
details p { color: var(--muted); margin: 10px 0 0; }

.footer { margin-top: 64px; padding: 28px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 14px; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Responsive */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  textarea { min-height: 200px; }
  .cards { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .topnav { gap: 14px; }
  .topnav a:first-child { display: none; }
  .hero { padding-top: 32px; }
  .panel { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
