/* ============================================================================
   Workout Log — design system
   ----------------------------------------------------------------------------
   Dark-first, with a selected (not auto-inverted) light theme. Layout is
   mobile-first: a bottom tab bar and thumb-reachable controls at the rack,
   promoted to a left sidebar with multi-column content on the desktop.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens -- */
:root {
  color-scheme: dark;

  /* surfaces & ink */
  --bg: #0a0b0d;
  --bg-grad: radial-gradient(120% 80% at 50% -10%, #12161d 0%, #0a0b0d 62%);
  --surface: #14171c;
  --surface-2: #1b1f26;
  --surface-3: #232832;
  --border: #262b34;
  --border-2: #333a46;
  --text: #f3f5f8;
  --text-2: #a3abb9;
  --text-3: #6b7382;

  /* brand & status */
  --accent: #5b8cff;
  --accent-hi: #85a8ff;
  --accent-ink: #07090c;
  --accent-soft: rgba(91, 140, 255, 0.15);
  --accent-line: rgba(91, 140, 255, 0.34);
  --good: #35d399;
  --good-ink: #04150e;
  --good-soft: rgba(53, 211, 153, 0.12);
  --good-line: rgba(53, 211, 153, 0.32);
  --warn: #f0a93b;
  --danger: #ff5f6d;
  --danger-soft: rgba(255, 95, 109, 0.12);

  /* data series — validated for this surface in both modes */
  --series-1: #4b87f0;
  --series-2: #d9762e;
  --series-3: #19a276;
  --series-4: #9085e9;

  /* elevation */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 6px 20px -6px rgba(0, 0, 0, 0.6);
  --shadow-3: 0 24px 48px -16px rgba(0, 0, 0, 0.75);
  --ring: 0 0 0 3px var(--accent-soft);

  /* geometry */
  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 26px;
  --r-full: 999px;

  /* motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast: 110ms;
  --t: 190ms;
  --t-slow: 340ms;

  /* metrics */
  --nav-h: 64px;
  --bar-h: 56px;
  --sidebar-w: 252px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --maxw: 780px;
}

/* Light theme: independently chosen steps, not an inversion of the dark set. */
@media (prefers-color-scheme: light) {
  :root:where(:not([data-theme='dark'])) {
    color-scheme: light;
    --bg: #f4f6f9;
    --bg-grad: radial-gradient(120% 80% at 50% -10%, #ffffff 0%, #f4f6f9 60%);
    --surface: #ffffff;
    --surface-2: #f3f5f8;
    --surface-3: #e9edf3;
    --border: #e3e8ef;
    --border-2: #d2d9e3;
    --text: #10141a;
    --text-2: #55606f;
    --text-3: #838e9e;
    --accent: #2563d9;
    --accent-hi: #1c50b4;
    --accent-ink: #ffffff;
    --accent-soft: rgba(37, 99, 217, 0.1);
    --accent-line: rgba(37, 99, 217, 0.28);
    --good: #0f9268;
    --good-ink: #ffffff;
    --good-soft: rgba(15, 146, 104, 0.10);
    --good-line: rgba(15, 146, 104, 0.3);
    --warn: #b4740c;
    --danger: #d93b48;
    --danger-soft: rgba(217, 59, 72, 0.09);
    --series-1: #2563d9;
    --series-2: #d2601f;
    --series-3: #0f9268;
    --series-4: #5646b8;
    --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-2: 0 8px 24px -8px rgba(16, 24, 40, 0.16);
    --shadow-3: 0 24px 48px -16px rgba(16, 24, 40, 0.24);
  }
}
:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f4f6f9;
  --bg-grad: radial-gradient(120% 80% at 50% -10%, #ffffff 0%, #f4f6f9 60%);
  --surface: #ffffff;
  --surface-2: #f3f5f8;
  --surface-3: #e9edf3;
  --border: #e3e8ef;
  --border-2: #d2d9e3;
  --text: #10141a;
  --text-2: #55606f;
  --text-3: #838e9e;
  --accent: #2563d9;
  --accent-hi: #1c50b4;
  --accent-ink: #ffffff;
  --accent-soft: rgba(37, 99, 217, 0.1);
  --accent-line: rgba(37, 99, 217, 0.28);
  --good: #0f9268;
  --good-ink: #ffffff;
  --good-soft: rgba(15, 146, 104, 0.10);
  --good-line: rgba(15, 146, 104, 0.3);
  --warn: #b4740c;
  --danger: #d93b48;
  --danger-soft: rgba(217, 59, 72, 0.09);
  --series-1: #2563d9;
  --series-2: #d2601f;
  --series-3: #0f9268;
  --series-4: #5646b8;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-2: 0 8px 24px -8px rgba(16, 24, 40, 0.16);
  --shadow-3: 0 24px 48px -16px rgba(16, 24, 40, 0.24);
}

/* ------------------------------------------------------------------ base -- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { margin: 0; font-weight: 680; letter-spacing: -0.015em; line-height: 1.25; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Every number in the UI is compared against another number — line them up. */
input[type='number'],
.tabular,
.stat-n,
.pr-n,
.set-row,
.data-table,
.chart-tip { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* Components below set display:flex/grid, which would otherwise win over the
   browser default for [hidden]. Keep the attribute authoritative. */
[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

/* ----------------------------------------------------------------- shell -- */
.content {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: var(--safe-t);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease);
}
.appbar.is-stuck { border-bottom-color: var(--border); }

.appbar-in {
  height: var(--bar-h);
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
#view-title {
  font-size: 20px;
  font-weight: 720;
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.appbar-actions { display: flex; align-items: center; gap: 6px; }

main {
  flex: 1;
  padding: 12px 16px calc(var(--nav-h) + var(--safe-b) + 28px);
}
.view {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: viewIn var(--t-slow) var(--ease-out) both;
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------------- nav -- */
.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}
.nav-brand { display: none; }
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 620;
  letter-spacing: 0.01em;
  text-decoration: none;
  position: relative;
  transition: color var(--t) var(--ease);
}
.tab:hover { text-decoration: none; color: var(--text-2); }
.tab .ico { transition: transform var(--t) var(--ease-out); }
.tab.active { color: var(--accent); }
.tab.active .ico { transform: translateY(-1px) scale(1.06); }
/* A short rule above the active tab reads faster than color alone. */
.tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 26px;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--accent);
}

/* ----------------------------------------------------------------- cards -- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-1);
}
.card-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-title .ico { color: var(--text-3); }
.section-title { font-size: 17px; font-weight: 700; letter-spacing: -0.015em; }

/* --------------------------------------------------------------- buttons -- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-bd: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 15px;
  font-weight: 640;
  letter-spacing: -0.005em;
  white-space: nowrap;
  transition: transform var(--t-fast) var(--ease), filter var(--t) var(--ease),
    background var(--t) var(--ease), border-color var(--t) var(--ease);
  touch-action: manipulation;
}
.btn:active { transform: scale(0.975); }
.btn:hover { filter: brightness(1.08); }
.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-ink);
  --btn-bd: transparent;
  box-shadow: 0 4px 14px -6px var(--accent);
}
.btn-quiet { --btn-bg: transparent; }
.btn-danger { --btn-bg: transparent; --btn-fg: var(--danger); --btn-bd: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn-danger:hover { background: var(--danger-soft); filter: none; }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 13.5px; border-radius: var(--r-sm); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

/* Dashed affordance = "bring something in", distinct from a solid commit. */
.btn-dashed {
  border-style: dashed;
  border-color: var(--border-2);
  background: transparent;
  color: var(--text-2);
}
.btn-dashed:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); filter: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-3);
  transition: background var(--t) var(--ease), color var(--t) var(--ease), transform var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- inputs -- */
