/* ===========================================================================
   Workout Tracker

   Paper, not a console. A light ground because the use scene is a brightly
   lit gym; ink for the primary action; green only for work completed; one
   warm note when a set beats your best.

   Two structural rules, both learned the hard way:

   1. No eyebrows. A heading carries its own weight — no SET / PREVIOUS / KG
      label rows, no kicker above a title. Units live inline with the number
      they belong to, so a logged set reads "24 kg x 10" rather than sitting
      under a spreadsheet header.
   2. Last week's numbers are the placeholders. Recognition beats recall, and
      it removes a whole column from the densest screen in the app.
   =========================================================================== */

:root {
  color-scheme: light dark;

  /* Ground is light because the use scene is a brightly lit gym, not because
     fitness apps are usually dark. */
  --ink: #F1F2F4;
  --ink-raise: #FFFFFF;
  --chrome: rgba(255, 255, 255, 0.88);

  --glass: #FFFFFF;
  --glass-strong: #FFFFFF;
  --glass-sunken: #F5F6F8;
  --hairline: #E4E7EB;
  --hairline-strong: #D2D7DE;
  --specular: rgba(255, 255, 255, 0);

  --text: #14161A;
  --text-2: #5C6472;
  --text-3: #5A616C;

  /* The primary action is ink on paper, not a glowing accent. */
  --accent: #16181C;
  --accent-deep: #000000;
  --on-accent: #FFFFFF;
  --accent-wash: #EDEFF2;
  --accent-edge: #D2D7DE;

  /* Completed work reads green; it is the only routine colour in the app. */
  --done: #14743F;
  --done-wash: #E4F1E9;
  --done-edge: #B4DCC4;
  --on-done: #FFFFFF;
  /* a switch that is on: green in both themes, deep enough to hold a white knob */
  --switch-on: #14743F;

  /* Beating your best is the one warm moment. */
  --ember: #A34A00;
  --ember-hot: #7E3800;
  --ember-wash: #FBEBDC;

  --ok: #14743F;
  --danger: #B3261E;
  --danger-solid: #B3261E;

  --r-card: 24px;
  --r-control: 14px;
  --r-capsule: 999px;

  --tabbar-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --surface-border: transparent;
  --surface-shadow: 0 6px 20px -10px rgba(16, 20, 28, 0.22);
  --lift: 0 6px 20px -10px rgba(16, 20, 28, 0.22);
  --lift-sheet: 0 -16px 44px -24px rgba(16, 20, 28, 0.28);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-exp: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #101215;
    --ink-raise: #181B20;
    --chrome: rgba(24, 27, 32, 0.90);
    --glass: #181B20;
    --glass-strong: #1D2126;
    --glass-sunken: #14171B;
    --hairline: #2A2F36;
    --hairline-strong: #3A4048;
    --specular: rgba(255, 255, 255, 0.04);
    --text: #F2F4F6;
    --text-2: #A7AFBA;
    --text-3: #98A1AC;
    --accent: #F2F4F6;
    --accent-deep: #FFFFFF;
    --on-accent: #101215;
    --accent-wash: #22262C;
    --accent-edge: #3A4048;
    --done: #63D397;
    --done-wash: #14301F;
    --done-edge: #2A6B45;
    --on-done: #07210F;
    --switch-on: #2E9E5F;
    --ember: #FFA55C;
    --ember-hot: #FF8A3D;
    --ember-wash: #33220F;
    --ok: #63D397;
    --danger: #FF7A6E;
    --danger-solid: #A8281F;
    --surface-border: #2A2F36;
    --surface-shadow: none;
    --lift: 0 8px 24px -14px rgba(0, 0, 0, 0.75);
    --lift-sheet: 0 -16px 44px -24px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--ink);
  color: var(--text);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.011em;
}

/* --------------------------------------------------------------- atmosphere
   Glass needs something behind it to bend. Two slow colour fields plus a
   grain overlay give the blurred chrome real depth instead of flat grey. */

.atmos {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--ink);
}



/* ------------------------------------------------------------- typography */

h1, h2, h3 { margin: 0; line-height: 1.08; font-weight: 700; letter-spacing: -0.03em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1.05rem; letter-spacing: -0.024em; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }

