/* ============================================================
   main.css — Paul S. Lou
   Consolidated stylesheet with light / dark mode support.
   ============================================================ */

/* ===== 1. CSS Custom Properties ===== */
:root {
  /* Brand palette — ocean blue
     Primary   #0d6590  ≈ OKLCH(L50, C0.11, H212) — 6.1:1 on cream   vivid ocean teal
     Accent    #3a5a88  ≈ OKLCH(L41, C0.09, H242) — 6.7:1 on cream   clear blue-slate */
  --c-primary:      #0d6590;
  --c-accent:       #3a5a88;

  /* Surface colours — warm cream palette */
  --c-bg:           #f9f6f0;
  --c-bg-card:      #f0ebe3;
  --c-bg-input:     #fffefb;

  /* Text */
  --c-text:         #1e1b18;
  --c-text-muted:   #6b6258;

  /* Borders */
  --c-border:       #e0d9cf;

  /* Links */
  --c-link:         #3a5a88;
  --c-link-header:  #0d6590;

  /* Highlights — pale blue tint */
  --c-highlight:    #d8ecf6;
  --c-tag-bg:       rgba(13, 101, 144, 0.10);
  --c-tag-accent:   rgba(58, 90, 136, 0.11);

  /* Typography */
  --font-display: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --font-sans:    'Inter', system-ui, -apple-system, sans-serif;
  --font-body:    'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:    'Source Code Pro', SFMono-Regular, Consolas, monospace;

  /* Layout */
  --max-width:  740px;
  --px:         1.5rem;

  /* Motion */
  --dur:        120ms;
}

[data-theme="dark"] {
  /* Dark mode — deep navy / sky blue + soft lavender
     Primary sky blue   #6aacde  ≈ OKLCH(L69, C0.10, H222) — 7.5:1 on dark bg
     Accent lavender    #a090cc  ≈ OKLCH(L62, C0.08, H286) — 6.2:1 on dark bg
     No green anywhere — clean, academic night palette */
  --c-primary:     #6aacde;  /* clear sky blue   */
  --c-accent:      #a090cc;  /* muted lavender   */
  --c-bg:          #141820;  /* deep cool navy   */
  --c-bg-card:     #1c2030;
  --c-bg-input:    #222640;
  --c-text:        #d0d4e8;  /* slightly blue-white */
  --c-text-muted:  #6878a0;
  --c-border:      #242a3a;
  --c-link:        #a090cc;
  --c-link-header: #6aacde;
  --c-highlight:   rgba(106, 172, 222, 0.13);
  --c-tag-bg:      rgba(106, 172, 222, 0.10);
  --c-tag-accent:  rgba(160, 144, 204, 0.12);
}


/* ===== 2. Base / Reset ===== */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  /* Transition theme colours smoothly */
  transition: background-color 180ms ease, color 180ms ease;
}

body {
  margin: 0 auto;
  padding: 0 var(--px) 4rem;
  max-width: var(--max-width);
  font-family: var(--font-body);
  font-size: 1.0625rem; /* ~17px — slightly larger for readability */
  line-height: 1.72;
  color: var(--c-text);
  background-color: var(--c-bg);
  font-feature-settings: 'cv05' 1; /* Inter: open 'a' variant */
}

img { max-width: 100%; height: auto; display: block; }

/* ===== 3. Typography ===== */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  line-height: 1.3;
  margin-top: 0;
  color: var(--c-primary);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }

p { margin-top: 0; }

