/* ============================================================
   Workout Tracker — "training instrument" identity.

   Direction: dark graphite panel, amber = action/live, cyan =
   reference/history, green = done. Space Grotesk for UI voice,
   JetBrains Mono for every figure (weights, reps, dates, ticks)
   so numbers read like a dashboard.

   Usability rules preserved from v1 (and tightened):
   - every tappable control >= 50px (--tap), steppers 56px tall
   - all text tokens >= 4.5:1 on their surface, marks >= 3:1
   - no decoration that competes with the numbers
   ============================================================ */

:root {
  --bg: #0b0d10;             /* page plane */
  --surface: #151a20;        /* cards (chart surface — palette validated on this) */
  --surface-2: #1d242c;      /* nested: steppers, chips, inputs */
  --surface-3: #27303a;      /* pressed / empty progress segments */
  --border: #2a333e;
  --border-strong: #3a4653;
  --grid: #222a33;           /* chart hairlines, one step off surface */

  --text: #eaeff5;
  --text-2: #b7c2cd;
  --muted: #8d9aa8;          /* 6.1:1 on --surface — safe at micro sizes */

  --accent: #ffb454;         /* amber — action & "now" */
  --accent-ink: #221503;     /* text on amber, 10:1 */
  --cyan: #56c8e0;           /* reference & history info */
  --green: #4ad189;          /* completed / success */
  --green-ink: #0b2213;
  --red: #f07575;

  --chart-1: #c98500;        /* chart-band amber (validated pair) */
  --chart-2: #1ba3cc;        /* chart-band cyan */

  --font-ui: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "JetBrains Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 14px;
  --radius-sm: 10px;
  --tap: 50px;               /* minimum tap-target size */
  --elev-card: inset 0 1px 0 rgba(255, 255, 255, 0.045),
               0 14px 28px -22px rgba(0, 0, 0, 0.9);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  background: var(--bg);
  background-image: radial-gradient(1100px 520px at 50% -12%, #10151b 0%, var(--bg) 70%);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

/* Main column: full-width on phones, centered on desktop.
   Top/bottom safe-area insets keep content clear of the Dynamic Island and
   home indicator in standalone (Home Screen) mode, where viewport-fit=cover
   extends the page under them. */
#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 14px calc(96px + env(safe-area-inset-bottom));
}

/* ---------- type scale ---------- */

h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin-bottom: 2px;
}

/* section heads: mono micro-label + hairline rule, instrument style */
h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-num);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 24px 0 10px;
}
h2::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.kicker {
  font-family: var(--font-num);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  margin-bottom: 4px;
}
.session-head .kicker { color: var(--accent); }

.muted { color: var(--muted); font-size: 14px; }
.num { font-family: var(--font-num); }
.spacer { height: 8px; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;   /* no 300ms double-tap-zoom delay */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

/* ---------- generic cards & buttons ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--elev-card);
  padding: 14px;
  margin-bottom: 12px;
}

.btn {
  display: block;
  width: 100%;
  min-height: 54px;
  border-radius: var(--radius);
  font-family: var(--font-num);
  font-size: 14.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 80ms ease, filter 80ms ease;
}
.btn:active { transform: translateY(1px) scale(0.99); filter: brightness(0.94); }

.btn-primary {
  background: linear-gradient(180deg, #ffc06a, #f7a844);
  border-color: #c07f24;
  color: var(--accent-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35),
              0 10px 20px -12px rgba(255, 180, 84, 0.55);
}
.btn-green {
  background: linear-gradient(180deg, #5adf99, #3ec87e);
  border-color: #2b9e63;
  color: var(--green-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35),
              0 10px 20px -12px rgba(74, 209, 137, 0.5);
}

.btn-danger-link {
  color: var(--red);
  font-size: 14px;
  font-weight: 500;
  min-height: var(--tap);
  padding: 0 12px;
}

/* ---------- day picker (Log view, no active session) ---------- */

.day-card {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--elev-card);
  padding: 16px 16px 14px;
  margin-bottom: 10px;
  transition: transform 80ms ease, background 80ms ease;
}
.day-card:active { background: var(--surface-2); transform: scale(0.99); }
.day-card.today { border-color: rgba(255, 180, 84, 0.55); }
.day-card.today::before {
  content: "";
  position: absolute;
  left: -1px; top: 14px; bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(255, 180, 84, 0.5);
}

.day-top { display: flex; align-items: center; gap: 10px; }
.day-key { font-size: 19px; font-weight: 700; }
.day-focus { color: var(--text-2); font-size: 14px; margin-top: 2px; }
.day-meta {
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-top: 8px;
}

