:root {
  --bg: #0b1220;
  --bg-elevated: #121a2b;
  --bg-card: #161f33;
  --bg-card-hover: #1c2740;
  --border: #243049;
  --border-strong: #334155;
  --text: #e8eef9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.15);
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --tap: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 50% -10%, #1a2744 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.45;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

a { color: var(--accent); }

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(12px);
  background: rgba(11, 18, 32, 0.88);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand .sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  padding: 0 12px;
  gap: 6px;
}

.icon-btn:hover, .icon-btn:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.unit-toggle {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* Main content */
main {
  flex: 1;
  padding: 16px;
}

.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-title {
  margin: 0 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
}

.muted { color: var(--text-muted); font-size: 0.9rem; }
.dim { color: var(--text-dim); font-size: 0.85rem; }

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.row.between { justify-content: space-between; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.badge.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.3);
}

.badge.rest {
  background: rgba(251, 191, 36, 0.12);
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.3);
}

/* Buttons */
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover, .btn:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.btn-primary {
  background: linear-gradient(180deg, #0ea5e9, #0284c7);
  border-color: transparent;
  color: #041018;
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-success {
  background: linear-gradient(180deg, #34d399, #10b981);
  border-color: transparent;
  color: #042014;
}

.btn-ghost {
  background: transparent;
}

.btn-block { width: 100%; }

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

select.field, input.field, textarea.field {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  outline: none;
}

select.field:focus, input.field:focus, textarea.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea.field {
  min-height: 96px;
  resize: vertical;
}

.label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field-group { margin-bottom: 12px; }

/* Exercise list */
.exercise-list { display: flex; flex-direction: column; gap: 10px; }

.exercise {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.exercise.done {
  border-color: rgba(52, 211, 153, 0.4);
}

.exercise-header {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 14px;
  background: transparent;
  border: 0;
  text-align: left;
  min-height: var(--tap);
}

.exercise-header:hover { background: var(--bg-card-hover); }

.ex-check {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
  margin-top: 2px;
  display: grid;
  place-items: center;
  background: transparent;
}

.exercise.done .ex-check {
  background: var(--success);
  border-color: var(--success);
  color: #042014;
}

.ex-meta { flex: 1; min-width: 0; }

.ex-name {
  font-weight: 700;
  font-size: 1rem;
  margin: 0 0 2px;
}

.ex-prescription {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.ex-chevron {
  color: var(--text-dim);
  transition: transform 0.2s;
  margin-top: 6px;
}

.exercise.open .ex-chevron { transform: rotate(180deg); }

.exercise-body {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
}

.exercise.open .exercise-body { display: block; padding-top: 14px; }

/* Sets table */
.sets {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
}

.sets th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 700;
  text-align: left;
  padding: 0 4px 4px;
}

.sets td { padding: 0 4px; vertical-align: middle; }

.set-num {
  width: 28px;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.set-input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.set-input::-webkit-outer-spin-button,
.set-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.set-input:focus {
  border-color: var(--accent);
  outline: none;
}

.set-done {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--border-strong);
  background: transparent;
  display: grid;
  place-items: center;
}

.set-done.on {
  background: var(--success);
  border-color: var(--success);
  color: #042014;
}

.video-wrap {
  margin-top: 12px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  aspect-ratio: 16 / 9;
}

.video-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.video-placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  background: linear-gradient(180deg, #111827, #0b1220);
}

.video-placeholder strong {
  display: block;
  color: var(--text);
  margin-bottom: 4px;
}

.ex-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* Rest day */
.rest-hero {
  text-align: center;
  padding: 28px 12px 8px;
}

.rest-hero .emoji {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

/* History */
.history-list { display: flex; flex-direction: column; gap: 10px; }

.history-item {
  width: 100%;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.history-item .title { font-weight: 700; margin: 0 0 2px; }
.history-item .meta { color: var(--text-muted); font-size: 0.85rem; }

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: rgba(11, 18, 32, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  display: flex;
  justify-content: center;
}

.bottom-nav-inner {
  width: 100%;
  max-width: 720px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.nav-btn {
  min-height: 52px;
  border: 0;
  background: transparent;
  border-radius: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 600;
}

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

.nav-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* Modal / sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 80;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open { display: flex; }

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  max-height: min(80vh, 640px);
  overflow: auto;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100% - 32px);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}

.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-strong), var(--success));
  width: 0%;
  transition: width 0.25s ease;
}

.complete-banner {
  display: none;
  margin-top: 12px;
}

.complete-banner.show { display: block; }

@media (min-width: 640px) {
  main { padding: 20px 20px 24px; }
  .topbar { padding: 14px 20px; }
}
