:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --primary: #6366f1;
  --primary-strong: #4f46e5;
  --accent: #f59e0b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --radius: 12px;
  --radius-lg: 24px;
  --glass: rgba(255, 255, 255, 0.7);
}

* {
  box-sizing: border-box;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
  color: var(--ink);
  background: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(245, 158, 11, 0.05) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
    radial-gradient(at 0% 100%, rgba(245, 158, 11, 0.05) 0px, transparent 50%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.6;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 40px 32px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--primary) 0%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 4px rgba(99, 102, 241, 0.1));
}

.brand span {
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: -0.01em;
}

/* Sound Controls */
.sound-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  padding: 4px 12px 4px 4px;
  border-radius: 16px;
  border: 1px solid var(--border);
}

.sound-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border-radius: 12px;
  background: transparent;
  box-shadow: none;
}

.sound-toggle:hover {
  background: rgba(0,0,0,0.05);
}

.volume-slider {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.volume-slider:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button {
  border: none;
  border-radius: 14px;
  padding: 12px 24px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

button.primary {
  background: var(--primary);
  color: #ffffff;
}

button.primary:hover {
  background: var(--primary-strong);
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.3);
}

button.ghost {
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  color: var(--ink);
}

button.ghost:hover {
  background: #ffffff;
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

/* Modal System */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}

.modal.open {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 40px;
  width: min(800px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.timer-done .modal-card {
  background: #fee2e2;
  transform: scale(1.05);
  border: 8px solid #ef4444;
}

.modal.timer-done #modal-prompt {
  color: #991b1b;
  opacity: 0.2;
  filter: blur(4px);
}

.modal.timer-done .modal-body::after {
  content: "TIME'S UP!";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-10deg);
  font-size: 100px;
  font-weight: 900;
  color: #ef4444;
  text-shadow: 4px 4px 0 #991b1b;
  white-space: nowrap;
  pointer-events: none;
  animation: stampIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes stampIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(3) rotate(20deg); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-10deg); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 32px;
  align-items: center;
  text-align: center;
}

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

.pill {
  padding: 10px 20px;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

#modal-timer {
  background: var(--ink);
  color: white;
  min-width: 80px;
}

#modal-timer.urgent {
  background: #ef4444;
  animation: pulse 0.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

#modal-prompt {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--ink);
  margin: 20px 0;
}

.answer {
  padding: 32px;
  border-radius: 24px;
  background: #f0fdf4;
  border: 2px solid #bbf7d0;
  color: #166534;
  font-size: 32px;
  font-weight: 800;
  width: 100%;
  display: none;
}

.answer.show {
  display: block;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-actions {
  display: flex;
  gap: 20px;
  width: 100%;
}

.modal-actions button {
  flex: 1;
  padding: 24px;
  font-size: 20px;
}

[data-action="mark-wrong"] {
  background: #fee2e2;
  color: #991b1b;
}

[data-action="mark-correct"] {
  background: #dcfce7;
  color: #166534;
}

/* Cutscene System */
.cutscene {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 2000;
}

.cutscene.open {
  display: flex;
}

.cutscene-card {
  width: min(760px, 100%);
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 24px;
  text-align: center;
}

/* Editor Styling */
.panel.editor {
  background: var(--glass);
  backdrop-filter: blur(16px);
  padding: 48px;
  gap: 40px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  display: flex;
  flex-direction: column;
}

.editor-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 48px;
  align-items: start;
}

.editor-header {
  border-bottom: 2px solid var(--border);
  padding-bottom: 32px;
  margin-bottom: 8px;
}

.editor-sidebar {
  position: sticky;
  top: 32px;
}

.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 8px;
  display: block;
}

input[type="text"],
input[type="number"] {
  background: #ffffff;
  border: 2px solid var(--border);
  padding: 14px 18px;
  font-size: 16px;
  border-radius: 16px;
  width: 100%;
}

input[type="text"]:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
  outline: none;
}

.category {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px;
  box-shadow: var(--shadow);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  margin-bottom: 24px;
}

.category:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
}

.category-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.color-swatch {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  padding: 0;
}

.color-swatch:hover {
  transform: scale(1.05);
  border-color: var(--primary);
}

/* Custom Color Picker Modal */
.custom-color-picker {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 10px 0;
}

.color-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.preset-btn {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
  box-shadow: var(--shadow-sm);
}

.preset-btn:hover {
  transform: scale(1.1);
}

