@import url("https://fonts.googleapis.com/css2?family=Courier+Prime:wght@400;700&family=Work+Sans:ital,wght@0,400;0,500;0,600;0,700;0,800;1,400;1,600&display=swap");

:root {
  color-scheme: light;
  --paper: #f7f2e8;
  --paper-raised: #fffdf8;
  --ink: #1a1a16;
  --muted-ink: #5b584f;
  --rule: #b9b1a2;
  --rule-strong: #756f63;
  --oxblood: #8c201b;
  --oxblood-dark: #65130f;
  --brass: #7b5714;
  --brass-wash: #f4e7c5;
  --evergreen: #1f5b45;
  --evergreen-wash: #dcebe2;
  --focus: #005fcc;
  --error: #8c201b;
  --font-size-small: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lead: 1.125rem;
  --font-size-heading: 2rem;
  --sans: "Work Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Courier Prime", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  min-width: 20rem;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 400 var(--font-size-base)/1.5 var(--sans);
  text-rendering: optimizeLegibility;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  background-image: linear-gradient(to bottom, rgba(26, 26, 22, 0.035) 1px, transparent 1px);
  background-size: 100% 2rem;
  content: "";
  pointer-events: none;
}

a {
  color: var(--oxblood-dark);
  font-weight: 600;
  text-decoration-thickness: 0.1em;
  text-underline-offset: 0.16em;
}

a:hover { color: var(--oxblood); }

a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 72rem);
  margin: 0 auto;
  padding: 0 1rem 2.5rem;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.75rem;
  border-bottom: 3px solid var(--ink);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  place-items: center;
  border: 2px solid var(--ink);
  color: var(--paper-raised);
  background: var(--oxblood);
  font: 700 0.78rem/1 var(--mono);
  letter-spacing: 0.08em;
}

.brand-copy { display: grid; line-height: 1.1; }
.brand-copy strong { font-size: 1.125rem; font-weight: 800; letter-spacing: -0.025em; }
.brand-copy small,
.eyebrow,
.ledger-meta {
  font: 700 var(--font-size-small)/1.35 var(--mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.brand-copy small, .eyebrow { color: var(--oxblood-dark); }

.primary-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.2rem;
}

.primary-nav > a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.55rem 0.7rem;
  color: var(--ink);
  font-size: 0.88rem;
  text-decoration: none;
}

.primary-nav > a:hover {
  background: #ece4d5;
  color: var(--oxblood-dark);
}

.page-home .primary-nav > a[href="/"],
.page-routine .primary-nav > a[href="/routine"],
.page-workout .primary-nav > a[href="/workout"],
.page-history .primary-nav > a[href="/history"] {
  color: var(--paper-raised);
  background: var(--oxblood);
}

.primary-nav > a[aria-current] {
  font-weight: 800;
}

/* The compact-desktop / mobile hamburger menu. It is a native details/summary
   disclosure carrying the same primary links and a CSRF sign-out form. It is
   hidden on wide desktop, where the inline .primary-nav and .account sign-out
   are shown instead. A responsive rule below reveals it once those crowd. */
.menu { position: relative; display: none; }

.menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--rule-strong);
  border-radius: 0.3rem;
  background: var(--paper);
  cursor: pointer;
  list-style: none;
}

/* Suppress the native disclosure triangle across engines. */
.menu-toggle::-webkit-details-marker { display: none; }
.menu-toggle::marker { content: ""; }

.menu-toggle:hover { background: #ece4d5; }

.menu-toggle-bars,
.menu-toggle-bars::before,
.menu-toggle-bars::after {
  display: block;
  width: 1.25rem;
  height: 2px;
  background: var(--ink);
}

.menu-toggle-bars { position: relative; }
.menu-toggle-bars::before,
.menu-toggle-bars::after {
  position: absolute;
  left: 0;
  content: "";
}
.menu-toggle-bars::before { top: -0.4rem; }
.menu-toggle-bars::after { top: 0.4rem; }

.menu-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.4rem);
  right: 0;
  display: flex;
  flex-direction: column;
  min-width: 12rem;
  border: 1px solid var(--rule-strong);
  border-top: 3px solid var(--oxblood);
  background: var(--paper-raised);
  border-radius: 0.35rem;
  box-shadow: 0 0.4rem 1.5rem rgba(26, 26, 22, 0.15);
  padding: 0.4rem;
}

