/* ifdmk.dev — design tokens
   Editorial. Warm off-white, ink black, a single quiet accent.
   Inspired by the field-note mockup. */

@import url("https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,500;8..60,600&family=Inter+Tight:wght@400;500;600&family=JetBrains+Mono:wght@400;500&family=Caveat:wght@500;600&display=swap");

:root {
  /* ===== Color: paper & ink (light) ===== */
  --paper:        #f6f1e8;
  --paper-2:      #efe8db;
  --paper-3:      #e6dccb;
  --card:         #fbf7ef;
  --ink:          #1a1714;
  --ink-2:        #4a4339;
  --ink-3:        #837a6c;
  --rule:         #d6cdbb;
  --rule-2:       #c5bba6;

  --accent:       #b9532b;
  --accent-soft:  #d97757;
  --accent-bg:    #f0d9c8;

  --tag-bg:       #e6dccb;
  --tag-fg:       #4a4339;
  --tag-warn-bg:  #f0d9c8;
  --tag-warn-fg:  #8a3d1f;
  --tag-cool-bg:  #d9e1e0;
  --tag-cool-fg:  #3d5552;
}

html[data-theme="dark"] {
  --paper:        #15130f;
  --paper-2:      #1d1a15;
  --paper-3:      #25211b;
  --card:         #1a1813;
  --ink:          #ece4d3;
  --ink-2:        #b6ad9a;
  --ink-3:        #968d7a; /* WCAG AA on dark paper */
  --rule:         #2c2820;
  --rule-2:       #3d382e;

  --accent:       #e08c63;
  --accent-soft:  #d97757;
  --accent-bg:    #3a2218;

  --tag-bg:       #25211b;
  --tag-fg:       #b6ad9a;
  --tag-warn-bg:  #3a2218;
  --tag-warn-fg:  #e8a079;
  --tag-cool-bg:  #1f2a28;
  --tag-cool-fg:  #8eb1ab;
}

:root {

  /* ===== Type ===== */
  --font-serif: "Source Serif 4", "Source Serif Pro", "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;
  --font-sans:  "Inter Tight", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:  "JetBrains Mono", "IBM Plex Mono", "SF Mono", ui-monospace, "Menlo", monospace;
  --font-hand:  "Caveat", "Bradley Hand", "Segoe Print", cursive;

  /* Type scale */
  --fs-display: 56px;
  --fs-h1:      36px;
  --fs-h2:      26px;
  --fs-h3:      19px;
  --fs-body:    16px;
  --fs-meta:    14px;
  --fs-small:   13px;
  --fs-micro:   12px;

  --lh-tight:   1.15; /* @kind font */
  --lh-snug:    1.3;  /* @kind font */
  --lh-body:    1.65; /* @kind font */
  --lh-loose:   1.8;  /* @kind font */

  --tracking-eyebrow: 0.08em;
  --tracking-tight:   -0.01em;

  /* Layout */
  --measure: 680px;       /* prose measure */
  --measure-wide: 880px;  /* index pages */
  --gutter: 32px;
  --page-pad-x: clamp(24px, 5vw, 64px);

  /* Radius (subtle — editorial) */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;

  /* Borders */
  --hairline: 0.5px solid var(--rule);
  --hairline-2: 1px solid var(--rule-2);

  /* Shadows — almost never used. Editorial = flat. */
  --shadow-soft: 0 1px 2px rgba(26, 23, 20, 0.04);

  /* Motion */
  --ease: cubic-bezier(0.19, 1, 0.22, 1); /* @kind other */
  --dur-fast: 140ms; /* @kind other */
  --dur: 240ms; /* @kind other */
  --dur-slow: 480ms; /* @kind other */
}

/* ===== Reset (tight) ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  position: relative;
}
/* Paper grain — fixed SVG noise overlay, baked in. 4% opacity, multiply on light, screen on dark. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.09 0 0 0 0 0.07 0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/></svg>");
  background-size: 240px 240px;
  opacity: 0.04;
  mix-blend-mode: multiply;
}
html[data-theme="dark"] body::before {
  opacity: 0.06;
  mix-blend-mode: screen;
}
/* Layered content sits above grain */
header, main, footer, .reading-progress { position: relative; z-index: 2; }

