/* ============================================
   HIIT Pro Timer - Premium Dark Theme
   Mobile-first responsive design
   ============================================ */

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #2a2a2a;
  --accent-neon: #00ff88;
  --accent-blue: #00aaff;
  --accent-red: #ff3366;
  --text-primary: #ffffff;
  --text-secondary: #aaaaaa;
  --border-radius: 12px;
  --spacing-xs: 8px;
  --spacing-sm: 12px;
  --spacing-md: 20px;
  --spacing-lg: 32px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Hamburger Menu Button */
.hamburger-btn {
  position: fixed;
  top: var(--spacing-sm);
  right: var(--spacing-sm);
  z-index: 200;
  width: 44px;
  height: 44px;
  background: var(--bg-secondary);
  border: 2px solid var(--bg-tertiary);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 0;
  transition: background 0.2s ease;
}

.hamburger-btn:hover {
  background: var(--bg-tertiary);
}

.hamburger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* Hamburger icon animates to X when menu is open */
.hamburger-btn.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger-btn.open span:nth-child(2) {
  opacity: 0;
}

.hamburger-btn.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Menu Overlay */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 149;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.menu-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Slide-in Menu */
.slide-menu {
  position: fixed;
  top: 0;
  right: 0;
  width: 260px;
  height: 100%;
  background: var(--bg-secondary);
  border-left: 2px solid var(--bg-tertiary);
  z-index: 150;
  padding: 72px var(--spacing-md) var(--spacing-md);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.slide-menu.open {
  transform: translateX(0);
}

/* Menu Items */
.menu-item {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  background: none;
  border: none;
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.menu-item:hover {
  background: var(--bg-tertiary);
  color: var(--accent-neon);
}

.menu-item:active {
  transform: scale(0.98);
}

/* Back Button in sub-views */
.back-btn {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  margin-bottom: var(--spacing-md);
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--border-radius);
  color: var(--accent-neon);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.back-btn:hover {
  background: #3a3a3a;
}

.back-btn:active {
  transform: scale(0.96);
}

/* Views */
.view {
  display: none;
  padding: var(--spacing-md);
  flex: 1;
}

.view.active {
  display: block;
}

/* Timer Display */
.timer-display {
  text-align: center;
  padding: var(--spacing-lg) 0;
  margin-bottom: var(--spacing-lg);
}

.timer-phase {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: var(--spacing-sm);
}

.timer-phase.work {
  color: var(--accent-neon);
  text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

.timer-phase.rest {
  color: var(--accent-blue);
  text-shadow: 0 0 20px rgba(0, 170, 255, 0.5);
}

.timer-digits {
  font-size: 52cqw;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  text-align: center;
  white-space: nowrap;
}

/* Shrink digits when 2 or 3 characters to stay inside ring */
.timer-digits.two-digits {
  font-size: 52cqw;
}

.timer-digits.three-digits {
  font-size: 52cqw;
}

/* Circular Progress Ring */
.timer-ring-container {
  container-type: inline-size;
  position: relative;
  width: min(60vw, 60vh);
  aspect-ratio: 1;
  margin: 0 auto var(--spacing-md);
}

.timer-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: var(--bg-tertiary);
  stroke-width: 10;
}

.timer-ring-progress {
  fill: none;
  stroke: var(--accent-neon);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 879.65; /* 2 * PI * 140 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.4s ease, stroke 0.3s ease;
  filter: drop-shadow(0 0 8px rgba(0, 255, 136, 0.5));
}

.timer-ring-progress.rest {
  stroke: var(--accent-blue);
  filter: drop-shadow(0 0 8px rgba(0, 170, 255, 0.5));
}

/* Tick marks around the ring */
.timer-ticks line {
  stroke: var(--bg-tertiary);
  stroke-width: 2;
  transition: stroke 0.3s ease;
}

.timer-ticks line.active {
  stroke: var(--accent-neon);
  filter: drop-shadow(0 0 3px rgba(0, 255, 136, 0.6));
}

.timer-ticks line.rest-active {
  stroke: var(--accent-blue);
  filter: drop-shadow(0 0 3px rgba(0, 170, 255, 0.6));
}

.timer-round {
  font-size: 20px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Buttons */
.btn {
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  border-radius: var(--border-radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-neon);
  color: var(--bg-primary);
}

.btn-primary:not(:disabled):hover {
  background: #00dd77;
  box-shadow: 0 4px 20px rgba(0, 255, 136, 0.4);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:not(:disabled):hover {
  background: #3a3a3a;
}

.btn-small {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: 14px;
}

.timer-controls {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: center;
  margin-bottom: var(--spacing-lg);
}

.timer-controls .btn {
  flex: 1;
  max-width: 150px;
}

/* Forms */
.form-group {
  margin-bottom: var(--spacing-md);
}

.form-group label {
  display: block;
  margin-bottom: var(--spacing-xs);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group select {
  width: 100%;
  padding: var(--spacing-sm);
  background: var(--bg-tertiary);
  border: 2px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 16px;
  transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent-neon);
}

.form-group input[type="range"] {
  width: 100%;
}

.form-group input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-right: var(--spacing-xs);
  cursor: pointer;
}

/* Heart Rate Input */
.heart-rate-input {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.heart-rate-input label {
  color: var(--accent-red);
  font-weight: 700;
  white-space: nowrap;
}

.heart-rate-input input {
  flex: 1;
  padding: var(--spacing-sm);
  background: var(--bg-tertiary);
  border: 2px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 16px;
}

/* Routines List */
.routines-list {
  display: grid;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-lg);
}

.routine-card {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
}

.routine-card:hover {
  border-color: var(--accent-neon);
  transform: translateY(-2px);
}

.routine-card.active {
  border-color: var(--accent-neon);
  background: var(--bg-tertiary);
}

.routine-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: var(--spacing-xs);
}

.routine-details {
  font-size: 14px;
  color: var(--text-secondary);
}

.custom-routine {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--border-radius);
}

.custom-routine h3 {
  margin-bottom: var(--spacing-md);
  color: var(--accent-neon);
}

/* Stats */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-lg);
}