.muted { color: var(--text-2); }
.small { font-size: 0.84rem; }
.pad { padding: 1rem; }
.pad-top { padding-top: 0.55rem; }

/* every number in the app aligns and never jitters */
.set-input, .rest-time, .session-elapsed, .stat strong, .stat-card strong,
.sched-date, .set-prev, .mini-row, .history-sets, .rest-pill, .rest-option {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "ss01" 1;
}

/* Supporting labels are quiet, not shouted. */
.section-title h2, .month-head, .stat span, .stat-card span,
.sched-day, .mini-head, .chart-caption, .week-day, .field-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-3);
}

/* ----------------------------------------------------------------- splash */

.splash {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1rem;
  color: var(--text-2);
}
.splash-mark {
  width: 46px;
  height: 46px;
  color: var(--accent);
  animation: breathe 2.4s var(--ease) infinite;
}
.splash-mark svg { width: 100%; height: 100%; }
@keyframes breathe { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

.boot-error { padding: 2.5rem 1.25rem; }

/* ----------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: calc(var(--safe-top) + 0.65rem) 1.1rem 0.65rem;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--ink) 82%, transparent), transparent);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
}

.brand {
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--text-2);
}

.sync-badge {
  border: 1px solid var(--hairline);
  /* opaque: a blurred backdrop makes per-pixel contrast depend on whatever
     the atmosphere happens to paint behind it */
  background: var(--ink-raise);
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  min-height: 44px;
  padding: 0 0.85rem;
  border-radius: var(--r-capsule);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.sync-badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 32%, transparent); }
.sync-badge.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 38%, transparent); }
.sync-badge.busy { color: var(--accent); border-color: var(--accent-edge); }

/* ------------------------------------------------------------------- main */

.main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 2.4rem);
}
body.resting .main { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 7rem); }

.view {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.5rem 1.1rem 1rem;
  max-width: 620px;
  margin: 0 auto;
  width: 100%;
}

/* one orchestrated reveal per screen, not scattered fidgeting */
.view > * {
  animation: rise 0.5s var(--ease) both;
}
.view > *:nth-child(1) { animation-delay: 0.01s; }
.view > *:nth-child(2) { animation-delay: 0.05s; }
.view > *:nth-child(3) { animation-delay: 0.09s; }
.view > *:nth-child(4) { animation-delay: 0.13s; }
.view > *:nth-child(n+5) { animation-delay: 0.16s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.hero { display: flex; flex-direction: column; gap: 0.3rem; padding: 0.9rem 0 0.2rem; }
.hero h1 { font-size: 2.1rem; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.7rem;
}
.month-head { margin-top: 0.9rem; }

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--r-control);
  font: inherit;
  font-weight: 650;
  letter-spacing: -0.012em;
  padding: 0.78rem 1.1rem;
  min-height: 48px;
  cursor: pointer;
  background: var(--glass-strong);
  color: var(--text);
  border-color: var(--hairline);
  transition: transform 0.12s var(--ease-exp), filter 0.2s, opacity 0.2s;
}
.btn:active { transform: scale(0.975); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 115%);
  color: var(--on-accent);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 8px 18px -10px rgba(0, 0, 0, 0.65);
  font-weight: 700;
}

.btn-secondary { background: var(--glass); border-color: var(--hairline); }
.btn-ghost { background: transparent; border-color: var(--hairline-strong); }
.btn-quiet { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-danger { background: var(--danger-solid); color: #fff; border-color: transparent; }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.06rem; border-radius: 17px; }
.btn-sm { min-height: 46px; padding: 0.4rem 0.8rem; font-size: 0.85rem; border-radius: 11px; }

.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 1.15rem;
  line-height: 1;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  flex: none;
  transition: background 0.2s, color 0.2s;
}
.icon-btn:active { background: var(--glass-strong); color: var(--text); }
.icon-btn:disabled { opacity: 0.28; }
.icon-danger { color: var(--danger); }

/* ------------------------------------------------------------------ cards
   Content surfaces are opaque-ish, not blurred: they scroll, and blurring
   scrolling layers is where iOS drops frames. */

.card {
  background: var(--glass);
  border: 0;
  border-radius: var(--r-card);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  box-shadow: var(--surface-shadow);
}

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.6rem; }
.card-tap { text-align: left; cursor: pointer; font: inherit; color: inherit; }
.card-cta { color: var(--accent); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.01em; }

