/*
 * Phone-first. Sizing is driven by one constraint: this gets used standing up,
 * mid-set, with sweaty hands, under time pressure. Nothing interactive is
 * smaller than 48px and the primary actions sit in the bottom third.
 */

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaef;
  --muted: #8d94a5;
  --accent: #6ea8fe;
  --accent-ink: #06101f;
  --warn: #f0b232;
  --bad: #f2555a;
  --ok: #4ec98a;
  --tap: 48px;
  --pad: 14px;
}

* { box-sizing: border-box; }

/*
 * Must outrank the display rules below: .sheet/.banner/.toast all set a
 * display value, which beats the UA stylesheet's [hidden] { display: none }
 * and leaves closed sheets on screen.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100dvh;
  /* room for the action bar and the tab bar beneath it */
  padding-bottom: calc(176px + env(safe-area-inset-bottom));
}

h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.85rem; border-radius: 9px; }
.btn-lg { min-height: 60px; font-size: 1.05rem; width: 100%; }
.btn-danger { color: var(--bad); }

.icon {
  min-width: var(--tap);
  min-height: var(--tap);
  font-size: 1.25rem;
  color: var(--muted);
  border-radius: 12px;
}

/* ---------- chrome ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: calc(env(safe-area-inset-top) + 4px) 6px 4px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg) 78%, transparent);
  z-index: 5;
}
.day { flex: 1; min-height: var(--tap); font-weight: 700; font-size: 1.02rem; }

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px var(--pad);
  background: #3a2d10;
  border-bottom: 1px solid #5a4416;
  color: #ffe0a3;
  font-size: 0.88rem;
}
.banner span { flex: 1; }

.session-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 var(--pad) 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.actions {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(58px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  padding: 14px var(--pad) 10px;
  background: linear-gradient(transparent, var(--bg) 32%);
  z-index: 5;
}

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

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 6;
}
.tab {
  flex: 1;
  min-height: 58px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  border-top: 2px solid transparent;
}
.tab[aria-pressed="true"] { color: var(--accent); border-top-color: var(--accent); }

.block-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 var(--pad) 8px;
  padding: 8px 12px;
  background: #1b2436;
  border: 1px solid #2c3b56;
  border-radius: 12px;
  font-size: 0.88rem;
}
.block-bar span { flex: 1; }
.actions .btn-primary { flex: 2; min-height: 58px; font-size: 1.05rem; }
.actions .btn-ghost { flex: 1; }

/* ---------- log list ---------- */

.log { padding: 0 var(--pad); display: flex; flex-direction: column; gap: 10px; }

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

.group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px 6px;
}
.group-head .name { font-weight: 650; }

.set-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
}
.set-row .idx {
  width: 22px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}
.set-row .body { flex: 1; min-width: 0; }
.set-row .desc { font-variant-numeric: tabular-nums; }
.set-row .meta { color: var(--muted); font-size: 0.78rem; }
.set-row .repeat { min-width: 44px; min-height: 44px; font-size: 1.2rem; color: var(--accent); }

.tag {
  display: inline-block;
  padding: 1px 7px;
  margin-right: 4px;
  border-radius: 99px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 0.72rem;
  color: var(--muted);
}
.tag.warmup { color: var(--accent); }
.tag.failure, .tag.technique_breakdown { color: var(--warn); }
.tag.pr_attempt { color: var(--ok); }

/* ---------- sheets ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10;
}

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  z-index: 11;
  animation: rise 0.16s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0.6; } }

.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px var(--pad) 6px;
}
.sheet-head > :first-child { flex: 1; } /* title takes the slack, close button stays right */
.sheet-head p { margin: 2px 0 0; }
.sheet-body { flex: 1; overflow-y: auto; padding: 6px var(--pad) 12px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px var(--pad) calc(12px + env(safe-area-inset-bottom)); }

.field {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  margin: 0 0 8px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
}
#picker-search { width: calc(100% - 2 * var(--pad)); margin: 0 var(--pad) 8px; }
textarea.field { min-height: 72px; padding: 10px 12px; resize: vertical; }

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

.picker-list { flex: 1; overflow-y: auto; padding: 0 var(--pad) calc(12px + env(safe-area-inset-bottom)); }
.picker-section { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; margin: 14px 0 6px; }
.picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 6px 12px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: left;
}
.picker-item .name { flex: 1; font-weight: 600; }
.picker-item .hint { color: var(--muted); font-size: 0.76rem; }