.menu-panel > a {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.55rem 0.7rem;
  color: var(--ink);
  border-radius: 0.25rem;
  font-size: 0.95rem;
  text-decoration: none;
}

.menu-panel > a:hover {
  background: #ece4d5;
  color: var(--oxblood-dark);
}

.menu-panel .logout { margin: 0.3rem 0 0; }
.menu-panel .logout input[type="submit"] { margin-top: 0; }

.page-home .menu-panel > a[href="/"],
.page-routine .menu-panel > a[href="/routine"],
.page-workout .menu-panel > a[href="/workout"],
.page-history .menu-panel > a[href="/history"] {
  color: var(--paper-raised);
  background: var(--oxblood);
}

.page-home .bottom-nav > a[href="/"],
.page-routine .bottom-nav > a[href="/routine"],
.page-workout .bottom-nav > a[href="/workout"],
.page-history .bottom-nav > a[href="/history"] {
  color: var(--paper-raised);
  background: var(--oxblood);
}

main { padding: 1.5rem 0; }

.bottom-nav { display: none; }

.page-surface {
  min-height: 26rem;
  border: 1px solid var(--rule-strong);
  border-top: 6px solid var(--oxblood);
  background: var(--paper-raised);
  border-radius: 0.45rem;
  box-shadow: 0 0.4rem 1.5rem rgba(26, 26, 22, 0.09);
  padding: clamp(1.25rem, 3vw, 2rem);
}

h1,
h2 {
  max-width: 38rem;
  margin: 0 0 0.45rem;
  color: var(--ink);
  font-size: clamp(1.75rem, 4vw, var(--font-size-heading));
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

h3 { margin: 0; color: var(--ink); font-size: 1.5rem; line-height: 1.2; }

p { max-width: 46rem; margin: 0.65rem 0; color: var(--muted-ink); }
h2 + p { font-size: var(--font-size-lead); }

.ledger-meta {
  color: var(--muted-ink);
  font-variant-numeric: tabular-nums;
}

.doctrine-note {
  max-width: 46rem;
  margin: 1.25rem 0;
  border-left: 4px solid var(--brass);
  color: #47350f;
  background: var(--brass-wash);
  font-size: 0.95rem;
  padding: 0.85rem 1rem;
}

fieldset {
  margin: 1rem 0 0;
  padding: 0.875rem;
  border: 1px solid var(--rule);
  border-top: 3px solid var(--ink);
  background: var(--paper);
  border-radius: 0.3rem;
}

legend {
  max-width: 100%;
  padding: 0 0.35rem;
  color: var(--ink);
  font: 700 var(--font-size-small)/1.35 var(--mono);
  letter-spacing: 0.025em;
}

.field { margin-top: 1rem; }
label {
  display: block;
  margin: 0 0 0.35rem;
  color: var(--ink);
  font-size: var(--font-size-small);
  font-weight: 700;
}

input, select {
  width: 100%;
  min-height: 3rem;
  border: 1px solid var(--rule-strong);
  border-radius: 0.25rem;
  color: var(--ink);
  background: var(--paper-raised);
  font: 500 1rem/1.3 var(--sans);
  padding: 0.65rem 0.75rem;
}

input:invalid { border-color: var(--error); }
input[type="number"] { font-family: var(--mono); font-variant-numeric: tabular-nums; }

input[type="submit"] {
  width: 100%;
  min-height: 3rem;
  margin-top: 1rem;
  border: 2px solid var(--oxblood-dark);
  border-radius: 0.3rem;
  color: var(--paper-raised);
  background: var(--oxblood);
  cursor: pointer;
  font: 700 var(--font-size-small)/1 var(--sans);
  letter-spacing: 0.055em;
  text-transform: uppercase;
  transition: background-color 150ms ease, transform 150ms ease;
}

input[type="submit"]:hover {
  background: var(--oxblood-dark);
  transform: translateY(-2px);
}
input[type="submit"]:disabled {
  border-color: var(--rule-strong);
  color: var(--muted-ink);
  background: #ded8cc;
  cursor: not-allowed;
}

/* A secondary submit: a lower-emphasis action next to the primary one. It reads
   as a receding, outlined control so the primary submit stays the obvious
   choice. Used for "Cancel logging" beside "Finish workout". */
input[type="submit"].secondary {
  color: var(--oxblood-dark);
  background: transparent;
  border-color: var(--rule-strong);
}
input[type="submit"].secondary:hover {
  color: var(--paper-raised);
  background: var(--rule-strong);
}

/* Keeps the finish and cancel controls together as equal-width actions. */
.button-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}
.button-group form { margin: 0; }
.button-group input[type="submit"] { width: 100%; }