.stat-card {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--border-radius);
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 900;
  color: var(--accent-neon);
  margin-bottom: var(--spacing-xs);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.history-list {
  margin-bottom: var(--spacing-md);
}

.history-item {
  background: var(--bg-secondary);
  padding: var(--spacing-sm);
  border-radius: var(--border-radius);
  margin-bottom: var(--spacing-xs);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-date {
  font-size: 12px;
  color: var(--text-secondary);
}

.history-routine {
  font-weight: 700;
  font-size: 14px;
}

/* Exercise History - Day by Day */
.exercise-history {
  margin-bottom: var(--spacing-md);
}

.no-history {
  color: var(--text-secondary);
  text-align: center;
  padding: var(--spacing-lg);
  font-size: 14px;
}

.day-group {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  margin-bottom: var(--spacing-sm);
  overflow: hidden;
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-tertiary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.day-date {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-neon);
}

.day-total {
  font-size: 12px;
  color: var(--text-secondary);
}

.exercise-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.exercise-entry:last-child {
  border-bottom: none;
}

.exercise-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.exercise-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.exercise-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.exercise-duration {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.exercise-hr {
  font-size: 12px;
  color: var(--accent-red);
  font-weight: 600;
}

/* Settings */
.settings-group {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--border-radius);
  margin-bottom: var(--spacing-md);
}

.settings-group h3 {
  margin-bottom: var(--spacing-md);
  color: var(--accent-neon);
  font-size: 16px;
}

.music-controls {
  display: flex;
  gap: var(--spacing-sm);
  margin: var(--spacing-sm) 0;
}

input[type="file"] {
  width: 100%;
  padding: var(--spacing-sm);
  background: var(--bg-tertiary);
  border: 2px dashed var(--bg-tertiary);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  font-size: 14px;
}

/* Responsive */
@media (min-width: 768px) {
  .stats-overview {
    grid-template-columns: repeat(4, 1fr);
  }

  .routines-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  #app {
    max-width: 800px;
    margin: 0 auto;
  }
}

