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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #DDDBE0;
  color: #2a2a2a;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */
#header {
  text-align: center;
  padding: 1.5rem 1rem 0.75rem;
}

#header-logo {
  max-width: 340px;
  width: 80%;
  height: auto;
  display: block;
  margin: 0 auto;
  drop-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ─── Main Layout ─────────────────────────────────────────────────────────── */
#main-layout {
  display: flex;
  justify-content: center;
  gap: 2rem;
  padding: 1rem 2rem;
  max-width: 1100px;
  margin: 0 auto;
}

/* ─── Wheel Section ───────────────────────────────────────────────────────── */
#wheel-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
}

#wheel-canvas {
  display: block;
  max-width: 500px;
  max-height: 500px;
  width: 100%;
  height: auto;
  cursor: grab;
}

#wheel-canvas:active {
  cursor: grabbing;
}

#wheel-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

#spin-btn {
  padding: 0.75rem 2.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: #CC0000;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 8px rgba(204, 0, 0, 0.2);
}

#spin-btn:hover:not(:disabled) {
  background: #e60000;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(204, 0, 0, 0.35);
}

#spin-btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(204, 0, 0, 0.25);
}

#spin-btn:disabled {
  background: #c8c8c8;
  color: #888;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#spin-counter {
  font-size: 0.95rem;
  color: #666;
  font-weight: 600;
}

#drag-hint {
  font-size: 0.78rem;
  color: #aaa;
  font-style: italic;
}

/* ─── Pick Result ─────────────────────────────────────────────────────────── */
#pick-result {
  width: 100%;
  max-width: 500px;
}

#pick-details {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

#pick-thumbnail {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid #CC0000;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

#pick-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

#pick-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #1a1a1a;
}

#pick-submitter {
  font-size: 0.82rem;
  color: #777;
}

#pick-copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: #f9f9fa;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

#pick-respin-row {
  margin-top: 0.6rem;
  text-align: center;
}

#pick-winner-title {
  font-size: 0.88rem;
  color: #CC0000;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* ─── Error Banner ────────────────────────────────────────────────────────── */
#error-banner {
  width: 100%;
  max-width: 500px;
  padding: 0.75rem 1rem;
  background: #fff5f5;
  border: 1px solid #CC0000;
  border-radius: 10px;
  color: #CC0000;
  font-size: 0.9rem;
  text-align: center;
  box-shadow: 0 2px 8px rgba(204, 0, 0, 0.08);
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 220px;
  padding-top: 0.5rem;
}

#sidebar h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #999;
  margin-bottom: 0.4rem;
  font-weight: 700;
}

/* Playlist buttons */
#playlist-selectors {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.playlist-btn-row {
  display: flex;
  gap: 0.35rem;
  align-items: stretch;
}

.playlist-btn-row .playlist-btn {
  flex: 1;
}

.playlist-remove-btn {
  padding: 0 0.6rem;
  font-size: 1.1rem;
  font-weight: 700;
  border: 2px solid #d0d0d0;
  border-radius: 10px;
  background: #fff;
  color: #999;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
}

.playlist-remove-btn:hover {
  border-color: #CC0000;
  color: #CC0000;
  background: #fff5f5;
}

.playlist-btn {
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 2px solid #d0d0d0;
  border-radius: 10px;
  background: #fff;
  color: #444;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.playlist-btn:hover {
  border-color: #CC0000;
  color: #CC0000;
  box-shadow: 0 2px 8px rgba(204, 0, 0, 0.08);
}

.playlist-btn.active {
  border-color: #CC0000;
  background: #fff5f5;
  color: #CC0000;
  box-shadow: 0 2px 12px rgba(204, 0, 0, 0.12);
}

.playlist-btn.completed {
  border-color: #28a745;
  color: #28a745;
  opacity: 0.85;
}

.playlist-btn.completed::after {
  content: ' ✓';
}

/* Filter checkboxes */
#filter-controls {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: #444;
  cursor: pointer;
  padding: 0.3rem 0;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #CC0000;
  cursor: pointer;
  border-radius: 4px;
}

/* Mute button */
#mute-btn {
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  border: 2px solid #d0d0d0;
  border-radius: 10px;
  background: #fff;
  color: #555;
  cursor: pointer;
  transition: all 0.2s ease;
}

#mute-btn:hover {
  border-color: #CC0000;
  color: #CC0000;
}

#mute-btn.muted {
  border-color: #CC0000;
  color: #CC0000;
  background: #fff5f5;
}

