/* ── Reset & Base ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #e8e4db;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --border: #ccc9c0;
  --link: #2c3e7a;
  --sidebar-w: 200px;
  --content-max: 760px;
}

html { font-size: 18px; }

body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: 300;
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  display: flex;
  min-height: 100vh;
}

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

/* ── Sidebar ──────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  border-right: 1px solid var(--border);
  background: var(--bg);
  z-index: 100;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  padding: 2.5rem 1.5rem 1.5rem;
}

.sidebar-top { display: flex; flex-direction: column; gap: .75rem; }

.photo-placeholder {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--border);
  position: relative;
}
.photo-placeholder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-fallback {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: .7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.site-name {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  letter-spacing: .01em;
}

.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  margin-top: 2rem;
}
.nav-links a {
  color: var(--muted);
  font-size: .9rem;
  font-weight: 400;
  padding: .15rem 0;
  display: block;
  transition: color .15s;
}
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-links a.active { color: var(--text); font-weight: 500; }

.sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.sidebar-bottom a {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 400;
}
.sidebar-bottom a:hover { color: var(--text); text-decoration: none; }

.mobile-toggle { display: none; }

/* ── Content ──────────────────────────────────────── */
.content-wrapper {
  margin-left: var(--sidebar-w);
  display: grid;
  grid-template-columns: 65% 35%;
  min-height: 100vh;
  width: calc(100vw - var(--sidebar-w));
}
.content-wrapper.full-width {
  grid-template-columns: 1fr;
}
.content-wrapper.full-width .margin-col {
  display: none;
}

.content {
  padding: 2.5rem 3rem 4rem;
  font-weight: 350;
  overflow: visible;
}

.margin-col {
  padding: 2.5rem 1.5rem 4rem 1.5rem;
  position: relative;
}

.margin-note {
  position: absolute;
  left: 1.5rem;
  padding: .75rem 1rem;
  font-size: .85rem;
  font-weight: 350;
  line-height: 1.55;
  color: #555;
  opacity: 0;
  transition: opacity .35s;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, .25);
  width: fit-content;
  max-width: calc(100% - 3rem);
}
.margin-note.visible {
  opacity: 1;
}
.margin-note strong {
  font-weight: 500;
  color: var(--text);
  display: block;
  margin-bottom: .2rem;
  font-size: .88rem;
}
.margin-note .note-sub {
  font-size: .82rem;
  line-height: 1.5;
  color: #555;
}
.margin-note .note-sub.muted {
  color: var(--muted);
  font-size: .78rem;
  margin-top: .1rem;
}
.margin-note p {
  margin: 0;
  font-size: .84rem;
  line-height: 1.55;
}

h1 { font-size: 1.5rem; font-weight: 500; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; font-weight: 500; margin: 2rem 0 .75rem; }
h3 { font-size: 1.05rem; font-weight: 500; margin: 1.5rem 0 .5rem; }
h4 { font-size: .95rem; font-weight: 500; margin: 1.25rem 0 .5rem; color: var(--muted); }

p { margin-bottom: .85rem; }
.subtitle { color: var(--muted); font-style: italic; margin-bottom: 1.5rem; }

/* ── Publication list ──────────────────────────────── */
.pub-list {
  list-style: none;
  counter-reset: pub;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-left: 0;
}
.pub-list li {
  line-height: 1.5;
}
.pub-authors {
  font-size: .88rem;
  color: var(--muted);
}
.pub-authors em {
  font-style: normal;
  color: var(--text);
  font-weight: 450;
}
.pub-venue {
  font-size: .85rem;
}

.inline-note {
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
  cursor: default;
}

.pub-links {
  font-size: .82rem;
  margin-top: .15rem;
  display: inline-block;
}
.pub-links a {
  font-weight: 450;
}

/* ── Teaching list ────────────────────────────────── */
.teaching-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}
.teaching-list li { padding-left: 0; }
.teaching-list a { font-weight: 400; }

/* ── Post list ────────────────────────────────────── */
/* ── Tag filters ──────────────────────────────────── */
.tag-filters {
  display: flex;
  gap: .4rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}
.tag-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .2rem .6rem;
  font-size: .75rem;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}
.tag-btn:hover { border-color: var(--muted); color: var(--text); }
.tag-btn.active { border-color: var(--text); color: var(--text); font-weight: 500; }
.tag-btn i { margin: 0; }

