/* studykiki design tokens. Daylight is the default; Midnight applies via data-theme="dark" or the
   system preference when no explicit choice is saved. Brand yellow #F4C542 is identical in both. */
:root {
  color-scheme: light;
  --yellow: #F4C542;
  --navy: #1C2638;
  --bg: #FFFFFF;
  --card: #FFFFFF;
  --surface-2: #F8FAFC;
  --sidebar: #F4C542;
  --sidebar-ink: #1C2638;
  --ink: #1C2638;
  --muted: #64748B;
  --accent: #F4C542;
  --accent-ink: #1C2638;
  --accent-soft: #FFF7D6;
  --link: #2563EB;
  --good: #16704B;
  --good-bg: #E6F4EE;
  --bad: #C83C35;
  --bad-bg: #FFE9E4;
  --flag: #D9603F;
  --flag-bg: #FFEDE8;
  --note-bg: #E8F1FF;
  --note-ink: #1D4ED8;
  --border: #E2E8F0;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(28, 38, 56, 0.06);
  --font-display: "Fredoka", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0E1726;
    --card: #19283D;
    --surface-2: #21344D;
    --sidebar: #121F33;
    --sidebar-ink: #F7F9FC;
    --ink: #F7F9FC;
    --muted: #B8C5D5;
    --accent-soft: #3A3A2C;
    --link: #8BB6FF;
    --good: #4AD6A0;
    --good-bg: #173A30;
    --bad: #FF9182;
    --bad-bg: #4A2A26;
    --flag: #FFAE98;
    --flag-bg: #3F2E2A;
    --note-bg: #1E2F4A;
    --note-ink: #8BB6FF;
    --border: #34465F;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0E1726;
  --card: #19283D;
  --surface-2: #21344D;
  --sidebar: #121F33;
  --sidebar-ink: #F7F9FC;
  --ink: #F7F9FC;
  --muted: #B8C5D5;
  --accent-soft: #3A3A2C;
  --link: #8BB6FF;
  --good: #4AD6A0;
  --good-bg: #173A30;
  --bad: #FF9182;
  --bad-bg: #4A2A26;
  --flag: #FFAE98;
  --flag-bg: #3F2E2A;
  --note-bg: #1E2F4A;
  --note-ink: #8BB6FF;
  --border: #34465F;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; touch-action: manipulation; }

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(112px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#app.no-bar { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }

h1, h2, h3 { margin: 0; font-family: var(--font-display); letter-spacing: -0.01em; }
h2 { font-weight: 600; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
}

.top-bar h1 { font-size: 1.2rem; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 0.84rem; margin-top: 3px; }

.link-btn {
  background: none;
  border: none;
  color: var(--link);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
}

.link-btn.danger { color: var(--bad); }
.link-btn:disabled { color: var(--muted); opacity: 0.5; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.stack { display: flex; flex-direction: column; gap: 10px; }

.card h2 { font-size: 1.08rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }

.meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); }

.pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  min-width: 120px;
  min-height: 48px;
  transition: transform 0.05s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--card); color: var(--ink); border: 1.5px solid var(--border); }
.btn-primary:hover { filter: brightness(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.banner {
  background: var(--accent-soft);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.banner .title { font-weight: 700; }
.banner .sub { font-size: 0.86rem; color: var(--muted); }

/* ---------- setup ---------- */

.section-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 4px 2px 0;
}

.choice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  background: var(--card);
  color: var(--ink);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
}

.choice .dot {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  margin-top: 1px;
}

.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.choice.on .dot { border-color: var(--accent); background: radial-gradient(var(--accent) 45%, transparent 50%); }
.choice b { display: block; font-size: 0.98rem; margin-bottom: 2px; }
.choice span.desc { color: var(--muted); font-size: 0.86rem; line-height: 1.4; }

.segmented {
  display: flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.segmented button {
  flex: 1;
  border: none;
  background: none;
  color: var(--ink);
  border-radius: 9px;
  padding: 10px 4px;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 42px;
  cursor: pointer;
}

.segmented button.on { background: var(--accent); color: var(--accent-ink); }
.segmented button:disabled { color: var(--muted); opacity: 0.45; }
.segmented button small { display: block; font-weight: 500; font-size: 0.72rem; opacity: 0.85; }

/* ---------- question ---------- */

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.2s ease; }

.qmeta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.flag-tag { color: var(--flag); }

.stem { font-size: 1.06rem; line-height: 1.5; font-weight: 600; }

.hint {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 4px 10px;
}

.hint.warn { color: var(--bad); background: var(--bad-bg); }

.options { display: flex; flex-direction: column; gap: 10px; }

.opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  color: var(--ink);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 0.97rem;
  line-height: 1.42;
  cursor: pointer;
}

.opt .badge {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--card);
}

.options.multi .opt .badge { border-radius: 7px; }

