/*
 * Unified editorial color system.
 *
 * One warm-neutral field carries the page. Oxide red is reserved for state
 * and interaction, while News and CV chronology use distinct visual roles.
 */

:root {
  color-scheme: light;

  --surface: #f0ede6;
  --ink: #2d2925;
  --body: #57514a;
  --muted: #625b53;
  --metadata: #75584d;
  --news-date: #615d59;
  --news-marker: #756f67;
  --rule: #cbc4b8;

  --signal: #a34335;
  --signal-text: #9b3d31;

  --bg: var(--surface);
  --text: var(--ink);
  --mid: var(--body);
  --light: var(--muted);
  --accent: var(--signal);
  --accent-fill: var(--signal);
  --line: var(--ink);
  --soft-line: var(--rule);
}

body {
  background: var(--surface);
}

/* Editorial justification is retained on wider measures. The biography copy
   is written to keep each line close to its natural width, while narrow phone
   columns fall back to ragged-right text before justification creates rivers. */
.bio-copy p {
  text-align: justify;
  text-justify: inter-word;
  text-wrap: wrap;
}

/* The navigation shares the page field; the rule supplies its structure. */
.site-nav {
  grid-template-columns: auto minmax(0, 1fr) auto;
  column-gap: clamp(12px, 2vw, 24px);
  background-color: var(--surface);
}

.site-nav-links {
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.site-nav-links a {
  justify-content: center;
  min-width: 44px;
}

.site-nav-links::-webkit-scrollbar {
  display: none;
}

::selection {
  background: color-mix(in srgb, var(--signal) 36%, var(--bg));
  color: var(--text);
}

a:hover {
  box-shadow: inset 0 -1px 0 var(--signal);
}

.site-nav-home:hover,
.site-nav-links a:hover {
  color: var(--text);
  box-shadow: inset 0 -1px 0 var(--signal);
}

.site-nav-home.is-active,
.site-nav-links a.is-active {
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--signal);
}

.site-nav-dot,
.chev {
  color: var(--signal);
}

.site-nav-home.is-active .site-nav-dot {
  color: var(--signal);
}

.contact-links a:hover::after {
  background: var(--signal);
}

.papers h3 a:hover {
  text-decoration-color: var(--signal);
}

.place a:hover,
.place-detail a:hover {
  box-shadow: inset 0 -1px 0 var(--signal);
}

a:focus-visible,
button:focus-visible,
.news-scroll:focus-visible {
  outline-color: var(--signal);
}

/* CV chronology uses the quiet end of the oxide family. */
time,
.date-range span {
  color: var(--metadata);
}

.date-range.is-current span:last-child {
  color: var(--signal-text);
  font-weight: 500;
}

/* News uses neutral dates and open markers; only the explicitly labelled
   latest entry receives a solid state signal. */
.news-scroll time {
  color: var(--news-date);
}

.news-scroll li::before,
.news-scroll li:first-child::before {
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border: 1px solid var(--news-marker);
  background: transparent;
}

.news-scroll li.is-latest::before {
  border-color: color-mix(in srgb, var(--signal) 72%, var(--ink));
  background: var(--signal);
}

.news-scroll li.is-latest time {
  color: var(--signal-text);
  font-weight: 500;
}

.news-scrollbar {
  display: none;
}

.theme-toggle-icon {
  position: relative;
  display: inline-block;
  flex: 0 0 1em;
  width: 1em;
  height: 1em;
}

.theme-toggle {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  touch-action: manipulation;
  user-select: none;
}

/* Inline SVG keeps the toggle independent of font loading on mobile. Both
   icons remain mounted, and the fixed frame prevents layout movement. */
.theme-toggle .theme-icon {
  position: absolute;
  inset: 0;
  display: block;
  width: 1em;
  height: 1em;
  color: var(--mid);
  opacity: 0;
  pointer-events: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.35;
  transform: translateY(1px) rotate(-24deg) scale(0.72);
  transition:
    color 180ms ease,
    opacity 180ms ease,
    transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}

