/* ============================================================
   base.css — design tokens, reset, typography, page layout
   ============================================================ */

:root {
  /* --- Palette -------------------------------------------------
     Drawn from metallurgy: annealed steel blues, a copper accent,
     a paper-white page. Deliberately quiet — the content carries
     the page, not the colours.                                  */
  --steel-900: #0e1a26;
  --steel-800: #16273a;
  --steel-700: #1e3855;
  --steel-600: #2b4d71;
  --steel-500: #3f6289;
  --steel-400: #6b8bab;
  --steel-200: #c3d1de;
  --steel-100: #e3eaf1;

  --copper-700: #8a4a20;
  --copper-600: #a85c28;
  --copper-500: #c07038;
  --copper-200: #f0d9c6;
  --copper-050: #fbf3ec;

  /* Surfaces */
  --page:      #ffffff;
  --surface:   #f7f9fb;
  --surface-2: #eef2f6;
  --line:      #ccd6e0;      /* stronger than the old #e2e8ef */
  --line-soft: #dde5ed;
  --line-bold: #a9bacb;      /* for edges that should read as structure */

  /* Border weights — raise these two to make every edge heavier. */
  --bw:      1.5px;
  --bw-bold: 2px;

  /* Text */
  --ink:       #16202b;
  --ink-2:     #43566b;
  --ink-3:     #6f8298;
  --ink-4:     #93a3b5;

  /* Semantic */
  --ok:    #0f7a52;
  --warn:  #a66a00;
  --error: #b32d2d;

  /* Type */
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:  'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Space + shape */
  --sidebar-w: 268px;
  --content-w: 780px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  /* Shadow — used sparingly, only for things that genuinely float */
  --shadow-1: 0 1px 2px rgba(16, 32, 48, .06);
  --shadow-2: 0 4px 16px rgba(16, 32, 48, .08);
  --shadow-3: 0 18px 48px rgba(16, 32, 48, .16);

  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* --- Dark theme ------------------------------------------------ */
[data-theme="dark"] {
  --page:      #0d141c;
  --surface:   #121b25;
  --surface-2: #18222e;
  --line:      #2c3e52;
  --line-soft: #243343;
  --line-bold: #3d5570;

  --ink:   #e4ecf4;
  --ink-2: #a8bacd;
  --ink-3: #7b8ea4;
  --ink-4: #5d7089;

  --steel-100: #1a2633;
  --steel-200: #2a3b4d;
  --copper-500: #d08850;
  --copper-600: #c07038;
  --copper-050: #1d1711;
  --copper-200: #3b2a1c;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-3: 0 18px 48px rgba(0, 0, 0, .55);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.72;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background .3s var(--ease), color .3s var(--ease);
}

img { max-width: 100%; display: block; }
a   { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }

::selection { background: var(--copper-200); color: var(--steel-900); }

:focus-visible {
  outline: 2px solid var(--copper-500);
  outline-offset: 2px;
  border-radius: 3px;
}

/* --- Typography ------------------------------------------------ */
h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -.011em;
  color: var(--ink);
}
h4, h5, h6 { font-family: var(--font-sans); font-weight: 600; line-height: 1.35; }

p { margin-bottom: 1em; }
p:last-child { margin-bottom: 0; }
strong { font-weight: 600; color: var(--ink); }

.mono {
  font-family: var(--font-mono);
  font-size: .78em;
  letter-spacing: .01em;
}

/* --- Skip link ------------------------------------------------- */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 10000;
  background: var(--steel-800); color: #fff;
  padding: 10px 18px; border-radius: 0 0 var(--r-sm) 0;
}
.skip-link:focus { left: 0; }

/* ============================================================
   PAGE LAYOUT — fixed sidebar + single flowing column
   ============================================================ */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* --- Sidebar --------------------------------------------------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: var(--bw) solid var(--line);
  padding: 34px 22px 20px;
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 40;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--steel-200); border-radius: 4px; }

.side-identity {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 15px;
}

/* The one profile picture on the site. */
.side-photo-wrap {
  position: relative;
  width: 116px; height: 116px;
  flex-shrink: 0;
}
.side-photo-wrap::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: var(--bw) solid var(--line);
  transition: border-color .3s var(--ease), transform .4s var(--ease);
}
.side-photo-wrap:hover::after {
  border-color: var(--copper-200);
  transform: scale(1.04);
}
.side-photo {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 22%;
  border: 3px solid var(--page);
  box-shadow: var(--shadow-2);
  background: var(--surface-2);
}

.side-name {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.012em;
}
.side-role {
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.5;
  margin-top: 5px;
}
.side-org {
  display: inline-flex; align-items: center; gap: 6px;
  justify-content: center;
  margin-top: 10px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--copper-600);
}
.side-org img { height: 17px; width: auto; opacity: .9; }

/* Nav */
.side-nav {
  margin-top: 26px;
  padding-top: 22px;
  border-top: var(--bw) solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}
.side-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 7px 11px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 450;
  color: var(--ink-2);
  position: relative;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.side-link i {
  width: 15px;
  font-size: 12.5px;
  text-align: center;
  color: var(--ink-4);
  transition: color .16s var(--ease);
}
.side-link:hover { background: var(--surface-2); color: var(--ink); }
.side-link:hover i { color: var(--copper-500); }
.side-link.active {
  background: var(--page);
  color: var(--ink);
  font-weight: 550;
  box-shadow: var(--shadow-1);
}
.side-link::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  width: 3px; height: 0;
  border-radius: 3px;
  background: var(--copper-500);
  transform: translateY(-50%);
  transition: height .26s var(--ease);
}
.side-link.active::before { height: 19px; }
.side-link.active i { color: var(--copper-600); }
.side-link.is-hidden-section { opacity: .38; }