.badge {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: 99px;
  padding: 3px 9px;
}

/* ---------- active session: exercise cards ---------- */

.ex-card { padding: 14px; transition: border-color 200ms ease; }
.ex-card.complete { border-color: rgba(74, 209, 137, 0.45); }
.ex-card.just-done { animation: done-glow 700ms ease-out; }

.ex-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ex-name { font-size: 16px; font-weight: 700; }
.ex-count { font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.ex-count.done { color: var(--green); }

/* per-set progress segments: fills green as sets are logged */
.segs { display: flex; gap: 4px; margin-top: 9px; }
.seg { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-3); }
.seg.on { background: var(--green); }
.seg-new { transform-origin: left; animation: seg-fill 300ms 40ms ease-out both; }

.ex-target {
  font-family: var(--font-num);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-top: 9px;
}

.ex-last { font-size: 13px; color: var(--text-2); margin-top: 7px; }
.ex-last .k {
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--cyan);
  margin-right: 6px;
}
.ex-last b { font-family: var(--font-num); font-size: 12.5px; font-weight: 500; color: var(--text); }

/* logged-set chips: tap to remove — green = done */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  min-height: 42px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: rgba(74, 209, 137, 0.1);
  border: 1px solid rgba(74, 209, 137, 0.35);
  font-family: var(--font-num);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}
.chip:active { transform: scale(0.96); }
.chip .x { color: var(--muted); margin-left: 8px; font-size: 11px; }
.chip-new { animation: chip-pop 280ms cubic-bezier(0.2, 1.4, 0.4, 1); }

/* weight / reps steppers */
.stepper-row { display: flex; gap: 10px; margin-top: 12px; }
.stepper-block { flex: 1; }
.stepper-block.narrow { flex: 0.8; }
.stepper-label {
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.stepper {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), inset 0 -1px 0 rgba(0, 0, 0, 0.25);
}
.stepper button {
  flex: 0 0 50px;
  min-height: 56px;
  font-family: var(--font-num);
  font-size: 25px;
  font-weight: 700;
  color: var(--accent);
  background: transparent;
  transition: background 60ms ease;
}
.stepper button:active { background: rgba(255, 180, 84, 0.16); }
.stepper input {
  flex: 1;
  width: 40px;              /* flex does the real sizing; keeps inputs from overflowing */
  min-height: 56px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-num);
  font-size: 20px;          /* >=16px so iOS doesn't zoom on focus */
  font-weight: 700;
  text-align: center;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.stepper input:focus { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 9px; }
.stepper input.bump { animation: num-bump 180ms ease-out; }

/* small phones: keep the row fitting without shrinking tap height */
@media (max-width: 370px) {
  .stepper button { flex-basis: 46px; }
  .stepper input { font-size: 18px; }
}

.log-set-btn { margin-top: 12px; }

/* session header + footer */
.session-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

.feel-row { display: flex; gap: 8px; margin: 10px 0 4px; }
.feel-btn {
  flex: 1;
  min-height: 54px;
  font-size: 24px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  opacity: 0.5;
  transition: opacity 120ms ease, border-color 120ms ease;
}
.feel-btn.selected {
  opacity: 1;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 0 14px rgba(255, 180, 84, 0.18);
}
.feel-caption { text-align: center; font-size: 13px; color: var(--muted); min-height: 18px; }

textarea.note {
  width: 100%;
  min-height: 72px;
  margin-top: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  resize: vertical;
}
textarea.note:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- progress view ---------- */

select.select {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 0 44px 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23ffb454' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 14px center;
  box-shadow: var(--elev-card);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 12px;
  appearance: none;
  -webkit-appearance: none;
}

