/* Name Wheel — web app styles. Light/dark via prefers-color-scheme. */

:root {
  color-scheme: light; /* native controls (number spinners, selects) */
  --nw-bg: #FFFFFF;
  --nw-bg2: #F4F5F7;
  --nw-text: #1d1d1f;
  --nw-text2: #6e6e73;
  --nw-border: #E3E4E8;
  --nw-accent: #FF6B35;
  --nw-accent2: #F7931E;
  --nw-radius: 16px;
  --nw-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

/* Theme is controlled by html[data-theme], set before first paint by an
   inline script (saved preference, falling back to the OS setting) and
   afterwards by the settings panel. */
html[data-theme="dark"] {
  color-scheme: dark; /* dark spinners, selects, and scrollbars */
  --nw-bg: #131316;
  --nw-bg2: #1d1d21;
  --nw-text: #f5f5f7;
  --nw-text2: #a1a1a6;
  --nw-border: #36363a;
  --nw-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

html[data-contrast="high"] {
  --nw-text2: #1d1d1f;
  --nw-border: #1d1d1f;
}

html[data-theme="dark"][data-contrast="high"] {
  --nw-text2: #ffffff;
  --nw-border: #ffffff;
}

html[data-text-size="small"] { font-size: 14px; }
html[data-text-size="large"] { font-size: 18px; }
html[data-text-size="extra-large"] { font-size: 20px; }

html[data-reduce-motion="true"] * {
  transition: none !important;
  animation: none !important;
}

/* ── Layout ──────────────────────────────────────────────────────── */

/* Wheel(s) on top at full width; panels in a row below. */
.nw {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Mode tabs, centered above everything */
.nw-tabs {
  display: flex;
  justify-content: center;
  gap: 6px;
  background: var(--nw-bg2);
  border: 1px solid var(--nw-border);
  border-radius: 999px;
  padding: 4px;
  width: fit-content;
  margin: 0 auto 4px;
}

.nw-tab {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--nw-text2);
  background: none;
  border: none;
  border-radius: 999px;
  padding: 8px 22px;
  cursor: pointer;
}

.nw-tab:hover { color: var(--nw-text); }

.nw-tab.active {
  background: var(--nw-accent);
  color: #fff;
}

/* Both wheels side by side in Match mode */
.nw-stage-row {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 28px;
  width: 100%;
  flex-wrap: wrap;
}

/* Panel row: settings + names (+ outcomes in Match) */
.nw-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* Pairs history + Group Maker pane share the panel look */
.nw-pairs,
.nw-groups-pane {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--nw-bg2);
  border: 1px solid var(--nw-border);
  border-radius: var(--nw-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.nw-groups-label {
  color: var(--nw-text);
  font-size: 0.95rem;
  font-weight: 600;
}

.nw-seg { display: flex; gap: 6px; }

.nw-seg .nw-size-btn { width: auto; padding: 6px 16px; }

.nw-dist { color: var(--nw-text2); font-size: 0.95rem; }

.nw-make { align-self: flex-start; }

.nw-pairs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
}

.nw-compact {
  align-items: center;
  gap: 12px;
}

.nw-stage-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

/* Winner banner above the wheel. Space is always reserved; only
   visibility toggles, so the wheel never shifts vertically. */
.nw-banner {
  text-align: center;
  background: var(--nw-bg2);
  border: 1px solid var(--nw-border);
  border-radius: 16px;
  padding: 10px 36px;
  visibility: hidden;
}

.nw-banner.nw-banner-show { visibility: visible; }

.nw-banner-name { min-height: 1.3em; }

.nw-banner-eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--nw-accent);
}

.nw-banner-name {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--nw-text);
  overflow-wrap: anywhere;
}

.nw-stage {
  position: relative;
  width: 100%;
  max-width: 480px; /* overridden by the 1x/2x/3x size buttons */
  aspect-ratio: 1;
}

/* On narrow screens (where the panels stack), Arc Mode's widescreen
   band falls back to the square so it doesn't become a thin sliver.
   !important beats the inline sizes set by applyStageSize(). */
@media (max-width: 640px) {
  .nw-stage {
    max-width: 480px !important;
    height: auto !important;
    aspect-ratio: 1 !important;
  }
}

.nw-canvas {
  width: 100%;
  height: 100%;
  cursor: pointer;
  display: block;
}

.nw-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.nw-pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 24px solid var(--nw-text);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
  z-index: 2;
}

.nw-spin {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--nw-accent), var(--nw-accent2));
  border: none;
  border-radius: 999px;
  padding: 14px 56px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 107, 53, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.nw-spin:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(255, 107, 53, 0.5);
}

.nw-spin:disabled { opacity: 0.7; cursor: default; }

.nw-live {
  min-height: 1.4em;
  font-size: 0.9rem;
  color: var(--nw-text2);
  text-align: center;
}

/* ── Controls ────────────────────────────────────────────────────── */

/* Settings panel: one option per row, stacked */
.nw-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  padding: 20px;
  background: var(--nw-bg2);
  border: 1px solid var(--nw-border);
  border-radius: var(--nw-radius);
}

