@import url('fonts.css');

/* =====================================================================
   Tokens (design-reference/DESIGN.md). Dark is the default theme.
   ===================================================================== */
:root {
  --bg: #0D0F0E;
  --surface: #161A18;
  --surface-2: #252B28;
  --tabbar: #111412;
  --line: #222724;
  --line-strong: #343B37;

  --text: #EDEFEA;
  --text-2: #C9CFCA;
  --text-muted: #A3ABA5;
  --text-faint: #7C857F;

  --accent: #C8F25A;
  --accent-ink: #0D0F0E;
  --accent-soft: #1F2A10;

  --ok: #6BD49A;   --ok-bg: #102219;   --ok-line: #23503A;
  --warn: #F2B84B; --warn-bg: #221A0B; --warn-line: #5A4417; --warn-ink: #E3D3B4;
  --bad-bg: #7A2620; --bad-ink: #FFD2CC;

  --macro: #9FB8FF;
  --water: #6FD3E0; --water-bg: #12343A; --water-ink: #8FE6F1;
  --chart-raw: #4E5651;
  --seg-skip: #4A3A1E; --seg-partial: #6F8A35; --seg-none: #2A302D;

  --r-sm: 10px; --r-md: 14px; --r-lg: 18px;
  --tap-min: 56px;
  --gutter: 16px;
  --tabbar-h: 72px;

  --font-num: 'Barlow Condensed', 'Roboto Condensed', 'Arial Narrow', sans-serif-condensed, system-ui, sans-serif;
  --font-text: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #F4F5F1;
  --surface: #FFFFFF;
  --surface-2: #E6E9E3;
  --tabbar: #FFFFFF;
  --line: #E1E4DE;
  --line-strong: #C5CBC4;

  --text: #121513;
  --text-2: #2F3632;
  --text-muted: #59615C;
  --text-faint: #6E7671;

  --accent: #3F6A00;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7F3CC;

  --ok: #1F7A4A;   --ok-bg: #E2F4EA;   --ok-line: #9ED3B5;
  --warn: #8A5A00; --warn-bg: #FFF2D6; --warn-line: #E9C77A; --warn-ink: #5C4310;
  --bad-bg: #B3261E; --bad-ink: #FFFFFF;

  --macro: #3557C4;
  --water: #0E7C8A; --water-bg: #D8F1F4; --water-ink: #0B5F6A;
  --chart-raw: #B8BFB9;
  --seg-skip: #E9C77A; --seg-partial: #9DBF5C; --seg-none: #DADFD8;

  color-scheme: light;
}

/* =====================================================================
   Base
   ===================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
body.no-scroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: .35; cursor: default; }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
ol, ul { margin: 0; padding: 0; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: max(20px, env(safe-area-inset-top)) var(--gutter) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#app.fullscreen {
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  gap: 0;
  overflow: hidden;
}

/* =====================================================================
   Tab bar
   ===================================================================== */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--tabbar);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
}
#tabbar[hidden] { display: none; }
#tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--text-muted); font-size: 12px; font-weight: 600;
}
#tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }

