/* =====================================================================
   components.css: pieces used on more than one page.
   ===================================================================== */

/* ---------- Top bars (public site + logged-in app) ---------- */
#topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  display: flex; align-items: center; gap: 1.25rem;
  min-height: 60px; padding: 0.5rem 1.25rem;
  max-width: 1400px; margin-inline: auto;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-serif); font-weight: 700; font-size: 1.15rem;
  color: var(--text); text-decoration: none; flex-shrink: 0;
}
.brand:hover { color: var(--text); }
.crest { width: 26px; height: 29px; flex-shrink: 0; }

.site-nav, .app-nav { display: flex; gap: 0.25rem; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.site-nav::-webkit-scrollbar, .app-nav::-webkit-scrollbar { display: none; }
.site-nav a, .app-nav a {
  padding: 0.4rem 0.7rem; border-radius: var(--radius);
  color: var(--text-soft); text-decoration: none; font-weight: 500; font-size: 0.92rem; white-space: nowrap;
}
.site-nav a:hover, .app-nav a:hover { color: var(--text); background: var(--bg-alt); }
.app-nav a.is-active { color: var(--primary); background: var(--primary-tint); font-weight: 600; }
.nav-count {
  display: inline-grid; place-items: center; min-width: 1.3em; height: 1.3em; margin-left: 0.3rem;
  padding: 0 0.3em; border-radius: 999px; background: var(--bad); color: #FFFFFF;
  font-size: 0.7rem; font-weight: 700; font-family: var(--font-mono);
}
.top-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; flex-shrink: 0; }
.stat {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem; border: 1px solid var(--rule); border-radius: 999px;
  font-size: 0.85rem; white-space: nowrap;
}
.stat b { font-family: var(--font-mono); font-weight: 700; }
.stat-level { background: var(--primary-tint); color: var(--primary); font-weight: 600; border-color: transparent; }
.coin { width: 0.8em; height: 0.8em; border-radius: 50%; background: var(--gold); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15); }
.lang-select {
  min-height: 32px; padding: 0.2rem 0.5rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface); font-size: 0.85rem;
}
.theme-toggle {
  display: inline-flex; align-items: center; gap: 3px;
  height: 32px; padding: 0 0.45rem;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface);
}
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 2px solid transparent; }
.swatch-academic { background: linear-gradient(135deg, #FFFFFF 50%, #2A4AA6 50%); border-color: #D6DCE8; }
.swatch-obsidian { background: linear-gradient(135deg, #0A0E1A 50%, #C9A227 50%); }
[data-theme="academic"] .swatch-academic,
[data-theme="obsidian"] .swatch-obsidian { outline: 2px solid var(--primary); outline-offset: 1px; }

@media (max-width: 1100px) {
  .stat-level { display: none; }
}
@media (max-width: 860px) {
  .site-nav { display: none; }
  .topbar-app .topbar-inner { flex-wrap: wrap; gap: 0.5rem 1rem; }
  .topbar-app .app-nav { order: 3; width: 100%; }
}
@media (max-width: 560px) {
  .hide-sm { display: none !important; }
}

/* ---------- Question card ---------- */
.q-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.4rem;
}
.q-card + .q-card { margin-top: 1.25rem; }
.q-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.q-num { font-family: var(--font-serif); font-weight: 700; font-size: 1.05rem; }
.q-meta { font-size: 0.8rem; color: var(--text-soft); display: inline-flex; gap: 0.5rem; align-items: center; }
.q-diff { padding: 0.05rem 0.45rem; border-radius: var(--radius-sm); border: 1px solid var(--rule); font-weight: 600; }
.q-diff[data-level="3"] { border-color: var(--gold); color: var(--gold-text); }
.q-passage {
  font-family: var(--font-serif); font-size: 1rem; line-height: 1.75;
  padding: 0.9rem 1rem; margin-bottom: 0.9rem;
  background: var(--bg-alt); border-left: 3px solid var(--rule); border-radius: 0 var(--radius) var(--radius) 0;
}
.q-passage ul { margin: 0.4rem 0 0; }
.q-stem { font-size: 1.02rem; font-weight: 500; margin-bottom: 0.9rem; }
.q-choices { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.choice {
  display: flex; align-items: center; gap: 0.75rem; width: 100%;
  padding: 0.6rem 0.8rem; text-align: left;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  transition: border-color 0.15s, background-color 0.15s;
}
.choice:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-tint); }
.choice-letter {
  display: grid; place-items: center; flex-shrink: 0;
  width: 1.8rem; height: 1.8rem; border-radius: 50%;
  border: 1.5px solid var(--text-soft); font-weight: 700; font-size: 0.85rem;
}
.choice[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-tint); }
.choice[aria-pressed="true"] .choice-letter { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.choice:disabled { cursor: default; color: var(--text); }
.choice.is-correct { border-color: var(--good); background: var(--good-tint); }
.choice.is-correct .choice-letter { background: var(--good); border-color: var(--good); color: #FFFFFF; }
.choice.is-wrong { border-color: var(--bad); background: var(--bad-tint); }
.choice.is-wrong .choice-letter { background: var(--bad); border-color: var(--bad); color: #FFFFFF; }

.q-tools { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.9rem; }
.q-tools .btn { font-weight: 500; }

.q-result { margin-top: 1rem; border-top: 1px dashed var(--rule); padding-top: 1rem; }
.verdict { font-weight: 700; margin-bottom: 0.6rem; }
.verdict-good { color: var(--good); }
.verdict-bad { color: var(--bad); }
.q-result h4 { font-family: var(--font-sans); font-size: 0.9rem; margin: 0.75rem 0 0.4rem; }
.q-steps { margin: 0 0 0.75rem; padding-left: 1.3rem; }
.q-steps li { margin-bottom: 0.35rem; }
.q-note { font-size: 0.92rem; padding: 0.6rem 0.8rem; border-radius: var(--radius); margin: 0.5rem 0 0; }
.q-note-trap { background: var(--gold-tint); border-left: 3px solid var(--gold); }
.q-note-desmos { background: var(--primary-tint); border-left: 3px solid var(--primary); }
.q-note-saved { background: var(--bad-tint); border-left: 3px solid var(--bad); }

/* ---------- Note guide: rendered like a printed handout ---------- */
.sheet {
  position: relative;
  background: var(--sheet);
  border: 1px solid var(--sheet-edge);
  border-radius: 2px;
  padding: 2.25rem clamp(1.25rem, 4vw, 3rem) 2.5rem;
  box-shadow: 0 1px 0 var(--sheet-edge), 0 6px 0 -3px var(--sheet), 0 7px 0 -3px var(--sheet-edge);
  font-family: var(--font-serif);
  font-size: 1.02rem; line-height: 1.8;
}
.sheet-head {
  display: flex; justify-content: space-between; gap: 1rem;
  font-family: var(--font-sans); font-size: 0.78rem; color: var(--text-soft);
  border-bottom: 2px solid var(--text); padding-bottom: 0.5rem; margin-bottom: 1.5rem;
}
.sheet h3 { font-size: 1.35rem; margin-bottom: 0.9rem; }
.sheet h4 { font-size: 1rem; margin: 1.4rem 0 0.5rem; }
.sheet p { max-width: 68ch; }
.sheet-rule {
  margin: 1.25rem 0; padding: 0.9rem 1.1rem;
  border: 1.5px solid var(--primary); border-radius: var(--radius-sm);
}
.sheet-rule strong { display: block; font-family: var(--font-sans); font-size: 0.85rem; color: var(--primary); margin-bottom: 0.2rem; }
.sheet-trap {
  margin: 1.25rem 0; padding: 0.8rem 1.1rem;
  background: var(--gold-tint); border-left: 4px solid var(--gold);
}
.sheet-trap strong { font-family: var(--font-sans); font-size: 0.85rem; color: var(--gold-text); margin-right: 0.35rem; }
.sheet-example { margin: 1rem 0; padding-left: 1rem; border-left: 2px dotted var(--text-soft); }
.sheet ol, .sheet ul { max-width: 66ch; }
.sheet li { margin-bottom: 0.4rem; }
.sheet-table-wrap { overflow-x: auto; margin: 1.1rem 0; }
.sheet table { border-collapse: collapse; width: 100%; font-family: var(--font-sans); font-size: 0.9rem; line-height: 1.5; }
.sheet th, .sheet td { border: 1px solid var(--rule); padding: 0.5rem 0.7rem; text-align: left; vertical-align: top; }
.sheet th { background: var(--bg-alt); font-weight: 600; }

/* ---------- Study plan table (PrepPros style) ---------- */
.plan-tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.plan-tabs button {
  border: 1px solid var(--rule); background: var(--surface);
  padding: 0.35rem 0.85rem; border-radius: var(--radius); font-weight: 600; font-size: 0.85rem;
}
.plan-tabs button[aria-selected="true"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.plan-table-wrap { overflow-x: auto; }
.plan-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; background: var(--surface); }
.plan-table caption {
  caption-side: top; background: var(--primary); color: var(--primary-ink);
  font-weight: 600; padding: 0.45rem; border: 1px solid var(--primary);
}
.plan-table th, .plan-table td { border: 1px solid var(--rule); padding: 0.55rem 0.7rem; vertical-align: top; text-align: left; }
.plan-table thead th { font-weight: 600; text-align: center; background: var(--bg-alt); }
.plan-table tbody th { font-weight: 600; width: 22%; background: var(--bg-alt); }
.plan-item { display: flex; gap: 0.5rem; align-items: flex-start; margin: 0 0 0.35rem; }
.plan-item:last-child { margin-bottom: 0; }
.plan-item input { margin-top: 0.25rem; accent-color: var(--primary); flex-shrink: 0; }
.plan-item input:checked + span { color: var(--text-soft); text-decoration: line-through; }
.plan-progress { font-size: 0.8rem; color: var(--text-soft); margin-top: 0.5rem; }

/* ---------- Tools drawer (Desmos, tutor, language helper) ---------- */
.drawer {
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--rule);
  min-height: 0; height: 100%;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--rule); }
.drawer-tabs { display: flex; gap: 0.25rem; }
.drawer-tabs button {
  border: 0; background: transparent; padding: 0.35rem 0.65rem; border-radius: var(--radius);
  font-weight: 600; font-size: 0.85rem; color: var(--text-soft);
}
.drawer-tabs button[aria-selected="true"] { background: var(--primary-tint); color: var(--primary); }
.drawer-close { border: 0; background: transparent; font-size: 1.1rem; line-height: 1; padding: 0.35rem 0.5rem; border-radius: var(--radius); color: var(--text-soft); }
.drawer-close:hover { background: var(--bg-alt); }
.drawer-context { margin: 0; padding: 0.5rem 0.9rem; font-size: 0.8rem; color: var(--text-soft); border-bottom: 1px solid var(--rule); background: var(--bg-alt); }
.pane { flex: 1; min-height: 0; overflow-y: auto; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.75rem; }
.pane[hidden] { display: none; }
.pane h4 { font-family: var(--font-sans); font-size: 0.85rem; margin: 0.25rem 0 0; }

.desmos-host { height: 420px; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; background: #FFFFFF; flex-shrink: 0; }
.desmos-host iframe { width: 100%; height: 100%; border: 0; }
.desmos-host .muted { padding: 1rem; }
.desmos-bar { font-size: 0.9rem; }
.desmos-bar code { font-family: var(--font-mono); font-size: 0.8rem; background: var(--bg-alt); padding: 0.1rem 0.3rem; border-radius: 3px; }

.chat { display: flex; flex-direction: column; gap: 0.6rem; }
.msg { max-width: 92%; padding: 0.6rem 0.8rem; border-radius: var(--radius-lg); font-size: 0.92rem; line-height: 1.55; }
.msg p:last-child { margin-bottom: 0; }
.msg-tutor { background: var(--bg-alt); border: 1px solid var(--rule); border-top-left-radius: 2px; }
.msg-you { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-top-right-radius: 2px; }
.msg-label { display: block; font-size: 0.72rem; font-weight: 700; color: var(--text-soft); margin-bottom: 0.15rem; }
.chat-quick { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chat-form { display: flex; gap: 0.4rem; }
.chat-note { margin: 0; }

.gloss { margin: 0; display: grid; gap: 0.5rem; }
.gloss-row { padding: 0.55rem 0.7rem; border: 1px solid var(--rule); border-radius: var(--radius); }
.gloss dt { font-weight: 700; }
.gloss dd { margin: 0.1rem 0 0; font-size: 0.9rem; color: var(--text-soft); }
.gloss-tr { display: block; margin-top: 0.2rem; color: var(--text); font-weight: 600; font-size: 0.95rem; }
.esl-plain { font-family: var(--font-serif); padding: 0.7rem 0.85rem; background: var(--primary-tint); border-radius: var(--radius); margin: 0; }
.esl-note { font-size: 0.85rem; color: var(--text-soft); margin: 0; }

/* ---------- Adaptive routing diagram (Tests) ---------- */
.route-map { width: 100%; max-width: 640px; margin: 0 auto; }
.route-map .rm-box { fill: var(--surface); stroke: var(--rule); stroke-width: 1.5; }
.route-map .rm-m1 { stroke: var(--primary); }
.route-map text { fill: var(--text); font-family: var(--font-sans); font-size: 14px; }
.route-map .rm-title { font-weight: 700; font-size: 15px; }
.route-map .rm-sub { fill: var(--text-soft); font-size: 12px; }
.route-map .rm-path { fill: none; stroke: var(--rule); stroke-width: 2.5; stroke-dasharray: 6 6; }
.route-map .is-chosen .rm-box { stroke: var(--gold); stroke-width: 2.5; }
.route-map .rm-path.is-chosen { stroke: var(--gold); stroke-dasharray: 340; stroke-dashoffset: 340; animation: draw-route 0.9s 0.2s ease-out forwards; }
.route-map .is-faded { opacity: 0.4; }
@keyframes draw-route { to { stroke-dashoffset: 0; } }
