/* ════════════════════════════════════════════════════════════════════════════
   SHARED STYLES — Common across all pages
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Common Elements ──────────────────────────────────────────────────────── */
a {
  color: var(--doc-link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all var(--transition);
}

a:hover {
  border-bottom-color: var(--doc-link);
  background: var(--doc-link-bg);
}

/* ── Reset & Variables ─────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Light mode colors */
  --bg: #f7f5f1;
  --bg-raised: #efece6;
  --bg-terminal: #151512;
  --bg-code: #eae7e1;
  --text: #1a1917;
  --text-muted: #595752;
  /* Darkened from #706e69 */
  --text-faint: #7a7873;
  /* Darkened from #b0ada6 */
  --border: #dedad3;
  --border-strong: #c8c4bc;

  /* Terminal colors — always vivid; terminal bg is always dark (#151512) */
  --term-green: #72d980;
  --term-dim: #4a9456;
  --term-cmd: #c8c4bc;
  --term-link: #7ac4a2;
  --term-data: #90b8cc;
  --term-cursor: #72d980;
  --term-desc: rgba(200, 196, 188, 0.7);

  /* Fonts */
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Layout */
  --radius: 0.25rem;
  --border-w: 0.0625rem;
  --transition: 200ms ease;

  /* State colors */
  --bg-hover-green: rgba(45, 138, 61, 0.04);
  --color-success: #78b89c; /* Consolidated from grade-b */
  --color-warning-alt: #cf9a6f; /* Consolidated from grade-d */

  /* Semantic color tokens */
  --color-error: #cf6f6f;
  --color-warning: #cfb16f;
  --color-error-border: rgba(207, 111, 111, 0.3);
  --color-error-bg: rgba(207, 111, 111, 0.05);

  /* Animations */
  --anim-duration: 0.6s;
  --anim-ease: ease;
  --anim-reveal: var(--anim-duration) var(--anim-ease) forwards;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark mode colors */
    --bg: #111110;
    --bg-raised: #1b1a18;
    --bg-terminal: #0c0c0b;
    --bg-code: #1f1e1b;
    --text: #e6e3dc;
    --text-muted: #a8a59e;
    /* Adjusted for dark mode */
    --text-faint: #8a8884;
    /* Adjusted for dark mode */
    --border: #2a2926;
    --border-strong: #3d3c38;

    /* State colors */
    --bg-hover-green: rgba(114, 217, 128, 0.05);

  }
}

/* ── Base ──────────────────────────────────────────────────────────────────── */
html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9375rem;
  line-height: 1.6;
  font-weight: 300;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

/* Grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.45;
}

/* ── Navigation ────────────────────────────────────────────────────────────── */
body>nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000; /* Must exceed body::before grain overlay (9999) */
  background: var(--bg);
  border-bottom: var(--border-w) solid var(--border);
  transition: background var(--transition), border-color var(--transition);
  padding-top: env(safe-area-inset-top, 0px);
  /* isolation: isolate removed — translateZ(0) already creates a stacking
     context; having both confused Safari's compositor, allowing content to
     paint above the nav on iOS. */
}

.nav-inner a {
  border-bottom: none;
}

.nav-inner a:hover {
  background: var(--bg-raised);
}

.nav-inner {
  max-width: 53.75rem;
  margin: 0 auto;
  padding: 0 1.125rem;
  height: 3.375rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  opacity: 0.9;
  transition: opacity var(--transition);
}

.nav-logo:hover {
  opacity: 1;
}

.nav-logo span {
  color: var(--text-muted);
}

.nav-links {
  display: flex;
  gap: 0.125rem;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
  /* Hide scrollbar Firefox */
  -ms-overflow-style: none;
  /* Hide scrollbar IE/Edge */
}

.nav-links::-webkit-scrollbar {
  display: none;
  /* Hide scrollbar Chrome/Safari */
}

.nav-links a {
  font-family: var(--font-mono);
  font-size: 0.71875rem;
  font-weight: 400;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.3125rem 0.625rem;
  border-radius: var(--radius);
  letter-spacing: 0.02em;
  transition: color var(--transition), background var(--transition);
}

/* Removed to prevent hover box clipping */
/* .nav-links li:last-child a {
  padding-right: 0;
} */

.nav-links a:hover,
.nav-links a:focus:not(:focus-visible) {
  color: var(--text);
  background: var(--bg-raised);
  outline: none;
}

.nav-links a.active {
  color: var(--text);
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
main {
  padding-top: calc(3.375rem + env(safe-area-inset-top, 0px));
}

.container {
  max-width: 53.75rem;
  margin: 0 auto;
  padding: 0 1.125rem;
}

/* ── Shared Page Headers ───────────────────────────────────────────────────── */
.page-header {
  padding: 3rem 0 2.5rem;
  opacity: 0;
  animation: fadeUp var(--anim-reveal);
}

.page-header-center {
  text-align: center;
}

.page-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--term-green);
  margin-bottom: 0.875rem;
}

.page-eyebrow.muted {
  color: var(--text-faint);
}

.page-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 300;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 0.75rem;
}

