/* ==========================================
   Design Tokens
   ========================================== */
:root {
  --bg-primary: #0f172a;
  --bg-surface: rgba(15, 23, 42, 0.7);
  --bg-card: rgba(255, 255, 255, 0.05);
  --bg-card-hover: rgba(255, 255, 255, 0.1);
  --bg-element: rgba(255, 255, 255, 0.08);
  --bg-input: rgba(255, 255, 255, 0.04);
  --border-card: rgba(255, 255, 255, 0.1);
  --border-card-hover: rgba(255, 255, 255, 0.2);
  --border-element: rgba(255, 255, 255, 0.12);

  --primary-500: #6366f1; /* Indigo */
  --primary-400: #818cf8;
  --primary-300: #a5b4fc;
  --primary-600: #4f46e5;
  --primary-700: #4338ca;
  --accent-blue: #0ea5e9; /* Sky Blue */
  --accent-violet: #8b5cf6; /* Violet */
  --rose-500: #f43f5e;
  --amber-400: #fbbf24;
  --green-400: #4ade80;

  --gradient-primary: linear-gradient(135deg, var(--primary-500), var(--accent-blue));
  --gradient-ring: conic-gradient(from 0deg, var(--primary-500), var(--accent-blue), var(--accent-violet), var(--primary-500));

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);
  --shadow-glow-active: 0 0 60px rgba(99, 102, 241, 0.3);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.2);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  --bg-body-g1: rgba(99, 102, 241, 0.25);
  --bg-body-g2: rgba(14, 165, 233, 0.25);
  --bg-body-g3: rgba(139, 92, 246, 0.25);
  --bg-body-g4: rgba(244, 63, 94, 0.15);
}

/* ==========================================
   Light Theme
   ========================================== */
:root[data-theme="light"] {
  --bg-primary: #f0f2f8;
  --bg-surface: rgba(255, 255, 255, 0.75);
  --bg-card: rgba(255, 255, 255, 0.55);
  --bg-card-hover: rgba(255, 255, 255, 0.75);
  --bg-element: rgba(0, 0, 0, 0.06);
  --bg-input: rgba(0, 0, 0, 0.04);
  --border-card: rgba(0, 0, 0, 0.08);
  --border-card-hover: rgba(0, 0, 0, 0.15);
  --border-element: rgba(0, 0, 0, 0.1);

  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.1);
  --shadow-glow-active: 0 0 60px rgba(99, 102, 241, 0.2);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.06);

  --bg-body-g1: rgba(99, 102, 241, 0.12);
  --bg-body-g2: rgba(14, 165, 233, 0.12);
  --bg-body-g3: rgba(139, 92, 246, 0.12);
  --bg-body-g4: rgba(244, 63, 94, 0.08);
}

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

body {
  font-family: var(--font);
  background-color: var(--bg-primary);
  background-image:
    radial-gradient(at 0% 0%, var(--bg-body-g1) 0px, transparent 50%),
    radial-gradient(at 100% 0%, var(--bg-body-g2) 0px, transparent 50%),
    radial-gradient(at 100% 100%, var(--bg-body-g3) 0px, transparent 50%),
    radial-gradient(at 0% 100%, var(--bg-body-g4) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================
   App Container
   ========================================== */
.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ==========================================
   Header
   ========================================== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header .logo {
  font-size: 28px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-primary);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}
.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-theme {
  background: transparent;
  border: 1px solid var(--border-card);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.btn-theme:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-card-hover);
  color: var(--text-primary);
}
.btn-theme svg { width: 20px; height: 20px; }

/* ==========================================
   BPM Section
   ========================================== */
.bpm-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.bpm-ring {
  position: relative;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  padding: 3px;
  background: var(--gradient-ring);
  box-shadow: var(--shadow-glow);
  transition: box-shadow 0.3s ease;
}
.bpm-ring.pulse {
  box-shadow: var(--shadow-glow-active);
}

.bpm-display {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.bpm-value {
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.bpm-unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}
.tempo-marking {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-style: italic;
}

/* BPM Controls */
.bpm-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 420px;
}
.btn-adj {
  width: 40px;
  height: 36px;
  border: 1px solid var(--border-card);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-adj:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-card-hover);
  color: var(--text-primary);
}
.btn-adj:active { transform: scale(0.92); }