input[type='text'],
input[type='number'],
input[type='password'],
input[type='date'],
select,
textarea {
  width: 100%;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 16px; /* keeps iOS from zooming on focus */
  outline: none;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), background var(--t) var(--ease);
  appearance: none;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type='number'] { -moz-appearance: textfield; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 6px;
}

/* -------------------------------------------------------------- segments -- */
.seg {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.seg-btn {
  flex: 1;
  min-height: 38px;
  padding: 0 10px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 640;
  transition: background var(--t) var(--ease), color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* -------------------------------------------------------------- date bar -- */
.datebar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 6px;
  box-shadow: var(--shadow-1);
}
.datebar .icon-btn { width: 42px; height: 42px; color: var(--text-2); }
.date-pick {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t) var(--ease);
}
.date-pick:hover { background: var(--surface-2); }
.date-pick input[type='date'] {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}
.date-main { font-size: 15.5px; font-weight: 680; letter-spacing: -0.01em; pointer-events: none; }
.date-sub { font-size: 11.5px; color: var(--text-3); pointer-events: none; margin-top: -1px; }

/* --------------------------------------------------------- session hero -- */
.hero { display: flex; flex-direction: column; gap: 12px; }
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hero-metrics { display: flex; gap: 20px; flex-wrap: wrap; }
.hm { display: flex; flex-direction: column; gap: 1px; }
.hm-n { font-size: 21px; font-weight: 720; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hm-l { font-size: 11px; font-weight: 620; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); }

