:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --page: #f9f9f7;
  --panel: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: #e1e0d9;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #e34948;
  --shadow: 0 10px 30px rgba(11, 11, 11, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface: #1a1a19;
    --page: #0d0d0d;
    --panel: #202020;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: #2c2c2a;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --danger: #e66767;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a19;
  --page: #0d0d0d;
  --panel: #202020;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: #2c2c2a;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --danger: #e66767;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
html { scroll-behavior: smooth; }
/* Guard against any stray horizontal overflow shifting the layout.
   overflow-x: clip (unlike hidden) does not create a scroll container,
   so the sticky navbar keeps working. */
body { overflow-x: clip; }

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
}

.app-header {
  text-align: center;
  max-width: 720px;
  margin-bottom: 20px;
}

.wheel-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  margin: 0 0 6px;
  outline: none;
  border-radius: 8px;
  padding: 2px 8px;
}
.wheel-title:hover,
.wheel-title:focus {
  background: var(--panel);
  box-shadow: 0 0 0 2px var(--border-strong);
}

.app-subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.layout {
  width: 100%;
  max-width: 1100px;
  display: flex;
  gap: 28px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.wheel-panel {
  flex: 1 1 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 300px;
}

.wheel-wrapper {
  position: relative;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wheel-wrapper:fullscreen {
  max-width: none;
  width: 100vw;
  height: 100vh;
  background: var(--page);
}

#wheel-canvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.28));
}

.pointer {
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 34px;
  height: 40px;
  z-index: 3;
  background: linear-gradient(#fff, #e6e6e6);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
  border-radius: 4px;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
}
.pointer::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.spin-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 22%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: none;
  background:
    radial-gradient(circle at 38% 32%, rgba(255,255,255,0.35), rgba(255,255,255,0) 55%),
    linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 62%, #000));
  color: var(--accent-ink);
  font-weight: 900;
  font-size: clamp(0.8rem, 2vw, 1.2rem);
  letter-spacing: 0.06em;
  cursor: pointer;
  z-index: 2;
  box-shadow:
    0 0 0 5px rgba(255, 255, 255, 0.9),
    0 0 0 7px rgba(0, 0, 0, 0.25),
    0 6px 18px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.spin-btn:hover:not(:disabled) {
  transform: translate(-50%, -50%) scale(1.06);
  box-shadow:
    0 0 0 5px rgba(255, 255, 255, 0.95),
    0 0 0 7px rgba(0, 0, 0, 0.25),
    0 8px 24px rgba(0, 0, 0, 0.5);
}
.spin-btn:active:not(:disabled) { transform: translate(-50%, -50%) scale(0.97); }
.spin-btn:disabled { cursor: not-allowed; opacity: 0.65; }

.fullscreen-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
}

.empty-hint {
  margin-top: 14px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: center;
}

.key-hint {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}
.key-hint kbd {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  font-family: inherit;
  font-size: 0.75rem;
}

.side-panel {
  flex: 0 1 340px;
  min-width: 280px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

.panel-actions {
  display: flex;
  gap: 8px;
}
.panel-actions .secondary-btn {
  flex: 1;
  white-space: nowrap;
}

.panel-tabs {
  display: flex;
  gap: 4px;
  background: var(--page);
  border-radius: 10px;
  padding: 4px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.tab-btn.active {
  background: var(--panel);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.tab-content { display: flex; flex-direction: column; gap: 10px; }
.tab-content[hidden] { display: none; }

.entries-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.entries-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
}
.entries-actions { display: flex; gap: 6px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text-secondary);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 0.85rem;
}
.icon-btn:hover { background: var(--page); color: var(--text-primary); }
.icon-btn svg { width: 17px; height: 17px; display: block; }
.icon-btn-text { font-weight: 700; font-size: 0.72rem; letter-spacing: 0.02em; }

/* Icon primitives (SVG line icons injected by icons.js) */
[data-icon] svg { display: block; }
.brand-icon { display: inline-flex; font-size: 1.4rem; }
.btn-icon { display: inline-flex; font-size: 1.05em; }
.chip-icon { display: inline-flex; font-size: 1.05em; flex-shrink: 0; }
.icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
  font-size: 1.35rem;
  margin-bottom: 14px;
  flex-shrink: 0;
}
.icon-badge-sm { width: 40px; height: 40px; font-size: 1.2rem; margin-bottom: 0; }

.use-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
}
.use-chip .chip-icon { color: var(--accent); }

.entries-input {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  background: var(--page);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
}
.entries-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.92rem;
  padding: 6px 2px;
  cursor: pointer;
}
.setting-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.setting-row select {
  background: var(--page);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.85rem;
}

.template-select {
  width: 100%;
  background: var(--page);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 10px;
  font-family: inherit;
  font-size: 0.9rem;
}

.tip-line {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.tip-line code {
  background: var(--page);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 0 5px;
  font-size: 0.78rem;
}

.group-label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.theme-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.theme-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--border-strong);
  background: var(--page);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
}
.theme-btn.active { border-color: var(--accent); }
.theme-dots { display: flex; gap: 2px; }
.theme-dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--page);
  font-size: 0.9rem;
}
.h-name { font-weight: 600; word-break: break-word; }
.h-time { color: var(--text-muted); font-size: 0.78rem; flex-shrink: 0; }

.wheels-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  border: none;
  border-radius: 18px;
  padding: 24px;
  background: var(--panel);
  color: var(--text-primary);
  box-shadow: var(--shadow);
  max-width: 92vw;
  width: 440px;
}
.wheels-dialog::backdrop { background: rgba(0,0,0,0.5); }
.dialog-title {
  margin: 0 0 14px;
  font-size: 1.2rem;
}
.save-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.save-row input {
  flex: 1;
  min-width: 0;
  background: var(--page);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 0.9rem;
}
.wheels-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wheels-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--page);
}
.w-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-count { color: var(--text-muted); font-size: 0.78rem; flex-shrink: 0; }
.secondary-btn.small { padding: 5px 10px; font-size: 0.8rem; flex-shrink: 0; }
.secondary-btn.danger { color: var(--danger); }

.secondary-btn, .primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid var(--border-strong);
}
.secondary-btn {
  background: var(--page);
  color: var(--text-primary);
}
.secondary-btn:hover { background: var(--border-strong); }
.primary-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.app-footer {
  margin-top: 32px;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

.winner-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  border: none;
  border-radius: 18px;
  padding: 28px 32px 22px;
  background: var(--panel);
  color: var(--text-primary);
  box-shadow: var(--shadow);
  max-width: 90vw;
  width: 380px;
}
.winner-dialog::backdrop { background: rgba(0,0,0,0.5); }
.winner-label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  font-weight: 700;
}
.winner-name {
  margin: 8px 0 20px;
  font-size: clamp(1.5rem, 6vw, 2.2rem);
  font-weight: 800;
  text-align: center;
  word-break: break-word;
}
.winner-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  width: 100%;
  height: 100%;
}

@media (max-width: 760px) {
  .layout { flex-direction: column; align-items: stretch; }
  .side-panel { order: -1; flex-basis: auto; }
  .entries-input { min-height: 160px; }
}
