:root {
  --bg: #0f1210;
  --surface: #1a1f1d;
  --border: #2a302d;
  --text: #e8ebe9;
  --text-soft: #8a9490;
  --accent: #3daa8a;
  --accent-soft: #1a2f28;
  --accent-dark: #5ec9a8;
  --radius: 8px;
  --maxw: 860px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

/* ---------- Header ---------- */
header.site {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.nav {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px;
}
.brand {
  display: flex; align-items: center; gap: 0;
  font-weight: 600; font-size: 1.02rem; color: var(--text); cursor: pointer;
}
.brand:hover { text-decoration: none; }
.brand .mark {
  padding: 2px 10px; border-radius: 6px;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 1.02rem; line-height: 1.6;
}
.nav-links { display: flex; gap: 2px; }
.nav-links button {
  font: inherit; background: none; border: none; color: var(--text-soft);
  padding: 8px 13px; border-radius: 6px; cursor: pointer; font-size: 0.94rem;
}
.nav-links button:hover { background: var(--accent-soft); color: var(--accent-dark); }
.nav-links button.active { color: var(--accent-dark); font-weight: 600; }

.menu-btn { display: none; background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px; cursor: pointer; }
.menu-btn span { display:block; width:18px; height:2px; background: var(--text); margin: 3px 0; }

/* ---------- Pages ---------- */
.page { display: none; padding: 40px 0 64px; }
.page.active { display: block; }

.eyebrow {
  text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 0.72rem; font-weight: 600; color: var(--accent); margin-bottom: 8px;
}
h1 { font-size: 1.8rem; line-height: 1.2; letter-spacing: -0.01em; margin-bottom: 10px; }
.lead { font-size: 1.04rem; color: var(--text-soft); max-width: 620px; }

/* ---------- Home ---------- */
.actions { margin-top: 22px; display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  font: inherit; font-size: 0.94rem; font-weight: 500;
  padding: 10px 18px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn.secondary { background: transparent; color: var(--accent-dark); }
.btn.secondary:hover { background: var(--accent-soft); }

.home-section { margin-top: 44px; }
.home-section h2 { font-size: 1.05rem; color: var(--text-soft); font-weight: 600; margin-bottom: 12px; }
.plain-list { list-style: none; }
.plain-list li { border-bottom: 1px solid var(--border); }
.plain-list li:first-child { border-top: 1px solid var(--border); }
.plain-list a, .plain-list button.linkish {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  font: inherit; text-align: left; background: none; border: none; cursor: pointer;
  padding: 11px 4px; color: var(--text);
}
.plain-list a:hover, .plain-list button.linkish:hover { color: var(--accent-dark); text-decoration: none; }
.plain-list .meta { color: var(--text-soft); font-size: 0.86rem; margin-left: auto; }

/* ---------- Collapsible categories ---------- */
.category {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 14px;
  overflow: hidden;
}
.category > summary {
  list-style: none;
  cursor: pointer;
  padding: 15px 18px;
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 1.02rem;
  user-select: none;
}
.category > summary::-webkit-details-marker { display: none; }
.category > summary:hover { background: var(--accent-soft); }
.category > summary .arrow {
  transition: transform .15s; color: var(--accent); font-size: 0.8rem; flex: none;
}
.category[open] > summary .arrow { transform: rotate(90deg); }
.category > summary .count {
  margin-left: auto; font-weight: 500; font-size: 0.82rem; color: var(--text-soft);
}

.cat-list { list-style: none; padding: 0 18px 6px; }
.category-body { padding: 14px 18px; }
.category-body > *:last-child { margin-bottom: 0; }
.cat-list li { border-top: 1px solid var(--border); }
.item-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  font: inherit; text-align: left; background: none; border: none; cursor: pointer;
  padding: 12px 2px; color: var(--text);
}
.item-row:hover { color: var(--accent-dark); }
.item-row .item-main { flex: 1; min-width: 0; }
.item-row .item-title { font-weight: 500; }
.item-row .item-desc { font-size: 0.85rem; color: var(--text-soft); }
.item-row .level-tag {
  flex: none; font-size: 0.72rem; font-weight: 600; color: var(--text-soft);
  background: var(--border); padding: 2px 8px; border-radius: 5px;
}
.item-row .open-hint { flex: none; color: var(--accent); font-size: 0.85rem; }

/* resource download link */
.res-row { display: flex; align-items: center; gap: 12px; padding: 12px 2px; }
.res-row .item-main { flex: 1; }
.res-row .item-title { font-weight: 500; }
.res-row .item-desc { font-size: 0.85rem; color: var(--text-soft); }
.res-row .dl {
  flex: none; font-size: 0.84rem; font-weight: 600; color: var(--accent-dark);
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
}
.res-row .dl:hover { background: var(--accent-soft); text-decoration: none; }
.res-row .dl.disabled { opacity: .5; cursor: default; }

/* ---------- Simulation viewer ---------- */
.viewer { display: none; padding: 0; }
.viewer.active { display: block; }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; gap: 16px; border-bottom: 1px solid var(--border);
}
.back-link {
  background: none; border: none; font: inherit; cursor: pointer;
  color: var(--accent-dark); font-weight: 600; font-size: 0.92rem;
  display: flex; align-items: center; gap: 6px;
}
.viewer-bar .vtitle { font-weight: 600; }
.fullscreen-btn {
  background: none; border: 1px solid var(--border); font: inherit; cursor: pointer;
  color: var(--text-soft); font-size: 0.85rem; padding: 6px 12px; border-radius: 6px;
  display: flex; align-items: center; gap: 7px;
}
.fullscreen-btn:hover { background: var(--accent-soft); color: var(--accent-dark); border-color: var(--accent-dark); }
.fullscreen-btn svg { flex: none; }

.viewer-frame:fullscreen,
.viewer-frame:-webkit-full-screen {
  /* inset ties directly to the real viewport rectangle; 100vw/100vh
     can briefly lag behind it during the fullscreen transition in
     some browsers, which would size this box wrong. */
  position: fixed !important; inset: 0 !important;
  width: auto !important; height: auto !important;
  margin: 0 !important; border: none !important;
  background: #000;
}
/* Centred via absolute positioning, not flexbox: Firefox forces this
   element's `display` back to its normal (non-fullscreen) value even
   with `!important`, so `display: flex` on the container never takes
   effect there. top/left 50% + a matching translate(-50%,-50%) in
   app.js's transform works regardless of the parent's display type.
   Default fallback fill (no !important on width/height, so app.js
   can size and scale the iframe with inline styles when it knows the
   simulation's natural content width — see applyFullscreenZoom()). */
.viewer-frame:fullscreen iframe,
.viewer-frame:-webkit-full-screen iframe {
  position: absolute !important;
  top: 50% !important; left: 50% !important;
  width: 100%; height: 100%;
  transform-origin: center center;
  transition: transform .25s ease;
}

/* Full-bleed row holding the simulation frame, with the teaching
   notes stacked underneath it. */
.viewer-layout {
  margin: 22px calc(50% - 50vw);
  width: 100vw;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.viewer-frame {
  width: 100%;
  min-width: 0;
  overflow: hidden;
}
.placeholder-sim {
  display: grid; place-items: center; text-align: center;
  min-height: 460px; padding: 40px; color: var(--text-soft);
}
.placeholder-sim h2 { color: var(--text); margin-bottom: 10px; font-size: 1.3rem; }
.placeholder-sim code {
  background: var(--border); padding: 2px 7px; border-radius: 5px;
  font-size: 0.85rem; color: var(--accent-dark);
}

/* ---------- Prose ---------- */
.prose { max-width: 660px; }
.prose p { margin-bottom: 16px; }
.prose h2 { margin: 26px 0 10px; font-size: 1.2rem; }
.prose ul, .prose ol { margin: 0 0 16px 22px; }
.prose li { margin-bottom: 6px; }

/* ---------- Contact form ---------- */
.contact-form {
  display: flex; flex-direction: column; gap: 16px;
  max-width: 480px; margin: 4px 0 0;
}
.contact-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 0.88rem; font-weight: 600; color: var(--text-soft);
}
.contact-form input, .contact-form textarea {
  font: inherit; font-size: 0.96rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px;
}
.contact-form input:focus, .contact-form textarea:focus {
  outline: none; border-color: var(--accent);
}
.contact-form input:invalid:not(:placeholder-shown) { border-color: #c0524a; }
.contact-form textarea { min-height: 120px; resize: vertical; }
.contact-form button { align-self: flex-start; }

/* ---------- Teaching notes ---------- */
.notes-sidebar {
  display: flex;
  flex-direction: column;
  width: 100%;
  border-top: 1px solid var(--border);
}
.notes-toggle {
  width: 100%;
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 16px; color: var(--text-soft);
}
.notes-toggle:hover { background: var(--accent-soft); color: var(--accent-dark); }
.notes-toggle-arrow { font-size: 0.7rem; transition: transform .2s; transform: rotate(-90deg); }
.notes-sidebar.open .notes-toggle-arrow { transform: rotate(90deg); }
.notes-toggle-label {
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap;
}
.notes-body {
  width: 100%;
  max-height: 0; overflow: hidden;
  transition: max-height .22s ease;
}
.notes-sidebar.open .notes-body { max-height: 70vh; overflow-y: auto; }
/* 1180px mirrors the simulation's own content width (see .wrap in
   mb-sim.html) so the notes line up with the simulation above them. */
.notes-content { width: 100%; max-width: 1180px; margin: 0 auto; padding: 18px; box-sizing: border-box; }
.notes-content > *:first-child { margin-top: 0; }
.notes-content h2, .notes-content h3 { margin: 20px 0 8px; font-size: 1.08rem; }
.notes-content h2:first-child, .notes-content h3:first-child { margin-top: 0; }
.notes-content p { margin-bottom: 14px; }
.notes-content ul, .notes-content ol { margin: 0 0 14px 22px; }
.notes-content li { margin-bottom: 5px; }
.notes-content code { background: var(--border); padding: 1px 6px; border-radius: 4px; font-size: 0.88em; }
.notes-content .katex-display { margin: 12px 0; overflow-x: auto; overflow-y: hidden; }

/* Collapsible question/answer boxes: <details class="qa"> written directly
   in a notes .md file (see the comment in data.js for the exact syntax). */
.notes-content details.qa {
  margin: 4px 0 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
}
.notes-content details.qa summary {
  list-style: none;
  cursor: pointer;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--accent-dark);
  user-select: none;
}
.notes-content details.qa summary::-webkit-details-marker { display: none; }
.notes-content details.qa summary::before {
  content: "\25B6"; display: inline-block; margin-right: 8px;
  font-size: 0.7em; color: var(--accent); transition: transform .15s;
}
.notes-content details.qa:hover summary { background: var(--accent-soft); }
.notes-content details.qa[open] summary::before { transform: rotate(90deg); }
.notes-content details.qa[open] summary { border-bottom: 1px solid var(--border); }
.notes-content details.qa > :not(summary) { padding: 0 14px; }
.notes-content details.qa > :not(summary):first-of-type { padding-top: 12px; }
.notes-content details.qa > :not(summary):last-child { padding-bottom: 12px; margin-bottom: 0; }

/* ---------- Footer ---------- */
footer.site {
  border-top: 1px solid var(--border); padding: 26px 0; margin-top: 32px;
  font-size: 0.85rem; color: var(--text-soft);
}
footer.site .wrap { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.footer-links { display: flex; gap: 18px; flex-wrap: wrap; }
.footer-links a { color: var(--text-soft); }
.footer-links a:hover { color: var(--accent-dark); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .nav-links {
    display: none; position: absolute; top: 60px; left: 0; right: 0;
    background: var(--surface); border-bottom: 1px solid var(--border);
    flex-direction: column; padding: 8px;
  }
  .nav-links.open { display: flex; }
  .nav-links button { text-align: left; width: 100%; }
  .menu-btn { display: block; }
  h1 { font-size: 1.55rem; }
}
