/* Reset + base typography + accessibility primitives. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-200);
  line-height: 1.6;
  color: var(--text-secondary);
  background: var(--background-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color var(--dur-base) var(--ease-standard),
    color var(--dur-base) var(--ease-standard);
}

/* ============================================================
   Architectural draftsman background (site-wide)
   - body::before = paper grid + dimension dots
   - body::after  = scattered architectural motifs (SVG)
   Both are fixed, behind content, theme-aware,
   and respect prefers-reduced-motion.
   ============================================================ */

body::before,
body::after {
  content: '';
  position: fixed;
  pointer-events: none;
}

body::before {
  inset: 0;
  z-index: -2;
  background-image:
    radial-gradient(circle, rgba(10,59,117,0.12) 1px, transparent 1.6px),
    linear-gradient(90deg, rgba(10,59,117,0.05) 1px, transparent 1px),
    linear-gradient(rgba(10,59,117,0.05) 1px, transparent 1px);
  background-size: 40px 40px, 40px 40px, 40px 40px;
  background-position: 0 0;
}

body::after {
  inset: -80px;
  z-index: -1;
  opacity: 0.85;
  background-repeat: repeat;
  background-size: 1600px 1200px;
  background-position: center;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1200' width='1600' height='1200'><g fill='none' stroke='rgba(10,59,117,0.22)' stroke-width='1.4' stroke-linejoin='round'><g transform='translate(80,90)'><path d='M0 60 L80 20 L160 60 L160 160 L80 200 L0 160 Z'/><path d='M0 60 L80 100 L160 60'/><path d='M80 100 L80 200'/><rect x='15' y='80' width='18' height='18'/><rect x='45' y='80' width='18' height='18'/><rect x='95' y='80' width='18' height='18'/><rect x='125' y='80' width='18' height='18'/><rect x='15' y='110' width='18' height='18'/><rect x='45' y='110' width='18' height='18'/></g><g transform='translate(1180,120)'><rect x='0' y='0' width='280' height='200'/><line x1='160' y1='0' x2='160' y2='110'/><path d='M120 110 A40 40 0 0 1 160 70'/><line x1='120' y1='110' x2='160' y2='110'/><rect x='20' y='20' width='60' height='30'/></g><g transform='translate(750,500)'><circle cx='0' cy='0' r='50'/><circle cx='0' cy='0' r='35'/><line x1='0' y1='-50' x2='0' y2='50'/><line x1='-50' y1='0' x2='50' y2='0'/><polygon points='0,-50 -8,-25 0,-30 8,-25' fill='rgba(10,59,117,0.22)'/><polygon points='0,50 -8,25 0,30 8,25' fill='rgba(10,59,117,0.22)'/></g><g transform='translate(150,950)'><line x1='0' y1='0' x2='320' y2='0'/><line x1='0' y1='-10' x2='0' y2='10'/><line x1='320' y1='-10' x2='320' y2='10'/><polygon points='0,0 14,-5 14,5' fill='rgba(10,59,117,0.22)'/><polygon points='320,0 306,-5 306,5' fill='rgba(10,59,117,0.22)'/></g><g transform='translate(1450,520)'><line x1='0' y1='0' x2='0' y2='240'/><line x1='-10' y1='0' x2='10' y2='0'/><line x1='-10' y1='240' x2='10' y2='240'/><polygon points='0,0 -5,14 5,14' fill='rgba(10,59,117,0.22)'/><polygon points='0,240 -5,226 5,226' fill='rgba(10,59,117,0.22)'/></g><g transform='translate(1280,920)'><path d='M0 0 L100 0 L100 12 L56 12 L56 76 L100 76 L100 88 L0 88 L0 76 L44 76 L44 12 L0 12 Z'/></g><g transform='translate(220,500)'><path d='M0 70 L0 60 L20 60 L20 50 L40 50 L40 40 L60 40 L60 30 L80 30 L80 20 L100 20 L100 10 L120 10 L120 0 L140 0 L140 80 L0 80 Z'/></g><g transform='translate(1100,580)'><rect x='0' y='0' width='90' height='14'/><rect x='10' y='14' width='70' height='90'/><rect x='0' y='104' width='90' height='14'/><line x1='25' y1='14' x2='25' y2='104'/><line x1='45' y1='14' x2='45' y2='104'/><line x1='65' y1='14' x2='65' y2='104'/></g><g transform='translate(560,150)'><line x1='0' y1='0' x2='200' y2='0'/><line x1='0' y1='0' x2='100' y2='-60'/><line x1='100' y1='-60' x2='200' y2='0'/><line x1='40' y1='0' x2='100' y2='-60'/><line x1='80' y1='0' x2='100' y2='-60'/><line x1='120' y1='0' x2='100' y2='-60'/><line x1='160' y1='0' x2='100' y2='-60'/></g><g transform='translate(700,1050)'><path d='M0 80 L0 40 A60 60 0 0 1 120 40 L120 80'/><line x1='0' y1='80' x2='120' y2='80'/><line x1='0' y1='80' x2='0' y2='100'/><line x1='120' y1='80' x2='120' y2='100'/></g></g></svg>");
  will-change: transform;
  transform: translate3d(0,0,0);
  animation: arch-drift 60s ease-in-out infinite;
}

[data-theme='dark'] body::before {
  background-image:
    radial-gradient(circle, rgba(59,130,246,0.18) 1px, transparent 1.6px),
    linear-gradient(90deg, rgba(148,163,184,0.05) 1px, transparent 1px),
    linear-gradient(rgba(148,163,184,0.05) 1px, transparent 1px);
}