a {
  color: var(--c-link);
  text-decoration: none;
  transition: color var(--dur) ease, opacity var(--dur) ease;
}
a:hover {
  color: var(--c-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ===== 4. Header / Nav ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--c-bg);
  padding: 1.1rem 0 0.9rem;
  border-top: 3px solid var(--c-primary);
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 2.5rem;
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1.1rem;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.site-nav__link {
  color: var(--c-text-muted);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
  transition: color var(--dur) ease, border-color var(--dur) ease;
}
.site-nav__link:hover,
.site-nav__link:focus {
  color: var(--c-link);
  border-color: var(--c-link);
  text-decoration: none;
}
.site-nav__link--active {
  color: var(--c-primary);
  border-color: var(--c-primary);
}

/* ===== Section jump-nav (in-page, home only) ===== */
.section-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0;
  margin-bottom: 2.25rem;
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.section-nav__link {
  color: var(--c-text-muted);
  text-decoration: none;
  transition: color var(--dur) ease;
}
.section-nav__link:hover,
.section-nav__link:focus {
  color: var(--c-primary);
  text-decoration: none;
}

/* · separator between links */
.section-nav__link + .section-nav__link::before {
  content: '·';
  margin: 0 0.65rem;
  color: var(--c-border);
  font-style: normal;
}


/* ===== 5. Dark-mode Toggle ===== */
.theme-toggle {
  background: none;
  border: 1px solid var(--c-border);
  border-radius: 0.35rem;
  padding: 0.3rem 0.45rem;
  cursor: pointer;
  color: var(--c-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color var(--dur) ease, border-color var(--dur) ease;
  font-size: 1rem;
  line-height: 1;
}
.theme-toggle:hover {
  color: var(--c-primary);
  border-color: var(--c-primary);
}

/* Show sun in dark mode (click → light), moon in light mode (click → dark) */
[data-theme="light"] .theme-toggle__sun  { display: none; }
[data-theme="dark"]  .theme-toggle__moon { display: none; }


/* ===== 6. Footer ===== */
.site-footer {
  border-top: 1px solid var(--c-border);
  padding: 1.5rem 0 2rem;
  margin-top: 3rem;
  font-size: 0.85rem;
  color: var(--c-text-muted);
}
.site-footer p { margin: 0; }
.site-footer a { color: inherit; }
.site-footer a:hover { color: var(--c-accent); text-decoration: underline; }



/* ===== 7. Home: Hero ===== */
.home-hero {
  margin: 1.5rem 0 2.5rem;
}

/* Identity block: photo + name/tagline/links as a flex row */
.home-hero__identity {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  margin-bottom: 2rem;
}

.home-hero__photo {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 0.6rem;
  border: 1px solid var(--c-border);
  flex-shrink: 0;
}

.home-hero__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.home-hero__name {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: var(--c-text);
  margin-bottom: 0.3rem;
}

.home-hero__tagline {
  font-size: 0.88rem;
  color: var(--c-text-muted);
  letter-spacing: 0.02em;
  margin: 0 0 1rem;
}

/* "About" label inside hero — matches .page-section > h2 style */
.home-hero__about-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--c-text-muted);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--c-border);
  margin: 0 0 1rem;
}

.home-hero__bio {
  font-size: 1rem;
  line-height: 1.8;
}
.home-hero__bio p + p { margin-top: 0.75rem; }

.highlight-term {
  background-color: var(--c-highlight);
  border-radius: 3px;
  padding: 0 0.18em;
}

/* Social links (including CV) */
.social-links {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}
.social-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.9rem;
  border: 1px solid var(--c-border);
  border-radius: 0.4rem;
  color: var(--c-text-muted);
  font-family: var(--font-body);
  font-size: 0.85rem;
  text-decoration: none;
  transition: background-color var(--dur) ease, color var(--dur) ease, border-color var(--dur) ease;
}
.social-link:hover {
  border-color: var(--c-text);
  color: var(--c-text);
  text-decoration: none;
}
/* CV: slightly foregrounded — teal outline, not filled */
.social-link--cv {
  border-color: var(--c-primary);
  color: var(--c-primary);
  font-weight: 500;
}
.social-link--cv:hover {
  background-color: var(--c-primary);
  color: #fff;
}

/* Icon-only social buttons */
.social-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--c-border);
  border-radius: 0.4rem;
  color: var(--c-text-muted);
  text-decoration: none;
  transition: color var(--dur) ease, border-color var(--dur) ease;
}
.social-icon:hover {
  border-color: var(--c-text);
  color: var(--c-text);
  text-decoration: none;
}
.social-link__note {
  font-size: 0.75em;
  opacity: 0.75;
}


/* ===== 8. Home: Sections ===== */
.page-section {
  margin-top: 2.75rem;
  scroll-margin-top: 5rem; /* breathing room below sticky header */
}
.page-section > h2 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--c-text-muted);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 1.25rem;
}

