/* ============================================================================
 * bienphiendoan - site design system (single source of truth)
 * Spec: notes/260608-design-system-spec.md
 * Influence: the "Toan Ngo PhD Thesis" reader style (serif reading face,
 * generous measure, small-caps labels, three ink levels, soft rules), recast
 * in the Bien Phien Doan brand red on a warm paper neutral.
 *
 * Rule: pages MUST consume these tokens and components. A page's own <style>
 * is only for genuinely page-specific layout (e.g. the methodology graph).
 * ========================================================================== */

/* ---- 1. Tokens ---------------------------------------------------------- */
:root {
  color-scheme: light dark;

  /* ink (3 levels) */
  --fg: #211c15;
  --muted: #6b6356;
  --faint: #968c7c;

  /* surfaces (warm paper) */
  --bg: #fcfbf7;
  --surface: #f5f1e8;
  --surface-2: #ede7d9;

  /* lines */
  --border: #e7dfce;
  --border-soft: #efe9dc;

  /* brand accent (Bien Phien Doan red) */
  --accent: #c1271d;
  --accent-strong: #97160f;
  --accent-fg: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 9%, transparent);
  /* aliases consumed by tool/graph pages */
  --tool-accent: var(--accent);
  --tool-accent-2: #df6b2c;

  /* fonts */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* type scale */
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-ui: 0.9375rem;
  --text-base: 1rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.9rem;
  --display: clamp(2.1rem, 1.35rem + 3vw, 3.1rem);
  --leading: 1.65;
  --leading-tight: 1.14;

  /* layout widths */
  --measure: 38rem;   /* reading column */
  --content: 64rem;   /* default page column */
  --page-max: 72rem;  /* wide pages */

  /* spacing scale */
  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem;
  --sp-5: 1.5rem; --sp-6: 2rem; --sp-7: 3rem; --sp-8: 4rem; --sp-9: 6rem;

  /* radii + elevation */
  --r-sm: 7px; --r-md: 11px; --r-lg: 16px; --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(33,28,21,0.05), 0 6px 18px -10px rgba(33,28,21,0.20);
  --shadow-2: 0 14px 40px -16px rgba(33,28,21,0.34);

  /* motion */
  --ease: 150ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #ece6d8; --muted: #ada393; --faint: #7e7464;
    --bg: #14110c; --surface: #1c1812; --surface-2: #241f17;
    --border: #332c21; --border-soft: #2a241b;
    --accent: #e7564a; --accent-strong: #f2705f; --accent-fg: #1b0d0a;
    --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
    --tool-accent-2: #ef8a4a;
    --shadow-1: 0 1px 2px rgba(0,0,0,0.45), 0 8px 22px -12px rgba(0,0,0,0.65);
    --shadow-2: 0 16px 44px -16px rgba(0,0,0,0.72);
  }
}

/* ---- 2. Base ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }
img { max-width: 100%; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-7) 0; }

/* headings use the serif display face */
h1, h2, h3, h4 { font-family: var(--font-serif); color: var(--fg); line-height: var(--leading-tight); letter-spacing: -0.012em; font-weight: 600; margin: 0 0 var(--sp-4); }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.92em; }

/* ---- 3. Layout --------------------------------------------------------- */
main { max-width: var(--content); margin: 0 auto; padding: var(--sp-8) var(--sp-5) var(--sp-9); }
main.wide { max-width: var(--page-max); }
.reading { max-width: var(--measure); }

/* ---- 4. Top bar -------------------------------------------------------- */
header.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--page-max); margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex; align-items: center; gap: 1.5rem;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font-weight: 700; font-size: var(--text-md); letter-spacing: -0.01em;
  color: var(--fg); white-space: nowrap; text-decoration: none;
}
.brand:hover { color: var(--fg); }
.brand .brand-logo { width: 30px; height: 30px; border-radius: 7px; display: block;
  box-shadow: 0 2px 8px -3px color-mix(in srgb, var(--accent) 65%, transparent); }
