/* =========================================================================
   frame.css - THE shared zero-dependency app shell stylesheet.
   Drop this in once per app. No framework, no CDN, no fonts, no images:
   reset + design tokens (light+dark) + layout primitives + a11y hygiene.

   Distilled from 100 hand-authored zero-dependency company pages and the
   mobile-web-blazor-guide. Every value here is deliberate - the whole point
   is to NOT read as AI-generated (see FRAME_SPEC.md, "anti-AI" section):
   no Inter-only stack, no indigo->purple gradient, no pure #000/#fff, a
   systematic (not uniform) spacing/radius/shadow scale, motion that honors
   reduced-motion. Override the --f-* tokens per app to give it a personality.
   ========================================================================= */

/* ---- 1. Modern reset ---------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: light dark;   /* native controls/scrollbars follow the theme */
}
body {
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-family: var(--f-font-body);
  font-size: var(--f-text-0);
  color: var(--f-ink);
  background: var(--f-bg);
}
img, picture, svg, video, canvas { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; padding: 0; }
h1, h2, h3, h4 { line-height: 1.08; text-wrap: balance; letter-spacing: -0.02em; }
p { text-wrap: pretty; }
:where(h1, h2, h3, h4, p, li) { overflow-wrap: break-word; }

/* ---- 2. Design tokens --------------------------------------------------- */
:root {
  /* Type: a two-face system. Body defaults to a system UI stack; the display
     face is a system serif so headings differ from body out of the box (one
     sans everywhere is the loudest AI tell). Override either per app. */
  --f-font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --f-font-display: var(--f-font-body);
  --f-font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  /* Fluid type scale (clamp keeps a rem term so browser zoom still works). */
  --f-text--1: clamp(0.83rem, 0.80rem + 0.15vw, 0.92rem);
  --f-text-0:  clamp(1.00rem, 0.96rem + 0.20vw, 1.13rem);
  --f-text-1:  clamp(1.20rem, 1.10rem + 0.50vw, 1.50rem);
  --f-text-2:  clamp(1.50rem, 1.30rem + 1.00vw, 2.10rem);
  --f-text-3:  clamp(1.95rem, 1.55rem + 2.00vw, 3.10rem);
  --f-text-4:  clamp(2.50rem, 1.80rem + 3.40vw, 4.60rem);

  /* Spacing scale (used everywhere, VARIED by hierarchy - not uniform). */
  --f-s1: 0.25rem; --f-s2: 0.5rem; --f-s3: 0.75rem; --f-s4: 1rem;
  --f-s5: 1.5rem;  --f-s6: 2rem;   --f-s7: 3rem;    --f-s8: 4.5rem;

  /* Radius as a small SYSTEM (different element types get different radii),
     not one value repeated. Concentric nesting: inner < outer. */
  --f-r1: 4px; --f-r2: 8px; --f-r3: 12px; --f-r4: 20px; --f-pill: 999px;

  /* Elevation: layered + tinted shadows (never one flat shadow on everything). */
  --f-shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
  --f-shadow-2: 0 8px 24px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.06);
  --f-shadow-3: 0 24px 56px rgba(16, 24, 40, 0.16), 0 6px 16px rgba(16, 24, 40, 0.08);

  /* Motion tokens (matches the pages' dominant .12-.28s + standard easing). */
  --f-ease: cubic-bezier(0.2, 0, 0, 1);
  --f-ease-out: cubic-bezier(0.2, 0.7, 0.3, 1);
  --f-dur-fast: 120ms; --f-dur: 180ms; --f-dur-slow: 280ms;

  /* Layout. */
  --f-wrap: 1200px;          /* readable app width; media-heavy apps go wider */
  --f-wrap-narrow: 720px;    /* prose / forms measure */
  --f-gutter: clamp(1rem, 4vw, 3rem);
  --f-header-h: 60px;
  --f-tap: 44px;             /* minimum touch target */

  /* Semantic colors - LIGHT. Off-white / near-black, never pure #fff/#000. */
  --f-bg: #fbfbfa;            /* paper */
  --f-surface: #ffffff;       /* raised cards/panels */
  --f-surface-2: #f2f3f5;     /* sunken / subtle fills */
  --f-ink: #17191d;           /* near-black text */
  --f-muted: #565b66;         /* secondary text (>= 4.5:1 on --f-bg) */
  --f-line: #e4e6ea;          /* hairline borders */
  --f-accent: #0f6d5b;        /* ONE confident brand color (~10% usage). */
  --f-accent-ink: #ffffff;    /* text on accent */
  --f-accent-weak: #e6f2ef;   /* tinted accent wash */
  --f-focus: #2563eb;         /* focus ring */
}

