/* "Lab Arcade" palette: lab-navy base, jetpack orange + coin yellow accents */
:root {
  --bg: #0e1422;
  --panel: #151d2f;
  --line: #243049;
  --fg: #eef1f6;      /* primary text */
  --dim: #7f8aa3;     /* secondary text */
  --accent: #ff8a3d;  /* section headers, primary action */
  --yellow: #ffd447;  /* selections, sets×reps */
  --teal: #4fd1c5;    /* cardio */
  --red: #ff6b6b;
  --font: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.term {
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 16px calc(40px + env(safe-area-inset-bottom));
}

.dim { color: var(--dim); }
.teal { color: var(--teal); }

/* --- top bar */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 12px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 16px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.prompt { font-weight: 700; white-space: nowrap; }

@media (max-width: 420px) {
  .host { display: none; }
  .part { font-size: 13px; padding: 8px 4px; }
}

.buddy {
  width: 64px;
  height: 64px;
  flex: none;
  image-rendering: pixelated;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1.1em;
  margin-left: 4px;
  vertical-align: text-bottom;
  background: var(--fg);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
}

nav { display: flex; gap: 4px; }
nav form { margin: 0; }

.tab {
  padding: 6px 8px;
  color: var(--dim);
  border-radius: 4px;
}
.tab.active { color: var(--bg); background: var(--fg); }

/* --- selection */

.comment { color: var(--dim); margin: 0 0 10px; }

.parts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.part {
  min-height: 48px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--dim);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.part .box { color: var(--dim); }

.part[aria-pressed="true"] {
  border-color: var(--yellow);
  color: var(--fg);
  font-weight: 700;
}
.part[aria-pressed="true"] .box { color: var(--yellow); }

.run {
  display: block;
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
  text-align: left;
  padding: 0 14px;
}
.run:disabled { border-color: var(--line); color: var(--dim); cursor: default; }
.run:not(:disabled):active { background: var(--accent); color: var(--bg); }

.status { margin: 10px 0 0; color: var(--dim); min-height: 1.5em; }
.status .meter { color: var(--teal); letter-spacing: 1px; }
.error { color: var(--red); }

/* --- generated plan */

#result { margin-top: 20px; }

.cmd { margin: 0; color: var(--dim); overflow-wrap: anywhere; }
.cmd b { color: var(--fg); font-weight: 400; }
.summary { margin: 2px 0 12px; color: var(--dim); }

.plan {
  width: 100%;
  border-collapse: collapse;
}

.plan th {
  text-align: left;
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  padding: 6px 6px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.plan td {
  padding: 10px 6px;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.plan th:first-child, .plan td:first-child { padding-left: 0; }
.plan th:last-child, .plan td:last-child { padding-right: 0; }

.plan tr.group td {
  padding-top: 18px;
  padding-bottom: 6px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  border-bottom: 1px dashed var(--line);
}
.plan tr.group.cardio td { color: var(--teal); }

.plan tr.item { cursor: pointer; }
.plan tr.item:active { background: var(--panel); }

.name { font-weight: 600; }
.meta { color: var(--dim); font-size: 13px; }
.cardio-row .name { color: var(--teal); }

.c-num { color: var(--dim); width: 2ch; }
.c-part { width: 6.5rem; }
.c-sets, .c-reps, .c-sxr, .c-rest { white-space: nowrap; }
.c-sxr, .c-sets { font-weight: 700; color: var(--yellow); }
.c-act { width: 40px; text-align: right; }

.swap {
  width: 36px;
  height: 36px;
  margin: -6px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
}
.swap:active { color: var(--accent); border-color: var(--accent); }
.swap[aria-busy="true"] { opacity: 0.5; }

tr.done td { opacity: 0.4; }
tr.done .name { text-decoration: line-through; }
tr.done .c-num::after { content: " ✓"; }

.hint { color: var(--dim); font-size: 13px; margin: 12px 0 0; }

.row-actions { display: flex; gap: 16px; margin-top: 16px; }
.link { color: var(--dim); text-decoration: underline; text-underline-offset: 3px; padding: 6px 0; }
.link.danger { color: var(--red); }

/* Phones: fold sets + reps into one "4×6–8" column, drop # and the part column
   (the group header already names the body part; the target moves into the meta line). */
.c-num, .c-sets, .c-reps, .c-part { display: none; }

@media (min-width: 640px) {
  body { font-size: 16px; }
  .parts { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .c-num, .c-sets, .c-reps, .c-part { display: table-cell; }
  .c-sxr, .m-target { display: none; }
  .c-part { width: 9rem; }
}

/* --- history */

.session { margin-bottom: 24px; }
.session-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: var(--accent);
  border-bottom: 1px dashed var(--line);
  padding-bottom: 4px;
  margin-bottom: 4px;
}
.session-head .parts-list { color: var(--dim); }
.session ol { list-style: none; margin: 0; padding: 0; }
.session li { display: flex; gap: 12px; padding: 3px 0; }
.session li .sxr { color: var(--dim); min-width: 9ch; white-space: nowrap; }
.session li.cardio .n { color: var(--teal); }

/* --- login */

.login { max-width: 420px; margin: 18vh auto 0; }
.login label { display: block; margin: 16px 0 8px; }
.login input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  caret-color: var(--accent);
}
.login .run { margin-top: 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
