/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #040714;
  --surface-1: rgba(255,255,255,.03);
  --surface-2: rgba(255,255,255,.06);
  --surface-3: rgba(255,255,255,.10);
  --border-subtle: rgba(255,255,255,.07);
  --border: rgba(255,255,255,.1);
  --border-strong: rgba(255,255,255,.22);
  --text-primary: #f9f9f9;
  --text-secondary: #cacaca;
  --text-muted: rgba(255,255,255,.55);
  --accent: #0063e5;
  --accent-bright: #0080ff;
  --danger: #ef4444;
  --font: 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px; --radius: 10px; --radius-lg: 15px; --radius-xl: 20px;
  --ease-snap: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur: 200ms;
  --settings-w: 380px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100vh;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────── */
.header-bar {
  background: linear-gradient(in oklch 135deg, #B015B0 0%, #3D0080 50%, #040714 100%);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 24px;
  height: 68px;
  position: sticky;
  top: 0;
  z-index: 300;
  display: flex;
  align-items: center;
}
.header-logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.header-logo-img {
  height: 36px; width: auto; flex-shrink: 0;
  filter: brightness(0) invert(1);
  transition: transform 0.3s var(--ease-snap);
  display: block;
}
.header-logo-img:hover { transform: scale(1.14) rotate(-9deg); }
.header-logo h1 { font-size: 1.1em; font-weight: 600; letter-spacing: .5px; }
.header-subtitle { font-size: .8em; color: rgba(255,255,255,.7); font-weight: 500; margin-top: 2px; }
.header-home {
  margin-left: auto;
  display: flex; align-items: center;
  padding: 5px;
  color: rgba(255,255,255,.9); text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background var(--dur);
}
.header-home:hover { background: rgba(255,255,255,.12); }
.header-home svg { width: 30px; height: 30px; display: block; }

/* Settings toggle button in header — centered absolutely */
.btn-settings-header {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  padding: 7px 18px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.9);
  font-size: .85em; font-weight: 500;
  cursor: pointer;
  transition: background var(--dur), border-color var(--dur);
  flex-shrink: 0;
  animation: settingsBorderPulse 3s ease-in-out infinite;
}
.btn-settings-header:hover {
  background: rgba(255,255,255,.18);
  border-color: rgba(255,255,255,.5);
  animation: none;
}
.btn-settings-header svg { width: 14px; height: 14px; }
@keyframes settingsBorderPulse {
  0%, 100% { border-color: rgba(255,255,255,.2); box-shadow: none; }
  50%       { border-color: rgba(0,128,255,.7);  box-shadow: 0 0 10px rgba(0,99,229,.4), inset 0 0 6px rgba(0,99,229,.08); }
}

/* ── Main layout ────────────────────────────────────────────────────── */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Wheel stage ────────────────────────────────────────────────────── */
.wheel-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 3vh, 32px) 24px;
  min-height: 0;
  transition: padding-right var(--dur);
}

.wheel-title {
  font-size: clamp(1rem, 2.5vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: clamp(8px, 1.5vh, 24px);
  text-align: center;
  display: flex;
  align-items: center;
  gap: 8px;
}
.wheel-title-icon { font-size: 1.4rem; }

.wheel-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#wheel-canvas {
  display: block;
  width: min(600px, calc(100vw - 48px), calc(100vh - 210px));
  height: min(600px, calc(100vw - 48px), calc(100vh - 210px));
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(0,99,229,.2), 0 0 40px rgba(0,99,229,.15), 0 16px 60px rgba(0,0,0,.6);
}

/* Pointer: triangle pointing DOWN at the top of the wheel */
.wheel-pointer {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 44px solid #0063e5;
  filter: drop-shadow(0 0 8px rgba(0,99,229,.8)) drop-shadow(0 2px 4px rgba(0,0,0,.7));
  z-index: 10;
  animation: pointerBounce 2s ease-in-out infinite;
}
.wheel-pointer::after {
  content: '';
  position: absolute;
  top: -44px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  background: #4BA3FF;
  border-radius: 50%;
  box-shadow: 0 0 8px #0063e5, 0 0 16px rgba(0,99,229,.5);
}
@keyframes pointerBounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%       { transform: translateX(-50%) translateY(-5px); }
}

/* Spin button */
.btn-spin {
  margin-top: clamp(12px, 2vh, 28px);
  padding: 14px 48px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: background var(--dur), transform var(--dur), box-shadow var(--dur);
  box-shadow: 0 4px 20px rgba(0,99,229,.5);
}
.btn-spin:hover:not(:disabled) {
  background: var(--accent-bright);
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(0,128,255,.6);
}
.btn-spin:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}
.btn-spin.spinning {
  background: #6b21a8;
  box-shadow: 0 4px 20px rgba(107,33,168,.5);
}

