/* ============================================================
   Study portal — cool graphite ground, warm paper reading surface
   Breakpoints: folded <600px · unfolded 600–1023px · desktop ≥1024px
   ============================================================ */

:root {
  --ground: #20242b;
  --ground-2: #2a2f38;
  --ground-3: #343a45;
  --ground-text: #cdd3dc;
  --ground-muted: #8b93a0;
  --paper: #f7f4ee;
  --paper-2: #efeae0;
  --card: #fffdf7;
  --ink: #23262b;
  --ink-muted: #5d636e;
  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --accent-wash: #e4efed;
  --rule: #ddd6c9;
  --danger: #a8322f;
  --ok: #2e6b34;
  --sans: "Segoe UI Variable Text", "Segoe UI", Roboto, "Noto Sans", system-ui, sans-serif;
  --display: "Segoe UI Variable Display", "Segoe UI", Roboto, system-ui, sans-serif;
  --serif: Charter, "Bitstream Charter", Cambria, Georgia, "Noto Serif", serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", monospace;
  --topbar-h: 3.25rem;
}

* { box-sizing: border-box; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--ground);
  overflow: hidden; /* the panes scroll, not the page */
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
#nav :focus-visible, #topbar :focus-visible {
  outline-color: #7fd6cc;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- frame ---------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

#topbar {
  flex: none;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .75rem;
  background: var(--ground);
  color: var(--ground-text);
  border-bottom: 1px solid var(--ground-3);
}

#topbar button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--ground-text);
}
#topbar button:hover { background: var(--ground-2); }

#glossary-btn {
  font-size: .875rem;
  padding: 0 .75rem;
  border: 1px solid var(--ground-3);
}

#bookmark-btn.active svg path { fill: var(--accent); stroke: var(--accent); }

#crumb {
  flex: 1;
  min-width: 0;
  font-size: .875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ground-muted);
}
#crumb strong { color: var(--ground-text); font-weight: 600; }

#topbar-actions { display: flex; gap: .25rem; }

#shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  position: relative;
}

/* ---------- nav ---------- */

#nav {
  background: var(--ground);
  color: var(--ground-text);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#nav-inner { padding: 1rem .875rem 2rem; }

.nav-course {
  font-family: var(--display);
  font-size: .8125rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ground-muted);
  margin: 0 .5rem .75rem;
}

.nav-list { list-style: none; margin: 0 0 1rem; padding: 0; }

.nav-item a {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  padding: .55rem .5rem;
  border-radius: 8px;
  color: var(--ground-text);
  text-decoration: none;
  font-size: .9375rem;
  line-height: 1.35;
}
.nav-item a:hover { background: var(--ground-2); }
.nav-item a.current { background: var(--ground-2); color: #fff; }

.nav-num {
  font-family: var(--mono);
  font-size: .75rem;
  color: var(--ground-muted);
  flex: none;
}
.nav-item a.current .nav-num { color: #7fd6cc; }

.nav-done {
  margin-left: auto;
  color: #7fd6cc;
  font-size: .8125rem;
  flex: none;
}

.nav-sections { list-style: none; margin: 0 0 .25rem; padding: 0 0 0 1.6rem; }
.nav-sections a {
  display: block;
  padding: .3rem .5rem;
  font-size: .8125rem;
  color: var(--ground-muted);
  text-decoration: none;
  border-radius: 6px;
  line-height: 1.35;
}
.nav-sections a:hover { background: var(--ground-2); color: var(--ground-text); }

.nav-heading {
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ground-muted);
  margin: 1.25rem .5rem .4rem;
}

.nav-bookmarks { list-style: none; margin: 0; padding: 0; }
.nav-bookmarks li { display: flex; align-items: center; gap: .25rem; }
.nav-bookmarks a {
  flex: 1;
  min-width: 0;
  padding: .35rem .5rem;
  font-size: .8125rem;
  color: var(--ground-text);
  text-decoration: none;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-bookmarks a:hover { background: var(--ground-2); }
.bookmark-del {
  flex: none;
  min-width: 2rem;
  min-height: 2rem;
  color: var(--ground-muted);
  border-radius: 6px;
}
.bookmark-del:hover { color: #e39a97; background: var(--ground-2); }
.nav-empty { font-size: .8125rem; color: var(--ground-muted); margin: 0 .5rem; }

.nav-data { display: grid; gap: .5rem; margin-top: .5rem; }
.nav-data button {
  display: block;
  width: 100%;
  text-align: center;
  padding: .55rem .75rem;
  border: 1px solid var(--ground-3);
  border-radius: 8px;
  font-size: .875rem;
  color: var(--ground-text);
}
.nav-data button:hover { background: var(--ground-2); }
.nav-data .primary-data {
  border-color: var(--accent);
  color: #9adfd7;
}
.nav-storage-note {
  font-size: .75rem;
  line-height: 1.5;
  color: var(--ground-muted);
  margin: .75rem .5rem 0;
}

/* ---------- content pane ---------- */

#content {
  position: relative;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  overscroll-behavior: contain;
}

#view {
  max-width: 43rem;
  margin: 0 auto;
  padding: 1.25rem 1.125rem 5rem;
}

/* ---------- outline (desktop) ---------- */

#outline {
  display: none;
  overflow-y: auto;
  background: var(--paper);
  border-left: 1px solid var(--rule);
}
#outline-inner { padding: 1.5rem 1rem; }
#outline .outline-title {
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-muted);
  margin: 0 0 .6rem;
}
#outline ul { list-style: none; margin: 0; padding: 0; }
#outline a {
  display: block;
  padding: .3rem .5rem;
  font-size: .8125rem;
  line-height: 1.4;
  color: var(--ink-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
}
#outline a:hover { color: var(--ink); background: var(--paper-2); }
#outline a.active { color: var(--accent-dark); border-left-color: var(--accent); font-weight: 600; }

