/* MuscleMap — mobile-first styles. No frameworks. */
:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #ecebe5;
  --line: #dddbd3;
  --text: #16181a;
  --muted: #6b6e70;
  --accent: #3e6b00;          /* text/icons on light */
  --accent-fill: #c8f03c;     /* volt fill */
  --on-accent: #16180c;
  --danger: #c2331f;
  --body-base: #e8e5dd;
  --body-line: #c8c4b9;
  --muscle: #c4beb0;
  --muscle-line: #f4f3ef;
  --heat-1: #ffd8a8;
  --heat-2: #ffa94d;
  --heat-3: #f76707;
  --heat-4: #c92a2a;
  --radius: 16px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101214;
    --surface: #191c1f;
    --surface-2: #22262a;
    --line: #2c3136;
    --text: #eef0f1;
    --muted: #8d9499;
    --accent: #c8f03c;
    --accent-fill: #c8f03c;
    --on-accent: #12140a;
    --danger: #ff6b57;
    --body-base: #2a2f34;
    --body-line: #3a4046;
    --muscle: #3b4249;
    --muscle-line: #191c1f;
    --heat-1: #5c3d1a;
    --heat-2: #a85d12;
    --heat-3: #e8590c;
    --heat-4: #ff4d3d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #101214;
    --surface: #191c1f;
    --surface-2: #22262a;
    --line: #2c3136;
    --text: #eef0f1;
    --muted: #8d9499;
    --accent: #c8f03c;
    --accent-fill: #c8f03c;
    --on-accent: #12140a;
    --danger: #ff6b57;
    --body-base: #2a2f34;
    --body-line: #3a4046;
    --muscle: #3b4249;
    --muscle-line: #191c1f;
    --heat-1: #5c3d1a;
    --heat-2: #a85d12;
    --heat-3: #e8590c;
    --heat-4: #ff4d3d;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

.app { max-width: 560px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 26px; height: 26px; fill: var(--accent); }
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.top-actions { display: flex; gap: 8px; }

main { flex: 1; padding: 4px 16px calc(var(--tab-h) + var(--safe-b) + 24px); }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  max-width: 560px; margin: 0 auto;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; fill: currentColor; }
.tab.is-active { color: var(--text); }
.tab.is-active svg { fill: var(--accent); }

/* Generic bits */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; font-weight: 700; }
.h2 { font-size: 18px; font-weight: 800; margin: 0; letter-spacing: -0.01em; }
.h3 { font-size: 15px; font-weight: 700; margin: 0; }
.section-title { margin: 22px 2px 8px; font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  background: var(--surface-2); font-weight: 700; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.btn.primary { background: var(--accent-fill); color: var(--on-accent); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.btn:active, .icon-btn:active, .chip:active { transform: scale(.97); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.is-on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-fill); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); font-size: 11px; font-weight: 700; color: var(--muted); }
.badge.accent { background: var(--accent-fill); color: var(--on-accent); }

.segmented { display: inline-grid; grid-auto-flow: column; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.segmented button { min-height: 34px; padding: 0 16px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted); }
.segmented button.is-on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

input.field, select.field {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid transparent; outline: none;
}
input.field:focus, select.field:focus { border-color: var(--accent); }

.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty .h2 { color: var(--text); margin-bottom: 6px; }

/* ---------- Body view ---------- */
.body-toolbar { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 6px; }
.anatomy-wrap { position: relative; display: flex; justify-content: center; }
.anatomy { width: 100%; max-width: 300px; max-height: calc(100vh - 270px); min-height: 380px; height: auto; touch-action: manipulation; }
.anatomy .silhouette { fill: var(--body-base); stroke: var(--body-line); stroke-width: .8; }
.anatomy .head { fill: var(--body-base); stroke: var(--body-line); stroke-width: .8; }
.anatomy .m { fill: var(--muscle); stroke: var(--muscle-line); stroke-width: 1.1; stroke-linejoin: round; cursor: pointer; transition: fill .18s; }
.anatomy .m:hover { fill: color-mix(in srgb, var(--muscle) 70%, var(--accent-fill)); }
.anatomy .m.h1 { fill: var(--heat-1); }
.anatomy .m.h2 { fill: var(--heat-2); }
.anatomy .m.h3 { fill: var(--heat-3); }
.anatomy .m.h4 { fill: var(--heat-4); }
.anatomy .m.is-sel { fill: var(--accent-fill); }
.anatomy .deco { fill: none; stroke: var(--muscle-line); stroke-width: 1; pointer-events: none; opacity: .8; }
.anatomy-label { position: absolute; top: 6px; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .08em; }
.anatomy-label.l { left: 6px; } .anatomy-label.r { right: 6px; }
.heat-legend { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.heat-legend i { width: 18px; height: 8px; border-radius: 2px; display: inline-block; }

.hint-card { display: flex; gap: 12px; align-items: center; }
.hint-card .pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-fill); box-shadow: 0 0 0 0 var(--accent-fill); animation: pulse 2s infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* Exercise list item */
.ex { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.ex:first-child { border-top: 0; }
.ex-main { flex: 1; min-width: 0; }
.ex-name { font-weight: 700; }
.ex-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.ex-cue { margin-top: 6px; font-size: 13px; color: var(--muted); }
.ex .add { flex: none; }
.ex .add.is-added { background: transparent; border: 1px solid var(--line); color: var(--muted); }

/* ---------- Program view ---------- */
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 10px; }
.plist { list-style: none; margin: 0; padding: 0; }
.pitem {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 10px 10px 4px; margin-bottom: 8px; touch-action: pan-y;
}
.pitem.dragging { opacity: .95; box-shadow: 0 12px 28px rgb(0 0 0 / .25); border-color: var(--accent); position: relative; z-index: 5; }
.handle { width: 36px; height: 44px; display: grid; place-items: center; color: var(--muted); touch-action: none; cursor: grab; flex: none; }
.handle svg { width: 20px; height: 20px; fill: currentColor; }
.pnum { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; font-weight: 800; flex: none; }
.ptarget { font-size: 13px; color: var(--muted); }
.ptarget b { color: var(--text); }
.moves { display: flex; flex-direction: column; }
.moves button { width: 32px; height: 22px; color: var(--muted); display: grid; place-items: center; }
.moves svg { width: 16px; height: 16px; fill: currentColor; }

