/* ===================================================================
   Project page styles. Tweak the variables in :root to rebrand.
   =================================================================== */

:root {
  --accent: #e06080;          /* primary accent (buttons, links, highlights) */
  --accent-soft: rgba(224, 96, 128, 0.08);
  --accent-border: rgba(224, 96, 128, 0.35);
  --page-font: 'Google Sans', 'Noto Sans', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

/* Page content width */
.container.is-max-desktop { max-width: 940px; }

body {
  font-family: var(--page-font);
  transition: background-color 0.25s, color 0.25s;
}

.publication-title { font-weight: 700; }
.publication-authors { margin-top: 1rem; }
.publication-authors a { color: var(--accent); }
.author-block { white-space: nowrap; }

.publication-links { margin-top: 1.5rem; }
.publication-links .button { margin: 0.25rem; }

/* ===================== TABLE OF CONTENTS ========================== */
.switcher-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  padding-top: 2.5rem;
}

.switch-btn {
  padding: 0.5rem 1.1rem;
  border: 2px solid var(--accent-border);
  border-radius: 20px;
  background: var(--accent-soft);
  cursor: pointer;
  text-decoration: none;          /* anchor links */
  font-family: var(--page-font);
  font-size: 0.88rem;
  font-weight: 600;
  color: inherit;
  transition: all 0.2s ease;
}
.switch-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 12px var(--accent-soft);
  color: inherit;
}
.switch-btn.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Offset anchored sections so the heading isn't hidden under the top edge */
section[id] { scroll-margin-top: 1.5rem; }

/* Visual separation between content sections: a short, centered divider
   above each section (not a full-width line). */
#puzzle::before, #why::before, #architecture::before,
#results::before, #BibTeX::before {
  content: "";
  display: block;
  width: 900px;
  height: 2px;
  margin: 0 auto 2.5rem;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.15;
}

/* ===================== TL;DR box ================================= */
.tldr-box {
  border: 2px solid var(--accent-border);
  border-radius: 14px;
  background: var(--accent-soft);
  padding: 1.5rem 1.75rem;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.04);
}
.tldr-box .title { color: var(--accent); margin-bottom: 1rem; }
html[data-theme="dark"] .tldr-box {
  background: rgba(224, 96, 128, 0.10);
  border-color: var(--accent);
  box-shadow: none;
}

/* ===================== Attention-map viewer ====================== */
/* the short centered divider isn't needed on the attention section */
#attention::before { content: none; }

.attn-viewer { margin-top: 1rem; }

.attn-row-title {
  margin: 1.75rem 0 0.75rem;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.75;
  text-align: center;
}

/* Row 1: input image, centered and a bit larger */
.attn-input-row {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}
.attn-input img { max-width: 220px; }

/* Row 2: the model attention maps */
.attn-panels {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}
/* keep the 4 model maps on one row on wide screens */
.attn-models { flex-wrap: nowrap; }
@media screen and (max-width: 760px) {
  .attn-models { flex-wrap: wrap; }
}

/* diffusion viewer: always keep all 4 panels on a single row */
.attn-diff-models { flex-wrap: nowrap; gap: 0.6rem; }
.attn-diff-models .attn-panel img { max-width: 180px; }
@media screen and (max-width: 760px) {
  .attn-diff-models .attn-panel img { max-width: 22vw; }
}
.attn-panel {
  margin: 0;
  text-align: center;
}
.attn-panel img {
  width: 100%;
  max-width: 190px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #dbdbdb;
  background: #f5f5f5;
  display: block;
}
/* Model name shown ABOVE the image */
.attn-panel .attn-model-name {
  margin-bottom: 0.4rem;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent);
}
/* Layer index shown BELOW the image */
.attn-panel figcaption {
  margin-top: 0.45rem;
}
.attn-panel figcaption .attn-layer {
  display: block;
  font-weight: 500;
  font-size: 0.8rem;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}
/* ViT viewer: no per-image layer index under the maps */
.attn-viewer .attn-panel .attn-layer { display: none; }

/* Caption shown beneath the slider controls */
.attn-caption {
  margin-top: 0.9rem;
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
}
.attn-caption code {
  background: var(--accent-soft);
  padding: 0.05rem 0.35rem;
  border-radius: 5px;
}

.attn-control {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  justify-content: center;
  max-width: 520px;
  margin: 1.5rem auto 0;
}
.attn-control-label { font-weight: 600; font-size: 0.9rem; }
.attn-end-label { font-size: 0.72rem; opacity: 0.6; white-space: nowrap; }
.attn-value-time { min-width: 11ch; }
.attn-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 6px;
}
.attn-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  min-width: 2.2ch;
  text-align: right;
}

html[data-theme="dark"] .attn-panel img { border-color: var(--border); background: var(--card); }

@media screen and (max-width: 600px) {
  .attn-panel img { max-width: 30vw; }
}

/* ================== Register guidance switcher =================== */
.rg-viewer { margin-top: 1.25rem; }
.rg-figure { margin: 0 auto; text-align: center; }
.rg-img {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid #dbdbdb;
  background: #f5f5f5;
  display: block;
  margin: 0 auto;
}
html[data-theme="dark"] .rg-img { border-color: var(--border); background: var(--card); }
.rg-viewer .attn-control { max-width: 420px; }
.rg-viewer .attn-value { min-width: 5ch; }
@media screen and (max-width: 600px) {
  .rg-img { max-width: 68vw; }
}