.nw-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--nw-text);
  font-size: 0.95rem;
}

.nw-toggle input { position: absolute; opacity: 0; }

.nw-toggle-slider {
  width: 42px;
  height: 26px;
  border-radius: 999px;
  background: var(--nw-border);
  position: relative;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.nw-toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
}

.nw-toggle input:checked + .nw-toggle-slider { background: #34C759; }
.nw-toggle input:checked + .nw-toggle-slider::after { transform: translateX(16px); }
.nw-toggle input:focus-visible + .nw-toggle-slider { outline: 2px solid var(--nw-accent); }

.nw-theme-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--nw-text);
  font-size: 0.95rem;
}

.nw-select {
  font: inherit;
  color: var(--nw-text);
  background: var(--nw-bg);
  border: 1px solid var(--nw-border);
  border-radius: 8px;
  padding: 6px 10px;
}

.nw-size-btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  width: 40px;
  padding: 6px 0;
  border: 1px solid var(--nw-border);
  border-radius: 8px;
  background: var(--nw-bg);
  color: var(--nw-text);
  cursor: pointer;
}

.nw-size-btn.active {
  background: var(--nw-accent);
  border-color: var(--nw-accent);
  color: #fff;
}

/* ── Names panel ─────────────────────────────────────────────────── */

.nw-panel {
  background: var(--nw-bg2);
  border: 1px solid var(--nw-border);
  border-radius: var(--nw-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 700px;
}

.nw-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.nw-panel-head h2 { font-size: 1.15rem; color: var(--nw-text); margin: 0; }

.nw-count { font-size: 0.85rem; color: var(--nw-text2); }

.nw-add-row { display: flex; gap: 8px; }

.nw-input {
  flex: 1;
  font: inherit;
  color: var(--nw-text);
  background: var(--nw-bg);
  border: 1px solid var(--nw-border);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}

.nw-input:focus { outline: 2px solid var(--nw-accent); border-color: transparent; }

.nw-input-small { flex: 0 0 80px; margin-left: 8px; }

.nw-btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--nw-text);
  background: var(--nw-bg);
  border: 1px solid var(--nw-border);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.nw-btn:hover { background: var(--nw-border); }

.nw-btn-primary {
  color: #fff;
  background: var(--nw-accent);
  border-color: var(--nw-accent);
}

.nw-btn-primary:hover { background: var(--nw-accent2); border-color: var(--nw-accent2); }

.nw-btn-danger { color: #FF3B30; }

.nw-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nw-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--nw-bg);
  color: var(--nw-text);
  font-size: 0.95rem;
}

.nw-item-removed { opacity: 0.45; }
.nw-item-removed .nw-item-name { text-decoration: line-through; }

.nw-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nw-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nw-item-del {
  border: none;
  background: none;
  color: var(--nw-text2);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.nw-item-del:hover { color: #FF3B30; background: var(--nw-bg2); }

.nw-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ── Overlays / modals ───────────────────────────────────────────── */

.nw-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

/* !important so it beats any element's own display rule regardless of
   where that rule sits in this file (CSS source order decides ties). */
.nw-hidden { display: none !important; }

.nw-winner-card,
.nw-modal-card {
  background: var(--nw-bg);
  color: var(--nw-text);
  border-radius: 20px;
  box-shadow: var(--nw-shadow);
  padding: 28px;
  width: min(440px, 100%);
  text-align: center;
}

.nw-modal-card { text-align: left; width: min(560px, 100%); }

.nw-winner-eyebrow {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--nw-accent);
  margin-bottom: 6px;
}

.nw-winner-name {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 20px;
  overflow-wrap: anywhere;
}

.nw-winner-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.nw-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.nw-modal-head h3 { margin: 0; font-size: 1.2rem; }

.nw-modal-close {
  border: none;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--nw-text2);
  cursor: pointer;
}

.nw-modal-body { display: flex; flex-direction: column; gap: 12px; }

.nw-hint { margin: 0; color: var(--nw-text2); font-size: 0.9rem; }

.nw-textarea {
  font: inherit;
  color: var(--nw-text);
  background: var(--nw-bg2);
  border: 1px solid var(--nw-border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 140px;
  resize: vertical;
}

.nw-file { font-size: 0.9rem; color: var(--nw-text2); }

.nw-groups-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.nw-groups-row label {
  display: flex;
  align-items: center;
  font-size: 0.95rem;
}

.nw-groups-result {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  max-height: 320px;
  overflow-y: auto;
}

.nw-group h4 {
  margin: 0 0 6px;
  padding-bottom: 4px;
  border-bottom: 3px solid;
  font-size: 0.95rem;
}

.nw-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
  color: var(--nw-text);
}

.nw-group li { padding: 2px 0; }

.nw-groups-export { display: flex; gap: 8px; }

.nw-more-link {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--nw-accent);
  text-decoration: none;
}

.nw-more-link:hover { text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .nw-spin, .nw-toggle-slider, .nw-toggle-slider::after, .nw-btn {
    transition: none;
  }
}
