/* Palette, type, geometry — ported from villain and rotated to blue.
   Villain's red (#e5645a, HSL ~7° / 71% / 63%) is a warm coral, not a pure
   red; the blue below is the same character rotated to ~210° so the whole
   product still reads as a sibling of villain rather than a stock template
   dropped onto a new hue.

   --danger stays a genuine red so real errors don't disappear into the
   accent color. */
:root {
  color-scheme: dark;
  --bg:         #0b0c0e;
  --panel:      #141619;
  --panel-2:    #191c20;
  --line:       #24272b;
  --edge:       #4b5058;
  --ink:        #f2f1ee;
  --ink-dim:    #c9c8c3;
  --muted:      #93938e;
  --mark-1:     #6f6e6b;
  --blue:       #5a9de5;
  --blue-hover: #4a86c9;
  --blue-dim:   #3d6a9e;
  --blue-wash:  rgba(90,157,229,0.10);
  --pr:         #7bb7ff;
  --danger:     #e5484d;

  /* Gym tints — variations on --blue so the three read as siblings, not
     three different colors. Used for the heatmap dots and gym pills. */
  --imsb:       #5a9de5;
  --ccrb:       #6fb4d9;
  --ncrb:       #7fa7e8;

  --radius-pill: 999px;
  --radius:      10px;
  --radius-sm:   6px;
}

@font-face {
  font-family: "Space Grotesk";
  font-style: normal; font-weight: 300 700;
  font-display: swap;
  src: url("space-grotesk.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal; font-weight: 100 800;
  font-display: swap;
  src: url("jetbrains-mono.woff2") format("woff2");
}

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

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

body {
  font: 15px/1.5 "Space Grotesk", ui-sans-serif, system-ui, -apple-system,
        "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100svh;
}

.mono, .num {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

/* ----- App shell ------------------------------------------------------ */
/* Auth lives at the edge (Cloudflare Access), so this file no longer
   carries a login screen. If Access ever bounces an expired session the
   user just re-signs on Cloudflare's own page, then lands back here. */

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spin-sm { animation-duration: 2.4s; }
}

#app {
  max-width: 68rem;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 4rem;
}

header.app-header {
  display: flex; align-items: center; gap: 1rem;
  padding: .25rem 0 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.25rem;
}

