/* ==========================================================================
   main.css — single style entry for the whole site.
   Typography and layout follow the custyhs.github.io reference spec;
   the page background keeps this site's own light-blue / deep-purple
   gradient. All design tokens live in :root / [data-theme="dark"];
   never hardcode colors elsewhere (AGENTS.md convention).
   ========================================================================== */

/* ---------- Design tokens ---------- */

:root {
  /* Layered background — pale blue daylight (PLAN.md round 2) */
  --bg-base: #F1F7FF;
  --bg-ambient-1: #d5e0f0;
  --bg-ambient-2: #EEE8FF;
  --bg-ambient-3: #D5E5FF;
  --nav-bg: #d2e3f7;

  /* Mouse-follow lights (positions driven by assets/js/ambient.js) */
  --glow: rgba(225, 242, 248, 0.5);
  --glow-aux: rgba(174, 203, 250, 0.32);

  /* Vignette + film grain intensity */
  --vignette: rgba(95, 134, 197, 0.1);
  --grain-opacity: 0.03;

  --text-primary: #1A2233;
  --text-secondary: #5A6B85;
  --accent: #1F4E8C;
  --accent-hover: #2A6FC9;
  --accent-soft: rgba(31, 78, 140, 0.08);
  --note: #B42318;
  --line: rgba(31, 78, 140, 0.16);
  --hover-bg: rgba(31, 78, 140, 0.05);

  /* Mouse-follow light positions (updated by assets/js/ambient.js);
     --mx/--my = main light, --mx2/--my2 = slower auxiliary light */
  --mx: 50%;
  --my: 30%;
  --mx2: 50%;
  --my2: 30%;

  --serif: Georgia, "Times New Roman", "Songti SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "PingFang SC", sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  /* Layered background — deep purple cinematic (PLAN.md round 2) */
  --bg-base: #100719;
  --bg-ambient-1: #07030c;
  --bg-ambient-2: #0d0614;
  --bg-ambient-3: #1B0E30;
  --nav-bg: #0a0618;

  --glow: rgba(34, 20, 52, 0.1);
  --glow-aux: rgba(166, 201, 255, 0.07);

  --vignette: rgba(5, 2, 11, 0.55);
  --grain-opacity: 0.05;

  --text-primary: #EAE6F7;
  --text-secondary: #9D94B8;
  --accent: #7FB0FF;
  --accent-hover: #A9C8FF;
  --accent-soft: rgba(127, 176, 255, 0.14);
  --note: #FF8A80;
  --line: rgba(234, 230, 247, 0.16);
  --hover-bg: rgba(234, 230, 247, 0.06);
  color-scheme: dark;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 88px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.4s ease, color 0.3s ease;
}

/* ---------- Ambient background stack ----------
   Four independent, individually adjustable layers:
   1. .ambient (parent) — base vignette + the two mouse-follow lights
   2. .ambient__drift   — large slow-drifting radial gradients (transform only)
   3. .ambient__grain   — near-invisible SVG film grain
   All layers: pointer-events none, behind content (z-index 0). */

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  transition: background 0.4s ease;
  /* First layer = painted on top: aux light, main light, vignette */
  background:
    radial-gradient(1100px circle at var(--mx2) var(--my2), var(--glow-aux), transparent 70%),
    radial-gradient(650px circle at var(--mx) var(--my), var(--glow), transparent 70%),
    radial-gradient(120% 95% at 50% 42%, transparent 52%, var(--vignette) 100%);
}

.ambient__drift {
  position: absolute;
  inset: -25%;
  background:
    radial-gradient(42% 38% at 30% 32%, var(--bg-ambient-1), transparent 72%),
    radial-gradient(38% 34% at 72% 62%, var(--bg-ambient-2), transparent 72%),
    radial-gradient(34% 30% at 48% 82%, var(--bg-ambient-3), transparent 72%);
  animation: ambient-drift 46s ease-in-out infinite alternate;
  will-change: transform;
}

@keyframes ambient-drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(4%, -3%, 0) scale(1.07); }
  100% { transform: translate3d(-3%, 3%, 0) scale(1.03); }
}

.ambient__grain {
  position: absolute;
  inset: 0;
  opacity: var(--grain-opacity);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="160" height="160"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" stitchTiles="stitch"/></filter><rect width="160" height="160" filter="url(%23n)"/></svg>');
  background-size: 160px 160px;
}

.site-header, main, .site-footer { position: relative; z-index: 1; }

