/* ==========================================================================
   Peptide Progress Tracker — design system derived from the book cover
   blue #007BAF · yellow #FFF000 · black · white
   Mobile-first. One theme in light, one in dark, one for paper.
   ========================================================================== */

:root {
  --blue:      #007BAF;
  --blue-deep: #005C84;
  --blue-ink:  #00405C;
  --yellow:    #FFF000;
  --ink:       #14171C;
  --ink-soft:  #4A5560;
  --ink-faint: #7A8794;
  --paper:     #FFFFFF;
  --wash:      #F2F5F8;
  --line:      #DCE3EA;
  --line-firm: #B9C4CE;
  --good:      #1B7F4B;
  --warn:      #A85B00;
  --alert:     #B3261E;
  --good-bg:   #E7F5EC;
  --warn-bg:   #FDF1E0;
  --alert-bg:  #FBEAE8;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;

  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(0,32,48,.08), 0 6px 20px rgba(0,32,48,.06);
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue:      #2FA6DC;
    --blue-deep: #1B7FAD;
    --blue-ink:  #BEE4F5;
    --ink:       #E8EDF2;
    --ink-soft:  #A9B6C2;
    --ink-faint: #7E8C99;
    --paper:     #151A20;
    --wash:      #1D242C;
    --line:      #2C353F;
    --line-firm: #3E4A57;
    --good:      #63D398;
    --warn:      #E9B166;
    --alert:     #F0847C;
    --good-bg:   #163023;
    --warn-bg:   #33261A;
    --alert-bg:  #33191A;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* the top bar and the day/week bar are both sticky: keep anything scrolled
     into view (focus jumps, anchors) from landing underneath them */
  scroll-padding-top: 124px;
}

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--wash);
  overscroll-behavior-y: none;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4 { margin: 0; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }

a { color: var(--blue-deep); }

button { font: inherit; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 99;
  background: var(--yellow); color: #000; padding: 10px 14px; font-weight: 700;
}
.skip:focus { left: 8px; top: 8px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.12);
}
.topbar__back {
  flex: 0 0 auto;
  width: 36px; height: 36px; margin-left: -6px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.14); border: 0; border-radius: 50%;
  color: #fff; cursor: pointer;
}
.topbar__back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.topbar__id { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; }
.topbar__kicker {
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: rgba(255,255,255,.78);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__title { font-weight: 800; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saveflag {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--yellow); opacity: 0; transition: opacity .25s ease;
}
.saveflag.on { opacity: 1; }

/* ---------- layout ---------- */

.main { max-width: 760px; margin: 0 auto; padding: 16px 14px 8px; }

.foot {
  max-width: 760px; margin: 0 auto; padding: 22px 16px 40px;
  color: var(--ink-faint); font-size: 12.5px; line-height: 1.55;
}
.foot p { margin: 0 0 10px; }
.foot__legal { color: var(--ink-soft); }
.foot__mark { font-family: var(--serif); font-style: italic; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  margin: 0 0 14px;
  overflow: hidden;
}
.card__head { padding: 14px 16px 0; }
.card__body { padding: 14px 16px 16px; }
.card__title { font-size: 15px; }

/* the book's yellow section band */
.band {
  background: var(--yellow); color: #000;
  font-size: 11.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  padding: 7px 16px;
}

.note {
  font-family: var(--serif); font-style: italic;
  font-size: 14.5px; line-height: 1.5; color: var(--ink-soft);
  border-left: 3px solid var(--yellow);
  background: color-mix(in srgb, var(--yellow) 9%, var(--paper));
  padding: 10px 14px; margin: 0 0 14px; border-radius: 0 8px 8px 0;
}

.hint { font-size: 12.5px; color: var(--ink-faint); margin: 6px 0 0; }

/* ---------- hub ---------- */

.hero { padding: 6px 2px 14px; }
.hero h1 { font-size: 26px; letter-spacing: -.02em; }
.hero h1 em {
  font-style: normal; background: var(--yellow); color: #000;
  padding: 0 6px; box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.hero p { margin: 10px 0 0; color: var(--ink-soft); font-size: 15px; }

.tiles { display: grid; gap: 12px; }

.tile {
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 13px;
  width: 100%; text-align: left; text-decoration: none;
  background: var(--paper); color: inherit;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 14px; cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.tile:active { transform: scale(.99); }
.tile:hover { border-color: var(--line-firm); }
.tile__num {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--blue); color: #fff;
  display: grid; place-items: center; line-height: 1;
}
.tile__num b { font-size: 17px; font-weight: 800; }
.tile__num span { font-size: 8.5px; letter-spacing: .08em; text-transform: uppercase; opacity: .85; display: block; margin-top: 2px; }
.tile__txt { min-width: 0; }
.tile__name { display: block; font-weight: 800; font-size: 16px; letter-spacing: -.01em; }
.tile__sub { display: block; font-size: 13px; color: var(--ink-faint); margin-top: 2px; }
.tile__meter { display: block; margin-top: 8px; height: 5px; border-radius: 3px; background: var(--wash); overflow: hidden; }
.tile__meter i { display: block; height: 100%; background: var(--blue); border-radius: 3px; }
.tile__go { color: var(--ink-faint); font-size: 20px; }

.tile--flag .tile__num { background: var(--warn); }

/* ---------- forms ---------- */

.field { margin: 0 0 14px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field__label {
  display: block;
  font-size: 10.5px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-faint); margin: 0 0 6px;
}
.field__desc { font-family: var(--serif); font-style: italic; font-size: 13.5px; color: var(--ink-soft); margin: -2px 0 8px; }

input[type="text"], input[type="date"], input[type="time"], input[type="number"], textarea, select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit; font-size: 16px; /* 16px: stops iOS zoom-on-focus */
  color: var(--ink);
  background: var(--wash);
  border: 1px solid var(--line-firm);
  border-radius: 10px;
  appearance: none;
}
textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { outline: 3px solid color-mix(in srgb, var(--blue) 45%, transparent); outline-offset: 1px; border-color: var(--blue); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .row2 { grid-template-columns: 1fr; } }

/* scale of buttons — 1..10 or 1..5 */
.scale { display: grid; gap: 5px; grid-auto-flow: column; grid-auto-columns: 1fr; }
.scale button {
  min-height: var(--tap); padding: 0 2px;
  font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--ink-soft); background: var(--wash);
  border: 1px solid var(--line-firm); border-radius: 9px;
  cursor: pointer; transition: none;
}
.scale button[aria-pressed="true"] { background: var(--blue); border-color: var(--blue-deep); color: #fff; }
.scale--5 button { font-size: 16px; }
.scale__legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-faint); margin-top: 5px; }