/* ===================== PCA feature-map viewer ==================== */
.pca-viewer { margin-top: 1rem; }
.pca-panels { gap: 1rem; }
.pca-panels .attn-panel img {
  max-width: 240px;
  image-rendering: pixelated;     /* raw 16x16 tokens, no smoothing */
}

/* ===================== Token-norm figure ========================= */
/* Break out of the 840px text column so the plots are large. */
.norms-figure {
  margin: 1.5rem auto 0;
  width: 100%;
  max-width: 820px;
}
.norms-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.norms-grid img {
  width: 100%;
  border-radius: 8px;
  background: #fff;
}
.norms-figure figcaption { margin-top: 1rem; }
@media screen and (max-width: 640px) {
  .norms-grid { grid-template-columns: 1fr; }
}

.algo-figure {
  margin: 2rem auto 0;
  width: 100%;
  max-width: 900px;
}
.algo-figure img {
  width: 100%;
  border-radius: 10px;
  background: #fff;
}
.algo-figure figcaption { margin-top: 1rem; }

/* ===================== In-context token attention maps =========== */
.incontext-figure {
  margin: 1.5rem 0 0;
  width: min(940px, 92vw);
  margin-left: 50%;
  transform: translateX(-50%);
}
.image-row {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
}
.image-card {
  width: 23%;
  text-align: center;
}
.image-caption {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 5px;
}
.image-card .attn-img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid #d0d0d0;
  border-radius: 14px;
  object-fit: cover;
}
html[data-theme="dark"] .image-card .attn-img { border-color: var(--border); }
.attn-input-cap {
  display: block;
  margin-top: 0.45rem;
  font-size: 0.85rem;
  opacity: 0.7;
}
@media screen and (max-width: 600px) {
  .image-card .image-caption { font-size: 11px; }
}

/* ===================== FID table (paper Table 2) ================= */
.fid-table-wrap { margin: 1.25rem auto 0; max-width: 560px; }
.fid-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 auto;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.fid-table th, .fid-table td {
  padding: 0.45rem 0.9rem;
  text-align: center;
}
.fid-table thead th {
  font-weight: 700;
  line-height: 1.2;
  border-bottom: 2px solid #333;
}
.fid-table thead th span { font-weight: 400; font-size: 0.82rem; opacity: 0.85; }
.fid-table td.rowhead, .fid-table th.rowhead {
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}
.fid-table tr.group td {
  font-style: italic;
  background: #f3f3f3;
  font-weight: 600;
  border-top: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
}
/* paper column colors */
.fid-table .col-rae { background: #f8dddd; }
.fid-table .col-vae { background: #fff1cc; }
.fid-table .col-pix { background: #dff2e1; }
.fid-table tbody tr:last-child td { border-bottom: 2px solid #333; }
html[data-theme="dark"] .fid-table thead th,
html[data-theme="dark"] .fid-table tbody tr:last-child td { border-color: #aaa; }
html[data-theme="dark"] .fid-table td.rowhead { color: var(--fg); }
html[data-theme="dark"] .fid-table tr.group td { background: #2a2a2a; color: var(--fg); border-color: #444; }
/* keep the pastel cell colors readable in dark mode: dark text */
.fid-table .col-rae, .fid-table .col-vae, .fid-table .col-pix { color: #222; }

/* ===================== Stat cards (optional) ====================== */
.stat-row {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}
.stat-card {
  border: 1px solid #dbdbdb;
  border-radius: 12px;
  padding: 1.25rem 1.75rem;
  min-width: 140px;
  text-align: center;
}
.stat-num { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 0.9rem; opacity: 0.75; }

/* ===================== Theme toggle =============================== */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font-size: 1.4rem;
  transition: transform 0.2s, color 0.2s;
}
.theme-toggle:hover { color: var(--accent); transform: scale(1.1); }

/* Show the correct icon for the active theme */
html[data-theme="light"] .sun-icon,
html[data-theme="dark"]  .moon-icon { display: none; }
html[data-theme="light"] .moon-icon,
html[data-theme="dark"]  .sun-icon  { display: inline-block; }

/* ===================== Dark theme ================================= */
html[data-theme="dark"] {
  --bg: #1a1a1a;
  --fg: #e8e8e8;
  --card: #262626;
  --border: #3a3a3a;
}
html[data-theme="dark"] body { background-color: var(--bg); color: var(--fg); }
html[data-theme="dark"] .hero,
html[data-theme="dark"] .section { background-color: var(--bg); }
html[data-theme="dark"] .footer { background-color: #111; color: var(--fg); }
html[data-theme="dark"] .title,
html[data-theme="dark"] .subtitle { color: #fff; }
html[data-theme="dark"] .content,
html[data-theme="dark"] .content p { color: var(--fg); }
html[data-theme="dark"] pre,
html[data-theme="dark"] code { background-color: #262626; color: var(--fg); }
html[data-theme="dark"] .stat-card { background-color: var(--card); border-color: var(--border); }
html[data-theme="dark"] .button.is-dark { background-color: #2b2b2b; color: var(--fg); }

/* Mobile */
@media screen and (max-width: 600px) {
  .switcher-buttons { gap: 0.6rem; }
  .switch-btn { font-size: 0.8rem; padding: 0.5rem 1rem; }
}

.section .content {
  font-size: 1.12rem;
  line-height: 1.5;
}

.section h2.title {
  margin-bottom: 2.5rem;
}

.norms-figure figcaption.attn-caption {
  max-width: 840px;
  margin: 1rem auto 0;
}