.preset-btn.active {
  border-color: var(--ink);
  transform: scale(1.1);
}

.custom-hex-input {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hex-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.current-color-preview {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.custom-hex-input input {
  flex: 1;
  font-family: monospace;
  text-transform: uppercase;
}

.category-header input[type="text"] {
.category-header input:focus {
  box-shadow: none;
  color: var(--primary);
}

.question-row {
  background: #f8fafc;
  padding: 20px;
  border-radius: 18px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.question-inputs {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.points-input {
  width: 120px;
}

input[type="number"] {
  padding: 14px 12px;
  text-align: center;
  -moz-appearance: textfield;
  appearance: auto;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  opacity: 1;
  height: 30px;
}

.content-inputs {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.add-q-btn {
  margin-top: 16px;
  width: 100%;
  border-style: dashed;
  background: transparent;
}

.add-cat-btn {
  margin-top: 32px;
  width: 100%;
  padding: 20px;
  font-size: 16px;
}

.team-row {
  background: #ffffff;
  padding: 12px 16px;
  border-radius: 16px;
  border: 2px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.team-row:hover {
  border-color: var(--primary);
}

.drag-handle {
  color: #cbd5e1;
  font-size: 24px;
  cursor: grab;
}

.full-width {
  width: 100%;
}

/* Board Styling */
.board {
  display: flex;
  flex-direction: column;
  gap: 32px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.board-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(var(--cols), 1fr);
  width: 100%;
}

.cell.header {
  background: linear-gradient(135deg, var(--primary) 0%, #818cf8 100%);
  border: none;
  border-radius: 16px;
  font-size: 18px;
  color: white;
  padding: 24px 16px;
  font-weight: 800;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

.cell.tile {
  border-radius: 20px;
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 32px;
  font-weight: 800;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.cell.tile.used {
  opacity: 0.3;
  background: #f1f5f9;
  cursor: default;
  box-shadow: none;
}

.cell.tile:not(.used):hover {
  background: var(--primary);
  color: #ffffff;
  border-color: transparent;
  transform: scale(1.05) translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.scoreboard {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.score-card {
  border-radius: 24px;
  padding: 24px 40px;
  background: white;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  border: 3px solid transparent;
}

.score-card.active {
  background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
  border-color: var(--primary);
  transform: scale(1.1);
  box-shadow: var(--shadow-lg);
}

.score-name {
  font-weight: 800;
  font-size: 18px;
}

.score-value {
  font-size: 36px;
  font-weight: 900;
  color: var(--primary-strong);
}

/* Winner View */
.winner-screen {
  text-align: center;
  padding: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.winner-emoji {
  font-size: 120px;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

.winner-name {
  font-size: 48px;
  font-weight: 900;
  background: linear-gradient(to right, var(--primary), #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Mode Selection */
.mode-option {
  padding: 24px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: white;
  cursor: pointer;
  margin-bottom: 16px;
  text-align: left;
}

.mode-option:hover {
  border-color: var(--primary);
  background: #f5f3ff;
}

.mode-option h4 {
  margin: 0 0 8px 0;
  font-size: 20px;
  color: var(--primary);
}

.mode-option p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .editor-grid {
    grid-template-columns: 1fr;
  }
  .editor-sidebar {
    position: static;
  }
}

/* Cutscene Overhaul */
.cutscene-arena {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 32px;
  padding: 40px 20px;
  border-radius: var(--radius);
  background: linear-gradient(to bottom, #f8fafc, #f1f5f9);
  border: 1px solid var(--border);
  perspective: 1000px;
}

.cutscene-hand {
  font-size: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 140px;
  width: 140px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: var(--shadow);
  margin: 0 auto;
  transition: transform 0.1s ease;
}

.cutscene-side.shaking .cutscene-hand {
  animation: handShake 0.4s infinite;
}

@keyframes handShake {
  0% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-20px) rotate(-15deg); }
  75% { transform: translateY(20px) rotate(15deg); }
  100% { transform: translateY(0) rotate(0); }
}

.cutscene-vs {
  font-size: 32px;
  font-weight: 900;
  color: var(--primary);
  font-style: italic;
  text-shadow: 0 0 20px rgba(79, 70, 229, 0.2);
}

.cutscene-badge {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  animation: badgePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.cutscene-badge span {
  color: var(--primary);
  font-size: 14px;
}

@keyframes badgePop {
  from { opacity: 0; transform: translateY(10px) scale(0.8); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cutscene-order {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 16px;
}