/* Automatic dark mode. */
@media (prefers-color-scheme: dark) {
  :root {
    --f-bg: #0e1116;
    --f-surface: #161a21;
    --f-surface-2: #1d222b;
    --f-ink: #e8ebf0;
    --f-muted: #9aa3b2;
    --f-line: #2a303b;
    --f-accent: #4fd1b3;
    --f-accent-ink: #06231c;
    --f-accent-weak: #14332c;
    --f-focus: #7aa2ff;
    --f-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.40), 0 1px 3px rgba(0, 0, 0, 0.30);
    --f-shadow-2: 0 8px 24px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.30);
    --f-shadow-3: 0 24px 56px rgba(0, 0, 0, 0.55), 0 6px 16px rgba(0, 0, 0, 0.35);
  }
}

/* Explicit user override wins over the OS setting (set data-theme on <html>).
   Duplicated values so forcing a theme never depends on media-query order. */
:root[data-theme="light"] {
  --f-bg: #fbfbfa; --f-surface: #ffffff; --f-surface-2: #f2f3f5;
  --f-ink: #17191d; --f-muted: #565b66; --f-line: #e4e6ea;
  --f-accent: #0f6d5b; --f-accent-ink: #ffffff; --f-accent-weak: #e6f2ef; --f-focus: #2563eb;
  --f-shadow-1: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
  --f-shadow-2: 0 8px 24px rgba(16,24,40,.10), 0 2px 6px rgba(16,24,40,.06);
  --f-shadow-3: 0 24px 56px rgba(16,24,40,.16), 0 6px 16px rgba(16,24,40,.08);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --f-bg: #0e1116; --f-surface: #161a21; --f-surface-2: #1d222b;
  --f-ink: #e8ebf0; --f-muted: #9aa3b2; --f-line: #2a303b;
  --f-accent: #4fd1b3; --f-accent-ink: #06231c; --f-accent-weak: #14332c; --f-focus: #7aa2ff;
  --f-shadow-1: 0 1px 2px rgba(0,0,0,.40), 0 1px 3px rgba(0,0,0,.30);
  --f-shadow-2: 0 8px 24px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.30);
  --f-shadow-3: 0 24px 56px rgba(0,0,0,.55), 0 6px 16px rgba(0,0,0,.35);
  color-scheme: dark;
}

/* ---- 3. Accessibility hygiene ------------------------------------------ */
.f-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 3px solid var(--f-focus); outline-offset: 2px; border-radius: 2px; }
:focus:not(:focus-visible) { outline: none; }
.f-skip {   /* skip-to-content link, visible only on focus */
  position: absolute; left: var(--f-s4); top: -3rem; z-index: 200;
  background: var(--f-surface); color: var(--f-ink); padding: var(--f-s3) var(--f-s4);
  border-radius: var(--f-r2); box-shadow: var(--f-shadow-2); transition: top var(--f-dur) var(--f-ease);
}
.f-skip:focus { top: var(--f-s4); }

/* The reduced-motion kill-switch: motion must never be load-bearing. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important; scroll-behavior: auto !important;
  }
}

/* ---- 4. Layout primitives ---------------------------------------------- */
/* .f-wrap: the centered content column with fluid gutters. */
.f-wrap { width: 100%; max-width: var(--f-wrap); margin-inline: auto; padding-inline: var(--f-gutter); }
.f-wrap--narrow { max-width: var(--f-wrap-narrow); }
.f-wrap--wide { max-width: 1440px; }

/* .f-app: the whole shell as a column so the footer sinks on short pages. */
.f-app { display: flex; flex-direction: column; min-height: 100dvh; }

/* Header: sticky, hairline underline, respects the notch. */
.f-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--f-bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--f-line);
  padding-top: env(safe-area-inset-top, 0);
}
.f-header__bar {
  display: flex; align-items: center; gap: var(--f-s4);
  min-height: var(--f-header-h);
}
.f-brand {
  display: inline-flex; align-items: center; gap: var(--f-s3);
  font-family: var(--f-font-display); font-weight: 800;
  font-size: var(--f-text-1); letter-spacing: -0.03em; color: var(--f-ink);
}
.f-brand__mark {   /* slot for an inline-SVG / CSS logo mark */
  display: grid; place-content: center; width: 30px; height: 30px;
  border-radius: var(--f-r2); background: var(--f-accent); color: var(--f-accent-ink);
  font-size: 0.95rem; font-weight: 800;
}
.f-nav { display: none; gap: clamp(1rem, 2vw, 1.75rem); margin-inline: auto; font-weight: 600; }
.f-nav a { padding: var(--f-s2) var(--f-s1); color: var(--f-muted); }
.f-nav a[aria-current], .f-nav a.is-active { color: var(--f-ink); }
.f-header__actions { display: flex; align-items: center; gap: var(--f-s3); margin-inline-start: auto; }

