/* Mobile first. Every rule here is the phone layout; the one media query at the
   bottom widens things for a desktop browser. Touch targets are 44px minimum,
   because this gets used with chalky hands between sets. */

:root {
  --bg: #12100e;
  --panel: #1b1815;
  --line: #2e2925;
  --ink: #ece6dd;
  --muted: #93887c;
  --accent: #c9743f;
  --good: #6f9e56;
  --danger: #a3453a;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f4ee;
    --panel: #fffdf9;
    --line: #e2dbcf;
    --ink: #221f1b;
    --muted: #6d6459;
    --accent: #b45f2b;
    --good: #4d7a37;
  }
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is `display: none`, which any class selector that
   sets display beats on specificity. Make hidden mean hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* 16px is the threshold below which iOS Safari zooms the page on focus, which
   then leaves the layout scrolled sideways. Never shrink an input's font. */
input, textarea, select { font-size: 16px; }

.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }
.hint { font-size: 0.85rem; margin: 0.4rem 0 0; }

button {
  min-height: 44px;
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.big { width: 100%; min-height: 52px; font-size: 1.05rem; font-weight: 600; }
button.ghost { background: transparent; }
button.small { min-height: 36px; padding: 0 0.6rem; font-size: 0.85rem; }
button:disabled { opacity: 0.5; }

input, textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
textarea { min-height: 60px; resize: vertical; }

/* ------------------------------------------------------------------ login */

.login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 1.5rem;
}

.login-box {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(340px, 100%);
  padding: 1.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.login-box h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }

/* -------------------------------------------------------------- app shell */

.app {
  /* Bottom padding clears the fixed tab bar plus the iOS home indicator. */
  padding: 0.75rem 0.75rem calc(84px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.tab { display: flex; flex-direction: column; gap: 0.75rem; }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  padding: 0.4rem 0.5rem calc(0.4rem + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.tabs button { border: none; background: transparent; color: var(--muted); }
.tabs button.active { color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- day bar */

.daybar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 0.5rem;
}
.daybar button { padding: 0; font-size: 1.4rem; line-height: 1; }
.daybar-mid { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.daybar-mid input { text-align: center; }
.daybar-mid span { font-size: 0.8rem; }

/* ------------------------------------------------------------ entry form */

.entry {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Name shortcuts. One scrolling row rather than a wrapping block, so the form
   below never jumps down the screen as the list of exercises grows. */
.chips {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
  scrollbar-width: none;
  /* Let a sideways swipe on the chips scroll them without dragging the page. */
  overscroll-behavior-x: contain;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 0.75rem;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 0.9rem;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.new { border-style: dashed; color: var(--muted); }

/* The repeat shortcut. Outlined rather than solid so it never competes with
   Add, which is the button that commits whatever is in the fields. */
.repeat {
  width: 100%;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.fields { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 0.5rem; }
.field { display: flex; flex-direction: column; gap: 0.2rem; }
.field > span { font-size: 0.75rem; color: var(--muted); }

/* --------------------------------------------------------------- session */

.session { display: flex; flex-direction: column; gap: 0.6rem; }

.group {
  padding: 0.6rem 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.group-head strong { font-size: 1rem; }

.set-row {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-top: 1px solid var(--line);
}
.set-row .idx { color: var(--muted); font-size: 0.8rem; }
.set-row .val { font-variant-numeric: tabular-nums; }
.set-row .pr { color: var(--good); font-size: 0.8rem; }
.set-row button { min-height: 34px; padding: 0 0.5rem; font-size: 0.85rem; }

.empty { padding: 1.25rem; text-align: center; color: var(--muted); }

.note { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }

/* ------------------------------------------------------------- dashboard */

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.tile {
  padding: 0.6rem 0.5rem;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.tile b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tile span { font-size: 0.7rem; color: var(--muted); }

.card {
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.picker { display: grid; grid-template-columns: 1.6fr 1fr; gap: 0.5rem; margin: 0.5rem 0; }

/* The SVG is written at a fixed viewBox and scaled by width; height:auto keeps
   the aspect ratio so the stroke never stretches. */
.chart svg { display: block; width: 100%; height: auto; margin-top: 0.5rem; }
.chart .axis { fill: var(--muted); font-size: 9px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: var(--accent); opacity: 0.12; }
.chart .dot { fill: var(--accent); }
.chart .grid { stroke: var(--line); stroke-width: 1; }

.summary { font-size: 0.85rem; margin-top: 0.5rem; }

/* --------------------------------------------------------------- history */

.history { display: flex; flex-direction: column; gap: 0.5rem; }
.hist-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  padding: 0.6rem 0.75rem;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.hist-row b { display: block; }
.hist-row span { font-size: 0.8rem; color: var(--muted); }
.hist-row .num { font-variant-numeric: tabular-nums; text-align: right; }

/* --------------------------------------------------------------- dialog */

dialog {
  width: min(360px, calc(100vw - 2rem));
  padding: 1.25rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
dialog form { display: flex; flex-direction: column; gap: 0.75rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

/* ------------------------------------------------------------- wider than
   a phone: the entry form gets one line and the tab bar stops being fixed. */

@media (min-width: 640px) {
  .fields { grid-template-columns: 1fr 1fr 1fr; }
  .tabs { position: sticky; border-radius: var(--radius); }
  .app { padding-bottom: 1rem; }
}