[data-theme='dark'] body::after {
  opacity: 0.7;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1200' width='1600' height='1200'><g fill='none' stroke='rgba(91,155,255,0.30)' stroke-width='1.4' stroke-linejoin='round'><g transform='translate(80,90)'><path d='M0 60 L80 20 L160 60 L160 160 L80 200 L0 160 Z'/><path d='M0 60 L80 100 L160 60'/><path d='M80 100 L80 200'/><rect x='15' y='80' width='18' height='18'/><rect x='45' y='80' width='18' height='18'/><rect x='95' y='80' width='18' height='18'/><rect x='125' y='80' width='18' height='18'/><rect x='15' y='110' width='18' height='18'/><rect x='45' y='110' width='18' height='18'/></g><g transform='translate(1180,120)'><rect x='0' y='0' width='280' height='200'/><line x1='160' y1='0' x2='160' y2='110'/><path d='M120 110 A40 40 0 0 1 160 70'/><line x1='120' y1='110' x2='160' y2='110'/><rect x='20' y='20' width='60' height='30'/></g><g transform='translate(750,500)'><circle cx='0' cy='0' r='50'/><circle cx='0' cy='0' r='35'/><line x1='0' y1='-50' x2='0' y2='50'/><line x1='-50' y1='0' x2='50' y2='0'/><polygon points='0,-50 -8,-25 0,-30 8,-25' fill='rgba(91,155,255,0.30)'/><polygon points='0,50 -8,25 0,30 8,25' fill='rgba(91,155,255,0.30)'/></g><g transform='translate(150,950)'><line x1='0' y1='0' x2='320' y2='0'/><line x1='0' y1='-10' x2='0' y2='10'/><line x1='320' y1='-10' x2='320' y2='10'/><polygon points='0,0 14,-5 14,5' fill='rgba(91,155,255,0.30)'/><polygon points='320,0 306,-5 306,5' fill='rgba(91,155,255,0.30)'/></g><g transform='translate(1450,520)'><line x1='0' y1='0' x2='0' y2='240'/><line x1='-10' y1='0' x2='10' y2='0'/><line x1='-10' y1='240' x2='10' y2='240'/><polygon points='0,0 -5,14 5,14' fill='rgba(91,155,255,0.30)'/><polygon points='0,240 -5,226 5,226' fill='rgba(91,155,255,0.30)'/></g><g transform='translate(1280,920)'><path d='M0 0 L100 0 L100 12 L56 12 L56 76 L100 76 L100 88 L0 88 L0 76 L44 76 L44 12 L0 12 Z'/></g><g transform='translate(220,500)'><path d='M0 70 L0 60 L20 60 L20 50 L40 50 L40 40 L60 40 L60 30 L80 30 L80 20 L100 20 L100 10 L120 10 L120 0 L140 0 L140 80 L0 80 Z'/></g><g transform='translate(1100,580)'><rect x='0' y='0' width='90' height='14'/><rect x='10' y='14' width='70' height='90'/><rect x='0' y='104' width='90' height='14'/><line x1='25' y1='14' x2='25' y2='104'/><line x1='45' y1='14' x2='45' y2='104'/><line x1='65' y1='14' x2='65' y2='104'/></g><g transform='translate(560,150)'><line x1='0' y1='0' x2='200' y2='0'/><line x1='0' y1='0' x2='100' y2='-60'/><line x1='100' y1='-60' x2='200' y2='0'/><line x1='40' y1='0' x2='100' y2='-60'/><line x1='80' y1='0' x2='100' y2='-60'/><line x1='120' y1='0' x2='100' y2='-60'/><line x1='160' y1='0' x2='100' y2='-60'/></g><g transform='translate(700,1050)'><path d='M0 80 L0 40 A60 60 0 0 1 120 40 L120 80'/><line x1='0' y1='80' x2='120' y2='80'/><line x1='0' y1='80' x2='0' y2='100'/><line x1='120' y1='80' x2='120' y2='100'/></g></g></svg>");
}

@keyframes arch-drift {
  0%, 100% { transform: translate3d(0, 0, 0); }
  25%      { transform: translate3d(-26px, -16px, 0); }
  50%      { transform: translate3d(-44px, 8px, 0); }
  75%      { transform: translate3d(-18px, 26px, 0); }
}

@media (prefers-reduced-motion: reduce) {
  body::after { animation: none !important; }
}

/* Animated theme transition (Chrome/Edge View Transitions API).
   Falls back gracefully elsewhere. */
@supports (view-transition-name: root) {
  html { view-transition-name: root; }

  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
  }

  /* Reveal the new theme from the toggle position */
  ::view-transition-new(root) {
    animation: theme-reveal 520ms var(--ease-emphatic) both;
  }
}

img,
svg,
video,
picture {
  display: block;
  max-width: 100%;
}

img,
video {
  height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-standard);
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 4px;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  color: var(--text-primary);
  line-height: 1.15;
  margin: 0 0 var(--space-4);
  letter-spacing: -0.01em;
  font-weight: 700;
}

h1 { font-size: var(--fs-700); }
h2 { font-size: var(--fs-600); }
h3 { font-size: var(--fs-500); }
h4 { font-size: var(--fs-400); }

p {
  margin: 0 0 var(--space-4);
}

ul, ol {
  margin: 0 0 var(--space-4);
  padding-left: 1.25rem;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-7) 0;
}

::selection {
  background: var(--accent);
  color: var(--text-on-accent);
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  background: var(--surface);
  color: var(--text-primary);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  z-index: 1000;
  transition: top var(--dur-base) var(--ease-emphatic);
}

.skip-link:focus {
  top: var(--space-4);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@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;
  }
}
