/* blood — a measuring instrument, not a wellness app.
   Numerals are the voice: IBM Plex Mono carries every measured value, Plex Sans only
   labels them. Colour is used as ink, not as decoration. */

@font-face {
  font-family: 'IBM Plex Sans';
  src: url('../fonts/plex-sans-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('../fonts/plex-sans-600.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('../fonts/plex-mono-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('../fonts/plex-mono-500.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}

:root {
  --ground: #f7f4f2;
  --raised: #fffdfc;
  --ink: #1b1513;
  --muted: #6b5f5a;   /* 5.6:1 on --ground; #877974 was 3.8 and failed AA */
  --line: #e4dbd6;
  --mark: #8e1b2e;
  --mark-ink: #ffffff;
  --mark-soft: #ecd4d8;
  --ok: #2f5d43;

  --sans: 'IBM Plex Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, monospace;

  --gap: 1.125rem;
  --pad: 1.25rem;
  --radius: 3px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #14100f;
    --raised: #1d1817;
    --ink: #f2eae5;
    --muted: #9c8d87;
    --line: #2f2725;
    --mark: #e2687c;   /* 5.9:1 on --ground; #d4485f was 4.4, just under AA */
    --mark-ink: #14100f;
    --mark-soft: #3d1c23;
    --ok: #7fb894;
  }
}

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

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  padding: 0 var(--pad) 3rem;
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
  max-width: 34rem;
  margin-inline: auto;
}

.numeral { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.skip {
  position: absolute; left: -9999px;
  background: var(--ink); color: var(--ground);
  padding: .6rem 1rem; border-radius: var(--radius);
}
.skip:focus { left: 0; top: 0; z-index: 10; }

:where(a, button, summary, input):focus-visible {
  outline: 2px solid var(--mark);
  outline-offset: 2px;
  border-radius: 2px;
}

/* --- header ------------------------------------------------------------- */

.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 0 .75rem;
  border-bottom: 1px solid var(--line);
}
.wordmark {
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: lowercase;
  color: var(--mark);
}
.who {
  display: flex; align-items: baseline; gap: .6rem;
  font-size: .8125rem; color: var(--muted);
}
.who form { display: inline; }

.linkish {
  background: none; border: 0; padding: 0;
  font: inherit; color: var(--muted);
  text-decoration: underline; text-underline-offset: 2px;
  cursor: pointer;
}
.linkish:hover { color: var(--ink); }

/* --- flashes ------------------------------------------------------------ */

.flashes { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .5rem; }
.flash {
  padding: .625rem .875rem;
  border-left: 3px solid var(--line);
  background: var(--raised);
  font-size: .875rem;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.flash-ok { border-left-color: var(--ok); }
.flash-error { border-left-color: var(--mark); }
.flash-note { border-left-color: var(--muted); }

/* --- the count ---------------------------------------------------------- */

.eyebrow {
  font-size: .6875rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 .25rem;
}

.now { padding: 2.25rem 0 1.75rem; }

.count { margin: 0; line-height: .88; }
.count .numeral {
  font-size: clamp(5.5rem, 34vw, 9rem);
  font-weight: 500;
  color: var(--mark);
  letter-spacing: -.04em;
  display: block;
}

.since { margin: .75rem 0 0; color: var(--muted); font-size: .9375rem; }

.forecast {
  margin: .375rem 0 0;
  font-size: .9375rem;
  color: var(--muted);
}
.forecast.late { color: var(--mark); }
.forecast.quiet { font-style: italic; }

.checkin { margin-top: 1.75rem; }

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

.primary, .secondary, .danger {
  font: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}

.primary {
  display: block; width: 100%;
  padding: 1.0625rem 1rem;
  background: var(--mark); color: var(--mark-ink);
  font-weight: 600; font-size: 1.0625rem;
  letter-spacing: .01em;
  text-align: center; text-decoration: none;
}
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.primary:disabled, .primary.done {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
  cursor: default;
  font-weight: 400;
}

.secondary {
  padding: .5rem .875rem;
  background: transparent; color: var(--ink);
  border-color: var(--line);
  font-size: .875rem;
}
.secondary:hover { border-color: var(--ink); }

.danger {
  padding: .5rem .875rem;
  background: transparent; color: var(--mark);
  border-color: transparent;
  font-size: .875rem;
  text-decoration: underline; text-underline-offset: 3px;
}

/* --- stats -------------------------------------------------------------- */

.stats { border-top: 1px solid var(--line); padding: 1.25rem 0; }
.stats dl {
  margin: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
}
.stats dt {
  font-size: .625rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted);
}
.stats dd {
  margin: .125rem 0 0;
  font-size: 1.375rem; font-weight: 500;
}
.stats-note { margin: .875rem 0 0; font-size: .8125rem; color: var(--muted); }