a {
  color: var(--accent);
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-size: 0 1px;
  background-position: 0 100%;
  transition: background-size 0.18s ease, color 0.18s ease;
}
a:hover { color: var(--accent-hover); background-size: 100% 1px; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

button { font: inherit; color: inherit; }
p { margin: 0 0 18px; }
ul, ol { margin: 0 0 18px; padding-left: 22px; }
li { margin-bottom: 6px; }
strong { font-weight: 700; }
img { display: block; max-width: 100%; }

h1, h2, h3 { color: var(--text-primary); margin: 0; line-height: 1.25; }
h1 {
  font-family: var(--sans);
  font-weight: 650;
  font-size: 40px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
h3 { font-size: 18px; line-height: 1.45; font-weight: 700; }

/* Section label: 14px sans, uppercase, accent, bottom border line */
.section-label {
  font: 600 14px/1.4 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 18px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: -100px;
  z-index: 20;
  padding: 8px 16px;
  background: var(--nav-bg);
  color: var(--text-primary);
}
.skip-link:focus { top: 12px; }

/* ---------- Header / navigation ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.site-header__inner {
  max-width: 1040px;
  height: 100%;
  padding: 0 12px;
  margin: 0 auto;
  display: flex;
  align-items: center;
}

.site-brand {
  color: var(--text-primary);
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-right: auto;
  white-space: nowrap;
  background: none;
}
.site-brand:hover { color: var(--accent); background: none; }

.site-navigation {
  display: flex;
  gap: 26px;
  align-items: center;
  font-size: 15px;
}

.site-navigation a {
  position: relative;
  color: var(--text-primary);
  line-height: 44px;
  white-space: nowrap;
  background: none;
}
.site-navigation a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.18s ease;
}
.site-navigation a:hover { color: var(--accent); }
.site-navigation a:hover::after,
.site-navigation a[aria-current="page"]::after { transform: scaleX(1); }
.site-navigation a[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* Theme toggle button */
.theme-toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  margin-left: 14px;
  color: var(--text-primary);
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  transition: background 0.18s ease, color 0.18s ease;
}
.theme-toggle:hover { background: var(--hover-bg); color: var(--accent); }

/* ---------- Content column ---------- */

.site-content {
  width: calc(100% - 48px);
  max-width: 840px;
  min-height: calc(100vh - 199px);
  margin: 0 auto;
  padding: 48px 0 64px;
}

.page-heading { margin-bottom: 18px; }
.page-heading h1 { font-size: 36px; }
.page-intro { color: var(--text-secondary); margin-bottom: 26px; }
.page-intro p { margin-bottom: 4px; }

/* ---------- Home: profile ---------- */

.profile-heading { margin-bottom: 22px; }
.profile-heading h1 { font-size: 44px; letter-spacing: -0.03em; }
.name-native { color: var(--text-secondary); font-size: 0.78em; font-weight: 500; margin-left: 8px; }
.profile-subtitle {
  font-family: var(--sans);
  font-size: 16px;
  color: var(--text-secondary);
  margin: 6px 0 0;
}

.profile-intro {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  column-gap: 40px;
  align-items: start;
}
.profile-copy > p { margin-bottom: 18px; }
.profile-portrait { margin: 4px 0 0; width: 200px; height: 200px; }
.profile-portrait img { width: 100%; height: 100%; object-fit: cover; }

/* Contact links (inline SVG icons, no icon fonts) */
.contact-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 24px;
  margin-top: 6px;
  font: 15px/1.6 var(--sans);
}
.contact-links a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--text-secondary);
  white-space: nowrap;
  background: none;
}
.contact-links a:hover { color: var(--accent); }
.contact-links svg { width: 17px; height: 17px; fill: currentColor; flex-shrink: 0; }

/* ---------- Home: sections ---------- */

.home-section { margin-top: 44px; }
.service-list li, .hobby-list li { margin-bottom: 14px; }
.service-list p:last-child, .hobby-list p:last-child { margin-bottom: 0; }

/* ---------- Publications ---------- */

.publication-section { margin-top: 30px; }
.pub-list { list-style: none; margin: 0; padding: 0; }

.pub {
  position: relative;
  display: grid;
  grid-template-columns: 5rem minmax(0, 1fr);
  column-gap: 18px;
  padding: 14px 0 15px;
  margin: 0;
  border-bottom: 1px solid var(--line);
}
.pub-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  font-family: var(--sans);
  line-height: 1.3;
  padding-top: 3px;
}
.pub-venue { color: var(--accent); font-weight: 700; font-size: 14px; letter-spacing: 0.01em; }
.pub-year { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.pub-body { min-width: 0; }
.pub-title { margin: 0 0 4px; font-size: 17.5px; line-height: 1.4; font-weight: 700; color: var(--text-primary); }
.pub-authors { margin: 0 0 3px; font-size: 15px; line-height: 1.6; }
.pub-self { color: var(--accent); font-weight: 700; }
.pub-where { margin: 0; font-size: 13.5px; color: var(--text-secondary); font-style: italic; line-height: 1.5; }
.pub-note { color: var(--note); font-style: normal; font-weight: 700; font-family: var(--sans); font-size: 13px; }
.pub-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }

