:root {
  --bg: #0f0f14;
  --bg-card: #1a1a24;
  --bg-elevated: #22222f;
  --text: #f0f0f5;
  --text-muted: #8888a0;
  --accent: #ff6b35;
  --accent-glow: rgba(255, 107, 53, 0.35);
  --work: #ff4757;
  --work-glow: rgba(255, 71, 87, 0.4);
  --rest: #2ed573;
  --rest-glow: rgba(46, 213, 115, 0.3);
  --round-rest: #3498db;
  --warmup: #feca57;
  --cooldown: #a29bfe;
  --radius: 16px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background 0.5s ease;
}

body[data-phase="warmup"] { background: linear-gradient(180deg, #1a1508 0%, var(--bg) 40%); }
body[data-phase="main"][data-type="work"] { background: linear-gradient(180deg, #1a0808 0%, var(--bg) 40%); }
body[data-phase="main"][data-type="rest"],
body[data-phase="main"][data-type="roundRest"] { background: linear-gradient(180deg, #081a0f 0%, var(--bg) 40%); }
body[data-phase="cooldown"] { background: linear-gradient(180deg, #0f0a1a 0%, var(--bg) 40%); }

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  min-height: 100dvh;
}

.screen {
  display: none;
  animation: fadeIn 0.35s ease;
}

.screen.active {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Home */
.hero {
  text-align: center;
  padding: 24px 0 8px;
}

.logo {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 8px;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.today-hint {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
}

.today-hint.high {
  background: rgba(255, 107, 53, 0.15);
  color: #ff9f7a;
  border: 1px solid rgba(255, 107, 53, 0.3);
}

.today-hint.recovery {
  background: rgba(46, 213, 115, 0.12);
  color: #7bed9f;
  border: 1px solid rgba(46, 213, 115, 0.25);
}

.today-hint.rest {
  background: rgba(162, 155, 254, 0.12);
  color: #c8c3ff;
  border: 1px solid rgba(162, 155, 254, 0.25);
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.card h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.structure-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 8px;
}

.structure-item {
  text-align: center;
  padding: 12px 8px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.structure-item.main {
  background: rgba(255, 107, 53, 0.12);
  border: 1px solid rgba(255, 107, 53, 0.25);
}

.structure-time {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.structure-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.3;
}

.schedule-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.schedule-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.schedule-list li.today {
  border: 1px solid rgba(255, 107, 53, 0.4);
  background: rgba(255, 107, 53, 0.08);
}

.schedule-days {
  font-weight: 600;
  color: var(--text);
}

.schedule-label {
  color: var(--text-muted);
  text-align: right;
  font-size: 0.8rem;
}

.settings-row {
  display: flex;
  gap: 8px;
}

.toggle-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background: rgba(255, 107, 53, 0.15);
  border-color: rgba(255, 107, 53, 0.4);
  color: var(--accent);
}

.toggle-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.start-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.start-alt {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Buttons */
.btn {
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ff8c42);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.8rem;
  padding: 12px;
}

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 1.2rem;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-danger {
  color: #ff6b6b;
}

.btn-large {
  padding: 18px 24px;
  font-size: 1rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Workout Screen */
.workout-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.phase-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.segment-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 4px 10px;
  border-radius: 20px;
}

.segment-badge.work {
  background: rgba(255, 71, 87, 0.2);
  color: var(--work);
  animation: pulse 1s ease infinite;
}

.segment-badge.rest {
  background: rgba(46, 213, 115, 0.15);
  color: var(--rest);
}

.segment-badge.round-rest {
  background: rgba(52, 152, 219, 0.15);
  color: var(--round-rest);
}

.segment-badge.phase {
  background: rgba(254, 202, 87, 0.15);
  color: var(--warmup);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.timer-section {
  text-align: center;
  padding: 8px 0;
}

.timer-rings {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 0 auto;
}

.ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.ring-segment {
  width: 160px;
  height: 160px;
}

.ring-total {
  width: 120px;
  height: 120px;
  opacity: 0.5;
}

.ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 6;
}

.ring-fill {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
  stroke-dasharray: 439.82;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s linear;
}

.ring-fill.segment {
  stroke: var(--accent);
  filter: drop-shadow(0 0 6px var(--accent-glow));
}

body[data-type="work"] .ring-fill.segment {
  stroke: var(--work);
  filter: drop-shadow(0 0 8px var(--work-glow));
}

body[data-type="rest"] .ring-fill.segment,
body[data-type="roundRest"] .ring-fill.segment {
  stroke: var(--rest);
  filter: drop-shadow(0 0 6px var(--rest-glow));
}

.ring-fill.total {
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 4;
}

.timer-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.timer-display {
  display: block;
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.total-remaining {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 12px;
}

.exercise-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.06);
  min-height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.exercise-emoji {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 8px;
}

.exercise-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
}

.exercise-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 6px;
}

.exercise-instruction {
  color: var(--text);
  font-size: 0.9rem;
  margin-top: 10px;
  line-height: 1.5;
}

.exercise-easy {
  color: var(--rest);
  font-size: 0.85rem;
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(46, 213, 115, 0.08);
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.timeline {
  display: flex;
  gap: 2px;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
}

.timeline-item {
  flex: 1;
  min-width: 2px;
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.3s;
}

.timeline-item.done {
  background: rgba(255, 107, 53, 0.4);
}

.timeline-item.current {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.timeline-item.work.current { background: var(--work); box-shadow: 0 0 8px var(--work-glow); }
.timeline-item.rest.current,
.timeline-item.roundRest.current { background: var(--rest); }

.workout-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 8px;
}

.btn-pause {
  flex: 1;
  max-width: 200px;
  font-size: 1rem;
}

.btn-pause.paused {
  background: linear-gradient(135deg, var(--rest), #26de81);
  box-shadow: 0 4px 20px var(--rest-glow);
}

/* Done Screen */
#screen-done {
  justify-content: center;
  align-items: center;
  min-height: calc(100dvh - 40px);
}

.done-content {
  text-align: center;
  padding: 24px;
}

.done-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.done-content h1 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.done-content > p {
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

.done-tips {
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 32px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
}

.done-tips li {
  font-size: 0.9rem;
  color: var(--text);
}