/* Reading-progress hairline — top of viewport on note pages */
.reading-progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 100%;
  background: transparent;
  z-index: 60;
  pointer-events: none;
}
.reading-progress__bar {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: 0 50%;
  transition: transform 80ms linear;
}

/* "Last verified" rubber-stamp — slightly off-axis, ink-bleed via SVG turbulence */
.stamp {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 9px;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transform: rotate(-2.4deg);
  filter: url(#stamp-bleed);
  opacity: 0.88;
  background: transparent;
}
.stamp::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
}
html[data-theme="dark"] .stamp { opacity: 0.92; }

/* Constellation patterns page */
.constellation {
  position: relative;
  width: 100%;
  max-width: 920px;
  margin: 32px auto 0;
  aspect-ratio: 16 / 11;
  background: var(--paper-2);
  border: var(--hairline);
  border-radius: var(--r-md);
  overflow: hidden;
}
.constellation svg { width: 100%; height: 100%; display: block; }
.constellation .c-edge { stroke: var(--rule-2); stroke-width: 0.6; transition: stroke var(--dur) var(--ease), stroke-width var(--dur) var(--ease); }
.constellation .c-edge--hot { stroke: var(--accent); stroke-width: 1.2; }
.constellation .c-star { fill: var(--ink); transition: fill var(--dur) var(--ease), r var(--dur) var(--ease); cursor: pointer; }
.constellation .c-star:hover { fill: var(--accent); }
.constellation .c-star--hot { fill: var(--accent); }
.constellation .c-pattern { fill: var(--ink); font-family: var(--font-serif); font-size: 13px; font-weight: 500; letter-spacing: -0.01em; cursor: pointer; }
.constellation .c-pattern:hover { fill: var(--accent); }
.constellation .c-pattern--hot { fill: var(--accent); }
.constellation .c-count { fill: var(--ink-3); font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.04em; }
.constellation .c-tooltip {
  position: absolute;
  background: var(--card);
  border: var(--hairline);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--ink);
  max-width: 260px;
  pointer-events: none;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.constellation .c-tooltip--on { opacity: 1; transform: translateY(0); }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ===== Semantic primitives ===== */
.serif { font-family: var(--font-serif); font-weight: 500; letter-spacing: var(--tracking-tight); }
.mono  { font-family: var(--font-mono); }
.eyebrow {
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow);
  color: var(--ink-3);
  font-weight: 500;
}
.section-h {
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow);
  font-weight: 500;
  color: var(--ink-3);
  margin: 2rem 0 0.5rem;
}
.muted { color: var(--ink-3); }
.rule  { border: 0; border-top: var(--hairline); margin: 2rem 0; }
.tag {
  display: inline-block;
  font-size: var(--fs-micro);
  padding: 3px 8px;
  background: var(--tag-bg);
  color: var(--tag-fg);
  border-radius: var(--r-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.tag--warn { background: var(--tag-warn-bg); color: var(--tag-warn-fg); }
.tag--cool { background: var(--tag-cool-bg); color: var(--tag-cool-fg); }

/* Editorial link with thin underline */
.link {
  border-bottom: 1px solid var(--rule-2);
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.link:hover { border-bottom-color: var(--ink); }
.link--accent { border-bottom-color: var(--accent); }
.link--accent:hover { color: var(--accent); }

/* "Live" pulse used in nav */
.dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}
.dot--pulse {
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.85); }
}

/* Buttons (used sparingly) */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--paper);
  font-size: var(--fs-meta);
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { background: #2c2620; }
.btn:active { transform: translateY(0.5px); }
.btn--ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule-2);
}
.btn--ghost:hover { background: var(--paper-2); border-color: var(--ink-3); }

/* Code block */
.code {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  background: var(--paper-2);
  border-left: 2px solid var(--rule-2);
  padding: 14px 16px;
  border-radius: var(--r-sm);
  color: var(--ink);
  line-height: 1.6;
  white-space: pre-wrap;
  margin: 0.75rem 0 1.25rem;
  overflow-x: auto;
}

/* Toggle button (header) */
.toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  min-width: 28px;
  padding: 0 8px;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--rule);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  cursor: pointer;
}
.toggle:hover { background: var(--paper-2); color: var(--ink); border-color: var(--rule-2); }
.toggle svg { width: 14px; height: 14px; }

/* Smooth theme transition */
html { transition: background-color var(--dur) var(--ease); }
body { transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease); }