/* ---------- set entry ---------- */

.row { margin: 0 0 14px; }
.row > label, .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.stepper { display: flex; align-items: stretch; gap: 8px; }
.stepper button {
  width: 62px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 1.6rem;
  font-weight: 500;
}
.stepper input {
  flex: 1;
  min-width: 0; /* flex default is min-width:auto — the + button falls off-screen without this */
  width: 100%;
  min-height: 64px;
  text-align: center;
  font-size: 1.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 650;
}
.chip.num { min-width: 52px; justify-content: center; font-variant-numeric: tabular-nums; }

.rpe { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rpe .chip { padding: 0; min-height: 44px; }

details.more { margin-top: 4px; border-top: 1px solid var(--line); padding-top: 10px; }
details.more summary { min-height: var(--tap); display: flex; align-items: center; color: var(--muted); }

.errors {
  margin: 0 var(--pad);
  padding: 10px 12px;
  border-radius: 12px;
  background: #3a1a1c;
  border: 1px solid #5c2a2d;
  color: #ffc9cb;
  font-size: 0.88rem;
}
.errors ul { margin: 0; padding-left: 18px; }

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

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; text-align: right; }
.v.ok { color: var(--ok); }
.v.warn { color: var(--warn); }
.settings-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.note { color: var(--muted); font-size: 0.82rem; margin: 14px 0 0; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 11px 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  z-index: 30;
  font-size: 0.9rem;
  max-width: 90vw;
}

/* ---------- library / ladders ---------- */

.block-group { border-left: 3px solid var(--accent); }
.block-group.warmup, .block-group.cooldown { border-left-color: var(--muted); }
.block-group.emom, .block-group.amrap, .block-group.interval { border-left-color: var(--warn); }

.sub-head { padding: 8px 12px 2px; border-top: 1px solid var(--line); }

.set-row.link, .rung { width: 100%; text-align: left; background: none; }
.chev { color: var(--muted); font-size: 1.3rem; padding-left: 6px; }

