:root {
  --bg: #0a0a0a;
  --panel: #161616;
  --text: #e5e5e5;
  --muted: #737373;
  --accent: #f5f5f5;       /* near-white — used for brand, primary surfaces */
  --accent-ink: #0a0a0a;   /* text color on top of --accent */
  --accent-soft: #262626;  /* subtle highlight tint */
  --accent-2: #10b981;     /* semantic: done / positive */
  --warn: #f59e0b;
  --danger: #ef4444;
  --link: #93c5fd;         /* charts / links keep a cool tint for differentiation */
  --border: #262626;
  --topnav-h: 52px;
  --bottomnav-h: 60px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Top nav (desktop primary) ---------- */
.topnav {
  display: flex; gap: 16px; align-items: center;
  background: var(--panel); padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
  min-height: var(--topnav-h);
}
.topnav a { color: var(--text); text-decoration: none; padding: 8px 12px; border-radius: 6px; }
.topnav a:hover { background: rgba(255,255,255,0.06); }
.topnav .brand { font-weight: 700; color: var(--accent); letter-spacing: 0.02em; }
.topnav .topnav-link.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- Bottom nav (mobile primary) ---------- */
.bottomnav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  min-height: 56px;
  color: var(--muted); text-decoration: none;
  font-size: 11px;
}
.bottomnav .tab .ico { font-size: 18px; line-height: 1; }
.bottomnav .tab.active { color: var(--accent); background: var(--accent-soft); }
.bottomnav .tab:active { background: rgba(255,255,255,0.05); }

/* ---------- Layout ---------- */
main {
  max-width: 960px;
  margin: 16px auto;
  padding: 0 16px calc(40px + env(safe-area-inset-bottom));
}
h1 { margin-top: 0; font-size: 22px; }
h2 { margin-top: 0; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; margin-bottom: 16px;
}

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row > div { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 16px;
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
  border-radius: 8px; cursor: pointer;
  text-decoration: none;
  font-size: 15px; font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: rgba(255,255,255,0.06); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(0.92); }
.btn.primary.big { width: 100%; min-height: 52px; font-size: 17px; margin-top: 8px; }
.btn.small { padding: 6px 10px; font-size: 13px; min-height: 36px; }
.btn.danger {
  background: rgba(220, 38, 38, 0.15); border-color: rgba(220, 38, 38, 0.5);
  color: #fca5a5;
}
.btn.danger:hover { background: rgba(220, 38, 38, 0.25); color: #fee2e2; }

/* Done toggle */
.btn.done {
  min-width: 96px;
  background: var(--accent-2); border-color: var(--accent-2); color: white;
  font-weight: 600;
}
.btn.done:hover { filter: brightness(1.1); }
.btn.done.is-done {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.5); color: var(--accent-2);
}

/* Two-tap inline confirm */
.btn.is-confirm-pending {
  background: var(--warn); border-color: var(--warn); color: #1f1611;
  font-weight: 600;
}