/* Layout helpers */
.page { max-width: var(--measure-wide); margin: 0 auto; padding: 0 var(--page-pad-x); }
.prose { max-width: var(--measure); margin: 0 auto; padding: 0 var(--page-pad-x); }

/* Selection */
::selection { background: var(--accent); color: var(--paper); }

/* Focus */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Severity / frequency / verified badges (per-note metadata strip) */
.meta-strip {
  display: flex; flex-wrap: wrap; gap: 14px 22px;
  padding: 14px 18px; margin: 0 0 28px;
  background: var(--paper-2); border: var(--hairline);
  border-radius: var(--r-sm);
  font-size: var(--fs-small); color: var(--ink-2);
}
.meta-strip dt {
  font-size: var(--fs-micro); text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow); color: var(--ink-3);
  font-weight: 500; margin-bottom: 2px;
}
.meta-strip dd { margin: 0; color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.meta-strip .sev { display: inline-flex; align-items: center; gap: 6px; }
.meta-strip .sev::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--rule-2);
}
.meta-strip .sev--silent::before      { background: #b8a169; }
.meta-strip .sev--loud::before        { background: var(--accent); }
.meta-strip .sev--catastrophic::before{ background: #b9532b; box-shadow: 0 0 0 3px rgba(185,83,43,0.18); }

/* Eval-spec download button slot */
.note-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding-top: 16px; margin-top: 24px;
  border-top: var(--hairline);
}

/* Reproduce-block actions row (eval-spec download) */
.repro-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin: -4px 0 22px;
}
.btn--sm { padding: 6px 11px; font-size: var(--fs-micro); }

