/* =========================================================================
   Alex Berns — personal site
   Warm, smooth, simple. Larger type. Light (default) + dark themes.
   All color via CSS variables.
   ========================================================================= */

:root,
[data-theme="light"] {
  --bg:          #f7f2ea;   /* warm cream            */
  --surface:     #fffdf8;
  --fg:          #322c26;   /* warm near-black       */
  --muted:       #8a7d6d;
  --line:        #e7ddcd;
  --accent:      #c56a45;   /* warm terracotta       */
  --accent-soft: rgba(197, 106, 69, 0.12);
  --shadow:      rgba(90, 66, 42, 0.20);
}

[data-theme="dark"] {
  --bg:          #1b1712;   /* warm near-black       */
  --surface:     #241f18;
  --fg:          #ece3d5;   /* warm cream text       */
  --muted:       #a4967f;
  --line:        #352e24;
  --accent:      #e08a5f;
  --accent-soft: rgba(224, 138, 95, 0.16);
  --shadow:      rgba(0, 0, 0, 0.55);
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Nunito Sans", "Noto Sans JP", "Noto Sans TC", system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.25s ease, color 0.25s ease;
}

.wrap {
  max-width: 660px;
  margin: 0 auto;
  padding: 26px 24px 44px;
}

/* ---- header row (profile left, controls stacked top-right) -------------- */
.site-header {
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}
.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
}

/* flags stacked vertically under the toggle */
.lang-switch { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.lang-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  line-height: 0;
  border-radius: 5px;
}
.lang-btn img {
  width: 23px;
  height: auto;
  display: block;
  border-radius: 4px;
  box-shadow: 0 1px 2px var(--shadow);
  opacity: 0.45;
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.lang-btn:hover img { opacity: 0.85; transform: translateY(-1px); }
.lang-btn[aria-pressed="true"] img {
  opacity: 1;
  box-shadow: 0 0 0 1.5px var(--bg), 0 0 0 3px var(--accent);
}

.theme-toggle {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--shadow);
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); transform: translateY(-1px); }
.theme-toggle svg { grid-area: 1 / 1; width: 18px; height: 18px; }
[data-theme="light"] .i-sun  { display: none; }
[data-theme="dark"]  .i-moon { display: none; }

/* ---- hero (photo left, text right; top-aligned with the toggle) --------- */
.hero {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  flex: 1 1 auto;
  min-width: 0;
}
.hero-text { min-width: 0; }

.avatar {
  width: 120px;
  height: 120px;
  flex: 0 0 auto;
  object-fit: cover;
  object-position: center;
  border-radius: 50%;
  display: block;
  border: 4px solid var(--surface);
  box-shadow: 0 8px 22px var(--shadow);
}

.name {
  font-size: clamp(1.7rem, 4.6vw, 2.15rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.12;
  margin: 0 0 5px;
}
.affil { margin: 0 0 8px; }
.affil-line { color: var(--muted); font-size: 0.98rem; line-height: 1.4; margin: 0; }
.affil-line:first-child { color: var(--fg); font-weight: 600; }

.links {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 10px 22px;
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}
.links a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  padding-bottom: 1px;
  transition: border-color 0.2s ease;
}
.links a:hover { border-bottom-color: var(--accent); }

/* CV dropdown (hover/tap to choose language) */
.cv-menu { position: relative; display: inline-block; }
.cv-trigger {
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.cv-trigger::after { content: " ▾"; font-size: 0.78em; }
.cv-list {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 8px;
  display: none;
  flex-direction: column;
  min-width: 128px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 28px var(--shadow);
  z-index: 20;
}
.cv-menu.open .cv-list { display: flex; }
.cv-item {
  display: block;
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
  white-space: nowrap;
  text-align: left;
}
a.cv-item:hover { background: var(--accent-soft); color: var(--accent); }
.cv-soon { color: var(--muted); font-weight: 400; cursor: default; }

/* ---- sections ----------------------------------------------------------- */
.section { margin-bottom: 22px; scroll-margin-top: 20px; }

.section-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}

.prose p { font-size: 1.06rem; margin: 0 0 7px; }
.prose p:last-child { margin-bottom: 0; }

/* mentor links: same colour as text, no underline; reveal subtly on hover */
.prose a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}
.prose a:hover { color: var(--accent); }

/* entries: two-column — period (left) · org + detail (right) */
.entry { display: flex; gap: 22px; margin-bottom: 10px; }
.entry:last-child { margin-bottom: 0; }
.entry-period { flex: 0 0 8.5em; color: var(--muted); font-weight: 600; }
.entry-body { flex: 1 1 auto; min-width: 0; }
.entry-org { font-size: 1.12rem; font-weight: 700; margin: 0; }
.entry-detail { color: var(--muted); margin: 2px 0 0; }

/* publications: title (subtle hover link) + authors (own name bold) — venue */
.pub { margin-bottom: 14px; }
.pub:last-child { margin-bottom: 0; }
.pub-title {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--fg);
}
a.pub-title { color: var(--fg); text-decoration: none; }
a.pub-title:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--muted);
  text-underline-offset: 2px;
}
.pub-meta { color: var(--muted); font-size: 0.95rem; line-height: 1.45; margin: 2px 0 0; }
.pub-meta strong { color: var(--fg); font-weight: 700; }

/* ---- footer ------------------------------------------------------------- */
.site-footer {
  margin-top: 20px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: left;
}

/* ---- responsive --------------------------------------------------------- */
@media (max-width: 520px) {
  body { font-size: 17px; }
  .header-row { gap: 14px; }
  .hero { gap: 16px; }
  .avatar { width: 92px; height: 92px; }
  .entry { gap: 14px; }
  .entry-period { flex-basis: 6.5em; }
}

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