/* The design system — every number this product is allowed to use.
 *
 * WHAT THIS REPLACES. The stylesheet beside this one had 15 font sizes, 13 corner radii, 20
 * spacing values and one box-shadow, each chosen by eye at the moment it was needed. None of them
 * was wrong on its own; together they are why the product reads as assembled rather than designed.
 * The fix is not better taste, it is a fixed set of values and a guard that stops it growing back
 * (tests/design-system.test.mjs).
 *
 * THE DIRECTION IS "REFINED PAPER" — the paper metaphor the founder already reads fluently on his
 * wall calendar, executed with craft: hairline rules, one radius family, tabular figures, a real
 * spacing rhythm. Warm AND precise. The premium quality comes from discipline, not from going dark.
 *
 * THE PRODUCT HAS NO FOURTH HUE. The three carer colours are spoken for by data; the interaction
 * accent is ink itself — black type and black buttons on warm paper. One alert red exists and is
 * reserved for escalation and failure. This restriction is the whole reason the result reads as
 * expensive, and it is the first thing that will be tempting to break.
 *
 * ROUNDING RULE, for anything that arrives off the scale: round to the nearest step, ties resolve
 * downward. A value with no token was a value chosen by eye — it gets corrected, not accommodated.
 *
 * Fonts are self-hosted woff2 under /fonts. They have to be: the Content-Security-Policy in
 * vercel.json is `style-src 'self'; script-src 'self'` with no external host, and `font-src` falls
 * back to `default-src 'self'`. Nothing here may ever reference a font CDN. Licences and the exact
 * source URLs are in src/fonts/OFL.txt — both families are SIL Open Font License 1.1.
 *
 * The two files are cached for a week with stale-while-revalidate (vercel.json, which takes no
 * comments — the reasoning is here and in tests/design-system.test.mjs). NOT `immutable`: these
 * filenames carry the family and weight, not a content hash, so a face replaced under the same
 * name would be stuck in every cache holding it with no way to evict it.
 */

/* Instrument Serif — the month title and the day numerals. The one distinctive signature in the
   product; nothing else in this category uses a display serif. Latin subset, 21,032 bytes. */
@font-face {
  font-family: 'Instrument Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/instrument-serif-400.woff2') format('woff2');
}