/* ---------- breakpoints ---------- */

/* folded: off-canvas nav */
@media (max-width: 599.98px) {
  #nav {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: min(20rem, 85vw);
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 40;
    box-shadow: none;
  }
  #nav.open {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0,0,0,.45);
  }
  #scrim {
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(15,18,22,.5);
    z-index: 35;
  }
}

/* unfolded: two panes */
@media (min-width: 600px) {
  #shell { grid-template-columns: 15rem minmax(0, 1fr); }
  #nav-toggle { display: none; }
  #scrim { display: none !important; }
  #view { padding: 2rem 2rem 6rem; }
}

/* desktop: three panes */
@media (min-width: 1024px) {
  #shell { grid-template-columns: 16.5rem minmax(0, 1fr) 14rem; }
  #outline { display: block; }
  #view { padding: 2.5rem 2.5rem 7rem; }
}

/* ---------- home ---------- */

.home-kicker {
  font-family: var(--mono);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--accent-dark);
  margin: .5rem 0 .4rem;
}
.home-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.6rem, 5vw, 2.3rem);
  letter-spacing: -.02em;
  line-height: 1.15;
  margin: 0 0 .5rem;
}
.home-sub {
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink-muted);
  margin: 0 0 2rem;
  line-height: 1.6;
}

.resume-link {
  display: inline-block;
  margin: 0 0 1.5rem;
  padding: .6rem 1rem;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: .9375rem;
}
.resume-link:hover { background: var(--accent-dark); }

.chapter-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  margin: 0 0 1rem;
  text-decoration: none;
  color: var(--ink);
}
.chapter-card:hover { border-color: var(--accent); }
.chapter-card .cc-top {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  font-family: var(--mono);
  font-size: .75rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
}
.chapter-card .cc-done { color: var(--ok); margin-left: auto; text-transform: none; letter-spacing: 0; }
.chapter-card h2 {
  font-family: var(--display);
  font-size: 1.25rem;
  letter-spacing: -.01em;
  margin: .35rem 0 .35rem;
}
.chapter-card p {
  font-family: var(--serif);
  font-size: .9375rem;
  line-height: 1.6;
  color: var(--ink-muted);
  margin: 0;
}

/* ---------- chapter body: reading is the product ---------- */

.chapter-kicker {
  font-family: var(--mono);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--accent-dark);
  margin: .5rem 0 0;
}

.chapter-body {
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.75;
}

.chapter-body h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.7rem, 5.5vw, 2.4rem);
  letter-spacing: -.02em;
  line-height: 1.12;
  margin: .35rem 0 1rem;
}

.chapter-body h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: -.015em;
  line-height: 1.25;
  margin: 2.5rem 0 .75rem;
  scroll-margin-top: .75rem;
}

.chapter-body h3 {
  font-family: var(--display);
  font-weight: 650;
  font-size: 1.1rem;
  margin: 1.75rem 0 .5rem;
  scroll-margin-top: .75rem;
}

.chapter-body p { margin: 0 0 1rem; }

