/* Theme variables */
:root {
  --bg: #f7f7f7;
  --card-bg: #ffffff;
  --text: #222;
  --muted: #666;
  
  /* Muted Blue for Primary Actions */
  --accent: #5a8bc9; 
  --accent-hover: #4772a8;
  
  /* Muted Red for Destructive Actions */
  --danger: #b56b6b;
  --danger-hover: #965252;
  
  --warning: #ffc107;
  --success: #28a745;
  --border: #ddd;
  
  /* Secondary/Inactive */
  --btn-secondary: #7e8791;
  
  /* Control panel active glow */
  --glow-color: rgba(90, 139, 201, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111;
    --card-bg: #1f1f1f;
    --text: #f5f5f5;
    --muted: #999;
    --accent: #5a8bc9; 
    --accent-hover: #7aa5db;
    --danger: #b56b6b;
    --danger-hover: #d18282;
    --warning: #e0a800;
    --success: #42c96b;
    --border: #333;
    --btn-secondary: #5a6268;
    --glow-color: rgba(90, 139, 201, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, sans-serif;
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  background: radial-gradient(circle at top, rgba(0,0,0,0.06), transparent 55%), var(--bg);
  color: var(--text);
}

.card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px 18px 5px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.10);
  border: 1px solid rgba(0,0,0,0.03);
}

h1 { font-size: 1.5rem; text-align: center; margin: 0 0 30px; }

/* Inputs */
.text-input, input[type="number"], input[type="range"], input[type="text"] {
  width: 100%;
  padding: 12px;
  font-size: 1.25rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 8px; 
  text-align: center;
  background: #fff;
  color: #222;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  text-transform: none;
}

/* Number inputs without spinners */
.num-input {
  -moz-appearance: textfield;
  appearance: textfield;
}

.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Locked input state */
.text-input.locked {
  background: rgba(0,0,0,0.05);
  opacity: 0.7;
  cursor: not-allowed;
}

@media (prefers-color-scheme: dark) {
  .text-input.locked {
    background: rgba(255,255,255,0.05);
  }
}

label { display: block; font-size: 0.9rem; margin-bottom: 8px; font-weight: 500; }

@media (prefers-color-scheme: dark) {
  .text-input, input[type="number"], input[type="text"] {
    background: #2a2a2a; color: #fff; border-color: #444;
  }
  .text-input:focus, input[type="number"]:focus, input[type="text"]:focus {
    background: #333; border-color: var(--accent);
  }
}

input[type="number"]:focus, .text-input:focus, input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(90, 139, 201, 0.2);
}

input[type=range] { width: 100%; margin: 4px 0 10px; cursor: pointer; }

/* Buttons */
.btn-row { display: flex; gap: 10px; margin-top: 4px; margin-bottom: 4px; }

button {
  flex: 1; padding: 12px; border-radius: 999px; border: none;
  font-size: 0.95rem; cursor: pointer; font-weight: 600; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  transition: transform 0.06s ease, background 0.15s ease, box-shadow 0.15s ease;
}

button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: default; box-shadow: none; }

/* Button Palette */
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--btn-secondary); color: #fff; }

/* Exit Queue Button - Subtle gray */
.btn-exit-queue {
  background: #aaa;
  color: #fff;
}
.btn-exit-queue:hover {
  background: #999;
}

@media (prefers-color-scheme: dark) {
  .btn-exit-queue {
    background: #555;
    color: #ccc;
  }
  .btn-exit-queue:hover {
    background: #666;
  }
}

/* Destructive Actions */
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

/* Pause / Warning */
.btn-warning { background: var(--warning); color: #222; }

/* Direction Buttons (CCW / CW) */
.toggle-wrapper.centered-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 15px;
}

.btn-dir {
  flex: 0 0 auto;
  min-width: 70px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--btn-secondary);
  color: #fff;
  border: 2px solid transparent;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: all 0.15s ease;
}

.btn-dir:hover {
  background: #6a747d;
}

.btn-dir.active {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--glow-color), 0 2px 4px rgba(0,0,0,0.1);
}

/* Mode Buttons (OFF / LOOP / BOUNCE) */
.mode-row {
  display: flex;
  gap: 8px;
  margin: 15px 0;
}

.btn-mode {
  flex: 1;
  padding: 10px 8px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(0,0,0,0.08);
  color: var(--muted);
  border: 2px solid transparent;
  box-shadow: none;
  transition: all 0.15s ease;
}

.btn-mode:hover {
  background: rgba(0,0,0,0.12);
  color: var(--text);
}

.btn-mode.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--glow-color), 0 2px 4px rgba(0,0,0,0.15);
}

