:root {
    --bg: #3a0d0d; --bg2: #1c0606; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #fff1f1; --muted: #f3c4c4; --accent: #ff8787; --accent-ink: #2d0505; --field: rgba(255,255,255,.08);
    --soft: rgba(255,135,135,.16); --good: #8ce99a; --warn: #ffd43b; --warn-bg: rgba(255,212,59,.13); --bad: #ffa8a8; --gold: #ffd43b;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #fff5f5; --bg2: #ffe3e3; --card: #fff; --line: #f5c2c2; --ink: #2b0a0a; --muted: #6f3a3a;
            --accent: #c92a2a; --accent-ink: #fff; --field: #fffafa; --soft: #ffe8e8; --good: #2b8a3e; --warn: #a15c00; --warn-bg: #fff4d6; --bad: #c92a2a; --gold: #a15c00; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #fff5f5; --bg2: #ffe3e3; --card: #fff; --line: #f5c2c2; --ink: #2b0a0a; --muted: #6f3a3a;
            --accent: #c92a2a; --accent-ink: #fff; --field: #fffafa; --soft: #ffe8e8; --good: #2b8a3e; --warn: #a15c00; --warn-bg: #fff4d6; --bad: #c92a2a; --gold: #a15c00; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #3a0d0d; --bg2: #1c0606; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #fff1f1; --muted: #f3c4c4; --accent: #ff8787; --accent-ink: #2d0505; --field: rgba(255,255,255,.08);
    --soft: rgba(255,135,135,.16); --good: #8ce99a; --warn: #ffd43b; --warn-bg: rgba(255,212,59,.13); --bad: #ffa8a8; --gold: #ffd43b;
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: clamp(1rem,4vw,2.5rem) 1rem 4rem; display: flex; justify-content: center;
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
       background: var(--bg2) linear-gradient(180deg, var(--bg), var(--bg2) 900px) no-repeat; touch-action: manipulation; }