.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-weight: 800; font-size: 1.15rem;
  letter-spacing: -.04em;
  color: var(--ink);
  text-decoration: none;
}
.brand .mark {
  width: 1.7rem; height: 1.7rem; border-radius: .45rem;
  background: var(--blue); color: var(--bg);
  padding: .22rem; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand .mark svg { width: 100%; height: 100%; display: block; }

nav.tabs {
  display: flex; gap: .25rem; margin-left: 1rem; flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
nav.tabs::-webkit-scrollbar { display: none; }

nav.tabs a {
  font: inherit; font-size: .88rem; color: var(--muted);
  text-decoration: none;
  padding: .45rem .8rem;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
nav.tabs a:hover { color: var(--ink); }
nav.tabs a.active {
  color: var(--ink);
  border-color: var(--edge);
  background: var(--panel);
}

.acct {
  display: flex; align-items: center; gap: .5rem;
  color: var(--muted); font-size: .82rem;
}
.acct .status { font-family: "JetBrains Mono", ui-monospace, monospace; }
.acct .status.on  { color: var(--blue); }
.acct .status.off { color: var(--muted); }
.acct .status.bad { color: var(--danger); }

.icon-btn {
  font: inherit; font-size: .82rem;
  height: 32px; padding: 0 .8rem;
  border: 1px solid var(--edge); background: transparent;
  color: var(--muted); border-radius: var(--radius-pill);
  cursor: pointer; white-space: nowrap;
}
.icon-btn:hover { color: var(--ink); border-color: var(--blue); }

/* ----- Common blocks -------------------------------------------------- */

section.view { display: none; }
section.view.active { display: block; }

.h {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 0 .75rem;
  gap: 1rem;
}
.h h2 {
  margin: 0; font-size: 1.05rem; font-weight: 600;
  letter-spacing: -.01em;
  color: var(--ink);
}
.h .meta {
  color: var(--muted); font-size: .82rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .grid.cols-2 { grid-template-columns: 1fr 1fr; }
}

.summary {
  color: var(--muted); font-size: .9rem;
  margin: 0 0 1rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.summary b { color: var(--ink); font-weight: 500; }
.summary .dot { color: var(--mark-1); margin: 0 .4rem; }

/* Charts */
.chart-title {
  color: var(--muted); font-size: .78rem;
  text-transform: uppercase; letter-spacing: .08em;
  margin: 0 0 .5rem;
}
.chart {
  width: 100%; height: auto;
  aspect-ratio: 2 / 1;   /* matches the 400×200 viewBox */
  display: block;
  overflow: visible;
}
.chart .axis   { stroke: var(--line); stroke-width: 1; }
.chart .grid   { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .label  { fill: var(--muted); font-size: 10px;
                 font-family: "JetBrains Mono", ui-monospace, monospace; }
.chart .line   { fill: none; stroke: var(--blue); stroke-width: 1.4;
                 stroke-linecap: round; stroke-linejoin: round; }
.chart .line.alt-1 { stroke: var(--ccrb); }
.chart .line.alt-2 { stroke: var(--ncrb); opacity: .85; }
.chart .point  { fill: var(--blue); }
.chart .bar    { fill: var(--blue); opacity: .75; }
.chart .bar:hover { opacity: 1; }
.chart .empty  { fill: var(--muted); font-size: 11px;
                 font-family: "JetBrains Mono", ui-monospace, monospace; }
.chart .cross  { stroke: var(--blue); stroke-width: 1;
                 stroke-dasharray: 2 3; opacity: .6; }

.chart-legend {
  display: flex; gap: 1rem; flex-wrap: wrap;
  margin-top: .5rem;
  font-size: .78rem; color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.chart-legend .sw {
  display: inline-block; width: 10px; height: 2px;
  vertical-align: middle; margin-right: .35rem;
  background: var(--blue);
}
.chart-legend .sw.alt-1 { background: var(--ccrb); }
.chart-legend .sw.alt-2 { background: var(--ncrb); opacity: .85; }

/* Heatmap grid */
.heatmap { display: grid; gap: 3px; }
.heatmap .cell {
  width: 100%; aspect-ratio: 1;
  background: var(--panel-2);
  border-radius: 2px;
}
.heatmap .cell[data-l="1"] { background: var(--blue-wash); }
.heatmap .cell[data-l="2"] { background: rgba(90,157,229,0.28); }
.heatmap .cell[data-l="3"] { background: rgba(90,157,229,0.55); }
.heatmap .cell[data-l="4"] { background: var(--blue); }

/* PR table */
table.prs {
  width: 100%; border-collapse: collapse;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .88rem;
}
table.prs th, table.prs td {
  text-align: left; padding: .55rem .5rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink-dim);
}
table.prs th {
  color: var(--muted); font-weight: 500;
  text-transform: uppercase; font-size: .7rem;
  letter-spacing: .08em;
}
table.prs tr:last-child td { border-bottom: 0; }
table.prs td.w { color: var(--ink); font-weight: 600; }
table.prs td.new { color: var(--pr); }
table.prs td.date { color: var(--muted); font-size: .78rem; }

/* ----- Log screen ----------------------------------------------------- */

.gym-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin-bottom: 1rem;
}
.gym-pill {
  font: inherit; font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .95rem; font-weight: 500;
  padding: .9rem .8rem;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink-dim); cursor: pointer;
  text-align: center;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.gym-pill:hover { color: var(--ink); border-color: var(--blue-dim); }
.gym-pill.active {
  border-color: var(--blue);
  background: var(--blue-wash);
  color: var(--ink);
}

.field { display: block; margin-bottom: .85rem; }
.field label {
  display: block; font-size: .74rem;
  color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: .35rem;
}
.input, .field input, .field select {
  width: 100%; font: inherit;
  padding: .7rem .9rem;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--ink);
}
.input:focus, .field input:focus, .field select:focus {
  outline: none; border-color: var(--blue);
}
.field input.num {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 1.15rem; font-weight: 500;
}

.two-col {
  display: grid; gap: .75rem;
  grid-template-columns: 1fr 1fr;
}

.quick-add {
  display: flex; gap: .4rem; flex-wrap: wrap;
  margin-top: .5rem;
}
.quick-add button {
  font: inherit; font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .82rem;
  padding: .35rem .7rem;
  border: 1px solid var(--edge);
  background: transparent;
  color: var(--ink-dim);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.quick-add button:hover {
  border-color: var(--blue); color: var(--blue);
}

.primary {
  font: inherit; font-weight: 600;
  padding: .85rem 1.4rem;
  border: 1px solid var(--blue);
  background: var(--blue); color: var(--bg);
  border-radius: var(--radius-pill);
  cursor: pointer; width: 100%;
  margin-top: .5rem;
}
.primary:hover { background: var(--blue-hover); border-color: var(--blue-hover); }
.primary:disabled { opacity: .5; cursor: default; }

/* Exercise autocomplete */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: 100%;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  max-height: 16rem;
  overflow-y: auto;
  z-index: 20;
  display: none;
}
.combo-list.open { display: block; }
.combo-item {
  padding: .55rem .8rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: .92rem;
}
.combo-item:last-child { border-bottom: 0; }
.combo-item:hover, .combo-item.hi { background: var(--panel-2); color: var(--ink); }
.combo-item .scope {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .68rem;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted);
}
.combo-item.add { color: var(--blue); }

/* Session preview */
.session-preview {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted); font-size: .88rem;
}
.session-preview:empty { display: none; }
.session-preview .sp-row {
  display: flex; justify-content: space-between;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  padding: .3rem 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink-dim);
}
.session-preview .sp-row:last-child { border-bottom: 0; }
.session-preview .sp-row .rm {
  cursor: pointer; color: var(--mark-1);
  border: 0; background: none; padding: 0 .35rem;
}
.session-preview .sp-row .rm:hover { color: var(--danger); }
.session-preview .sp-head {
  color: var(--muted); font-size: .74rem;
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: .35rem;
}