/* ── Settings drawer ────────────────────────────────────────────────── */
.settings-drawer {
  width: var(--settings-w);
  flex-shrink: 0;
  background: #06091a;
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--dur), transform var(--dur);
  position: relative;
  z-index: 200;
}
.settings-drawer.closed {
  width: 0;
}
.settings-drawer-inner {
  width: var(--settings-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.settings-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.settings-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}
.btn-close-settings {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  transition: color var(--dur), background var(--dur);
}
.btn-close-settings:hover { color: var(--text-primary); background: var(--surface-2); }

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.settings-body::-webkit-scrollbar { width: 4px; }
.settings-body::-webkit-scrollbar-track { background: transparent; }
.settings-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.settings-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Setting rows ───────────────────────────────────────────────────── */
.setting-group { display: flex; flex-direction: column; gap: 8px; }
.setting-group label {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.setting-row-2 { display: flex; gap: 8px; }
.setting-row-2 .form-input:first-child { width: 62px; flex-shrink: 0; text-align: center; }

.form-input {
  flex: 1;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: .875rem;
  font-family: var(--font);
  padding: 8px 10px;
  transition: border-color var(--dur);
  outline: none;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }
.form-hint {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: -4px;
}

/* Segments list */
.segments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.segment-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}
.seg-emoji-input {
  width: 44px;
  flex-shrink: 0;
  text-align: center;
  font-size: 1.1rem;
  padding: 6px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  outline: none;
}
.seg-text-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  color: var(--text-primary);
  font-size: .875rem;
  font-family: var(--font);
  padding: 4px 4px 6px;
  outline: none;
  transition: border-color var(--dur);
}
.seg-text-input:focus { border-color: var(--accent); }
.seg-color-input {
  width: 28px; height: 28px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  background: none;
  overflow: hidden;
}
.seg-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.seg-color-input::-webkit-color-swatch { border: none; border-radius: 50%; }
.btn-seg-delete {
  width: 24px; height: 24px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--dur), background var(--dur);
}
.btn-seg-delete:hover { color: var(--danger); background: rgba(239,68,68,.1); }
.btn-seg-msg-toggle {
  width: 22px; height: 22px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: .8rem;
  cursor: pointer;
  border-radius: 4px;
  transition: color var(--dur);
  title: 'Custom message';
}
.btn-seg-msg-toggle:hover { color: var(--accent-bright); }
.btn-seg-msg-toggle.has-msg { color: var(--accent-bright); }

.seg-msg-row {
  display: none;
  padding: 0 8px 6px;
}
.seg-msg-row.open { display: block; }
.seg-msg-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--border);
  color: var(--text-secondary);
  font-size: .8rem;
  font-family: var(--font);
  font-style: italic;
  padding: 4px 0;
  outline: none;
}
.seg-msg-input:focus { border-color: var(--accent-bright); }
.seg-msg-input::placeholder { color: var(--text-muted); }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn-primary {
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  font-size: .875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur);
  width: 100%;
}
.btn-primary:hover { background: var(--accent-bright); }
.btn-secondary {
  padding: 9px 16px;
  background: transparent;
  color: var(--text-secondary);
  font-size: .875rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--dur), color var(--dur), background var(--dur);
  width: 100%;
}
.btn-secondary:hover { border-color: var(--border-strong); color: var(--text-primary); background: var(--surface-1); }
.btn-ghost {
  padding: 8px 12px;
  background: transparent;
  color: var(--accent-bright);
  font-size: .8rem;
  font-weight: 500;
  border: 1px dashed rgba(0,128,255,.35);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur), border-color var(--dur);
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-ghost:hover { background: rgba(0,99,229,.08); border-color: var(--accent); }

/* ── Result overlay ─────────────────────────────────────────────────── */
.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4,7,20,.75);
  backdrop-filter: blur(8px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.result-overlay.show {
  opacity: 1;
  pointer-events: all;
}
.result-card {
  background: #0e1230;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 40px 48px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  transform: scale(0.9) translateY(20px);
  transition: transform 0.3s var(--ease-snap);
  box-shadow: 0 32px 80px rgba(0,0,0,.6);
}
.result-overlay.show .result-card {
  transform: scale(1) translateY(0);
}
.result-emoji-big {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 16px;
  display: block;
}
.result-segment-text {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}
.result-message {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
  line-height: 1.5;
}
.result-color-bar {
  height: 4px;
  border-radius: 2px;
  margin: 0 auto 24px;
  width: 60px;
}
.btn-spin-again {
  padding: 12px 32px;
  background: var(--surface-3);
  color: var(--text-primary);
  font-size: .9rem;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  border-radius: 50px;
  cursor: pointer;
  transition: background var(--dur), transform var(--dur);
}
.btn-spin-again:hover { background: var(--surface-2); transform: scale(1.03); }

/* ── Result excuses (pipe-separated) ───────────────────────────────────── */
.result-excuses {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
  text-align: left;
}
.result-excuse-item {
  padding: 10px 14px;
  background: rgba(255,255,255,.05);
  border-left: 3px solid var(--item-color, #0063e5);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: .875rem;
  color: var(--text-secondary);
  line-height: 1.45;
  animation: slideInExcuse .35s ease both;
}
.result-excuse-item:nth-child(2) { animation-delay: .07s; }
.result-excuse-item:nth-child(3) { animation-delay: .14s; }
@keyframes slideInExcuse {
  from { opacity:0; transform: translateX(-12px); }
  to   { opacity:1; transform: translateX(0); }
}

/* ── Confetti ───────────────────────────────────────────────────────── */
.confetti-piece {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  z-index: 600;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg) scaleX(1);  opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg) scaleX(-1); opacity: 0; }
}