/* Pattern index page */
.pattern-list { display: grid; gap: 28px; max-width: var(--measure); margin: 0 auto; padding: 0 var(--page-pad-x); }
.pattern-group {
  border-top: var(--hairline);
  padding-top: 22px;
}
.pattern-group h2 {
  font-family: var(--font-serif);
  font-size: 24px; font-weight: 500; letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.pattern-group .pattern-meta {
  font-size: var(--fs-small); color: var(--ink-3);
  margin: 0 0 12px;
}
.pattern-group .pattern-desc {
  font-family: var(--font-serif); font-size: 16px; line-height: 1.65;
  color: var(--ink-2);
  margin: 0 0 14px;
}
.pattern-group ol {
  list-style: decimal; padding-left: 24px;
  font-size: var(--fs-meta); color: var(--ink-2);
  display: grid; gap: 6px;
}
.pattern-group ol a { color: var(--ink); }
.pattern-group ol a:hover { color: var(--accent); }
.pattern-group .sev-tag {
  display: inline-block; font-size: 11px; padding: 1px 6px;
  margin-left: 6px; border-radius: 3px;
  background: var(--paper-2); color: var(--ink-3);
  text-transform: uppercase; letter-spacing: 0.06em;
}

/* Print: editorial PDF, no chrome, code blocks unbroken across pages */
@media print {
  :root {
    --paper: #ffffff; --paper-2: #f6f4ee; --paper-3: #ece8de;
    --card: #ffffff; --ink: #111; --ink-2: #333; --ink-3: #555;
    --rule: #cfc8b8; --rule-2: #b6ad97;
  }
  html, body { background: #fff; color: #111; }
  header, footer, nav, .toggle, .note-actions { display: none !important; }
  .page, .prose { max-width: none; padding: 0 24mm; }
  .code, pre, blockquote, figure, table { page-break-inside: avoid; break-inside: avoid; }
  h1, h2, h3, h4, .serif { page-break-after: avoid; break-after: avoid-page; }
  .meta-strip { background: #fff; border: 1px solid #ccc; }
  a { color: #111; border-bottom: 0; }
  a[href^="http"]:after { content: " (" attr(href) ")"; font-size: 10pt; color: #666; }
  @page { margin: 18mm 16mm; }
}

/* ===== Ink-bleed entry — JS adds .ink-bleed--in on mount; we transition into the visible state.
   No CSS animation: avoids stuck-currentTime issues in iframes / background tabs. Initial state is
   the start-of-bleed (small mask), end state is fully revealed. If JS doesn't run, .ink-bleed--in
   is never added, but we also expose .ink-bleed--ready as a no-JS fallback. */
.ink-bleed {
  opacity: 0;
  -webkit-mask-image: radial-gradient(ellipse at 30% 18%, #000 35%, rgba(0,0,0,0.65) 60%, transparent 78%);
          mask-image: radial-gradient(ellipse at 30% 18%, #000 35%, rgba(0,0,0,0.65) 60%, transparent 78%);
  -webkit-mask-repeat: no-repeat;
          mask-repeat: no-repeat;
  -webkit-mask-position: center;
          mask-position: center;
  -webkit-mask-size: 0% 0%;
          mask-size: 0% 0%;
  transform: translateY(8px);
  transition:
    opacity 600ms cubic-bezier(0.22, 0.61, 0.36, 1),
    mask-size 720ms cubic-bezier(0.22, 0.61, 0.36, 1),
    -webkit-mask-size 720ms cubic-bezier(0.22, 0.61, 0.36, 1),
    transform 720ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.ink-bleed--in {
  opacity: 1;
  -webkit-mask-size: 280% 280%;
          mask-size: 280% 280%;
  transform: translateY(0);
}
/* No-JS fallback: if .ink-bleed--in never lands, after 1.2s we still want it visible. */
@keyframes inkbleed-fallback { to { opacity: 1; -webkit-mask-size: 280% 280%; mask-size: 280% 280%; transform: translateY(0); } }
.ink-bleed { animation: inkbleed-fallback 0s 1.5s forwards; }

/* ===== Marginalia — handwritten asides anchored next to a section. */
.marginalia {
  font-family: var(--font-hand);
  font-size: 19px;
  line-height: 1.25;
  color: var(--accent);
  opacity: 0.82;
  display: block;
  margin: 4px 0 14px;
  padding: 4px 12px;
  border-left: 1.5px solid var(--accent);
  font-weight: 500;
  letter-spacing: 0.005em;
  transform: rotate(-0.6deg);
  max-width: 380px;
}
.marginalia::before {
  content: "—\00a0";
  opacity: 0.7;
}

/* ===== Dot-grid background — drifts slowly behind the homepage hero. */
.dotgrid {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}
.dotgrid::before {
  content: "";
  position: absolute;
  inset: -40px;
  z-index: 0;
  background-image: radial-gradient(currentColor 1px, transparent 1.2px);
  background-size: 22px 22px;
  color: var(--rule-2);
  opacity: 0.45;
  -webkit-mask-image: radial-gradient(ellipse at 25% 35%, #000 0%, transparent 75%);
          mask-image: radial-gradient(ellipse at 25% 35%, #000 0%, transparent 75%);
  animation: dotgrid-drift 80s linear infinite;
  pointer-events: none;
}
.dotgrid > * { position: relative; z-index: 1; }
@keyframes dotgrid-drift {
  0%   { background-position: 0 0; }
  100% { background-position: 220px 88px; }
}

/* ===== 404 — misfiled-note styling */
.misfile-stamp {
  position: absolute;
  top: 24px; right: 24px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transform: rotate(6deg);
  filter: url(#stamp-bleed);
  opacity: 0.86;
  background: transparent;
  pointer-events: none;
}
.misfile-stamp::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  border: 2px solid currentColor;
}
.nf-shell { position: relative; }

/* Reduced motion: kill non-essential transitions for users who opt out */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Skip-to-content link — visible on focus for keyboard users */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; z-index: 9999;
  font-family: var(--font-sans); font-size: 14px;
  border-radius: 0 0 6px 0;
}
.skip-link:focus { left: 0; }

/* Min tap targets — touch screens */
@media (hover: none) and (pointer: coarse) {
  .btn, .toggle button, a.link, nav a {
    min-height: 44px;
  }
}

/* Mobile tightening — prose padding, header collapse, code overflow */
@media (max-width: 640px) {
  .prose { padding-left: 18px; padding-right: 18px; }
  .meta-strip { grid-template-columns: 1fr 1fr !important; }
  pre, .code { font-size: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  h1.serif { font-size: 28px !important; line-height: 1.18 !important; }
  .pattern-group h2 { font-size: 20px; }
}

/* Forced-colors / Windows high contrast — preserve focus + borders */
@media (forced-colors: active) {
  :focus-visible { outline: 3px solid CanvasText; }
  .btn, .meta-strip, .code, pre { border: 1px solid CanvasText; }
}