.chapter-body hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2rem auto;
  width: 100%;
}

.chapter-body blockquote {
  margin: 1.25rem 0;
  padding: .75rem 1.1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-wash);
  border-radius: 0 8px 8px 0;
  font-style: italic;
}
.chapter-body blockquote p { margin: 0; }

.chapter-body ul, .chapter-body ol { margin: 0 0 1rem; padding-left: 1.4rem; }
.chapter-body li { margin: 0 0 .45rem; }

.chapter-body a { color: var(--accent-dark); text-underline-offset: 2px; }

.chapter-body code {
  font-family: var(--mono);
  font-size: .85em;
  background: var(--paper-2);
  border-radius: 4px;
  padding: .1em .3em;
  overflow-wrap: anywhere;
}

/* ---------- glossary terms in body ---------- */

.term {
  font: inherit;
  color: inherit;
  border-bottom: 1px dotted var(--accent);
  padding-bottom: 1px;
  cursor: pointer;
  text-align: inherit;
}
.term:hover { color: var(--accent-dark); border-bottom-style: solid; }

/* ---------- code blocks ---------- */

.code-block {
  margin: 1.25rem 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--ground-2);
  color: #d7dde6;
  font-size: .8125rem;
}

.code-block figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem .4rem .4rem .9rem;
  font-family: var(--mono);
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ground-muted);
  background: var(--ground);
}

.copy-btn {
  font-family: var(--sans);
  font-size: .75rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ground-text);
  border: 1px solid var(--ground-3);
  border-radius: 6px;
  padding: .35rem .7rem;
  min-height: 2rem;
}
.copy-btn:hover { background: var(--ground-3); }
.copy-btn.copied { color: #9adfd7; border-color: var(--accent); }

.code-block pre {
  margin: 0;
  padding: .9rem 1rem;
  font-family: var(--mono);
  line-height: 1.6;
  white-space: pre-wrap;       /* wrap, never scroll */
  overflow-wrap: anywhere;
}

.j-key { color: #8fd3f4; }
.j-str { color: #b8dba0; }
.j-num { color: #eabf8d; }
.j-lit { color: #d0a9e8; }

/* agent transcripts: numbered lines, hanging indent, wrap */
.transcript pre { padding: .9rem 1rem; }
.transcript .tline {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding-left: 5ch;
  text-indent: -5ch;
  min-height: 1.3em;
}
.transcript .tline .tno { color: #7fd6cc; }
.transcript .tline .trole { color: var(--ground-muted); }

@media (max-width: 599.98px) {
  .code-block { font-size: .75rem; }
}

/* ---------- tables: the signature element ---------- */

.table-wrap { margin: 1.5rem 0; }

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: .875rem;
  line-height: 1.55;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
}

/* border-radius on collapsed tables needs the wrapper */
.table-wrap { border-radius: 10px; overflow: hidden; border: 1px solid var(--rule); }
.md-table { border: none; border-radius: 0; }

.md-table th {
  background: var(--ground);
  color: var(--ground-text);
  font-family: var(--mono);
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 600;
  text-align: left;
  padding: .65rem .8rem;
}

.md-table td {
  padding: .65rem .8rem;
  border-top: 1px solid var(--rule);
  vertical-align: top;
  overflow-wrap: anywhere;
}

.md-table td:first-child { font-weight: 600; }
.md-table tbody tr:nth-child(even) { background: var(--paper); }

/* Below 600px every table becomes stacked label/value cards.
   Horizontal scroll is a build failure. */
@media (max-width: 599.98px) {
  .table-wrap { border: none; border-radius: 0; overflow: visible; }

  .md-table, .md-table tbody, .md-table tr, .md-table td { display: block; width: 100%; }
  .md-table { background: none; }
  .md-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); }

  .md-table tr {
    background: var(--card);
    border: 1px solid var(--rule);
    border-left: 3px solid var(--accent);
    border-radius: 0 10px 10px 0;
    padding: .35rem .9rem .7rem;
    margin: 0 0 .75rem;
  }
  .md-table tbody tr:nth-child(even) { background: var(--card); }

  .md-table td {
    border: none;
    padding: .45rem 0 0;
  }
  .md-table td:first-child { font-weight: 650; }

  .md-table td::before {
    content: attr(data-label);
    display: block;
    font-family: var(--mono);
    font-size: .625rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--ink-muted);
    margin-bottom: .1rem;
  }
}

/* ---------- materials (readings / slides) ---------- */

.materials {
  margin: 1.5rem 0;
  padding: 1rem 1.1rem;
  background: var(--paper-2);
  border-radius: 10px;
  font-family: var(--sans);
  font-size: .875rem;
}
.materials h2 {
  font-family: var(--mono);
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--ink-muted);
  margin: 0 0 .5rem;
}
.materials ul { list-style: none; margin: 0; padding: 0; }
.materials li { margin: 0 0 .35rem; }
.materials a { color: var(--accent-dark); }
.materials .req {
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent-dark);
  margin-left: .4rem;
}