.progress {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-hi));
  transition: width var(--t-slow) var(--ease-out);
}
.progress.done > i { background: linear-gradient(90deg, var(--good), var(--good)); }

/* --------------------------------------------------------- exercise card -- */
.exercise { padding: 14px 14px 10px; transition: border-color var(--t) var(--ease); }
.exercise.complete { border-color: var(--good-line); }

.ex-head { display: flex; align-items: flex-start; gap: 10px; }
.ex-id {
  flex: none;
  min-width: 26px; height: 26px;
  margin-top: 1px;
  padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-xs);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px; font-weight: 750; letter-spacing: 0.02em;
}
.ex-titles { flex: 1; min-width: 0; }
.ex-name {
  font-size: 16px;
  font-weight: 690;
  letter-spacing: -0.015em;
  cursor: text;
  border-radius: 5px;
  transition: background var(--t) var(--ease);
}
.ex-name:hover { background: var(--surface-2); }
.ex-sub { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 620;
  color: var(--text-2);
  white-space: nowrap;
}
.chip-target { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip-pr { background: var(--good-soft); border-color: transparent; color: var(--good); }
.ex-count { font-size: 12px; font-weight: 660; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------------------- set table -- */
.sets { margin-top: 12px; }
/* Delete gets a real column of its own. Floating it over the row let it sit
   on top of the check button and swallow taps meant for "set complete". */
.set-row {
  display: grid;
  grid-template-columns: 30px minmax(46px, 1fr) minmax(46px, 1fr) 42px 40px 26px;
  gap: 5px;
  align-items: center;
}
.set-head {
  padding-bottom: 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  text-align: center;
}
.set-head > span:first-child { text-align: left; padding-left: 4px; }

.set {
  position: relative;
  padding: 3px 2px;
  border-radius: var(--r-sm);
  animation: setIn var(--t) var(--ease-out) both;
  transition: background var(--t) var(--ease);
}
@keyframes setIn {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: none; }
}
.set-num {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.set-prev { font-size: 9.5px; font-weight: 600; color: var(--text-3); opacity: 0.8; }
.set input.cell {
  text-align: center;
  padding: 8px 2px;
  font-weight: 640;
  border-radius: var(--r-sm);
}
.set input.cell::placeholder { font-weight: 500; opacity: 0.6; }
.set .set-rpe { font-size: 14px; color: var(--text-2); }

/* Completing a set is the primary gesture in the gym — make it a real target. */
.set-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-3);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease),
    color var(--t) var(--ease), transform var(--t-fast) var(--ease);
}
.set-check:hover { border-color: var(--good); color: var(--good); }
.set-check:active { transform: scale(0.9); }
.set-check .ico { opacity: 0.4; transition: opacity var(--t) var(--ease), transform var(--t) var(--ease-out); }
.set.is-done .set-check {
  background: var(--good);
  border-color: var(--good);
  color: var(--good-ink);
}
.set.is-done .set-check .ico { opacity: 1; }
/* Tint stops short of the check so the row reads as a row, not a green slab. */
.set.is-done { background: var(--good-soft); }
.set.is-done .set-num { color: var(--good); }
.set.is-done input.cell { background: transparent; border-color: transparent; }

.set-del {
  width: 26px; height: 26px;
  color: var(--text-3);
  opacity: 0.4;
  transition: opacity var(--t) var(--ease), color var(--t) var(--ease), background var(--t) var(--ease);
}
.set:hover .set-del, .set:focus-within .set-del { opacity: 1; }
.set-del:hover { opacity: 1; }

