/* Exercises — "Minimal sage" theme (design handoff: minimal UI redesign, section 7a) */

:root {
  --bg: #f6f6f1;
  --card: #fdfdf9;
  --ink: #26271f;
  --muted: #a3a596;        /* meta */
  --muted2: #83857a;       /* secondary */
  --line: #e3e4d8;
  --line-strong: #dcddd0;
  --check-border: #cfd1c2;
  --accent: #5c7a52;
  --accent-dark: #4c6a44;  /* text on tint */
  --accent-soft: #e8eee0;
  --seg-rest: #dfe0d3;
  --danger: #a8574a;
  --toast-bg: #26271f;
  --toast-ink: #f3f3ec;
  --bar-shadow: 0 6px 20px rgba(38, 39, 31, 0.12);
  --content-pad: 90px;
  /* Top clearance for the status bar / notch (0 in a desktop/iPad window). */
  --safe-top: env(safe-area-inset-top, 0px);
  /* Left inset applied only in an installed window that has OS traffic-light
     controls (iPad / macOS) — see the .app-windowed class set from app.js. */
  --win-controls: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1c16; --card: #24251d; --ink: #f3f3ec;
    --muted: #7f8174; --muted2: #9fa193;
    --line: #303128; --line-strong: #3a3b31; --check-border: #4a4c41;
    --accent: #5c7a52; --accent-dark: #aec49f; --accent-soft: #2a3124;
    --seg-rest: #34352b;
  }
}
:root[data-theme="light"] {
  --bg: #f6f6f1; --card: #fdfdf9; --ink: #26271f;
  --muted: #a3a596; --muted2: #83857a;
  --line: #e3e4d8; --line-strong: #dcddd0; --check-border: #cfd1c2;
  --accent: #5c7a52; --accent-dark: #4c6a44; --accent-soft: #e8eee0;
  --seg-rest: #dfe0d3;
}
:root[data-theme="dark"] {
  --bg: #1b1c16; --card: #24251d; --ink: #f3f3ec;
  --muted: #7f8174; --muted2: #9fa193;
  --line: #303128; --line-strong: #3a3b31; --check-border: #4a4c41;
  --accent: #5c7a52; --accent-dark: #aec49f; --accent-soft: #2a3124;
  --seg-rest: #34352b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Helvetica Neue", Helvetica, Arial, sans-serif;
  padding-bottom: calc(var(--content-pad) + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
img { -webkit-user-drag: none; user-select: none; }

main { max-width: 1180px; margin: 0 auto; }

.iconbtn {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted);
}
.iconbtn:active { background: var(--line); }
.iconbtn svg { width: 18px; height: 18px; }

/* ————— filter tabs (text links, no chips) ————— */
/* The filter bar sticks to the top and stays put while the grid scrolls under
   it. Its top padding reserves room for the status bar / window controls so the
   OS close/minimise/maximise buttons never land on the tabs. */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding-top: var(--safe-top);
  transition: box-shadow .2s, border-color .2s;
  border-bottom: 1px solid transparent;
}
.topbar.stuck { border-bottom-color: var(--line); }
.chips {
  display: flex; gap: 18px; align-items: center;
  overflow-x: auto; scrollbar-width: none;
  padding: 6px 18px 12px;
}
/* In an installed iPad/Mac window, start the tabs to the right of the OS
   traffic-light controls (var is 0 everywhere else, incl. iPhone). */
.topbar .chips { padding-left: calc(18px + var(--win-controls)); }
:root.app-windowed { --win-controls: 78px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  font-size: 15px; color: var(--muted);
  padding: 0 0 4px; border-bottom: 2px solid transparent; border-radius: 0;
  transition: color .18s ease, border-color .18s ease;
}
.chip.on { color: var(--ink); font-weight: 700; border-bottom-color: var(--accent); }
.themebtn { color: var(--muted); padding: 4px; }
.themebtn svg { width: 18px; height: 18px; display: block; }
/* tab links carry 4px padding + 2px underline under their text, so their text
   sits ~3px above the flex row's center — lift the icon to match it */
.chips .themebtn { margin-left: auto; flex: 0 0 auto; margin-bottom: 6px; }
.chips.sub { padding-top: 0; gap: 14px; }
.chips.sub .chip { font-size: 12.5px; }