@media (prefers-color-scheme: dark) {
  .btn-mode {
    background: rgba(255,255,255,0.08);
  }
  .btn-mode:hover {
    background: rgba(255,255,255,0.12);
  }
}

/* Reservation Note */
.reservation-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

/* Turn Countdown Area - Fixed height for consistency */
.countdown-area {
  min-height: 52px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-top: 12px;
  margin-bottom: 8px;
}

.turn-countdown {
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.4rem;
}

.turn-countdown.has-time {
  font-weight: 600;
  color: var(--text);
}

/* Tabs */
.tab-row { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { flex: 1; padding: 12px; background: none; border: none; color: var(--muted); cursor: pointer; font-weight: 600; box-shadow: none; border-radius: 8px 8px 0 0; }
.tab:hover { background: rgba(0,0,0,0.03); }
.tab.active { color: var(--accent); border-bottom: 3px solid var(--accent); background: rgba(0,0,0,0.02); }

.hidden { display: none; }

/* Control Panel */
.controls-panel {
  background: var(--card-bg);
  padding: 20px;
  border-radius: 16px;
  margin-top: 20px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.15);
  transition: opacity 0.3s ease, box-shadow 0.3s ease, border 0.3s ease;
  border: 2px solid transparent;
}

.controls-disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* Active control panel glow */
.controls-panel.controls-active {
  border: 2px solid var(--accent);
  box-shadow: 0 0 20px var(--glow-color), 0 6px 16px rgba(0,0,0,0.15);
}

/* Animation Params */
.anim-params { background: rgba(0,0,0,0.03); padding: 12px; border-radius: 10px; margin-bottom: 15px; border: 1px solid var(--border); }
.anim-row-inputs { display: flex; gap: 10px; } .anim-col { flex: 1; }

/* Toggle Switch (legacy - kept for compatibility) */
.toggle-wrapper { display: flex; align-items: center; margin-bottom: 10px; justify-content: center; gap: 15px; }
.toggle-label { font-size: 0.9rem; font-weight: 600; min-width: 40px; text-align: center; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }

input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(20px); }

/* Queue Box - 40% smaller */
#queue-box {
  display: block;
  border-radius: 12px;
  padding: 10px;
  background: rgba(0,0,0,0.05);
  height: 140px;
  overflow-y: auto;
  box-sizing: border-box;
}

@media (prefers-color-scheme: dark) {
  #queue-box { background: rgba(255,255,255,0.06); }
}

/* Queue Items */
.queue-item {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--card-bg);
  margin-bottom: 6px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.queue-item:last-child {
  margin-bottom: 0;
}

/* Controller (first in queue) */
.queue-item.controller {
  background: rgba(90, 139, 201, 0.15);
  border-color: var(--accent);
  font-weight: 600;
}

/* Your position in queue */
.queue-item.you {
  border-color: var(--success);
  background: rgba(40, 167, 69, 0.1);
}

/* Controller + You */
.queue-item.controller.you {
  background: linear-gradient(135deg, rgba(90, 139, 201, 0.2), rgba(40, 167, 69, 0.15));
  border-color: var(--success);
}

/* Breathing dot for controller */
.controller-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  animation: breathe 2s infinite ease-in-out;
  flex-shrink: 0;
}

.controller-dot.yellow {
  background: var(--warning);
}

.controller-dot.red {
  background: var(--danger);
}

.controller-dot.solo {
  background: var(--accent);
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.7); opacity: 0.6; }
}

.queue-item-name {
  flex: 1;
}

.queue-item-time {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: normal;
}

.queue-item-status {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
}

/* Live View */
.live-view {
  margin-top: 20px;
}

.video-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0,0,0,0.05);
  position: relative;
}

@media (prefers-color-scheme: dark) {
  .video-frame {
    background: rgba(255,255,255,0.06);
  }
}

.video-offline-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.video-offline-text {
  font-size: 0.85rem;
  color: var(--muted);
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

/* Live Badge */
.badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-offline {
  color: var(--muted);
}

.badge-dot {
  width: 8px;
  height: 8px;
  background: currentColor;
  border-radius: 50%;
  animation: pulsedot 1.2s infinite ease-in-out;
}

.badge-dot-offline {
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  opacity: 0.6;
}

@keyframes pulsedot {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.6); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

/* Status */
.status {
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.4rem;
  margin-top: 10px;
}

.status--ok { color: var(--success); }
.status--error { color: var(--danger); }
.status--info { color: var(--muted); }

/* Footer */
.footer-note {
  text-align: center;
  margin-top: 30px;
  color: var(--muted);
  font-size: 0.8rem;
}

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