:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --border: #ddd8cc;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --danger: #b42318;
  --win-bg: #fff4d6;
  --focus: #2563eb;
  --slice-1: #e8a33d;
  --slice-2: #357893;
  --slice-3: #c2553a;
  --slice-4: #5a9e6f;
  --slice-5: #8064b4;
  --slice-6: #d9775c;
  --slice-7: #3f6e9e;
  --slice-8: #b98a2e;
  --slice-text: #ffffff;
  --slice-text-dark: #1f2328;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e8e6e1;
    --muted: #a0a6ae;
    --border: #33373d;
    --accent: #f08a4b;
    --accent-text: #15171a;
    --danger: #f97066;
    --win-bg: #3a2f14;
    --focus: #60a5fa;
    --slice-1: #c9892b;
    --slice-2: #2f6e88;
    --slice-3: #b14a31;
    --slice-4: #43805a;
    --slice-5: #7559a8;
    --slice-6: #b65c44;
    --slice-7: #355d87;
    --slice-8: #8f6a1f;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1e2125;
  --text: #e8e6e1;
  --muted: #a0a6ae;
  --border: #33373d;
  --accent: #f08a4b;
  --accent-text: #15171a;
  --danger: #f97066;
  --win-bg: #3a2f14;
  --focus: #60a5fa;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; }

a { color: var(--accent); }

button, input {
  font: inherit;
  color: inherit;
}

input {
  width: 100%;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

button {
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.big { font-size: 1.25rem; padding: 0.75rem 2.5rem; }
button.icon { padding: 0.25rem 0.55rem; background: transparent; }
button.link { border: none; background: none; padding: 0.2rem 0.4rem; color: var(--accent); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.lead { font-size: 1.1rem; color: var(--muted); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.stack { display: flex; flex-direction: column; gap: 0.6rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.landing { max-width: 32rem; margin: 10vh auto; padding: 0 16px; }
.landing .card { margin-top: 1.5rem; }

.room-header {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.25rem 16px 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.title-row { display: flex; align-items: center; gap: 0.25rem; min-width: 0; }
.title-row h1 { margin: 0; overflow-wrap: anywhere; }
.header-meta { display: flex; align-items: center; gap: 0.5rem; }

.layout {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0.5rem 16px 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
}
@media (max-width: 640px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
}

.stage { display: flex; flex-direction: column; gap: 1rem; }

.wheel-area {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  aspect-ratio: 1;
}
.wheel-area canvas { width: 100%; height: 100%; display: block; }
.pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  translate: -50% 0;
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 26px solid var(--text);
  z-index: 1;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.3));
}
.pointer-label {
  position: absolute;
  bottom: -2.25rem;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 600;
}

.result { text-align: center; }
.result p { margin: 0; }
.result-name {
  font-size: clamp(2rem, 7vw, 3.25rem);
  font-weight: 800;
  line-height: 1.1;
  margin: 0.25rem 0 0.75rem !important;
  overflow-wrap: anywhere;
}
.result .row { justify-content: center; }

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.tabs button {
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: none;
  padding: 0.6rem 0.9rem;
  color: var(--muted);
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.list, .tick-list, .history { list-style: none; margin: 0; padding: 0; }
.list li, .tick-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.tick-list label { display: flex; gap: 0.6rem; align-items: center; cursor: pointer; width: 100%; }
.tick-list input { width: auto; }
#setup-list { max-height: 22rem; overflow-y: auto; }

#add-form { margin-bottom: 0.75rem; flex-wrap: nowrap; }

.history li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.history li.win { background: var(--win-bg); font-weight: 600; border-radius: 6px; }
.history time { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
#history-more { margin-top: 0.75rem; }

.segmented { display: inline-flex; margin-bottom: 0.75rem; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 8px 0 0 8px; }
.segmented button:last-child { border-radius: 0 8px 8px 0; border-left: none; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.danger-zone { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px dashed var(--border); }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.25rem;
  width: min(26rem, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin-bottom: 0; }

.notice {
  position: fixed;
  top: 1rem;
  left: 50%;
  translate: -50% 0;
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 0.65rem 1rem;
  border-radius: 8px;
  z-index: 20;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
}

.confetti {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 10;
}

[hidden] { display: none !important; }

#new-wheel-button { margin-top: 1rem; }

.privacy { margin-top: 2rem; }
.privacy h2 { margin-bottom: 0.25rem; }
.privacy p { margin: 0 0 0.5rem; }
