/* =========================================================
   PULSE Workout Timer — Mobile-First Graphical PWA Design
   ========================================================= */

:root {
  --bg: #061124;
  --bg-elevated: rgba(10, 26, 52, 0.84);
  --bg-surface: rgba(43, 211, 232, 0.055);
  --bg-surface-hover: rgba(43, 211, 232, 0.11);
  --border: rgba(56, 189, 248, 0.13);
  --border-strong: rgba(56, 189, 248, 0.24);
  --text: #f8fafc;
  --text-muted: #93b4d8;
  --text-dim: #6484a8;

  --c-marines-cyan: #2bd3e8;
  --c-marines-blue: #2b8ae8;
  --c-work: #ff4d4f;
  --c-work-2: #ff7a33;
  --c-rest: #06d6a0;
  --c-rest-2: #2bd3e8;
  --c-prep: #f59e0b;
  --c-setrest: #38bdf8;
  --c-complete: #34d399;

  --phase-color: var(--c-prep);
  --phase-glow: rgba(245, 158, 11, 0.28);

  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-pill: 999px;
  --shadow-card: 0 20px 50px rgba(0, 0, 0, 0.44);
  --font-sans: "SF Pro Display", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --nav-height: 70px;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elevated: rgba(255, 255, 255, 0.9);
  --bg-surface: rgba(15, 23, 42, 0.045);
  --bg-surface-hover: rgba(15, 23, 42, 0.085);
  --border: rgba(15, 23, 42, 0.085);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --shadow-card: 0 14px 36px rgba(15, 23, 42, 0.08);
}

[data-phase="prep"] {
  --phase-color: var(--c-prep);
  --phase-glow: rgba(245, 158, 11, 0.30);
}
[data-phase="work"] {
  --phase-color: var(--c-work);
  --phase-glow: rgba(255, 77, 79, 0.34);
}
[data-phase="rest"] {
  --phase-color: var(--c-rest);
  --phase-glow: rgba(6, 214, 160, 0.28);
}
[data-phase="setrest"] {
  --phase-color: var(--c-setrest);
  --phase-glow: rgba(96, 165, 250, 0.30);
}
[data-phase="complete"] {
  --phase-color: var(--c-complete);
  --phase-glow: rgba(52, 211, 153, 0.36);
}

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

html, body {
  min-height: 100%;
  max-width: 100%;
  overflow-x: clip;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  transition: background-color 0.35s ease, color 0.35s ease;
}

[hidden] {
  display: none !important;
}

.ambient-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(640px circle at 32% 36%, var(--phase-glow), transparent 65%),
    radial-gradient(560px circle at 84% 16%, rgba(43, 211, 232, 0.15), transparent 60%);
  transition: background 0.55s ease;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 22px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(43, 211, 232, 0.28));
}

.brand-mark svg,
.brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

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

.brand-title {
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1.1;
}

.mobile-br {
  display: none;
}

.brand-sub {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--text-muted);
  margin-top: 2px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--c-rest);
  background: rgba(6, 214, 160, 0.14);
  border: 1px solid rgba(6, 214, 160, 0.34);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-rest);
  box-shadow: 0 0 8px var(--c-rest);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.icon-pill,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: all 0.18s ease;
  white-space: nowrap;
}

.icon-btn {
  width: 38px;
  padding: 0;
}

.icon-pill svg,
.icon-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.icon-pill:hover,
.icon-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.icon-pill.active {
  color: var(--text);
  border-color: color-mix(in srgb, var(--phase-color) 55%, transparent);
  background: color-mix(in srgb, var(--phase-color) 16%, var(--bg-elevated));
}

.install-banner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255, 122, 51, 0.16), rgba(255, 77, 79, 0.14));
  border: 1px solid rgba(255, 122, 51, 0.38);
}

.install-banner-text {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  min-width: 0;
}

.install-banner-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.install-banner-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  border: none;
  background: linear-gradient(135deg, var(--c-work-2), var(--c-work));
  color: #ffffff;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.install-banner-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.76rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

[data-gym-mode="true"] .install-banner {
  display: none !important;
}

#btn-sound .icon-off { display: none; }
#btn-sound:not(.active) .icon-on { display: none; }
#btn-sound:not(.active) .icon-off { display: block; }

[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }

/* Mode Switcher */
.mode-switcher {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 6px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.mode-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 42px;
  padding: 0 10px;
  border-radius: 13px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-tab:hover {
  color: var(--text);
  background: var(--bg-surface);
}

.mode-tab.active {
  color: #ffffff;
  background: linear-gradient(135deg, var(--phase-color), color-mix(in srgb, var(--phase-color) 72%, #000));
  box-shadow: 0 8px 20px var(--phase-glow);
}

.mode-tag {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.14);
}

.mode-tab:not(.active) .mode-tag {
  background: var(--bg-surface-hover);
  color: var(--text-muted);
}

/* Main Layout */
.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-card);
}

/* Timer Stage */
.timer-stage {
  padding: 20px 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.stage-meta-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.active-preset-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 0.84rem;
  font-weight: 700;
}

.chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--phase-color);
  box-shadow: 0 0 10px var(--phase-color);
}

.round-set-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-pill {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-pill strong {
  font-size: 0.92rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Active Exercise Spotlight */
.exercise-spotlight {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, color-mix(in srgb, var(--phase-color) 14%, var(--bg-surface)), var(--bg-surface));
  border: 1px solid color-mix(in srgb, var(--phase-color) 32%, var(--border));
  transition: all 0.3s ease;
}

.exercise-spotlight-icon {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--phase-color);
  background: color-mix(in srgb, var(--phase-color) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--phase-color) 35%, transparent);
  flex-shrink: 0;
  padding: 6px;
}

.exercise-spotlight-icon svg {
  width: 100%;
  height: 100%;
}

.exercise-spotlight-body {
  flex: 1;
  min-width: 0;
}

.exercise-spotlight-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--phase-color);
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.exercise-spotlight-name {
  font-size: 1.24rem;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exercise-next-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--text-muted);
  flex-shrink: 0;
  max-width: 165px;
}

.next-chip-label {
  font-weight: 700;
  color: var(--text-dim);
}

.next-chip-icon {
  width: 22px;
  height: 22px;
  color: var(--text);
  flex-shrink: 0;
}

.next-chip-icon svg {
  width: 100%;
  height: 100%;
}