/* Main + footer. */
.f-main { flex: 1 0 auto; }
.f-main:focus { outline: none; }   /* FocusOnNavigate target, no visible ring */
.f-footer {
  border-top: 1px solid var(--f-line); color: var(--f-muted);
  padding-block: var(--f-s7);
  padding-bottom: max(var(--f-s7), env(safe-area-inset-bottom));
  font-size: var(--f-text--1);
}
.f-footer__grid { display: grid; gap: var(--f-s6); grid-template-columns: 1fr; }
.f-footer__note { border-top: 1px solid var(--f-line); padding-top: var(--f-s5); margin-top: var(--f-s5); }

/* Section rhythm - vary by importance, do not pad everything the same. */
.f-section { padding-block: clamp(2.5rem, 7vw, 5.5rem); }
.f-section--tight { padding-block: clamp(1.5rem, 4vw, 3rem); }

/* Auto-fit responsive grid (breakpoint-free). Set --f-col to the min tile. */
.f-grid {
  display: grid; gap: clamp(1rem, 2.5vw, 1.75rem);
  grid-template-columns: repeat(auto-fit, minmax(min(var(--f-col, 260px), 100%), 1fr));
}
.f-stack { display: flex; flex-direction: column; gap: var(--f-s4); }
.f-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--f-s4); }

/* ---- 5. Type helpers ---------------------------------------------------- */
.f-eyebrow { font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: var(--f-text--1); color: var(--f-accent); }
.f-title { font-family: var(--f-font-display); font-size: var(--f-text-4); font-weight: 780; line-height: 1.02; }
.f-h2 { font-family: var(--f-font-display); font-size: var(--f-text-2); font-weight: 750; }
.f-lede { color: var(--f-muted); font-size: var(--f-text-1); line-height: 1.5; max-width: 60ch; }
.f-prose { max-width: 68ch; }
.f-prose p + p { margin-top: var(--f-s4); }

/* ---- 6. Card ------------------------------------------------------------ */
.f-card {
  background: var(--f-surface); border: 1px solid var(--f-line);
  border-radius: var(--f-r3); box-shadow: var(--f-shadow-1);
  padding: clamp(1.25rem, 3vw, 1.75rem);
  transition: box-shadow var(--f-dur) var(--f-ease), transform var(--f-dur) var(--f-ease);
}
.f-card--pad0 { padding: 0; overflow: hidden; }   /* for edge-to-edge media */
.f-card--link { display: block; color: inherit; }
.f-card__media { aspect-ratio: 16 / 10; background: var(--f-surface-2); }
.f-card__body { padding: clamp(1rem, 3vw, 1.5rem); }
.f-card__title { font-size: var(--f-text-1); font-weight: 700; }
.f-card__meta { color: var(--f-muted); font-size: var(--f-text--1); margin-top: var(--f-s1); }

/* ---- 7. Button ---------------------------------------------------------- */
.f-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  min-height: 48px; padding: 0.75rem 1.4rem; border-radius: var(--f-pill);
  font-weight: 650; letter-spacing: -0.01em; line-height: 1;
  border: 1px solid transparent; touch-action: manipulation;
  transition: transform var(--f-dur-fast) var(--f-ease), background var(--f-dur) var(--f-ease), box-shadow var(--f-dur) var(--f-ease), border-color var(--f-dur) var(--f-ease);
}
.f-btn:active { transform: translateY(1px) scale(0.99); }   /* tactile on every device */
.f-btn--primary { background: var(--f-accent); color: var(--f-accent-ink); }
.f-btn--secondary { background: var(--f-surface); color: var(--f-ink); border-color: var(--f-line); }
.f-btn--ghost { background: transparent; color: var(--f-ink); border-color: var(--f-line); }
.f-btn--quiet { background: transparent; color: var(--f-ink); padding-inline: 0.5rem; }
.f-btn--sm { min-height: 40px; padding: 0.5rem 1rem; font-size: var(--f-text--1); }
.f-btn--lg { min-height: 54px; padding: 1rem 1.9rem; font-size: var(--f-text-1); }
.f-btn--block { width: 100%; }

/* ---- 8. Badge + chip ---------------------------------------------------- */
.f-badge {
  display: inline-flex; align-items: center; gap: 0.35em;
  padding: 0.2rem 0.6rem; border-radius: var(--f-pill);
  font-size: var(--f-text--1); font-weight: 650; line-height: 1.4;
  background: var(--f-accent-weak); color: var(--f-accent);
}
.f-badge--neutral { background: var(--f-surface-2); color: var(--f-muted); }
.f-chip {
  display: inline-flex; align-items: center; min-height: var(--f-tap);
  padding: 0.4rem 0.9rem; border-radius: var(--f-pill);
  border: 1px solid var(--f-line); background: var(--f-surface); color: var(--f-ink);
  font-size: var(--f-text--1); font-weight: 600; touch-action: manipulation;
  transition: border-color var(--f-dur) var(--f-ease), background var(--f-dur) var(--f-ease);
}
.f-chip[aria-pressed="true"], .f-chip.is-active { background: var(--f-ink); color: var(--f-bg); border-color: var(--f-ink); }