.stepper { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: 12px; }
.stepper button { width: 44px; height: 44px; font-size: 20px; font-weight: 700; }
.stepper span { min-width: 34px; text-align: center; font-weight: 800; }

/* ---------- Train view ---------- */
.next-card { background: #16191c; color: #f1f2f2; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.next-card .tiny { color: var(--accent-fill); }
.next-card .h2 { margin-top: 4px; }
.next-card .muted { color: #9aa1a6; }
.next-card .muted b { color: #f1f2f2; }
.next-card .btn.primary { margin-top: 12px; }
.tip { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: rgb(255 255 255 / .08); font-size: 13px; }

.wcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.wcard.is-current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.wcard-head { display: flex; align-items: center; gap: 12px; padding: 14px; width: 100%; text-align: left; }
.wcheck { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; font-size: 13px; font-weight: 800; color: var(--muted); }
.wcard.is-done .wcheck { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent); }
.wcard.is-done .wname { color: var(--muted); }
.wname { font-weight: 700; }
.wsub { font-size: 13px; color: var(--muted); }
.wbody { padding: 0 14px 14px; }
.sets { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
.sets th { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); text-align: center; padding: 0 2px; }
.sets td { text-align: center; padding: 0 3px; }
.sets td.sn { width: 30px; font-weight: 800; color: var(--muted); }
.sets td.prev { font-size: 12px; color: var(--muted); width: 70px; }
.sets input {
  width: 100%; height: 42px; text-align: center; border-radius: 10px;
  border: 1px solid transparent; background: var(--surface-2); font-weight: 700; font-size: 16px; outline: none;
}
.sets input:focus { border-color: var(--accent); }
.sets tr.done input { background: color-mix(in srgb, var(--accent-fill) 22%, var(--surface)); }
.setok { width: 42px; height: 42px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; color: var(--muted); }
tr.done .setok { background: var(--accent-fill); color: var(--on-accent); }
.wactions { display: flex; gap: 8px; margin-top: 6px; }

.rest {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 25;
  bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
  display: flex; align-items: center; gap: 10px;
  background: var(--text); color: var(--bg); border-radius: 999px; padding: 6px 6px 6px 16px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .3);
}
.rest-label { font-size: 12px; font-weight: 700; opacity: .7; }
.rest-time { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; min-width: 46px; }
.rest button { height: 34px; min-width: 34px; padding: 0 10px; border-radius: 999px; background: color-mix(in srgb, var(--bg) 18%, transparent); font-weight: 800; }

/* ---------- Progress view ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.vol-row { display: grid; grid-template-columns: 92px 1fr 34px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.vol-track { height: 10px; border-radius: 6px; background: var(--surface-2); position: relative; overflow: hidden; }
.vol-fill { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: var(--accent-fill); }
.vol-fill.low { background: var(--heat-2); }
.vol-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--muted); opacity: .5; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-fill); opacity: .14; }
.chart .pt { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .lbl { fill: var(--text); font-size: 11px; font-weight: 700; }
.log-day { padding: 12px 0; border-top: 1px solid var(--line); }
.log-day:first-child { border-top: 0; }
.log-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 2px 0; }
.log-line span:last-child { color: var(--muted); text-align: right; }

/* ---------- Sheet / toast ---------- */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 560px; margin: 0 auto; max-height: 86vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding-bottom: var(--safe-b); animation: up .25s cubic-bezier(.2,.8,.2,1);
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 2px; flex: none; }
.sheet-body { overflow-y: auto; padding: 8px 16px 20px; -webkit-overflow-scrolling: touch; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.toast {
  position: fixed; left: 50%; top: calc(14px + var(--safe-t)); z-index: 60;
  transform: translate(-50%, -150%); transition: transform .25s;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  max-width: calc(100% - 32px);
}
.toast.show { transform: translate(-50%, 0); }

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