/* ---------- Forms / inputs ---------- */
input, select, textarea {
  font-family: inherit;
  font-size: 16px;  /* prevents iOS zoom on focus */
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px;
  min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
form.inline { display: inline-flex; gap: 6px; align-items: center; }

label { display: block; margin: 12px 0; font-size: 14px; }
label > input, label > select { display: block; width: 100%; max-width: 360px; margin-top: 6px; }

/* ---------- Tags ---------- */
.tag {
  display: inline-block; font-size: 12px; padding: 3px 10px;
  background: rgba(255,255,255,0.06); color: var(--text);
  border-radius: 999px; border: 1px solid var(--border);
}
.tag.muted { background: transparent; color: var(--muted); border-color: var(--border); }
.tag.superset { background: rgba(245,158,11,0.15); color: var(--warn); border-color: rgba(245,158,11,0.3); }
.tagrow { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

/* ---------- Today / planlist ---------- */
.planlist { list-style: none; padding: 0; margin: 0; }
.planlist li { padding: 14px 0; border-bottom: 1px solid var(--border); }
.planlist li:last-child { border-bottom: none; }
.prescribe { font-weight: 600; }
.rationale { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* ---------- Recovery bars ---------- */
.fatiguebars { display: grid; grid-template-columns: 1fr; gap: 8px; }
.fatiguebars.big .fatiguebar { padding: 8px 0; }
.fatiguebar {
  display: grid; grid-template-columns: 110px 1fr 50px;
  align-items: center; gap: 10px; min-height: 32px;
}
.fatiguebar .label { font-size: 13px; color: var(--muted); }
.fatiguebar .val { font-size: 12px; color: var(--muted); text-align: right; }
.bar { height: 10px; background: rgba(255,255,255,0.05); border-radius: 5px; overflow: hidden; }
.fill { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--warn)); }

/* ---------- Workout: timer header ---------- */
.workout-header {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 10px; margin-bottom: 16px;
  position: sticky; top: var(--topnav-h);
  z-index: 4;
}
.workout-header h1 { margin: 0; font-size: 18px; }
.timer-display { display: flex; flex-direction: column; align-items: flex-end; }
.timer-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.timer-value {
  font-size: 28px; font-weight: 700; color: var(--text); line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ---------- Workout: exercise sections ---------- */
.exercise > .exercise-header {
  position: sticky;
  top: calc(var(--topnav-h) + 70px);
  background: var(--panel);
  z-index: 2;
  margin: -16px -16px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  display: flex; flex-direction: column; gap: 6px;
}
.exercise > .exercise-header h2 { margin: 0 0 4px; font-size: 16px; }
.exercise > .exercise-header h2 a { color: var(--text); text-decoration: none; }
.exercise > .exercise-header h2 a:hover { color: var(--accent); }
.exercise-fatigue { margin-top: 4px; }
.exercise-desc { margin: 4px 0 0; line-height: 1.4; }

/* ---------- Setcards (replaces sets table) ---------- */
.setlist { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.setcard {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  grid-template-areas: "meta fields actions";
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
}
.setcard.is-done { background: rgba(16, 185, 129, 0.06); border-color: rgba(16,185,129,0.25); }
.setcard .set-meta { grid-area: meta; display: flex; flex-direction: column; gap: 2px; }
.setcard .set-num { font-weight: 600; font-size: 14px; }
.setcard .set-fields { grid-area: fields; display: flex; gap: 10px; margin: 0; }
.setcard .set-fields label { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; margin: 0; font-size: 11px; color: var(--muted); }
.setcard .set-fields label > input { width: 100%; max-width: none; margin: 0; }
.setcard .set-actions { grid-area: actions; display: flex; gap: 6px; }

/* ---------- History ---------- */
.historylist { list-style: none; padding: 0; margin: 0; }
.historylist li { padding: 12px 0; border-bottom: 1px solid var(--border); }

/* Recent history table inside workout setcard */
.recent-history { margin: 0 0 12px; }
.history-label { margin: 0 0 6px; }
.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th,
.history-table td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.history-table th { background: var(--surface); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.history-table td.muted { color: var(--muted); }

/* ---------- Library ---------- */
.filterbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filterbar input { flex: 1; min-width: 200px; }
.exercise-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.exercise-card h3 { margin: 0 0 8px; font-size: 16px; }
.exercise-card h3 a { color: var(--text); text-decoration: none; }
.exercise-card h3 a:hover { color: var(--accent); }
.exercise-card .desc { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* .exercise-thumb sizing handled by .media-wrap.exercise-thumb */
.exercise-header-top { display: flex; gap: 12px; align-items: flex-start; }
.exercise-header-text { flex: 1; min-width: 0; }
.edit-desc-card summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.edit-desc-card textarea {
  font-family: inherit; font-size: 14px; padding: 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  min-height: 120px; resize: vertical;
}

/* ---------- Charts ---------- */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart { width: 100%; height: 240px; background: rgba(255,255,255,0.02); border-radius: 6px; }
.ax-title { font-size: 11px; fill: var(--muted); }
.tick { font-size: 10px; fill: var(--muted); }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.chart-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; margin-right: 4px; }

/* ---------- Barbell calculator ---------- */
.barbell-calc {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; margin: 12px 0;
}
.barbell-calc h3 { margin: 0 0 4px; font-size: 14px; color: var(--text); }
.bc-row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 8px;
}
.bc-side { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 220px; }
.bc-side-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.bc-plates { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.bc-plates select { min-width: 0; padding: 8px 6px; font-size: 14px; }
.bc-bar-wrap { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.bc-bar-wrap select { padding: 8px 10px; font-size: 14px; }
.bc-plus, .bc-equals { color: var(--muted); font-weight: 600; align-self: center; }
.bc-total { color: var(--text); width: 100%; padding-top: 6px; border-top: 1px dashed var(--border); margin-top: 4px; text-align: right; }
.bc-total strong { font-size: 22px; color: var(--accent); }

/* ---------- Nutrition ---------- */
.nutrition ul { padding-left: 18px; }
.nutrition li { margin: 4px 0; }

/* ---------- Mobile (≤ 720px): bottom tab bar replaces top nav, setcards stack ---------- */
@media (max-width: 720px) {
  .topnav { padding: 8px 14px; }
  .topnav .topnav-link { display: none; }
  .topnav .brand { font-size: 16px; }

  .bottomnav { display: flex; }

  main { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 24px); }

  .setcard {
    grid-template-columns: 1fr;
    grid-template-areas:
      "meta"
      "fields"
      "actions";
    gap: 8px;
  }
  .setcard .set-actions { justify-content: stretch; gap: 8px; }
  .setcard .set-actions > .btn.done { flex: 1; min-height: 48px; font-size: 16px; }
  .setcard .set-actions > .inline { flex: 0 0 auto; }
  .setcard .set-actions > .inline .btn { min-height: 48px; }

  .workout-header { padding: 10px 12px; }
  .workout-header h1 { font-size: 16px; }
  .timer-value { font-size: 24px; }
  .exercise > .exercise-header { top: calc(var(--topnav-h) + 64px); }
  .media-wrap.exercise-thumb { width: 72px; height: 72px; }

  .bc-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .bc-side, .bc-bar-wrap { min-width: 0; }
  .bc-plus, .bc-equals { display: none; }
  .bc-total { text-align: center; }
  .bc-total strong { font-size: 26px; }

  .fatiguebar { grid-template-columns: 90px 1fr 44px; }

  .row { gap: 8px; }

  .filterbar input, .filterbar select { min-height: 44px; }

  /* Analytics stat grid stacks to 2 cols on mobile */
  .analytics-stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Media tap-to-play wrapper (static image + MP4 overlay) ---------- */
.media-wrap {
  position: relative; overflow: hidden; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
}
.media-wrap img {
  display: block; width: 100%; height: 100%; object-fit: cover;
}
.media-wrap video {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
}
.media-play-btn {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.45);
  color: rgba(255,255,255,0.9); font-size: 13px; font-weight: 600;
  gap: 4px; pointer-events: none;
  transition: opacity 0.2s;
}
.media-wrap.playing .media-play-btn { opacity: 0; pointer-events: none; }

/* Thumbnail in workout exercise header */
.media-wrap.exercise-thumb { width: 96px; height: 96px; }

/* Larger view on exercise detail page */
.media-wrap-detail {
  width: 100%; max-width: 440px; height: 300px;
  margin: 12px 0;
}

/* Card thumbnail in exercise library */
.media-wrap-card {
  width: 100%; height: 160px;
  margin-bottom: 10px;
}

/* ---------- Add-exercise panel ---------- */
.add-exercise-panel { margin-bottom: 12px; }
.add-exercise-panel > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.add-ex-search { display: flex; gap: 8px; margin: 12px 0; }
.add-ex-search input { flex: 1; }
.add-ex-results { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.add-ex-results li { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.add-ex-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.add-ex-info { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.add-ex-info strong { font-size: 14px; }

/* ---------- Analytics ---------- */
.analytics-stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 14px; text-align: center;
}
.stat-val { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Multi-line chart legend */
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 10px 20px;
  margin-top: 10px; font-size: 12px; color: var(--text);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }

/* 6-tab bottom nav: slightly smaller labels */
@media (max-width: 720px) {
  .bottomnav .tab { font-size: 10px; padding: 6px 2px; }
  .bottomnav .tab .ico { font-size: 16px; }
}