.routine-grid { display: grid; gap: 0.65rem; }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }

.note {
  background: var(--accent-wash);
  border: 1px solid var(--accent-edge);
  border-radius: var(--r-card);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  font-size: 0.92rem;
}

.empty {
  text-align: center;
  padding: 2.6rem 1rem;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}
.empty-icon { width: 34px; height: 34px; color: var(--text-3); margin-bottom: 0.3rem; }
.empty-icon svg { width: 100%; height: 100%; }
.empty h3 { color: var(--text); font-size: 1.15rem; }

/* ------------------------------------------------------------------ stats */

.stat-row { display: flex; gap: 0.75rem; justify-content: space-between; }
.stat { display: flex; flex-direction: column; gap: 0.18rem; flex: 1; min-width: 0; }
.stat strong { font-size: 1.12rem; font-weight: 700; letter-spacing: -0.03em; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.65rem; }
.stat-card {
  background: var(--glass);
  border: 0;
  border-radius: 18px;
  padding: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  box-shadow: var(--surface-shadow);
}
.stat-card strong { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.045em; }

/* ---------------------------------------------------------------- session */

.session-head { display: flex; align-items: flex-start; gap: 0.7rem; padding-top: 0.6rem; }
.session-head-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }

.session-title {
  background: transparent;
  border: none;
  min-height: 44px;
  color: var(--text);
  font: inherit;
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.038em;
  padding: 0;
  width: 100%;
  line-height: 1.05;
}
.session-title:focus { outline: none; }

.session-elapsed { color: var(--text-2); font-size: 0.86rem; font-weight: 600; }
.tile .session-elapsed { color: var(--text); font-size: inherit; font-weight: inherit; }


.entries { display: flex; flex-direction: column; gap: 0.75rem; }

.entry {
  background: var(--ink-raise);
  border: 0;
  border-radius: var(--r-card);
  padding: 1.1rem 1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-shadow: var(--surface-shadow);
}
.entry-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.entry h3 { font-size: 1.32rem; letter-spacing: -0.028em; }

/* one meta line, not three stacked labels */
.entry-meta {
  font-size: 0.88rem;
  color: var(--text-2);
  margin-top: 3px;
}
.entry-meta strong { color: var(--text); font-weight: 650; }

.entry-note {
  font-size: 0.88rem;
  color: var(--text-2);
  margin-top: 7px;
  line-height: 1.4;
  padding-left: 0.7rem;
  border-left: 2px solid var(--hairline);
}

.entry-rest { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; }
.rest-pill {
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  color: var(--text-2);
  border-radius: var(--r-capsule);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 1rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

/* ------------------------------------------------------------- set rows */

.sets { display: flex; flex-direction: column; gap: 0.5rem; }

.set-row {
  display: grid;
  grid-template-columns: 26px 1fr 1fr 52px;
  gap: 0.5rem;
  align-items: center;
  padding: 0.25rem 0.5rem 0.25rem 0;
  border-radius: 16px;
  margin-inline: -0.15rem;
  padding-left: 0.15rem;
}

/* the number is small by design; its hit area is not */
.set-index {
  position: relative;
  background: none;
  border: none;
  color: var(--text-3);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 650;
  height: 44px;
  cursor: pointer;
  padding: 0;
}
.set-index::after { content: ""; position: absolute; inset: 0 -9px; }

/* number and unit are one object, so a set reads as a phrase */
.set-field {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.28rem;
  background: var(--glass-sunken);
  border: 1.5px solid var(--hairline);
  border-radius: 15px;
  height: 54px;
  padding: 0 0.55rem;
  transition: border-color 0.16s, background 0.16s;
}
.set-field:focus-within {
  border-color: var(--accent);
  background: var(--ink-raise);
}

.set-input {
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-align: right;
  width: 100%;
  min-width: 0;
  padding: 0;
}
.set-input:focus { outline: none; }
.set-input::placeholder { color: var(--text-3); font-weight: 600; opacity: 1; }

.set-unit {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-3);
  flex: none;
}