.section-note {
  font-size: 0.875rem;
  color: var(--c-text-muted);
  margin-bottom: 1rem;
  margin-top: -0.5rem;
}


/* ===== 9. Publications ===== */
.pub-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.pub-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--c-border);
}
.pub-item:first-child { padding-top: 0; }
.pub-item:last-child  { border-bottom: none; }

.pub-title {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--c-link);
  display: block;
  margin-bottom: 0.3rem;
  text-decoration: none;
}
.pub-title:hover {
  color: var(--c-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.pub-authors {
  font-size: 0.875rem;
  color: var(--c-text-muted);
  line-height: 1.5;
  margin: 0 0 0.2rem;
}
/* Highlight the site owner's name in author lists */
.pub-self {
  font-weight: 700;
  color: var(--c-text);
}

.pub-venue {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--c-primary);
  margin: 0 0 0.3rem;
}

.pub-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
}
.pub-link {
  font-size: 0.78rem;
  font-family: var(--font-sans);
  color: var(--c-primary);
  border: 1px solid var(--c-primary);
  border-radius: 0.3rem;
  padding: 0.1rem 0.5rem;
  text-decoration: none;
  transition: background-color var(--dur) ease, color var(--dur) ease;
}
.pub-link:hover {
  background-color: var(--c-primary);
  color: #fff;
  text-decoration: none;
}

.pub-note {
  font-size: 0.8rem;
  color: var(--c-text-muted);
  font-style: italic;
  margin: 0.2rem 0 0;
}


/* ===== 10. Service & Teaching ===== */
.section-card {
  background-color: var(--c-bg-card);
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  font-size: 0.93rem;
  line-height: 1.75;
}
.section-card p { margin: 0; }

.teaching-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.teaching-item {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--c-border);
}
.teaching-item:last-child { border-bottom: none; }

.teaching-course {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--c-accent);
  display: block;
  margin-bottom: 0.15rem;
}
.teaching-role {
  font-size: 0.85rem;
  color: var(--c-text-muted);
  display: block;
}


/* ===== 11. Notes Index ===== */
.notes-index header h1 {
  margin-bottom: 0.25rem;
}

.notes-search {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
  margin-top: 1rem;
}
.notes-search input,
.notes-search select {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--c-border);
  border-radius: 0.4rem;
  font-size: 0.9rem;
  font-family: var(--font-body);
  background: var(--c-bg-input);
  color: var(--c-text);
  width: 100%;
}
.notes-search input:focus,
.notes-search select:focus {
  outline: 2px solid var(--c-primary);
  outline-offset: 1px;
}

.notes-search__tags {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.notes-search__tag {
  font-size: 0.8rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--c-border);
  cursor: pointer;
  background: transparent;
  color: var(--c-primary);
  font-family: var(--font-body);
  line-height: 1.3;
  transition: border-color var(--dur) ease, color var(--dur) ease, background-color var(--dur) ease;
}
.notes-search__tag:not(.notes-search__tag--active):hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
}
.notes-search__tag--active {
  border-color: var(--c-accent);
  color: var(--c-accent);
  background: var(--c-tag-accent);
}


/* ===== 12. Notes Grid & Cards ===== */
.notes-grid {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: 2rem;
}
.notes-card {
  border-left: 3px solid var(--c-border);
  border-radius: 0 0.4rem 0.4rem 0;
  padding: 0.8rem 1rem;
  background: var(--c-bg-card);
  transition: border-color var(--dur) ease;
}
.notes-card:hover,
.notes-card:focus-within {
  border-color: var(--c-accent);
}
.notes-card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  border-bottom: none;
  padding-bottom: 0;
}
.notes-card h2 a {
  color: var(--c-primary);
  text-decoration: none;
}
.notes-card h2 a:hover {
  color: var(--c-accent);
  text-decoration: underline;
}
.notes-card__meta {
  font-size: 0.8rem;
  color: var(--c-text-muted);
}
.notes-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0;
}
.notes-card__tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--c-tag-accent);
  color: var(--c-accent);
}