/* ---------- exercises ---------- */

.exercises-block { margin-top: 3rem; font-family: var(--sans); }
.exercises-block > h2 {
  font-family: var(--display);
  font-size: 1.4rem;
  letter-spacing: -.015em;
  margin: 0 0 .35rem;
}
.exercises-intro {
  font-family: var(--serif);
  color: var(--ink-muted);
  font-size: .9375rem;
  margin: 0 0 1.25rem;
}

.grading-banner {
  font-size: .8125rem;
  padding: .6rem .9rem;
  border-radius: 8px;
  margin: 0 0 1rem;
  background: var(--paper-2);
  color: var(--ink-muted);
}
.grading-banner.offline { background: #efe6d4; color: #6b5518; }

.exercise-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1.1rem 1.2rem 1.2rem;
  margin: 0 0 1.25rem;
}
.exercise-card h3 {
  font-family: var(--display);
  font-size: 1.05rem;
  margin: 0 0 .4rem;
}
.exercise-card .ex-prompt {
  font-family: var(--serif);
  font-size: .9375rem;
  line-height: 1.65;
  margin: 0 0 .85rem;
}

.exercise-card textarea {
  width: 100%;
  min-height: 7.5rem;
  font: .9375rem/1.6 var(--serif);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: .7rem .8rem;
  resize: vertical;
}
.exercise-card textarea:focus-visible { outline-offset: 0; }

.ex-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .7rem;
  flex-wrap: wrap;
}
.ex-submit {
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: .55rem 1.1rem;
  font-size: .875rem;
  min-height: 2.75rem;
}
.ex-submit:hover { background: var(--accent-dark); }
.ex-submit:disabled { opacity: .55; cursor: default; }
.ex-status { font-size: .8125rem; color: var(--ink-muted); }
.ex-status.queued { color: #6b5518; }
.ex-status.error { color: var(--danger); }

.feedback { margin-top: 1rem; display: grid; gap: .7rem; }
.feedback .fb-verdict {
  display: inline-block;
  justify-self: start;
  font-family: var(--mono);
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: .3rem .6rem;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-muted);
}
.fb-verdict.correct { background: #dcebdc; color: var(--ok); }
.fb-verdict.partially_correct { background: #f0e7cd; color: #6b5518; }
.fb-verdict.off_track { background: #f2dcdb; color: var(--danger); }

.fb-region { border: 1px solid var(--rule); border-radius: 8px; padding: .7rem .9rem; font-size: .875rem; line-height: 1.6; background: var(--paper); }
.fb-region h4 {
  font-family: var(--mono);
  font-size: .625rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--ink-muted);
  margin: 0 0 .35rem;
}
.fb-region ul { margin: 0; padding-left: 1.1rem; }
.fb-region li { margin: 0 0 .25rem; }
.fb-region p { margin: 0; }
.fb-region.fb-hint { background: var(--accent-wash); border-color: var(--accent); }

.ex-history { margin-top: .8rem; font-size: .8125rem; }
.ex-history summary { cursor: pointer; color: var(--ink-muted); }
.ex-history .attempt { border-top: 1px solid var(--rule); padding: .6rem 0; }
.ex-history .attempt-meta { font-size: .75rem; color: var(--ink-muted); margin-bottom: .3rem; }
.ex-history blockquote { margin: 0 0 .4rem; padding-left: .8rem; border-left: 2px solid var(--rule); font-family: var(--serif); }

/* ---------- chapter footer: notes, complete, next ---------- */

.notes-block { margin-top: 2rem; font-family: var(--sans); }
.notes-block summary {
  cursor: pointer;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 650;
  padding: .4rem 0;
}
.notes-block textarea {
  width: 100%;
  min-height: 7rem;
  margin-top: .5rem;
  font: .9375rem/1.6 var(--serif);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: .7rem .8rem;
  resize: vertical;
}
.notes-hint { font-size: .75rem; color: var(--ink-muted); margin: .3rem 0 0; }

.chapter-footer {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  display: grid;
  gap: 1rem;
}
.complete-btn {
  justify-self: start;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: .65rem 1.2rem;
  font-size: .9375rem;
  min-height: 2.75rem;
}
.complete-btn:hover { background: var(--accent-dark); }
.complete-btn.done {
  background: none;
  color: var(--ok);
  border: 1px solid var(--ok);
  cursor: default;
}
.next-hint {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-muted);
  font-size: .9375rem;
}
.next-link { color: var(--accent-dark); font-size: .9375rem; }

/* ---------- term popover / bottom sheet ---------- */

#term-scrim {
  position: fixed;
  inset: 0;
  background: rgba(15,18,22,.45);
  z-index: 60;
}