.next-chip-name {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chronograph Dial */
.dial-wrapper {
  position: relative;
  width: min(100%, 348px);
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}

.dial-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dial-ticks line {
  stroke: var(--text-dim);
  stroke-opacity: 0.25;
  stroke-linecap: round;
}

.dial-ticks line.major {
  stroke-opacity: 0.5;
}

.total-ring-track {
  fill: none;
  stroke: var(--bg-surface);
  stroke-width: 5;
}

.total-ring-progress {
  fill: none;
  stroke: var(--text-muted);
  stroke-opacity: 0.55;
  stroke-width: 5;
  stroke-linecap: round;
}

.phase-ring-track {
  fill: none;
  stroke: var(--bg-surface);
  stroke-width: 15;
}

.phase-ring-progress {
  fill: none;
  stroke: url(#ring-grad-work);
  stroke-width: 15;
  stroke-linecap: round;
  transition: stroke 0.35s ease;
}

[data-phase="work"] .phase-ring-progress { stroke: url(#ring-grad-work); }
[data-phase="rest"] .phase-ring-progress { stroke: url(#ring-grad-rest); }
[data-phase="prep"] .phase-ring-progress { stroke: url(#ring-grad-prep); }
[data-phase="setrest"] .phase-ring-progress { stroke: url(#ring-grad-setrest); }
[data-phase="complete"] .phase-ring-progress { stroke: url(#ring-grad-complete); }

.ring-head-dot {
  fill: #ffffff;
  filter: drop-shadow(0 0 8px var(--phase-color));
  transition: opacity 0.2s ease;
}

.dial-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  pointer-events: none;
}

.phase-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--phase-color);
  background: color-mix(in srgb, var(--phase-color) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--phase-color) 42%, transparent);
  margin-bottom: 6px;
}

.time-display {
  font-size: clamp(3.3rem, 7vw, 4.9rem);
  font-weight: 900;
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 8px 30px color-mix(in srgb, var(--phase-color) 24%, transparent);
}

.time-display.is-stopwatch {
  font-size: clamp(2.8rem, 6vw, 4.1rem);
}

.time-display.pulse-tick {
  animation: pulseTick 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes pulseTick {
  0% {
    transform: scale(1.08);
    color: var(--phase-color);
  }
  100% {
    transform: scale(1);
    color: var(--text);
  }
}

.next-up {
  margin-top: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Visual Interval Timeline */
.timeline-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.timeline-header strong {
  color: var(--text);
  font-weight: 800;
}

.timeline-bar {
  display: flex;
  align-items: stretch;
  gap: 3px;
  width: 100%;
  height: 18px;
  padding: 3px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

.timeline-seg {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: rgba(148, 163, 184, 0.16);
  transition: transform 0.15s ease;
  min-width: 4px;
}

.timeline-seg:hover {
  transform: scaleY(1.22);
}

.timeline-seg .seg-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  border-radius: 6px;
}

.timeline-seg[data-type="prep"] { background: rgba(245, 158, 11, 0.2); }
.timeline-seg[data-type="prep"] .seg-fill { background: var(--c-prep); }

.timeline-seg[data-type="work"] { background: rgba(255, 77, 79, 0.22); }
.timeline-seg[data-type="work"] .seg-fill { background: linear-gradient(90deg, var(--c-work-2), var(--c-work)); }

.timeline-seg[data-type="rest"] { background: rgba(6, 214, 160, 0.2); }
.timeline-seg[data-type="rest"] .seg-fill { background: linear-gradient(90deg, var(--c-rest-2), var(--c-rest)); }

.timeline-seg[data-type="setrest"] { background: rgba(96, 165, 250, 0.22); }
.timeline-seg[data-type="setrest"] .seg-fill { background: var(--c-setrest); }

.timeline-seg.active {
  box-shadow: 0 0 0 1.5px var(--text);
}

/* AMRAP Round Counter */
.amrap-counter-section {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

.amrap-stats {
  display: flex;
  flex-direction: column;
}

.amrap-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
}

.amrap-value {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--phase-color);
}

.amrap-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.amrap-minus-btn {
  height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.amrap-plus-btn {
  height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, var(--c-rest-2), var(--c-rest));
  color: #06281e;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(6, 214, 160, 0.28);
  transition: transform 0.12s ease;
}

.amrap-plus-btn:active {
  transform: scale(0.96);
}

/* Stopwatch Laps */
.stopwatch-laps-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.laps-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.laps-list {
  max-height: 132px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

.laps-empty {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 12px 6px;
}

.lap-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 11px;
  border-radius: 10px;
  background: var(--bg-elevated);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

.lap-item strong {
  color: var(--phase-color);
}

/* Controls */
.controls-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 2px;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.2s ease;
  user-select: none;
}

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

.ctrl-secondary {
  height: 54px;
  padding: 0 16px;
  border-radius: 16px;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.88rem;
}

.ctrl-secondary svg {
  width: 18px;
  height: 18px;
}

.ctrl-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.ctrl-primary {
  height: 62px;
  min-width: 184px;
  padding: 0 28px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, var(--phase-color), color-mix(in srgb, var(--phase-color) 72%, #000));
  color: #ffffff;
  font-size: 1.08rem;
  letter-spacing: 0.04em;
  box-shadow: 0 12px 30px var(--phase-glow);
}

.ctrl-primary svg {
  width: 21px;
  height: 21px;
}

.ctrl-primary .icon-pause { display: none; }
.ctrl-primary.is-running .icon-play { display: none; }
.ctrl-primary.is-running .icon-pause { display: block; }

.shortcuts-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.72rem;
  color: var(--text-dim);
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  margin-right: 3px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 700;
}

/* Right Control Panel */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.desktop-panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.panel-tab {
  height: 38px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
}

.panel-tab.active {
  background: var(--bg-surface-hover);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.side-view {
  display: none;
}

.side-view.active {
  display: flex;
}

.panel-section {
  padding: 18px 20px;
  flex-direction: column;
  gap: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-head h2 {
  font-size: 1rem;
  font-weight: 800;
}

.section-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.section-badge,
.total-badge {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.total-badge strong {
  color: var(--text);
}

.mini-action-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, var(--phase-color) 48%, transparent);
  background: color-mix(in srgb, var(--phase-color) 14%, transparent);
  color: var(--text);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.exercise-editor-list,
.laps-list {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.28) transparent;
}

.exercise-editor-list::-webkit-scrollbar,
.laps-list::-webkit-scrollbar {
  width: 6px;
}

.exercise-editor-list::-webkit-scrollbar-track,
.laps-list::-webkit-scrollbar-track {
  background: transparent;
}

.exercise-editor-list::-webkit-scrollbar-thumb,
.laps-list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.28);
  border-radius: 999px;
}

/* Exercise Editor List */
.exercise-editor-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 510px;
  overflow-y: auto;
  padding-right: 4px;
}

.exercise-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.exercise-row.is-active {
  border-color: color-mix(in srgb, var(--phase-color) 65%, transparent);
  background: color-mix(in srgb, var(--phase-color) 12%, var(--bg-surface));
}

.ex-round-num {
  width: 30px;
  text-align: center;
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.ex-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--phase-color);
  padding: 5px;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: transform 0.14s ease, border-color 0.18s ease;
}

.ex-icon-btn:hover {
  border-color: var(--phase-color);
  transform: scale(1.05);
}

.ex-icon-btn svg {
  width: 100%;
  height: 100%;
}

.ex-name-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 11px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  outline: none;
}

.ex-name-input:focus {
  border-color: var(--phase-color);
}

/* Presets Grid */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.preset-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 12px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s ease;
}

.preset-card:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.preset-card.active {
  border-color: color-mix(in srgb, var(--phase-color) 65%, transparent);
  background: color-mix(in srgb, var(--phase-color) 14%, var(--bg-surface));
}

.preset-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.preset-name {
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.25;
}

.preset-duration {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--phase-color);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.preset-meta {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.preset-icons-preview {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.preset-mini-icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  padding: 2px;
  display: grid;
  place-items: center;
}

.preset-mini-icon svg {
  width: 100%;
  height: 100%;
}

.preset-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(239, 68, 68, 0.22);
  color: #f87171;
  font-size: 0.85rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

/* Settings & Steppers */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

.setting-row.is-dimmed {
  opacity: 0.45;
}

.setting-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.setting-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}

.setting-row[data-accent="prep"] .setting-dot { background: var(--c-prep); }
.setting-row[data-accent="work"] .setting-dot { background: var(--c-work); }
.setting-row[data-accent="rest"] .setting-dot { background: var(--c-rest); }
.setting-row[data-accent="setrest"] .setting-dot { background: var(--c-setrest); }

.setting-title {
  font-size: 0.86rem;
  font-weight: 700;
}

.setting-desc {
  font-size: 0.71rem;
  color: var(--text-muted);
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.step-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  user-select: none;
}

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

.step-value {
  min-width: 66px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.ratio-summary {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ratio-bar {
  display: flex;
  height: 8px;
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--bg-surface);
  gap: 2px;
}

.ratio-seg.work {
  background: linear-gradient(90deg, var(--c-work-2), var(--c-work));
}

.ratio-seg.rest {
  background: linear-gradient(90deg, var(--c-rest-2), var(--c-rest));
}

.ratio-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ratio-legend strong { color: var(--text); }
.ratio-legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}
.ratio-legend .dot.work { background: var(--c-work); }
.ratio-legend .dot.rest { background: var(--c-rest); }

.save-preset-form {
  display: flex;
  gap: 8px;
}

.save-preset-form input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
  outline: none;
}

.save-preset-form input:focus {
  border-color: var(--phase-color);
}

.save-btn {
  height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  border: none;
  background: var(--phase-color);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
}

/* Modal Icon Picker */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 8, 15, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.modal-sheet {
  width: 100%;
  max-width: 540px;
  max-height: 78vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.modal-header h3 {
  font-size: 1rem;
  font-weight: 800;
}

.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
}

.picker-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.16s ease;
}

.picker-item:hover,
.picker-item.selected {
  border-color: var(--phase-color);
  background: color-mix(in srgb, var(--phase-color) 16%, var(--bg-surface));
}

.picker-svg {
  width: 44px;
  height: 44px;
  color: var(--phase-color);
}

.picker-svg svg {
  width: 100%;
  height: 100%;
}

.picker-name {
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
}

.picker-cat {
  font-size: 0.66rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 70;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.94);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}

/* Mobile Bottom Nav (Hidden on Desktop) */
.mobile-bottom-nav {
  display: none;
}

/* Fullscreen Focus Mode & Gym / Court Display Mode */
.stage-preset-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.share-chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, var(--c-marines-cyan) 42%, var(--border));
  background: color-mix(in srgb, var(--c-marines-cyan) 12%, var(--bg-surface));
  color: var(--text);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.share-chip-btn svg {
  width: 15px;
  height: 15px;
  color: var(--c-marines-cyan);
  flex-shrink: 0;
}