/* ==========================================
   Custom Slider
   ========================================== */
.slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-element);
  outline: none;
  transition: var(--transition);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gradient-primary);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(57, 197, 187, 0.4);
  transition: transform 0.15s ease;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gradient-primary);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 8px rgba(57, 197, 187, 0.4);
}

/* ==========================================
   Beat Indicators
   ========================================== */
.beat-section { display: flex; justify-content: center; }
.beat-indicators {
  display: flex;
  gap: 12px;
  align-items: center;
}
.beat-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-element);
  border: 2px solid var(--border-element);
  transition: all 0.1s ease;
  position: relative;
}
.beat-dot.accent {
  width: 22px;
  height: 22px;
  border-color: rgba(99, 102, 241, 0.3);
}
.beat-dot.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  box-shadow: 0 0 16px rgba(14, 165, 233, 0.6);
  transform: scale(1.2);
}
.beat-dot.accent.active {
  background: var(--primary-400);
  border-color: var(--primary-400);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.7);
  transform: scale(1.3);
}

/* ==========================================
   Action Section (Play + Tap)
   ========================================== */
.action-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.btn-play {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
  transition: all 0.2s ease;
}
.btn-play:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 28px rgba(99, 102, 241, 0.5);
}
.btn-play:active { transform: scale(0.95); }
.btn-play svg { width: 28px; height: 28px; }
.btn-play .icon-play { margin-left: 3px; }

.btn-tap, .tap-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tap-placeholder { visibility: hidden; }
.btn-tap {
  border: 2px solid var(--border-card);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: var(--transition);
}
.btn-tap:hover {
  border-color: var(--primary-500);
  color: var(--text-primary);
  background: rgba(99, 102, 241, 0.1);
}
.btn-tap:active { transform: scale(0.9); }
.tap-bpm {
  font-size: 10px;
  font-weight: 500;
  color: var(--primary-400);
  min-height: 14px;
}

/* ==========================================
   Glass Card
   ========================================== */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-card);
}
.glass-card:hover { 
  border-color: var(--border-card-hover); 
  background: var(--bg-card-hover);
}

/* ==========================================
   Settings Panel
   ========================================== */