/* Inter — everything else. ONE file covers both weights: Google serves a single latin file for
   Inter at every weight because the face is variable along the weight axis, and the 400 and 600
   URLs are byte-identical. Shipping it twice would be 48KB of duplicate bytes under a filename
   stating something untrue, so it is declared once with the weight RANGE. Latin subset, 48,256
   bytes. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/fonts/inter-variable.woff2') format('woff2');
}

:root {
  --font-serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* ---- Type: six sizes, and no others ----------------------------------------------------
   *
   * Each token is a complete `font` shorthand — weight, size, line-height and face — because six
   * names have to carry all four and `font` is the only property that takes them together.
   *
   * THE SHORTHAND RESETS font-variant-numeric TO normal. That is a CSS rule, not a quirk, and it
   * means any block writing `font: var(--t-…)` loses tabular figures unless it says so again on
   * the next line. The guard asserts it for --t-numeral, where a column of dates that does not
   * align is the whole point of choosing tabular in the first place.
   *
   * The old `oldstyle-nums` on the grid numerals is dropped: old-style figures have descenders of
   * uneven height, which is charming in prose and wrong in a column of dates.
   */
  --t-display: 400 32px/1.1 var(--font-serif);   /* month name                                  */
  --t-numeral: 400 24px/1 var(--font-serif);     /* day numbers in the grid                     */
  --t-title: 600 17px/1.3 var(--font-sans);      /* item titles, section headings               */
  --t-body: 400 15px/1.45 var(--font-sans);      /* body text                                   */
  --t-meta: 400 13px/1.4 var(--font-sans);       /* dates, counts, secondary lines              */
  --t-micro: 600 11px/1 var(--font-sans);        /* day-of-week headers, tags, chips            */

  /* Inter's own optical correction at 15px and above, and the tracking the micro step needs to
     stay legible as letterspaced caps. */
  --track-tight: -0.011em;
  --track-micro: 0.08em;

  /* ---- Spacing: a 4pt grid, six steps ---------------------------------------------------- */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;   /* the page gutter */
  --s5: 24px;
  --s6: 32px;

  /* ---- Radii: one family, four steps, plus the pill -------------------------------------- */
  /* The hand-drawn `3px 6px 4px 5px` stripe radius is retired. It was the one deliberate liberty
     in the original design, and it is the detail that most reads as unfinished at a glance. */
  --r-chip: 8px;
  --r-cell: 10px;
  --r-card: 12px;
  --r-sheet: 20px;
  --r-pill: 999px;

  /* ---- Elevation: three steps ------------------------------------------------------------ */
  /* Shadows are cast in ink, not in black: a neutral-black shadow over warm paper greys the paper
     under it, which is exactly the muddiness this direction is correcting. */
  --e1: 0 1px 2px rgba(23, 21, 15, 0.05);      /* cards at rest              */
  --e2: 0 4px 16px rgba(23, 21, 15, 0.08);     /* floating chrome, raised    */
  --e3: 0 -8px 40px rgba(23, 21, 15, 0.18);    /* sheets and modals          */

  /* ---- Colour ---------------------------------------------------------------------------- */
  --ground: #F7F4ED;
  --surface: #FFFFFF;
  --rule: #E5DFD4;
  --ink: #17150F;
  /* Darker than the spec's #6E655A, and the reason is the token below rather than anything wrong
     with this one. Fixing --ink-3's contrast moved it DOWN to L* 46.6, which left these two 3.3 L*
     apart — three names resolving to two greys. Five later tasks build an item title, its
     secondary line and a tertiary label out of this ramp, so a collision here produces exactly the
     flatness this rebuild exists to remove, and it would read as a design choice rather than a
     mistake, which is why nobody would ever question it.
     L* 43.3 → 34.1, and it carries real secondary text rather than labels, so it holds 7.33:1 on
     --ground and 8.05:1 on --surface. */
  --ink-2: #574F44;
  /* The quiet ink, and it is DARKER than the spec wrote it. §7.5 had #9A9186, which is 2.82:1 on
     --ground — a fail for text at any size, and §8 sets the home screen's inline legend in it.
     That legend is read one-handed at arm's length in a bright kitchen, so the 4.5:1 text
     threshold is the one that applies, not the 3:1 non-text floor. L* 60.6 → 46.6, measured at
     4.62:1 on --ground and 5.07:1 on --surface.
     This token took the other branch of the fork the first draft of this comment left open: --ink-2
     was darkened (to L* 34.1, ruling T, see above) rather than the two merged, so the ramp has
     three steps and --ink-2 sits 12.5 L* from this one. The ink-ramp test measures that pair. */
  --ink-3: #766D63;
  --alert: #B3261E;

  /* The three carer hues differ in LIGHTNESS as well as hue, in both themes, so the month survives
     greyscale, printing and the common forms of colour blindness. The letter in the cell is always
     present: colour is never the only signal.
     Named --carer-* rather than --mike so that a colour belonging to a person is never one typo
     away from --ink, and so the guard can find the set by pattern.

     THESE ARE NOT THE SPEC'S HEXES, because the spec's hexes did not do what the spec claimed.
     Measured, §7.5's light values were L* 43.1 / 45.3 / 51.3 — the first two carers 2.2 apart, which
     means that in greyscale, in print, or to a deuteranope those two cells are the SAME GREY. The
     claim that the month survives all three was the whole argument for colour carrying the signal.
     Each hue is unchanged — these are the founder's actual highlighter families, blue, green and
     amber, and that metaphor is load-bearing — and only lightness moved: L* 34.1 / 44.9 / 56.1
     light, 54.9 / 66.1 / 77.1 dark, every pair at least 10 L* apart in both themes and every one
     at 3:1 or better on its own background. The guard asserts both, because a value fixed by hand
     and not asserted comes back. */
  --carer-mike: #1A4AAB;
  --carer-shannon: #1E794B;
  --carer-gp: #BE7619;
  /* The label on a SELECTED Grandparents segment. The other two carers take --surface (white on a
     deep fill), but white on this amber is 3.62:1 - a fail for 13px/600 text. Ink on it is 5.1:1.
     It is a token rather than a literal in app.css so the dark theme, where the amber is pale and
     the label has to go dark, can say so on its own line. */
  --on-carer-gp: #17150F;

  /* Behind a sheet. Ink rather than neutral black, for the reason the elevation ladder gives. */
  --scrim: rgba(23, 21, 15, 0.32);

  /* ---- Motion ---------------------------------------------------------------------------- */
  --m-state: 160ms;
  --m-sheet: 240ms;

  /* ---- Translucency: exactly two surfaces, the header and the tab bar --------------------- */
  /* One move borrowed from the glass direction and only one — warm white blurred over whatever
     scrolls beneath. Everything else is opaque, which is how iOS itself behaves: glass chrome,
     solid content. The fallbacks at the bottom of this file replace the colour and drop the blur
     without touching a single size, so the layout cannot shift between the two states. */
  --chrome-bg: rgba(247, 244, 237, 0.72);
  --chrome-blur: blur(20px) saturate(140%);
  --chrome-rule: rgba(23, 21, 15, 0.06);

  /* ---- The inverted "today" cell ----------------------------------------------------------
   *
   * Spec §8.3 inverts the today cell — the ground becomes --ink — and nothing else in the design
   * changes, which is why it could not work as written. MEASURED on the inverted ground: the
   * uncovered-closure bar is 2.79:1 in the light theme and 2.40:1 in the dark one, and in the dark
   * theme the three carer stripes collapse to 1.57, 1.87 and 2.27 because --ink is near-white
   * there. That is the product's loudest signal, failing on the one cell every reader looks at
   * first. The spec is amended; these tokens are the amendment.
   *
   * It is closer to a rename than a new palette, and that was checked rather than assumed: each
   * one IS the other theme's value, and each clears 3:1 on the inverted ground — 4.84 / 7.04 /
   * 9.85 / 6.58 in the light theme, 6.95 / 4.66 / 3.13 / 5.65 in the dark one. It works because
   * the light and dark sets sit on opposite sides of the lightness window the inversion creates,
   * and the carer lightness fix above is what put them there.
   *
   * Task 5 consumes these. They are an interface; the names are fixed.
   */
  --carer-mike-on-today: #5C7FE0;
  --carer-shannon-on-today: #02B871;
  --carer-gp-on-today: #F9B049;
  --alert-on-today: #FF6B6B;
}