#term-pop {
  position: fixed;
  z-index: 65;
  background: var(--ground);
  color: var(--ground-text);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  max-width: min(22rem, calc(100vw - 2rem));
  padding: .9rem 2.4rem .95rem 1.1rem;
}

#term-pop-handle { display: none; }

#term-pop-term {
  font-family: var(--display);
  font-weight: 650;
  font-size: .9375rem;
  margin-bottom: .3rem;
  color: #fff;
}
#term-pop-def {
  font-family: var(--serif);
  font-size: .9375rem;
  line-height: 1.6;
}

#term-pop-close {
  position: absolute;
  top: .35rem;
  right: .35rem;
  min-width: 2.25rem;
  min-height: 2.25rem;
  border-radius: 8px;
  color: var(--ground-muted);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
#term-pop-close:hover { background: var(--ground-2); color: #fff; }

/* bottom sheet on narrow screens */
@media (max-width: 599.98px) {
  #term-pop {
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    max-width: none;
    border-radius: 16px 16px 0 0;
    padding: .5rem 2.6rem 1.4rem 1.25rem;
    padding-bottom: calc(1.4rem + env(safe-area-inset-bottom));
    transform: translateY(0);
    transition: transform .18s ease;
  }
  #term-pop.closing { transform: translateY(100%); }
  #term-pop-handle {
    display: block;
    width: 2.5rem;
    height: 4px;
    border-radius: 2px;
    background: var(--ground-3);
    margin: .25rem auto .75rem;
  }
  #term-pop-term { font-size: 1.05rem; }
  #term-pop-def { font-size: 1rem; }
}

/* ---------- dialogs ---------- */

dialog {
  border: none;
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  padding: 1.1rem 1.25rem 1.25rem;
  width: min(30rem, calc(100vw - 2rem));
  max-height: min(80dvh, 40rem);
  overflow-y: auto;
}
dialog::backdrop { background: rgba(15,18,22,.5); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}
.dialog-head h2 {
  font-family: var(--display);
  font-size: 1.15rem;
  margin: 0;
}
.dialog-close {
  min-width: 2.5rem;
  min-height: 2.5rem;
  border-radius: 8px;
  font-size: 1.25rem;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dialog-close:hover { background: var(--paper-2); }

#glossary-filter {
  width: 100%;
  font: .9375rem var(--sans);
  padding: .55rem .7rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  margin-bottom: .75rem;
}

#glossary-list { margin: 0; }
#glossary-list dt {
  font-family: var(--display);
  font-weight: 650;
  font-size: .9375rem;
  margin-top: .8rem;
}
#glossary-list dd {
  font-family: var(--serif);
  font-size: .9375rem;
  line-height: 1.6;
  margin: .15rem 0 0;
  color: var(--ink-muted);
}
#glossary-list .no-match { color: var(--ink-muted); font-size: .875rem; }

#modal-body { font-size: .9375rem; line-height: 1.6; }
#modal-body ul { padding-left: 1.2rem; margin: .5rem 0; }
#modal-actions {
  display: flex;
  gap: .6rem;
  justify-content: flex-end;
  margin-top: 1.1rem;
  flex-wrap: wrap;
}
#modal-actions button {
  padding: .55rem 1rem;
  border-radius: 8px;
  font-size: .875rem;
  min-height: 2.75rem;
  border: 1px solid var(--rule);
}
#modal-actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
#modal-actions .primary:hover { background: var(--accent-dark); }
#modal-actions .danger { background: var(--danger); border-color: var(--danger); color: #fff; }
#modal-actions button:not(.primary):not(.danger):hover { background: var(--paper-2); }