/* yes / no pair */
.yesno { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.yesno button {
  min-height: var(--tap); font-weight: 800; letter-spacing: .04em;
  border-radius: 10px; border: 1px solid var(--line-firm);
  background: var(--wash); color: var(--ink-soft); cursor: pointer;
}
.yesno button[aria-pressed="true"][data-val="yes"] { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.yesno button[aria-pressed="true"][data-val="no"]  { background: var(--alert-bg); border-color: var(--alert); color: var(--alert); }

/* checkbox list */
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { border-top: 1px solid var(--line); }
.checks li:first-child { border-top: 0; }
.checks label {
  display: grid; grid-template-columns: 26px 1fr; gap: 11px; align-items: start;
  padding: 11px 0; cursor: pointer; font-size: 14.5px; line-height: 1.45;
}
.checks input { position: absolute; opacity: 0; pointer-events: none; }
.checks .box {
  width: 24px; height: 24px; margin-top: 1px;
  border: 2px solid var(--line-firm); border-radius: 6px; background: var(--paper);
  display: grid; place-items: center;
}
.checks .box::after {
  content: ""; width: 11px; height: 6px; margin-top: -3px;
  border-left: 2.5px solid #000; border-bottom: 2.5px solid #000;
  transform: rotate(-45deg) scale(0); transition: transform .12s ease;
}
.checks input:checked + .box { background: var(--yellow); border-color: #000; }
.checks input:checked + .box::after { transform: rotate(-45deg) scale(1); }
.checks input:focus-visible + .box { outline: 3px solid color-mix(in srgb, var(--blue) 45%, transparent); outline-offset: 2px; }

/* option grid (next action decision) */
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.options button {
  min-height: 58px; padding: 8px 6px;
  font-size: 12.5px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; line-height: 1.25;
  border: 1px solid var(--line-firm); border-radius: 10px;
  background: var(--wash); color: var(--ink-soft); cursor: pointer;
}
.options button[aria-pressed="true"] { background: var(--blue); border-color: var(--blue-deep); color: #fff; }

/* ---------- period switcher (day 1-7 / week 1-8) ---------- */

.periods {
  position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 15;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -14px 14px; padding: 10px 14px;
  background: color-mix(in srgb, var(--wash) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.periods::-webkit-scrollbar { display: none; }
.periods button {
  flex: 0 0 auto; min-width: 60px; min-height: 40px; padding: 0 12px;
  font-size: 13px; font-weight: 800;
  border: 1px solid var(--line-firm); border-radius: 20px;
  background: var(--paper); color: var(--ink-soft); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.periods button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.periods .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line-firm); }
.periods button[data-filled="1"] .dot { background: var(--blue); }
.periods button[aria-pressed="true"] .dot { background: var(--yellow); }

/* ---------- readouts, flags, charts ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px; }
.stat { background: var(--wash); border-radius: 10px; padding: 10px; text-align: center; }
.stat__k { font-size: 9.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); }
.stat__v { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 3px; }
.stat__d { font-size: 11.5px; font-variant-numeric: tabular-nums; margin-top: 1px; color: var(--ink-faint); }
.stat__d.up { color: var(--good); }
.stat__d.down { color: var(--alert); }

.flag {
  display: grid; grid-template-columns: 20px 1fr; gap: 10px; align-items: start;
  border-radius: 10px; padding: 11px 13px; margin: 0 0 8px;
  font-size: 14px; line-height: 1.45;
}
.flag:last-child { margin-bottom: 0; }
.flag b { display: block; }
.flag__i { font-size: 15px; line-height: 1.3; }
.flag--good  { background: var(--good-bg);  color: var(--good); }
.flag--warn  { background: var(--warn-bg);  color: var(--warn); }
.flag--alert { background: var(--alert-bg); color: var(--alert); }
.flag--idle  { background: var(--wash);     color: var(--ink-faint); }
.flag span.t { color: var(--ink); }
.flag--idle span.t { color: var(--ink-faint); }

.chart { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-faint); margin-top: 8px; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

.spark { display: grid; grid-template-columns: 1fr auto 64px; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.spark:first-child { border-top: 0; }
.spark__v { font-variant-numeric: tabular-nums; font-weight: 800; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  font-size: 15px; font-weight: 800; letter-spacing: .01em;
  border-radius: 11px; border: 1px solid transparent; cursor: pointer;
  background: var(--blue); color: #fff; text-decoration: none;
}
.btn--ghost { background: var(--paper); color: var(--ink); border-color: var(--line-firm); }
.btn--yellow { background: var(--yellow); color: #000; }
.btn--danger { background: var(--paper); color: var(--alert); border-color: var(--alert); }
.btn--wide { width: 100%; }
.btn:active { transform: scale(.99); }
.btnrow { display: grid; gap: 9px; }

.pagenav { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 4px 0 18px; }

/* ---------- print: the paper version, for the physician ---------- */

.printsheet { display: none; }

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body { background: #fff; color: #000; font-size: 10pt; }
  .topbar, .foot, .main, .skip { display: none !important; }
  .printsheet { display: block; }
  .printsheet h1 { font-size: 17pt; margin: 0 0 2mm; }
  .printsheet h2 {
    font-size: 11pt; margin: 7mm 0 2mm; padding: 1.5mm 2mm;
    background: #FFF000; color: #000; text-transform: uppercase; letter-spacing: .06em;
    break-after: avoid;
  }
  .printsheet .meta { font-size: 9pt; color: #333; margin: 0 0 4mm; border-bottom: 1.5pt solid #000; padding-bottom: 2mm; }
  .printsheet table { width: 100%; border-collapse: collapse; margin: 0 0 3mm; break-inside: auto; }
  .printsheet th, .printsheet td { border: .5pt solid #999; padding: 1.4mm 1.8mm; text-align: left; vertical-align: top; font-size: 8.5pt; }
  .printsheet th { background: #EEE; font-size: 7.5pt; text-transform: uppercase; letter-spacing: .05em; }
  .printsheet td.n { text-align: center; font-variant-numeric: tabular-nums; }
  .printsheet .sect { break-inside: avoid; }
  .printsheet .legal { margin-top: 6mm; font-size: 7.5pt; color: #444; border-top: .5pt solid #999; padding-top: 2mm; }
}
