/* ===== Akili brand system =====
   Palette pulled from the real Akili artwork (welcome poster + how-to-use infographic):
   dark-navy base, vibrant multi-colour category accents, gold primary, teal + purple character
   colours. Rich atmospheric background (the study/library hero image) with light cards on top. */
:root {
  --navy: #14223b;
  --navy-2: #1e3352;
  --teal: #23b06e;
  --teal-2: #1a9d7e;
  --gold: #f4b223;
  --gold-2: #e89c15;
  --purple: #8257d4;
  --blue: #2f7fe4;
  --orange: #f2792a;
  --pink: #e8508c;
  --coral: #f2685c;

  --ink: #16233a;
  --mut: #5c6b82;
  --card: #ffffff;
  --border: #e7ecf3;
  --danger: #c0392b;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(10, 20, 40, 0.18);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font: 16px/1.55 Arial, Helvetica, sans-serif;
  /* Rich fallback that shows even before the hero image is added. */
  background: linear-gradient(160deg, #16264a 0%, #123a4a 45%, #0f5a52 100%) fixed;
}

/* Akili hero art anchored bottom-RIGHT. On wide screens the content column shifts left (see .wrap
   media query) so the meerkat gets a clear zone on the right and is never behind the cards. On
   narrow screens a full character can't sit behind full-width content without covering it, so he
   becomes a small, faint corner accent instead. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url("/assets/akili-hero.jpg") right bottom / auto 42vh no-repeat;
  opacity: 0.4;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(90deg, rgba(13, 22, 42, 0.28) 0%, rgba(13, 22, 42, 0.08) 45%, rgba(13, 22, 42, 0) 72%);
}

@media (min-width: 1080px) {
  body::before { background-size: auto min(88vh, 820px); opacity: 1; }
}

a { color: var(--blue); }

/* ===== Top bar ===== */
header.topbar {
  background: linear-gradient(90deg, rgba(16, 26, 46, 0.96), rgba(24, 44, 78, 0.96));
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  border-bottom: 3px solid var(--gold);
}
header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
}
header.topbar .brand .logo { flex: none; }
header.topbar .brand .wordmark { font-size: 22px; font-weight: 800; letter-spacing: 1px; color: var(--gold); line-height: 1; }
header.topbar .brand .tagline { display: block; font-size: 10px; font-weight: 600; color: #cdd7e6; letter-spacing: .2px; }

header.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
header.topbar nav a {
  color: #e7eefb;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: 999px;
}
header.topbar nav a.active, header.topbar nav a:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }
header.topbar button.logout {
  background: var(--gold);
  color: var(--navy);
  border: 0;
  border-radius: 999px;
  padding: 8px 15px;
  font-weight: 800;
  cursor: pointer;
  font-size: 13px;
}
header.topbar button.logout:hover { background: var(--gold-2); }

/* ===== Layout ===== */
.wrap { position: relative; z-index: 1; max-width: 980px; margin: 0 auto; padding: 24px 16px 64px; }
/* On wide screens, shift content left and cap its width so the right side is a clear zone for the
   Akili mascot (keeps him fully visible, never behind the cards). */
