:root {
  --bg: #000000;
  --bg-elevated: #1a1a1a;
  --bg-elevated-2: #262626;
  --fg: #f5f5f5;
  --fg-dim: #9a9a9a;
  --accent: #FF6B00;
  --accent-dim: #b34a00;
  --danger: #d6394a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

#view-root {
  flex: 1 1 auto;
  overflow-y: auto;
  padding-bottom: calc(72px + var(--safe-bottom));
}

.view { min-height: 100%; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid #2c2c2c;
  padding-bottom: var(--safe-bottom);
  z-index: 50;
}
.nav-btn {
  flex: 1;
  text-align: center;
  padding: 16px 0;
  min-height: 60px;
  color: var(--fg-dim);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.nav-btn.active { color: var(--accent); }
.nav-btn:active { background: var(--bg-elevated-2); }

/* Buttons */
.btn {
  display: block;
  width: 100%;
  min-height: 60px;
  border: none;
  border-radius: 14px;
  font-size: 22px;
  font-weight: 700;
  margin-top: 16px;
  cursor: pointer;
  color: var(--fg);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; }
.btn-huge { min-height: 72px; font-size: 26px; }
.btn-primary { background: var(--accent); color: #1a0d00; }
.btn-secondary { background: var(--bg-elevated-2); color: var(--fg); border: 2px solid #3a3a3a; }

.icon-btn {
  width: 48px;
  height: 48px;
  min-height: unset;
  border: none;
  border-radius: 50%;
  background: var(--bg-elevated-2);
  color: var(--fg);
  font-size: 26px;
  line-height: 1;
}
.icon-btn:active { background: var(--bg-elevated); }

.screen-title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin: calc(24px + var(--safe-top)) 0 24px;
  padding: 0 20px;
}

.empty-hint {
  color: var(--fg-dim);
  text-align: center;
  padding: 40px 24px;
  font-size: 16px;
}

/* Timer: select screen */
.timer-select { padding: 0 24px 24px; }
.wod-select {
  width: 100%;
  min-height: 60px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 2px solid #3a3a3a;
  border-radius: 12px;
  font-size: 18px;
  padding: 0 14px;
}
.wod-summary {
  margin-top: 20px;
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 16px;
  font-size: 15px;
  color: var(--fg-dim);
  line-height: 1.6;
}
.wod-summary strong { color: var(--fg); }

/* Timer: active screen */
.timer-active {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 72px - var(--safe-bottom));
  padding: var(--safe-top) 20px 16px;
}
.progress-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
  background: var(--bg-elevated);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s linear;
}
.timer-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 18px;
}
.wod-name {
  font-size: 14px;
  color: var(--fg-dim);
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 10px;
}
.round-counter {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.timer-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
}
.phase-label {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
}
.exercise-name {
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 800;
  line-height: 1.1;
}
.exercise-target {
  font-size: 20px;
  color: var(--fg-dim);
}
.clock {
  font-size: clamp(80px, 26vw, 140px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 8px 0;
}
.next-preview {
  font-size: 16px;
  color: var(--fg-dim);
}
.timer-controls { padding-top: 8px; }

/* Auth */
.view-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
}
.auth-title {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 24px;
  color: var(--accent);
}
.auth-mode-tabs { justify-content: center; margin-bottom: 8px; }
.auth-mode-tabs .pill { flex: 1; text-align: center; }

/* Account */
.view-account { padding: 0 20px 24px; }
.account-card {
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 20px;
}
.account-name {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 8px;
}
.logged-in-as {
  text-align: center;
  color: var(--fg-dim);
  font-size: 14px;
  margin: -8px 0 16px;
}

/* Builder */
.view-builder { padding: 0 20px 24px; }
.section-title {
  font-size: 18px;
  font-weight: 700;
  margin: 28px 0 12px;
}
.field-label {
  display: block;
  font-size: 14px;
  color: var(--fg-dim);
  margin: 16px 0 6px;
}
.text-input {
  width: 100%;
  min-height: 56px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 2px solid #3a3a3a;
  border-radius: 12px;
  font-size: 18px;
  padding: 0 14px;
}

.category-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.pill {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  border: 2px solid #3a3a3a;
  background: var(--bg-elevated);
  color: var(--fg-dim);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.active { background: var(--accent); color: #1a0d00; border-color: var(--accent); }

.exercise-pick-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.exercise-pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 60px;
  background: var(--bg-elevated);
  border: none;
  border-radius: 12px;
  padding: 0 16px;
  color: var(--fg);
  text-align: left;
}
.exercise-pick-row:active { background: var(--bg-elevated-2); }
.exercise-pick-name { flex: 1; font-size: 17px; font-weight: 600; }
.exercise-pick-cat { font-size: 12px; color: var(--fg-dim); text-transform: uppercase; }
.exercise-pick-add { font-size: 22px; color: var(--accent); font-weight: 800; }

.builder-selected-list { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.builder-row {
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 14px;
}
.builder-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.builder-row-name { font-size: 17px; font-weight: 700; }
.row-remove {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg-elevated-2);
  color: var(--danger);
  font-size: 20px;
}
.builder-row-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.mode-pills { display: flex; gap: 6px; }
.mode-pills .pill { min-height: 40px; padding: 0 12px; font-size: 14px; }
.row-value {
  width: 80px;
  min-height: 44px;
  background: var(--bg-elevated-2);
  border: 2px solid #3a3a3a;
  border-radius: 10px;
  color: var(--fg);
  font-size: 17px;
  text-align: center;
}
.row-unit { font-size: 13px; color: var(--fg-dim); }
.reorder-btns { display: flex; gap: 6px; margin-left: auto; }
.reorder-btns .icon-btn { width: 40px; height: 40px; font-size: 18px; }
.reorder-btns .icon-btn:disabled { opacity: 0.3; }

.save-status {
  text-align: center;
  margin-top: 12px;
  font-size: 15px;
  min-height: 20px;
  color: var(--accent);
}
.save-status.error { color: var(--danger); }

/* History */
.view-history { padding: 0 20px 24px; }
.history-overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}
.stat-value { font-size: 26px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 13px; color: var(--fg-dim); margin-top: 4px; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-row {
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 14px 16px;
}
.history-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.history-name { font-size: 17px; font-weight: 700; }
.history-date { font-size: 13px; color: var(--fg-dim); }
.history-row-bottom {
  display: flex;
  gap: 14px;
  font-size: 14px;
  color: var(--fg-dim);
}
.history-type { color: var(--accent); font-weight: 700; text-transform: uppercase; font-size: 12px; }

/* Timer: done screen */
.timer-done { padding: 0 24px 24px; text-align: center; }
.done-stats {
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 20px;
  font-size: 18px;
  line-height: 1.8;
  margin-bottom: 8px;
}
.done-stats strong { color: var(--accent); }