.theme-toggle .theme-icon-sun {
  transform: translateY(1.5px) rotate(-24deg) scale(0.72);
}

.theme-toggle[data-theme-mode="light"] .theme-icon-sun,
.theme-toggle[data-theme-mode="dark"] .theme-icon-moon {
  opacity: 1;
  transform: translateY(var(--theme-icon-nudge, 1px)) rotate(0) scale(1);
}

.theme-toggle[data-theme-mode="light"] .theme-icon-sun {
  --theme-icon-nudge: 1.5px;
}

@media (hover: hover) and (pointer: fine) {
  .theme-toggle:hover[data-theme-mode="light"] .theme-icon-sun,
  .theme-toggle:hover[data-theme-mode="dark"] .theme-icon-moon {
    opacity: 0.86;
    transform: translateY(var(--theme-icon-nudge, 1px)) rotate(0) scale(1.04);
  }
}

.theme-toggle:focus-visible .theme-icon {
  color: var(--signal);
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 220ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

::view-transition-old(root) {
  animation-name: theme-fade-out;
}

::view-transition-new(root) {
  animation-name: theme-fade-in;
}

@keyframes theme-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes theme-fade-in {
  from {
    opacity: 0;
  }
}

:root.theme-transitioning body,
:root.theme-transitioning .site-nav,
:root.theme-transitioning .identity,
:root.theme-transitioning .page > section {
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

@media (hover: none), (pointer: coarse) {
  .theme-toggle:active {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle .theme-icon {
    transition: none;
    will-change: auto;
  }
}

.bio img,
:root[data-theme="dark"] .bio img {
  border: 0;
  outline: 1px solid color-mix(in srgb, var(--ink) 16%, transparent);
  outline-offset: -1px;
  filter: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --surface: #191817;
  --ink: #f1ece3;
  --body: #c8c0b5;
  --muted: #b4ab9f;
  --metadata: #c49a89;
  --news-date: #aaa39a;
  --news-marker: #8f8981;
  --rule: #3a352f;

  --signal: #df7863;
  --signal-text: #df7863;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;

    --surface: #191817;
    --ink: #f1ece3;
    --body: #c8c0b5;
    --muted: #b4ab9f;
    --metadata: #c49a89;
    --news-date: #aaa39a;
    --news-marker: #8f8981;
    --rule: #3a352f;

    --signal: #df7863;
    --signal-text: #df7863;
  }
}

/* Keep the compact scroll rail through the phone range. The previous
   540–640px three-track restoration allowed Service and the theme control to
   overlap. */
@media (max-width: 640px) {
  .bio-copy p {
    text-align: justify;
    text-justify: inter-word;
    text-wrap: wrap;
    -webkit-hyphens: auto;
    hyphens: auto;
  }

  .news-scroll-shell {
    position: relative;
  }

  .news-scroll {
    max-height: 288px;
    overflow-y: auto;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding-right: 16px;
    scrollbar-gutter: auto;
    scrollbar-width: none;
  }

  .news-scroll::-webkit-scrollbar {
    display: none;
  }

  .news-scrollbar {
    display: block;
    position: absolute;
    top: 0;
    right: 1px;
    bottom: 0;
    width: 3px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--news-marker) 24%, transparent);
    pointer-events: none;
  }

  .news-scrollbar-thumb {
    display: block;
    width: 100%;
    min-height: 32px;
    border-radius: inherit;
    background: color-mix(in srgb, var(--news-marker) 82%, var(--surface));
    will-change: transform;
  }

  .site-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0;
  }

  .site-nav-home {
    display: none;
  }

  .site-nav-links {
    display: contents;
  }

  .site-nav-links a {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    justify-content: center;
    padding: 0;
    font-size: clamp(9px, 2.8vw, 11px);
  }

  .site-nav-links .nav-label-full {
    display: none;
  }

  .site-nav-links .nav-label-compact {
    display: inline;
  }

  .site-nav .theme-toggle {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    padding: 0;
    gap: 4px;
    font-size: clamp(9px, 2.8vw, 11px);
  }
}