.post-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.post-list li {
  transition: opacity .15s;
}
.post-date {
  font-size: .85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-right: .5rem;
}
.post-tag-icon {
  font-size: .75rem;
  color: var(--muted);
  margin-right: .4rem;
}

/* ── Post body ────────────────────────────────────── */
.post-title { margin-bottom: .25rem; }
.post-meta { font-size: .85rem; color: var(--muted); display: block; margin-bottom: 1.5rem; }

.post-body h2 { font-size: 1.1rem; margin-top: 2rem; }
.post-body code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: .85em;
  background: #f0f0f0;
  padding: .1em .35em;
  border-radius: 3px;
}
.post-body pre {
  background: #282a36;
  color: #f8f8f2;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1rem 0;
  line-height: 1.5;
  font-size: .85rem;
}
.post-body pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* Pygments (dracula-ish) */
.highlight pre { background: #282a36; color: #f8f8f2; }
.highlight .k, .highlight .kn, .highlight .kd { color: #ff79c6; }
.highlight .s, .highlight .s2, .highlight .s1 { color: #f1fa8c; }
.highlight .c, .highlight .c1, .highlight .cm { color: #6272a4; }
.highlight .nf { color: #50fa7b; }
.highlight .n, .highlight .nb { color: #f8f8f2; }
.highlight .mi, .highlight .mf { color: #bd93f9; }
.highlight .o, .highlight .p { color: #f8f8f2; }

/* ── Clean table (races etc) ──────────────────────── */
.clean-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  margin: .75rem 0 1.5rem;
}
.clean-table th {
  text-align: left;
  font-weight: 500;
  padding: .4rem .75rem .4rem 0;
  border-bottom: 1px solid var(--text);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.clean-table td {
  padding: .35rem .75rem .35rem 0;
  border-bottom: 1px solid var(--border);
}

/* ── Tier list (Columbia style) ───────────────────── */
.tier-section { margin-bottom: 2rem; }
.tier-intro { margin-bottom: 1rem; }

.tier-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: .75rem 0 1.5rem;
}

.tier-row {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tier-row:last-child { border-bottom: none; }

.tier-label {
  width: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: .95rem;
  flex-shrink: 0;
}

.tier-items {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
}

.tier-item {
  padding: .3rem .75rem;
  font-size: .9rem;
  border-bottom: 1px solid var(--border);
}
.tier-item:last-child { border-bottom: none; }

/* tier colors — muted pastels */
.tier-S { background: #fde8e8; color: #9b2c2c; }
.tier-A { background: #fef3e2; color: #9a5b13; }
.tier-B { background: #fefce8; color: #7c6f1b; }
.tier-C { background: #e8f5e9; color: #2e7d32; }
.tier-D { background: #e3f2fd; color: #1565c0; }
.tier-F { background: #f3e5f5; color: #6a1b9a; }

/* ── Tier controls ────────────────────────────────── */
.tier-controls {
  display: flex;
  gap: .4rem;
  margin: .5rem 0;
  flex-wrap: wrap;
}

.tier-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .2rem .6rem;
  font-size: .75rem;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}
.tier-btn:hover { border-color: var(--muted); color: var(--text); }
.tier-btn.active { border-color: var(--text); color: var(--text); font-weight: 500; }

/* ── Dual-tier list (MIT style) ───────────────────── */
.dual-tier-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: .75rem 0 1.5rem;
}
.dual-tier-entry { display: none; }

/* Header */
.dual-tier-header {
  display: grid;
  grid-template-columns: 48px 48px 1fr;
  align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: .7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: var(--bg);
}
.dual-tier-h-col {
  text-align: center;
  padding: .4rem 0;
  font-size: .85rem;
  border-right: 1px solid var(--border);
}
.dual-tier-h-name {
  padding: .4rem .75rem;
}

/* Group — CSS grid so badges and items share row heights */
.dual-tier-group {
  display: grid;
  grid-template-columns: 48px 48px 1fr;
  border-bottom: 1px solid var(--border);
}
.dual-tier-group:last-child {
  border-bottom: none;
}

/* Continuous label (sorted column) */
.dual-tier-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: .95rem;
  border-right: 1px solid var(--border);
}

/* Per-row badge (unsorted column) */
.dual-tier-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: .75rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.dual-tier-group > .dual-tier-badge:last-of-type,
.dual-tier-group > .dual-tier-item:last-of-type {
  border-bottom: none;
}

/* Item (cafe name) — same row as its badge */
.dual-tier-item {
  padding: .35rem .75rem;
  font-size: .9rem;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.dual-tier-note {
  display: block;
  font-size: .8rem;
  color: var(--muted);
  margin-top: .1rem;
  line-height: 1.4;
}

/* Keep the .grade badges for Columbia page */
.grade {
  display: inline-block;
  width: 26px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 3px;
  font-weight: 600;
  font-size: .75rem;
}
.grade-S { background: #fde8e8; color: #9b2c2c; }
.grade-A { background: #fef3e2; color: #9a5b13; }
.grade-B { background: #fefce8; color: #7c6f1b; }
.grade-C { background: #e8f5e9; color: #2e7d32; }
.grade-D { background: #e3f2fd; color: #1565c0; }
.grade-F { background: #f3e5f5; color: #6a1b9a; }

/* ── Unranked ─────────────────────────────────────── */
.unranked {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  font-size: .9rem;
  color: var(--muted);
}
.unranked li::before {
  content: "–";
  margin-right: .4rem;
}

/* ── Bento grid (legacy) ──────────────────────────── */
.bento {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: .75rem;
  margin-top: .5rem;
}

.bento-card {
  background: rgba(255, 255, 255, .45);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.35rem;
  display: flex;
  flex-direction: column;
  transition: background .2s, box-shadow .2s;
  color: var(--text);
  text-decoration: none;
  position: relative;
}
a.bento-card:hover {
  background: rgba(255, 255, 255, .7);
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  text-decoration: none;
}
.bento-card h3 {
  font-size: .95rem;
  font-weight: 500;
  margin: 0 0 .4rem;
  color: var(--text);
}
.bento-card p {
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: .5rem;
  line-height: 1.55;
}
.bento-card .inline-link {
  font-size: .82rem;
}

.bento-emoji {
  font-size: 1.5rem;
  margin-bottom: .5rem;
  display: block;
  line-height: 1;
}

.bento-arrow {
  font-size: .85rem;
  color: var(--muted);
  margin-top: auto;
}

/* MIT card spans 2 rows */
.bento-mit {
  grid-row: 1 / 3;
}

/* ── Fun page – lock body scroll ──────────────────── */
html.fun-active,
body.fun-active {
  overflow: hidden;
  overscroll-behavior: none;
}

/* ── Fun page – horizontal scroll blocks ──────────── */
.content-wrapper.full-width .content {
  padding: 0;
  overflow: hidden;
  position: relative;
  width: calc(100vw - var(--sidebar-w));
  height: 100vh;
}

.fun-scroll-wrap {
  --avail-w: calc(100vw - var(--sidebar-w));
  /* after -90deg rotation, "width" = visual height, "height" = visual width */
  width: 100vh;
  height: var(--avail-w);
  transform: rotate(-90deg) translateX(-100vh);
  transform-origin: top left;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: none;
  scrollbar-width: none;
  position: absolute;
  top: 0;
  left: 0;
}
.fun-scroll-wrap::-webkit-scrollbar { display: none; }

.fun-track {
  display: flex;
  gap: .75rem;
  transform: rotate(90deg) translateY(-100vh);
  transform-origin: top left;
  /* after +90deg counter-rotation, this height = visual height = viewport height */
  height: 100vh;
  align-items: stretch;
  padding: 2rem 3rem;
  /* width here = visual width = must be tall enough to create scroll in outer wrap */
  width: fit-content;
}
.fun-track::after {
  content: '';
  flex-shrink: 0;
  width: 3rem;
}

.fun-col {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  width: 260px;
  min-width: 260px;
  flex-shrink: 0;
}

.fun-block {
  background: rgba(255, 255, 255, .45);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  transition: background .2s, box-shadow .2s;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
}
a.fun-block:hover {
  background: rgba(255, 255, 255, .7);
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  text-decoration: none;
}
.fun-block h3 {
  font-size: .9rem;
  font-weight: 500;
  margin: 0 0 .35rem;
  color: var(--text);
}
.fun-block p {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: .4rem;
  line-height: 1.5;
}
.fun-block .inline-link { font-size: .8rem; }

.fun-emoji {
  font-size: 1.4rem;
  margin-bottom: .4rem;
  display: block;
  line-height: 1;
}

.fun-arrow {
  font-size: .82rem;
  color: var(--muted);
  margin-top: auto;
}

.fun-detail {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .6rem;
  font-size: .75rem;
  color: var(--muted);
  margin-top: .25rem;
}

/* Block sizes — flex-based for stacking */
.fun-tiny   { flex: 0 0 auto; }
.fun-short  { flex: 1 1 0; min-height: 120px; }
.fun-medium { flex: 2 1 0; min-height: 180px; }
.fun-tall   { flex: 3 1 0; min-height: 260px; }

/* Bento race table */
.bento-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .78rem;
  margin-top: .25rem;
}
.bento-table td {
  padding: .2rem .4rem .2rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.bento-table tr:last-child td { border-bottom: none; }
.bento-table a { font-size: .78rem; }

/* ── Toast note (small screens) ───────────────────── */
.note-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: .75rem 1rem;
  font-size: .85rem;
  font-weight: 350;
  line-height: 1.55;
  color: #555;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  box-shadow: 0 2px 12px rgba(0,0,0,.1);
  max-width: 320px;
  width: fit-content;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s;
}
.note-toast.visible {
  opacity: 1;
  pointer-events: auto;
}
.note-toast strong {
  font-weight: 500;
  color: var(--text);
  display: block;
  margin-bottom: .2rem;
  font-size: .88rem;
}
.note-toast .note-sub {
  font-size: .82rem;
  line-height: 1.5;
  color: #555;
}
.note-toast .note-sub.muted {
  color: var(--muted);
  font-size: .78rem;
  margin-top: .1rem;
}
.note-toast p {
  margin: 0;
  font-size: .84rem;
  line-height: 1.55;
}

/* ── Tablet / half-screen ─────────────────────────── */
@media (max-width: 1100px) {
  .content-wrapper {
    grid-template-columns: 1fr;
  }
  .margin-col { display: none; }

  .sidebar {
    width: 160px;
  }
  .content-wrapper {
    margin-left: 160px;
    width: calc(100vw - 160px);
  }

  .dual-tier-header,
  .dual-tier-group {
    grid-template-columns: 40px 40px 1fr;
  }
  .dual-tier-badge { font-size: .7rem; }
  .dual-tier-label { font-size: .85rem; }
  .dual-tier-item { padding: .35rem .5rem; font-size: .85rem; }

  .fun-scroll-wrap {
    --avail-w: calc(100vw - 160px);
  }
  .fun-col {
    width: 240px;
    min-width: 240px;
  }
}

/* ── Mobile ───────────────────────────────────────── */
@media (max-width: 700px) {
  body { flex-direction: column; }

  .sidebar {
    position: fixed;
    left: -260px;
    width: 260px;
    transition: left .25s ease;
    box-shadow: none;
  }
  .sidebar.open {
    left: 0;
    box-shadow: 2px 0 12px rgba(0,0,0,.1);
  }

  .mobile-toggle {
    display: block;
    position: fixed;
    top: .75rem;
    left: .75rem;
    z-index: 200;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: .25rem .5rem;
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
  }

  .sidebar {
    width: 260px;
  }
  .content-wrapper {
    margin-left: 0;
    grid-template-columns: 1fr;
    width: 100%;
  }
  .content {
    padding: 3.5rem .75rem 3rem;
  }

  .dual-tier-header,
  .dual-tier-group {
    grid-template-columns: 32px 32px 1fr;
  }
  .dual-tier-h-col {
    font-size: .6rem;
  }
  .dual-tier-badge { font-size: .6rem; }
  .dual-tier-label { font-size: .75rem; }
  .dual-tier-item { padding: .3rem .5rem; font-size: .85rem; }
  .dual-tier-note { font-size: .75rem; }
  .dual-tier-list { margin-left: -.75rem; margin-right: -.75rem; border-radius: 0; border-left: none; border-right: none; }

  .bento {
    grid-template-columns: 1fr;
  }
  .bento-mit {
    grid-row: auto;
  }

  .fun-scroll-wrap {
    --avail-w: 100vw;
  }
  .fun-track {
    padding: 1rem 1.25rem;
  }
  .fun-col {
    width: 220px;
    min-width: 220px;
  }
}
