/* ---------- Design tokens ---------- */
:root {
  --bg: #faf9f7;
  --bg-elevated: #ffffff;
  --text: #1c1c1a;
  --text-muted: #6b6a66;
  --border: #e7e5e0;
  --accent: #a15c2f;
  --accent-soft: #f3e6da;
  --shadow: 0 1px 2px rgba(20, 19, 15, 0.04), 0 8px 24px rgba(20, 19, 15, 0.05);
  --radius: 14px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --max-width: 760px;
}

:root[data-theme="dark"] {
  --bg: #121212;
  --bg-elevated: #191919;
  --text: #ece9e4;
  --text-muted: #9c9a94;
  --border: #2c2b28;
  --accent: #e0a674;
  --accent-soft: #2c2115;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --bg-elevated: #191919;
    --text: #ece9e4;
    --text-muted: #9c9a94;
    --border: #2c2b28;
    --accent: #e0a674;
    --accent-soft: #2c2115;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

a { color: inherit; }

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

/* ---------- Nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(12px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-links a {
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.nav-links a:hover { color: var(--accent); }

.nav-icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.nav-icon-btn svg { width: 16px; height: 16px; }

.nav-icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.theme-toggle:hover { border-color: var(--accent); transform: translateY(-1px); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}

/* ---------- Layout ---------- */
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

section { padding: 56px 0; }
section + section { border-top: 1px solid var(--border); }

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 40px;
  align-items: center;
  padding-top: 64px;
}

.hero-text .eyebrow {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 10px;
}

.hero-text h1 {
  font-family: var(--serif);
  font-size: clamp(32px, 5vw, 44px);
  font-weight: 600;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.hero-text p.bio {
  color: var(--text-muted);
  font-size: 16px;
  margin: 0 0 24px;
  max-width: 54ch;
}

.current-focus {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 24px;
  max-width: 54ch;
}

.current-focus-label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 4px;
}