.pub--has-figure { grid-template-columns: 8.5rem minmax(0, 1fr); }
.pub-figure { margin: 0; min-width: 0; }
.pub-figure a { display: block; }
.pub-figure img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--accent-soft);
}
.pub-abstract { margin: 7px 0 0; font-size: 13.5px; line-height: 1.55; color: var(--text-secondary); }
.pub-list-more { margin: 12px 0 0; font-size: 14px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--accent);
  background: transparent;
  font: 500 12.5px/1.3 var(--sans);
  transition: border-color 0.18s ease, background-color 0.18s ease;
}
.pill:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------- Awards ---------- */

.award-list { list-style: none; margin: 0; padding: 0; }
.award {
  display: grid;
  grid-template-columns: 60px 24px minmax(0, 1fr);
  column-gap: 12px;
  align-items: start;
  padding: 14px 0;
  margin: 0;
  border-bottom: 1px solid var(--line);
}
.year-badge {
  justify-self: start;
  font: 600 12px/1 var(--sans);
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 6px 8px;
  border-radius: 4px;
  margin-top: 3px;
}
.award > svg { width: 15px; height: 15px; fill: var(--text-secondary); margin-top: 6px; }
.award h3 { font-size: 17px; margin-bottom: 3px; }
.award p { margin: 0; color: var(--text-secondary); font-size: 15px; line-height: 1.55; }

/* ---------- Hero banner (home only) ---------- */

.hero { height: 45vh; min-height: 280px; overflow: hidden; }
.hero img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Blog / travel index ---------- */

.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li { padding: 12px 0; border-bottom: 1px solid var(--line); margin: 0; }
.post-list a { background: none; color: var(--text-primary); font-weight: 700; }
.post-list a:hover { color: var(--accent); }
.post-list .post-list-date { color: var(--text-secondary); font-size: 0.88rem; font-family: var(--sans); margin-left: 10px; }

.empty-state { padding: 48px 24px; text-align: center; color: var(--text-secondary); }
.empty-state h1 { margin-bottom: 10px; }

/* ---------- Blog post page ---------- */

.post-title { margin-bottom: 6px; }
.post-meta { color: var(--text-secondary); margin: 0 0 24px; font-size: 0.92rem; font-family: var(--sans); }
.post-content img { border-radius: 4px; }

/* ---------- Footer ---------- */

.site-footer {
  max-width: 840px;
  width: calc(100% - 48px);
  margin: 0 auto;
  padding: 22px 0 28px;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--text-secondary);
  font: 12px/1.7 var(--sans);
}
.site-footer a { color: inherit; }
.site-footer p { margin: 0; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .site-header__inner { width: calc(100% - 24px); padding: 0; }
}

@media (max-width: 700px) {
  .profile-intro { grid-template-columns: 160px minmax(0, 1fr); column-gap: 24px; }
  .profile-portrait { width: 160px; height: 160px; }
  .profile-heading h1 { font-size: 38px; }
}

@media (max-width: 600px) {
  html { scroll-padding-top: 124px; }
  body { font-size: 16px; line-height: 1.7; }
  h1 { font-size: 32px; }
  .site-header { height: auto; }
  .site-header__inner {
    width: calc(100% - 40px);
    display: grid;
    grid-template-columns: 1fr 40px;
    padding: 8px 0 4px;
  }
  .site-brand { grid-column: 1; grid-row: 1; font-size: 18px; }
  .site-navigation {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 14px;
  }
  .site-navigation a { line-height: 40px; }
  .theme-toggle { grid-column: 2; grid-row: 1; margin: 0; }
  .site-content { width: calc(100% - 40px); padding-top: 32px; padding-bottom: 44px; }
  .page-heading h1 { font-size: 30px; }
  .profile-heading h1 { font-size: 34px; }
  .profile-intro { display: flex; flex-direction: column; gap: 22px; }
  .profile-portrait { margin: 0; width: 150px; height: 150px; }
  .contact-links { gap: 8px 20px; font-size: 14px; }
  .home-section { margin-top: 36px; }
  .pub { grid-template-columns: 1fr; row-gap: 6px; padding: 14px 0; }
  .pub--has-figure { grid-template-columns: 1fr; row-gap: 10px; }
  .pub-figure { max-width: 280px; }
  .pub-meta { flex-direction: row; align-items: baseline; gap: 8px; text-align: left; padding-top: 0; }
  .pub-year { margin-top: 0; }
  .pub-title { font-size: 16.5px; }
  .pub-authors { font-size: 14px; }
  .award { grid-template-columns: 56px minmax(0, 1fr); }
  .award > svg { display: none; }
  .site-footer { width: calc(100% - 40px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