/* Sidebar footer */
.side-foot {
  margin-top: 18px;
  padding-top: 16px;
  border-top: var(--bw) solid var(--line);
}
.side-socials { display: flex; gap: 7px; margin-bottom: 14px; flex-wrap: wrap; }
.side-socials a {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: var(--bw) solid var(--line);
  border-radius: 50%;
  font-size: 12px;
  color: var(--ink-3);
  background: var(--page);
  transition: all .18s var(--ease);
}
.side-socials a:hover {
  color: var(--copper-600);
  border-color: var(--copper-200);
  background: var(--copper-050);
  transform: translateY(-1px);
}
.side-meta { font-size: 10.5px; color: var(--ink-4); line-height: 1.6; }

.theme-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 8px 11px;
  margin-bottom: 12px;
  border: var(--bw) solid var(--line);
  border-radius: var(--r-sm);
  background: var(--page);
  font-size: 12.5px;
  color: var(--ink-2);
  transition: all .18s var(--ease);
}
.theme-btn:hover { border-color: var(--steel-200); color: var(--ink); }
.theme-btn i { font-size: 11.5px; color: var(--ink-4); }

/* --- Mobile top bar (hidden on desktop) ------------------------ */
.topbar { display: none; }

/* --- Main column ----------------------------------------------- */
.main { min-width: 0; position: relative; }
.wrap { width: 100%; max-width: var(--content-w); margin: 0 auto; padding: 0 40px; }

/* Reading-progress hairline */
#progress-line {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--copper-500);
  z-index: 200;
  transition: width .08s linear;
}

/* ============================================================
   SECTIONS — continuous flow, separated by rules, not boxes
   ============================================================ */
.section {
  padding: 62px 0;
  border-top: var(--bw) solid var(--line-soft);
  scroll-margin-top: 20px;
}
/* Only the hero sits flush against the top — every other section
   is introduced by its hairline rule. */
.hero { border-top: none; }
.section.is-hidden { display: none; }

/* Section heading: small label + serif title */
.sec-head { margin-bottom: 30px; }
.sec-label {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--copper-600);
  margin-bottom: 9px;
}
.sec-title {
  font-size: clamp(25px, 3.4vw, 31px);
  font-weight: 600;
}
.sec-sub {
  margin-top: 9px;
  font-size: 14.5px;
  color: var(--ink-3);
  max-width: 58ch;
}

/* Subsection inside a section */
.sub { margin-top: 42px; }
.sub:first-of-type { margin-top: 0; }
.sub-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 9px;
  border-bottom: var(--bw) solid var(--line);
}
.sub-title {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink);
}
.sub-title i { font-size: 11.5px; color: var(--copper-500); }
.sub-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-4);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1000px) {
  /* minmax(0,1fr) — a bare 1fr lets a wide child stretch the track
     past the viewport, which is what caused sideways scrolling. */
  .layout { grid-template-columns: minmax(0, 1fr); }

  .sidebar { display: none; }

  .topbar {
    display: block;
    min-width: 0;
    position: sticky; top: 0; z-index: 60;
    background: color-mix(in srgb, var(--page) 88%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: var(--bw) solid var(--line);
  }
  .topbar-row {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 20px;
  }
  .topbar-photo {
    width: 34px; height: 34px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center 22%;
    border: 2px solid var(--page);
    box-shadow: var(--shadow-2);
    background: var(--surface-2);
    flex-shrink: 0;
  }
  .topbar-name {
    font-family: var(--font-serif);
    font-size: 16px; font-weight: 600;
    flex: 1; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-btn {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border: var(--bw) solid var(--line);
    border-radius: var(--r-sm);
    color: var(--ink-2);
    font-size: 13px;
    background: var(--page);
  }
  .topbar-scroll {
    display: flex; gap: 2px;
    padding: 0 14px 9px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .topbar-scroll::-webkit-scrollbar { display: none; }
  .topbar-scroll .side-link {
    flex-shrink: 0;
    padding: 5px 11px;
    font-size: 12.5px;
    white-space: nowrap;
  }
  .topbar-scroll .side-link i { display: none; }
  .topbar-scroll .side-link.active {
    background: var(--surface-2);
    box-shadow: none;
  }

  .wrap { padding: 0 22px; }
  .section { padding: 46px 0; }
}

@media (max-width: 560px) {
  body { font-size: 15px; }
  .wrap { padding: 0 18px; }
  .section { padding: 38px 0; }
}

@media print {
  .sidebar, .topbar, #progress-line, .reader-overlay, .modal-overlay,
  .toast-wrap, .btn, .show-more { display: none !important; }
  /* minmax(0,1fr) — a bare 1fr lets a wide child stretch the track
     past the viewport, which is what caused sideways scrolling. */
  .layout { grid-template-columns: minmax(0, 1fr); }
  .section { padding: 18px 0; break-inside: avoid; }
}

/* Anyone who has asked their system to reduce motion gets the finished
   layout with no movement at all — including the hero entrance, which
   must not leave elements stuck at opacity 0. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .anim, .reveal, .reveal-child {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }
  /* The wipe clips the text, so it must be released explicitly or the
     line would stay invisible. */
  .wipe { clip-path: none !important; }
  .wipe::after { display: none !important; }
  /* A looping rotation is exactly what this setting asks us to stop.
     config.js → profile.alwaysRotate: true opts back in. */
  #rotating-image:not(.always-rotate) { animation: none !important; }
}