/* ----- History -------------------------------------------------------- */

.filter-row {
  display: flex; flex-wrap: wrap; gap: .35rem;
  margin-bottom: 1rem;
}
.chip {
  font: inherit; font-size: .78rem;
  padding: .35rem .75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--edge);
  background: transparent;
  color: var(--muted); cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.chip:hover { color: var(--ink); border-color: var(--ink-dim); }
.chip.on {
  background: var(--blue-wash);
  border-color: var(--blue);
  color: var(--ink);
}

.session {
  margin-bottom: 1.25rem;
}
.session .s-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: .35rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--line);
}
.session .s-date {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .82rem; color: var(--ink);
}
.session .s-meta {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .74rem; color: var(--muted);
}
.session .s-list {
  list-style: none; margin: 0; padding: 0;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .86rem;
}
.session .s-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 1rem;
  padding: .35rem 0;
  color: var(--ink-dim);
  border-bottom: 1px dotted var(--line);
}
.session .s-list li:last-child { border-bottom: 0; }
.session .s-list .ex { color: var(--ink); }
.session .s-list .load { color: var(--ink); }
.session .s-list .rm {
  color: var(--mark-1); cursor: pointer; background: none;
  border: 0; padding: 0 .35rem;
  font: inherit; font-family: inherit;
}
.session .s-list .rm:hover { color: var(--danger); }

.empty-state {
  color: var(--muted); text-align: center;
  padding: 3rem 1rem;
  font-size: .95rem;
}
.empty-state .hint { color: var(--mark-1); font-size: .82rem; margin-top: .5rem; }

/* History exercise picker */
.ex-picker { margin-bottom: 1.25rem; }
.ex-picker select {
  appearance: none; -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.5rem;
  cursor: pointer;
}
.ex-picker select:focus { outline: none; border-color: var(--blue); }

.sub-h {
  margin: 1.75rem 0 .75rem;
  font-size: .78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 500;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

/* ----- Exercises manager --------------------------------------------- */

.scope-block { margin-bottom: 1.5rem; }
.scope-block .sh {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: .55rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--line);
}
.scope-block .sh h3 {
  font: inherit; font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .82rem; margin: 0;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted);
}
.scope-block .sh .count { color: var(--mark-1); font-size: .78rem;
                          font-family: "JetBrains Mono", ui-monospace, monospace; }

.ex-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: .4rem;
}
.ex-list li {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .35rem .75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--panel);
  color: var(--ink-dim);
  font-size: .82rem;
}
.ex-list li .del {
  background: none; border: 0; cursor: pointer;
  color: var(--mark-1); font: inherit; padding: 0;
}
.ex-list li .del:hover { color: var(--danger); }

/* Exercises → Add flow. The toggle button collapses down into a card with
   a scope picker and name field. Keeps the manager visually calm when idle
   and lets the four scope blocks below be pure lists. */
#ex-add-wrap { margin-bottom: 1.5rem; }
.primary.compact {
  width: auto; padding: .55rem 1.1rem; font-size: .88rem;
  margin-top: 0;
}
.ex-add-card { margin-top: .75rem; }
.field-label {
  margin: 0 0 .5rem;
  font-size: .74rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}
.gym-row.four {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 1rem;
}
.row-btns {
  display: flex; gap: .5rem; margin-top: .35rem;
}
.row-btns .primary { flex: 1; margin-top: 0; }
.ghost {
  font: inherit; font-weight: 500;
  padding: .85rem 1.4rem;
  border: 1px solid var(--edge);
  background: transparent; color: var(--muted);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.ghost:hover { color: var(--ink); border-color: var(--ink-dim); }

@media (max-width: 500px) {
  .gym-row.four {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ----- Responsive tweaks --------------------------------------------- */

@media (max-width: 640px) {
  #app { padding: 1rem 1rem 6rem; }
  header.app-header {
    flex-wrap: wrap; gap: .5rem;
  }
  nav.tabs { order: 3; width: 100%; margin-left: 0; }
  .acct { order: 2; margin-left: auto; }
  .brand { order: 1; }
  .h { flex-direction: column; align-items: flex-start; gap: .25rem; }
  .two-col { grid-template-columns: 1fr; }
  .gym-pill { padding: 1rem .5rem; font-size: .88rem; }
}

/* ----- Toasts --------------------------------------------------------- */

.toast-wrap {
  position: fixed; left: 50%; bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 50;
  display: flex; flex-direction: column; gap: .5rem;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--edge);
  color: var(--ink);
  border-radius: var(--radius-pill);
  padding: .55rem 1rem;
  font-size: .84rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  opacity: 0; transform: translateY(6px);
  animation: pop .28s ease forwards;
}
.toast.pr {
  border-color: var(--pr);
  color: var(--pr);
  font-weight: 600;
}
.toast.bad { border-color: var(--danger); color: var(--danger); }
@keyframes pop {
  to { opacity: 1; transform: translateY(0); }
}
