/* ─────────────────────────────────────────────────────────────────────────────
   Design tokens, reset, typography and the app shell.
   Theme: the active theme is stamped on <html data-theme="light|dark"> by a tiny
   script in index.html (it follows the system setting unless the student chose one).
   ───────────────────────────────────────────────────────────────────────────── */

@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 500 800;
  font-display: swap;
  src: url('../fonts/nunito-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Young Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/young-serif-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Caveat';
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url('../fonts/caveat-latin.woff2') format('woff2');
}

/* Index-card design: cream paper on a squared grid, ink outlines, offset shadows,
   masking tape. Neutral throughout; colour comes from each student's subject colours. */
:root {
  color-scheme: light;

  /* surfaces & ink */
  --plane: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #f3eee4;
  --surface-3: #e9e2d4;
  --ink: #2a2723;
  --ink-2: #6d675d;
  --ink-3: #8b8478;
  --line: #e0d8ca;
  --line-strong: #b7ad9c;
  --grid-line: rgba(60, 50, 40, 0.07);
  --tape: rgba(214, 196, 160, 0.72);
  --rule-red: rgba(200, 90, 80, 0.35);
  --rule-blue: rgba(90, 120, 160, 0.16);
  --card-shadow: 4px 5px 0 rgba(42, 39, 35, 0.14);
  --btn-shadow: 3px 3px 0 var(--ink);
  --pen: #b5534a;

  /* accent: ink, so the page stays neutral */
  --accent: #2a2723;
  --accent-strong: #000000;
  --accent-wash: #efe8da;
  --highlight: #f7e3a6;
  --demo-bg: #f7e3a6;
  --demo-ink: #2a2723;

  /* status (fixed meanings: always paired with an icon or label) */
  --good: #6fb383;
  --good-ink: #2f6b40;
  --good-wash: #cfe8d5;
  --warn: #e5b84a;
  --warn-ink: #7a5a10;
  --warn-wash: #f7e3a6;
  --crit: #d9776a;
  --crit-ink: #9a3d32;
  --crit-wash: #f4cfc7;

  /* chart series: the subject swatch colours, deep enough to read on cream */
  --series-1: #6fa3d6;
  --series-2: #e98a5f;
  --series-3: #5fae78;
  --series-4: #d9ac2e;
  --series-5: #e07c97;
  --series-6: #8a9b5a;
  --series-7: #9a82d6;
  --series-8: #c96a5f;
  --grid: #e0d8ca;
  --axis: #b7ad9c;

  --radius: 4px;
  --radius-sm: 4px;
  --shadow: var(--card-shadow);
  --sidebar: 0px;

  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Young Serif', Georgia, serif;
  --font-hand: 'Caveat', 'Segoe Print', cursive;
  --font-mono: ui-monospace, 'Cascadia Code', Consolas, 'Liberation Mono', monospace;
}

/* Dark mode: warm browns, cream text, muted subject colours. No neon. */
:root[data-theme='dark'] {
  color-scheme: dark;
  --plane: #3d3832;
  --surface: #4a443d;
  --surface-2: #443e37;
  --surface-3: #544b3c;
  --ink: #eee5d4;
  --ink-2: #bdb2a1;
  --ink-3: #a09684;
  --line: #5c544a;
  --line-strong: #7a7062;
  --grid-line: rgba(255, 240, 220, 0.05);
  --tape: rgba(190, 170, 130, 0.55);
  --rule-red: rgba(220, 120, 110, 0.3);
  --rule-blue: rgba(200, 215, 235, 0.08);
  --card-shadow: 4px 5px 0 rgba(0, 0, 0, 0.28);
  --btn-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4);
  --pen: #f0b0a5;
  --accent: #eee5d4;
  --accent-strong: #ffffff;
  --accent-wash: #544b3c;
  --highlight: #6b5a2f;
  --demo-bg: #6b5a2f;
  --demo-ink: #eee5d4;
  --good: #5e8a68;
  --good-ink: #b9dcc0;
  --good-wash: #4c6552;
  --warn: #b89a45;
  --warn-ink: #ecd08a;
  --warn-wash: #645534;
  --crit: #a8655a;
  --crit-ink: #f0b0a5;
  --crit-wash: #6a463f;
  --series-1: #7d9cba;
  --series-2: #c08466;
  --series-3: #7aa486;
  --series-4: #bea057;
  --series-5: #bb8493;
  --series-6: #96a272;
  --series-7: #a291c4;
  --series-8: #b9766c;
  --grid: #5c544a;
  --axis: #7a7062;
}

/* ── reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 72px;
}
body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1,
h2,
h3,
h4,
p,
ul,
ol,
figure,
blockquote {
  margin: 0;
}
ul,
ol {
  padding: 0;
  list-style: none;
}
img,
svg {
  max-width: 100%;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
a {
  color: var(--accent-strong);
  text-underline-offset: 3px;
}
a:hover {
  text-decoration-thickness: 2px;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
h1:focus {
  outline: none;
}
[hidden] {
  display: none !important;
}
.icon {
  flex: none;
  vertical-align: -0.2em;
}

/* ── type helpers ── */
.h2 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.h3 {
  font-size: 15.5px;
  font-weight: 650;
  line-height: 1.35;
}
.lead {
  font-size: 17px;
  color: var(--ink-2);
  max-width: 62ch;
}
.muted {
  color: var(--ink-2);
}
.small {
  font-size: 13px;
}
.label {
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.mono {
  font-family: var(--font-mono);
  font-size: 0.93em;
}
.nowrap {
  white-space: nowrap;
}
.num {
  font-variant-numeric: tabular-nums;
}
.right {
  text-align: right;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── layout helpers ── */
.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.stack--sm {
  gap: 8px;
}
.stack--lg {
  gap: 28px;
}
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.row--between {
  justify-content: space-between;
}
.row--top {
  align-items: flex-start;
}
.row--tight {
  gap: 6px;
}
.row--nowrap {
  flex-wrap: nowrap;
}
.spacer {
  flex: 1;
}
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
}
.grid--stats {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
}
.grid--2 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
}
.grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.split {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}
.split--wide-aside {
  grid-template-columns: minmax(0, 1fr) 400px;
}
@media (max-width: 1080px) {
  .split,
  .split--wide-aside {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ── app shell ── */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px 12px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0;
  padding: 4px 10px 14px;
  font: 600 25px/1 var(--font-display);
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}
.brand mark {
  color: inherit;
  background: linear-gradient(transparent 58%, var(--highlight) 58%);
  padding: 0 2px;
}
.nav__label {
  margin: 14px 10px 4px;
}
.nav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-weight: 500;
  text-decoration: none;
  border: 1px solid transparent;
}
.nav__item:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.nav__item.is-active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 650;
}
.nav__item .badge {
  margin-left: auto;
}
.sidebar__foot {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.userchip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--surface);
}
.userchip:hover {
  border-color: var(--line-strong);
}
.userchip__avatar {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--plane);
  font-weight: 650;
  font-size: 13px;
}
.userchip__name {
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.userchip__meta {
  font-size: 12px;
  color: var(--ink-2);
}
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 12px;
  background: var(--plane);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  padding: 0 4px;
  font-size: 22px;
}
.main {
  min-width: 0;
}
.view {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 32px 72px;
}
.view--narrow {
  max-width: 760px;
}
.scrim {
  display: none;
}

/* signed-out pages: no sidebar, a simple header */
.app[data-layout='public'] {
  grid-template-columns: minmax(0, 1fr);
}
.app[data-layout='public'] .sidebar,
.app[data-layout='focus'] .sidebar {
  display: none;
}
.app[data-layout='focus'] {
  grid-template-columns: minmax(0, 1fr);
}
.pubbar {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 32px 0;
}
.pubbar .brand {
  padding: 0;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .topbar {
    display: flex;
  }
  .app[data-layout='public'] .topbar,
  .app[data-layout='focus'] .topbar {
    display: none;
  }
  .sidebar {
    position: fixed;
    z-index: 50;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    background: var(--plane);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .app.is-nav-open .sidebar {
    transform: none;
  }
  .app.is-nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(11, 11, 11, 0.4);
    border: 0;
  }
  .view {
    padding: 20px 16px 64px;
  }
  .pubbar {
    padding: 14px 16px 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ── page header ── */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px 24px;
  margin-bottom: 24px;
}
.page-head__text {
  min-width: 0;
  flex: 1 1 420px;
}
.page-head__title {
  font: 600 32px/1.15 var(--font-display);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.page-head__title .badge {
  vertical-align: middle;
  margin-left: 6px;
}
.page-head__sub {
  margin-top: 8px;
  color: var(--ink-2);
  max-width: 70ch;
}
.page-head__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--ink-2);
}
.crumbs a {
  color: var(--ink-2);
}
@media (max-width: 920px) {
  .page-head__title {
    font-size: 26px;
  }
}
.section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
  margin: 8px 0 12px;
}