/* --- the ruler: the page's one idea ------------------------------------- */

.ruler { border-top: 1px solid var(--line); padding: 1.25rem 0 .5rem; }
.ruler .eyebrow { margin-bottom: 1rem; }

.row { margin-bottom: 1.125rem; }

.row-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem;
  margin-bottom: .3125rem;
}
.row-date { font-size: .875rem; color: var(--muted); }
.row-days { font-size: .9375rem; font-weight: 500; }
.row-days .unit { color: var(--muted); font-size: .75rem; margin-left: .0625rem; }

.track {
  position: relative;
  height: 12px;
  background: linear-gradient(var(--line), var(--line)) left bottom / 100% 1px no-repeat;
}

.bar {
  position: absolute; left: 0; bottom: 0;
  height: 12px;
  width: var(--w);
  background: var(--mark-soft);
  border-left: 2px solid var(--mark);
  animation: draw .5s cubic-bezier(.2, .7, .3, 1) backwards;
}

/* The open bar is the cycle still being measured: no closing edge, because it has
   not happened yet. */
.bar-open {
  background: repeating-linear-gradient(
    90deg, var(--mark-soft) 0 5px, transparent 5px 9px
  );
  border-right: 2px dashed var(--mark);
}

/* Where this cycle is expected to close. */
.expected {
  position: absolute; bottom: -3px;
  width: 1px; height: 18px;
  background: var(--muted);
}
.expected::after {
  content: '';
  position: absolute; top: -4px; left: -2px;
  width: 5px; height: 5px;
  background: var(--muted);
  border-radius: 50%;
}

.row-note { margin: .375rem 0 0; font-size: .75rem; color: var(--muted); }

@keyframes draw { from { width: 0; } to { width: var(--w); } }

.row:nth-child(2) .bar { animation-delay: .04s; }
.row:nth-child(3) .bar { animation-delay: .08s; }
.row:nth-child(4) .bar { animation-delay: .12s; }
.row:nth-child(5) .bar { animation-delay: .16s; }
.row:nth-child(n+6) .bar { animation-delay: .2s; }

/* --- entries ------------------------------------------------------------ */

.entries { border-top: 1px solid var(--line); padding: 1.25rem 0 0; }
.entries .eyebrow { margin-bottom: .5rem; }

.entry { border-bottom: 1px solid var(--line); }
.entry summary {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem;
  padding: .8125rem .125rem;
  cursor: pointer;
  list-style: none;
  min-height: 44px;
}
.entry summary::-webkit-details-marker { display: none; }
.entry summary::after {
  content: '+';
  font-family: var(--mono); color: var(--muted); font-size: 1.125rem;
  line-height: 1;
}
.entry[open] summary::after { content: '\2212'; }

.entry-date { font-size: .9375rem; }
.entry-meta { font-size: .75rem; color: var(--muted); margin-left: auto; }

.entry-body { padding: .25rem .125rem 1.125rem; }

.edit {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  margin-bottom: .5rem;
}
.edit label { font-size: .8125rem; color: var(--muted); width: 100%; }
.edit input[type="date"] {
  font: inherit;
  font-family: var(--mono);
  padding: .5rem .625rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
  color: var(--ink);
  flex: 1 1 10rem;
  min-height: 44px;
}

.danger-form { display: inline; }

.provenance { margin: .75rem 0 0; font-size: .75rem; color: var(--muted); }

.add summary { color: var(--mark); }
.add summary::after { content: '+'; color: var(--mark); }
.add[open] summary::after { content: '\2212'; }

/* --- gate pages --------------------------------------------------------- */

.gate { padding: 3rem 0 2rem; }
.gate h1 {
  font-size: 1.75rem; font-weight: 600; line-height: 1.15;
  letter-spacing: -.02em;
  margin: 0 0 .875rem;
}
.gate .lede { color: var(--muted); margin: 0 0 1.75rem; }
.gate .primary { margin-bottom: .875rem; }
.gate code {
  font-family: var(--mono); font-size: .875em;
  background: var(--raised); padding: .1em .35em;
  border: 1px solid var(--line); border-radius: 2px;
}

.quiet { color: var(--muted); font-size: .8125rem; margin: 0; }

/* --- footer ------------------------------------------------------------- */

.foot {
  border-top: 1px solid var(--line);
  margin-top: 2rem; padding-top: 1rem;
}
.foot p { margin: 0; font-size: .75rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .bar { animation: none; }
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}
