:root {
  --bg: #0E0F11;
  --card: #1A1C20;
  --card2: #16181B;
  --line: #2C2F35;
  --line2: #23262B;
  --text: #F2F2F0;
  --text2: #C9CBD0;
  --muted: #9A9DA3;
  --dim: #6E7178;
  --lift: #C6F432;
  --lift-bg: #2A3312;
  --run: #6CBCFF;
  --run-bg: #12283A;
  --miss: #FF8A3D;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Barlow', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  /* Nothing should ever scroll sideways; clip stops stray overflow without breaking fixed/sticky bits */
  overflow-x: hidden;
  overflow-x: clip;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: var(--lift); }

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: calc(env(safe-area-inset-top) + 28px) 20px calc(env(safe-area-inset-bottom) + 104px);
}
#app.full { padding-bottom: calc(env(safe-area-inset-bottom) + 24px); }

h1 { margin: 0; font-family: var(--cond); font-size: 44px; line-height: 1; font-weight: 700; }
h2 { margin: 0; font-family: var(--cond); font-size: 30px; line-height: 1.05; font-weight: 700; }
.cond { font-family: var(--cond); font-weight: 700; }
.eyebrow { font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.sub { font-size: 16px; color: var(--muted); line-height: 1.4; }
.small { font-size: 14px; color: var(--muted); line-height: 1.4; }
.muted { color: var(--muted); }
.lift { color: var(--lift); }
.runc { color: var(--run); }
.missc { color: var(--miss); }
.center { text-align: center; }
.grow { flex-grow: 1; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack4 { display: flex; flex-direction: column; gap: 4px; }
.hrow { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }

/* ---------- rows & cards ---------- */
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left; border: none; color: var(--text);
  background: var(--card); border-radius: 14px; padding: 14px 16px; min-height: 56px;
  text-decoration: none;
}
.row.today { box-shadow: inset 0 0 0 2px var(--lift); }
/* Long per-set targets drop to their own line instead of squashing the exercise name */
.row.exrow { flex-wrap: wrap; row-gap: 4px; }
.row.exrow > div:first-child { flex: 1 1 140px; min-width: 0; }
.row.exrow .big { margin-left: auto; }
.row.dashed { background: transparent; border: 1px dashed #3A3E45; color: var(--muted); }
.row .name { font-size: 18px; font-weight: 600; }
.row .meta { font-size: 14px; color: var(--muted); margin-top: 2px; }
.row .meta.lift { color: var(--lift); }
.row .meta.missc { color: var(--miss); }
.row .big { font-family: var(--cond); font-size: 24px; font-weight: 700; white-space: nowrap; }
.unit { font-size: 15px; color: var(--muted); font-family: 'Barlow', sans-serif; font-weight: 500; }
.card { background: var(--card); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.done { gap: 8px; }
.line-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 2px; border-bottom: 1px solid var(--line2); min-height: 48px;
  background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; color: var(--text);
}
.line-item:last-child { border-bottom: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; flex-grow: 1; }
.tag { border-radius: 8px; padding: 5px 10px; font-size: 15px; font-weight: 600; }
.tag.lift { background: var(--lift-bg); color: var(--lift); }
.tag.run { background: var(--run-bg); color: var(--run); }
.tag { display: inline-flex; align-items: center; gap: 5px; }
.tag.todo { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }
.tag.missed { background: transparent; color: var(--miss); box-shadow: inset 0 0 0 1.5px #5A3420; font-weight: 500; }
.dayname { width: 40px; flex-shrink: 0; font-family: var(--cond); font-size: 20px; font-weight: 700; color: var(--muted); }

.chg { display: inline-flex; gap: 12px; }

/* ---------- supersets: joined rows with a lime edge ---------- */
.row.ss { box-shadow: inset 4px 0 0 var(--lift); }
.row.ss:not(.ss-last) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: -6px; }
.row.ss:not(.ss-first) { border-top-left-radius: 0; border-top-right-radius: 0; border-top: 1px solid var(--line2); }
.sslabel { display: block; font-size: 12px; font-weight: 600; color: var(--lift); letter-spacing: .06em; text-transform: uppercase; margin-top: 2px; }

/* ---------- accordion ---------- */
.acc { background: var(--card); border-radius: 18px; overflow: hidden; }
.acc-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 72px; padding: 14px 18px; border: none; background: none; color: var(--text); text-align: left;
}
.acc-title { font-family: var(--cond); font-size: 26px; font-weight: 700; }
.acc-chev { color: var(--muted); display: flex; transition: transform .2s ease; }
.acc-head[aria-expanded="true"] .acc-chev { transform: rotate(90deg); }
.acc-body { padding: 0 16px 10px; border-top: 1px solid var(--line2); }
.acc-body .empty { margin: 12px 0; }

/* ---------- drag to reorder ---------- */
[data-sortable] > [data-idx] { transition: transform .15s ease; }
[data-sortable] > .dragging { transition: none; position: relative; z-index: 5; box-shadow: 0 10px 28px rgba(0, 0, 0, .6); background: #23262B; }
/* Live workout list: each exercise can link to the next with a button on the boundary */
.queue { gap: 16px; }
.qitem { position: relative; }
.qitem .row { min-height: 60px; }
.queue .row.ss:not(.ss-last) { margin-bottom: -16px; }
.queue .row.ss:not(.ss-first) { border-top: 0; }
.linker {
  position: absolute; left: 50%; bottom: -8px; transform: translate(-50%, 50%); z-index: 3;
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 12px; border-radius: 15px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 13px; font-weight: 600;
}
.queue .row.ss:not(.ss-last) + .linker { bottom: -16px; }
.linker.on { width: 34px; padding: 0; justify-content: center; border-color: var(--lift); background: var(--lift-bg); color: var(--lift); }
.is-dragging .linker { visibility: hidden; }
[data-sortable] > .dragging > .row { background: #23262B; }
[data-sortable] > .droptarget { box-shadow: inset 0 0 0 2px var(--run); }
.handle {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 44px; height: 44px; margin: -10px -8px; color: var(--dim);
  touch-action: none; cursor: grab;
}
.dragging .handle { color: var(--text); cursor: grabbing; }

/* ---------- buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 52px; border: none; border-radius: 14px;
  font-size: 17px; font-weight: 600; text-decoration: none;
}
.btn-primary {
  background: var(--lift); color: var(--bg); height: 70px; border-radius: 18px;
  font-family: var(--cond); font-size: 28px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.btn-run { background: var(--run); color: var(--bg); height: 64px; border-radius: 18px; font-family: var(--cond); font-size: 26px; font-weight: 700; text-transform: uppercase; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text2); }
.btn-danger { background: transparent; border: 1px solid #4A2A1C; color: var(--miss); }
.btn-small { height: 44px; font-size: 15px; }
.btn-delete { background: var(--miss); color: var(--bg); font-weight: 700; }
.delbtn { background: transparent; color: var(--muted); margin: -8px -8px -8px 0; }
.iconbtn:disabled { opacity: .35; }
.iconbtn {
  width: 44px; height: 44px; flex-shrink: 0; border: none; border-radius: 12px;
  background: var(--card); color: var(--text2); display: flex; align-items: center; justify-content: center;
}
.linkbtn.skipbtn { align-self: center; color: var(--muted); font-weight: 500; }
.backtoday {
  display: inline-flex; align-items: center; gap: 4px; align-self: flex-start; min-height: 44px; margin: -8px 0 -6px -6px;
  padding: 0 14px 0 6px; border: none; border-radius: 12px; background: var(--card); color: var(--lift); font-size: 15px; font-weight: 600;
}
.linkbtn { display: inline-flex; align-items: center; gap: 2px; background: none; border: none; color: var(--lift); font-size: 15px; font-weight: 600; padding: 10px 0; }

/* Buttons share the row by label length, so "Threshold" gets more room than "Long". */
.seg { display: flex; gap: 6px; background: var(--card); border-radius: 14px; padding: 5px; }
.seg button { flex: 1 1 auto; height: 46px; min-width: 0; padding: 0 8px; border: none; border-radius: 10px; background: transparent; color: var(--text2); font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg:has(> :nth-child(4)) button { font-size: 15px; padding: 0 6px; } /* 4+ options, e.g. None/Threshold/Long/Easy */
.sheet .seg { background: var(--bg); }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.seg.run button[aria-pressed="true"] { background: var(--run); }
.chips { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.chips button { height: 48px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text2); font-family: var(--cond); font-size: 22px; font-weight: 700; }
.chips button[aria-pressed="true"] { background: var(--lift); border-color: var(--lift); color: var(--bg); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.input {
  height: 52px; width: 100%; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); padding: 0 14px; font-size: 18px;
}
.input:focus { outline: 2px solid var(--lift); outline-offset: -1px; }
.input.num { text-align: center; font-family: var(--cond); font-size: 24px; font-weight: 700; padding: 0 4px; }
.card .input { background: var(--bg); }
.input.num::placeholder { letter-spacing: 0; font-family: 'Barlow', sans-serif; font-size: 17px; font-weight: 500; color: var(--dim); }
select.input { appearance: none; -webkit-appearance: none; }
/* iOS Safari gives date inputs a fixed minimum width that ignores width:100%,
   which pushed the Run page wider than the screen and let it slide sideways. */
input[type="date"].input { -webkit-appearance: none; appearance: none; min-width: 0; max-width: 100%; display: block; line-height: 50px; }
input[type="date"].input::-webkit-date-and-time-value { text-align: left; margin: 0; }
.bigfield { display: flex; flex-direction: column; gap: 6px; background: var(--card); border-radius: 18px; padding: 14px 16px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.bigfield input { border: none; background: transparent; color: var(--text); padding: 0; width: 100%; font-family: var(--cond); font-size: 46px; font-weight: 700; letter-spacing: 0; }
.bigfield input:focus { outline: none; }
.bigfield:focus-within { box-shadow: inset 0 0 0 2px var(--run); }
.bigfield.pace { background: var(--run-bg); color: var(--run); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; font-size: 17px; font-weight: 500; border-bottom: 1px solid var(--line2); }
.toggle:last-child { border-bottom: 0; }
.toggle input { width: 26px; height: 26px; accent-color: var(--lift); flex-shrink: 0; }
.addform { background: var(--card2); border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- active set ---------- */
.setbars { display: flex; gap: 8px; }
.setbars span { flex-grow: 1; height: 8px; border-radius: 4px; background: var(--line); }
.setbars .hit { background: var(--lift); }
.setbars .missed { background: var(--miss); }
.setbars .now { background: var(--text); }
.setcard {
  flex-grow: 1; min-height: 300px; background: var(--card); border-radius: 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px;
}
.setnum { display: flex; align-items: baseline; gap: 14px; font-family: var(--cond); font-weight: 700; }
.setnum .n { font-size: 112px; line-height: 1; }
.setnum .x { font-size: 40px; color: var(--muted); }
.setlabels { display: grid; grid-template-columns: 1fr 1fr; width: 100%; max-width: 280px; text-align: center; font-size: 16px; color: var(--muted); }
/* One row under the set card: Different (pencil) · last week · last set · Done (tick) */
.actrow { display: grid; grid-template-columns: 60px minmax(0, 1fr) minmax(0, 1fr) minmax(76px, 1.1fr); gap: 8px; }
.actrow button { height: 76px; border-radius: 18px; display: flex; align-items: center; justify-content: center; }
.act-diff { border: 2px solid var(--line); background: transparent; color: var(--text); }
.act-quick { flex-direction: column; gap: 3px; border: 1px solid var(--line); background: var(--card); color: var(--muted); padding: 0 4px; }
.act-quick b { font-family: var(--cond); font-size: 20px; font-weight: 700; color: var(--text); white-space: nowrap; }
.act-quick:disabled { opacity: .4; }
.act-done { border: none; background: var(--lift); color: var(--bg); }
/* Short phones (e.g. iPhone SE): smaller set card so everything fits without scrolling */
@media (max-height: 780px) {
  #app.full { gap: 12px; padding-top: calc(env(safe-area-inset-top) + 14px); }
  #app.full h1 { font-size: 38px; }
  .setcard { min-height: 150px; padding: 12px; gap: 4px; }
  .setnum .n { font-size: 76px; }
  .actrow button { height: 68px; }
}
@media (max-width: 350px) {
  .actrow { grid-template-columns: 52px minmax(0, 1fr) minmax(0, 1fr) 68px; gap: 6px; }
  .act-quick b { font-size: 17px; }
}

/* minmax(0, …) lets the columns shrink below the inputs' natural width on narrow phones */
/* kg gets more room than reps ("52.5" vs "12") */
.setedit { display: grid; grid-template-columns: 14px minmax(0, 0.85fr) minmax(0, 1.15fr) 36px; gap: 6px; align-items: center; }
.setedit .iconbtn { width: 36px; }
.mini { display: flex; align-items: center; justify-content: space-between; gap: 2px; min-width: 0; background: var(--bg); border-radius: 12px; padding: 3px; }
.mini button { flex: 0 0 32px; width: 32px; height: 44px; border: none; border-radius: 10px; background: #23262B; color: var(--text); font-size: 22px; }
.mini input { flex: 1 1 0; width: 0; min-width: 0; text-align: center; border: none; background: transparent; color: var(--text); padding: 0; font-family: var(--cond); font-size: 23px; font-weight: 700; }
@media (max-width: 345px) {
  .mini button { flex-basis: 28px; width: 28px; }
  .mini input { font-size: 20px; }
}

.stepper { display: flex; align-items: center; justify-content: space-between; background: var(--bg); border-radius: 18px; padding: 8px; }
.stepper button { width: 72px; height: 72px; border: none; border-radius: 14px; background: #23262B; color: var(--text); font-size: 36px; }
.stepper .val {
  flex: 1 1 0; width: 0; min-width: 0; text-align: center; border: none; background: transparent; color: var(--text);
  font-family: var(--cond); font-size: 60px; font-weight: 700; line-height: 1; padding: 0;
}
.stepper .val.lift { color: var(--lift); }
.stepper .val.missc { color: var(--miss); }
.stepper .val:focus, .mini input:focus { outline: 2px solid var(--lift); border-radius: 10px; }

/* ---------- nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(14, 15, 17, .96); border-top: 1px solid var(--line2);
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 10px);
}
.nav-inner { max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 48px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 500; }
.nav a[aria-current="page"] { color: var(--lift); font-weight: 600; }
.nav a.runtab[aria-current="page"] { color: var(--run); }

/* ---------- sheet & toast ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 92dvh; overflow-y: auto; overflow-x: hidden;
  max-width: 520px; margin: 0 auto; background: var(--card); border-radius: 28px 28px 0 0;
  padding: 14px 20px calc(env(safe-area-inset-bottom) + 24px); display: flex; flex-direction: column; gap: 18px;
}
.sheet .input, .sheet .stepper { background: var(--bg); }
.sheet .row { background: var(--bg); }
/* Buttons that stay pinned to the bottom of a long sheet while it scrolls */
.sheetbar {
  position: sticky; bottom: calc(-1 * (env(safe-area-inset-bottom) + 24px)); z-index: 2;
  margin: 0 -20px calc(-1 * (env(safe-area-inset-bottom) + 24px)); padding: 12px 20px calc(env(safe-area-inset-bottom) + 24px);
  background: var(--card); border-top: 1px solid var(--line2);
}
/* A native select styled like the inputs, with a down chevron */
.selectwrap { position: relative; display: block; }
.selectwrap select { padding-right: 44px; font-size: 17px; font-weight: 600; background: var(--bg); }
.selchev { position: absolute; right: 14px; top: 50%; transform: translateY(-50%) rotate(90deg); color: var(--muted); display: flex; pointer-events: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.grab { width: 44px; height: 5px; border-radius: 3px; background: #3A3E45; align-self: center; }
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 30;
  max-width: calc(100% - 40px);
}

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.tbl { display: grid; grid-template-columns: 1fr auto auto; column-gap: 16px; align-items: center; }
.tbl > * { padding: 11px 2px; border-top: 1px solid var(--line2); }
.tbl .th { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; border-top: 0; padding-top: 0; }
.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--lift); border-radius: 4px; }
.empty { border: 1px dashed #3A3E45; border-radius: 16px; padding: 20px; text-align: center; color: var(--muted); line-height: 1.5; }
