:root {
  --bg-deep: #090d16;
  --bg-card: #131b2e;
  --bg-card-elevated: #1c2742;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Phase Colors */
  --sec-a-primary: #10b981;
  --sec-a-glow: rgba(16, 185, 129, 0.28);
  --sec-b-primary: #06b6d4;
  --sec-b-glow: rgba(6, 182, 212, 0.28);
  --prep-primary: #f59e0b;
  --prep-glow: rgba(245, 158, 11, 0.30);
  --warn-color: #f97316;

  /* Music Colors */
  --workout-accent: #f97316;
  --workout-glow: rgba(249, 115, 22, 0.25);
  --cooldown-accent: #8b5cf6;
  --cooldown-glow: rgba(139, 92, 246, 0.25);

  --danger: #ef4444;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.app-shell {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
  gap: 8px;
}

/* 1. HEADER BAR */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 2px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  font-size: 0.88rem;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--sec-a-primary);
  box-shadow: 0 0 10px var(--sec-a-primary);
  transition: background 0.3s ease;
}

.top-Controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sound-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 6px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sound-pill:active {
  transform: scale(0.95);
}

.sound-pill .gain-val {
  color: var(--sec-a-primary);
  font-family: 'JetBrains Mono', monospace;
}

/* 2. MAIN TIMER DISPLAY (RING) */
.timer-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 185px;
  background: radial-gradient(circle at center, var(--active-glow, var(--sec-a-glow)) 0%, transparent 70%);
  border-radius: var(--radius-lg);
  transition: background 0.35s ease;
}

.ring-container {
  position: relative;
  width: min(50vw, 200px);
  height: min(50vw, 200px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.07);
  stroke-width: 10;
}

.ring-progress {
  fill: none;
  stroke: var(--active-color, var(--sec-a-primary));
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 615.75;
  stroke-dashoffset: 0;
  transition: stroke 0.25s ease;
}

.timer-readout {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.phase-badge {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--active-color, var(--sec-a-primary));
  margin-bottom: 2px;
  transition: color 0.25s ease, transform 0.2s ease;
}

.digits-main {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(3.3rem, 13vw, 4.4rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  transition: color 0.15s ease, transform 0.15s ease;
}

.digits-main.countdown-warn {
  color: #fbbf24;
  text-shadow: 0 0 24px rgba(251, 191, 36, 0.65);
  animation: warnScale 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes warnScale {
  0% { transform: scale(1.24); }
  100% { transform: scale(1); }
}

.cycle-sub {
  margin-top: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 3. SPLIT CONFIGURATOR CARD */
.split-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  flex-shrink: 0;
  transition: opacity 0.25s ease;
}

.split-card.locked {
  opacity: 0.48;
  pointer-events: none;
}

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

.split-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
}

.split-pill .val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.92rem;
  padding: 2px 7px;
  border-radius: 6px;
}

.split-pill.sec-a .val {
  background: rgba(16, 185, 129, 0.16);
  color: var(--sec-a-primary);
}

.split-pill.sec-b .val {
  background: rgba(6, 182, 212, 0.16);
  color: var(--sec-b-primary);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card-elevated);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-btn:active {
  transform: scale(0.93);
}

.range-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

input[type="range"]#splitSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--sec-a-primary) 0%,
    var(--sec-a-primary) var(--split-pct, 66.6%),
    var(--sec-b-primary) var(--split-pct, 66.6%),
    var(--sec-b-primary) 100%
  );
  outline: none;
}

input[type="range"]#splitSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--bg-deep);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

input[type="range"]#splitSlider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--bg-deep);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.presets-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
}

.preset-chip {
  flex: 1;
  padding: 5px 0;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  text-align: center;
}

.preset-chip.active {
  background: rgba(16, 185, 129, 0.16);
  border-color: var(--sec-a-primary);
  color: var(--text-primary);
}

/* 4. TIMER ACTION BUTTONS */
.controls-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  flex-shrink: 0;
}

.btn-main {
  min-height: 52px;
  border-radius: var(--radius-md);
  border: none;
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #06130e;
  background: var(--sec-a-primary);
  box-shadow: 0 6px 20px var(--sec-a-glow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.12s ease, background 0.2s ease;
}

.btn-main:active {
  transform: scale(0.97);
}

.btn-main.running {
  background: var(--danger);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.3);
}

.btn-reset {
  min-width: 52px;
  min-height: 52px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-reset:active {
  transform: scale(0.95);
}

/* 5. MUSIC PLAYER SECTION */
.music-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  flex-shrink: 0;
}

.music-btns-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.music-btn {
  min-height: 58px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card-elevated);
  color: var(--text-primary);
  padding: 8px 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}

.music-btn:active {
  transform: scale(0.97);
}

.music-btn-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.music-icon {
  font-size: 1.05rem;
}

.music-title {
  font-size: 0.82rem;
  font-weight: 800;
  margin-top: 3px;
}

.music-sub {
  font-size: 0.68rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.music-btn.workout.active {
  border-color: var(--workout-accent);
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.22), rgba(249, 115, 22, 0.05));
  box-shadow: 0 4px 16px var(--workout-glow);
}

.music-btn.cooldown.active {
  border-color: var(--cooldown-accent);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.22), rgba(139, 92, 246, 0.05));
  box-shadow: 0 4px 16px var(--cooldown-glow);
}

.eq-bars {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.music-btn.active .eq-bars {
  display: inline-flex;
}

.eq-bar {
  width: 3px;
  background: currentColor;
  border-radius: 2px;
  animation: eqBounce 0.8s infinite ease-in-out;
}

.eq-bar:nth-child(1) { height: 6px; animation-delay: 0s; }
.eq-bar:nth-child(2) { height: 12px; animation-delay: 0.2s; }
.eq-bar:nth-child(3) { height: 8px; animation-delay: 0.4s; }

@keyframes eqBounce {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

.now-playing-bar {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.73rem;
  color: var(--text-secondary);
}

.track-info {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
}

.track-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.track-dot.playing {
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
}

.track-name {
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.music-Quick-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.vol-control {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.04);
  padding: 3px 7px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
}

.vol-control span {
  font-size: 0.68rem;
  font-weight: 700;
}

input[type="range"].vol-slider {
  width: 54px;
  height: 5px;
  accent-color: var(--text-primary);
  cursor: pointer;
}

.next-track-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.next-track-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

@keyframes pulseFlash {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.flash-transition {
  animation: pulseFlash 0.38s ease-out;
}

/* Dynamic Phase Themes */
body[data-phase="prep"] {
  --active-color: var(--prep-primary);
  --active-glow: var(--prep-glow);
}

body[data-phase="sectionA"] {
  --active-color: var(--sec-a-primary);
  --active-glow: var(--sec-a-glow);
}

body[data-phase="sectionB"] {
  --active-color: var(--sec-b-primary);
  --active-glow: var(--sec-b-glow);
}