.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.sel .badge { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.opt.correct { border-color: var(--good); background: var(--good-bg); }
.opt.correct .badge { background: var(--good); border-color: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .badge { background: var(--bad); border-color: var(--bad); color: #fff; }
.opt.missed { border-color: var(--good); border-style: dashed; }
.opt.missed .badge { border-color: var(--good); color: var(--good); }
.opt:disabled { cursor: default; }
.opt .tag { display: block; font-size: 0.74rem; font-weight: 700; margin-top: 4px; }
.opt.correct .tag, .opt.missed .tag { color: var(--good); }
.opt.wrong .tag { color: var(--bad); }
.opt.correct .tag::before, .opt.missed .tag::before { content: "\2713  "; }
.opt.wrong .tag::before { content: "\2715  "; }

.feedback { display: flex; flex-direction: column; gap: 10px; }

.verdict {
  font-weight: 800;
  font-size: 1rem;
}
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }

.rationale {
  font-size: 0.93rem;
  line-height: 1.55;
  background: var(--note-bg);
  border-radius: 12px;
  padding: 12px 14px;
}

.note {
  font-size: 0.86rem;
  line-height: 1.5;
  background: var(--flag-bg);
  border-radius: 12px;
  padding: 10px 14px;
}

.note b { color: var(--note-ink); }

/* ---------- bottom action bar ---------- */

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  z-index: 10;
}

.action-bar .inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
}

.action-bar .btn { min-width: 0; }
.action-bar .btn.narrow { flex: 0 0 auto; padding: 13px 14px; }
.btn-flag.on { background: var(--flag-bg); color: var(--flag); border-color: var(--flag); }

/* ---------- navigator sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  background: var(--card);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet .counts { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 8px;
}

.cell {
  position: relative;
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.cell.ans { background: var(--accent-soft); border-color: var(--accent); }
.cell { background: var(--surface-2); }
.cell.cur { outline: 2px solid var(--ink); outline-offset: 1px; }
.cell.flagged::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--flag);
}

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; border: 1.5px solid var(--border); background: var(--surface-2); }
.legend i.ans { background: var(--accent-soft); border-color: var(--accent); }
.legend i.flagged { background: var(--flag); border-color: var(--flag); border-radius: 50%; }

/* ---------- results ---------- */

.score-card { text-align: center; display: flex; flex-direction: column; gap: 4px; }
.score { font-size: 2.8rem; font-weight: 700; letter-spacing: -0.02em; font-family: var(--font-display); }
.score span { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.score-sub { color: var(--muted); font-size: 0.88rem; }

.breakdown-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.breakdown-row:last-child { border-bottom: none; }
.breakdown-row .bar { grid-column: 1 / -1; height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
.breakdown-row .bar div { height: 100%; background: var(--good); }
.breakdown-row .bar div.low { background: var(--bad); }
.breakdown-row .bar div.mid { background: var(--accent); }

.review-item { display: flex; flex-direction: column; gap: 10px; }
.review-item .rhead { display: flex; justify-content: space-between; gap: 10px; font-size: 0.78rem; font-weight: 700; color: var(--muted); }
.review-item .rhead .ok { color: var(--good); }
.review-item .rhead .no { color: var(--bad); }
.review-item .stem { font-size: 0.98rem; }
.review-item .opt { font-size: 0.9rem; padding: 10px 12px; }

.empty { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 8px 0; }

footer.tip {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 6px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.hidden { display: none !important; }

/* Legal footer on the home screen */
.legal {
  margin: 8px 0 24px;
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}
.legal a { color: var(--muted); text-decoration: underline; }

/* ---------- Phase 1: accounts, nav, forms, dashboard ---------- */

@media (min-width: 760px) {
  #app { max-width: 840px; }
  .bank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .bank-grid > .card { margin: 0; }
  .bank-grid > .empty { grid-column: 1 / -1; }
}

.loading { text-align: center; color: var(--muted); padding: 48px 0; }

.hero { padding: 28px 0 10px; text-align: center; }
.hero h1 { margin: 0 0 6px; font-size: 1.9rem; }
.hero .subtitle { margin: 0 auto; max-width: 420px; }

.nav { align-items: center; }
.nav-links { display: flex; gap: 14px; }
.nav-links .link-btn { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.nav-links .link-btn.on { font-weight: 700; color: var(--ink); }
.nav-links .link-btn svg { width: 18px; height: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.field input, .select {
  width: 100%; font: inherit; font-size: 1rem; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
}
.field input:focus, .select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.row-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.check { display: flex; gap: 10px; align-items: center; font-size: 0.95rem; }
.check input { width: 20px; height: 20px; }
.tip { color: var(--muted); font-size: 0.85rem; margin: 0; }
.link-btn.inline { padding: 0; font-size: inherit; }

.banner.warn { background: var(--flag-bg); border-color: var(--flag); display: block; }
.banner.warn a { color: var(--ink); }

.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.pick {
  text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card); color: var(--ink); font: inherit; cursor: pointer;
}
.pick small { color: var(--muted); }
.pick.add { border-style: dashed; }
.pick:active { background: var(--accent-soft); }
.add-school summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; margin-bottom: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink); font-size: 0.9rem;
}
.chip button { border: 0; background: none; font-size: 1.1rem; color: var(--muted); cursor: pointer; padding: 0 2px; }

.bank-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.bank-head h2 { margin: 0; }
.by { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.pill.soft { background: var(--accent-soft); color: var(--ink); border-color: transparent; }
.card.empty p { color: var(--muted); margin: 6px 0 12px; }

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 4px 0 14px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 6px; text-align: center; }
.stat b { display: block; font-size: 1.25rem; font-family: var(--font-display); }
.stat span { font-size: 0.75rem; color: var(--muted); }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 28px; }
.spark i { display: block; width: 7px; border-radius: 2px; background: var(--good); }
.spark i.mid { background: var(--accent); }
.spark i.low { background: var(--bad); }

.list { display: flex; flex-direction: column; }
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0;
  border-top: 1px solid var(--border); background: none; border-left: 0; border-right: 0; border-bottom: 0;
  font: inherit; color: var(--ink); text-align: left; width: 100%;
}
.row:first-child { border-top: 0; }
.row small { display: block; color: var(--muted); font-size: 0.8rem; }
button.row { cursor: pointer; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 0.95rem; }
.kv span { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%); z-index: 50;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 0.9rem;
  box-shadow: var(--shadow); max-width: 90vw;
}
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }

/* ---------- Phase 2: set management & editor ---------- */
.pill.warn { background: var(--flag-bg); color: var(--flag); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.qlist { padding: 0 14px; }
.qrow {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 12px 0;
  border: 0; border-top: 1px solid var(--border); background: none; color: var(--ink); font: inherit; cursor: pointer;
}
.qrow:first-child { border-top: 0; }
.qrow .n { color: var(--muted); font-size: 0.85rem; min-width: 1.6em; padding-top: 2px; }
.qrow .body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.qrow .stem { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 0.95rem; }
.qrow small { color: var(--muted); }
.qrow .review { color: var(--flag); }
.editor textarea, #impText {
  width: 100%; font: inherit; font-size: 1rem; padding: 12px 14px; border-radius: 12px; resize: vertical;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
}
.editor textarea:focus, #impText:focus { outline: 2px solid var(--accent); border-color: transparent; }
.opt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.opt-row .chk input { width: 22px; height: 22px; }
.opt-row .opt-text { flex: 1; font: inherit; font-size: 1rem; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); min-width: 0; }
.opt-row .opt-text:focus { outline: 2px solid var(--accent); border-color: transparent; }
.opt-row .link-btn { font-size: 1.3rem; padding: 0 6px; }
.fmt { background: var(--note-bg); border-radius: 10px; padding: 10px 12px; font-size: 0.78rem; line-height: 1.4; overflow-x: auto; margin: 0 0 10px; }
.sheet .banner ul { margin: 6px 0 0 18px; padding: 0; font-size: 0.85rem; }

/* ---------- brand: wordmark, mascot, illustrations, sidebar, appearance ---------- */

.wordmark {
  background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; align-items: baseline;
  font-family: var(--font-display); font-weight: 700; font-size: 1.45rem; letter-spacing: -0.03em; line-height: 1;
  color: var(--ink);
}
.wordmark .ki { color: var(--yellow); }
.wordmark.lg { font-size: 2.6rem; }
.hero .underline { display: block; width: 150px; height: 10px; margin: 2px auto 10px; }
.hero .underline path { stroke: var(--yellow); }

