/* ============ IRON LOG — bumper-plate palette on dark iron ============ */
:root {
  --bg: #101318;
  --surface: #171c23;
  --surface-2: #1e242d;
  --line: #2a323d;
  --ink: #f2efe8;        /* chalk */
  --ink-2: #a8b0ba;
  --ink-3: #6b7480;
  --red: #e8574a;        /* 25 kg plate */
  --blue: #5292e0;       /* 20 kg plate */
  --yellow: #e4b63c;     /* 15 kg plate */
  --green: #57b26e;      /* 10 kg plate */
  --fail: #e8574a;
  --radius: 14px;
  --display: "Avenir Next Condensed", "HelveticaNeue-CondensedBold", "Arial Narrow", system-ui, sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font-family: inherit; }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }

.view { display: none; padding: 16px 16px 24px; max-width: 640px; margin: 0 auto; }
.view.active { display: block; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: calc(6px + env(safe-area-inset-top)) 2px 14px;
}
.brand {
  font-family: var(--display);
  font-weight: 700; font-size: 22px; letter-spacing: 3px;
  display: flex; align-items: center; gap: 8px;
}
.plate { width: 10px; height: 22px; border-radius: 3px; display: inline-block; }
.plate-red { background: var(--red); }
.plate-blue { background: var(--blue); height: 18px; }
.plate-yellow { background: var(--yellow); height: 14px; margin-right: 2px; }
.topbar-date { color: var(--ink-3); font-size: 13px; }

/* ---- exercise picker button ---- */
.exercise-btn {
  width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.exercise-btn:active { background: var(--surface-2); }
.exercise-btn-label { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--ink-3); }
.exercise-btn-name {
  font-family: var(--display); font-weight: 600; font-size: 26px; letter-spacing: .5px;
  color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.exercise-btn-name.placeholder { color: var(--ink-3); }

/* ---- steppers ---- */
.stepper-row { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 14px; }
@media (min-width: 480px) { .stepper-row { grid-template-columns: 1fr 1fr; } }
.stepper {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 10px 10px;
  min-width: 0;
}
.stepper-label {
  font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--ink-3);
  text-align: center; margin-bottom: 6px;
}
.stepper-label .unit { color: var(--ink-3); text-transform: none; letter-spacing: 0; }
.stepper-controls { display: flex; align-items: center; gap: 4px; }
.step-btn {
  flex: 0 0 52px; height: 56px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 18px; font-weight: 700; color: var(--ink-2);
}
.step-btn:active { background: var(--line); }
.stepper-controls input {
  flex: 1; min-width: 0; height: 56px; text-align: center;
  background: transparent; border: none; color: var(--ink);
  font-family: var(--display); font-size: 38px; font-weight: 700;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper-controls input::-webkit-outer-spin-button,
.stepper-controls input::-webkit-inner-spin-button { -webkit-appearance: none; }
.stepper-fine { display: flex; gap: 6px; margin-top: 8px; }
.fine-btn {
  flex: 1; height: 34px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: transparent; border: 1px solid var(--line); color: var(--ink-2);
}
.fine-btn:active { background: var(--surface-2); }

/* ---- failed toggle ---- */
.failed-toggle {
  width: 100%; height: 52px; border-radius: var(--radius); margin-bottom: 14px;
  border: 1px dashed var(--line); color: var(--ink-2);
  font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: all .15s ease;
}
.failed-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink-3); }
.failed-toggle[aria-pressed="true"] {
  border: 1px solid var(--fail); color: var(--fail); background: rgba(232, 87, 74, .1);
}
.failed-toggle[aria-pressed="true"] .failed-dot { background: var(--fail); border-color: var(--fail); }

