:root {
  --bg: #0f1216;
  --surface: #171c22;
  --surface-2: #212932;
  --border: #2b333d;
  --text: #e8edf2;
  --muted: #8a97a5;
  --accent: #4cc38a;
  --accent-dim: #24503c;
  --accent-text: #06130c;
  --danger: #e5484d;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

/* Fast repeated taps (steppers, chips, ±15s) must not trigger the mobile
   double-tap zoom. Set on the root so near-miss taps beside a button
   can't zoom either — scrolling and pinch zoom stay available, and the
   floor map's own touch-action: none still wins (intersection). */
html { touch-action: manipulation; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

#view {
  flex: 1;
  overflow-y: auto;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(76px + env(safe-area-inset-bottom));
}

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

#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

#tabbar a {
  flex: 1;
  text-align: center;
  padding: 15px 0 13px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#tabbar a.active { color: var(--accent); }

/* --- typography & layout bits --- */

h1 { font-size: 22px; margin: 10px 0 16px; }

h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin: 0 0 10px;
}

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

.muted { color: var(--muted); font-size: 13px; }

a { color: var(--accent); }

.notice {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
}

.btn .sub { display: block; font-weight: 400; font-size: 13px; margin-top: 4px; opacity: 0.8; }
.footnote { margin-top: 20px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

/* --- buttons --- */

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin: 8px 0;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { filter: brightness(1.2); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-big { padding: 18px; font-size: 17px; }

.btn-next { background: var(--accent-dim); border-color: var(--accent); color: #dff5e9; }

.btn-danger {
  color: var(--danger);
  background: transparent;
  border-color: rgba(229, 72, 77, 0.4);
}

.btn-danger.armed { background: var(--danger); color: #fff; }

/* armed state of non-danger two-tap buttons (finish, template replace) */
.btn.armed:not(.btn-danger) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-inline { display: inline-block; width: auto; padding: 10px 14px; margin: 0; }

.btn:disabled { opacity: 0.45; cursor: default; }

a.btn { text-decoration: none; }

/* --- forms --- */

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
  font-size: 15px;
}

input[type="number"], input[type="text"] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  min-width: 0;
}

/* iOS auto-zooms into focused fields below 16px — never go under it */
input[type="number"], input[type="text"], select, textarea { font-size: max(16px, 1em); }

input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.field input[type="text"] { flex: 1; max-width: 62%; }
.field > span { flex-shrink: 0; }

.field-block { margin: 14px 0; font-size: 15px; }
.field-block > span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.field-block .row { margin-top: 8px; }

.chip-select { display: flex; flex-wrap: wrap; gap: 6px; }
.chip.sel { background: var(--accent-dim); border-color: var(--accent); color: #dff5e9; }

/* quick-switch: swing back to a recently trained other station */
.quick-switch { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }

.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; }

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.swatch.none {
  background: linear-gradient(135deg, transparent 44%, var(--muted) 44%,
    var(--muted) 56%, transparent 56%);
  border-color: var(--border);
}

.swatch.sel { border-color: #fff; }

.map-mode { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.toolbar-sub { flex-wrap: wrap; }
.toolbar-sub .btn { flex: 1 1 22%; }

textarea {
  width: 100%;
  font: 13px/1.5 ui-monospace, 'SF Mono', Monaco, monospace;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
}

.stack { display: block; margin: 10px 0; }
.stack > span { display: block; margin-bottom: 6px; }

.stepper { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.stepper input {
  width: 76px;
  text-align: center;
  padding: 11px 4px;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.stepper button {
  width: 48px;
  height: 48px;
  font-size: 24px;
  line-height: 1;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.stepper button:active { filter: brightness(1.3); }

/* --- studio --- */

.studio-head { align-items: center; }
.undo-group { display: flex; gap: 6px; }
.undo-group .btn { min-width: 48px; font-size: 18px; padding: 10px 12px; }

.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar .btn { margin: 0; padding: 12px 8px; font-size: 14px; }
.toolbar-sub .btn { padding: 9px 4px; font-size: 12px; font-weight: 500; }

svg .fixture-box { fill: #242d38; stroke: #4a5765; stroke-width: 0.12; }
svg .door-gap { fill: #10151c; }
svg .entrance-arrow { fill: none; stroke: #b9c4cf; stroke-width: 0.22; stroke-linecap: round; stroke-linejoin: round; }
svg .window-gap { fill: #10151c; }
svg .window-line { stroke: #7d92a8; stroke-width: 0.14; }
svg .door-arc { fill: none; stroke: #8a97a5; stroke-width: 0.12; stroke-dasharray: 0.5 0.35; }
svg .door-leaf { stroke: #b9c4cf; stroke-width: 0.28; stroke-linecap: round; }
svg .fixture-icon, svg .zone-label { font-family: system-ui, -apple-system, sans-serif; }
svg .zone-label { fill: #5f6d7d; font-weight: 600; letter-spacing: 0.04em; }

.floor-wrap { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }

svg.floor { display: block; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }

svg .outline-floor { fill: #10151c; stroke: #4a5765; stroke-width: 0.45; stroke-linejoin: round; }
svg .vertex { fill: #fff; stroke: #0f1216; stroke-width: 0.1; cursor: grab; }
svg .vertex.sel { fill: var(--accent); }
svg .midpoint { fill: var(--surface); stroke: #8a97a5; stroke-width: 0.14; cursor: copy; }

svg .shape-rect { fill: #1a212b; stroke: #38424e; stroke-width: 0.15; }
svg .shape-line { stroke: #38424e; stroke-width: 0.35; stroke-linecap: round; }
svg .hit { stroke: transparent; stroke-width: 2; fill: none; }
/* Fill-based invisible tap targets for finger-sized handles and pads.
   Kept separate from .hit (stroke-based, for thin lines) so the two
   rules never fight over fill when combined. */
svg .tap-hit { fill: transparent; stroke: none; }
svg .vertex-hit { cursor: grab; }
svg .mid-hit { cursor: copy; }
svg .handle-hit { cursor: nwse-resize; }
svg .handle-icon { stroke: #0f1216; fill: none; stroke-linecap: round; stroke-linejoin: round; }
svg .machine-box { fill: var(--accent-dim); stroke: var(--accent); stroke-width: 0.15; }
svg .machine-num { fill: #dff5e9; font-weight: 700; font-family: system-ui, -apple-system, sans-serif; }
svg .selected-outline { fill: none; stroke: #fff; stroke-width: 0.2; stroke-dasharray: 0.7 0.5; }
svg .handle { fill: #fff; stroke: #0f1216; stroke-width: 0.1; }
svg .grid-line { stroke: #ffffff; stroke-opacity: 0.04; stroke-width: 0.05; }

#props .card { margin-top: 10px; }

/* --- train --- */

.machine-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  border-radius: 10px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: #dff5e9;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.machine-badge.sm { min-width: 34px; height: 34px; font-size: 15px; border-radius: 8px; }

.machine-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.machine-head .title { font-size: 19px; font-weight: 700; }

/* a button restyled as a flush tappable row — the plan, recent and muscle
   rows share this reset and add only their own layout below */
.plan-row,
.recent-row .recent-info,
.muscle-row {
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.plan-row:active,
.recent-row .recent-info:active,
.muscle-row:active { filter: brightness(1.3); }

/* workout overview hub */
.plan-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.plan-row:last-of-type { border-bottom: 0; }
.plan-row .plan-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-row .plan-status { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.plan-row .plan-status.done { color: var(--accent); }

/* an exercise that has no machine yet: dashed badge, "assign" as the call
   to action — open work, not an error */
.plan-row.unbound .machine-badge,
.plan-item.unbound .machine-badge {
  background: none;
  border: 1px dashed var(--border);
  color: var(--muted);
}

.plan-row.unbound .plan-status { color: var(--accent); }

/* what today is about — one stated line above the start button */
.day-status {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--muted);
}

.day-status strong { color: var(--text); }
.day-status.done { color: var(--accent); }
.day-status.done strong { color: var(--accent); }
.day-status.missed strong { color: var(--text); }

/* an inline action inside a sentence — a button that reads as a link */
.linkish {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* recent workouts on the start screen */
.recent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.recent-row:last-child { border-bottom: 0; }
/* it IS a button (tap = open its settings) — the shared row reset above
   strips the chrome; only the column layout lives here */
.recent-row .recent-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0;
  margin: 0;
}
.recent-row .recent-info .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-row .row-chevron { color: var(--muted); flex-shrink: 0; font-size: 18px; }
.recent-row .btn-inline { flex-shrink: 0; }

/* plan builder: one editable item per machine (reorder, remove, targets) */
.plan-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.plan-item:last-child { border-bottom: 0; }
.plan-item-head { display: flex; align-items: center; gap: 10px; }
.plan-item-head .plan-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.plan-item-actions { display: flex; flex-shrink: 0; }
.plan-item-actions .x { color: var(--muted); background: none; border: 0; font-size: 16px; padding: 6px 8px; cursor: pointer; }
.plan-item .chip-select { margin: 8px 0 2px; }
.plan-item .it-bind { margin: 8px 0 0; }
/* the bind prompt, inline under the item it belongs to */
.plan-bind {
  margin: 8px 0 2px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.plan-bind .chip-select { margin: 8px 0; max-height: 132px; overflow-y: auto; }
.plan-bind .btn { margin-top: 4px; }
.plan-targets { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.plan-targets .spread { align-items: center; }
.plan-targets .label { font-size: 14px; color: var(--muted); width: 96px; }

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.set-row:last-child { border-bottom: 0; }
.set-row .x { color: var(--muted); background: none; border: 0; font-size: 18px; padding: 6px 10px; cursor: pointer; }

/* inline history edit: compact weight/reps inputs inside a set row */
.edit-set { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.edit-set input { width: 64px; text-align: center; }

/* exercise chips: mark movements already logged this session */
.chip.done::after { content: ' ✓'; }

.next-set { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.next-set .spread { align-items: center; }
.next-set .label { font-size: 14px; color: var(--muted); width: 64px; }

.pick-muscle { margin-top: 10px; }

.pick-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 9px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip:active { filter: brightness(1.2); }

.doc-link { font-size: 13px; }

.map-wrap { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); margin: 10px 0; }
.map-wrap svg { display: block; width: 100%; }
.map-wrap .machine-box { cursor: pointer; }

/* 📍 "where is it?" triggers — open the fullscreen map overlay.
   min 44px box follows the touch-target guideline used across the app. */
.locate-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 17px;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.locate-btn:active { filter: brightness(1.4); }

.next-row { display: flex; gap: 8px; }
.next-row #next-machine { flex: 1; min-width: 0; }
.next-row .locate-next { flex: 0 0 auto; width: auto; padding-inline: 16px; }

/* --- rest overlay --- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 13, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 50;
  padding: 24px;
}

.overlay .countdown {
  font-size: 84px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.overlay .countdown.done { color: var(--accent); }
.overlay .row { width: 100%; max-width: 360px; }

/* Dimmed rest screen: the display stays ON (the wake lock's job) — this
   only stops it glaring in a dark gym. The countdown keeps TICKING: each
   passing second jerks it brighter for a moment (.lit, driven per second
   from tick()), which reads as "the timer is alive" while the average lit
   area stays low. Controls fade further back but stay tappable — opacity
   does not affect hit testing. */
.overlay .countdown, .overlay > .muted, .overlay .row, .overlay .rest-opts {
  transition: opacity 320ms ease;
}

.overlay.dim { background: rgba(4, 5, 7, 0.985); }
.overlay.dim .countdown { opacity: 0.22; transition: opacity 220ms ease-out; }
.overlay.dim .countdown.lit { opacity: 0.55; transition-duration: 60ms; }
.overlay.dim > .muted, .overlay.dim .row, .overlay.dim .rest-opts { opacity: 0.3; }

/* the timer's own settings row — small chips, out of the way */
.rest-opts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; }
.chip.sm { padding: 6px 11px; font-size: 12px; }

/* --- map overlay ("where is it?") --- */

.map-overlay { gap: 16px; }
.map-overlay .map-wrap { width: 100%; max-width: 528px; margin: 0; }

/* the white stroke itself comes inline from machineSvg's highlightId */
svg .machine.locate .machine-box { animation: locate-pulse 1.1s ease-in-out infinite; }

@keyframes locate-pulse {
  50% { stroke-width: 1; stroke-opacity: 0.35; }
}

/* Collapsed locker row on the workout overview: once sets are logged the
   locker is a detail, so it reads as one quiet line above Finish — same
   markerless summary as History's workout rows. */
details.locker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 14px;
  margin-bottom: 14px;
}

details.locker summary { list-style: none; cursor: pointer; padding: 10px 0; color: var(--muted); }
details.locker summary::-webkit-details-marker { display: none; }
details.locker .row { margin-bottom: 12px; }

/* --- history --- */

details.workout { border-bottom: 1px solid var(--border); padding: 4px 0; }
details.workout summary { list-style: none; cursor: pointer; padding: 10px 0; }
details.workout summary::-webkit-details-marker { display: none; }
.entry-line { padding: 6px 0 6px 12px; font-size: 14px; border-left: 2px solid var(--border); margin: 6px 0; }
.entry-line .sets { color: var(--muted); font-variant-numeric: tabular-nums; }

/* training-days heatmap — sequential ramp, dark→light monotone */
.hm-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.hm-head .btn-inline { min-width: 48px; font-size: 18px; }

.hm-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin-top: 10px;
}

.hm-dow { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0; }

.hm-cell {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.hm-cell.l1 { background: #183b2b; border-color: transparent; color: #b9d6c7; }
.hm-cell.l2 { background: #23593f; border-color: transparent; color: #cfe8db; }
.hm-cell.l3 { background: #2c7d55; border-color: transparent; color: #e2f4ea; }
.hm-cell.l4 { background: #35a273; border-color: transparent; color: #06130c; }
.hm-cell.today { outline: 2px solid var(--text); outline-offset: -2px; }
.hm-cell:active { filter: brightness(1.3); }

.hm-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  justify-content: flex-end;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.hm-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: inline-block;
}

.hm-swatch.l1 { background: #183b2b; border-color: transparent; }
.hm-swatch.l2 { background: #23593f; border-color: transparent; }
.hm-swatch.l3 { background: #2c7d55; border-color: transparent; }
.hm-swatch.l4 { background: #35a273; border-color: transparent; }

#hm-machine { margin-bottom: 4px; }

/* muscle usage: one tappable row per group, bar LENGTH carries the value
   (single accent — hue would just duplicate the channel). Button reset
   comes from the shared row ruleset; block display stacks the bar track. */
.muscle-row {
  width: 100%;
  display: block;
  padding: 9px 4px;
  border-bottom: 1px solid var(--border);
}
.muscle-row:last-child { border-bottom: 0; }
.muscle-row.sel { background: var(--accent-dim); border-radius: 8px; }
.muscle-row .m-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.bar-track {
  display: block; /* spans collapse to height 0 otherwise */
  height: 6px;
  margin-top: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
/* bar color #35a273 on its real background, the track's --surface-2
   (#212932): 4.6:1 — re-check against THAT, not the card surface */
.bar-fill { display: block; height: 100%; background: #35a273; border-radius: 3px; }

.chart-wrap { position: relative; margin-top: 10px; }
.chart-wrap svg { display: block; width: 100%; }

/* chart color #35a273 validated against surface #171c22 (dataviz checks) */
.c-grid { stroke: rgba(255, 255, 255, 0.06); stroke-width: 1; }
.c-tick { fill: var(--muted); font-size: 11px; font-family: system-ui, -apple-system, sans-serif; }
.c-line { fill: none; stroke: #35a273; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: #35a273; stroke: var(--surface); stroke-width: 2; }
.c-hit { fill: transparent; }
.c-label { fill: var(--text); font-size: 12px; font-weight: 600; font-family: system-ui, -apple-system, sans-serif; }

.c-tip {
  position: absolute;
  transform: translate(-50%, -130%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  width: 100%;
}

/* --- empty states --- */

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}

.empty .big { font-size: 40px; margin-bottom: 12px; }