.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; }

/* The exercise button group. Server-rendered links, one per prescription slot,
   carrying the slot in a query parameter. The active button reads as pressed; a
   recorded slot is marked with a check. Buttons stack vertically and fill the
   width, so a narrow screen never needs horizontal scrolling. */
.exercise-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 1.25rem 0 0;
}

.exercise-button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--rule-strong);
  border-radius: 0.3rem;
  color: var(--ink);
  background: var(--paper);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
}

.exercise-button:hover {
  color: var(--oxblood-dark);
  background: #ece4d5;
}

.exercise-button.is-active {
  color: var(--paper-raised);
  background: var(--oxblood);
  border-color: var(--oxblood-dark);
}

.exercise-button-index {
  display: grid;
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font: 700 0.72rem/1 var(--mono);
  font-variant-numeric: tabular-nums;
}

.exercise-button.is-done .exercise-button-index {
  border-color: var(--evergreen);
  color: var(--paper-raised);
  background: var(--evergreen);
}

.exercise-button.is-active.is-done .exercise-button-index {
  border-color: var(--paper-raised);
  color: var(--oxblood);
  background: var(--paper-raised);
}

.slot-panel { margin-top: 1.25rem; }

.recorded-slot { margin: 1rem 0; }
.recorded-slot .done { margin-bottom: 0.35rem; }

.warn {
  max-width: 47rem;
  margin: 1rem 0;
  border: 1px solid var(--brass);
  border-left: 5px solid var(--brass);
  color: #47350f;
  background: var(--brass-wash);
  padding: 0.9rem 1rem;
}

.done {
  color: var(--evergreen);
  font: 700 0.85rem/1.4 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

ul {
  margin: 1rem 0;
  padding-left: 1.5rem;
  list-style: disc;
}
li {
  margin: 0.4rem 0;
  padding: 0;
  color: var(--ink);
}
li::marker { color: #000; }
li ul {
  margin: 0.55rem 0 0;
  list-style: disc;
}
li li { color: var(--muted-ink); font-size: 0.92rem; }

/* Compact desktop: from just above the mobile breakpoint up to 60rem (960px).
   Four inline text links plus the brand and a sign-out button start to crowd
   and wrap here, so the inline .primary-nav and header sign-out give way to the
   hamburger .menu. The bottom nav stays a mobile-only affordance. 60rem is the
   chosen compact-desktop breakpoint: comfortably wider than the 42rem mobile
   breakpoint, and about where the inline row runs out of room. */
@media (min-width: 42.0625rem) and (max-width: 60rem) {
  .primary-nav { display: none; }
  .account { display: none; }
  .menu { display: block; }
}

@media (max-width: 42rem) {
  .app-shell {
    padding: 0 0.75rem calc(6.75rem + env(safe-area-inset-bottom));
  }

  .masthead {
    min-height: 4.5rem;
    padding: 0.9rem 0 0.7rem;
  }

  .primary-nav { display: none; }

  /* The inline header sign-out is hidden with the primary nav; the hamburger
     .menu is retained so sign-out stays reachable. The bottom nav carries the
     three main destinations but has no sign-out. */
  .account { display: none; }
  .menu { display: block; }

  .bottom-nav {
    position: fixed;
    z-index: 20;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    border-top: 2px solid var(--ink);
    background: var(--ink);
    box-shadow: 0 -0.35rem 1.2rem rgba(26, 26, 22, 0.15);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bottom-nav > a {
    display: grid;
    min-height: 3.5rem;
    place-items: center;
    color: var(--ink);
    background: var(--paper-raised);
    font: 700 0.76rem/1.1 var(--sans);
    letter-spacing: 0.025em;
    text-align: center;
    text-decoration: none;
  }

  .bottom-nav > a:hover {
    color: var(--oxblood-dark);
    background: #ece4d5;
  }

  .page-surface { min-height: calc(100vh - 9rem); padding: 1.25rem; }
}

@media (max-width: 26rem) {
  .row,
  .button-group { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
