/* ============================================================
   CSS CUSTOM PROPERTIES — THEME TOKENS
   ============================================================ */
:root,
[data-theme="default"] {
  --theme-bg:          #0d0d1a;
  --theme-surface:     #1a1a2e;
  --theme-surface-2:   #16213e;
  --theme-border:      #2d2d5e;
  --theme-accent-1:    #7c3aed;
  --theme-accent-2:    #06b6d4;
  --theme-text:        #e2e8f0;
  --theme-text-muted:  #94a3b8;
  --theme-beat-glow:   #a855f7;
  --theme-error:       #ef4444;
  --theme-success:     #22c55e;
  --theme-warning:     #f59e0b;
}

[data-theme="neon-city"] {
  --theme-bg:          #0a0018;
  --theme-surface:     #1a0030;
  --theme-surface-2:   #12002a;
  --theme-border:      #5500aa;
  --theme-accent-1:    #ff00ff;
  --theme-accent-2:    #00e5ff;
  --theme-text:        #e0d7ff;
  --theme-text-muted:  #9d7fd6;
  --theme-beat-glow:   #ff00aa;
}

[data-theme="forest-night"] {
  --theme-bg:          #0d1f0d;
  --theme-surface:     #0f2d0f;
  --theme-surface-2:   #0a1f0a;
  --theme-border:      #2e7d32;
  --theme-accent-1:    #39ff14;
  --theme-accent-2:    #ff9800;
  --theme-text:        #d4f7dc;
  --theme-text-muted:  #88c98f;
  --theme-beat-glow:   #76ff03;
}

[data-theme="deep-space"] {
  --theme-bg:          #03001a;
  --theme-surface:     #090030;
  --theme-surface-2:   #060020;
  --theme-border:      #1a237e;
  --theme-accent-1:    #4fc3f7;
  --theme-accent-2:    #aa00ff;
  --theme-text:        #b3e5fc;
  --theme-text-muted:  #7ba7c2;
  --theme-beat-glow:   #e040fb;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background-color: var(--theme-bg);
  color: var(--theme-text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

/* iOS safe-area support */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-header {
  background: var(--theme-surface);
  border-bottom: 1px solid var(--theme-border);
  padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--theme-accent-1);
  flex: 1;
  white-space: nowrap;
}

/* Theme selector lives in header */
.theme-select--header {
  width: auto;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.app-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.75rem 0.875rem calc(1rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* Two-column grid: player | scheduler */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 0.875rem;
  align-items: start;
}

@media (max-width: 820px) {
  .content-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   SHARED SECTION CHROME
   ============================================================ */
.section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--theme-accent-1);
  margin-bottom: 0.625rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.625rem 1rem;
  border: 1px solid var(--theme-border);
  border-radius: 6px;
  background: var(--theme-surface);
  color: var(--theme-text);
  font-size: 0.9375rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  white-space: nowrap;
  min-height: 44px;
}

.btn:hover:not(:disabled) {
  background: var(--theme-surface-2);
  border-color: var(--theme-accent-1);
}

.btn:focus-visible {
  outline: 2px solid var(--theme-accent-1);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary */
.btn--primary {
  background: var(--theme-accent-1);
  border-color: var(--theme-accent-1);
  color: #fff;
  font-weight: 600;
}
.btn--primary:hover:not(:disabled) {
  background: var(--theme-accent-1);
  opacity: 0.85;
}

/* Alarm — gradient CTA */
.btn--alarm {
  background: linear-gradient(135deg, var(--theme-accent-1), var(--theme-accent-2));
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.6875rem 1.5rem;
  box-shadow: 0 0 14px rgba(120, 40, 200, 0.35);
}
.btn--alarm:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 0 22px rgba(120, 40, 200, 0.55);
}

/* Large variant */
.btn--large { padding: 1rem 2.5rem; font-size: 1.1875rem; }

/* Icon button */
.btn--icon {
  padding: 0.5rem 0.625rem;
  font-size: 1.0625rem;
  min-width: 2.25rem;
}

/* Mode buttons */
.btn--mode {
  padding: 0.3125rem 0.875rem;
  font-size: 0.8125rem;
}
.btn--mode.active {
  background: var(--theme-accent-1);
  border-color: var(--theme-accent-1);
  color: #fff;
  font-weight: 600;
}

/* Small */
.btn--small { padding: 0.3125rem 0.75rem; font-size: 0.8125rem; }

/* Danger icon */
.btn--danger {
  color: var(--theme-error);
  border-color: var(--theme-error);
  padding: 0.3rem 0.55rem;
  font-size: 0.8rem;
  min-height: 36px;
}
.btn--danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.15);
}

/* Toggle button for collapsible visualizer */
.btn--toggle-viz {
  width: 100%;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  background: var(--theme-surface);
  border-color: var(--theme-border);
  min-height: 40px;
}
.btn--toggle-viz .toggle-arrow {
  margin-left: auto;
  font-size: 0.75rem;
  transition: transform 0.2s;
}
.btn--toggle-viz[aria-expanded="true"] .toggle-arrow {
  transform: rotate(180deg);
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
input[type="text"],
select {
  background: var(--theme-surface-2);
  border: 1px solid var(--theme-border);
  border-radius: 6px;
  padding: 0.6875rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--theme-text);
  width: 100%;
  transition: border-color 0.15s;
}

@media (max-width: 820px) {
  .app-main {
    padding: 0.625rem 0.625rem calc(0.875rem + env(safe-area-inset-bottom));
    gap: 0.75rem;
  }
  .app-title { font-size: 1rem; }
}

@media (max-width: 560px) {
  .content-grid { gap: 0.75rem; }
  .btn--small, .btn--mode { font-size: 0.875rem; }
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--theme-accent-1);
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.25);
}

input[type="text"]::placeholder { color: var(--theme-text-muted); }

select option {
  background: var(--theme-surface);
  color: var(--theme-text);
}