/* ---- 9. Form controls (16px min = no iOS zoom; visible focus) ----------- */
.f-field { display: grid; gap: var(--f-s2); }
.f-label { font-weight: 650; font-size: var(--f-text--1); }
.f-input, .f-select, .f-textarea {
  min-height: 48px; width: 100%; font-size: max(16px, 1rem);
  padding: 0.7rem 0.9rem; border-radius: var(--f-r2);
  border: 1px solid var(--f-line); background: var(--f-surface); color: var(--f-ink);
  transition: border-color var(--f-dur) var(--f-ease), box-shadow var(--f-dur) var(--f-ease);
}
.f-input:focus, .f-select:focus, .f-textarea:focus {
  outline: none; border-color: var(--f-accent);
  box-shadow: 0 0 0 3px var(--f-accent-weak);
}
.f-textarea { min-height: 7rem; resize: vertical; }

/* ---- 10. CSS-only mobile drawer (checkbox + label, no JS) --------------- */
/* Markup contract: put #f-drawer-toggle + .f-burger + .f-scrim + .f-drawer
   as siblings inside .f-header__bar (see frame.html / components). */
.f-burger {
  margin-inline-start: auto; width: var(--f-tap); height: var(--f-tap);
  display: grid; place-content: center; gap: 5px; touch-action: manipulation;
}
.f-burger span { width: 24px; height: 2px; background: var(--f-ink); display: block; border-radius: 2px; }
.f-drawer-toggle { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.f-drawer {
  position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 90;
  width: min(86vw, 360px); background: var(--f-surface); color: var(--f-ink);
  display: flex; flex-direction: column; gap: var(--f-s1);
  padding: calc(env(safe-area-inset-top) + 4.5rem) var(--f-s5) var(--f-s6);
  transform: translateX(101%); transition: transform var(--f-dur-slow) var(--f-ease);
  box-shadow: var(--f-shadow-3); overflow-y: auto; overscroll-behavior: contain;
}
.f-drawer a { padding: var(--f-s3) 0; min-height: var(--f-tap); border-bottom: 1px solid var(--f-line); font-size: var(--f-text-1); font-weight: 650; }
.f-scrim {
  position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, 0.5);
  opacity: 0; visibility: hidden; transition: opacity var(--f-dur-slow) var(--f-ease), visibility var(--f-dur-slow);
}
.f-drawer-toggle:checked ~ .f-drawer { transform: translateX(0); }
.f-drawer-toggle:checked ~ .f-scrim { opacity: 1; visibility: visible; }

/* ---- 11. Archetype helpers (see FRAME_SPEC.md) -------------------------- */
/* (B) full-screen canvas/WASM stage: hands the viewport to a canvas below a
   slim chrome. Uses svh so mobile browser chrome doesn't clip it. */
.f-stage {
  position: relative; width: 100%;
  height: calc(100svh - var(--f-header-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: 320px; background: var(--f-surface-2); overflow: hidden;
  touch-action: none;   /* let the app own gestures; remove if it should scroll */
}
.f-stage > canvas, .f-stage > iframe, .f-stage > .f-stage__fill { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.f-stage--full { height: 100svh; }   /* immersive: no chrome */

/* (C) tool/simulator split: controls rail + output panel, stacks on mobile. */
.f-tool { display: grid; gap: var(--f-s5); grid-template-columns: 1fr; align-items: start; }
.f-tool__panel { position: static; }

/* (A) gallery caption block under media tiles. */
.f-caption { margin-top: var(--f-s3); }
.f-caption__title { font-weight: 700; }
.f-caption__meta { color: var(--f-muted); font-size: var(--f-text--1); }

/* ---- 12. Responsive: real layout changes, not just scaling -------------- */
@media (min-width: 720px) {
  .f-burger { display: none; }
  .f-nav { display: flex; }
  .f-footer__grid { grid-template-columns: 2fr 1fr 1fr 1fr; }
  .f-tool { grid-template-columns: 320px 1fr; }
  .f-tool__panel { position: sticky; top: calc(var(--f-header-h) + var(--f-s4)); }
}

/* ---- 13. Hover only where a real pointer exists ------------------------- */
@media (hover: hover) {
  .f-btn--primary:hover { box-shadow: var(--f-shadow-2); filter: brightness(1.03); }
  .f-btn--secondary:hover, .f-btn--ghost:hover { border-color: var(--f-ink); }
  .f-nav a:hover { color: var(--f-ink); }
  .f-card--link:hover { box-shadow: var(--f-shadow-2); transform: translateY(-2px); }
  .f-chip:hover { border-color: var(--f-ink); }
}
