/* ============================================================
   AI-Tutor design system
   Concept: a school "bookshelf". Each subject is an exercise
   book with its own coloured spine. Ink-on-cool-paper palette,
   rounded friendly display type, one warm accent.
   ============================================================ */

:root {
  /* Type */
  --font-display: "SF Pro Rounded", ui-rounded, "Nunito", "Segoe UI", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  /* Colour */
  --paper: #eef1fa;
  --paper-2: #f6f8fe;
  --card: #ffffff;
  --ink: #1b2352;
  --ink-soft: #4b5480;
  --muted: #8891b0;
  --line: #e5e9f5;
  --brand: #6d5ef6;
  --brand-ink: #4b3ddb;
  --accent: #ff9f45;
  --good: #14b8a6;
  --danger: #ef4767;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(27, 35, 82, .06);
  --shadow: 0 10px 26px -14px rgba(27, 35, 82, .35);
  --shadow-lg: 0 24px 48px -22px rgba(27, 35, 82, .45);
  --r: 16px;
  --r-lg: 24px;
  --r-pill: 999px;

  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, #e7e2ff 0%, transparent 55%),
    radial-gradient(900px 500px at -10% 0%, #dff6f1 0%, transparent 50%),
    var(--paper);
  background-attachment: fixed;
}

a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.02em; line-height: 1.12; margin: 0; }
h1 { font-size: clamp(28px, 4.2vw, 42px); font-weight: 800; }
h2 { font-size: 22px; font-weight: 800; }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 14px clamp(16px, 4vw, 32px);
  background: rgba(255, 255, 255, .72);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand {
  font-family: var(--font-display); font-weight: 800; font-size: 20px;
  color: var(--ink); letter-spacing: -.02em; white-space: nowrap;
}
.topbar .brand b { color: var(--brand); }
.topbar nav { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.topbar nav .navlink {
  color: var(--ink-soft); font-weight: 600; font-size: 15px;
  padding: 7px 12px; border-radius: var(--r-pill);
}
.topbar nav .navlink:hover { background: var(--paper); color: var(--ink); text-decoration: none; }

.usercluster { display: flex; align-items: center; gap: 10px; margin-left: 6px; }
.usercluster .who { font-weight: 600; font-size: 14px; color: var(--ink); }
.usercluster .who small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }

/* Grade crest — the signature identity mark for a student */
.crest {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 14px;
  background: linear-gradient(150deg, var(--brand), #8b7bff);
  color: #fff; box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, .3);
  line-height: 1; flex: none;
}
.crest .k { font-size: 8px; font-weight: 700; letter-spacing: .14em; opacity: .85; }
.crest .g { font-family: var(--font-display); font-size: 20px; font-weight: 800; }
.role-chip {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--brand-ink);
  background: color-mix(in srgb, var(--brand) 12%, white);
  padding: 5px 10px; border-radius: var(--r-pill);
}

.link-btn {
  background: none; border: 1px solid var(--line); color: var(--ink-soft);
  cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  padding: 7px 14px; border-radius: var(--r-pill);
}
.link-btn:hover { border-color: var(--brand); color: var(--brand-ink); }
.inline { display: inline; margin: 0; }

/* ---------- Layout ---------- */
.container { max-width: 1000px; margin: 0 auto; padding: clamp(24px, 5vw, 48px) clamp(16px, 4vw, 32px) 72px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 0 40px; }
.subtitle { color: var(--ink-soft); margin: 8px 0 0; font-size: 17px; }
.muted { color: var(--muted); }

/* ---------- Hero (student home) ---------- */
.hero { margin-bottom: 34px; }
.hero .wave { font-size: 1em; display: inline-block; transform-origin: 70% 70%; }
.hero h1 .name { color: var(--brand); }
.grade-tag {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 14px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 7px 14px 7px 8px; box-shadow: var(--shadow-sm); font-weight: 700; color: var(--ink);
}
.grade-tag .dot {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--brand), #8b7bff); color: #fff;
  font-family: var(--font-display); font-size: 13px; font-weight: 800;
}
.grade-tag small { color: var(--muted); font-weight: 600; }

