/* GymBuddy — Edge Lifestyle Products
 * Visual direction: "Grounded, not Loud".
 * Visible structure and direct typography, warmed up so it reads as approachable
 * rather than edgy. Motion only where it explains a state change.
 * Built to stay legible on a budget phone in bad gym lighting.
 */

:root {
  /* Warm neutrals — paper, not glass */
  --bg:        #F7F3EC;
  --surface:   #FFFDFA;
  --surface-2: #F1EAE0;
  --ink:       #1C1917;
  --ink-2:     #57504A;
  --ink-3:     #7C736B;
  --line:      #DED3C4;
  --line-firm: #C4B7A4;

  /* One accent, used sparingly: terracotta */
  --accent:      #A6431C;
  --accent-ink:  #FFFFFF;
  --accent-soft: #F6E7DF;

  /* Added-to-list state */
  --good:      #2C6046;
  --good-soft: #E2EFE7;

  --focus: #1C5FBF;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;

  --tap: 48px;               /* minimum touch target */
  --shell: 720px;

  --step:  clamp(1.0rem, 0.96rem + 0.2vw, 1.08rem);
  --step-s: 0.875rem;
  --step-xs: 0.78rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #17150F;
    --surface:   #211E18;
    --surface-2: #2B271F;
    --ink:       #F5F0E7;
    --ink-2:     #C4BAAB;
    --ink-3:     #9C9184;
    --line:      #3A342A;
    --line-firm: #4E463A;
    --accent:      #E08356;
    --accent-ink:  #1A1005;
    --accent-soft: #3A2418;
    --good:      #7CC29B;
    --good-soft: #1E3227;
    --focus: #79ADFF;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--step)/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 96px;                     /* room for the sticky list bar */
}

.shell { max-width: var(--shell); margin: 0 auto; padding: 0 16px; }

/* ---------- Focus & motion ---------- */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Header ---------- */
.masthead {
  border-bottom: 1.5px solid var(--line);
  background: var(--surface);
}
.masthead .shell { display: flex; align-items: center; gap: 12px; padding-block: 14px; }
.wordmark { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.wordmark span { color: var(--accent); }
.byline { margin-left: auto; font-size: var(--step-xs); color: var(--ink-3); }

/* ---------- Steps / breadcrumb ---------- */
.steps {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: 12px 0 4px; font-size: var(--step-xs); color: var(--ink-3);
}
.steps b { color: var(--ink); font-weight: 600; }
.steps .sep { opacity: 0.5; }

/* ---------- Typography blocks ---------- */
h2.screen-title { font-size: 1.45rem; line-height: 1.25; letter-spacing: -0.015em; margin: 14px 0 6px; }
.lede { color: var(--ink-2); margin: 0 0 18px; max-width: 56ch; }
.section-label {
  font-size: var(--step-xs); text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--ink-3); font-weight: 700; margin: 26px 0 10px;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600;
  min-height: var(--tap); padding: 12px 18px;
  border-radius: var(--r); border: 1.5px solid var(--line-firm);
  background: var(--surface); color: var(--ink);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(0.94); background: var(--accent); }
.btn-primary[disabled] { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); padding-inline: 10px; }
.btn-quiet:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: var(--step-s); }

/* ---------- Shared card surface ----------
   Every clickable block on the page uses this one treatment, so the picker, the
   exercise list and the video rows read as the same family. */
