/* Workouts: friendly, high-contrast gym UI. The accent follows the chosen person. */
:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --ink: #17181b;
  --ink-2: #4a4d55;
  --muted: #7b7f88;
  --line: #e7e5df;
  --soft: #f0eee9;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --good: #1f8a4c;
  --danger: #c8372d;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 6px 20px rgba(20, 20, 30, .05);
  --r: 20px;
  --font: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Rubik', var(--font);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --card: #1b1c20;
    --ink: #f2f2f3;
    --ink-2: #c3c5cb;
    --muted: #8d919a;
    --line: #2b2d33;
    --soft: #24262b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --good: #4cc27f;
    --danger: #ff7a6e;
  }
}
/* Person colours (light value, dark value). */
body[data-color="ember"] { --accent: #e4572e; }
body[data-color="ocean"] { --accent: #2a6fdb; }
body[data-color="grape"] { --accent: #7448d1; }
body[data-color="leaf"]  { --accent: #23864d; }
body[data-color="rose"]  { --accent: #cf3f74; }
body[data-color="sun"]   { --accent: #b36b00; }
@media (prefers-color-scheme: dark) {
  body[data-color="ember"] { --accent: #ff7a4f; --accent-ink: #1b0c05; }
  body[data-color="ocean"] { --accent: #6aa4ff; --accent-ink: #06142b; }
  body[data-color="grape"] { --accent: #a98bff; --accent-ink: #160a33; }
  body[data-color="leaf"]  { --accent: #4fd08a; --accent-ink: #04190d; }
  body[data-color="rose"]  { --accent: #ff7aa8; --accent-ink: #2b0614; }
  body[data-color="sun"]   { --accent: #f3b13c; --accent-ink: #261600; }
}
.c-ember { --c: #e4572e; } .c-ocean { --c: #2a6fdb; } .c-grape { --c: #7448d1; }
.c-leaf { --c: #23864d; } .c-rose { --c: #cf3f74; } .c-sun { --c: #b36b00; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 var(--font); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.01em; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
p { margin: 0; }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.grow { flex: 1; }
.eyebrow { font-size: 13px; color: var(--muted); font-weight: 500; }

/* ----- controls ----- */
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
button:disabled { opacity: .5; cursor: default; }
.primary, .ghost, .danger, .on-accent {
  min-height: 44px; padding: 10px 18px; border-radius: 999px; font-weight: 600;
  transition: transform .08s ease, filter .15s;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: var(--soft); color: var(--ink); }
.danger { background: var(--danger); color: #fff; }
.on-accent { background: rgba(255,255,255,.22); color: var(--accent-ink); }
.primary:active, .ghost:active, .danger:active, .on-accent:active { transform: scale(.97); }
.wide { width: 100%; }
.small-btn { min-height: 38px; padding: 6px 14px; font-size: 15px; }
.danger-link { color: var(--danger); font-weight: 600; padding: 10px 4px; }
.danger-text { color: var(--danger) !important; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card); width: 100%; min-width: 0;
  border: 1.5px solid var(--line); border-radius: 14px; padding: 11px 14px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type="date"] { appearance: none; -webkit-appearance: none; min-height: 48px; }
textarea { resize: vertical; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 14px 0 6px; }
.form-msg { color: var(--danger); font-size: 14px; margin-top: 10px; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }

.switch { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; padding: 0; border: 0; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .15s; cursor: pointer; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll-x { flex-wrap: nowrap; overflow-x: auto; margin: 10px -4px 4px; padding: 2px 4px 6px; scrollbar-width: none; }
.chip { padding: 7px 13px; border-radius: 99px; background: var(--soft); font-size: 14px; font-weight: 500; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button { padding: 10px; border-radius: 12px; background: var(--soft); font-weight: 500; font-size: 15px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ----- layout ----- */
.center-screen { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 6px; }
.gate h1 { margin-top: 6px; }
.gate .primary, .gate .ghost { margin-top: 14px; }
.logo { width: 64px; height: 64px; border-radius: 18px; background: url(/icon-192.png) center/cover; box-shadow: var(--shadow); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 12px; }
.section-title { font-size: 20px; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 12px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.wrap { max-width: 640px; margin: 0 auto; padding: 6px 16px calc(96px + var(--safe-b)); }
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--c, var(--accent)); color: #fff; font: 600 17px var(--display); }
.avatar-btn { padding: 0; border-radius: 50%; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + var(--safe-b)); background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabbar svg { width: 25px; height: 25px; fill: currentColor; }
.tabbar button.on { color: var(--accent); }
@media (min-width: 900px) {
  .tabbar { top: 50%; bottom: auto; left: 16px; right: auto; transform: translateY(-50%); grid-template-columns: 1fr; gap: 6px; padding: 10px 8px; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
  .tabbar button { padding: 8px 10px; }
  .wrap { padding-bottom: 40px; }
}

/* ----- people ----- */
.people { display: grid; gap: 10px; margin-top: 14px; }
.person { display: flex; align-items: center; gap: 14px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); text-align: left; font-size: 18px; font-weight: 600; }
.person .avatar { width: 46px; height: 46px; font-size: 20px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: 50%; background: var(--c); border: 3px solid transparent; box-shadow: inset 0 0 0 2px var(--card); }
.swatch.on { border-color: var(--ink); }

/* ----- today ----- */
.accent-card { background: var(--accent); color: var(--accent-ink); border: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.accent-card p { opacity: .85; font-size: 14px; }
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.day .dot { width: 100%; max-width: 40px; aspect-ratio: 1; border-radius: 12px; background: var(--soft); display: grid; place-items: center; color: var(--ink-2); font: 600 12px var(--display); overflow: hidden; }
.day.planned .dot { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); color: var(--accent); }
.day.done .dot { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.day.today { color: var(--ink); }
.day.today .label { background: var(--ink); color: var(--bg); border-radius: 99px; padding: 0 7px; }
.hero h2 { font-size: 24px; margin: 2px 0 4px; }
.hero .ex-preview { margin: 14px 0 16px; display: grid; gap: 8px; }
.ex-preview li { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
ul.ex-preview, ul.plain { list-style: none; padding: 0; }
.ex-preview .muted { white-space: nowrap; }
.hero .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hero .actions .primary { flex: 1; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.start-label { margin-top: 14px; }
.other-routines { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); }
.stat b { display: block; font: 700 26px/1.1 var(--display); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ----- routines ----- */
.routine { padding: 16px 18px; }
.routine .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.routine p { color: var(--muted); font-size: 14px; margin-top: 4px; }
.routine .actions { display: flex; gap: 8px; margin-top: 12px; }
.plan { display: grid; gap: 6px; }
.plan-row { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 10px; }
.plan-row b { font-size: 15px; }
.plan-row select { padding: 9px 12px; }
.plan-row.today b { color: var(--accent); }
.empty { text-align: center; padding: 26px 18px; }
.empty p { color: var(--muted); margin: 6px 0 14px; }
.starters { display: grid; gap: 8px; margin-top: 8px; text-align: left; }
.starter { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--soft); }
.starter small { display: block; color: var(--muted); }

.ro-items { display: grid; gap: 8px; }
.ro-item { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; background: var(--card); }
.ro-item .head { display: flex; align-items: center; gap: 6px; }
.ro-item .head b { flex: 1; font-size: 15px; }
.ro-item .targets { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 6px; margin-top: 8px; }
.ro-item label { font-size: 11px; color: var(--muted); font-weight: 600; display: flex; flex-direction: column; gap: 3px; }
.ro-item input, .ro-item select { padding: 7px 9px; border-radius: 10px; font-size: 15px; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--muted); font-size: 17px; }
.icon-btn:active { background: var(--soft); }

/* ----- picker ----- */
.pick-list { display: grid; gap: 2px; margin-top: 4px; }
.pick { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 10px; border-radius: 12px; text-align: left; }
.pick:active, .pick:hover { background: var(--soft); }
.pick small { color: var(--muted); font-size: 12px; text-transform: capitalize; }
.pick .add { color: var(--accent); font-weight: 700; font-size: 20px; }
.pick.added .add { color: var(--good); }

/* ----- active workout ----- */
#screen-workout { min-height: 100vh; }
.wo-top { padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.wo-title { text-align: center; min-width: 0; }
.wo-title h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wo-title p { font-size: 14px; color: var(--accent); font-weight: 600; }
.wo-wrap { padding-top: 14px; padding-bottom: calc(140px + var(--safe-b)); }
.wo-ex { padding: 14px 14px 10px; }
.wo-ex .head { display: flex; align-items: flex-start; gap: 6px; }
.wo-ex .head > div { flex: 1; min-width: 0; }
.wo-ex .head h3 { font-size: 18px; }
.wo-ex .last { font-size: 13px; color: var(--muted); margin-top: 2px; }
.sets { margin-top: 10px; display: grid; gap: 6px; }
.set { display: grid; grid-template-columns: 30px 1fr 1fr 48px; gap: 8px; align-items: center; }
.set.one { grid-template-columns: 30px 1fr 48px; }
.set.cols-h { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.set.cols-h span { text-align: center; }
.set .no { text-align: center; font: 600 15px var(--display); color: var(--muted); }
.set input { text-align: center; padding: 10px 6px; font: 600 18px var(--display); font-variant-numeric: tabular-nums; border-radius: 12px; background: var(--soft); border-color: transparent; }
.set input:focus { background: var(--card); border-color: var(--accent); }
.tick { width: 48px; height: 44px; border-radius: 12px; background: var(--soft); display: grid; place-items: center; color: var(--muted); }
.tick svg { width: 22px; height: 22px; }
.set.done .tick { background: var(--good); color: #fff; }
.set.done input { background: color-mix(in srgb, var(--good) 12%, transparent); }
.set-tools { display: flex; gap: 8px; margin-top: 10px; }
.set-tools button { flex: 1; padding: 8px; border-radius: 12px; background: var(--soft); font-size: 14px; font-weight: 600; color: var(--ink-2); }
.pr-badge { color: var(--accent); font-weight: 700; font-size: 12px; }

.timer {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 7; max-width: 616px; margin: 0 auto;
  background: var(--ink); color: var(--bg); border-radius: 22px; padding: 10px 12px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  animation: rise .2s ease;
}
.timer-bar { height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--bg) 20%, transparent); overflow: hidden; margin-bottom: 8px; }
.timer-bar span { display: block; height: 100%; background: var(--accent); width: 100%; transition: width .25s linear; }
.timer-row { display: flex; align-items: center; gap: 8px; }
.timer-main { flex: 1; text-align: center; display: flex; flex-direction: column; line-height: 1.1; }
.timer-main .muted { color: color-mix(in srgb, var(--bg) 65%, transparent); }
.timer-main b { font-size: 32px; }
.tbtn { min-width: 56px; height: 44px; border-radius: 14px; background: color-mix(in srgb, var(--bg) 14%, transparent); color: var(--bg); font-weight: 600; }
.tbtn.skip { background: var(--accent); color: var(--accent-ink); }
.timer.over { background: var(--accent); color: var(--accent-ink); }
.timer.over .timer-main .muted, .timer.over .tbtn { color: var(--accent-ink); }
.timer.over .tbtn.skip { background: var(--accent-ink); color: var(--accent); }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }

/* ----- history ----- */
.month { margin: 18px 4px 8px; font-size: 14px; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; }
.month:first-child { margin-top: 4px; }
.hist { display: flex; gap: 14px; align-items: center; width: 100%; text-align: left; padding: 14px 16px; margin-bottom: 8px; }
.hist .date { width: 46px; flex: none; text-align: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent); padding: 6px 0; line-height: 1.1; }
.hist .date b { display: block; font: 700 20px var(--display); }
.hist .date span { font-size: 11px; font-weight: 700; text-transform: uppercase; }
.hist .info { flex: 1; min-width: 0; }
.hist .info b { display: block; font-size: 16px; }
.hist .info p { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wd-sets { display: grid; gap: 10px; margin: 14px 0; }
.wd-ex b { font-size: 15px; }
.wd-ex p { font-size: 14px; color: var(--ink-2); }
.wd-edit { margin: 6px 0; }
.wd-edit summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 6px 0; }
.wd-notes { background: var(--soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; }

/* ----- progress / charts ----- */
#pr-exercise { margin-bottom: 12px; }
.pr-head { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 8px; }
.pr-head div span { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.pr-head div b { font: 700 22px var(--display); font-variant-numeric: tabular-nums; }
.metric-switch { margin: 4px 0 10px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font: 500 11px var(--font); font-variant-numeric: tabular-nums; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-soft); stroke: none; }
.chart .pt { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hl { fill: var(--card); stroke: var(--accent); stroke-width: 2.5; }
.tip { position: absolute; top: 0; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 10px; font-size: 13px; white-space: nowrap; transform: translateX(-50%); box-shadow: var(--shadow); }
.tip b { font-family: var(--display); }
.chart-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; padding: 6px 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
table.data th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.data td { padding: 8px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.data td:last-child, table.data th:last-child { text-align: right; }
table.data button { color: var(--accent); font-weight: 600; }
.note { font-size: 14px; color: var(--muted); padding: 8px 0; }

/* ----- dialogs: bottom sheets on phones ----- */
dialog { border: 0; padding: 0; border-radius: 24px; background: var(--card); color: var(--ink); width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 10, 14, .45); }
dialog > form, dialog > .dlg-body { padding: 22px 20px 0; display: flex; flex-direction: column; }
dialog h2 { font-size: 21px; outline: none; }
.dlg-actions { position: sticky; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 16px 0 calc(16px + var(--safe-b)); margin-top: 8px; background: var(--card); }
dialog fieldset { min-width: 0; }
dialog.tall > form, dialog.tall > .dlg-body { min-height: 100%; }
dialog.tall .dlg-actions { margin-top: auto; }
.menu { display: grid; margin-top: 12px; }
.menu > button, .menu-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 500; cursor: pointer; }
.summary { display: flex; gap: 10px; margin-top: 12px; }
.summary div { flex: 1; background: var(--soft); border-radius: 14px; padding: 10px; text-align: center; }
.summary b { display: block; font: 700 20px var(--display); }
.summary span { font-size: 12px; color: var(--muted); }
@media (max-width: 560px) {
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 24px 24px 0 0; max-height: 100dvh; }
  dialog.tall { height: 92dvh; }
  dialog[open] { animation: sheet .22s ease; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: .5; } }

.toast { position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%); z-index: 20; background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 500; font-size: 15px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }

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