:root {
  --bg: #0f1115; --card: #181b22; --card2: #20242d; --line: #2b303b;
  --text: #e9ecf1; --muted: #8b93a3; --accent: #4ade80; --accent-ink: #052e16;
  --danger: #f87171; --warn: #fbbf24;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; }
button, input { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

.shell { max-width: 960px; margin: 0 auto; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 0 12px; }
header.top h1 { font-size: 1.35rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
nav.tabs button { flex: 1; background: none; border: 0; padding: 12px 4px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; font-size: .8rem; }
nav.tabs button .ic { font-size: 1.35rem; line-height: 1; }
nav.tabs button.on { color: var(--accent); }
@media (min-width: 720px) {
  nav.tabs { position: static; border: 0; background: none; gap: 8px; padding: 0 0 12px; }
  nav.tabs button { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 8px 16px; border-radius: 999px;
    font-size: .95rem; background: var(--card); }
  nav.tabs button.on { background: var(--accent); color: var(--accent-ink); }
  .shell { padding-bottom: 40px; }
}

.btn { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px;
  cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { width: 100%; padding: 18px; font-size: 1.15rem; border-radius: 16px; }
.btn.sm { padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.98); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.tile { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  overflow: hidden; padding: 0; text-align: left; cursor: pointer; display: block; width: 100%; }
.tile .pic { aspect-ratio: 4/3; background: var(--card2) center/cover no-repeat; display: grid; place-items: center;
  font-size: 2.2rem; color: var(--muted); }
.tile .meta { padding: 8px 10px 10px; }
.tile .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { position: absolute; top: 8px; right: 8px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: .8rem; border-radius: 999px; padding: 2px 9px; }
.tile.done { border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--card2); border-radius: 999px; padding: 3px 10px; font-size: .8rem; color: var(--muted); }
.chip.goal { color: var(--accent); }
.chip.limit { color: var(--warn); }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number] { width: 100%; background: var(--card2);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--text); }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end;
  justify-content: center; z-index: 50; }
.sheet { background: var(--bg); border: 1px solid var(--line); width: 100%; max-width: 560px; max-height: 92dvh;
  overflow: auto; border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 720px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
.sheet .hero { width: 100%; aspect-ratio: 16/9; border-radius: 14px; background: var(--card2) center/cover no-repeat; }

.stepper { display: flex; align-items: stretch; gap: 6px; }
.stepper button { width: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2);
  font-size: 1.4rem; cursor: pointer; }
.stepper input { text-align: center; font-size: 1.3rem; font-weight: 700; }

.setrow { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; }
.setrow .n { width: 24px; color: var(--muted); }
.setrow .v { flex: 1; font-weight: 600; }
.x { background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }

.warn { color: var(--warn); font-size: .85rem; }
.err { color: var(--danger); font-size: .9rem; min-height: 1.2em; }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }

.auth { max-width: 380px; margin: 0 auto; padding: 12vh 16px 24px; }
.auth h1 { text-align: center; margin-bottom: 20px; }
.timer { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; z-index: 100; }
details.wk summary { cursor: pointer; list-style: none; }
details.wk summary::-webkit-details-marker { display: none; }

/* filters / chips */
.filters { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.filters::-webkit-scrollbar { display: none; }
.fchip { flex: none; background: var(--card); border: 1px solid var(--line); color: var(--muted); border-radius: 999px;
  padding: 5px 13px; font-size: .85rem; cursor: pointer; }
.fchip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }

