:root {
  --bg: #fafbfc;
  --fg: #0f172a;
  --muted: #6b7280;
  --card: #ffffff;
  --border: #e5e7eb;
  --accent: #0ea5e9;
  --accent-2: #2563eb;
  --chip-bg: #eef2ff;
  --chip-fg: #4338ca;
  --chip-2-bg: #e0f2fe;
  --chip-2-fg: #075985;
}

* { box-sizing: border-box; }
html, body { height: 100%; text-align: justify; }
body {
  margin: 0;
  font: 16px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--fg);
  background: var(--bg);
}

/* -------- header -------- */
header {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(6px);
  background: rgba(250,251,252,.9);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 16px;
}
header a { color: #111827; font-weight: 600; text-decoration: none; padding: 6px 8px; border-radius: 8px; }
header a:hover { background: #f3f4f6; }
header a + a { color: inherit; }
header input {
  margin-left: auto; width: 380px; max-width: 50vw; height: 36px;
  border-radius: 10px; border: 1px solid var(--border);
  padding: 0 12px; outline: none; background: #fff;
}

.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }

/* -------- text & links -------- */
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

h1 { font-size: 34px; margin: 0 0 8px; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 16px; margin: 0; }
.small { font-size: 15px; color: inherit; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  background: #eef2f7; color: #334155; font-size: 11px; border: 1px solid var(--border);
}
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: var(--chip-bg); color: var(--chip-fg); border: 1px solid #dbeafe;
}
.chip2 {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: var(--chip-2-bg); color: var(--chip-2-fg); border: 1px solid #bae6fd;
}
.count {
  font-size: 11px; color: #475569; background: #f1f5f9;
  padding: 2px 6px; border-radius: 999px; border: 1px solid var(--border);
}

/* -------- cards -------- */
.card {
  background: #fff; border: 1px solid #e9edf2; border-radius: 12px; padding: 12px;
  transition: box-shadow .12s ease, transform .06s ease, border-color .12s ease;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.05); transform: translateY(-1px); border-color: #e2e8f0; }
.card a { color: inherit; }

/* -------- grid -------- */
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1fr 1fr; } }

/* -------- collapsibles (uniform) -------- */
.section { margin: 18px 0 8px; padding: 0; }
.section + .section { margin-top: 6px; }
.section-head {
  display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; padding: 8px 12px;
  background: #fff; border: 1px solid #e9edf2; border-radius: 12px;
}
.section-head .caret {
  width: 18px; text-align: center; color: #64748b; transform: rotate(-90deg); transition: transform .12s ease;
}
.section.open .section-head .caret { transform: rotate(0deg); }