/* ===== 13. Note Content ===== */
.note-title,
.page-section > h1 {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: 0.01em;
  color: var(--c-text);
  margin-bottom: 0.5rem;
}
.note-meta {
  color: var(--c-text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}
.note-meta a { color: inherit; }

.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.note-tag {
  font-size: 0.8rem;
  padding: 0.2rem 0.55rem;
  background: var(--c-tag-bg);
  border-radius: 999px;
  color: var(--c-primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background-color var(--dur) ease;
}
.note-tag:hover,
.note-tag:focus {
  background: var(--c-tag-accent);
  text-decoration: none;
}

.note-content {
  font-size: 1rem;
  line-height: 1.8;
  margin-top: 1.5rem;
  /* Prevent long words / math from busting the layout on mobile */
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}
.note-content h1, .note-content h2, .note-content h3 { margin-top: 1.5rem; }
.note-content p + p { margin-top: 0.75rem; }

/* Tables scroll horizontally instead of overflowing */
.note-content table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

.note-content pre {
  padding: 1rem;
  overflow-x: auto;
  background: var(--c-bg-card);
  border-radius: 0.4rem;
}
.note-content code,
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: rgba(135, 146, 163, 0.12);
  padding: 0.1rem 0.3rem;
  border-radius: 0.25rem;
}


/* ===== 14. Note Navigation ===== */
.note-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 2rem 0;
  font-size: 0.9rem;
  border-top: 1px solid var(--c-border);
  padding-top: 1rem;
}
.note-nav--top {
  border-top: none;
  border-bottom: 1px solid var(--c-border);
  padding-top: 0;
  padding-bottom: 1rem;
  margin-top: 1.25rem;
  margin-bottom: 1.5rem;
}
.note-nav__group {
  flex: 1;
  display: flex;
  align-items: center;
}
.note-nav__group--left  { justify-content: flex-start; }
.note-nav__group--center { justify-content: center; }
.note-nav__group--right { justify-content: flex-end; }

.note-nav__link {
  color: var(--c-primary);
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  border-radius: 0.3rem;
  transition: background-color var(--dur) ease, color var(--dur) ease;
}
.note-nav__link:hover,
.note-nav__link:focus {
  color: var(--c-accent);
  background: var(--c-tag-accent);
  text-decoration: none;
}
.note-nav__link--back { font-weight: 600; }


/* ===== 15. Code Highlighting ===== */
.highlight pre {
  margin: 0;
  padding: 1rem;
  background: #1f2933;
  color: #f5f7fa;
  border-radius: 0.4rem;
}
.highlight code { background: transparent; padding: 0; }


/* ===== 16. LaTeX Environments ===== */
.theorem, .lemma, .definition, .proof {
  font-family: var(--font-body);
  display: block;
  margin: 1.1rem 0;
  padding: 0.75rem 1.1rem;
  background: var(--c-bg-card);
  border-left: 3px solid var(--c-primary);
  border-radius: 0 0.4rem 0.4rem 0;
  line-height: 1.7;
}
.theorem  { font-style: italic; }
.theorem::before  { content: "Theorem.\00a0";    font-weight: bold; font-style: normal; }
.lemma::before    { content: "Lemma.\00a0";      font-weight: bold; font-style: italic; }
.proof            { font-style: normal; }
.proof::before    { content: "Proof.\00a0";      font-style: italic; }
.proof::after     { content: "\25FC"; float: right; }
.definition::before { content: "Definition.\00a0"; font-weight: bold; }


/* ===== 17. Portfolio / Hobbies ===== */
.portfolio-section {
  margin-top: 2rem;
}
.portfolio-section__title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 400;
  color: var(--c-text);
  letter-spacing: 0.01em;
  text-align: center;
  margin: 2.5rem 0 1rem;
}

.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}
.portfolio-img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 0.45rem;
  cursor: pointer;
  border: 1px solid var(--c-border);
  transition: opacity var(--dur) ease, transform var(--dur) ease;
}
.portfolio-img:hover { opacity: 0.82; transform: scale(1.015); }

/* Modal overlay */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.88);
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.modal-overlay.is-open { display: flex; }