/* rest timer pill */
.rest { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px; background: var(--card2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 8px 6px 16px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.rest .rt { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.15rem; min-width: 3.2ch; text-align: center; }
.rest.go { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.rest.go .muted, .rest.go .x { color: var(--accent-ink); }
@media (min-width: 720px) { .rest { bottom: 24px; } }
.toast { bottom: calc(140px + env(safe-area-inset-bottom)); z-index: 100; }
@media (min-width: 720px) { .toast { bottom: 80px; } }

/* progress */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 12px; text-align: left; cursor: default; }
button.stat { cursor: pointer; }
.stat .big { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.meter { height: 6px; background: var(--card2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.mrow { width: 100%; text-align: left; cursor: pointer; }
.mrow .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .meter { margin: 6px 0 3px; }
.pic.thumb { width: 52px; height: 52px; aspect-ratio: 1; border-radius: 10px; flex: none; font-size: 1.2rem; }

/* charts */
.chart { position: relative; }
.svgchart { width: 100%; height: auto; display: block; touch-action: pan-y; overflow: visible; }
.svgchart .grid { stroke: var(--line); stroke-width: 1; }
.svgchart .grid.base { stroke: var(--muted); opacity: .5; }
.svgchart .ax { fill: var(--muted); font-size: 11px; }
.svgchart .ax.goal { fill: var(--warn); }
.svgchart .goalline { stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 5 4; opacity: .8; }
.svgchart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.svgchart .dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.svgchart .dot.best { fill: var(--accent); stroke: var(--text); }
.svgchart .cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.svgchart .bar { fill: var(--accent); opacity: .5; }
.svgchart .bar.cur, .svgchart .bar.hover { opacity: 1; }
.sheet .svgchart .dot { stroke: var(--bg); }
.tip { position: absolute; top: -4px; transform: translate(-50%, -100%); background: var(--card2); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 10px; pointer-events: none; white-space: nowrap; z-index: 5; }
.tip[hidden] { display: none; }
@media (max-width: 380px) { .stat .big { font-size: 1.3rem; } }
.stacked .rest { display: none; }
/* while a sheet is open the rest pill moves to the top so it never covers the form */
body:has(.overlay) .rest { bottom: auto; top: calc(10px + env(safe-area-inset-top)); }
button.setrow { width: 100%; font: inherit; color: inherit; }
.pic { background: var(--card2) center/cover no-repeat; display: grid; place-items: center; color: var(--muted); }
.pic.thumb { font-size: 1.3rem; }
a.btn { color: var(--text); text-decoration: none; display: block; }

/* segmented control (sub-views inside a tab) */
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.seg button { flex: 1; background: none; border: 0; border-radius: 9px; padding: 8px 4px; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--card2); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
@media (min-width: 720px) { .seg { max-width: 320px; } }

.spark { width: 110px; height: 26px; flex: none; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.spark .dot { fill: var(--accent); }
.up { color: var(--accent); }
.gsrow { display: flex; align-items: center; gap: 10px; }
.gsrow .gname { width: 84px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.gsrow .meter { flex: 1; margin: 0; height: 8px; }
.gsrow .gval { width: 36px; text-align: right; }

/* body diagram */
.bd { display: flex; gap: 10px; justify-content: center; }
.bd-col { flex: 1; max-width: 170px; text-align: center; }
.bd.small .bd-col { max-width: 120px; }
.bd.large .bd-col { max-width: 240px; }
.bd-view { width: 100%; height: auto; display: block; }
.bd-label { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.bd-sil ellipse, .bd-sil path { fill: var(--card2); stroke: var(--line); stroke-width: .8; }
.bd-m { fill: #2c323e; stroke: var(--bg); stroke-width: .7; stroke-linejoin: round; }
.bd-m.p { fill: var(--accent); }
.bd-m.s { fill: var(--accent); opacity: .42; }
.bd-m.h { fill: var(--accent); }
.bd-m.tap { cursor: pointer; }
.bd-m.tap:hover { stroke: var(--text); stroke-width: 1.2; }
.bd-detail path, .bd-detail ellipse, .bd-detail circle { fill: none; stroke: var(--bg); stroke-width: .9; stroke-linecap: round; opacity: .75; }
.preset summary { cursor: pointer; }
.sheet > * { flex-shrink: 0; } /* keep rows (chips, buttons) at natural height inside a scrolling sheet */

select { width: auto; max-width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 7px 10px; color: var(--text); font: inherit; font-size: .85rem; }
label.f select { width: 100%; padding: 12px; font-size: 1rem; }
.selbar { position: sticky; bottom: -16px; display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 10px; box-shadow: 0 -8px 20px rgba(0,0,0,.35); z-index: 3; }
.selbar[hidden] { display: none; }
input[type=checkbox] { accent-color: var(--accent); width: 20px; height: 20px; }

/* sync status pill (header) */
.status { border: 1px solid var(--line); background: var(--card2); color: var(--muted); border-radius: 999px;
  padding: 4px 10px; font-size: .78rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.status.off { color: var(--warn); border-color: var(--warn); }
.status[hidden] { display: none; }

/* search field + hints */
input[type=search], input[type=datetime-local] { width: 100%; background: var(--card2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; color: var(--text); -webkit-appearance: none; appearance: none; }
input[type=search].search { padding-left: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b93a3' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 10px center; background-size: 18px; }
.hint { color: var(--muted); font-size: .9rem; background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* editable set rows (sheet) and exercise rows in a past workout (history) */
.setrow.tap { cursor: pointer; }
.setrow.tap:hover { border-color: var(--muted); }
.setrow.on { border-color: var(--accent); background: var(--card2); }
button.hrow { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 6px; border-radius: 12px;
  background: none; border: 1px solid transparent; color: inherit; cursor: pointer; }
button.hrow:hover, button.hrow:focus-visible { border-color: var(--line); background: var(--card2); }
button.hrow:disabled { cursor: default; opacity: .7; }
button.hrow .pic { width: 56px; height: 56px; aspect-ratio: 1; border-radius: 10px; flex: none; font-size: 1.2rem; }

/* duplicate exercises card */
.dup { border-color: var(--warn); }
.dup .btn { flex: none; }
