:root {
  --bg: #12160f;
  --card: #1c2318;
  --line: #2e3826;
  --text: #e8ecdf;
  --muted: #9aa58c;
  --accent: #c8a24a;
  --good: #7fb35a;
  --mid: #d8b24a;
  --low: #d0664a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px);
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  max-width: 560px;
  margin: 0 auto;
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 40px; height: 40px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent); color: #1a1a12; font-weight: 800;
}
h1 { margin: 0; font-size: 20px; letter-spacing: 0.5px; }
.tag { margin: 0; font-size: 12px; color: var(--muted); }
.date { margin: 0; font-size: 13px; color: var(--muted); }

main { max-width: 560px; margin: 0 auto; display: grid; gap: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
h2 { margin: 0 0 4px; font-size: 16px; text-transform: uppercase; letter-spacing: 1px; }
.hint { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

.slider {
  display: grid;
  grid-template-columns: 1fr 1.4fr 24px;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.slider small { color: var(--muted); }
.slider input { width: 100%; accent-color: var(--accent); }
.slider output { text-align: right; font-weight: 700; }

.btn {
  width: 100%;
  padding: 12px;
  margin-top: 6px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #1a1a12;
  font-weight: 700;
  font-size: 16px;
}
.btn:active { transform: scale(0.99); }

.score {
  margin-top: 14px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.score .num { font-size: 40px; font-weight: 800; }
.score .label { color: var(--muted); }
.good { color: var(--good); }
.mid { color: var(--mid); }
.low { color: var(--low); }

.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex; justify-content: space-between;
  padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px;
}
.history li:first-child { border-top: 0; }
.history .empty { color: var(--muted); }

/* ---------- Conditioning timer ---------- */
h3 { margin: 18px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 10px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: #252e20; color: var(--text); font-size: 14px;
}
.custom { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.custom label { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.custom input {
  width: 100%; padding: 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px;
}
.custom .btn { grid-column: 1 / -1; }
.btn.small { padding: 10px; font-size: 15px; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.big { font-size: 20px; padding: 18px; }

body.timing { overflow: hidden; }
.timer-view {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: var(--bg); text-align: center;
  --seg: var(--accent);
}
.timer-view[hidden] { display: none; }
.timer-view[data-kind="work"] { --seg: var(--low); }
.timer-view[data-kind="rest"] { --seg: var(--good); }
.timer-view[data-kind="warm"], .timer-view[data-kind="prep"] { --seg: var(--mid); }
.timer-view p { margin: 4px 0; }
.tv-name { color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }
.tv-round { color: var(--muted); font-size: 15px; min-height: 1.4em; }
.tv-label { font-size: 30px; font-weight: 800; color: var(--seg); text-transform: uppercase; }
.tv-time { font-size: clamp(72px, 26vw, 140px); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.tv-cue { color: var(--muted); min-height: 1.4em; }
.tv-track { width: 100%; max-width: 480px; height: 8px; background: var(--card); border-radius: 4px; margin: 14px 0; overflow: hidden; }
.tv-bar { height: 100%; width: 0; background: var(--seg); transition: width .2s linear; }
.tv-next, .tv-laps { color: var(--muted); font-size: 14px; min-height: 1.3em; }
.tv-buttons { width: 100%; max-width: 480px; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 18px; }
.tv-buttons #tvLap { grid-column: 1 / -1; }
.tv-buttons [hidden] { display: none; }
.score[hidden] { display: none; }

/* ---------- Layout additions ---------- */
.iconbtn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 14px; font-weight: 600;
}
.row-between { display: flex; justify-content: space-between; align-items: baseline; }
.today-title { font-size: 22px; font-weight: 800; margin: 2px 0 8px; }
.wk-sub { margin: 0; font-size: 13px; color: var(--muted); }
.preview { list-style: none; padding: 0; margin: 0 0 8px; }
.preview li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.preview li span:last-child { color: var(--muted); text-align: right; }
.hint.small { font-size: 13px; margin: 0 0 8px; }
.ready { font-size: 14px; margin: 6px 0; }
.warn { font-size: 14px; color: var(--mid); margin: 6px 0; }
.btnrow { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; margin-top: 8px; }
.btnrow .btn { margin-top: 0; }
h3.first { margin-top: 0; }

/* Full-screen screens */
.screen {
  position: fixed; inset: 0; z-index: 5; overflow-y: auto; background: var(--bg);
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 110px);
}
.screen[hidden] { display: none; }
.screen main { max-width: 560px; margin: 0 auto; display: grid; gap: 14px; }
.screen-top {
  position: sticky; top: 0; z-index: 2; background: var(--bg);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  max-width: 560px; margin: 0 auto; padding: 14px 0;
}
.screen-top h2 { margin: 0; text-align: center; }
.back { background: none; border: 0; color: var(--accent); font-size: 16px; padding: 6px 0; }
.wk-head { text-align: center; }
.wk-head h2 { font-size: 17px; text-transform: none; letter-spacing: 0; }

/* Picker */
.stack { display: grid; gap: 8px; }
.pick {
  display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  padding: 12px; border-radius: 8px; border: 1px solid var(--line); background: #252e20; color: var(--text); font-size: 15px;
}
.pick.current { border-color: var(--accent); }
.pick.done span:last-child { color: var(--good); }
.pick span:last-child { color: var(--muted); white-space: nowrap; }
.pick.day { margin-top: 6px; font-size: 14px; }
details.wk { border-top: 1px solid var(--line); padding: 10px 0; }
details.wk summary { font-weight: 700; cursor: pointer; }
details.paste { margin-top: 12px; }
details.paste summary { color: var(--muted); cursor: pointer; }
textarea {
  width: 100%; margin: 10px 0; padding: 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: 13px/1.4 ui-monospace, Menlo, monospace;
}
.errors { color: var(--low); font-size: 13px; padding-left: 18px; margin: 8px 0 0; }
.errors:empty { display: none; }
.tm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.tm-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.unit-in { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.tm-grid input, .setrow input {
  width: 100%; min-width: 0; padding: 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px;
}

/* Workout items */
.item { padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.item-name { font-weight: 700; }
.item-rx { color: var(--muted); font-size: 13px; text-align: right; }
.item.complete .item-name { color: var(--good); }
.setrow { display: grid; grid-template-columns: 22px 1fr auto 1fr 44px; align-items: center; gap: 8px; margin-top: 6px; }
.setrow:has(> .x:nth-child(2)) { grid-template-columns: 22px auto 1fr 44px; }
.setno { color: var(--muted); font-size: 13px; text-align: center; }
.x { color: var(--muted); font-size: 13px; }
.check {
  height: 40px; border-radius: 8px; border: 1px solid var(--line); background: #252e20; color: var(--muted); font-size: 18px; font-weight: 800;
}
.setrow.done .check, .check.on { background: var(--good); color: #10170c; border-color: var(--good); }
.setrow.done input { opacity: .7; }
.setrow.amrap .setno { color: var(--accent); font-weight: 700; }
.setrow.amrap input[data-f="reps"] { border-color: var(--accent); }
.amrap-note { margin: 6px 0 0; }
.item-actions { display: grid; grid-template-columns: 1fr auto 44px; align-items: center; gap: 8px; }
.item-actions .btn { margin-top: 0; }
.result { font-weight: 700; font-variant-numeric: tabular-nums; }

.wk-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
#workoutView[hidden] .wk-footer { display: none; }
.wk-footer > * { max-width: 560px; margin-left: auto; margin-right: auto; }
.restbar {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 8px; border-radius: 10px; background: var(--card); border: 1px solid var(--good);
}
.restbar[hidden] { display: none; }
.restbar strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.btn.tiny { padding: 6px 10px; font-size: 13px; margin-top: 0; width: auto; }

/* Settings and dice */
.brand { min-width: 0; }
.iconbtn { flex: none; }
#varyView .field-row label { text-transform: capitalize; }
#varyView select {
  width: 100%; min-width: 0; min-height: 40px; padding: 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px;
}
.file-btn { display: block; text-align: center; min-height: 40px; box-sizing: border-box; }
#settingsView .btn.small { min-height: 40px; }
#settingsView .toggle-row input { width: 24px; height: 24px; accent-color: var(--accent); }
.vary-today {
  margin: 0; padding: 12px 14px; border: 1px solid var(--accent); border-radius: 10px;
  background: var(--card); font-weight: 700;
}

/* Groups, circuits and timed blocks */
.cluster-label { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); color: var(--accent); font-size: 13px; font-weight: 700; }
.cluster-label + .item { border-top: 0; padding-top: 6px; }
.item.optional { opacity: .6; }
.optional-tag { color: var(--muted); font-weight: 400; }
.moves { list-style: none; margin: 0 0 8px; padding: 0; font-size: 14px; }
.moves li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 0; }
.moves .btn.small { width: auto; margin: 0; flex: none; min-height: 40px; padding: 6px 12px; }
.round-row { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.round-row .check { width: 44px; }
.round-row.done .check { background: var(--good); color: #10170c; border-color: var(--good); }
.score-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.score-row label, .load-row { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.load-row { margin-bottom: 8px; }
.score-row input, .load-row input {
  width: 100%; min-width: 0; min-height: 40px; padding: 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px;
}
.load-row .unit-in input { max-width: 110px; }
.score-text { margin: 8px 0 0; }
.score-text:empty { display: none; }

/* New 1RM notice on the home screen */
.notice { border-color: var(--accent); }
.notice[hidden] { display: none; }
.notice-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; }
.notice-row .hint { margin: 2px 0 0; }
.notice-row .btn.tiny { min-height: 40px; }
.notice .btn.small { min-height: 40px; }

/* Profile */
.top-actions { display: flex; align-items: center; gap: 8px; }
.iconbtn { min-height: 40px; }
.iconbtn.round { width: 40px; padding: 0; justify-content: center; }
.profile-note { margin: 0; text-align: center; }
.field-row, .lift-row { display: grid; align-items: center; gap: 8px; margin-bottom: 10px; }
.field-row { grid-template-columns: 1fr 1.3fr; }
.field-row.with-top { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); margin-bottom: 4px; }
.field-row small { color: var(--muted); }
.lift-row { grid-template-columns: 1fr 104px 74px; }
.lift-tm { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }
.est-inputs .full { grid-column: 1 / -1; }
.p-unit { min-width: 18px; }
#profileView input[type="text"], #profileView input[type="number"], #profileView select {
  width: 100%; min-width: 0; min-height: 40px; padding: 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px;
}
.est { margin: 12px 0; padding: 12px; border: 1px solid var(--accent); border-radius: 10px; }
.est[hidden] { display: none; }
#profileView .btn.small, .back { min-height: 40px; }
.est-title { margin: 0 0 6px; font-weight: 700; }
.est-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.est-inputs label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.est-result { margin: 8px 0 6px; font-size: 18px; font-weight: 800; color: var(--accent); }
.est-result:empty, .est .hint:empty { display: none; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; min-height: 40px; }
.toggle-row input { width: 24px; height: 24px; accent-color: var(--accent); }

.toast {
  position: fixed; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 12px); z-index: 20;
  max-width: 528px; margin: 0 auto; padding: 12px 14px; border-radius: 10px;
  background: #2c3725; border: 1px solid var(--accent); font-size: 14px;
}
.toast[hidden] { display: none; }

/* Account (sign in with an emailed code) */
.acct-label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.acct-input {
  width: 100%; min-width: 0; min-height: 44px; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px; /* 16px stops iPhone zooming in */
}
.acct-input.code { font-size: 22px; letter-spacing: 6px; font-variant-numeric: tabular-nums; }
#accountCard form[hidden], #accountCard div[hidden] { display: none; }
#accountCard .btn:disabled { opacity: .6; }
.acct-error { margin: 10px 0 0; color: var(--low); font-size: 14px; font-weight: 600; }
.acct-error:empty { display: none; }
.btn.danger { color: var(--low); border-color: var(--low); margin-top: 8px; }
.acct-who { margin: 0 0 6px; overflow-wrap: anywhere; }

/* AI suggestions (coach.js): inbox on the home screen, history in Settings */
.ai-prop { padding: 10px 0; border-top: 1px solid var(--line); }
.ai-prop:first-child { border-top: 0; padding-top: 0; }
.ai-from { margin: 0; font-size: 13px; color: var(--muted); }
.ai-reason { margin: 4px 0 6px; }
.ai-lines { margin: 0 0 6px; padding-left: 18px; }
.ai-lines li { margin: 2px 0; }
.ai-prop .btnrow { grid-template-columns: 1fr 1fr; }
.ai-prop .btn.small { min-height: 40px; }
.ai-diff summary { min-height: 40px; display: flex; align-items: center; color: var(--accent); cursor: pointer; }
.ai-diff pre { margin: 4px 0 8px; padding: 8px; background: var(--bg); border-radius: 8px; font-size: 12px; overflow-x: auto; max-height: 50vh; }
.ai-diff pre span { display: block; white-space: pre; }
.d-add { color: var(--good); }
.d-del { color: var(--low); text-decoration: line-through; }
.d-same, .d-gap { color: var(--muted); }
.ai-change { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ai-change .hint.small { margin: 2px 0 0; }
.ai-change .btn.tiny { min-height: 40px; flex: none; }
.ai-change.undone strong { color: var(--muted); }
.ai-why { font-style: italic; }

/* Admin card (admin.js): access requests and invites */
#adminCard form { margin-top: 14px; }
#adminCard .btn:disabled { opacity: .6; }
.adm-list { list-style: none; margin: 0; padding: 0; }
.adm-req { padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.adm-req:first-child { border-top: 0; padding-top: 0; }
.adm-req .hint.small { margin: 2px 0 8px; }
.adm-req .btnrow { grid-template-columns: 1fr 1fr; }
.adm-req .btn.small { min-height: 40px; }
.adm-done { margin: 14px 0 8px; }
.adm-done summary { min-height: 40px; display: flex; align-items: center; color: var(--accent); cursor: pointer; }
#admSearch { margin: 0 0 4px; }
.adm-done > .btn { margin-top: 8px; }
.adm-done summary { list-style: none; }
.adm-done summary::-webkit-details-marker { display: none; }
.adm-done summary::before { content: "\25B8"; width: 18px; display: inline-block; }
.adm-done[open] summary::before { content: "\25BE"; }

/* Readiness (app.js): a summary on the home card, sliders in a pop-up */
#readiness .row-between { align-items: center; }
#readiness h2 { margin: 0; }
.ready-btn { width: auto; min-width: 104px; min-height: 40px; margin: 0; padding: 8px 16px; }
.ready-none { margin: 10px 0 0; }
#readiness .score { margin-top: 10px; }
.sheet {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 20px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .6); }
.sheet h2 { margin-top: 0; }
.sheet .btnrow { grid-template-columns: 2fr 1fr; }

/* Role tabs on the Profile screen (admin.js): Profile | Admin */
.tabs {
  position: sticky; top: 58px; z-index: 2; background: var(--bg);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  max-width: 560px; margin: 0 auto 12px; padding: 4px;
  border: 1px solid var(--line); border-radius: 10px;
}
.tabs[hidden] { display: none; }
.tabs button {
  min-height: 44px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-size: 15px; font-weight: 700; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: #1a1a12; }
#tabProfile[hidden], #tabAdmin[hidden] { display: none; }

/* Program library (workout.js): search, type filters, program cards */
#libSearch { margin-bottom: 10px; }
.lib-types { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.lib-types .chip { min-height: 40px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #1a1a12; font-weight: 700; }
#libCount:empty { display: none; }
.lib-card { padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.lib-card.current { border-color: var(--accent); }
.lib-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.lib-head h4 { margin: 0; font-size: 17px; line-height: 1.3; }
.lib-badge { flex: none; font-size: 12px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 2px 8px; }
.lib-types-line { margin: 4px 0 6px; font-size: 13px; color: var(--accent); }
.lib-summary { margin: 0 0 6px; font-size: 15px; }
.lib-by { margin: 0; }
.lib-card .btn { margin-top: 10px; }