.rung {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}
.rung-body { flex: 1; min-width: 0; }
.rung-head { display: flex; align-items: baseline; gap: 8px; }
.rung-head .name { font-weight: 620; }
.rung .tier {
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
}
.rung.blocked .rung-head .name { color: var(--muted); }
.rung.next { background: #16202f; }
.rung.next .rung-head .name { color: var(--text); }

.next-tag {
  display: inline-block;
  margin-top: 5px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
}

/* Typed reasons: each block type implies a different action (SCHEMA.md §3). */
.block-reason {
  display: flex;
  gap: 7px;
  margin-top: 5px;
  font-size: 0.78rem;
  color: var(--muted);
}
.block-reason .why {
  flex: none;
  padding: 0 6px;
  border-radius: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.block-reason.strength .why { color: var(--accent); }
.block-reason.mobility .why { color: var(--warn); }
.block-reason.apparatus .why { color: #c08adf; }
.block-reason.open { color: var(--ok); }
.block-reason .detail { min-width: 0; }

.cues { margin: 0 0 10px; padding-left: 18px; color: var(--muted); font-size: 0.88rem; }
.cues li { margin-bottom: 4px; }

.chip.static { pointer-events: none; }
.chip.static.on { color: var(--text); border-color: var(--accent); }
.chip.wide { width: 100%; justify-content: flex-start; text-transform: capitalize; }
.chip.tiny { min-height: 30px; padding: 0 9px; font-size: 0.76rem; }
.chips.inline { flex: none; }
.row.pad { padding: 0 2px; }
.picker-item.dim .name { color: var(--muted); }

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

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.tile-value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--muted); font-size: 0.82rem; }
.tile-sub { color: var(--muted); font-size: 0.72rem; margin-top: 2px; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  font-size: 0.86rem;
}
.bar-label { width: 96px; flex: none; color: var(--muted); text-transform: capitalize; }
.bar-track { flex: 1; height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar-value { width: 62px; flex: none; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.cols {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 130px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.col-value { font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-bar { flex: none; width: 100%; background: var(--accent); border-radius: 5px 5px 0 0; margin-top: auto; }
.col-label { font-size: 0.68rem; color: var(--muted); padding-top: 4px; }

.spark { width: 100%; height: 64px; display: block; padding: 8px 0; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark .line.b { stroke: var(--warn); }
.spark .dot { fill: var(--accent); }
.spark .dot.b { fill: var(--warn); }
.legend { display: flex; gap: 12px; padding: 0 12px 10px; font-size: 0.76rem; color: var(--muted); }
.key.cold::before, .key.warm::before {
  content: ''; display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-right: 5px;
}
.key.cold::before { background: var(--accent); }
.key.warm::before { background: var(--warn); }

select.field { appearance: none; }

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

.routine-card { border-left: 3px solid var(--ok); }
.routine-item { width: 100%; text-align: left; background: none; }
.routine-item .tickbox {
  width: 26px; height: 26px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 8px;
  color: var(--ok); font-size: 0.9rem;
}
.routine-item.done .tickbox { border-color: var(--ok); background: rgba(78, 201, 138, 0.12); }
.routine-item.done .desc { color: var(--muted); }

.routine-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.routine-edit-name { flex: 1; min-width: 0; font-size: 0.9rem; font-weight: 600; }
.routine-edit-nums { display: flex; gap: 6px; flex: none; }
.routine-edit-tools { display: flex; gap: 4px; flex: none; }
.routine-edit-tools .btn { min-width: 34px; padding: 0 6px; }
label.mini { display: flex; flex-direction: column; width: 52px; }
label.mini span { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; }
label.mini input {
  width: 100%; min-height: 38px; text-align: center;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  font: inherit; font-size: 0.9rem;
}

/* ---------- media ---------- */

.media-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.media-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 9px; flex: none; background: var(--panel-2); }

.media-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  margin: 6px 0 12px;
}
.media-hit {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  text-align: left;
}
.media-hit img {
  width: 100%;
  height: 82px;
  object-fit: cover;
  border-radius: 7px;
  background: var(--bg);
}
.media-hit .hit-title {
  font-size: 0.7rem;
  line-height: 1.25;
  max-height: 2.5em;
  overflow: hidden;
}
.media-hit .hit-license { font-size: 0.62rem; color: var(--muted); }

.media-figure { margin: 0 0 12px; }
.media-figure img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 12px;
  background: var(--panel-2);
}
.media-figure figcaption { color: var(--muted); font-size: 0.74rem; padding-top: 5px; }
.media-figure a { color: var(--accent); }

/* ---------- ladder map ---------- */

.view-toggle { display: flex; gap: 7px; }
.map-scroll { overflow-x: auto; padding: 4px 8px 10px; -webkit-overflow-scrolling: touch; }
.map { display: block; max-width: none; }

.map .edge { fill: none; stroke: var(--line); stroke-width: 2; }
.map .edge.met { stroke: var(--accent); stroke-opacity: 0.75; }
.map .edge.unmet { stroke-dasharray: 4 4; }

.mapnode rect { fill: var(--panel-2); stroke: var(--line); stroke-width: 1; }
.mapnode text { fill: var(--muted); font-size: 11px; font-weight: 600; }
.mapnode.unlocked rect { stroke: var(--ok); }
.mapnode.unlocked text { fill: var(--text); }
.mapnode.hard rect { stroke: #6b4b80; stroke-dasharray: 5 3; }
.mapnode.next rect { fill: #16202f; stroke: var(--accent); stroke-width: 2; }
.mapnode.current rect { fill: #17301f; stroke: var(--ok); stroke-width: 2; }
.mapnode.current text, .mapnode.next text { fill: var(--text); }
.mapnode text.gate { fill: var(--warn); font-size: 10px; }
.mapnode { cursor: pointer; }
.mapnode:focus { outline: none; }
.mapnode:focus rect { stroke: var(--accent); stroke-width: 2; }

.map-legend { flex-wrap: wrap; }
.map-legend.standalone { padding: 0 4px 2px; }
.key.open::before, .key.locked::before, .key.kit::before {
  content: ''; display: inline-block; width: 9px; height: 9px;
  border-radius: 3px; margin-right: 5px; border: 1px solid var(--line);
}
.key.open::before { border-color: var(--ok); }
.key.locked::before { border-color: var(--line); }
.key.kit::before { border-color: #6b4b80; }

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

/* Roomier on a desktop screen, but the phone layout is the real one. */
@media (min-width: 640px) {
  .log, .actions, .banner { max-width: 620px; margin-inline: auto; }
  .sheet { left: 50%; transform: translateX(-50%); width: 620px; border-radius: 18px 18px 0 0; }
}
