:root {
  --text: #222;
  --muted: #666;
  --link: #2a6496;
  --link-hover: #1a4a75;
  --rule: #e5e5e5;
  --bg: #ffffff;
}

/* Dark palette: applies when the visitor's system is in dark mode (unless they
   chose light with the toggle), or when they chose dark with the toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #d8d8d5;
    --muted: #91918e;
    --link: #82aed6;
    --link-hover: #a8c8e8;
    --rule: #33363b;
    --bg: #16181c;
  }
}

:root[data-theme="dark"] {
  --text: #d8d8d5;
  --muted: #91918e;
  --link: #82aed6;
  --link-hover: #a8c8e8;
  --rule: #33363b;
  --bg: #16181c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.65;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* ---------- Theme toggle ---------- */

.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 50%;
  color: var(--muted);
  display: inline-flex;
}

.theme-toggle:hover { color: var(--link); }

/* show the moon in light mode (click → dark), the sun in dark mode (click → light) */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

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

.site-header {
  text-align: center;
  padding: 3rem 1rem 1.5rem;
  border-bottom: 1px solid var(--rule);
}

.avatar {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 1rem;
}

.site-title {
  margin: 0;
  font-size: 2rem;
  font-weight: normal;
  letter-spacing: 0.02em;
}

.site-tagline {
  margin: 0.35rem 0 1.25rem;
  color: var(--muted);
  font-style: italic;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1.75rem;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.site-nav a { color: var(--text); }
.site-nav a:hover { color: var(--link); text-decoration: none; }
.site-nav a.active {
  color: var(--link);
  border-bottom: 2px solid var(--link);
  padding-bottom: 2px;
}

.social-links {
  margin-top: 1.1rem;
  display: flex;
  justify-content: center;
  gap: 1.1rem;
}

.social-links a { color: var(--muted); display: inline-flex; }
.social-links a:hover { color: var(--link); }

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

.content {
  /* fluid column: ~78% of the window, from 680px up to 1150px on big screens */
  width: min(100%, clamp(680px, 78vw, 1150px));
  margin: 0 auto;
  padding: 2rem clamp(1.25rem, 3vw, 2.5rem) 3rem;
}

.content h1 {
  font-size: 1.6rem;
  font-weight: normal;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
}

.content h2 {
  font-size: 1.25rem;
  font-weight: normal;
  margin-top: 2.25rem;
}

.content ul { padding-left: 1.25rem; }
.content li { margin-bottom: 0.5rem; }

/* Publications-style list */
.pub-list { list-style: none; padding-left: 0; }
.pub-list li {
  margin-bottom: 1.1rem;
  padding-left: 1rem;
  border-left: 3px solid var(--rule);
}
.pub-list .pub-venue { color: var(--muted); font-style: italic; }

/* Photo gallery (home page footer + topic pages) */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.gallery img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.gallery figcaption,
.caption {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.3rem;
}

.gallery figure { margin: 0; }

.gallery a img { transition: opacity 0.15s ease; }
.gallery a:hover img { opacity: 0.8; }
.gallery figcaption a { color: var(--muted); }
.gallery figcaption a:hover { color: var(--link); text-decoration: none; }

/* Full-width page variant (used by the Writing page) */
.content.wide {
  width: 100%;
  padding-left: clamp(1.25rem, 4vw, 4rem);
  padding-right: clamp(1.25rem, 4vw, 4rem);
}

/* Writing page */
.writing-layout {
  display: grid;
  grid-template-columns: clamp(70px, 9vw, 140px) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  align-items: stretch;
  min-height: 60vh;
}

/* the sidebar column (and its rule) runs the full height of the section */
.year-sidebar {
  border-right: 1px solid var(--rule);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.9rem;
}

.year-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
  position: sticky;
  top: 1rem;
}

.year-sidebar li { margin: 0; }

.year-sidebar a {
  display: block;
  padding: 0.35rem 0.75rem 0.35rem 0;
  color: var(--muted);
}

.year-sidebar a:hover {
  color: var(--link);
  text-decoration: none;
}

.writing-posts h1 { margin-top: 0; }

@media (max-width: 560px) {
  .writing-layout { display: block; min-height: 0; }
  .year-sidebar { border-right: none; margin-bottom: 1rem; }
  .year-sidebar ul { position: static; display: flex; gap: 1rem; }
  .year-sidebar a { padding: 0; }
}

.post-list { list-style: none; padding-left: 0; }
.post-list li { margin-bottom: 0.65rem; }

.post-date { color: var(--muted); font-style: italic; margin-top: -0.75rem; }
.post-back { margin-top: 2.5rem; }

/* Justified photo collage (Google Photos style): each row is a fixed height,
   photos keep their natural aspect ratio and stretch slightly to fill the row.
   Adding/removing photos just reflows the rows. */
.collage {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 1rem;
}

.collage figure {
  margin: 0;
  height: 220px;
  flex-grow: 1;
  position: relative;
}

.collage a {
  display: block;
  height: 100%;
  position: relative;
}

.collage img {
  height: 100%;
  width: auto;
  min-width: 100%;
  object-fit: cover;
  display: block;
  border-radius: 4px;
  aspect-ratio: auto;
  transition: opacity 0.15s ease;
}

.collage a:hover img { opacity: 0.85; }

.more-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 1.6rem;
  border-radius: 4px;
}

@media (max-width: 560px) {
  .collage figure { height: 130px; }
}

/* Full album view */
.album {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  overflow-y: auto;
}

.album[hidden] { display: none; }

.album-header {
  position: sticky;
  top: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--rule);
}

.album-title {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.album-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}

.album-close:hover { color: var(--text); }

.album-grid {
  padding: 1.25rem clamp(1rem, 3vw, 2.5rem) 3rem;
  margin-top: 0;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox[hidden] { display: none; }

.lightbox figure {
  margin: 0;
  max-width: 90vw;
  text-align: center;
}

.lightbox img {
  max-width: 90vw;
  max-height: 82vh;
  border-radius: 4px;
}

.lightbox figcaption {
  color: #bbb;
  font-size: 0.9rem;
  margin-top: 0.6rem;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: fixed;
  background: none;
  border: none;
  color: #ddd;
  cursor: pointer;
  line-height: 1;
  padding: 0.5rem;
  z-index: 101;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover { color: #fff; }

.lightbox-close { top: 0.75rem; right: 1rem; font-size: 2.2rem; }
.lightbox-prev { left: 0.75rem; top: 50%; transform: translateY(-50%); font-size: 3rem; }
.lightbox-next { right: 0.75rem; top: 50%; transform: translateY(-50%); font-size: 3rem; }

/* SoundCloud embed */
.soundcloud-embed {
  border: 0;
  border-radius: 6px;
  margin: 1rem 0 0.25rem;
  background: var(--rule);
}

/* Responsive YouTube embed */
.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 1rem 0 0.25rem;
  border-radius: 6px;
  overflow: hidden;
  background: var(--rule);
}

.video-wrapper iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

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

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 1.5rem 1rem 2.5rem;
  border-top: 1px solid var(--rule);
}

@media (max-width: 480px) {
  body { font-size: 16px; }
  .avatar { width: 120px; height: 120px; }
}