.page-sub {
  font-size: 0.9375rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.page-sub-center {
  max-width: 30rem;
  margin: 0 auto;
}

/* ── Footer ────────────────────────────────────────────────────────────────── */
footer {
  border-top: var(--border-w) solid var(--border);
  padding: 1.5rem 0;
}

.footer-inner a {
  border-bottom: none;
}

.footer-inner a:hover {
  background: transparent;
}

.footer-inner {
  max-width: 53.75rem;
  margin: 0 auto;
  padding: 0 1.125rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.footer-left {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-faint);
  letter-spacing: 0.03em;
}

.footer-right {
  display: flex;
  gap: 1.125rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.footer-right a {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-faint);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-right a:hover,
.footer-right a:focus:not(:focus-visible) {
  color: var(--text-muted);
  outline: none;
}

/* ── Doc / Article accent colors (shared by /docs/ and /writes/) ───────────── */
:root {
  --doc-h1: #5c6b7a;
  --doc-h2: #6b5c7a;
  --doc-h3: #5a7a6b;
  --doc-link: #4a7a6b;
  --doc-link-bg: rgba(74, 122, 107, 0.08);
  --doc-code-text: #6b4a8a;
  --doc-code-bg: rgba(107, 74, 138, 0.08);
  --doc-blockquote: #7a6b5c;
  --doc-blockquote-border: #c4b8a8;
  --doc-table-hd: rgba(74, 122, 107, 0.12);
  --doc-bold: #3d3b37;
  --doc-h4: #7a6b5a;
  --doc-mark: rgba(180, 150, 80, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --doc-h1: #88a8c0;
    --doc-h2: #a888c0;
    --doc-h3: #88c0a8;
    --doc-link: #7ac4a2;
    --doc-link-bg: rgba(122, 196, 162, 0.1);
    --doc-code-text: #b898d8;
    --doc-code-bg: rgba(184, 152, 216, 0.1);
    --doc-blockquote: #b8a898;
    --doc-blockquote-border: #4a4540;
    --doc-table-hd: rgba(122, 196, 162, 0.1);
    --doc-bold: #d8d5ce;
    --doc-h4: #c0a888;
    --doc-mark: rgba(200, 170, 90, 0.2);
  }
}

/* ── Noscript fallback ─────────────────────────────────────────────────────── */
.noscript-msg {
  padding: 5rem 1.75rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.8;
}

/* ── Markdown Alerts ──────────────────────────────────────────────────────── */
.alert {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  border-radius: 0.375rem;
  border-left: 0.25rem solid var(--border);
  background: var(--bg-raised);
  font-size: 0.875rem;
}

.alert-title {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 0.375rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert-content {
  color: var(--text-muted);
  line-height: 1.6;
}

.alert-content p:last-child {
  margin-bottom: 0;
}

/* Alert Variants */
.alert-note {
  border-left-color: #5c6b7a;
}

.alert-tip {
  border-left-color: var(--term-green);
}

.alert-important {
  border-left-color: #6b5c7a;
}

.alert-warning {
  border-left-color: var(--color-warning);
}

.alert-caution {
  border-left-color: var(--color-error);
}

.alert-note .alert-title {
  color: #5c6b7a;
}

.alert-tip .alert-title {
  color: var(--term-green);
}

.alert-important .alert-title {
  color: #6b5c7a;
}

.alert-warning .alert-title {
  color: var(--color-warning);
}

.alert-caution .alert-title {
  color: var(--color-error);
}

@media (prefers-color-scheme: dark) {
  .alert-note {
    border-left-color: #88a8c0;
  }

  .alert-important {
    border-left-color: #a888c0;
  }

  .alert-note .alert-title {
    color: #88a8c0;
  }

  .alert-important .alert-title {
    color: #a888c0;
  }
}

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}


/* ── Utilities ────────────────────────────────────────────────────────────── */
.u-hidden {
  display: none;
}

.u-flex {
  display: flex;
}

.u-align-center {
  align-items: center;
}

.u-gap-8 {
  gap: 0.5rem;
}

.u-flex-1 {
  flex: 1;
}

.u-flex-2 {
  flex: 2;
}

.u-mt-8 {
  margin-top: 0.5rem;
}

.u-mt-16 {
  margin-top: 1rem;
}

.u-mt-24 {
  margin-top: 1.5rem;
}

.u-mb-8 {
  margin-bottom: 0.5rem;
}

.u-mb-24 {
  margin-bottom: 1.5rem;
}

.u-mono {
  font-family: var(--font-mono);
}

.u-faint {
  color: var(--text-faint);
}

.u-small {
  font-size: 0.6875rem;
}

.u-text-muted {
  color: var(--text-muted);
}

.u-text-center {
  text-align: center;
}

.u-text-dim {
  color: var(--term-dim);
}

.u-text-green {
  color: var(--term-green);
}

.u-text-error {
  color: var(--color-error);
}

.sr-only {
  position: absolute;
  width: 0.0625rem;
  height: 0.0625rem;
  padding: 0;
  margin: -0.0625rem;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 0.125rem solid var(--term-green);
  outline-offset: 0.25rem;
}

@media (max-width: 40rem) {
  .u-mobile-hidden {
    display: none !important;
  }
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 40rem) {
  .nav-inner {
    padding: 0 1rem;
    gap: 0.75rem;
  }

  .nav-links a {
    padding: 0.3125rem 0.375rem;
    white-space: nowrap;
  }
}

@media (max-width: 40rem) {
  .footer-inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1rem;
    padding-bottom: 1rem;
  }

  .footer-right {
    justify-content: center;
    gap: 0.75rem 1.25rem;
  }

  .page-header {
    padding: 2.75rem 0 1.75rem;
  }

  .page-title {
    font-size: 2.625rem;
  }

  .page-sub {
    font-size: 0.875rem;
    padding: 0 1rem;
  }
}