/* ————— exercise grid ————— */
.grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 18px 16px; padding: 4px 16px 24px;
}
@media (min-width: 768px)  { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.group-head {
  grid-column: 1 / -1;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); padding: 8px 2px 0;
}
.gcard {
  text-align: center;
  display: flex; flex-direction: column; gap: 5px;
  transition: transform .08s;
  cursor: pointer;
}
.gcard:active { transform: scale(0.97); }
.g-img { position: relative; }
.gcard img { width: 100%; aspect-ratio: 120 / 100; object-fit: contain; display: block; }
img[src^="img/gen/"] { border-radius: 18px; }
.gcard .g-name { font-size: 13.5px; font-weight: 600; line-height: 1.25; }
.gcard .g-meta {
  display: flex; justify-content: center; gap: 6px;
  font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums;
  min-height: 17px; margin-top: -3px;
}
.g-meta .kg { color: var(--accent); font-weight: 600; }

/* quick-log check — 26px circle, 44px hit area */
.qlog {
  position: absolute; top: -1px; right: -1px;
  width: 44px; height: 44px; padding: 9px;
  display: grid; place-items: center;
  border-radius: 50%;
}
.qlog i {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1.5px solid var(--check-border);
  background: color-mix(in srgb, var(--card) 85%, transparent);
  color: var(--muted);
}
.qlog svg { width: 13px; height: 13px; }
.qlog.logged i { background: var(--accent); border-color: var(--accent); color: #f6f6f1; }

/* ————— fullscreen player ————— */
.player-overlay[hidden] { display: none; }
.player-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg);
  display: flex;
}
/* The player content lives in a card. On phones it fills the screen; on roomy
   screens (iPad/Mac) it becomes a centred lightbox — see the media query below. */