.stats-row { display: flex; gap: 8px; margin-bottom: 12px; }
.stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--elev-card);
  padding: 11px 8px 9px;
  text-align: center;
}
.stat .v { font-family: var(--font-num); font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.stat .k {
  font-family: var(--font-num);
  font-size: 9.5px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

.legend { display: flex; gap: 16px; margin-bottom: 8px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.legend .key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }

.chart-caption {
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

svg.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .tick {
  fill: var(--muted);
  font-family: var(--font-num);
  font-size: 9px;
  letter-spacing: 0.04em;
}
svg.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .pt { stroke: var(--surface); stroke-width: 2; }   /* surface ring */
svg.chart .wash { stroke: none; }

/* scrub cursor: touch/drag the chart to read exact values */
svg.chart .scrub-line { stroke: var(--border-strong); stroke-width: 1; }
svg.chart .scrub-pt { stroke: var(--surface); stroke-width: 2; }
svg.chart .scrub-txt {
  font-family: var(--font-num);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  fill: var(--text-2);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.chart-empty { color: var(--muted); font-size: 14px; padding: 24px 0; text-align: center; }

.recent-list { margin-top: 6px; }
.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-num);
  font-size: 12.5px;
  font-weight: 500;
}
.recent-item:last-of-type { border-bottom: none; }

/* expand/collapse the recent lists (default: latest 5) */
.show-more {
  display: block;
  width: 100%;
  min-height: var(--tap);
  border-top: 1px solid var(--border);
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.show-more:active { background: rgba(255, 180, 84, 0.08); }
.recent-item .del {
  color: var(--muted);
  font-size: 16px;
  min-width: var(--tap);
  min-height: var(--tap);
  display: flex; align-items: center; justify-content: center;
}

.bw-row { display: flex; gap: 10px; align-items: flex-end; }
.bw-row .stepper-block { flex: 1.4; }
.bw-row .btn { flex: 1; min-height: 58px; }

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

.session-card { padding: 0; overflow: hidden; }
.session-summary {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px;
}
.session-summary:active { background: var(--surface-2); }
.session-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.session-title .d { font-weight: 700; font-size: 16px; }
.session-title .feel { font-size: 20px; }
.session-detail { border-top: 1px solid var(--border); padding: 12px 14px; }
.session-ex { margin-bottom: 10px; font-size: 14px; }
.session-ex .n { font-weight: 500; }
.session-ex .s { color: var(--muted); font-family: var(--font-num); font-size: 12.5px; }
.session-note { font-style: italic; color: var(--muted); font-size: 14px; margin: 6px 0 10px; }

.empty-state { text-align: center; color: var(--muted); padding: 48px 16px; font-size: 15px; }
.empty-state .big { font-size: 40px; margin-bottom: 10px; }

/* ---------- bottom tab bar ---------- */

#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(11, 13, 16, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 11px 0 9px;
  min-height: 60px;
  color: var(--muted);
  position: relative;
  transition: color 120ms ease;
}
.tab.active { color: var(--accent); }
.tab.active::after {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 26px; height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(255, 180, 84, 0.7);
}
.tab-icon { width: 23px; height: 23px; }
.tab-label {
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.tab .tab-dot {
  position: absolute;
  top: 8px; right: calc(50% - 24px);
  width: 8px; height: 8px;
  border-radius: 99px;
  background: var(--green);
  animation: dot-pulse 1.8s ease-in-out infinite;
}

/* ---------- lock screen ---------- */

body.locked #tabbar { display: none; }

.lock-screen {
  min-height: calc(100vh - 180px);
  max-width: 320px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.lock-icon { width: 42px; height: 42px; margin: 0 auto 14px; color: var(--accent); }
.lock-screen .kicker { margin-bottom: 6px; }
.lock-screen h1 { margin-bottom: 4px; }
.lock-screen .muted { margin-bottom: 20px; }

.pw-input {
  width: 100%;
  min-height: 54px;
  margin-bottom: 10px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-num);
  font-size: 17px;          /* >=16px so iOS doesn't zoom on focus */
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
}
.pw-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.pw-input::placeholder {
  color: var(--muted);
  font-weight: 400;
  letter-spacing: normal;
  text-transform: uppercase;
  font-size: 12px;
}

.pw-error { color: var(--red); font-size: 14px; min-height: 22px; margin-top: 12px; }

.lock-shake { animation: lock-shake 320ms ease-in-out; }
@keyframes lock-shake {
  20% { transform: translateX(-7px); }
  45% { transform: translateX(6px); }
  70% { transform: translateX(-4px); }
  90% { transform: translateX(2px); }
}

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

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 13px 22px;
  border-radius: 99px;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 20;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 10px 30px rgba(0, 0, 0, 0.55);
  animation: toast-in 200ms cubic-bezier(0.2, 1.2, 0.4, 1);
}

/* ---------- motion ---------- */

.view-enter { animation: view-in 220ms ease-out; }

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes chip-pop {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes seg-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}
@keyframes num-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes done-glow {
  0%   { box-shadow: 0 0 0 0 rgba(74, 209, 137, 0.45); }
  100% { box-shadow: 0 0 0 16px rgba(74, 209, 137, 0); }
}
@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
@keyframes toast-in {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}

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