/* ── Toast ──────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 700;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1a1d35;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: .875rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in .25s ease forwards;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  white-space: nowrap;
}
.toast.out { animation: toast-out .25s ease forwards; }
@keyframes toast-in  { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
@keyframes toast-out { from { opacity:1; } to { opacity:0; transform:translateY(4px); } }

/* ── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  :root { --settings-w: 100vw; }

  .settings-drawer {
    position: fixed;
    inset: 68px 0 0 0;
    width: 100% !important;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(0.16,1,0.3,1);
  }
  .settings-drawer.closed { width: 100% !important; transform: translateX(100%); }
  .settings-drawer:not(.closed) { transform: translateX(0); }
  .settings-drawer-inner { width: 100%; }

  .btn-spin { padding: 13px 40px; }
}

/* ── Help button & menu ─────────────────────────────────────────────────── */
.help-button {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 44px; height: 44px;
  background: var(--accent);
  border: none; border-radius: 50%;
  color: #fff;
  font-size: 1.2rem; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,99,229,.5);
  z-index: 400;
  transition: transform var(--dur), box-shadow var(--dur);
}
.help-button:hover { transform: scale(1.1); box-shadow: 0 6px 24px rgba(0,99,229,.7); }
.help-menu {
  position: fixed;
  bottom: 80px; right: 24px;
  width: 280px;
  background: #0e1230;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 20px;
  z-index: 400;
  box-shadow: 0 16px 48px rgba(0,0,0,.6);
  transform: scale(0.9) translateY(10px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: transform .2s var(--ease-snap), opacity .2s;
}
.help-menu.show { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }
.help-menu h3 { font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; }
.help-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--border-subtle); font-size: .8rem; }
.help-row:last-child { border-bottom: none; }
.help-key {
  display: inline-block;
  padding: 2px 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: monospace;
  font-size: .78rem;
  color: var(--accent-bright);
}
.help-section { margin-top: 12px; }

/* ── Explosion Easter Egg ───────────────────────────────────────────────── */
.explosion-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 900;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.explosion-overlay.show { opacity: 1; pointer-events: all; }
.you-container { text-align: center; position: relative; z-index: 2; }
.you-text {
  font-size: clamp(5rem, 20vw, 14rem);
  font-weight: 900;
  color: #fff;
  letter-spacing: -.02em;
  line-height: 1;
  text-shadow: 0 0 60px #0063e5, 0 0 120px rgba(0,99,229,.6);
  animation: youFlash .4s ease;
}
@keyframes youFlash {
  0%   { transform: scale(.4) rotate(-5deg); opacity: 0; }
  60%  { transform: scale(1.15) rotate(2deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.pointing-hand { font-size: clamp(3rem, 10vw, 6rem); animation: pointBounce 1s ease-in-out infinite; }
@keyframes pointBounce {
  0%, 100% { transform: translateY(0) rotate(-10deg); }
  50%       { transform: translateY(-12px) rotate(-10deg); }
}
.you-subtitle { font-size: 1.2rem; color: rgba(255,255,255,.6); margin-top: 12px; letter-spacing: .2em; text-transform: uppercase; }
.explosion-close-hint { position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,.35); font-size: .85rem; }
.explosion-particles { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.particle {
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  top: 50%; left: 50%;
  animation: particleFly .8s ease-out forwards;
  transform: translate(var(--tx), var(--ty));
}
@keyframes particleFly {
  from { transform: translate(0,0) scale(1); opacity: 1; }
  to   { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* ── Button press feedback ────────────────────────────────────── */
button:active, .btn:active {
  transform: scale(0.97);
  transition-duration: 120ms;
}

/* ── Skeleton loading ─────────────────────────────────────────── */
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 10px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
:focus-visible {
  outline: 2px solid var(--accent-bright, #0080ff);
  outline-offset: 2px;
}
.skip-link {
  position: absolute; top: -100%; left: 16px; z-index: 1000;
  padding: 8px 16px; background: var(--accent-bright, #0080ff); color: #000;
  font-weight: 600; font-size: .875rem; border-radius: 0 0 6px 6px;
  text-decoration: none; transition: top .2s;
}
.skip-link:focus { top: 0; }