.hero-photo img {
  width: 152px;
  height: 152px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.pill svg { width: 15px; height: 15px; }

/* ---------- Scholar stats ---------- */
.scholar-stats {
  display: flex;
  gap: 28px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-decoration: none;
  color: inherit;
}

.stat-num {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  transition: color 0.15s ease;
}

.stat:hover .stat-num { color: var(--accent); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats-note {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.stats-note a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stats-note a:hover { color: var(--accent); }

/* ---------- Section heading ---------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.section-head h2 {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  margin: 0;
}

.pub-count {
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Publications search ---------- */
.pub-search {
  position: relative;
  margin-bottom: 28px;
}

.pub-search input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pub-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pub-search svg {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-hint {
  margin: -18px 0 24px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.hint-chip {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.hint-chip:hover { color: var(--text); }

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

.pub-item {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.pub-item.in-view { opacity: 1; transform: translateY(0); }
.pub-item:last-child { border-bottom: none; }
.pub-item.is-hidden { display: none; }

.pub-title {
  font-size: 15.5px;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.45;
}

.pub-title:hover { color: var(--accent); }

.pub-authors {
  font-size: 13.5px;
  color: var(--text-muted);
  margin: 5px 0 4px;
}

.pub-authors .me { color: var(--text); font-weight: 600; }

.pub-venue {
  font-size: 13px;
  color: var(--accent);
  font-style: italic;
}

.pub-empty {
  color: var(--text-muted);
  font-size: 14px;
  padding: 20px 0;
  display: none;
}

.pub-empty.show { display: block; }

/* ---------- Footer ---------- */
footer {
  padding: 32px 0 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.footer-note {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.7;
}

.back-to-top {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  transition: color 0.15s ease;
}

.back-to-top:hover { color: var(--accent); }

/* ---------- Game modal ---------- */
.game-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 9, 7, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.game-modal-backdrop[hidden] { display: none; }

.game-modal {
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.game-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.game-modal-title {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
}

.game-modal-close {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 6px;
  transition: color 0.15s ease;
}

.game-modal-close svg { width: 18px; height: 18px; }
.game-modal-close:hover { color: var(--accent); }

.game-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.game-tab {
  border: none;
  background: none;
  padding: 8px 4px 10px;
  margin-bottom: -1px;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.game-tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.game-panel[hidden] { display: none; }

.game-new-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.game-new-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 2048 ---------- */
.game2048-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.game2048-score {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  text-align: center;
  min-width: 56px;
}

.game2048-score-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.game2048-score-value {
  display: block;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
}

.game2048-bar .game-new-btn { margin-left: auto; }

.game2048-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  outline: none;
  touch-action: none;
}

.game2048-cell {
  aspect-ratio: 1;
  border-radius: 6px;
  background: color-mix(in srgb, var(--border) 45%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  animation: tile-pop 0.15s ease;
}

.game2048-cell[data-value="2"]    { background: #f4ede4; color: #3a2c1e; }
.game2048-cell[data-value="4"]    { background: #efe0cf; color: #3a2c1e; }
.game2048-cell[data-value="8"]    { background: #e3bf90; color: #3a2411; }
.game2048-cell[data-value="16"]   { background: #dfae74; color: #3a2411; }
.game2048-cell[data-value="32"]   { background: #d6934f; color: #fff8f0; }
.game2048-cell[data-value="64"]   { background: #c97f3a; color: #fff8f0; }
.game2048-cell[data-value="128"]  { background: #b96a2e; color: #fff8f0; font-size: 15px; }
.game2048-cell[data-value="256"]  { background: #a15c2f; color: #fff8f0; font-size: 15px; }
.game2048-cell[data-value="512"]  { background: #8a4a24; color: #fff8f0; font-size: 15px; }
.game2048-cell[data-value="1024"] { background: #6f3a1c; color: #fff8f0; font-size: 13px; }
.game2048-cell[data-value="2048"] { background: #4a2712; color: #ffe9cf; font-size: 13px; box-shadow: 0 0 0 2px var(--accent); }

@keyframes tile-pop {
  from { transform: scale(0.8); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

.game2048-dpad {
  display: grid;
  grid-template-columns: repeat(3, 38px);
  grid-template-rows: repeat(3, 38px);
  gap: 6px;
  justify-content: center;
  margin-top: 14px;
}

.game2048-dpad-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.game2048-dpad-btn svg { width: 16px; height: 16px; }

.game2048-dpad-btn:hover { color: var(--accent); border-color: var(--accent); }
.game2048-dpad-btn:active { transform: scale(0.92); }

.game2048-dpad-up    { grid-column: 2; grid-row: 1; }
.game2048-dpad-left  { grid-column: 1; grid-row: 2; }
.game2048-dpad-right { grid-column: 3; grid-row: 2; }
.game2048-dpad-down  { grid-column: 2; grid-row: 3; }

.game2048-hint {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Tic-tac-toe ---------- */
.ttt-first {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.ttt-first-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.ttt-first-btn:hover { border-color: var(--accent); color: var(--accent); }

.ttt-first-btn.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.ttt-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.ttt-status {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}

.ttt-cell {
  aspect-ratio: 1;
  border: none;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.ttt-cell:hover:not(:disabled) { border-color: var(--accent); }
.ttt-cell:disabled { cursor: default; }

/* ---------- Chess puzzles ---------- */
.chess-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.chess-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.chess-bar-actions {
  display: flex;
  gap: 6px;
}

.chess-puzzle-num {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 600;
}

.chess-difficulty {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 9px;
}

.chess-objective {
  margin: 0 0 2px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.chess-source {
  margin: 0 0 12px;
  font-size: 11px;
  font-style: italic;
  color: var(--text-muted);
  opacity: 0.85;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.chess-square {
  border: none;
  padding: 0;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 4.6vw, 26px);
  line-height: 1;
  cursor: pointer;
  position: relative;
}

.chess-square-light { background: var(--accent-soft); }
.chess-square-dark { background: color-mix(in srgb, var(--accent) 30%, var(--accent-soft)); }

.chess-piece-white { color: #fff8f0; text-shadow: 0 0 0 var(--text), 0 1px 2px rgba(0, 0, 0, 0.35); }
.chess-piece-black { color: #171410; }

.chess-square.is-selected { box-shadow: inset 0 0 0 2px var(--accent); }

.chess-square.is-dest::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 55%, transparent);
}

.chess-board.chess-shake { animation: chess-shake 0.35s ease; }

@keyframes chess-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.chess-status {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
}

.chess-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.chess-nav-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.chess-nav-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.chess-nav-btn:disabled { opacity: 0.35; cursor: default; }

.chess-dots { display: flex; gap: 6px; }

.chess-dot {
  border: 1px solid var(--border);
  background: var(--bg);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
}

.chess-dot.is-active { border-color: var(--accent); }
.chess-dot.is-solved { background: var(--accent); border-color: var(--accent); }

.chess-prize {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 10px;
  text-align: center;
}

.chess-prize p {
  margin: 0;
  font-family: var(--serif);
  font-size: 13.5px;
  color: var(--text);
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .hero { grid-template-columns: 1fr; text-align: center; }
  .hero-photo { justify-self: center; }
  .hero-text p.bio { max-width: none; }
  .links { justify-content: center; }
  .scholar-stats { justify-content: center; }
  .stats-note { text-align: center; }
  .nav-links span.nav-label { display: none; }
}