/* ---------- Bookshelf (subject tiles) ---------- */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; }
.book {
  --c: var(--brand);
  position: relative; display: block; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 22px 22px 20px 30px; color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform .18s cubic-bezier(.2,.8,.2,1), box-shadow .18s, border-color .18s;
}
.book::before { /* the coloured spine */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 10px;
  background: linear-gradient(var(--c), color-mix(in srgb, var(--c) 70%, black));
  transition: width .18s;
}
.book:hover { transform: translateY(-6px); box-shadow: var(--shadow-lg); border-color: transparent; text-decoration: none; }
.book:hover::before { width: 14px; }
.book .chip {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  font-size: 30px; margin-bottom: 16px;
  background: color-mix(in srgb, var(--c) 14%, white);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 22%, white);
}
.book .name { font-family: var(--font-display); font-weight: 800; font-size: 19px; letter-spacing: -.01em; }
.book .count { margin-top: 4px; color: var(--muted); font-size: 14px; font-weight: 600; }
.book .go {
  margin-top: 14px; display: inline-flex; align-items: center; gap: 6px;
  color: var(--c); font-weight: 700; font-size: 14px;
}
.book .go .arr { transition: transform .18s; }
.book:hover .go .arr { transform: translateX(4px); }

/* ---------- Subject page ---------- */
.crumb { color: var(--muted); font-weight: 600; margin-bottom: 18px; }
.crumb a { color: var(--ink-soft); }
.subject-head { --c: var(--brand); display: flex; align-items: center; gap: 18px; margin-bottom: 26px; }
.subject-head .emoji {
  width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center; font-size: 40px;
  background: color-mix(in srgb, var(--c) 14%, white);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 22%, white); flex: none;
}
.subject-head .meta { color: var(--ink-soft); font-weight: 600; margin-top: 6px; }

.lesson-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.lesson-list .row {
  --c: var(--brand);
  display: flex; align-items: center; gap: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px 18px; color: var(--ink); box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.lesson-list .row:hover { transform: translateX(3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--c) 40%, var(--line)); text-decoration: none; }
.lesson-list .num {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, white);
}
.lesson-list .row .t { font-weight: 700; font-size: 16px; }
.lesson-list .row .d { color: var(--muted); font-size: 14px; margin-top: 2px; }
.lesson-list .row .open { margin-left: auto; color: var(--c); font-weight: 700; white-space: nowrap; }

/* ---------- Lesson viewer ---------- */
.lesson-top { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.frame-wrap { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.frame-wrap .bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--paper-2); color: var(--muted); font-size: 13px; font-weight: 600;
}
.frame-wrap .bar .dots { display: flex; gap: 6px; }
.frame-wrap .bar .dots i { width: 11px; height: 11px; border-radius: 50%; background: #d7dcec; display: inline-block; }
iframe.lesson { width: 100%; height: 72vh; min-height: 460px; border: 0; display: block; background: #fff; }

/* ---------- Cards / generic ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px; box-shadow: var(--shadow-sm); margin-bottom: 20px; }
.card h2 { margin-bottom: 6px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: var(--r-pill); padding: 4px 12px; font-size: 13px; font-weight: 700; color: #fff; background: var(--brand); }
.badge.tint { background: color-mix(in srgb, var(--brand) 14%, white); color: var(--brand-ink); }
.badge.good { background: var(--good); }
.badge.gray { background: #9aa3c2; }
.badge.amber { background: var(--accent); color: #6b3d00; }
.badge.outline { background: #fff; color: var(--ink-soft); border: 1px solid var(--line); }

/* ---------- Forms ---------- */
label { display: block; font-weight: 700; margin: 16px 0 6px; font-size: 14px; color: var(--ink); }
input[type=text], input[type=password], input[type=email], select, textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) center, calc(100% - 13px) center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--brand); color: #fff; border: 0; border-radius: 12px;
  padding: 11px 20px; font-size: 15px; font-weight: 700; font-family: inherit; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s, background .12s;
}
.btn:hover, button.btn:hover { background: var(--brand-ink); transform: translateY(-1px); box-shadow: var(--shadow); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn.gray { background: #eef1fa; color: var(--ink); box-shadow: none; }
.btn.gray:hover { background: #e3e8f6; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #d5325a; }
.btn.small { padding: 7px 13px; font-size: 13px; }
.btn.block { width: 100%; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.stack-end { display: flex; flex-direction: column; }

/* ---------- Grade multi-picker (chips) ---------- */
.grade-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.grade-picker label { margin: 0; cursor: pointer; }
.grade-picker input { position: absolute; opacity: 0; width: 0; height: 0; }
.grade-picker span {
  display: grid; place-items: center; min-width: 46px; height: 42px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 12px; font-weight: 700; font-size: 15px;
  background: #fff; color: var(--ink-soft); transition: all .12s;
}
.grade-picker label:hover span { border-color: var(--brand); color: var(--brand-ink); }
.grade-picker input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow-sm); }
.grade-picker input:focus-visible + span { outline: 3px solid var(--brand); outline-offset: 2px; }
.grade-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Tables (admin) ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-sm); }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
th { background: var(--paper-2); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbff; }

