:root {
  color-scheme: dark;
  --page-bg: #202020;
  --page-text: #f5f5f5;
  --surface: rgba(44, 44, 44, .94);
  --surface-2: rgba(50, 50, 50, .94);
  --surface-3: rgba(58, 58, 58, .94);
  --border: rgba(255, 255, 255, .095);
  --border-strong: rgba(255, 255, 255, .18);
  --text: #f5f5f5;
  --muted: #b7b7b7;
  --subtle: #8f8f8f;
  --accent: #60a5fa;
  --accent-hover: #7cb5fb;
  --accent-soft: rgba(96, 165, 250, .15);
  --danger: #ff8a8a;
  --danger-soft: rgba(255, 90, 90, .12);
  --success: #72d89b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0,0,0,.26);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page-bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--page-bg);
  color: var(--page-text);
  transition: background-color .18s ease, color .18s ease;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

body.private-mode {
  --page-bg: #2b1141;
  --surface: rgba(29, 14, 44, .94);
  --surface-2: rgba(46, 24, 67, .95);
  --surface-3: rgba(64, 32, 91, .95);
  --border: rgba(247, 226, 255, .12);
  --border-strong: rgba(247, 226, 255, .22);
  --text: #fff7ff;
  --muted: #dbc9e3;
  --subtle: #b99ac7;
  --accent: #d74cf0;
  --accent-hover: #e779f7;
  --accent-soft: rgba(215, 76, 240, .16);
}

.app-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 18px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 auto; border-radius: 11px; background: var(--surface-3); border: 1px solid var(--border); font-weight: 800; letter-spacing: -.03em; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .12em; }
.page-title { display: block; font-size: clamp(1.22rem, 2.6vw, 1.8rem); line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: min(54vw, 650px); }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.button, .icon-button, .spin-button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  transition: background-color .14s ease, border-color .14s ease, transform .14s ease, opacity .14s ease;
}
.button { color: var(--text); min-height: 42px; padding: 9px 14px; border-radius: 10px; font-weight: 650; }
.button:hover, .icon-button:hover { background: var(--surface-3); border-color: var(--border-strong); }
.button:active, .icon-button:active { transform: translateY(1px); }
.button.primary { background: var(--accent); color: #0b0b0b; border-color: transparent; }
.button.primary:hover { background: var(--accent-hover); }
.button.ghost { background: rgba(255,255,255,.035); }
.button.danger { background: var(--danger-soft); color: #ffd6d6; border-color: rgba(255,138,138,.3); }
.button:disabled, .icon-button:disabled { cursor: not-allowed; opacity: .45; }
.full-width { width: 100%; }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; padding: 0; font-size: 1.5rem; }
.icon-button svg { width: 22px; height: 22px; fill: currentColor; }
.private-toggle { position: relative; }
body.private-mode .private-toggle { background: #050505; color: #fff; border-color: rgba(255,255,255,.28); box-shadow: 0 0 0 3px rgba(215,76,240,.16); }

.private-banner { display: flex; gap: 11px; align-items: center; padding: 11px 14px; margin-bottom: 16px; border: 1px solid rgba(215,76,240,.3); background: rgba(5,5,5,.25); border-radius: 12px; }
.private-banner svg { width: 25px; height: 25px; fill: #fff; flex: 0 0 auto; }
.private-banner div { display: grid; gap: 2px; }
.private-banner span { color: var(--muted); font-size: .88rem; }

.main-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, .72fr); gap: 18px; align-items: start; }
.wheel-section, .side-panel { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.wheel-section { padding: clamp(14px, 2.5vw, 24px); min-width: 0; }
.side-panel { padding: 18px; min-width: 0; }
.wheel-wrap { position: relative; width: min(100%, 620px); aspect-ratio: 1; margin: 2px auto 16px; display: grid; place-items: center; }
#wheelCanvas { display: block; width: 100%; height: 100%; }
.pointer { position: absolute; z-index: 3; top: -3px; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 18px solid transparent; border-right: 18px solid transparent; border-top: 35px solid var(--text); filter: drop-shadow(0 3px 2px rgba(0,0,0,.35)); }
.spin-button { position: absolute; z-index: 4; width: 92px; height: 92px; border-radius: 50%; border: 7px solid rgba(255,255,255,.82); background: #111; color: #fff; font-weight: 850; letter-spacing: .04em; box-shadow: 0 10px 26px rgba(0,0,0,.3); }
.spin-button:hover { background: #191919; transform: scale(1.025); }
.spin-button:disabled { opacity: .6; cursor: wait; transform: none; }
body.private-mode .spin-button { background: #0a0710; }

.result-panel { min-height: 104px; display: grid; place-items: center; align-content: center; text-align: center; padding: 14px; background: rgba(255,255,255,.035); border: 1px solid var(--border); border-radius: 13px; }
.result-label { margin: 0 0 3px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: .7rem; font-weight: 700; }
.result-text { margin: 0; max-width: 100%; font-size: clamp(1.35rem, 3vw, 2.2rem); font-weight: 750; line-height: 1.15; overflow-wrap: anywhere; }
.result-meta { margin: 5px 0 0; color: var(--muted); font-size: .82rem; }
.quick-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 12px; }
.section-heading h2 { margin: 0; font-size: 1.15rem; }
.count-pill { display: inline-grid; place-items: center; min-width: 32px; height: 28px; padding: 0 9px; border-radius: 99px; background: var(--surface-3); color: var(--muted); font-size: .82rem; font-weight: 700; }
.choice-list { display: grid; gap: 7px; max-height: 610px; overflow: auto; padding-right: 3px; scrollbar-color: var(--surface-3) transparent; }
.choice-item { display: grid; grid-template-columns: 13px minmax(0,1fr) auto; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 10px; background: rgba(255,255,255,.028); border: 1px solid transparent; }
.choice-dot { width: 10px; height: 10px; border-radius: 50%; }
.choice-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choice-odds { color: var(--muted); font-size: .78rem; }
.choice-item.is-ineligible { opacity: .45; }

.footer { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 20px 4px 4px; color: var(--muted); font-size: .8rem; }
.private-footer { color: #f6b8ff; font-weight: 650; }

.dialog { width: min(920px, calc(100% - 24px)); max-width: none; padding: 0; border: 0; background: transparent; color: var(--text); }
.dialog::backdrop { background: rgba(0,0,0,.66); backdrop-filter: blur(4px); }
.dialog-card { max-height: min(84vh, 820px); overflow: auto; padding: 20px; border-radius: 18px; border: 1px solid var(--border-strong); background: #292929; color: #f5f5f5; box-shadow: 0 28px 80px rgba(0,0,0,.55); }
body.private-mode .dialog-card { background: #21102f; }
.dialog-card.compact { width: min(620px, 100%); margin: auto; }
.confirm-card { width: min(480px, 100%); margin: auto; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dialog-head h2 { margin: 0; font-size: 1.35rem; }
.dialog-note, .section-note, .confirm-message { margin: 5px 0 0; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.sticky-head { position: sticky; top: -20px; z-index: 5; margin: -20px -20px 18px; padding: 20px; background: #292929; border-bottom: 1px solid var(--border); }
body.private-mode .sticky-head { background: #21102f; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.settings-section { padding: 15px; border: 1px solid var(--border); border-radius: 13px; background: rgba(255,255,255,.025); min-width: 0; }
.settings-section h3 { margin: 0 0 13px; font-size: 1rem; }
.field { display: grid; gap: 7px; margin-top: 12px; color: var(--text); font-size: .9rem; }
.field:first-of-type { margin-top: 0; }
.field > span { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; }
.field small, .switch-row small, .privacy-info span { color: var(--muted); font-size: .78rem; line-height: 1.4; font-weight: 400; }
input[type="text"], input[type="number"], textarea, select { width: 100%; min-height: 42px; border: 1px solid var(--border-strong); border-radius: 9px; padding: 9px 10px; background: #1c1c1c; color: #fff; }
textarea { resize: vertical; min-height: 190px; line-height: 1.45; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="color"] { width: 100%; min-height: 44px; padding: 4px; border: 1px solid var(--border-strong); border-radius: 9px; background: #1c1c1c; }
.switch-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 14px; margin-top: 12px; }
.switch-row span { display: grid; gap: 2px; }
.switch-row input { appearance: none; width: 44px; height: 24px; padding: 2px; border-radius: 99px; background: #555; cursor: pointer; transition: background .14s ease; }
.switch-row input::before { content: ""; display: block; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .14s ease; }
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::before { transform: translateX(20px); }
.switch-row input:disabled { opacity: .45; cursor: not-allowed; }
.background-controls { display: grid; grid-template-columns: 110px minmax(0,1fr); gap: 10px; align-items: end; }
.background-controls .grow { min-width: 0; }
.contrast-status { min-height: 20px; margin: 9px 0 0; color: var(--muted); font-size: .8rem; }
.contrast-status.good { color: var(--success); }
.contrast-status.warn { color: #ffd67a; }
.privacy-info { display: grid; gap: 3px; margin: 10px 0 12px; padding: 11px; border-radius: 10px; background: rgba(215,76,240,.12); border: 1px solid rgba(215,76,240,.22); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.history-list { display: grid; gap: 7px; min-height: 80px; }
.history-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 11px; border-radius: 9px; background: rgba(255,255,255,.035); }
.history-item time { color: var(--muted); font-size: .78rem; }
.empty-state { color: var(--muted); text-align: center; padding: 24px 10px; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 20px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; max-width: min(520px, calc(100% - 32px)); padding: 10px 14px; border-radius: 99px; background: #101010; color: #fff; border: 1px solid rgba(255,255,255,.15); box-shadow: 0 14px 40px rgba(0,0,0,.4); transition: opacity .16s ease, transform .16s ease; text-align: center; font-size: .86rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confetti-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

@media (max-width: 860px) {
  .main-grid { grid-template-columns: 1fr; }
  .side-panel { order: 2; }
  .choice-list { max-height: 340px; }
}
@media (max-width: 680px) {
  .app-shell { width: min(100% - 20px, 1180px); padding-top: 14px; }
  .topbar { align-items: flex-start; }
  .brand-mark { display: none; }
  .page-title { max-width: 48vw; }
  .top-actions .button { padding-inline: 10px; }
  .settings-grid { grid-template-columns: 1fr; }
  .wheel-section { padding: 12px; }
  .spin-button { width: 76px; height: 76px; border-width: 6px; }
  .pointer { border-left-width: 14px; border-right-width: 14px; border-top-width: 28px; }
}
@media (max-width: 470px) {
  .topbar { display: grid; grid-template-columns: 1fr auto; }
  .brand { min-width: 0; }
  .page-title { max-width: 62vw; }
  .top-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .top-actions .button { flex: 1 1 auto; }
  .quick-row .button { flex: 1 1 100%; }
  .dialog-card { padding: 15px; border-radius: 15px; }
  .sticky-head { top: -15px; margin: -15px -15px 16px; padding: 15px; }
  .background-controls { grid-template-columns: 90px minmax(0,1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