.settings-panel { display: flex; flex-direction: column; gap: 18px; }
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.setting-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Button Group */
.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.btn-group button {
  padding: 7px 14px;
  border: 1px solid var(--border-card);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.btn-group button:hover {
  border-color: var(--border-card-hover);
  color: var(--text-primary);
  background: var(--bg-card-hover);
}
.btn-group button.active {
  background: var(--gradient-primary);
  border-color: transparent;
  color: white;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

/* Volume */
.volume-control {
  display: flex;
  align-items: center;
  gap: 10px;
}
.volume-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.volume-val {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* ==========================================
   Timer Panel
   ========================================== */
.timer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.timer-header h2 {
  font-size: 15px;
  font-weight: 600;
}
.timer-mode-toggle {
  display: flex;
  background: var(--bg-element);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.timer-mode-toggle button {
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.timer-mode-toggle button.active {
  background: var(--gradient-primary);
  color: white;
}
.timer-mode-toggle button:hover:not(.active) { color: var(--text-secondary); }

.timer-display {
  font-size: 48px;
  font-weight: 300;
  text-align: center;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  margin-bottom: 16px;
}
.timer-display.warning {
  color: var(--amber-400);
  animation: timerBlink 1s ease-in-out infinite;
}
.timer-display.finished {
  color: var(--rose-500);
  animation: timerBlink 0.5s ease-in-out infinite;
}
@keyframes timerBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Countdown Presets */
.countdown-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.countdown-presets button {
  padding: 6px 14px;
  border: 1px solid var(--border-card);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.countdown-presets button:hover {
  border-color: var(--border-card-hover);
  color: var(--text-primary);
}
.countdown-presets button.active {
  background: var(--gradient-primary);
  border-color: transparent;
  color: white;
}
.custom-time {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.custom-time input {
  width: 60px;
  padding: 5px 8px;
  border: 1px solid var(--border-card);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12px;
  outline: none;
  transition: var(--transition);
}
.custom-time input:focus { border-color: var(--primary-500); }

/* Bar Info */
.bar-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.bar-count-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.bar-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.bar-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary-400);
  font-variant-numeric: tabular-nums;
}
.bar-limit-control {
  display: flex;
  align-items: center;
  gap: 6px;
}
.bar-limit-input {
  width: 56px;
  padding: 5px 8px;
  border: 1px solid var(--border-card);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  text-align: center;
  outline: none;
  transition: var(--transition);
}
.bar-limit-input:focus { border-color: var(--primary-500); }
.bar-limit-input::placeholder { color: var(--text-muted); }

/* ==========================================
   Speed Trainer
   ========================================== */
.trainer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.trainer-header h2 {
  font-size: 15px;
  font-weight: 600;
}

/* Toggle Switch */
.switch {
  position: relative;
  width: 44px;
  height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-element);
  border-radius: 12px;
  cursor: pointer;
  transition: var(--transition);
}
.switch-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-secondary);
  left: 3px;
  top: 3px;
  transition: var(--transition);
}
.switch input:checked + .switch-slider {
  background: var(--gradient-primary);
}
.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
  background: white;
}

.trainer-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.trainer-controls.enabled {
  opacity: 1;
  pointer-events: auto;
}
.trainer-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.trainer-input {
  width: 52px;
  padding: 6px 8px;
  border: 1px solid var(--border-card);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  text-align: center;
  outline: none;
  transition: var(--transition);
}
.trainer-input:focus { border-color: var(--primary-500); }

/* ==========================================
   Footer
   ========================================== */
.footer {
  text-align: center;
  padding-top: 8px;
}
.shortcuts {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  align-items: center;
}
kbd {
  display: inline-block;
  padding: 2px 7px;
  background: var(--bg-element);
  border: 1px solid var(--border-card);
  border-radius: 4px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 2px;
}

/* ==========================================
   Animations
   ========================================== */
@keyframes pulseRing {
  0% { box-shadow: var(--shadow-glow); }
  50% { box-shadow: var(--shadow-glow-active); }
  100% { box-shadow: var(--shadow-glow); }
}
.bpm-ring.playing {
  animation: pulseRing 0.6s ease-in-out;
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 480px) {
  .app { padding: 16px 14px 32px; gap: 22px; }
  .bpm-ring { width: 170px; height: 170px; }
  .bpm-value { font-size: 46px; }
  .bpm-controls { gap: 6px; }
  .btn-adj { width: 34px; height: 32px; font-size: 12px; }
  .btn-group button { padding: 6px 10px; font-size: 12px; }
  .timer-display { font-size: 40px; }
  .bar-info { flex-direction: column; align-items: flex-start; gap: 10px; }
  .action-section { gap: 14px; }
  .btn-play { width: 64px; height: 64px; }
  .btn-tap, .tap-placeholder { width: 54px; height: 54px; }
}

/* Panels Grid (default: single column) */
.panels-grid {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Number input arrows */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 0.5;
}

/* ==========================================
   Desktop Layout (>= 900px)
   ========================================== */
@media (min-width: 900px) {
  .app {
    max-width: 920px;
    padding: 36px 32px 48px;
  }

  .bpm-ring {
    width: 240px;
    height: 240px;
  }
  .bpm-value { font-size: 64px; }
  .bpm-controls { max-width: 480px; }

  .beat-indicators { gap: 16px; }
  .beat-dot { width: 20px; height: 20px; }
  .beat-dot.accent { width: 26px; height: 26px; }

  .btn-play { width: 80px; height: 80px; }
  .btn-play svg { width: 32px; height: 32px; }
  .btn-tap, .tap-placeholder { width: 70px; height: 70px; }
  .btn-tap { font-size: 13px; }

  .panels-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }

  .settings-panel {
    grid-column: 1;
    grid-row: 1;
  }
  .timer-panel {
    grid-column: 2;
    grid-row: 1;
  }
  .trainer-panel {
    grid-column: 1 / -1;
  }
}

/* Extra wide screens */
@media (min-width: 1200px) {
  .app {
    max-width: 1060px;
  }
  .bpm-ring {
    width: 260px;
    height: 260px;
  }
  .bpm-value { font-size: 72px; }
}