/* ---------- Stat cards (dashboard) ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.stat .n { font-family: var(--font-display); font-size: 34px; font-weight: 800; line-height: 1; color: var(--ink); }
.stat .n.small { font-size: 22px; }
.stat .k { color: var(--muted); font-weight: 600; font-size: 13px; margin-top: 8px; }
.stat .ic { font-size: 22px; }

/* ---------- Alerts ---------- */
.alert { border-radius: 14px; padding: 13px 16px; margin-bottom: 18px; font-size: 14px; font-weight: 600; display: flex; gap: 10px; }
.alert.error { background: #fff0f3; color: #c01f45; border: 1px solid #ffd0dc; }
.alert.ok { background: #e9fbf6; color: #0b7a63; border: 1px solid #bff0e3; }

/* ---------- Login ---------- */
.auth { min-height: calc(100vh - 20px); display: grid; place-items: center; padding: 24px; }
.auth .panel { width: 100%; max-width: 400px; }
.auth .logo { text-align: center; margin-bottom: 22px; }
.auth .logo .crest { width: 58px; height: 58px; margin: 0 auto 12px; }
.auth .logo .crest .g { font-size: 26px; }
.auth h1 { text-align: center; font-size: 26px; }
.auth .sub { text-align: center; color: var(--ink-soft); margin: 6px 0 22px; }
.auth .card { padding: 26px; margin: 0; }

/* ---------- Glossary callout ---------- */
.gloss-callout {
  position: absolute; z-index: 60; max-width: 300px;
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 15px 16px 13px;
  animation: rise .18s ease both;
}
.gloss-callout .gloss-term { font-family: var(--font-display); font-weight: 800; font-size: 16px; color: var(--ink); margin: 0 18px 5px 0; }
.gloss-callout .gloss-def { color: var(--ink-soft); font-size: 14px; line-height: 1.5; }
.gloss-callout .gloss-link { display: inline-block; margin-top: 11px; font-weight: 700; font-size: 13px; color: var(--brand-ink); }
.gloss-callout .gloss-x { position: absolute; top: 8px; right: 11px; border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; }
.gloss-callout .gloss-x:hover { color: var(--ink); }

/* ---------- Motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes wavehand { 0%,60%,100% { transform: rotate(0); } 15% { transform: rotate(18deg); } 30% { transform: rotate(-8deg); } 45% { transform: rotate(14deg); } }
.reveal { animation: rise .5s cubic-bezier(.2,.8,.2,1) both; }
.shelf .book { animation: rise .5s cubic-bezier(.2,.8,.2,1) both; }
.shelf .book:nth-child(1){animation-delay:.04s}.shelf .book:nth-child(2){animation-delay:.09s}
.shelf .book:nth-child(3){animation-delay:.14s}.shelf .book:nth-child(4){animation-delay:.19s}
.shelf .book:nth-child(5){animation-delay:.24s}.shelf .book:nth-child(6){animation-delay:.29s}
.hero .wave { animation: wavehand 2.4s ease-in-out 1s 2; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar { gap: 10px; }
  .topbar nav .navlink { padding: 6px 9px; font-size: 14px; }
  .usercluster .who { display: none; }
  iframe.lesson { height: 66vh; }
}