.share-chip-btn:hover {
  border-color: var(--c-marines-cyan);
  background: color-mix(in srgb, var(--c-marines-cyan) 22%, var(--bg-surface));
}

.share-modal-sheet {
  max-width: 440px;
}

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

.share-menu-info {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}

.share-menu-info strong {
  font-size: 1rem;
  font-weight: 800;
}

.share-menu-info span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.qr-frame {
  width: min(230px, 64vw);
  aspect-ratio: 1 / 1;
  padding: 10px;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
}

.qr-frame svg {
  width: 100%;
  height: 100%;
  display: block;
}

.share-caption {
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
}

.share-actions-grid {
  width: 100%;
  display: flex;
  gap: 8px;
}

.share-action-btn {
  flex: 1;
  height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.share-action-btn:hover {
  background: var(--bg-surface-hover);
}

.share-action-btn.primary {
  border: none;
  background: linear-gradient(135deg, var(--c-marines-cyan), var(--c-marines-blue));
  color: #05162d;
  font-weight: 800;
}

.backup-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
}

.backup-divider::before,
.backup-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.gym-exit-btn {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: 16px;
  z-index: 45;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: rgba(6, 17, 36, 0.86);
  color: #f8fafc;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(12px);
}

[data-gym-mode="true"] .top-bar,
[data-gym-mode="true"] .mode-switcher,
[data-gym-mode="true"] .control-panel,
[data-gym-mode="true"] .mobile-bottom-nav,
[data-gym-mode="true"] .shortcuts-hint,
[data-gym-mode="true"] .share-chip-btn {
  display: none !important;
}