.modal-overlay__img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 0.35rem;
  display: block;
  animation: modal-pop 0.22s ease;
}
.modal-overlay__caption {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 0.9rem;
  text-align: center;
  background: rgba(0,0,0,0.5);
  padding: 0.35rem 1rem;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.modal-overlay__close {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity var(--dur) ease;
}
.modal-overlay__close:hover { opacity: 1; }

@keyframes modal-pop {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}


/* ===== 18. KaTeX ===== */
.katex, .katex * {
  font-family: KaTeX_Main, KaTeX_AMS, serif;
}


/* ===== 19. Back to Top ===== */
/* Separator between CV pill and icon group */
.social-links__sep {
  display: inline-block;
  width: 1px;
  height: 22px;
  background: var(--c-border);
  align-self: center;
  margin: 0 0.2rem;
  flex-shrink: 0;
}

/* Plant / mountain buttons — hidden on mobile (no margins) */
.plant-btn, .mountain-btn {
  position: fixed;
  bottom: 4.75rem;  /* sits above the back-to-top button */
  right: 1.75rem;
  z-index: 50;
  width: 2.4rem;
  height: 2.4rem;
  background: var(--c-bg-card);
  color: var(--c-text-muted);
  border: 1px solid var(--c-border);
  border-radius: 0.4rem;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--dur) ease, color var(--dur) ease,
              border-color var(--dur) ease;
}
.plant-btn:hover, .mountain-btn:hover {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}
.plant-btn.is-planted, .mountain-btn.is-planted {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}
.mountain-btn { display: none; } /* shown only on personal page */
@media (max-width: 860px) { /* hide when margins are too narrow */
  .plant-btn, .mountain-btn { display: none; }
}

.back-to-top {
  position: fixed;
  bottom: 1.75rem;
  right: 1.75rem;
  z-index: 50;
  width: 2.4rem;
  height: 2.4rem;
  background: var(--c-bg-card);
  color: var(--c-text-muted);
  border: 1px solid var(--c-border);
  border-radius: 0.4rem;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.4rem);
  transition: opacity 200ms ease, transform 200ms ease,
              background-color var(--dur) ease, color var(--dur) ease,
              border-color var(--dur) ease;
}
.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}
.back-to-top:hover {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}

/* ===== 20. Utilities ===== */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Faded divider */
.fadedline {
  border: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--c-border), transparent);
  margin: 2rem 0;
}


/* ===== 20. Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; }
}


/* ===== 21. Responsive ===== */
@media (max-width: 600px) {
  :root { --px: 1rem; }

  /* clip (not hidden) — prevents body scroll without breaking sticky or inner scroll containers */
  body { overflow-x: clip; }

  h1, .home-hero__name { font-size: 1.7rem; text-align: center; }
  .home-hero__tagline { text-align: center; }

  .home-hero__identity {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }

  .home-hero__info {
    align-items: center;
    text-align: center;
  }

  .home-hero__photo {
    width: 110px;
    height: 110px;
  }

  .social-links { justify-content: center; }

  /* Header: keep nav + toggle on one line, never wrap */
  .site-header {
    padding: 0.7rem 0 0.6rem;
    margin-bottom: 1.5rem;
  }
  .site-header__inner {
    flex-wrap: nowrap;
    gap: 0.5rem;
    align-items: center;
  }
  /* Nav scrolls horizontally if needed; never wraps */
  .site-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 0.1rem 0.55rem;
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    flex: 1;
    min-width: 0;
  }
  .site-nav::-webkit-scrollbar { display: none; }
  /* Theme toggle stays in header — compact size keeps it on one line */
  .theme-toggle {
    padding: 0.2rem 0.35rem;
    font-size: 0.9rem;
    flex-shrink: 0;
  }
  /* Section jump-nav: wrap tightly, no dots */
  .section-nav {
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.65rem;
  }
  .section-nav__link + .section-nav__link::before { display: none; }

  /* Note title & cards: ensure long titles wrap */
  .note-title {
    word-break: break-word;
    overflow-wrap: break-word;
  }
  .notes-card h2 a {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* Note nav: stack vertically on small screens */
  .note-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .note-nav__group { justify-content: center; }

  /* Notes search: full-width single column */
  .notes-search { grid-template-columns: 1fr; }

  /* KaTeX display math: allow horizontal scroll instead of overflow */
  .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 0.25rem;
  }

  .portfolio-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .portfolio-img { height: 120px; }
}