/* Reset button */
#reset-btn {
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  border: 2px solid #CC0000;
  border-radius: 10px;
  background: transparent;
  color: #CC0000;
  cursor: pointer;
  transition: all 0.2s ease;
}

#reset-btn:hover {
  background: #CC0000;
  color: #fff;
  box-shadow: 0 2px 10px rgba(204, 0, 0, 0.2);
}

/* ─── Results Panel ───────────────────────────────────────────────────────── */
#results-panel {
  max-width: 1100px;
  margin: 1rem auto;
  padding: 0 2rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ─── Shared Result Box ───────────────────────────────────────────────────── */
.result-box {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.result-box h3 {
  font-size: 1rem;
  color: #CC0000;
  margin-bottom: 0.75rem;
  font-weight: 700;
}

.result-box pre {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 0.9rem;
  color: #333;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 0.75rem;
  line-height: 1.7;
}

/* ─── Copy Button ─────────────────────────────────────────────────────────── */
.copy-btn {
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1.5px solid #CC0000;
  border-radius: 8px;
  background: transparent;
  color: #CC0000;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.copy-btn:hover {
  background: #CC0000;
  color: #fff;
  box-shadow: 0 2px 8px rgba(204, 0, 0, 0.2);
}

.copy-btn.copied {
  border-color: #28a745;
  background: #28a745;
  color: #fff;
}

/* ─── Respin Button ───────────────────────────────────────────────────────── */
.respin-btn {
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 2px solid #e68a00;
  border-radius: 10px;
  background: transparent;
  color: #e68a00;
  cursor: pointer;
  transition: all 0.2s ease;
}

.respin-btn:hover {
  background: #e68a00;
  color: #fff;
  box-shadow: 0 2px 10px rgba(230, 138, 0, 0.2);
}

/* Playlist summary actions row */
#playlist-summary-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

/* ─── AI Section ──────────────────────────────────────────────────────────── */
#ai-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 2rem 2rem;
}

.ai-collapsible {
  cursor: default;
}

.ai-collapsible summary.ai-toggle {
  font-size: 1.05rem;
  font-weight: 700;
  color: #CC0000;
  cursor: pointer;
  padding: 0.75rem 0;
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.ai-collapsible summary.ai-toggle::-webkit-details-marker {
  display: none;
}

.ai-collapsible summary.ai-toggle::before {
  content: '▶';
  font-size: 0.7rem;
  transition: transform 0.2s ease;
  display: inline-block;
}

.ai-collapsible[open] summary.ai-toggle::before {
  transform: rotate(90deg);
}

.ai-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 0.75rem;
}

#ai-section h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #999;
  margin-bottom: 0.3rem;
  font-weight: 700;
}

.ai-description {
  font-size: 0.9rem;
  color: #666;
  line-height: 1.5;
}

#ai-playlist-selection,
#ai-filters {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ai-btn-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ai-btn {
  padding: 0.65rem 1.8rem;
  font-size: 0.95rem;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: #CC0000;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  box-shadow: 0 2px 8px rgba(204, 0, 0, 0.2);
}

.ai-btn:hover:not(:disabled) {
  background: #e60000;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(204, 0, 0, 0.3);
}

.ai-btn:active:not(:disabled) {
  transform: translateY(0);
}

.ai-btn:disabled {
  background: #c8c8c8;
  color: #888;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ai-btn-secondary {
  padding: 0.65rem 1.8rem;
  font-size: 0.95rem;
  font-weight: 700;
  border: 2px solid #CC0000;
  border-radius: 10px;
  background: transparent;
  color: #CC0000;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ai-btn-secondary:hover:not(:disabled) {
  background: #CC0000;
  color: #fff;
  box-shadow: 0 4px 12px rgba(204, 0, 0, 0.2);
}

.ai-btn-secondary:disabled {
  border-color: #c8c8c8;
  color: #888;
  cursor: not-allowed;
}

.btn-subtitle {
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.75;
  letter-spacing: normal;
  text-transform: none;
}

#ai-loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: #CC0000;
  font-weight: 500;
}

.ai-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid #e0e0e0;
  border-top-color: #CC0000;
  border-radius: 50%;
  animation: ai-spin 0.8s linear infinite;
}

@keyframes ai-spin {
  to { transform: rotate(360deg); }
}

#ai-results #ai-results-text {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 0.9rem;
  color: #333;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.8;
  margin-bottom: 0.75rem;
}

#ai-results-text a {
  color: #CC0000;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

#ai-results-text a:hover {
  color: #e60000;
}

#ai-results-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