[data-gym-mode="true"] .app-shell {
  max-width: none;
  width: 100%;
  min-height: 100dvh;
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  justify-content: center;
  overflow-x: hidden;
}

[data-gym-mode="true"] .main-grid {
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  flex: 1;
  align-items: center;
}

[data-gym-mode="true"] .timer-stage {
  display: flex !important;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: calc(100dvh - 36px);
  justify-content: space-between;
  padding: calc(66px + env(safe-area-inset-top)) 14px 16px;
  background: transparent;
  border: none;
  box-shadow: none;
}

[data-gym-mode="true"] .exercise-spotlight {
  width: 100%;
  max-width: 780px;
  padding: 12px 16px;
}

[data-gym-mode="true"] .exercise-spotlight-icon {
  width: clamp(52px, 12vw, 76px);
  height: clamp(52px, 12vw, 76px);
}

[data-gym-mode="true"] .exercise-spotlight-name {
  font-size: clamp(1.25rem, 4.5vw, 2.8rem);
}

[data-gym-mode="true"] .dial-wrapper {
  width: min(48vh, 76vw, 480px);
}

[data-gym-mode="true"] .time-display {
  font-size: clamp(3.8rem, 13vw, 8.2rem);
}

[data-gym-mode="true"] .phase-badge {
  font-size: clamp(1rem, 2.2vw, 1.4rem);
  padding: 8px 20px;
}

[data-gym-mode="true"] .timeline-section {
  max-width: 920px;
}

:fullscreen .control-panel,
:fullscreen .mobile-bottom-nav {
  display: none !important;
}

:fullscreen .main-grid {
  grid-template-columns: 1fr;
}

:fullscreen .dial-wrapper {
  width: min(64vh, 480px);
}