.hero.brand-hero { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hero .kiki { width: 128px; height: auto; margin-bottom: -6px; }
.mascot-row { display: flex; align-items: center; gap: 14px; }
.mascot-row img { width: 96px; height: auto; flex: none; }
.score-card.with-kiki { flex-direction: row; align-items: center; justify-content: center; gap: 14px; text-align: left; }
.score-card.with-kiki img { width: 110px; height: auto; }
.score-card.with-kiki .score-text { display: flex; flex-direction: column; gap: 4px; }
.illus { display: block; width: min(260px, 70%); height: auto; margin: 0 auto 6px; }
.card.empty.illustrated { padding-top: 10px; }

.tagline { font-family: var(--font-display); font-weight: 600; color: var(--ink); font-size: 1.1rem; }

/* Light · Dark · System */
.appearance .segmented button.on { background: var(--accent); color: var(--accent-ink); }

/* Desktop and tablet-landscape: the nav becomes the brand sidebar (yellow in Daylight, navy in Midnight). */
@media (min-width: 960px) {
  #app:has(.nav) { margin-left: 240px; max-width: 980px; padding-left: 32px; padding-right: 32px; }
  .top-bar.nav {
    position: fixed; left: 0; top: 0; bottom: 0; width: 240px; z-index: 5;
    flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 28px;
    padding: 28px 18px; background: var(--sidebar); color: var(--sidebar-ink);
  }
  .top-bar.nav .wordmark { color: var(--sidebar-ink); font-size: 1.6rem; padding-left: 6px; }
  :root[data-theme="light"] .top-bar.nav .wordmark .ki, .top-bar.nav .wordmark .ki { color: var(--navy); }
  :root[data-theme="dark"] .top-bar.nav .wordmark .ki { color: var(--yellow); }
  @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .top-bar.nav .wordmark .ki { color: var(--yellow); } }
  .top-bar.nav .nav-links { flex-direction: column; gap: 4px; }
  .top-bar.nav .nav-links .link-btn {
    color: var(--sidebar-ink); opacity: 0.8; font-size: 1rem; padding: 11px 12px; border-radius: 12px; text-align: left; gap: 10px;
  }
  .top-bar.nav .nav-links .link-btn svg { width: 20px; height: 20px; }
  .top-bar.nav .nav-links .link-btn.on { opacity: 1; background: rgba(255, 255, 255, 0.55); }
  :root[data-theme="dark"] .top-bar.nav .nav-links .link-btn.on { background: rgba(244, 197, 66, 0.16); color: var(--yellow); }
  @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .top-bar.nav .nav-links .link-btn.on { background: rgba(244, 197, 66, 0.16); color: var(--yellow); } }
  .bank-grid { grid-template-columns: 1fr 1fr; }
}

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

/* Compact nav on phones: text only, tighter spacing */
@media (max-width: 959px) {
  .nav-links { gap: 6px; }
  .nav-links .link-btn { padding: 8px 6px; font-size: 0.92rem; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
  .nav-links .link-btn svg { display: none; }
  .top-bar.nav .wordmark { font-size: 1.3rem; }
}

/* ---------- admin & view-as ---------- */
.imp-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: var(--flag-bg); color: var(--ink); border-bottom: 2px solid var(--flag);
  padding: 8px 16px; font-size: 0.88rem;
}
.imp-bar .btn { flex: 0 0 auto; min-width: 0; min-height: 34px; padding: 6px 12px; font-size: 0.85rem; }
body.impersonating #app { padding-top: calc(60px + env(safe-area-inset-top)); }
body.impersonating .top-bar.nav { top: 48px; }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; font: inherit; font-size: 1rem; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); min-width: 0; }
.search-row .btn { flex: 0 0 auto; min-width: 0; }

/* ---------- courses, people, sharing ---------- */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.course-card {
  display: flex; flex-direction: column; gap: 4px; text-align: left; cursor: pointer; font: inherit; color: var(--ink);
  padding: 14px; min-height: 96px;
}
.course-card .code { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.course-card .ctitle { font-size: 0.9rem; line-height: 1.3; }
.course-card small { color: var(--muted); font-size: 0.75rem; margin-top: auto; }
.course-card.add { border-style: dashed; color: var(--muted); align-items: center; justify-content: center; text-align: center; }
.course-card.add .code { color: var(--muted); }
.course-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.btn-pill { font: inherit; cursor: pointer; color: var(--ink); }
.badge-dot {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--flag); color: #fff; font-size: 0.7rem; font-weight: 700; margin-left: 4px;
}
.row.unread { font-weight: 600; }
.btn-row.compact { gap: 6px; flex-wrap: nowrap; }
.btn-row.compact .btn { min-width: 0; min-height: 36px; padding: 6px 12px; font-size: 0.85rem; flex: 0 0 auto; }
@media (max-width: 959px) { .nav-name { display: none; } .nav-links .link-btn[aria-label="Account"] svg { display: inline; width: 22px; height: 22px; } }
@media (min-width: 760px) { .course-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
/* Phone nav can hold five items (admins): let it scroll sideways instead of clipping */
@media (max-width: 959px) {
  .nav-links { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; flex: 1; justify-content: flex-start; margin-left: 10px; }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-links .link-btn { flex: 0 0 auto; max-width: none; }
}

/* ---------- materials library ---------- */
.upload-box { text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.upload-box .illus { width: min(200px, 60%); margin: 0; }
.upload-box p { margin: 0; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto; min-width: 180px; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.material h2 .kind { color: var(--muted); margin-right: 6px; font-weight: 400; }
.material.failed { border-color: var(--flag); }
.preview-list { display: flex; flex-direction: column; gap: 10px; max-height: 45vh; overflow-y: auto; }
.seg { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.seg b { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.seg p { margin: 0; font-size: 0.88rem; line-height: 1.45; white-space: pre-wrap; }
