/* Classwork AI: shared styles */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #1b1f2a;
  --muted: #5b6475;
  --border: #dde2ee;
  --accent: #4f46e5;
  --accent-soft: #e6e5fd;
  --accent-text: #ffffff;
  --pos: #0f9d58;
  --pos-soft: #dcf5e8;
  --neg: #d93a3a;
  --neg-soft: #fde4e4;
  --warn: #c77700;
  --c1: #4f46e5;
  --c2: #e8590c;
  --c3: #0f9d58;
  --c4: #c2255c;
  --shadow: 0 1px 2px rgba(20,24,40,.06), 0 4px 16px rgba(20,24,40,.06);
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1220;
  --surface: #181c2e;
  --surface-2: #22273d;
  --text: #e9ecf5;
  --muted: #9aa3b8;
  --border: #2e3450;
  --accent: #8b85ff;
  --accent-soft: #2a2858;
  --accent-text: #0f1220;
  --pos: #3ccf8e;
  --pos-soft: #133a2a;
  --neg: #ff6b6b;
  --neg-soft: #401e24;
  --warn: #ffb547;
  --c1: #8b85ff;
  --c2: #ff8f4d;
  --c3: #3ccf8e;
  --c4: #f06595;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.55;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
h2 { font-size: clamp(1.3rem, 3vw, 1.7rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: var(--accent-text); font-size: .8rem; }
.crumbs { color: var(--muted); font-size: .9rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 1.05rem;
  display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }

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

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font: inherit; font-size: .95rem; font-weight: 600;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 6px 12px; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Cards & grids */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
a.card { text-decoration: none; color: inherit; display: block; transition: transform .15s, border-color .15s; }
a.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card.disabled { opacity: .55; pointer-events: none; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tag.soon { background: var(--surface-2); color: var(--muted); }
.big-num { font-size: 2.6rem; font-weight: 800; color: var(--accent); line-height: 1; }

/* Gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate .card { width: 100%; max-width: 380px; text-align: center; }
.gate input {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); margin: 12px 0; text-align: center; letter-spacing: .15em;
}
.gate .err { color: var(--neg); min-height: 1.4em; font-size: .9rem; }

/* Topic sections */
.topic { margin-top: 36px; scroll-margin-top: 70px; }
.topic-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 10px; }
.topic-head h2 { margin: 0; }
.topic-num { color: var(--accent); font-weight: 800; margin-right: 6px; }
.viz {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative;
}
.viz:fullscreen { overflow: auto; padding: 32px; font-size: 1.15rem; }
.viz-tools { position: absolute; top: 10px; right: 10px; }
.callout { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; margin: 12px 0 0; font-size: .95rem; }
.toc { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.toc a { font-size: .85rem; padding: 5px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); }
.toc a:hover { border-color: var(--accent); }

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 7px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .9rem; font-weight: 600; }
.tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin: 10px 0; }
.controls label { font-size: .9rem; display: flex; align-items: center; gap: 8px; }
input[type=range] { accent-color: var(--accent); width: 140px; }
.stat { font-variant-numeric: tabular-nums; font-weight: 700; }
.two-col { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .two-col { grid-template-columns: 1.4fr 1fr; } }

svg { display: block; max-width: 100%; height: auto; }
svg text { fill: var(--text); font-family: inherit; }
.chip {
  display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: grab; font-size: .9rem; user-select: none; margin: 3px;
}
.chip.ok { background: var(--pos-soft); border-color: var(--pos); }
.chip.bad { background: var(--neg-soft); border-color: var(--neg); }

/* Quiz modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(10,12,24,.55); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--surface); color: var(--text); border-radius: 18px; width: 100%; max-width: 620px;
  max-height: 92vh; overflow: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.quiz-progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 18px; }
.quiz-progress span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.quiz-q { font-size: 1.15rem; font-weight: 600; margin-bottom: 14px; }
.opt {
  display: block; width: 100%; text-align: left; font: inherit; padding: 12px 14px; margin: 8px 0;
  border-radius: 10px; border: 1.5px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.correct { border-color: var(--pos); background: var(--pos-soft); }
.opt.wrong { border-color: var(--neg); background: var(--neg-soft); }
.opt:disabled { cursor: default; }
.explain { font-size: .92rem; color: var(--muted); margin-top: 8px; min-height: 1.4em; }
.score-big { font-size: 3.4rem; font-weight: 800; color: var(--accent); text-align: center; }

footer.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 30px 16px; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .viz { padding: 14px; }
  .crumbs { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Visual helpers */
.flow { stroke-dasharray: 7 5; animation: flow .9s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -24; } }
.clickable { cursor: pointer; }
.draggable { cursor: grab; }
.calc { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.calc td { padding: 4px 6px; border-bottom: 1px solid var(--border); }
.calc td:last-child { text-align: right; font-weight: 600; }
.basket { display: inline-block; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 10px; padding: 6px 8px; margin: 4px; font-size: 1.25rem; min-width: 70px; text-align: center; }
.basket.hit { border-color: var(--accent); background: var(--accent-soft); }
.basket small { display: block; font-size: .7rem; color: var(--muted); }
.bar-row { display: grid; grid-template-columns: 110px 1fr 48px; align-items: center; gap: 8px; margin: 6px 0; font-size: .9rem; }
.bar { height: 14px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.nrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.nrow input[type=range] { width: 120px; }