@media (min-width: 1080px) {
  .wrap { margin-left: 4vw; margin-right: auto; max-width: 680px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

h1 { font-size: 26px; margin: 6px 0 4px; color: #fff; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35); }
.card h1, .card h2 { color: var(--ink); text-shadow: none; }
h2 { font-size: 19px; margin: 4px 0 10px; color: var(--teal-2); }
p.sub { color: #dbe4f0; margin: 0 0 16px; }
.card p.sub, .card .sub { color: var(--mut); }

label { display: block; font-size: 13px; color: var(--mut); margin: 12px 0 4px; font-weight: 700; }

input[type=text], input[type=tel], input[type=search], textarea, select {
  width: 100%;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fbfcfe;
  color: var(--ink);
}
textarea { resize: vertical; min-height: 90px; }

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  background: var(--gold);
  color: var(--navy);
  border: 0;
  border-radius: 10px;
  padding: 12px 20px;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  margin-top: 14px;
  text-decoration: none;
  text-align: center;
}
.btn:hover { background: var(--gold-2); color: var(--navy); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.teal { background: var(--teal); color: #fff; }
.btn.teal:hover { background: var(--teal-2); color: #fff; }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.gold:hover { background: var(--gold-2); }
.btn.link { background: none; color: var(--blue); padding: 6px 0; margin-top: 0; text-decoration: underline; font-weight: 700; }

.msg { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 14px; display: none; }
.msg.ok { display: block; background: #e7f6ee; color: var(--teal-2); }
.msg.err { display: block; background: #fbe9e7; color: var(--danger); }

/* ===== Tiles (dashboard) - colour-coded per the brand's category system ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
  border-top: 5px solid var(--teal);
  transition: transform .12s ease;
}
.tile:hover { transform: translateY(-3px); }
.tile .ico { font-size: 26px; line-height: 1; margin-bottom: 8px; }
.tile .name { font-weight: 800; margin-bottom: 4px; font-size: 17px; }
.tile .meta { font-size: 13px; color: var(--mut); }
/* category colours cycle through the brand palette */
.tile:nth-child(6n+1) { border-top-color: var(--teal); }
.tile:nth-child(6n+2) { border-top-color: var(--pink); }
.tile:nth-child(6n+3) { border-top-color: var(--blue); }
.tile:nth-child(6n+4) { border-top-color: var(--purple); }
.tile:nth-child(6n+5) { border-top-color: var(--orange); }
.tile:nth-child(6n+6) { border-top-color: var(--gold); }

/* ===== Document rows ===== */
.doc-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.doc-row:last-child { border-bottom: none; }
.doc-row .name { flex: 1; font-weight: 600; }
.doc-row .meta { font-size: 12px; color: var(--mut); }

.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #eaf6f0; color: var(--teal-2); }

/* Collapsible (dropdown) module sections in the document library */
.accordion-head { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 13px 6px; font-weight: 800; color: var(--teal-2); border-bottom: 1px solid var(--border); user-select: none; }
.accordion-head:hover { color: var(--teal); }
.accordion-head .count { font-weight: 600; color: var(--mut); font-size: 13px; }
.accordion-head .chev { margin-left: auto; transition: transform .15s; color: var(--mut); font-size: 13px; }
.accordion-head.open .chev { transform: rotate(90deg); }
.accordion-body { display: none; padding: 2px 6px 8px; }
.accordion-body.open { display: block; }
.doc-row .btn { margin-top: 0; padding: 9px 15px; }

/* ===== Chat ===== */
.chat-log { display: flex; flex-direction: column; gap: 12px; max-height: 55vh; overflow-y: auto; margin-bottom: 12px; }
.bubble { padding: 12px 14px; border-radius: 14px; max-width: 85%; white-space: pre-wrap; }
.bubble.student { align-self: flex-end; background: var(--teal); color: #fff; }
.bubble.akili { align-self: flex-start; background: #f1f5fb; border: 1px solid var(--border); }
.bubble .sources { display: block; margin-top: 8px; font-size: 12px; color: var(--mut); }

/* ===== Quiz ===== */
.quiz-option { display: block; width: 100%; text-align: left; padding: 12px; margin: 6px 0; border-radius: 10px; border: 1px solid var(--border); background: #fbfcfe; cursor: pointer; font: inherit; }
.quiz-option.correct { background: #e7f6ee; border-color: var(--teal); }
.quiz-option.incorrect { background: #fbe9e7; border-color: var(--danger); }
.quiz-option.chosen { border-color: var(--purple); background: #f1ecfb; }
.quiz-option:disabled { cursor: default; }

.quiz-setup-row { margin-bottom: 4px; }

.mode-toggle { display: flex; gap: 8px; margin-top: 6px; }
.mode-toggle button { flex: 1; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: #fbfcfe; cursor: pointer; font: inherit; font-weight: 700; color: var(--ink); }
.mode-toggle button.active { background: var(--purple); color: #fff; border-color: var(--purple); }
.mode-toggle .mode-desc { display: block; font-weight: 400; font-size: 12px; margin-top: 3px; opacity: .85; }

.quiz-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; background: #eaf6f0; color: var(--teal-2); padding: 5px 12px; border-radius: 999px; }
.timer.warn { background: #fbe9e7; color: var(--danger); }

.navigator { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.nav-dot { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: #fbfcfe; cursor: pointer; font: inherit; font-size: 13px; font-weight: 700; color: var(--mut); }
.nav-dot.answered { background: #e7f6ee; color: var(--teal-2); border-color: var(--teal); }
.nav-dot.current { outline: 2px solid var(--purple); outline-offset: 1px; }

.results-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 14px 0; }
.tile-stat { background: #f1f5fb; border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; }
.tile-stat .num { font-size: 26px; font-weight: 800; color: var(--teal-2); }
.tile-stat .lbl { font-size: 12px; color: var(--mut); margin-top: 2px; }
.score-big { font-size: 46px; font-weight: 800; color: var(--teal-2); text-align: center; }
.score-big.fail { color: var(--coral); }

.review-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.review-item:last-child { border-bottom: none; }
.review-item .rq { font-weight: 600; margin-bottom: 4px; }
.source-ref { font-size: 12px; color: var(--mut); margin-top: 6px; display: block; }
.answer-line { font-size: 14px; margin-top: 4px; }
.answer-line.ok { color: var(--teal-2); }
.answer-line.bad { color: var(--danger); }

.empty { color: var(--mut); text-align: center; padding: 30px 10px; }

/* ===== Login ===== */
.login-shell { position: relative; z-index: 1; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; }
.login-hero { text-align: center; margin-bottom: 18px; color: #fff; }
.login-hero .logo-lg { margin: 0 auto 10px; display: block; }
.login-hero h1 { margin: 6px 0 2px; color: #fff; }
.login-hero .tagline { color: var(--gold); font-weight: 700; font-size: 14px; }
.login-hero .avatar { width: 120px; height: 120px; border-radius: 50%; border: 4px solid var(--gold); box-shadow: var(--shadow); object-fit: cover; }
.otp-boxes { display: flex; gap: 8px; }
.otp-boxes input { width: 46px; text-align: center; font-size: 20px; letter-spacing: 2px; }

/* ===== Mobile ===== */
/* Long filenames / titles must wrap, never force horizontal scroll. */
.doc-row .name, .doc-row .meta, .accordion-head, .tile .name, .review-item .rq, .bubble { overflow-wrap: anywhere; word-break: break-word; }

@media (max-width: 640px) {
  header.topbar { padding: 10px 12px; gap: 8px; }
  header.topbar .brand .tagline { display: none; }         /* save the row for nav */
  header.topbar .brand .wordmark { font-size: 19px; }
  header.topbar nav { gap: 2px; width: 100%; order: 3; justify-content: flex-start; }
  header.topbar nav a { padding: 6px 10px; font-size: 13px; }
  header.topbar button.logout { padding: 6px 11px; font-size: 12px; margin-left: auto; }
  h1 { font-size: 22px; }
  .card { padding: 15px 14px; }
  .wrap { padding: 18px 12px 56px; }
  .btn { padding: 11px 16px; }
  .mode-toggle { flex-direction: column; }                 /* stack the two mode buttons */
  .doc-row { flex-wrap: wrap; }                             /* let the download button drop below on tight rows */
}