/* =====================================================================
   Typography helpers
   ===================================================================== */
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; line-height: 1; }
.title { font-family: var(--font-num); font-size: 34px; font-weight: 700; line-height: 1; text-transform: uppercase; letter-spacing: .01em; }
.label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.label.accent, .accent { color: var(--accent); }
.hero { font-size: 52px; }
.stat { font-size: 30px; }
.stat-sm { font-size: 22px; font-weight: 600; }
.big { font-size: 36px; }
.unit { font-size: 14px; color: var(--text-muted); font-family: var(--font-text); font-weight: 400; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.text-2 { color: var(--text-2); }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.bad-text { color: var(--bad-ink); }
.danger { color: #FF8A80; }
:root[data-theme="light"] .danger { color: #B3261E; }
.grow { flex: 1; min-width: 0; }
.col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gap-6 { gap: 6px; } .gap-10 { gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.row-between { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.hidden { display: none !important; }

/* =====================================================================
   Primitives
   ===================================================================== */
.card { background: var(--surface); border-radius: var(--r-lg); padding: 16px; display: flex; flex-direction: column; gap: 10px; color: var(--text); min-width: 0; }
.card.tight { padding: 12px; gap: 2px; }
.card-row { flex-direction: row; align-items: center; gap: 14px; }
.card-row.slim { padding: 12px 16px; }
.card-title { font-size: 30px; text-transform: uppercase; }
.accent-border { border: 2px solid var(--accent); }
.list-card { padding: 4px 16px; gap: 0; }
.list-row { min-height: 60px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); color: var(--text); }
.list-row:last-child { border-bottom: 0; }

.btn {
  min-height: 52px; padding: 0 16px; border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: transparent; color: var(--text);
  font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  white-space: nowrap;
}
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 14px; }
.btn-primary {
  border: 0; background: var(--accent); color: var(--accent-ink);
  font-family: var(--font-num); font-size: 24px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
  min-height: 60px;
}
.btn-primary.btn-sm { font-size: 18px; min-height: 44px; }
.btn-start { min-height: 64px; padding: 0 22px; font-size: 26px; border-radius: 16px; }
.btn-fill { border: 0; background: var(--surface-2); }
.btn-accent-outline { border: 1px solid var(--accent); color: var(--accent); font-weight: 700; }
.btn-done { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 12px; font-size: 14px; font-weight: 600; color: var(--text-muted); }
.btn.danger { border-color: #7A2620; }
.label-btn { background: none; border: 0; padding: 0; text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); min-height: 24px; }
.icon-btn { width: 48px; height: 48px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; color: var(--text); background: transparent; border: 0; }

.chip { padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip-accent { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chip-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok-line); padding: 6px 12px; font-size: 14px; }
.chip-warn { background: var(--warn-bg); color: var(--warn); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field input, .field select, .field textarea {
  min-height: 52px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--bg); padding: 0 14px; font-size: 17px; width: 100%;
}
.field textarea { padding: 10px 12px; min-height: 72px; resize: vertical; font-size: 16px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; }
.field-inline { display: flex; align-items: center; gap: 8px; }

.alert { border-radius: 16px; padding: 14px; display: flex; gap: 12px; font-size: 14px; line-height: 1.4; }
.alert-body { display: flex; flex-direction: column; gap: 4px; }
.alert-body strong { font-size: 16px; }
.alert-icon { flex: none; margin-top: 1px; }
.alert-warn { border: 1px solid var(--warn-line); background: var(--warn-bg); color: var(--warn); }
.alert-warn .alert-body span { color: var(--warn-ink); }
.alert-bad { background: var(--bad-bg); color: var(--bad-ink); }
.alert-ok { border: 1px solid var(--ok-line); background: var(--ok-bg); color: var(--ok); }

.dot { width: 8px; height: 8px; border-radius: 4px; display: inline-block; flex: none; }
.sync-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); padding-top: 4px; min-height: 32px; }

.bar { position: relative; border-radius: 99px; background: var(--surface-2); }
.bar-fill { height: 100%; border-radius: 99px; }
.bar-marker { position: absolute; top: -3px; bottom: -3px; width: 3px; background: var(--text); border-radius: 2px; }

.empty { border: 1px dashed var(--line-strong); border-radius: var(--r-lg); padding: 18px; display: flex; flex-direction: column; gap: 12px; color: var(--text-2); font-size: 14px; }
.empty-screen { padding-top: 10vh; display: flex; flex-direction: column; gap: 16px; padding-left: var(--gutter); padding-right: var(--gutter); }

.page-head { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.page-head .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-head-right { display: flex; align-items: center; gap: 8px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; }
.seg-btn { min-height: 48px; border-radius: 9px; border: 0; background: transparent; color: var(--text-muted); font-size: 15px; font-weight: 600; }
.seg-btn.on, .seg-btn[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 700; }

.stepper-row { display: flex; align-items: center; gap: 10px; }
.step-btn { width: 56px; height: 56px; border-radius: 12px; border: 0; background: var(--surface-2); font-size: 28px; line-height: 1; }
.stepper-val { font-size: 40px; min-width: 64px; text-align: center; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(5, 6, 5, .72); display: flex; flex-direction: column; justify-content: flex-end; }
.sheet {
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; max-height: 88vh; overflow-y: auto; width: 100%; max-width: 560px; margin: 0 auto;
}
.sheet-list { display: flex; flex-direction: column; gap: 8px; }
.sheet-item { min-height: 60px; border-radius: 14px; border: 0; background: var(--surface-2); font-size: 17px; font-weight: 600; text-align: left; padding: 0 16px; }
.sheet-num { height: 72px; border-radius: 14px; border: 1px solid var(--line-strong); background: var(--bg); font-family: var(--font-num); font-size: 44px; font-weight: 700; text-align: center; width: 100%; }

/* =====================================================================
   Auth
   ===================================================================== */
.auth { max-width: 420px; width: 100%; margin: 0 auto; padding-top: 8vh; display: flex; flex-direction: column; gap: 20px; }
.auth form { display: flex; flex-direction: column; gap: 14px; }
.auth .hint { font-size: 14px; color: var(--text-2); }

/* =====================================================================
   Today
   ===================================================================== */
.today-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.today-head .muted { font-size: 14px; }
.protein-card { flex-direction: row; align-items: center; gap: 16px; padding: 18px 16px; }
.protein-ring { position: relative; width: 160px; height: 160px; flex: none; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.mini-ring { align-items: center; padding: 12px 4px; gap: 6px; text-align: center; }
.mini-ring .num { font-size: 20px; }
.mini-ring .small { font-size: 12px; }
.sup-card { gap: 0; padding: 14px 16px; }
.sup-group { font-size: 13px; font-weight: 600; color: var(--text-faint); padding: 12px 0 2px; }
.sup-item { min-height: 52px; display: flex; align-items: center; gap: 14px; font-size: 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.sup-item:last-child { border-bottom: 0; }
.sup-item input { width: 26px; height: 26px; accent-color: var(--accent); margin: 0; flex: none; }
.sup-item.on .grow { color: var(--text-muted); text-decoration: line-through; }
.posture-list { padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.posture-list li { display: flex; flex-direction: column; }

@media (max-width: 370px) {
  .protein-ring { width: 128px; height: 128px; }
  .protein-ring svg { width: 128px; height: 128px; }
  .hero { font-size: 42px; }
  .grid-4 { gap: 6px; }
}

/* =====================================================================
   Workout in progress — fixed layout, no scroll
   ===================================================================== */
.wk-head { height: 64px; flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); position: relative; }
.wk-head-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wk-tpl { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.wk-head-sub { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.wk-elapsed { font-size: 17px; font-weight: 600; color: var(--text); }
.wk-sync { display: inline-flex; align-items: center; gap: 6px; }
.wk-end { min-height: 48px; }
.wk-rest { background: var(--accent); color: var(--accent-ink); border-bottom: 0; padding: 0 8px 0 16px; gap: 8px; }
.wk-rest-main { flex: 1; display: flex; align-items: baseline; gap: 10px; }
.wk-rest-label { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.wk-rest-time { font-size: 46px; }
.wk-rest-btn { height: 48px; min-width: 64px; border-radius: 12px; font-size: 16px; font-weight: 700; }
.wk-rest-btn.outline { border: 2px solid var(--accent-ink); background: transparent; color: var(--accent-ink); }
.wk-rest-btn.solid { border: 0; background: var(--accent-ink); color: var(--accent); }
.wk-rest-bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent-ink); opacity: .35; transition: width .25s linear; }
.wk-go { background: var(--accent-soft); border-bottom: 2px solid var(--accent); padding: 0 16px; }
.wk-go-dot { width: 12px; height: 12px; border-radius: 6px; background: var(--accent); }
.wk-go-text { font-size: 28px; color: var(--accent); text-transform: uppercase; }
.wk-go-elapsed { margin-left: auto; font-size: 13px; }

.wk-segs { display: flex; gap: 4px; padding: 10px 16px 0; flex: none; }
.wk-seg { flex: 1; height: 5px; border-radius: 3px; background: var(--seg-none); }
.wk-seg.current { background: var(--text); }
.wk-seg.full { background: var(--accent); }
.wk-seg.partial { background: var(--seg-partial); }
.wk-seg.skipped { background: var(--seg-skip); }

.wk-body { flex: 1; min-height: 0; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.wk-ex { display: flex; flex-direction: column; gap: 4px; }
.wk-pos { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.wk-name { font-family: var(--font-num); font-size: 34px; line-height: 1; font-weight: 700; text-transform: uppercase; letter-spacing: .01em; }
.wk-meta { font-size: 15px; color: var(--text-2); }
.wk-tech { font-size: 13px; color: var(--text-muted); }
.wk-last { background: var(--surface); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.wk-last-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wk-last-line { font-size: 24px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.wk-slots { display: flex; gap: 6px; }
.wk-slot { flex: 1; min-width: 0; height: 44px; border-radius: 10px; display: flex; align-items: center; gap: 8px; padding: 0 8px; font-size: 14px; }
.wk-slot .num { font-size: 20px; font-weight: 600; white-space: nowrap; overflow: hidden; }
.wk-slot-badge { width: 24px; height: 24px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.wk-slot.done { background: var(--surface); border: 0; color: var(--text); text-align: left; }
.wk-slot.done .wk-slot-badge { background: var(--accent); color: var(--accent-ink); }
.wk-slot.now { border: 2px solid var(--accent); color: var(--text); font-weight: 600; }
.wk-slot.now .wk-slot-badge { border: 2px solid var(--accent); color: var(--accent); }
.wk-slot.pending { border: 1px dashed var(--line-strong); color: var(--text-faint); }
.wk-slot.pending .wk-slot-badge { border: 1px solid var(--line-strong); }

.wk-weight { display: flex; flex-direction: column; gap: 8px; }
.wk-stepper { display: flex; align-items: center; gap: 8px; }
.wk-big-btn { width: 72px; height: 64px; border-radius: 14px; border: 0; background: var(--surface-2); font-size: 34px; font-weight: 500; line-height: 1; flex: none; }
.wk-weight-val { flex: 1; display: flex; align-items: baseline; justify-content: center; gap: 6px; background: none; border: 0; min-height: 64px; }
.wk-weight-val .num { font-size: 56px; }
.wk-weight-val .muted { font-size: 16px; }
.wk-incs { display: flex; gap: 6px; }
.wk-inc { flex: 1; height: 44px; border-radius: 10px; font-size: 14px; font-weight: 600; border: 1px solid var(--line-strong); background: transparent; color: var(--text-muted); }
.wk-inc.on { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent); }

.wk-rr { display: flex; gap: 10px; }
.wk-reps { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.wk-reps-box { display: flex; align-items: center; gap: 4px; background: var(--surface); border-radius: 14px; padding: 4px; }
.wk-mid-btn { width: 56px; height: 56px; border-radius: 10px; border: 0; background: var(--surface-2); font-size: 28px; line-height: 1; flex: none; }
.wk-reps-val { flex: 1; text-align: center; font-size: 40px; }
.wk-rir { width: 150px; display: flex; flex-direction: column; gap: 4px; flex: none; }
.wk-rir-box { display: flex; gap: 4px; background: var(--surface); border-radius: 14px; padding: 4px; }
.wk-rir-btn { flex: 1; height: 56px; border-radius: 10px; border: 0; background: var(--surface-2); color: var(--text-2); font-family: var(--font-num); font-size: 22px; font-weight: 700; }
.wk-rir-btn.on { background: var(--accent); color: var(--accent-ink); }

.wk-main { margin-top: auto; min-height: 76px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 100%; flex: none; }
.wk-main-label { font-family: var(--font-num); font-size: 28px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; line-height: 1; }
.wk-main-sub { font-size: 14px; font-weight: 600; opacity: .75; }
.wk-nav { display: flex; gap: 8px; flex: none; }
.wk-nav-arrow { width: 64px; height: 56px; border-radius: 14px; border: 0; background: var(--surface-2); font-size: 30px; line-height: 1; flex: none; }
.wk-nav-btn { flex: 1; min-height: 56px; }

.wk-summary { padding: 28px 16px 20px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; height: 100%; }
.wk-sum-title { font-size: 44px; }
.wk-sum-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.wk-sum-row { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.wk-sum-row .num { font-size: 19px; font-weight: 600; color: var(--text-2); }
.saved-box { border-radius: 18px; border: 2px solid var(--accent); padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.saved-box .num { font-size: 26px; color: var(--accent); text-transform: uppercase; }

/* Short phones (≤ 700 px tall): compress so nothing scrolls. */
@media (max-height: 740px) {
  .wk-body { gap: 8px; padding-top: 8px; padding-bottom: 8px; }
  .wk-name { font-size: 28px; }
  .wk-meta { font-size: 14px; }
  .wk-tech { display: none; }
  .wk-last { padding: 8px 10px; gap: 2px; }
  .wk-last-line { font-size: 20px; }
  .wk-slot { height: 38px; }
  .wk-big-btn { height: 56px; width: 64px; }
  .wk-weight-val { min-height: 56px; }
  .wk-weight-val .num { font-size: 46px; }
  .wk-inc { height: 40px; }
  .wk-mid-btn, .wk-rir-btn { height: 56px; }
  .wk-reps-val { font-size: 34px; }
  .wk-main { min-height: 64px; }
  .wk-main-label { font-size: 24px; }
}
@media (max-height: 640px) {
  .wk-pos { display: none; }
  .wk-incs { display: none; }
}
@media (max-width: 370px) {
  .wk-rir { width: 132px; }
  .wk-big-btn { width: 60px; }
}

/* =====================================================================
   Library / history / editors
   ===================================================================== */
.tpl-badge { min-width: 44px; padding: 0 6px; height: 44px; border-radius: 12px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-family: var(--font-num); font-size: 26px; font-weight: 700; flex: none; }
.tpl-badge.today { background: var(--accent); color: var(--accent-ink); }
.chips-scroll { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin: 0 calc(-1 * var(--gutter)); padding-left: var(--gutter); padding-right: var(--gutter); }
.chips-scroll::-webkit-scrollbar { display: none; }
.pill { height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--line-strong); background: transparent; color: var(--text-2); font-size: 14px; font-weight: 600; white-space: nowrap; flex: none; display: inline-flex; align-items: center; }
.pill.on { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chart-box { position: relative; height: 180px; width: 100%; }
.chart-box.tall { height: 200px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.inset { border-radius: 12px; background: var(--bg); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.inset .num { font-size: 24px; }

.editor-item { background: var(--surface); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.editor-item.dragging { opacity: .5; }
.editor-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.editor-grid .field input { min-height: 44px; padding: 0 8px; font-size: 16px; text-align: center; }
.editor-grid .label { font-size: 11px; }
.order-btns { display: flex; gap: 4px; }
.order-btns button { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line-strong); background: transparent; font-size: 18px; }

/* =====================================================================
   Diet
   ===================================================================== */
.food-row { min-height: 64px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.food-row:last-child { border-bottom: 0; }
.food-add { width: 52px; height: 52px; border-radius: 12px; border: 0; background: var(--surface-2); color: var(--accent); font-size: 28px; line-height: 1; flex: none; }
.food-name { background: none; border: 0; padding: 0; text-align: left; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; min-height: 56px; justify-content: center; }
.water-btn { min-height: 56px; padding: 0 14px; border-radius: 14px; border: 0; background: var(--water-bg); color: var(--water-ink); font-size: 16px; font-weight: 700; }
.week-cols { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.week-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.week-cell { width: 100%; height: 56px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-family: var(--font-num); font-size: 18px; font-weight: 700; }
.week-cell.ok { background: var(--ok); color: #0D0F0E; }
.week-cell.warn { background: var(--warn); color: #0D0F0E; }
.week-cell.bad { background: var(--bad-bg); color: var(--bad-ink); }
.week-cell.none { border: 1px dashed var(--line-strong); color: var(--text-faint); font-family: var(--font-text); font-size: 16px; font-weight: 400; }
.week-cell.open { background: var(--surface); color: var(--text); }
.week-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.entry-row { min-height: 52px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); font-size: 15px; }
.entry-row:last-child { border-bottom: 0; }
.entry-del { width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; color: var(--text-faint); flex: none; display: inline-flex; align-items: center; justify-content: center; }
.macro-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

/* =====================================================================
   Body
   ===================================================================== */
.weight-input { flex: 1; height: 60px; border-radius: 14px; border: 1px solid var(--line-strong); background: var(--bg); display: flex; align-items: center; padding: 0 14px; gap: 6px; }
.weight-input input { width: 100%; border: 0; background: transparent; font-family: var(--font-num); font-size: 34px; font-weight: 700; outline: none; min-width: 0; }
.rate-card { flex-direction: row; align-items: center; gap: 14px; padding: 14px 16px; }
.rate-card.ok { border: 1px solid var(--ok-line); background: var(--ok-bg); }
.rate-card.warn { border: 1px solid var(--warn-line); background: var(--warn-bg); }
.rate-card.bad { background: var(--bad-bg); color: var(--bad-ink); }
.measure-row { min-height: 48px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; padding: 0; }
.measure-row:last-child { border-bottom: 0; }
.measure-row .num { font-size: 22px; }
.measure-delta { width: 80px; text-align: right; font-size: 14px; color: var(--text-muted); }
.photo-slot { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.photo-frame { aspect-ratio: 3 / 4; border-radius: 12px; border: 1px dashed var(--line-strong); background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--text-faint); font-size: 13px; overflow: hidden; text-align: center; padding: 8px; }
.photo-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-frame.has { border: 0; padding: 0; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.photo-thumb { aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; background: var(--bg); border: 0; padding: 0; position: relative; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb span { position: absolute; left: 4px; bottom: 4px; font-size: 11px; background: rgba(0, 0, 0, .6); color: #fff; padding: 2px 6px; border-radius: 6px; }

/* =====================================================================
   More / cardio timer
   ===================================================================== */
.more-link { min-height: 64px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); color: var(--text); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; padding: 0; }
.more-link:last-child { border-bottom: 0; }
.more-link .chev { font-size: 22px; color: var(--text-faint); }
.switch-row { min-height: 64px; display: flex; align-items: center; gap: 12px; }
.switch-row input { width: 26px; height: 26px; accent-color: var(--accent); margin: 0; }
.timer-screen { height: 100%; display: flex; flex-direction: column; gap: 16px; padding: 16px; }
.timer-phase { font-family: var(--font-num); font-size: 40px; font-weight: 700; text-transform: uppercase; text-align: center; }
.timer-phase.work { color: var(--accent); }
.timer-phase.rest { color: var(--water); }
.timer-time { font-family: var(--font-num); font-size: 132px; font-weight: 700; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.timer-round { text-align: center; font-size: 20px; color: var(--text-2); }
.timer-bg-work { background: var(--accent-soft); }
.timer-bg-rest { background: var(--water-bg); }
.sync-fail { font-size: 13px; color: var(--warn); padding: 6px 0; border-bottom: 1px solid var(--line); }
.install-banner { border: 1px solid var(--accent); }

/* Update offer (new service worker waiting). Hidden during a workout. */
#update-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 40;
  background: var(--surface-2); border: 1px solid var(--accent); border-radius: 14px; padding: 8px 8px 8px 14px;
  display: flex; align-items: center; gap: 10px; font-size: 14px; max-width: 536px; margin: 0 auto;
}
#update-bar span { flex: 1; }
body:has(#app.fullscreen) #update-bar { display: none; }

/* Week calendar (Today) */
.cal-card { gap: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-day { min-height: 92px; border-radius: 12px; border: 1px solid transparent; background: var(--bg); padding: 6px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text); }
.cal-day.is-today { border: 2px solid var(--accent); }
.cal-wd { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.cal-date { font-family: var(--font-num); font-size: 18px; font-weight: 600; line-height: 1.1; }
.cal-items { display: flex; flex-direction: column; align-items: center; gap: 3px; margin-top: 2px; width: 100%; }
.cal-w { font-family: var(--font-num); font-size: 16px; font-weight: 700; line-height: 1; padding: 4px 0; border-radius: 6px; width: calc(100% - 6px); text-align: center; background: var(--surface-2); }
.cal-w.done { background: var(--accent); color: var(--accent-ink); }
.cal-w.today { background: transparent; border: 2px solid var(--accent); color: var(--accent); padding: 2px 0; }
.cal-w.missed { background: transparent; border: 1px dashed var(--line-strong); color: var(--text-faint); padding: 3px 0; }
.cal-c { font-size: 10px; color: var(--text-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-missed { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.day-row { display: flex; align-items: center; gap: 8px; min-height: 56px; border-bottom: 1px solid var(--line); }
.move-target { padding: 0 6px; gap: 4px; }

/* Meal plan check-list (Diet) */
.plan-meal { padding: 12px 8px 6px 14px; gap: 0; }
.plan-meal.complete { opacity: .75; }
.plan-meal-head { display: flex; align-items: center; gap: 10px; padding-bottom: 6px; }
.plan-item { display: flex; align-items: center; border-top: 1px solid var(--line); }
.plan-check { flex: 1; min-width: 0; min-height: 60px; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 4px 0; text-align: left; }
.plan-box { width: 30px; height: 30px; flex: none; border-radius: 9px; border: 2px solid var(--line-strong); display: flex; align-items: center; justify-content: center; color: var(--accent-ink); }
.plan-item.on .plan-box { background: var(--accent); border-color: var(--accent); }
.plan-item.on .plan-name { color: var(--text-muted); text-decoration: line-through; }
.plan-more { width: 48px; height: 52px; border: 0; background: none; color: var(--text-muted); font-size: 22px; flex: none; }
.factor-btn { flex-direction: column; gap: 0; min-height: 60px; }

/* Calendar v2: the day header opens the day; each workout chip opens its detail. */
.cal-day { padding: 0 2px 6px; gap: 0; }
.cal-head { width: 100%; background: none; border: 0; padding: 6px 0 2px; display: flex; flex-direction: column; align-items: center; gap: 0; color: var(--text); min-height: 40px; }
.cal-w { border: 0; color: var(--text); min-height: 30px; font-size: 15px; padding: 0 1px; display: flex; align-items: center; justify-content: center; }
.cal-w.cardio { font-family: var(--font-text); font-size: 10px; font-weight: 700; letter-spacing: .01em; }
.cal-w.planned { background: var(--surface-2); }
.cal-w.missed { padding: 0 1px; }
.card-open, .day-open { background: none; border: 0; padding: 0; text-align: left; color: var(--text); min-height: 48px; justify-content: center; }
.detail-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.detail-ex { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.detail-n { font-family: var(--font-num); font-size: 20px; font-weight: 700; color: var(--text-faint); width: 20px; flex: none; }