/* Animations */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.timer-phase.pulse {
  animation: pulse 1s ease-in-out infinite;
}

/* ==============================
   Exercise Display (during workout)
   ============================== */
.exercise-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: var(--spacing-sm);
  min-height: 90px;
  transition: opacity 0.3s ease;
}

.exercise-display.hidden {
  opacity: 0;
  pointer-events: none;
  min-height: 0;
}

.exercise-anim {
  width: 80px;
  height: 68px;
  color: var(--accent-neon);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.exercise-anim svg.human-figure {
  width: 100%;
  height: 100%;
}

/* Rest phase uses blue color */
.exercise-display.rest-phase .exercise-anim {
  color: var(--accent-blue);
}

.exercise-name-display {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-neon);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.exercise-display.rest-phase .exercise-name-display {
  color: var(--accent-blue);
}

/* Exercise icon animations now handled by injected keyframe styles */

/* ==============================
   Exercise Editor (before start)
   ============================== */
.exercise-editor {
  margin-bottom: var(--spacing-md);
}

.exercise-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-sm);
}

.exercise-editor-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.exercise-editor-toggle {
  background: var(--bg-tertiary);
  border: none;
  color: var(--accent-neon);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.exercise-rounds-list {
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  padding: var(--spacing-xs);
}

.exercise-rounds-list.collapsed {
  display: none;
}

.exercise-round-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 6px var(--spacing-xs);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.exercise-round-item:last-child {
  border-bottom: none;
}

.exercise-round-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 28px;
}

.exercise-round-select {
  flex: 1;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}

.exercise-round-select:focus {
  outline: none;
  border-color: var(--accent-neon);
}

.exercise-round-icon {
  width: 32px;
  height: 28px;
  color: var(--accent-neon);
  flex-shrink: 0;
}

.exercise-round-icon svg.human-figure {
  width: 100%;
  height: 100%;
}

/* ==============================
   Exercise Media Display (during workout)
   ============================== */
.exercise-anim {
  overflow: hidden;
  border-radius: 8px;
}

.exercise-media-img {
  width: 80px;
  height: 68px;
  object-fit: cover;
  border-radius: 6px;
}

.exercise-media-video {
  width: 100px;
  height: 75px;
  object-fit: cover;
  border-radius: 6px;
}

.exercise-svg-fallback {
  width: 80px;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.exercise-svg-fallback svg.human-figure {
  width: 100%;
  height: 100%;
}

/* ==============================
   Exercise Media Manager (Settings)
   ============================== */
.settings-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: var(--spacing-sm);
  line-height: 1.4;
}

.media-manager {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.media-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg-tertiary);
  border-radius: 8px;
}

.media-item-info {
  flex: 1;
  min-width: 0;
}

.media-item-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-item-source {
  display: block;
  font-size: 10px;
  margin-top: 2px;
}

.media-item-source.user {
  color: var(--accent-neon);
}

.media-item-source.online {
  color: var(--accent-blue);
}

.media-item-source.stickfigure {
  color: var(--text-secondary);
}

.media-item-preview {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-preview-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-preview-svg {
  width: 32px;
  height: 32px;
  color: var(--accent-neon);
}

.media-preview-svg svg {
  width: 100%;
  height: 100%;
}

.media-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.media-upload-btn {
  cursor: pointer;
  font-size: 11px !important;
  padding: 3px 8px !important;
  background: var(--bg-secondary) !important;
  border: 1px solid var(--accent-neon) !important;
  color: var(--accent-neon) !important;
}

.media-remove-btn {
  font-size: 11px !important;
  padding: 3px 8px !important;
  background: transparent !important;
  border: 1px solid #ff4444 !important;
  color: #ff4444 !important;
}

.media-remove-btn:hover {
  background: rgba(255, 68, 68, 0.15) !important;
}