.app { width: min(560px, 100%); min-width: 0; display: flex; flex-direction: column; }
.col-main, .col-side { display: contents; }
.app > .topbar, .app > .back { order: 0; }
.app > header, .warn-box { order: 1; }
.today { order: 2; }
.progress { order: 3; }
.history { order: 4; }
.settings { order: 5; }
.app > .faq { order: 6; }
.app > footer { order: 7; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.7rem; line-height: 1.2; letter-spacing: -.02em; }
.sub { margin: .4rem 0 0; color: var(--muted); font-size: 1rem; }
h2 { margin: 0 0 .7rem; font-size: 1.15rem; overflow-wrap: anywhere; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label, legend, .label-like { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); padding: 0; }
input[type=text], input[type=search], input[type=date], input[type=time], select, textarea { display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 48px; padding: .6rem .8rem; font: inherit; font-size: 1.05rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; -webkit-appearance: none; appearance: none; }
select { -webkit-appearance: auto; appearance: auto; }
input[type=date], input[type=time] { -webkit-appearance: auto; appearance: auto; }
textarea { resize: vertical; line-height: 1.4; min-height: 84px; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); }
select option { color: #111; background: #fff; }
input:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
::placeholder { color: var(--muted); opacity: .75; }
.hint { margin: .45rem 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.hint:empty { display: none; }
[hidden] { display: none !important; }
.warn-box { margin: 0 0 .9rem; padding: .7rem .9rem; border-radius: 12px; background: var(--warn-bg); border-left: 5px solid var(--warn); font-weight: 600; }

/* buttons */
.primary, .secondary, .danger { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
       font: inherit; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; line-height: 1.2; overflow-wrap: anywhere; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.secondary { border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; }
.secondary.small { width: auto; min-height: 44px; padding: 0 .85rem; font-size: .92rem; margin: 0; }
.danger { border: 1px solid var(--bad); background: transparent; color: var(--bad); font-weight: 600; margin-top: .9rem; }
button:disabled { opacity: .45; cursor: default; }
.link { display: block; min-height: 44px; margin-top: .3rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.err { margin: .4rem 0 0; color: var(--bad); font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.err:empty { margin: 0; }
.msg { margin: 0; color: var(--muted); font-size: .95rem; overflow-wrap: anywhere; }
.msg.show { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; margin: .2rem 0 .8rem; padding: .5rem .75rem; border-radius: 12px; background: var(--soft); color: var(--ink); }
.msg .undo { min-height: 40px; padding: 0 .9rem; border: 1px solid var(--accent); border-radius: 10px; background: none; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }
.settings .msg.show { margin: .8rem 0 0; }
.row-btns { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.row-btns > * { flex: 1 1 9rem; width: auto; }
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: .4rem; }
.tool-grid .wide { grid-column: 1 / -1; }
.settings .tool-grid + label { margin-top: 1.1rem; }
.settings select + .tool-grid { margin-top: 1rem; }


.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; }
.check { display: flex; align-items: center; gap: .55rem; min-height: 44px; margin: .5rem 0 0; color: var(--ink); font-weight: 600; font-size: .95rem; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }
.link.muted { color: var(--muted); }
.today { border: 2px solid var(--accent); }
.lead { margin: 0 0 .7rem; }
.week { margin: 0 0 .8rem; padding: .55rem .75rem; border-radius: 12px; background: var(--soft); overflow-wrap: anywhere; }
.empty { margin: 0 0 .6rem; color: var(--muted); }

/* ready-made plans */
.preset-grid { display: grid; gap: .5rem; margin-bottom: .9rem; }
.preset { display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; min-height: 56px; padding: .6rem .9rem; border: 1px solid var(--accent); border-radius: 14px;
          background: var(--soft); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.preset b { font-size: 1.05rem; }
.preset span { color: var(--muted); font-size: .9rem; }

/* boxes */
.box-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .65rem; }
.box-list:empty { display: none; }
.box { border: 1px solid var(--line); border-left: 6px solid var(--accent); border-radius: 14px; padding: .7rem .8rem .75rem; background: var(--field); min-width: 0; }
.box.editing { opacity: .55; }
.box-top { display: flex; justify-content: space-between; align-items: baseline; gap: .2rem .6rem; flex-wrap: wrap; }
.box-name { margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; min-width: 0; }
h4.box-name { font-size: 1.02rem; }
.badge { font-size: .82rem; font-weight: 700; padding: .1rem .6rem; border-radius: 999px; background: var(--soft); color: var(--ink); border: 1px solid var(--line); white-space: nowrap; }
.box-sub { margin: .15rem 0 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.box-btns { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.mini { flex: 1 1 4.5rem; min-height: 44px; padding: 0 .6rem; border: 1px solid var(--line); border-radius: 10px; background: none; color: var(--accent); font: inherit; font-size: .92rem; font-weight: 700; cursor: pointer; min-width: 0; overflow-wrap: anywhere; }
.mini.strong { flex-basis: 8rem; color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.mini.bad { color: var(--bad); }
.mini.tiny { flex: none; min-height: 40px; padding: 0 .7rem; font-size: .88rem; }
.dl { list-style: none; margin: .45rem 0 0; padding: 0; }
.dl li { padding: .1rem 0; font-size: .95rem; overflow-wrap: anywhere; }
.best-line { margin: .35rem 0 0; color: var(--gold); font-weight: 700; font-size: .92rem; overflow-wrap: anywhere; }
.best-set { margin: .3rem 0 0; overflow-wrap: anywhere; }

/* the workout */
.sess-meta { margin: 0 0 .7rem; color: var(--muted); font-weight: 600; }
.overnight { margin: 0 0 .9rem; padding: .7rem .9rem; border-radius: 12px; background: var(--warn-bg); border-left: 5px solid var(--warn); }
.overnight p { margin: 0; font-weight: 600; }
.overnight .row-btns { margin-top: .6rem; }
.past-fields { margin-bottom: .8rem; }
.pair3 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
.pair3 label { margin-top: 0; }
.ex-list { margin-bottom: .8rem; }
.box.ex { padding-bottom: .8rem; }
.last { margin: .3rem 0 0; font-size: 1rem; overflow-wrap: anywhere; }
.last.first { color: var(--muted); }
.sets { list-style: none; margin: .55rem 0 0; padding: 0; display: grid; gap: .3rem; }
.set { display: flex; align-items: center; gap: .3rem .6rem; padding: .3rem .3rem .3rem .4rem; border-radius: 10px; background: var(--card); border: 1px solid var(--line); min-width: 0; }
.set-n { flex: none; width: 1.9rem; height: 1.9rem; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: .9rem; }
.set.wu .set-n { background: var(--line); color: var(--ink); }
.set-main { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .45rem; }
.set-v { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; min-width: 0; }
.set .mini.tiny { margin-left: auto; }
.set-edit .mini.tiny { margin-left: 0; }
.tag { display: inline-block; padding: 0 .5rem; border-radius: 999px; border: 1px solid var(--line); font-size: .78rem; font-weight: 700; color: var(--muted); vertical-align: middle; }
.tag.best { border-radius: 8px; padding: .05rem .5rem; line-height: 1.35; border-color: var(--gold); color: var(--gold); white-space: normal; }
.set-edit { flex: 1 1 100%; min-width: 0; padding: .2rem .1rem; }
.set-edit .check { margin-top: .2rem; }
.rest { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .35rem .7rem; margin-top: .6rem; padding: .6rem .75rem; border-radius: 12px; background: var(--soft); border: 1px solid var(--accent); }
.rest-lab { font-weight: 700; color: var(--muted); }
.rest-clock { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; justify-self: end; }
.rest-bar { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.rest-bar i { display: block; height: 100%; width: 100%; background: var(--accent); }
.rest-btns { grid-column: 1 / -1; display: flex; gap: .4rem; }
.log { margin-top: .5rem; padding-top: .1rem; }
.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
.fields.k-time { grid-template-columns: minmax(0, 1fr); }
.fields label { margin-top: .5rem; }
.field { min-width: 0; }
.stepper { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--field); }
.stepper input { border: 0; border-radius: 0; text-align: center; font-weight: 700; font-size: 1.15rem; padding: .5rem .2rem; background: transparent; }
.stepper input[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--bad); }
.step { min-height: 48px; border: 0; background: var(--soft); color: var(--ink); font: inherit; font-size: 1.35rem; font-weight: 700; cursor: pointer; padding: 0; }
.log-row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; margin-top: .5rem; }
.log-row .check { margin: 0; flex: none; }
.log-btn { flex: 1 1 10rem; width: auto; }
.box-links { display: flex; flex-wrap: wrap; gap: 0 1.2rem; margin-top: .2rem; }
.box-links .link { margin-top: .1rem; }
.box.ex textarea { min-height: 64px; }
.box .msg.show { margin: .5rem 0 0; }
.add-ex { margin: .2rem 0 .4rem; padding: .2rem .9rem .9rem; border: 1px dashed var(--line); border-radius: 14px; }
.add-ex .row-btns { margin-top: .7rem; }
.add-ex > .secondary { margin-top: .8rem; }
.end-btns { margin-top: 1.2rem; }
.end-btns .danger { margin-top: 0; }
#s-add-open { margin-top: .2rem; }
.plan-ex { margin: .3rem 0 .7rem; }
.pex .rest-pick label { margin-top: .5rem; }
.rest-pick .inline { margin-top: .5rem; }
.inline { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.inline input { width: 5.5rem; flex: none; text-align: center; }
.inline.grow input { flex: 1 1 auto; width: auto; text-align: left; }
.inline.grow .mini { flex: none; }
.unit { color: var(--muted); font-weight: 600; font-size: .92rem; }

/* after finishing */
.done-big { margin: 0; font-size: 1.25rem; font-weight: 800; overflow-wrap: anywhere; }
.done-stats { list-style: none; margin: .8rem 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr)); gap: .5rem; }
.done-stats li { padding: .55rem .7rem; border-radius: 12px; background: var(--soft); border: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.done-stats b { font-size: 1.3rem; overflow-wrap: anywhere; }
.done-stats span { color: var(--muted); font-size: .88rem; }
.g-h { margin: .2rem 0 .4rem; font-size: 1rem; color: var(--gold); }
.best-list { margin: 0; padding-left: 1.2rem; }
.best-list li { margin: .15rem 0; overflow-wrap: anywhere; }
#d-close { margin-top: .6rem; }

/* progress chart */
.detail { margin-top: .6rem; padding-top: .5rem; border-top: 1px solid var(--line); }
.chart-h { margin: .2rem 0 .3rem; font-size: .92rem; color: var(--muted); }
.chart { display: block; width: 100%; height: auto; max-height: 220px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--bg); stroke-width: 1.5; }
.detail .danger { margin-top: 1rem; }
#hist-more { margin-top: .7rem; }
.later { margin-top: .8rem; }
.later .hint { margin: .2rem 0 .6rem; }
.settings .check { margin-top: .8rem; }
.tool-grid { margin-top: 1rem; }

/* questions */
.faq { margin-top: 1.2rem; }
.faq details { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 .5rem; background: var(--card); }
.faq summary { cursor: pointer; padding: .75rem .9rem; font-weight: 600; min-height: 44px; }
.faq details p { margin: 0; padding: 0 .9rem .8rem; color: var(--muted); }
footer { margin-top: 1.4rem; text-align: center; font-size: .9rem; }
footer a { color: var(--muted); }

.back { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin: 0 0 .5rem; padding: 0 1rem 0 .8rem; border: 1px solid var(--line, rgba(127,127,127,.4)); border-radius: 999px; color: var(--muted, var(--mut, inherit)); font-size: .92rem; font-weight: 600; text-decoration: none; background: transparent; }
.back:hover { color: var(--ink, inherit); border-color: currentColor; }
.back:focus-visible { outline: 3px solid var(--accent, var(--acc, #fff)); outline-offset: 2px; }


/* narrow phones */
@media (max-width: 420px) {
    .card { padding: 1rem .8rem; }
    .box { padding: .6rem .65rem .7rem; }
    .tool-grid { grid-template-columns: minmax(0, 1fr); }
    .row-btns > * { flex-basis: 100%; }
    h1 { font-size: 1.5rem; }
    .pair3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .pair3 > :first-child { grid-column: 1 / -1; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
    .stepper { grid-template-columns: 38px minmax(0, 1fr) 38px; }
    .fields label { font-size: .85rem; }
}
@media (max-width: 340px) {
    .fields { grid-template-columns: minmax(0, 1fr); }
}

/* laptops and desktops: the workout on the left, progress and history on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .col-main, .col-side { display: block; min-width: 0; }
    .app > .topbar { grid-row: 1; }
    .app > header { grid-row: 2; }
    .app > .warn-box { grid-row: 3; }
    .app > .col-main { grid-column: 1; grid-row: 4; }
    .app > .col-side { grid-column: 2; grid-row: 4; }
    .app > .settings { grid-row: 5; width: min(760px, 100%); justify-self: center; margin-top: .6rem; }
    .app > .faq { grid-row: 6; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 7; width: min(760px, 100%); justify-self: center; }
    header h1 { font-size: 2.3rem; }
    .preset-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .settings .tool-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .settings .tool-grid .wide { grid-column: auto; }
}