/* ---- log button ---- */
.log-btn {
  width: 100%; height: 68px; border-radius: var(--radius);
  background: var(--yellow); color: #17130a;
  font-family: var(--display); font-size: 26px; font-weight: 700; letter-spacing: 4px;
  transition: transform .08s ease, opacity .15s;
  margin-bottom: 26px;
}
.log-btn:active { transform: scale(.98); }
.log-btn:disabled { opacity: .35; cursor: default; }
.log-btn.logged { background: var(--green); color: #0d1810; }

/* ---- session list ---- */
.session-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.session-head h2, .day-head h3 {
  font-family: var(--display); font-size: 17px; font-weight: 600;
  letter-spacing: 2px; text-transform: uppercase; color: var(--ink-2);
}
.session-count { color: var(--ink-3); font-size: 13px; }
.set-list { list-style: none; }
.set-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px;
}
.set-row .grp { width: 4px; align-self: stretch; border-radius: 2px; }
.set-row .set-main { flex: 1; min-width: 0; }
.set-row .set-ex { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set-row .set-meta { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.set-row .set-nums { font-family: var(--display); font-size: 22px; font-weight: 700; white-space: nowrap; }
.set-row .set-nums small { font-size: 13px; color: var(--ink-3); font-family: var(--body); font-weight: 400; }
.set-row .fail-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 1px; color: var(--fail);
  border: 1px solid var(--fail); border-radius: 4px; padding: 2px 5px;
}
.set-row .del-btn { color: var(--ink-3); font-size: 20px; padding: 6px 4px; line-height: 1; }
.set-row.repeatable { cursor: pointer; }
.empty-note { color: var(--ink-3); text-align: center; padding: 28px 12px; font-size: 14px; display: none; }
.empty-note.show { display: block; }

/* ---- history ---- */
.day-block { margin-bottom: 22px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.day-head .day-vol { color: var(--ink-3); font-size: 12px; }
.ghost-btn {
  display: block; margin: 8px auto 20px; padding: 10px 22px; border-radius: 10px;
  border: 1px solid var(--line); color: var(--ink-2); font-size: 14px;
}
.backup-row { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.backup-row .ghost-btn { margin: 0; cursor: pointer; }
.backup-note { color: var(--ink-3); font-size: 12px; text-align: center; margin: 10px 24px 0; }

/* ---- exercise sheet ---- */
.sheet[hidden], .sheet-backdrop[hidden] { display: none; }
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(6, 8, 11, .7); z-index: 40;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--surface); border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--line);
  max-height: 78dvh; display: flex; flex-direction: column;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  animation: sheet-up .22s ease;
}
@keyframes sheet-up { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet-search {
  width: 100%; height: 48px; border-radius: 10px; padding: 0 14px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  font-size: 16px; margin-bottom: 10px;
}
.exercise-list { list-style: none; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.exercise-item {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 13px 6px; border-bottom: 1px solid var(--line); font-size: 16px;
}
.exercise-item:active { background: var(--surface-2); }
.exercise-item .grp-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.exercise-item .ex-name { flex: 1; font-weight: 500; }
.exercise-item .ex-sub { color: var(--ink-3); font-size: 12px; }
.exercise-item.add-new { color: var(--yellow); font-weight: 600; }

/* ---- tab bar ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(16, 19, 24, .92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; padding: 10px 0 8px; font-size: 11px; font-weight: 600; letter-spacing: .5px;
  color: var(--ink-3); display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab svg { width: 24px; height: 24px; fill: currentColor; }
.tab.active { color: var(--yellow); }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 18px; font-size: 14px; color: var(--ink);
  animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ============ stats ============ */
.tile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 12px; overflow: hidden; position: relative;
}
.tile .tile-accent { position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.tile .tile-num {
  font-family: var(--display); font-size: 34px; font-weight: 700; line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.tile .tile-num small { font-size: 16px; color: var(--ink-2); }
.tile .tile-label { color: var(--ink-3); font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; margin-top: 4px; }

.chart-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 14px 12px; margin-bottom: 16px;
}
.chart-card h3 {
  font-family: var(--display); font-size: 16px; font-weight: 600;
  letter-spacing: 2px; text-transform: uppercase; color: var(--ink-2); margin-bottom: 2px;
}
.chart-card .chart-sub { color: var(--ink-3); font-size: 12px; margin-bottom: 12px; }
.chart-card svg { display: block; width: 100%; height: auto; }
.chart-card .svg-wrap { position: relative; }

.chart-tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--ink); white-space: nowrap;
  transform: translate(-50%, -110%); display: none;
}
.chart-tip b { font-family: var(--display); font-size: 15px; }
.chart-tip .tip-sub { color: var(--ink-3); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; }
.legend .lg { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }

/* exercise select pills for progression chart */
.pill-row { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.pill-row::-webkit-scrollbar { display: none; }
.pill {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap;
}
.pill.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* calendar heatmap */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.heatmap .hm-cell { width: 100%; aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); }

/* PR table */
.pr-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.pr-table td { padding: 9px 4px; border-bottom: 1px solid var(--line); }
.pr-table tr:last-child td { border-bottom: none; }
.pr-table .pr-ex { font-weight: 600; }
.pr-table .pr-sub { color: var(--ink-3); font-size: 12px; }
.pr-table .pr-val { text-align: right; font-family: var(--display); font-size: 20px; font-weight: 700; white-space: nowrap; }
.pr-table .pr-val small { font-family: var(--body); font-size: 12px; color: var(--ink-3); font-weight: 400; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 640px) {
  .tile-grid { grid-template-columns: repeat(4, 1fr); }
}