.set-check {
  height: 48px;
  width: 48px;
  justify-self: end;
  border-radius: 50%;
  border: 1.5px solid var(--hairline-strong);
  background: var(--ink-raise);
  color: var(--text-3);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s var(--ease-exp), background 0.18s, border-color 0.18s, color 0.18s;
}
.set-check:active { transform: scale(0.9); }
.set-check.on {
  background: var(--done);
  border-color: var(--done);
  color: var(--on-done);
}

/* a completed set is a filled band you can read across the room */
.set-row.set-done {
  background: var(--done-wash);
}
.set-done .set-field { border-color: var(--done-edge); background: transparent; }
.set-done .set-index { color: var(--done); }
.set-warmup .set-index { color: var(--ember); }

.set-pr { animation: ember 1.5s var(--ease); }
@keyframes ember {
  0% { background: var(--done-wash); }
  25% { background: var(--ember-wash); }
  100% { background: var(--done-wash); }
}
.set-pr .set-check.on { background: var(--ember); border-color: var(--ember); color: #fff; }

/* --------------------------------------------------------------- rest bar
   The hero moment. Real glass, oversized clock, a fill that drains left to
   right so you can read progress without reading the number. */

.restbar {
  position: fixed;
  left: 0.7rem;
  right: 0.7rem;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 0.75rem);
  z-index: 25;
  border-radius: 20px;
  overflow: hidden;
  background: var(--chrome);
  backdrop-filter: blur(28px) saturate(190%);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  border: 0;
  box-shadow: var(--surface-shadow);
  max-width: 604px;
  margin: 0 auto;
  animation: rise 0.35s var(--ease-exp) both;
}
.restbar[hidden] { display: none; }

/* scaleX, never width: animating a layout property re-lays out the bar on
   every frame of a three-minute countdown. */
.rest-fill {
  position: absolute;
  inset: 0;
  transform: scaleX(0);
  transform-origin: left center;
  will-change: transform;
  background: linear-gradient(90deg, var(--accent-wash), color-mix(in srgb, var(--accent) 22%, transparent));
  transition: transform 0.25s linear;
}

.restbar-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
}

.rest-main { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1; gap: 3px; }
.rest-time {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.restbar.urgent .rest-time { color: var(--accent); animation: tick 1s steps(2) infinite; }
@keyframes tick { 50% { opacity: 0.45; } }

.rest-adjust, .rest-skip {
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  color: var(--text);
  border-radius: 11px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  min-height: 44px;
  padding: 0 0.75rem;
  cursor: pointer;
  flex: none;
}
.rest-skip { background: transparent; color: var(--text-2); border-color: transparent; }

.rest-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.45rem; }
.rest-option {
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  color: var(--text);
  border-radius: 12px;
  padding: 0.65rem 0.2rem;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.rest-option.on {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 120%);
  color: var(--on-accent);
  border-color: transparent;
}

/* ----------------------------------------------------------------- tabbar
   Floating capsule rather than a full-width bar — the signature Liquid
   Glass control, and it lets the atmosphere show through underneath. */

.tabbar {
  position: fixed;
  left: 0.7rem;
  right: 0.7rem;
  bottom: calc(var(--safe-bottom) + 0.5rem);
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: var(--tabbar-h);
  border-radius: var(--r-capsule);
  background: var(--chrome);
  backdrop-filter: blur(30px) saturate(200%);
  -webkit-backdrop-filter: blur(30px) saturate(200%);
  border: 0;
  box-shadow: var(--surface-shadow);
  max-width: 604px;
  margin: 0 auto;
  padding: 0 0.3rem;
}

.tab {
  position: relative;
  background: none;
  border: none;
  color: var(--text-3);
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: color 0.22s var(--ease);
}
.tab-icon { display: block; width: 21px; height: 21px; transition: transform 0.3s var(--ease-exp); }
.tab-icon svg { width: 100%; height: 100%; display: block; }
.tab-label { font-size: 0.72rem; font-weight: 650; letter-spacing: 0.02em; }