/* sticky variant for heads under global header */
.sticky-head { position: sticky; top: 56px; z-index: 2; background: #fff; }

/* outline preview / markdown */
.markdown { line-height: 1.6; }
.markdown h1, .markdown h2 { margin-top: 18px; }
.toggle { cursor: pointer; }
.prose { line-height: 1.6; }

/* timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 64px 1fr; column-gap: 12px; align-items: baseline; margin: 6px 0; }
.timeline .yr {
  display: inline-block; font-weight: 600; font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: #f3f4f6; color: #374151; text-align: center;
}
.timeline .evt { line-height: 1.5; }

/* themes list */
.theme-list { margin: 0; padding-left: 18px; }
.theme-list li { margin: 6px 0; }
.theme-list b { font-weight: 600; }

/* -------- toolbar (sort bar) -------- */
.sortbar {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 12px; flex-wrap: wrap;
}
.sortbar-label { font-size: 14px; color: #64748b; }
.select-wrap { position: relative; display: inline-flex; align-items: center; }
.select-wrap::after {
  content: "▾"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: #64748b; font-size: 12px; pointer-events: none;
}
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding: 8px 30px 8px 12px; border: 1px solid #e5e7eb; border-radius: 9999px;
  background: #f8fafc; font-size: 14px; line-height: 1.2; color: #0f172a; outline: none;
}
.select:focus {
  border-color: #94a3b8; box-shadow: 0 0 0 3px rgba(100,116,139,.15);
}

/* -------- work lists -------- */
.work-list { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 8px; }
.work-list .card { grid-column: 1 / -1; width: 100%; }

/* compact work rows */
.card.work-row {
  background: #f8fafc; border: 1px solid #eef1f4; padding: 8px 10px;
}
.card.work-row b { font-size: 15px; font-weight: 600; }
.card.work-row .small, .card.work-row .meta { font-size: 12px; color: #6b7280; }

/* horizontal meta block in row head */
.work-row .work-meta { display: flex; gap: 6px; align-items: center; }
@media (max-width: 720px) { .work-row .work-meta { align-self: flex-end; } }

/* Remove gray background + padding from collapsible sections wrapping work cards */
.section {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  margin: 0;
  padding: 0;
}

/* Keep spacing tidy between work rows */
.work-list {
  margin-top: 6px;
  gap: 6px;
}

/* Make work rows float cleanly — no extra border layering */
.work-list .card.work-row {
  background: #fff;           /* pure white card */
  border: 1px solid #e6e8eb;  /* light line */
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  border-radius: 8px;
}

/* remove the outer card.section chrome */
.card.section {
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

/* domain badge tone */
.chip-domain {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #dbeafe;
}


:root { --wrap: 1100px; --gut: 16px; --header-h: 56px; }

/* 1) Page width rule (container + header match exactly) */
.container{
  width: min(var(--wrap), calc(100vw - 2*var(--gut)));
  margin: 24px auto;
  padding: 0 var(--gut);
}

/* 2) Header becomes a shell; inner matches .container width */
header{
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(6px);
  background: rgba(250,251,252,.9);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  padding: 0;                 /* remove global padding */
  display: block;             /* no flex here */
}
header .header-inner{
  width: min(var(--wrap), calc(100vw - 2*var(--gut)));
  height: var(--header-h);
  margin: 0 auto;             /* center with page */
  padding: 0 var(--gut);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;         /* anchor popover */
}

/* 3) Left: page switcher */
.page-switch{
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; cursor: pointer; user-select: none;
  padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff;
}
.page-switch .caret{ transition: transform .12s ease; }
.page-switch.open .caret{ transform: rotate(180deg); }

/* 4) Right: search input stays on the right edge of inner width */
header input{
  margin-left: auto;
  width: clamp(240px, 42vw, 620px);
  max-width: 100%;
  height: 36px; border-radius: 10px; border: 1px solid var(--border);
  padding: 0 12px; outline: none; background: #fff;
}

/* 5) Horizontal popover, full inner width (no vertical scroll) */
.page-popover{
  position: absolute;
  left: var(--gut);
  top: calc(100% + 8px);
  width: calc(100% - 2*var(--gut));
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.06);
  padding: 10px; z-index: 60;

  display: flex; flex-wrap: nowrap; gap: 12px;
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
}
.page-popover a{
  flex: 0 0 auto; white-space: nowrap; font-weight: 600;
  padding: 6px 8px; border-radius: 8px; text-decoration: none; color: inherit;
}
.page-popover a:hover{ background:#f3f4f6; }

/* 6) Centered search results dropdown (matches page width) */
.search-results{
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  top: calc(var(--header-h) + 8px);
  width: min(700px, calc(100vw - 2*var(--gut)));
  max-height: 60vh; overflow: auto;
}

/* 7) Small screens: stack cleanly */
@media (max-width: 640px){
  header .header-inner{ flex-wrap: wrap; height: auto; padding: 8px var(--gut); }
  .page-switch{ order: 1; }
  header input{ order: 2; flex: 1 1 100%; }
  .search-results{ top: 96px; }
}

:root { --wrap: 1100px; --gut: 16px; --header-h: 56px; }

/* 1) Page width rule (container + header match exactly) */
.container{
  width: min(var(--wrap), calc(100vw - 2*var(--gut)));
  margin: 24px auto;
  padding: 0 var(--gut);
}

/* 2) Header becomes a shell; inner matches .container width */
header{
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(6px);
  background: rgba(250,251,252,.9);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  padding: 0;                 /* remove global padding */
  display: block;             /* no flex here */
}
header .header-inner{
  width: min(var(--wrap), calc(100vw - 2*var(--gut)));
  height: var(--header-h);
  margin: 0 auto;             /* center with page */
  padding: 0 var(--gut);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;         /* anchor popover */
}

/* 3) Left: page switcher */
.page-switch{
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; cursor: pointer; user-select: none;
  padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff;
}
.page-switch .caret{ transition: transform .12s ease; }
.page-switch.open .caret{ transform: rotate(180deg); }

/* 4) Right: search input stays on the right edge of inner width */
header input{
  margin-left: auto;
  width: clamp(240px, 42vw, 620px);
  max-width: 100%;
  height: 36px; border-radius: 10px; border: 1px solid var(--border);
  padding: 0 12px; outline: none; background: #fff;
}

/* 5) Horizontal popover, full inner width (no vertical scroll) */
.page-popover{
  position: absolute;
  left: var(--gut);
  top: calc(100% + 8px);
  width: calc(100% - 2*var(--gut));
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.06);
  padding: 10px; z-index: 60;

  display: flex; flex-wrap: nowrap; gap: 12px;
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
}
.page-popover a{
  flex: 0 0 auto; white-space: nowrap; font-weight: 600;
  padding: 6px 8px; border-radius: 8px; text-decoration: none; color: inherit;
}
.page-popover a:hover{ background:#f3f4f6; }

/* 6) Centered search results dropdown (matches page width) */
.search-results{
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  top: calc(var(--header-h) + 8px);
  width: min(700px, calc(100vw - 2*var(--gut)));
  max-height: 60vh; overflow: auto;
}

/* 7) Small screens: stack cleanly */
@media (max-width: 640px){
  header .header-inner{ flex-wrap: wrap; height: auto; padding: 8px var(--gut); }
  .page-switch{ order: 1; }
  header input{ order: 2; flex: 1 1 100%; }
  .search-results{ top: 96px; }
}

/* --- vertical page popover instead of horizontal --- */
.page-popover {
  position: absolute;
  left: var(--gut);
  top: calc(100% + 8px);
  width: auto;                     /* fit to content */
  min-width: 160px;                /* tidy min width */
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.06);
  padding: 6px 0;
  z-index: 60;

  display: flex;
  flex-direction: column;          /* vertical layout */
  gap: 0;
  overflow: visible;
  white-space: nowrap;
}

.page-popover a {
  display: block;
  padding: 8px 14px;
  text-decoration: none;
  color: inherit;
  font-weight: 500;
}

.page-popover a:hover {
  background: #f3f4f6;
}


/* --- clean, compact vertical dropdown --- */
.page-popover {
  position: absolute;
  left: 0;                        /* align exactly with trigger */
  top: calc(100% + 4px);
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  padding: 4px 0;
  z-index: 60;

  display: flex;
  flex-direction: column;
  gap: 0;
}

.page-popover a {
  display: block;
  padding: 6px 12px;
  text-decoration: none;
  color: #111827;
  font-weight: 500;
  line-height: 1.4;
}

.page-popover a:hover {
  background: #f3f4f6;
}

/* keep the dropdown aligned even when the header is centered */
header .header-inner { position: relative; }
.page-switch { position: relative; }


/* --- final tidy vertical dropdown: no side offset --- */
.page-popover {
  position: absolute;
  left: 0;                      /* no side gap */
  right: auto;
  top: calc(100% + 4px);
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  padding: 4px 0;
  z-index: 60;

  display: flex;
  flex-direction: column;
  gap: 0;
}

.page-popover a {
  display: block;
  padding: 6px 12px;
  text-decoration: none;
  color: #111827;
  font-weight: 500;
  line-height: 1.4;
}

.page-popover a:hover {
  background: #f3f4f6;
}

/* ensure alignment under trigger */
header .header-inner { position: relative; }
.page-switch { position: relative; }


/* Header shell already set; just make contents flex smart */
header .header-inner{
  display: flex;
  align-items: center;
  gap: 8px;              /* tighter on small screens */
}

/* Page label stays its natural size */
.page-switch{
  flex: 0 0 auto;
}

/* SEARCH: fill the remaining header width */
header input{
  flex: 1 1 auto;        /* <-- grow + shrink to available space */
  width: auto;           /* ignore earlier fixed/clamped widths */
  max-width: none;       /* remove the desktop cap so it can truly fill */
  min-width: 120px;      /* keep a sane minimum on tiny screens */
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0 12px;
  background: #fff;
}

/* If you still want a soft cap on big desktops, uncomment this: */
/* @media (min-width: 1100px){ header input{ max-width: 720px; } } */

/* When header wraps on very narrow iPhones, let the input take the full row */
@media (max-width: 520px){
  header .header-inner{ flex-wrap: wrap; }
  .page-switch{ order: 1; }
  header input{ order: 2; flex: 1 1 100%; }
}


/* Make the search fill the available header space */
header .header-inner > input{
  flex: 1 1 0 !important;   /* grow + shrink from zero */
  min-width: 0;             /* allow flexbox to actually shrink */
  width: auto !important;   /* override the 380px */
  max-width: none !important;
  margin-left: 0 !important;/* override the auto push */
}

/* When it wraps to a new line on tiny screens, let it span full width */
@media (max-width: 560px){
  header .header-inner{ flex-wrap: nowrap; }
  header .header-inner > input{
    flex: 1 1 100% !important;
  }

}


/* don't let card hover override transform on the dropdown */
.card:hover:not(.no-raise){
  box-shadow: 0 4px 16px rgba(0,0,0,.05);
  transform: translateY(-1px);
}

/* keep the dropdown's transform stable even on hover */
.search-results{
  transform: translateX(-50%) !important;
}
.search-results:hover{
  transform: translateX(-50%) !important;
}


.section .section-head { border-radius: 10px; }
.section.open .section-head    { border-left: 3px solid var(--accent); background: #fff; }
.section:not(.open) .section-head { border-left: 3px solid transparent; background: #f7f9fc; }
.section .caret { transition: transform .15s ease, opacity .15s; opacity: .6; }
.section.open .caret { transform: rotate(90deg); opacity: 1; }
.section.open .details { margin-left: 10px; border-left: 1px dashed var(--border); padding-left: 10px; }


/* ——— Rhythm shim (paste at end) ——— */
:root { --rh-font: 16px; --rh-pad-x: 12px; --rh-pad-y: 8px; --rh-gap: 8px; }

/* 1) Make group titles look the same everywhere */
.section-head h2,
.section-head h3,
.section-head .small b {
  font-size: var(--rh-font);
  line-height: 1.4;
  margin: 0;
  font-weight: 700;
}

/* 2) Unify section head/body padding */
.section-head {
  padding: var(--rh-pad-y) var(--rh-pad-x);
}
.section.open .details {
  padding: var(--rh-gap) var(--rh-pad-x) var(--rh-pad-x);
}

/* 3) Keep stripped .card.section looking like the others (spacing only) */
.card.section { padding: 0; }            /* keep chrome off */
.card.section .section-head {             /* but keep the spacing consistent */
  border-radius: 10px;
}

/* 4) Markdown rhythm so Domain/Category pages don’t look “airier” */
.markdown { line-height: 1.55; }
.markdown h1, .markdown h2 { margin: 14px 0 0px; }

/* 5) Compact work rows match the same padding rhythm */
.work-list .card.work-row { padding: 10px 12px; }

/* Podcasts layout */
.podcasts .lead { color:#334155; margin-top:4px; }
.podcast-grid {
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(280px,1fr));
  gap:12px;
  margin-top:10px;
}
.podcast-card { padding:14px; }
.podcast-title { margin:0 0 6px 0; font-size:1rem; }
.podcast-actions { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:8px; }

/* Buttons reused elsewhere if you want */
.btn { display:inline-block; padding:8px 12px; border-radius:8px; text-decoration:none; font-size:14px; }
.btn.primary { background:#1d4ed8; color:#fff; }
.btn.secondary { background:#e2e8f0; color:#0f172a; border:none; cursor:pointer; }

/* URL chip */
.rss-url {
  display:block;
  font-size:12px;
  background:#f8fafc;
  color:#475569;
  border:1px dashed #e2e8f0;
  border-radius:8px;
  padding:6px 8px;
  word-break:break-all;
}

/* bullets */
.exam-item-list {
  list-style: disc;
  padding-left: 1.2rem;
  margin: 0;
}

.exam-item {
  margin-bottom: 10px;
}

.exam-item-text {
  font-weight: 600;
}

/* existing note */
.exam-note-box {
  margin-top: 4px;
  padding: 6px 10px;
  background: #f7f7f7;
  border-radius: 4px;
  border-left: 3px solid #ccc;
  white-space: pre-wrap;
  cursor: pointer;
}

.exam-note-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #777;
  margin-bottom: 2px;
}

.exam-note-empty {
  color: #999;
  font-style: italic;
}

/* editing state */
.exam-note-editing {
  cursor: default;
}

.exam-note-actions {
  margin-top: 4px;
  display: flex;
  gap: 6px;
}

/* empty state: minimal inline control */
.exam-note-add {
  margin-top: 2px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.exam-note-add:hover {
  text-decoration: underline;
}