.card-base {
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.hint { color: var(--ink-2); font-size: var(--step-s); margin: -4px 0 12px; max-width: 60ch; }

/* ---------- Common combinations ---------- */
.pair-row {
  display: grid; gap: 10px; margin-bottom: 8px;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  grid-auto-rows: 1fr;
}
.pair {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  padding: 13px 15px; min-height: var(--tap);
  border: 1.5px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
  transition: background-color 120ms ease, border-color 120ms ease;
}
.pair:hover { background: var(--surface-2); }
.pair-name { font-weight: 650; }
.pair-muscles { font-size: var(--step-xs); color: var(--accent); font-weight: 600; }
.pair-why { font-size: var(--step-xs); color: var(--ink-2); line-height: 1.45; margin-top: 2px; }
.pair[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.pair[aria-pressed="true"] .pair-muscles { color: var(--ink-2); }

/* ---------- Muscle picker ---------- */
.muscle-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  grid-auto-rows: 1fr;                       /* every tile the same height */
}
.muscle {
  position: relative; display: flex; flex-direction: column; align-items: flex-start;
  text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  padding: 13px 15px; padding-right: 34px; min-height: var(--tap);
  border: 1.5px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
  transition: background-color 120ms ease, border-color 120ms ease;
}
.muscle:hover { background: var(--surface-2); }
.muscle .m-name { font-weight: 650; }
.muscle .m-count { font-size: var(--step-xs); color: var(--ink-3); margin-top: 2px; }
.muscle .m-plain {
  font-size: var(--step-xs); color: var(--ink-2); line-height: 1.45; margin-top: 6px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.muscle[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.muscle[aria-pressed="true"]::after {
  content: "✓"; position: absolute; top: 11px; right: 13px;
  color: var(--accent); font-weight: 700; line-height: 1;
}

/* ---------- Exercise cards ---------- */
.ex-list { display: grid; gap: 12px; }
.ex-card {
  border: 1.5px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); overflow: hidden;
}
.ex-card[data-open="true"] { border-color: var(--line-firm); }
.ex-head {
  width: 100%; text-align: left; font: inherit; color: inherit;
  background: none; border: 0; cursor: pointer;
  display: flex; gap: 14px; align-items: flex-start; padding: 14px;
}
.ex-head:hover { background: var(--surface-2); }

/* One tile for every card, carrying the push/pull movement icon. */
.ex-art {
  flex: 0 0 56px; height: 56px; border-radius: var(--r);
  border: 1.5px solid var(--line); background: var(--surface-2);
  display: grid; place-items: center; color: var(--accent);
}
.ex-art svg { width: 26px; height: 26px; display: block; }

/* Equipment icon riding inside its tag. */
.tag-icon { display: inline-flex; vertical-align: -2px; margin-right: 5px; }
.tag-icon svg { width: 13px; height: 13px; display: block; }

.ex-meat { flex: 1 1 auto; min-width: 0; }
.ex-name { display: block; font-weight: 650; }
.ex-plain {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: var(--step-s); color: var(--ink-2); margin-top: 3px;
}

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.tag {
  font-size: var(--step-xs); font-weight: 600; line-height: 1.6; white-space: nowrap;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  padding: 1px 9px; border-radius: 999px;
  border: 1.5px solid var(--line); color: var(--ink-2); background: var(--surface-2);
}
.tag-type { border-color: var(--line-firm); color: var(--ink); display: inline-flex; align-items: center; }
/* The movement is the headline fact about an exercise, so it carries the accent. */
.tag-move { border-color: var(--accent); color: var(--accent); background: transparent; }

.ex-chevron { flex: 0 0 auto; color: var(--ink-3); display: grid; place-items: center; align-self: center; }
.ex-chevron svg { width: 20px; height: 20px; transition: transform 160ms ease; }
.ex-card[data-open="true"] .ex-chevron svg { transform: rotate(90deg); }

/* ---------- Exercise detail ---------- */
.ex-body { border-top: 1.5px solid var(--line); padding: 16px 14px 18px; background: var(--surface); }
.ex-body[hidden] { display: none; }



.howto { margin: 10px 0 0; padding-left: 20px; }
.howto li { margin-bottom: 7px; }

.find-note {
  margin-top: 12px; padding: 11px 13px; border-radius: var(--r);
  background: var(--surface-2); border-left: 4px solid var(--accent);
  font-size: var(--step-s); color: var(--ink-2);
}

/* ---------- Videos ----------
   Just the clips: a row of tap-to-play thumbnails, and the player in place. */
.videos {
  display: grid; gap: 10px; margin-top: 16px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.videos:has(.is-playing) { grid-template-columns: 1fr; }

.vid { padding: 0; border: 0; background: none; font: inherit; color: inherit; }
button.vid { cursor: pointer; display: block; width: 100%; }

.vid-thumb {
  position: relative; display: block; width: 100%; aspect-ratio: 16 / 9;
  border-radius: var(--r); overflow: hidden; background: var(--surface-2);
  border: 1.5px solid var(--line);
}
button.vid:hover .vid-thumb { border-color: var(--accent); }
button.vid:focus-visible .vid-thumb { border-color: var(--focus); }
.vid-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vid-play {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-size: 22px; text-shadow: 0 1px 6px rgba(0,0,0,0.65);
  background: rgba(20,16,12,0.24);
}
.vid-dur {
  position: absolute; right: 5px; bottom: 5px;
  background: rgba(20,16,12,0.82); color: #fff;
  font-size: 11px; font-weight: 650; padding: 1px 5px; border-radius: 4px;
}

/* Clips are vertical Shorts, so the player is portrait. */
.vid.is-playing { display: block; }
.vid-frame {
  position: relative; width: 100%; max-width: 264px; margin: 0 auto;
  aspect-ratio: 9 / 16; max-height: 52vh;
  border-radius: var(--r); overflow: hidden; background: #000;
}
.vid-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.vid-close { margin: 10px auto 0; display: block; border: 1.5px solid var(--line-firm); }

/* ---------- Add to list ---------- */
.ex-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.btn-add[data-added="true"] { background: var(--good-soft); border-color: var(--good); color: var(--good); }

/* ---------- Sticky list bar ---------- */
.listbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--surface); border-top: 1.5px solid var(--line-firm);
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 0 rgba(0,0,0,0.03);
}
.listbar[hidden] { display: none; }
/* While a sheet is open the bar underneath it would sit at full contrast — hide it. */
body:has(dialog[open]) .listbar { display: none; }
.listbar .shell { display: flex; align-items: center; gap: 12px; }
.listbar .count { font-weight: 650; min-width: 0; line-height: 1.3; }
.listbar .count small { display: block; font-weight: 400; font-size: var(--step-xs); color: var(--ink-3); }
.listbar .btn { margin-left: auto; flex: 0 0 auto; white-space: nowrap; }

/* ---------- Export sheet ---------- */
dialog.sheet {
  border: 1.5px solid var(--line-firm); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink);
  padding: 0; width: min(640px, calc(100vw - 24px)); max-height: 86vh;
}
dialog.sheet::backdrop { background: rgba(20, 16, 12, 0.5); }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1.5px solid var(--line); }
.sheet-head h3 { margin: 0; font-size: 1.1rem; }
.sheet-head .btn { margin-left: auto; }
.sheet-body { padding: 16px; overflow: auto; }
textarea.export {
  width: 100%; min-height: 220px; resize: vertical;
  font: 0.85rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--ink); background: var(--surface-2);
  border: 1.5px solid var(--line-firm); border-radius: var(--r); padding: 12px;
}
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- My list rows ---------- */
.picked { display: grid; gap: 8px; margin-bottom: 6px; }
.picked-row {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--line); border-radius: var(--r);
  background: var(--surface); padding: 11px 13px; min-height: var(--tap);
}
.picked-row .p-name { font-weight: 600; font-size: var(--step-s); }
.picked-row .p-sub { display: block; font-size: var(--step-xs); color: var(--ink-3); }
.picked-row .btn { margin-left: auto; }