#ai-error {
  padding: 0.75rem 1rem;
  background: #fff5f5;
  border: 1px solid #CC0000;
  border-radius: 10px;
  color: #CC0000;
  font-size: 0.9rem;
}

/* ─── Loading Overlay ──────────────────────────────────────────────────────── */
#loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(221, 219, 224, 0.85);
  border-radius: 12px;
  z-index: 10;
  backdrop-filter: blur(2px);
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #e0e0e0;
  border-top-color: #CC0000;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-spinner-small {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2.5px solid #e0e0e0;
  border-top-color: #CC0000;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.95rem;
  color: #666;
  font-weight: 600;
}

/* ─── Add Playlist Button ─────────────────────────────────────────────────── */
.add-playlist-btn {
  padding: 0.5rem 1rem;
  font-size: 1.2rem;
  font-weight: 700;
  border: 2px dashed #d0d0d0;
  border-radius: 10px;
  background: transparent;
  color: #999;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.add-playlist-btn:hover {
  border-color: #CC0000;
  color: #CC0000;
  background: #fff5f5;
}

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
}

.modal-content {
  background: #fff;
  border-radius: 14px;
  padding: 1.75rem 2rem;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-content h3 {
  font-size: 1.1rem;
  color: #1a1a1a;
  margin-bottom: 0.3rem;
}

.modal-description {
  font-size: 0.88rem;
  color: #777;
  margin-bottom: 1rem;
}

.modal-content input[type="text"] {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-size: 0.9rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s ease;
  margin-bottom: 0.6rem;
}

.modal-content input[type="text"]:focus {
  border-color: #CC0000;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

.modal-cancel-btn {
  padding: 0.55rem 1.2rem;
  font-size: 0.88rem;
  font-weight: 600;
  border: 2px solid #d0d0d0;
  border-radius: 8px;
  background: transparent;
  color: #666;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-cancel-btn:hover {
  border-color: #999;
  color: #333;
}

.modal-confirm-btn {
  padding: 0.55rem 1.2rem;
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: #CC0000;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(204, 0, 0, 0.2);
}

.modal-confirm-btn:hover:not(:disabled) {
  background: #e60000;
  box-shadow: 0 4px 12px rgba(204, 0, 0, 0.3);
}

.modal-confirm-btn:disabled {
  background: #c8c8c8;
  color: #888;
  cursor: not-allowed;
  box-shadow: none;
}

.modal-error {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #fff5f5;
  border: 1px solid #CC0000;
  border-radius: 8px;
  color: #CC0000;
  font-size: 0.85rem;
}

.modal-loading {
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: #CC0000;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ─── Version Tag ─────────────────────────────────────────────────────────── */
#version-tag {
  position: fixed;
  bottom: 0.5rem;
  right: 0.75rem;
  font-size: 0.7rem;
  color: #aaa;
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

/* ─── Utility ─────────────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #main-layout {
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    gap: 1.5rem;
  }

  #sidebar {
    min-width: unset;
    width: 100%;
    max-width: 400px;
  }

  #wheel-canvas {
    max-width: 350px;
    max-height: 350px;
  }

  #header-logo {
    max-width: 260px;
  }

  #results-panel,
  #ai-section {
    padding: 0 1rem 1.5rem;
  }

  .result-box {
    padding: 1rem;
  }

  #pick-result {
    max-width: 100%;
  }

  #spin-btn {
    padding: 0.65rem 2rem;
    font-size: 1rem;
  }

  .ai-btn,
  .ai-btn-secondary {
    padding: 0.6rem 1.4rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) {
  #header {
    padding: 1rem 0.75rem 0.5rem;
  }

  #header-logo {
    max-width: 200px;
  }

  #wheel-canvas {
    max-width: 280px;
    max-height: 280px;
  }

  #main-layout {
    padding: 0.75rem;
    gap: 1rem;
  }

  .playlist-btn {
    font-size: 0.85rem;
    padding: 0.55rem 0.8rem;
  }

  #pick-details {
    flex-direction: column;
    align-items: flex-start;
  }

  #pick-thumbnail {
    width: 100%;
    height: auto;
    max-width: 200px;
  }

  #pick-copy-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  #playlist-summary-actions,
  #ai-results-actions,
  .ai-btn-row {
    flex-direction: column;
    align-items: stretch;
  }

  .ai-btn,
  .ai-btn-secondary,
  .copy-btn,
  .respin-btn {
    text-align: center;
    width: 100%;
  }

  .modal-content {
    padding: 1.25rem 1.5rem;
    width: 95%;
  }
}