.tab.live { color: var(--text); }
.tab.live .tab-icon::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.tab.live .tab-icon { position: relative; }

.tab.on { color: var(--text); }
.tab.on .tab-icon { transform: translateY(-1px) scale(1.06); }
.tab.on .tab-icon svg { stroke-width: 2.1; }
.tab.on::before {
  content: "";
  position: absolute;
  inset: 6px 4px;
  border-radius: var(--r-capsule);
  background: var(--accent-wash);
  border: 1px solid var(--accent-edge);
  z-index: -1;
  animation: pill 0.34s var(--ease-exp) both;
}
@keyframes pill { from { opacity: 0; transform: scale(0.82); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ forms */

.form { display: flex; flex-direction: column; gap: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-hint { font-size: 0.76rem; color: var(--text-3); letter-spacing: 0; text-transform: none; font-weight: 400; }

.input {
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--r-control);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 0.76rem 0.85rem;
  width: 100%;
  min-height: 48px;
}
.input:focus { outline: none; border-color: var(--accent-edge); background: var(--accent-wash); }
.input::placeholder { color: var(--text-3); }
textarea.input { min-height: 96px; resize: vertical; }
.input-sm { min-height: 40px; padding: 0.4rem 0.5rem; text-align: center; border-radius: 11px; }

.mini-field { display: flex; flex-direction: column; gap: 0.25rem; }
.mini-field span {
  font-size: 0.64rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-3); text-align: center;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0;
  cursor: pointer;
  font-size: 0.94rem;
}
.switch-input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  flex: none;
  width: 48px;
  height: 29px;
  border-radius: var(--r-capsule);
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  position: relative;
  transition: background 0.24s var(--ease), border-color 0.24s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform 0.28s var(--ease-exp), background 0.24s;
}
/* On is green in both themes. It used to borrow the accent, which in dark mode
   is near-white — under a white knob the whole switch vanished. */
.switch-input:checked ~ .switch-track {
  background: var(--switch-on);
  border-color: transparent;
}
.switch-input:checked ~ .switch-track::after {
  transform: translateX(19px);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}
.switch-input:focus-visible ~ .switch-track { outline: 2px solid var(--switch-on); outline-offset: 2px; }

/* ------------------------------------------------------------------ sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 8, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.24s var(--ease);
  z-index: 40;
}
.sheet-backdrop.open { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--chrome);
  backdrop-filter: blur(36px) saturate(190%);
  -webkit-backdrop-filter: blur(36px) saturate(190%);
  border-top-left-radius: 30px;
  border-top-right-radius: 30px;
  border-top: 0;
  box-shadow: var(--lift-sheet);
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.34s var(--ease);
  max-width: 620px;
  margin: 0 auto;
}
.sheet.open { transform: translateY(0); }
.sheet-full { height: 88dvh; }

.sheet-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.1rem 3rem 0.7rem;
  border-bottom: 1px solid var(--hairline);
}
.sheet-grip {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--hairline-strong);
}
.sheet-head h2 { font-size: 1.02rem; }
.sheet-close {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 1.6rem;
  line-height: 1;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1.1rem calc(1.4rem + var(--safe-bottom));
  flex: 1;
}

.menu { display: flex; flex-direction: column; }
.menu-item {
  background: none;
  border: none;
  border-bottom: 1px solid var(--hairline);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  text-align: left;
  padding: 1rem 0.25rem;
  cursor: pointer;
}
.menu-item:last-child { border-bottom: none; }
.menu-item:disabled { opacity: 0.3; }
.menu-danger { color: var(--danger); }

.confirm { display: flex; flex-direction: column; gap: 1.1rem; }
.confirm-actions { display: flex; gap: 0.55rem; }
.confirm-actions .btn { flex: 1; }

/* ----------------------------------------------------------------- picker */

.picker { display: flex; flex-direction: column; gap: 0.65rem; height: 100%; }
.picker-search { position: sticky; top: 0; }

/* flex-shrink:0 or the 5000px-tall result list below crushes this row to a
   few unreadable pixels. */