.p-card {
  flex: 1; min-height: 0; width: 100%;
  display: flex; flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 20px calc(16px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  background: var(--bg);
}
@media (min-width: 768px) and (min-height: 600px) {
  .player-overlay {
    background: rgba(24, 25, 20, 0.5);
    align-items: center; justify-content: center;
    padding: 24px;
  }
  .p-card {
    flex: 0 1 auto; width: 448px; max-width: 100%; max-height: 100%;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
    padding: 16px 26px 24px;
  }
}
.p-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.p-count { font-size: 12px; color: var(--muted2); font-variant-numeric: tabular-nums; font-weight: 600; }
.p-segments { display: flex; gap: 4px; margin-top: 10px; }
.p-segments.many { gap: 1.5px; }
.p-segments i { flex: 1; height: 3px; border-radius: 2px; background: var(--seg-rest); }
.p-segments i.done { background: var(--accent); }
.p-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 3px; max-width: 520px; margin: 0 auto; width: 100%;
}
.p-body.slide { animation: slidein .22s ease; }
@keyframes slidein { from { opacity: 0; transform: translateX(26px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .p-body.slide { animation: none; } }
.p-img { width: min(52vw, 190px); }
.p-img img { width: 100%; border-radius: 14px; }
.p-name { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin-top: 8px; }
.p-pt { font-size: 13px; color: var(--muted2); }
.p-cue { font-size: 12.5px; color: var(--muted2); margin-top: 4px; min-height: 1.4em; }
.p-badges { display: flex; gap: 7px; margin-top: 9px; align-items: center; }
.p-badges .kg { background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; border-radius: 8px; padding: 3px 10px; font-size: 13px; }
.p-badges .bside { border: 1.5px solid var(--line-strong); border-radius: 8px; padding: 3px 10px; font-size: 12px; color: var(--muted2); font-weight: 600; }
.wedit { display: inline-flex; align-items: center; gap: 6px; }
.wbtn {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  font-size: 18px; font-weight: 500; display: grid; place-items: center; line-height: 1;
}
.wbtn:active { transform: scale(0.94); }
.wval {
  background: var(--accent-soft); color: var(--accent-dark); font-weight: 700;
  border-radius: 8px; padding: 3px 10px; font-size: 13px;
  font-variant-numeric: tabular-nums;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.wval b { font-weight: 800; }
.wval:active { background: var(--accent); color: #fff; }
.editbtn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1.5px solid var(--line-strong); border-radius: 8px;
  padding: 3px 10px; font-size: 12px; color: var(--muted2); font-weight: 600;
}
.editbtn svg { width: 12px; height: 12px; }
.editbtn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg {
  display: inline-flex; margin-top: 12px;
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px;
  background: var(--card);
}
.seg button { padding: 3px 14px; border-radius: 999px; font-size: 11.5px; font-weight: 600; color: var(--muted2); }
.seg button.on { background: var(--ink); color: var(--bg); }

.stepper { display: flex; align-items: center; gap: 18px; margin-top: 14px; }
.stepper button {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  font-size: 26px; font-weight: 500; color: var(--ink);
  display: grid; place-items: center; line-height: 1;
}
.stepper .val { min-width: 96px; }
.stepper .val b { font-size: 62px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; display: block; line-height: 1; }
.stepper .val span { font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); display: block; margin-top: 4px; }

.p-clock { margin-top: 10px; }
.p-clock b { font-size: 62px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.05; display: block; }
.p-clock b.paused { color: var(--muted); }
.p-clock span { font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

.donebtn {
  display: block; width: 100%; max-width: 520px; margin: 18px auto 0;
  padding: 15px; border-radius: 16px;
  background: var(--accent); color: #f7f8f2;
  font-size: 15.5px; font-weight: 700; text-align: center;
  flex: 0 0 auto;
}
.donebtn:active { transform: scale(0.985); }
.p-nextline { text-align: center; font-size: 11.5px; color: var(--muted2); margin-top: 9px; min-height: 1.4em; }
.p-nextline b { color: var(--ink); font-weight: 600; }

.p-done-screen { text-align: center; padding: 40px 0; }
.p-done-screen h2 { font-size: 30px; }
.p-done-screen p { color: var(--muted2); margin-top: 6px; }

/* ————— routine ————— */
.routine-wrap, .history-wrap { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-top) + 4px) 18px 32px; }
.r-hero { text-align: center; padding: 26px 0 18px; }
.r-hero h2 { font-size: 30px; letter-spacing: -0.02em; }
.r-hero .tagline { color: var(--muted2); font-size: 14px; margin-top: 4px; }
.r-hero .r-stats { display: flex; gap: 18px; justify-content: center; margin-top: 14px; color: var(--muted2); font-size: 12.5px; }
.r-hero .r-stats b { color: var(--ink); font-weight: 600; }
.bigbtn {
  display: block; width: 100%;
  margin-top: 18px; padding: 15px;
  border-radius: 16px;
  background: var(--accent); color: #f7f8f2;
  font-size: 16px; font-weight: 700; text-align: center;
}
.bigbtn.ghost { background: transparent; color: var(--muted2); border: 1px solid var(--line); font-weight: 600; }
.blocklist { margin-top: 22px; display: grid; gap: 8px; }
.block-row {
  display: flex; justify-content: space-between; align-items: baseline;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 11px 14px;
}
.block-row .b-name { font-size: 14px; font-weight: 600; }
.block-row .b-count { font-size: 12px; color: var(--muted2); font-variant-numeric: tabular-nums; }

.series-card {
  margin-top: 16px; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 15px;
  display: grid; gap: 8px;
}
.series-card .s-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.series-card .s-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.series-card .s-meta { font-size: 12px; color: var(--muted2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.series-card .block-row { background: var(--bg); }
.series-card .s-tip { font-size: 12px; color: var(--muted2); line-height: 1.5; padding: 0 2px; }
.series-card .s-actions { display: flex; gap: 10px; }
.series-card .s-actions .bigbtn { margin-top: 6px; padding: 12px; font-size: 15px; }
.series-card .s-actions .bigbtn.ghost { flex: 0 0 32%; }
.r-src { margin-top: 20px; font-size: 11.5px; color: var(--muted2); line-height: 1.6; }

.player { text-align: center; padding-top: 8px; }
.pl-block { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.pl-name { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin-top: 5px; min-height: 1.3em; }
.pl-side {
  display: inline-block; margin-left: 7px;
  font-size: 13px; font-weight: 700; color: var(--accent);
  border: 1.5px solid var(--accent); border-radius: 7px;
  padding: 0 6px; vertical-align: 3px;
}
.pl-cue { color: var(--muted2); font-size: 13px; margin-top: 3px; min-height: 1.5em; }
.pl-fig { display: grid; place-items: center; margin: 6px 0 2px; }
.pl-fig img { width: min(56vw, 240px); border-radius: 14px; }
.pl-phase { font-size: 12px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.pl-phase.rest { color: var(--muted); }
.pl-clock {
  font-size: 74px; font-weight: 600; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; line-height: 1.05;
}
.pl-next { font-size: 13px; color: var(--muted2); min-height: 1.5em; margin-top: 2px; }
.pl-next b { color: var(--ink); font-weight: 600; }
.progress { height: 4px; border-radius: 2px; background: var(--seg-rest); margin: 18px 0 6px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .4s; }
.pl-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted2); font-variant-numeric: tabular-nums; }
.pl-controls { display: flex; justify-content: center; gap: 14px; margin-top: 22px; }
.pl-controls .ctl {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; color: var(--ink);
}
.pl-controls .ctl.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 64px; height: 64px; }
.pl-controls .ctl svg { width: 20px; height: 20px; }
.pl-controls .ctl.primary svg { width: 24px; height: 24px; }

/* ————— history ————— */
.h-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 2px; }
.h-title { font-size: 22px; font-weight: 600; }
.h-sub { color: var(--muted2); font-size: 12px; margin-bottom: 14px; }
.day { margin-bottom: 16px; }
.day h3 { font-size: 12.5px; color: var(--muted2); font-weight: 650; margin-bottom: 6px; }
.day .rows { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.h-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 10px 13px; font-size: 13px; }
.h-row span:first-child { font-weight: 600; }
.h-row + .h-row { border-top: 1px solid color-mix(in srgb, var(--line) 72%, var(--card)); }
.h-row .h-val { color: var(--muted2); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { text-align: center; color: var(--muted2); padding: 48px 20px; font-size: 14px; }
.databar { display: flex; gap: 18px; justify-content: center; margin-top: 22px; }
.databar button { font-size: 12px; font-weight: 600; color: var(--muted2); padding: 6px 8px; border-radius: 8px; }
.databar button:active { background: var(--line); }
.databar .danger { color: var(--danger); }

/* ————— gist sync ————— */
.sync-section { margin-top: 26px; }
.sync-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 14px; display: grid; gap: 10px;
}
.sync-help { font-size: 12px; color: var(--muted2); line-height: 1.55; }
.sync-form { display: flex; gap: 8px; }
.sync-form input {
  flex: 1; min-width: 0;
  font: 13px/1.4 inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 10px;
  padding: 9px 12px;
}
.sync-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sync-form button {
  flex: 0 0 auto;
  background: var(--accent); color: #f7f8f2;
  font-size: 13px; font-weight: 700;
  border-radius: 10px; padding: 9px 16px;
}
.sync-form button:disabled { opacity: 0.6; }
.sync-status { font-size: 12.5px; color: var(--muted2); }
.sync-status b { color: var(--ink); font-weight: 600; }
.sync-status code { font-family: inherit; color: var(--accent-dark); background: var(--accent-soft); border-radius: 5px; padding: 1px 5px; }
.sync-actions { display: flex; gap: 16px; }
.sync-actions button { font-size: 12px; font-weight: 600; color: var(--accent-dark); padding: 2px 0; }
.sync-actions .danger { color: var(--danger); }

/* ————— floating tab bar — content-hugging, label under every icon ————— */
.tabbar {
  /* overlap the home-indicator inset instead of stacking on it: ~40px on a
     notched iPhone, the spec's 14px minimum everywhere else */
  position: fixed; left: 50%; bottom: max(14px, calc(6px + env(safe-area-inset-bottom, 0px)));
  transform: translateX(-50%);
  z-index: 30;
  display: inline-flex;            /* hugs its tabs — no gaps, no stretch */
  background: var(--card);         /* fully opaque */
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 5px;
  box-shadow: var(--bar-shadow);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 16px 5px; border-radius: 17px;
  color: var(--muted2);
  transition: background .18s ease, color .18s ease;
}
.tabbar button span { display: block; font-size: 11px; font-weight: 500; color: var(--muted2); }
.tabbar button svg { width: 21px; height: 21px; display: block; }
/* active tab: one sage capsule wrapping icon *and* label */
.tabbar button.on { background: var(--accent-soft); color: var(--accent); }
.tabbar button.on span { color: var(--ink); font-weight: 650; }
@media (min-width: 768px) {
  .tabbar { border-radius: 26px; padding: 6px; bottom: max(20px, calc(6px + env(safe-area-inset-bottom, 0px))); }
  .tabbar button { padding: 8px 22px 7px; border-radius: 21px; gap: 3px; }
  .tabbar button span { font-size: 13px; }
  .tabbar button svg { width: 25px; height: 25px; }
}
@media (min-width: 1200px) {
  .tabbar { border-radius: 24px; }
  .tabbar button { padding: 7px 20px 6px; border-radius: 19px; }
  .tabbar button span { font-size: 12.5px; }
  .tabbar button svg { width: 23px; height: 23px; }
}
/* the labelled bar is taller and sits higher on tablet/desktop (~96px of the
   bottom edge) — give the page and the toast room to clear it */
@media (min-width: 768px) {
  :root { --content-pad: 120px; }
  #toast { bottom: calc(106px + env(safe-area-inset-bottom, 0px)); }
}

/* ————— toast ————— */
#toast {
  position: fixed; left: 50%; bottom: calc(64px + 18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(8px);
  background: var(--toast-bg); color: var(--toast-ink);
  font-size: 13px; font-weight: 600;
  padding: 9px 16px; border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