.add-set {
  width: 100%;
  margin-top: 6px;
  min-height: 42px;
  border: 1px dashed var(--border-2);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 640;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--t) var(--ease);
}
.add-set:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* --------------------------------------------------------------- add bar -- */
.add-exercise { display: flex; gap: 8px; }
.add-exercise input { flex: 1; }

/* ---------------------------------------------------------- rest timer -- */
.rest {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  z-index: 45;
  width: min(440px, calc(100vw - 24px));
  transform: translate(-50%, 140%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  backdrop-filter: blur(14px);
  transition: transform var(--t-slow) var(--ease-out), opacity var(--t) var(--ease);
  opacity: 0;
}
.rest.show { transform: translate(-50%, 0); opacity: 1; }
.rest-ring { flex: none; width: 34px; height: 34px; transform: rotate(-90deg); }
.rest-ring circle { fill: none; stroke-width: 3.5; stroke-linecap: round; }
.rest-ring .track { stroke: var(--surface-3); }
.rest-ring .bar { stroke: var(--accent); transition: stroke-dashoffset 1s linear; }
.rest-info { flex: 1; min-width: 0; line-height: 1.25; }
.rest-time { font-size: 18px; font-weight: 720; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.rest-label { font-size: 11px; font-weight: 620; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); }
.rest.is-up .rest-time { color: var(--good); }
.rest.is-up .rest-ring .bar { stroke: var(--good); }

/* ------------------------------------------------------------ stat tiles -- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
  box-shadow: var(--shadow-1);
}
.stat-n { display: block; font-size: 24px; font-weight: 730; letter-spacing: -0.025em; line-height: 1.1; }
.stat-l { display: block; margin-top: 4px; font-size: 11.5px; font-weight: 620; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }

/* --------------------------------------------------------------- history -- */
.hist { padding: 14px 16px; transition: transform var(--t) var(--ease), border-color var(--t) var(--ease); }
.hist:hover { border-color: var(--border-2); }
.hist-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.hist-date { font-size: 15.5px; font-weight: 700; letter-spacing: -0.015em; }
.hist-sub { margin-top: 2px; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.hist-actions { display: flex; gap: 2px; flex: none; }
.hist-body { margin-top: 10px; display: flex; flex-direction: column; gap: 7px; }
.hist-ex { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; font-size: 13.5px; }
.hist-ex-name { font-weight: 620; }
.hist-ex-sets { color: var(--text-3); text-align: right; font-variant-numeric: tabular-nums; }
.hist-notes {
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--text-2);
}

/* ---------------------------------------------------------------- charts -- */
.chart-plot { position: relative; width: 100%; }
.chart { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .c-grid { stroke: var(--border); stroke-width: 1; }
.chart .c-axis { fill: var(--text-3); font-size: 11px; font-weight: 560; }
.chart .c-line { stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
/* The 2px surface ring keeps dots legible where they cross the line. */
.chart .c-dot { stroke: var(--surface); stroke-width: 2; }
.chart .c-focus { stroke: var(--surface); stroke-width: 2.5; }
.chart .c-cross { stroke: var(--border-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .c-endlabel rect { fill: var(--surface-2); stroke: var(--border); stroke-width: 1; }
.chart .c-endlabel text { fill: var(--text); font-size: 12px; font-weight: 700; }
.chart-empty {
  padding: 44px 12px;
  text-align: center;
  color: var(--text-3);
  font-size: 13.5px;
}
.chart-tip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  padding: 7px 10px;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
}
.chart-tip .tip-d { display: block; color: var(--text-3); font-weight: 600; }
.chart-tip .tip-v { display: block; color: var(--text); font-weight: 700; font-size: 13.5px; }

/* PR grid */
.pr-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pr {
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.pr-n { display: block; font-size: 21px; font-weight: 730; letter-spacing: -0.02em; line-height: 1.15; }
.pr-l { display: block; margin-top: 2px; font-size: 12px; font-weight: 620; }
.pr-d { display: block; font-size: 11px; color: var(--text-3); }

/* data table */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  padding: 7px 6px;
  text-align: right;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table td { padding: 9px 6px; text-align: right; border-bottom: 1px solid var(--surface-2); white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--t) var(--ease); }
.data-table tbody tr:hover { background: var(--surface-2); }

/* ---------------------------------------------------------------- states -- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-3);
  background: var(--surface);
  border: 1px dashed var(--border-2);
  border-radius: var(--r-lg);
}
.empty-ico {
  display: grid;
  place-items: center;
  width: 52px; height: 52px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-3);
}
.empty-t { font-size: 15px; font-weight: 660; color: var(--text-2); }
.empty-d { font-size: 13px; max-width: 34ch; }

/* Single column until the desktop breakpoint promotes it to two. */
.grid-2 { display: flex; flex-direction: column; gap: 14px; }

.muted { color: var(--text-3); }
.small { font-size: 12.5px; line-height: 1.55; }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------------------------------------------------------------- modals -- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(3, 5, 8, 0.55);
  backdrop-filter: blur(3px);
  animation: fadeIn var(--t) var(--ease) both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 18px 16px calc(18px + var(--safe-b));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: sheetUp var(--t-slow) var(--ease-out) both;
}
@keyframes sheetUp { from { transform: translateY(14px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-head h3 { font-size: 18px; }
.modal-grip {
  width: 38px; height: 4px;
  border-radius: var(--r-full);
  background: var(--border-2);
  margin: -6px auto 2px;
}
.pp-preview {
  max-height: 34dvh;
  overflow-y: auto;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
}
.pp-ex {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px;
  border-radius: var(--r-xs);
  font-size: 13px;
}
.pp-ex + .pp-ex { border-top: 1px solid var(--border); }
.pp-ex b { font-weight: 640; }
.pp-ex span { color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- toast -- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 18px);
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-3);
  font-size: 13.5px;
  font-weight: 620;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px) scale(0.97);
  transition: opacity var(--t) var(--ease), transform var(--t-slow) var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ------------------------------------------------------------------ sync -- */
.sync-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.sync-toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 4px 0; cursor: pointer; }
.sync-toggle input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.sync-help { margin: 6px 0; padding-left: 20px; }
.sync-help li { margin: 4px 0; }
code {
  padding: 1.5px 5px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.sync-status {
  display: flex; align-items: center; gap: 7px;
  min-height: 20px;
  margin: 4px 0;
  font-size: 12.5px;
  font-weight: 620;
  word-break: break-word;
}
.sync-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; flex: none; background: currentColor; }
.sync-status:empty { display: none; }
.sync-idle { color: var(--text-3); }
.sync-working { color: var(--accent); }
.sync-working::before { animation: pulse 1.1s var(--ease) infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.sync-ok { color: var(--good); }
.sync-error { color: var(--danger); }
.card.danger { border-color: color-mix(in srgb, var(--danger) 34%, var(--border)); }

.bw-form { display: grid; grid-template-columns: 1.15fr 1fr auto; gap: 8px; }

/* =========================================================== breakpoints == */

/* Roomier phones / small tablets */
@media (min-width: 480px) {
  .stats-row { grid-template-columns: repeat(4, 1fr); }
  .set-row { grid-template-columns: 42px minmax(64px, 1fr) minmax(64px, 1fr) 56px 48px; gap: 8px; }
}

/* Desktop: the bottom bar becomes a sidebar and content gains a second column */
@media (min-width: 1000px) {
  :root { --maxw: 900px; }

  .nav {
    top: 0; right: auto; bottom: 0;
    width: var(--sidebar-w);
    height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 18px 14px;
    border-top: none;
    border-right: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 70%, transparent);
  }
  .nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 20px;
    font-size: 15.5px;
    font-weight: 730;
    letter-spacing: -0.02em;
  }
  .nav-brand .mark {
    display: grid; place-items: center;
    width: 32px; height: 32px;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--accent-ink);
  }
  .tab {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 12px;
    height: 44px;
    border-radius: var(--r-md);
    font-size: 14.5px;
    font-weight: 640;
  }
  .tab:hover { background: var(--surface-2); }
  .tab.active { background: var(--accent-soft); }
  .tab.active::before { display: none; }
  .tab.active .ico { transform: none; }

  .content { margin-left: var(--sidebar-w); }
  main { padding: 16px 28px 60px; }
  .appbar-in { padding: 0 28px; }
  :root { --nav-h: 0px; }

  .toast, .rest { left: calc(50% + var(--sidebar-w) / 2); }
  .rest { bottom: 24px; }
  .toast { bottom: 28px; }

  /* Trends reads better as a two-column board on a wide screen. */
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  .grid-2 > .span-2 { grid-column: 1 / -1; }
  .pr-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1280px) {
  :root { --maxw: 1080px; }
}