/* Responsive: Mobile-First App Shell (<= 980px) */
@media (max-width: 980px) {
  .app-shell {
    padding: calc(10px + env(safe-area-inset-top)) 14px calc(var(--nav-height) + 22px + env(safe-area-inset-bottom));
    gap: 12px;
  }

  .main-grid {
    grid-template-columns: 1fr;
  }

  .desktop-panel-tabs {
    display: none;
  }

  .shortcuts-hint {
    display: none;
  }

  /* Show only the active mobile tab panel */
  [data-mobile-tab="timer"] .control-panel { display: none; }
  [data-mobile-tab="exercises"] .timer-stage { display: none; }
  [data-mobile-tab="presets"] .timer-stage { display: none; }
  [data-mobile-tab="settings"] .timer-stage { display: none; }

  [data-mobile-tab="exercises"] .side-view,
  [data-mobile-tab="presets"] .side-view,
  [data-mobile-tab="settings"] .side-view {
    display: none;
  }

  [data-mobile-tab="exercises"] .side-view[data-side-view="exercises"],
  [data-mobile-tab="presets"] .side-view[data-side-view="presets"],
  [data-mobile-tab="settings"] .side-view[data-side-view="settings"] {
    display: flex;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100vw;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-strong);
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 4px;
    border: none;
    border-radius: 14px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.16s ease;
  }

  .mobile-nav-btn svg {
    width: 22px;
    height: 22px;
  }

  .mobile-nav-btn.active {
    color: var(--phase-color);
    background: color-mix(in srgb, var(--phase-color) 12%, transparent);
  }

  .mode-tab {
    flex-direction: row;
    height: 36px;
    padding: 0 4px;
    gap: 4px;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .mode-tag {
    display: none;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    padding: calc(8px + env(safe-area-inset-top)) 10px calc(var(--nav-height) + 12px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  .top-bar {
    width: 100%;
    max-width: 100%;
    flex-wrap: nowrap;
    gap: 6px;
    margin-bottom: 4px;
  }

  .brand {
    gap: 6px;
    flex-shrink: 0;
    min-width: 0;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-title {
    font-size: 0.64rem;
    line-height: 1.05;
    letter-spacing: 0.03em;
    white-space: normal;
    color: var(--c-marines-cyan);
  }

  .mobile-br {
    display: inline;
  }

  .brand-sub {
    display: block;
    font-size: 0.54rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    line-height: 1.1;
    margin-top: 2px;
    color: var(--text-muted);
  }

  .top-actions {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 4px;
    justify-content: flex-end;
  }

  .top-actions::-webkit-scrollbar {
    display: none;
  }

  .icon-pill,
  .icon-btn {
    padding: 0;
    width: 30px;
    height: 30px;
    font-size: 0.72rem;
    flex-shrink: 0;
  }

  .icon-pill svg,
  .icon-btn svg {
    width: 15px;
    height: 15px;
  }

  .icon-pill span {
    display: none;
  }

  .install-banner {
    padding: 6px 10px;
    gap: 8px;
  }

  .install-banner-text {
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mode-switcher {
    padding: 4px;
    gap: 4px;
    border-radius: 14px;
  }

  .mode-tab {
    height: 34px;
    font-size: 0.69rem;
    letter-spacing: -0.02em;
    border-radius: 10px;
  }

  .timer-stage {
    padding: 12px 10px 14px;
    gap: 10px;
    border-radius: 22px;
  }

  .stage-meta-top {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .stage-preset-group {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 5px;
  }

  .active-preset-chip {
    min-width: 0;
    padding: 5px 9px;
    font-size: 0.76rem;
    gap: 6px;
  }

  #active-preset-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .share-chip-btn {
    height: 28px;
    padding: 0 7px;
    font-size: 0.7rem;
    flex-shrink: 0;
  }

  .share-chip-btn span {
    display: none;
  }

  .round-set-badges {
    flex-shrink: 0;
  }

  .stat-pill {
    padding: 4px 9px;
    gap: 5px;
  }

  .stat-pill strong {
    font-size: 0.82rem;
  }

  .exercise-spotlight {
    padding: 8px 11px;
    gap: 10px;
    border-radius: 14px;
  }

  .exercise-spotlight-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }

  .exercise-spotlight-name {
    font-size: 0.98rem;
  }

  .exercise-next-chip {
    display: none;
  }

  .dial-wrapper {
    width: min(58vw, 228px);
  }

  .phase-badge {
    padding: 4px 11px;
    font-size: 0.76rem;
    margin-bottom: 3px;
  }

  .time-display {
    font-size: 2.9rem;
  }

  .time-display.is-stopwatch {
    font-size: 2.35rem;
  }

  .next-up {
    margin-top: 5px;
    font-size: 0.68rem;
    max-width: 72%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .timeline-header {
    font-size: 0.74rem;
  }

  .timeline-bar {
    height: 14px;
  }

  .controls-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
  }

  .ctrl-primary {
    grid-column: 1 / -1;
    order: -1;
    min-width: 0;
    width: 100%;
    height: 50px;
    font-size: 1rem;
  }

  .ctrl-secondary {
    height: 44px;
    padding: 0 8px;
    font-size: 0.78rem;
    border-radius: 14px;
  }

  .preset-grid {
    grid-template-columns: 1fr;
  }

  .amrap-counter-section {
    flex-direction: row;
    align-items: center;
    padding: 10px 12px;
  }

  .amrap-value {
    font-size: 1.6rem;
  }

  .amrap-plus-btn,
  .amrap-minus-btn {
    height: 42px;
    font-size: 0.84rem;
  }
}