/* Warm near-black, never pure #000, so the paper character survives the lights going out. */
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #141311;
    --surface: #1C1A17;
    --rule: #2E2B26;
    --ink: #F2EEE6;
    /* Lighter than the spec's #A49A8D, which measured 6.71:1 on --ground and 6.27:1 on --surface.
       The dark ramp's SPACING was fine at 9.3 L* and would have passed a check that only looked at
       separation — the contrast half is what it failed, and only measuring both found it.
       L* 64.1 → 69.0, now 7.84:1 and 7.33:1. */
    --ink-2: #B1A79A;
    /* Lighter than the spec's #6E655A, which was 3.25:1 on --ground. Same reasoning as the light
       theme: this token carries text. L* 43.3 → 54.8, measured 4.91:1 on --ground and 4.59:1 on
       --surface. */
    --ink-3: #8B8276;
    --alert: #FF6B6B;

    /* L* 54.9 / 66.1 / 77.1, every pair at least 10 apart. The spec's dark values were 65.7 /
       77.7 / 71.9 — the second carer and the grandparents 5.8 apart, and in the wrong order besides. */
    --carer-mike: #5C7FE0;
    --carer-shannon: #02B871;
    --carer-gp: #F9B049;
    --on-carer-gp: #1C1A17;

    /* Ink, driven down in lightness rather than swapped for neutral black. It has to be driven
       down: the dark ground (#141311) is already DARKER than ink itself (#17150F), so ink at any
       alpha would lighten the page instead of dimming it. The channel ratios are ink's, so the
       scrim stays warm — which is what the comment in the light theme claims, and this is the half
       that used to say "Ink rather than black" over rgba(0, 0, 0, 0.56). */
    --scrim: rgba(9, 8, 6, 0.66);

    --chrome-bg: rgba(20, 19, 17, 0.72);
    --chrome-rule: rgba(242, 238, 230, 0.08);

    --carer-mike-on-today: #1A4AAB;
    --carer-shannon-on-today: #1E794B;
    --carer-gp-on-today: #BE7619;
    --alert-on-today: #B3261E;
  }
}

/* The opaque fallbacks, and they come LAST on purpose: they override the dark theme's translucent
   values as well as the light one's. A reader who has asked for less transparency, or a browser
   with no backdrop-filter, gets fully opaque --ground in whichever theme is in force — resolved at
   use time through var(), so neither block needs to know which theme that is. */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --chrome-bg: var(--ground);
    --chrome-blur: none;
  }
}

/* Nested, and it has to be: Safari shipped -webkit-backdrop-filter years before the unprefixed
   property, so a lone `not (backdrop-filter: …)` is TRUE on an iPhone running iOS 17 and would
   throw the glass away on the one device this product is designed for. Both must be absent. */
@supports not (backdrop-filter: blur(1px)) {
  @supports not (-webkit-backdrop-filter: blur(1px)) {
    :root {
      --chrome-bg: var(--ground);
      --chrome-blur: none;
    }
  }
}