/* ---------- Empty & status ---------- */
.empty {
  border: 1.5px dashed var(--line-firm); border-radius: var(--r-lg);
  padding: 22px 18px; color: var(--ink-2); background: var(--surface);
}
.empty h3 { margin: 0 0 6px; font-size: 1.05rem; color: var(--ink); }

.note {
  margin-top: 26px; padding: 16px 18px;
  border: 1.5px solid var(--line); border-left: 4px solid var(--line-firm);
  border-radius: var(--r); background: var(--surface);
}
.note h3 { margin: 0 0 6px; font-size: 1rem; }
.note p { margin: 0; color: var(--ink-2); font-size: var(--step-s); max-width: 62ch; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 96px; z-index: 60;
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: var(--step-s); font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 160ms ease;
}
.toast.show { opacity: 1; }

/* ---------- Footer ---------- */
.foot {
  margin-top: 40px; padding: 20px 0 8px;
  border-top: 1.5px solid var(--line); font-size: var(--step-xs); color: var(--ink-3);
}
.foot p { margin: 0 0 8px; max-width: 62ch; }
.foot a { color: var(--ink-2); }
.foot-actions { margin: 12px 0 18px; }

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

/* High-contrast / forced colors safety */
@media (forced-colors: active) {
  .muscle[aria-pressed="true"] { border: 3px solid Highlight; }
  .btn { border: 1.5px solid ButtonText; }
}
