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

:root {
  --sb-w: 440px;
  --bg: #f6f5f1;
  --sb-bg: #ffffff;
  --sb-border: #e3e1d8;
  --surface: #f0efe7;
  --border: #dcdacf;
  --accent: #cc2222;
  --red: #cc2222;
  --text: #1a1a1f;
  --muted: #767686;
  --shadow: rgba(20, 20, 25, .12);
}

html[data-theme="dark"] {
  --bg: #111113;
  --sb-bg: #18181b;
  --sb-border: #2a2a30;
  --surface: #222228;
  --border: #333340;
  --accent: #cc2222;
  --red: #cc2222;
  --text: #f0f0f5;
  --muted: #7a7a8c;
  --shadow: rgba(0, 0, 0, .7);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow: hidden;
  transition: background .2s ease, color .2s ease;
}

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

.sidebar {
  width: var(--sb-w);
  background: var(--sb-bg);
  border-left: 1px solid var(--sb-border);
  padding: 32px 28px;
  height: 100vh;
  position: fixed;
  top: 0;
  right: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
  z-index: 100;
}

.sidebar-top {
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 62vh;
  padding-right: 4px;
  margin-right: -4px;
}

.options-section {
  flex: 1;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: 20px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}

.sidebar-logo .brand {
  font-family: 'Anton', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 3px;
  color: var(--accent);
  display: block;
}

.sidebar-logo .domain {
  font-size: .75rem;
  color: var(--muted);
  letter-spacing: 1.5px;
  margin-top: 3px;
}

.theme-toggle {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sb-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.sb-divider {
  border: none;
  border-top: 1px solid var(--sb-border);
  margin: 20px 0;
}

input[type=text] {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: .95rem;
  padding: 10px 14px;
  outline: none;
}

input[type=text]:focus {
  border-color: var(--accent);
}

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

.add-row input[type="color"] {
  width: 46px;
  height: 44px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  padding: 2px;
}

.btn-add {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1.2rem;
  padding: 0 20px;
  cursor: pointer;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-action {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}

.sound-select-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}

.sound-select-box select {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px;
  font-family: 'Inter', sans-serif;
  font-size: .85rem;
  outline: none;
}

.btn-upload-sound {
  display: block;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 8px;
  text-align: center;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
  transition: border-color 0.2s;
}

.btn-upload-sound:hover {
  border-color: var(--accent);
}

.audio-test-row {
  display: flex;
  gap: 8px;
}

.audio-test-row button {
  flex: 1;
}

.word-tags {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  margin-top: 4px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--sb-border);
  border-radius: 10px;
}

.word-tag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .9rem;
  flex-shrink: 0;
}

.tag-left {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

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

.word-tag button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
}

.word-count {
  font-size: .78rem;
  color: var(--muted);
  text-align: right;
  margin-top: 8px;
}

.btn-reset-defaults {
  display: none;
  width: 100%;
  margin-top: 12px;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.btn-reset-defaults:hover {
  border-color: var(--accent);
}

.main {
  position: fixed;
  top: 0;
  left: 0;
  right: var(--sb-w);
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1;
}

.wheel-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 520px;
  margin-top: 100px;
}

.winner-banner {
  display: none;
  position: absolute;
  top: -85px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-family: 'Anton', sans-serif;
  font-size: 2rem;
  letter-spacing: 2px;
  padding: 12px 32px;
  border-radius: 12px;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 10px 25px var(--shadow);
  z-index: 50;
  animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop {
  0% {
    transform: translateX(-50%) scale(0.5);
    opacity: 0;
  }

  100% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

.winner-banner.show {
  display: block;
}

#wheel-card {
  background: var(--sb-bg);
  border: 1px solid var(--sb-border);
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 20px 60px var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}

.wheel-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.arrow {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 30px solid var(--accent);
  z-index: 10;
  filter: drop-shadow(0 4px 6px var(--shadow));
}

canvas#wheel {
  border-radius: 50%;
  display: block;
  background: var(--bg);
  width: 100%;
  max-width: 380px;
  height: auto;
  aspect-ratio: 1 / 1;
}

.controls {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 380px;
}

.btn-spin {
  flex: 2;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-family: 'Anton', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 2px;
  padding: 14px 28px;
  cursor: pointer;
}

.btn-spin:disabled {
  background: var(--surface);
  color: var(--muted);
  cursor: not-allowed;
}

.btn-sound {
  flex: 1;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
}

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--sb-bg);
  border-bottom: 1px solid var(--sb-border);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 200;
}

.mobile-logo {
  font-family: 'Anton', sans-serif;
  font-size: 1.2rem;
  letter-spacing: 3px;
  color: var(--accent);
}

.mobile-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hamburger {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 6px 10px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 99;
}

.sidebar-overlay.show {
  display: block;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  display: flex;
  opacity: 1;
}

.modal-box {
  background: var(--sb-bg);
  border: 1px solid var(--sb-border);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 50px var(--shadow);
  transform: scale(0.9);
  transition: transform 0.2s ease;
}

.modal-overlay.show .modal-box {
  transform: scale(1);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.modal-text {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.btn-modal {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

.btn-modal:hover {
  opacity: 0.9;
}

.btn-cancel {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--accent);
  color: #ffffff;
}

@media (max-width: 1000px) {
  :root {
    --sb-w: 360px;
  }
}

@media (max-width: 768px) {
  body {
    overflow: auto;
  }

  .mobile-header {
    display: flex;
  }

  .sidebar {
    width: min(88vw, 380px) !important;
    transform: translateX(110%);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    padding-top: 80px;
    right: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    right: 0 !important;
    padding-top: 100px;
  }

  .wheel-wrapper {
    margin-top: 50px;
  }

  .winner-banner {
    font-size: 1.3rem;
    padding: 10px 20px;
    top: -70px;
    max-width: 90vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #wheel-card {
    padding: 20px 16px;
  }

  .controls {
    flex-direction: column;
  }

  .btn-spin {
    padding: 16px 20px;
  }

  .btn-sound {
    padding: 12px;
  }

  .sidebar-top {
    max-height: 42vh;
  }

  .options-section {
    min-height: 180px;
  }
}

/* === AUDIO MANAGER === */
.audio-manager-box {
  max-width: 600px;
  text-align: left;
}

.audio-file-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 350px;
  overflow-y: auto;
  margin-top: 16px;
}

.audio-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.audio-file-name {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-file-actions {
  display: flex;
  gap: 8px;
}

.btn-select-audio,
.btn-delete-audio {
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-select-audio {
  background: var(--accent);
  color: white;
}

.btn-delete-audio {
  background: #444;
  color: white;
}

.btn-select-audio.active {
  background: #22aa55;
}