.chips {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: none;
  flex-shrink: 0;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  color: var(--text-2);
  border-radius: var(--r-capsule);
  padding: 0 0.9rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex: none;
}
.chip-on {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 130%);
  color: var(--on-accent);
  border-color: transparent;
}

.picker-list { display: flex; flex-direction: column; }
.picker-item {
  background: none;
  border: none;
  border-bottom: 1px solid var(--hairline);
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 0.85rem 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  cursor: pointer;
}
.picker-name { font-weight: 600; }
.picker-meta { font-size: 0.76rem; color: var(--text-3); }
.picker-create { color: var(--accent); }

/* --------------------------------------------------------------- routines */

.routine-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.routine-items li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 0.4rem;
}
.routine-items li:last-child { border-bottom: none; padding-bottom: 0; }

.editor-items { display: flex; flex-direction: column; gap: 0.6rem; }
.editor-item {
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--r-control);
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.editor-item-head { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; }
.editor-item-actions { display: flex; gap: 0.1rem; flex: none; }
.editor-item-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.45rem; }

/* ---------------------------------------------------------------- history */

.history-detail { display: flex; flex-direction: column; gap: 0.5rem; border-top: 1px solid var(--hairline); padding-top: 0.7rem; }
.history-line { display: grid; grid-template-columns: 1fr auto; gap: 0.18rem 0.5rem; font-size: 0.88rem; }
.history-ex { font-weight: 650; }
.history-best { color: var(--text-3); font-size: 0.76rem; text-align: right; font-weight: 600; }
.history-sets { color: var(--text-2); grid-column: 1 / -1; font-weight: 500; }

/* ------------------------------------------------------------------- plan */

.card-today {
  border-color: var(--accent-edge);
  background:
    linear-gradient(180deg, var(--accent-wash), transparent 62%),
    var(--glass);
  box-shadow: inset 0 1px 0 var(--specular), var(--lift);
}
.today-label { color: var(--accent); }
.card-today h3 { font-size: 1.55rem; letter-spacing: -0.035em; }

.sched { display: flex; flex-direction: column; }
.sched-row {
  display: grid;
  grid-template-columns: 32px 54px 1fr auto auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.89rem;
}
.sched-row:last-child { border-bottom: none; }
.sched-date { color: var(--text-3); font-size: 0.79rem; font-weight: 600; }
.sched-name { min-width: 0; font-weight: 650; line-height: 1.25; }
.sched-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.sched-row.is-rest .sched-name { color: var(--text-3); font-weight: 500; }
.sched-row.is-today {
  background: var(--accent-wash);
  margin: 0 -0.5rem;
  padding-inline: 0.5rem;
  border-radius: 12px;
  border-bottom-color: transparent;
}
.sched-row.is-today .sched-day { color: var(--accent); }
.sched-row.is-past { opacity: 0.45; }
.sched-row.is-done .sched-name { color: var(--text-2); }
.sched-done-tag { margin-left: 0.45rem; color: var(--ok); }
.sched-start { min-height: 44px; padding: 0 0.85rem; font-size: 0.82rem; border-radius: 11px; }
/* with several plans running, each session says which plan it came from */
.sched-plan {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* two sessions today: the second sits under the first, divided by a rule */
.today-block { display: flex; flex-direction: column; gap: 0.35rem; }
.today-block-next { border-top: 1px solid var(--hairline); padding-top: 0.8rem; margin-top: 0.45rem; }
.today-block-next h3 { font-size: 1.2rem; }

/* ------------------------------------------------------------ your plans */

.plan-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--hairline);
}
.plan-row:last-of-type { border-bottom: none; }
.plan-row-text { min-width: 0; }
.plan-row-name { font-weight: 700; overflow-wrap: anywhere; line-height: 1.3; }
.plan-row-actions { display: flex; gap: 0.3rem; flex: none; }
.plan-remove { color: var(--danger); }

.confirm-stack { display: flex; flex-direction: column; gap: 0.5rem; }
.custom-list { list-style: none; margin: 0.4rem 0 0; padding: 0; }
.in-use-list { margin: 0; padding-left: 1.1rem; font-weight: 600; line-height: 1.6; }

/* ------------------------------------------------------- training days */