nav.primary { display: flex; gap: 1.25rem; flex: 1; }
nav.primary a {
  font-size: var(--text-ui); color: var(--muted);
  padding: 0.3rem 0; border-bottom: 1.5px solid transparent;
  transition: color var(--ease), border-color var(--ease);
}
nav.primary a:hover, nav.primary a:focus-visible, nav.primary a[aria-current="page"] {
  color: var(--fg); border-bottom-color: var(--accent); outline: none;
}
.auth { display: flex; gap: 0.5rem; align-items: center; }

/* ---- 5. Buttons -------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-family: var(--font-sans); font-size: var(--text-ui); font-weight: 550;
  padding: 0.48rem 0.95rem; border-radius: var(--r-sm);
  border: 1px solid var(--border); color: var(--fg); background: transparent;
  cursor: pointer; text-decoration: none; transition: background var(--ease), border-color var(--ease), color var(--ease), transform var(--ease);
}
.btn:hover, .btn:focus-visible { background: var(--surface); border-color: var(--muted); outline: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover, .btn.primary:focus-visible { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-fg); }

/* ---- 6. Editorial pieces ----------------------------------------------- */
.eyebrow {
  font-family: var(--font-sans); font-size: var(--text-xs); font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent);
  margin: 0 0 var(--sp-3);
}
.hero { margin: 0 0 var(--sp-8); }
.hero h1 { font-size: var(--display); letter-spacing: -0.025em; margin: 0 0 var(--sp-4); }
.hero .lede, .lede {
  font-family: var(--font-serif); font-size: var(--text-lg);
  color: var(--muted); line-height: 1.5; max-width: var(--measure); margin: 0;
}
h2.section, .section-label {
  font-family: var(--font-sans); font-size: var(--text-xs); font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 var(--sp-4); display: flex; align-items: center; gap: 0.6rem;
}
h2.section::before, .section-label::before {
  content: ""; width: 1.5rem; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--tool-accent-2));
}

/* reading prose (serif, measured) */
.prose { font-family: var(--font-serif); max-width: var(--measure); font-size: var(--text-md); color: var(--fg); }
.prose > * + * { margin-top: var(--sp-5); }
.prose p { margin: 0; }
.prose p.lede { font-size: var(--text-lg); color: var(--muted); }
.prose h2 {
  font-family: var(--font-sans); font-size: var(--text-xs); font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  margin: var(--sp-7) 0 0;
}
.prose h2 + p { margin-top: var(--sp-3); }
.prose a { border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.prose a:hover { border-bottom-color: var(--accent); }
.prose blockquote {
  margin: var(--sp-5) 0; padding: 0.2rem 0 0.2rem 1.1rem;
  border-left: 3px solid var(--border); color: var(--muted); font-style: italic;
}

/* ---- 7. Surfaces: card / pill / notice / form -------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-5); transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}
.card.interactive:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: var(--shadow-2); }

.pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: var(--text-sm); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-pill);
  padding: 0.32rem 0.8rem; background: var(--surface);
}
.pill b { color: var(--accent); font-weight: 700; }

.notice {
  padding: 0.85rem 1rem; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: var(--text-sm); color: var(--fg);
}

.form { display: grid; gap: var(--sp-4); }
.field { display: block; }
.field > span { display: block; font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--sp-1); }
.field input, .field textarea, .field select {
  width: 100%; font: inherit; font-size: var(--text-ui);
  padding: 0.55rem 0.7rem; color: var(--fg); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--r-sm); transition: border-color var(--ease);
}
.field input:focus-visible, .field textarea:focus-visible { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- 8. Footer --------------------------------------------------------- */
footer.site {
  max-width: var(--page-max); margin: var(--sp-9) auto 0;
  padding: var(--sp-5) var(--sp-5) var(--sp-6);
  border-top: 1px solid var(--border);
  color: var(--faint); font-size: var(--text-sm);
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
footer.site a { color: var(--faint); }
footer.site a:hover { color: var(--fg); }

/* ---- 9. Small utilities ------------------------------------------------ */
.muted { color: var(--muted); }
.center { text-align: center; }

@media (max-width: 560px) {
  .topbar-inner { flex-wrap: wrap; gap: 0.7rem 1rem; padding: 0.65rem 1rem; }
  nav.primary { order: 3; width: 100%; gap: 1rem; }
  main { padding: var(--sp-6) var(--sp-4) var(--sp-8); }
}