.setup-lead { font-size: 1rem; line-height: 1.45; }
.day-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.3rem;
}
.day-chip {
  position: relative;
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--hairline-strong);
  background: var(--glass-sunken);
  color: var(--text-2);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.day-chip.is-on {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
}
/* a day another plan already trains on: a quiet dot, not a warning */
.day-chip.is-taken::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 7px;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
}
.setup-count { font-weight: 700; font-size: 0.9rem; color: var(--text-2); }
.setup-count.is-ready { color: var(--done); }

.switch-note { display: block; margin-top: 0.15rem; }



.week-block {
  border: 1px solid var(--hairline);
  border-radius: var(--r-control);
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--glass-sunken);
}
.week-head { display: flex; align-items: center; justify-content: space-between; }
.week-row { display: grid; grid-template-columns: 38px 1fr; gap: 0.5rem; align-items: center; }

.plan-input {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  line-height: 1.55;
  min-height: 200px;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.plan-preview {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--r-control);
  padding: 0.8rem;
}
.plan-ok { font-weight: 700; font-size: 0.92rem; }
.plan-session { font-size: 0.84rem; }
.plan-weeks { margin-top: 0.45rem; display: flex; flex-direction: column; gap: 0.18rem; }
.plan-note { font-size: 0.8rem; color: var(--accent); margin-top: 0.35rem; }
.plan-warn { font-size: 0.8rem; color: var(--danger); }

/* ------------------------------------------------------- program library */

.prog-browse { display: flex; flex-direction: column; gap: 0.55rem; }
.prog-browse .picker-list { margin-top: 0.15rem; }
.prog-summary {
  font-size: 0.86rem;
  color: var(--text-2);
  line-height: 1.35;
}
.prog-detail { display: flex; flex-direction: column; gap: 0.7rem; }
.prog-para {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-2);
}
.prog-detail .field-label { margin-top: 0.2rem; }
.update-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem 1rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
  background: var(--ink-raise);
  border-top: 1px solid var(--hairline-strong);
  font-size: 0.9rem;
  font-weight: 600;
  transform: translateY(100%);
  transition: transform 0.28s var(--ease-exp);
}
.update-bar.show { transform: translateY(0); }

.prog-session {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--hairline);
}
.prog-session:last-of-type { border-bottom: none; }
.prog-session-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-bottom: 0.15rem;
}
.prog-day { font-size: 0.72rem; color: var(--text-3); font-weight: 700; }
.prog-ex {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.5rem;
  font-size: 0.84rem;
  line-height: 1.5;
}
.prog-ex-sets { color: var(--text-3); font-variant-numeric: tabular-nums; }
.prog-ex-name { color: var(--text-2); }
a.prog-ex-name { color: var(--text); text-decoration: underline; text-decoration-color: var(--hairline-strong); text-underline-offset: 2px; }
.prog-taste {
  font-size: 0.78rem;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prog-source {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-3);
  border-left: 2px solid var(--hairline-strong);
  padding-left: 0.6rem;
}

/* ----------------------------------------------------------------- charts */

.chart { width: 100%; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-empty { color: var(--text-3); font-size: 0.85rem; padding: 1.2rem 0; text-align: center; }
.chart-caption { margin-top: 0.65rem; }

.chart-grid { stroke: var(--hairline); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent-wash); stroke: none; }
.chart-dot { fill: var(--accent); }
.chart-bar { fill: var(--accent); opacity: 0.8; }
.chart-label { fill: var(--text-3); font-size: 9px; font-family: inherit; font-weight: 600; }

.mini-table { display: flex; flex-direction: column; }
.mini-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.8rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.87rem;
  font-weight: 550;
}
.mini-row:last-child { border-bottom: none; }
.mini-head { font-weight: 700; }
.mini-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------- settings */

.sync-status { font-size: 0.86rem; color: var(--text-2); }
.sync-status.is-ok { color: var(--ok); }
.sync-status.is-error { color: var(--danger); }

.help { display: flex; flex-direction: column; gap: 0.8rem; font-size: 0.93rem; }
.help ol { margin: 0; padding-left: 1.25rem; display: flex; flex-direction: column; gap: 0.65rem; }
.code-block {
  display: block;
  background: var(--glass-sunken);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  margin-top: 0.4rem;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  word-break: break-all;
  user-select: all;
  color: var(--accent);
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 3.6rem);
  transform: translate(-50%, -0.8rem);
  z-index: 60;
  background: var(--chrome);
  backdrop-filter: blur(24px) saturate(190%);
  -webkit-backdrop-filter: blur(24px) saturate(190%);
  border: 0;
  color: var(--text);
  padding: 0.7rem 1.15rem;
  border-radius: var(--r-capsule);
  font-size: 0.89rem;
  font-weight: 600;
  box-shadow: inset 0 1px 0 var(--specular), var(--lift);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s var(--ease), transform 0.34s var(--ease-exp);
  max-width: calc(100vw - 2rem);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-success { border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.toast-error { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }

/* achievement toast burns warm */
.toast-success.is-pr {
  border-color: var(--ember);
  color: var(--ember);
  box-shadow: inset 0 1px 0 var(--specular), var(--lift);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .view > * { animation: none; opacity: 1; transform: none; }
}


/* ---------------------------------------------------------------- summary */

.summary { display: flex; flex-direction: column; gap: 0.9rem; }
.sum-headline { font-size: 1.9rem; letter-spacing: -0.042em; }
.sum-delta { font-size: 0.88rem; font-weight: 650; color: var(--text-2); }
.sum-delta.up { color: var(--ok); }
.sum-delta.down { color: var(--text-2); }
.sum-stats { border-top: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); padding: 0.8rem 0; }
.sum-prs {
  background: var(--ember-wash);
  border: 1px solid color-mix(in srgb, var(--ember) 40%, transparent);
  border-radius: var(--r-control);
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.sum-prs .today-label { color: var(--ember); }
.sum-pr { font-size: 0.92rem; }
.sum-lines { display: flex; flex-direction: column; }
.sum-line {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.sum-line:last-child { border-bottom: none; }

/* ---------------------------------------------------------------- session */

.entry-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding-top: 0.15rem;
}

/* the session's own numbers, given weight rather than a caption */
.session-totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
}
.tile {
  background: var(--ink-raise);
  border: 0;
  border-radius: 18px;
  padding: 0.75rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.tile strong {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}
.tile span { font-size: 0.78rem; color: var(--text-3); font-weight: 550; }
.tile.is-progress { background: var(--done-wash); }
.tile.is-progress strong { color: var(--done); }
.tile.is-time strong { font-variant-numeric: tabular-nums; }


/* ------------------------------------------------------- depth per theme
   On paper a soft shadow lifts a card. In the dark a shadow is invisible,
   so a hairline does the work instead — never both, which is the stock
   "generated card" signature. */
@media (prefers-color-scheme: dark) {
  .card, .entry, .tile, .stat-card {
    border: 1px solid var(--hairline);
    box-shadow: none;
  }
  .tile.is-progress { border-color: var(--done-edge); }
  .tabbar, .restbar, .toast { border: 1px solid var(--hairline-strong); }
  .sheet { border-top: 1px solid var(--hairline-strong); }
}


/* -------------------------------------------------------- schedule editing */

/* Only the grip opts out of touch scrolling. Putting touch-action:none on the
   whole row would make the 21-day list impossible to scroll on a phone. */
.sched-grip {
  touch-action: none;
  background: none;
  border: 0;
  padding: 0 0.15rem;
  width: 36px;
  height: 44px;
  color: var(--text-3);
  cursor: grab;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sched-grip svg { width: 20px; height: 20px; display: block; }
.sched-grip:active { cursor: grabbing; color: var(--text); }

.sched-row.is-dragging {
  /* so elementFromPoint sees the row underneath, not the one being dragged */
  pointer-events: none;
  position: relative;
  z-index: 2;
  background: var(--ink-raise);
  border-radius: 12px;
  box-shadow: var(--lift);
  opacity: 0.96;
}

.sched-row.is-drop-target {
  background: var(--accent-wash);
  border-radius: 12px;
  outline: 2px solid var(--accent-edge);
  outline-offset: -2px;
}

.picker-item.is-selected { background: var(--accent-wash); }
.picker-item.picker-danger { color: var(--danger); }
