:root {
  --bg: #f7f8fb; --card: #ffffff; --ink: #1f2430; --ink-soft: #5b6172;
  --accent: #5b6bf5; --accent-soft: #eef0ff; --good: #1f9d63; --good-soft: #e7f8ef;
  --bad: #e0524d; --bad-soft: #fdeceb; --border: #e6e8ef; --radius: 16px;
  /* Reading-text scale, toggled by the Small/Med/Large control (app.js). Applied
     only to content she reads (bullets, options, flashcards, chat) — nav chrome
     like tabs/buttons/header stays fixed size so layout doesn't break at Large. */
  --font-scale: 1;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}
.app { max-width: 900px; margin: 0 auto; padding: 20px 16px 80px; }

/* Desktop: use 75% of the viewport instead of a fixed cap. Mobile (below this
   breakpoint) keeps the original near-full-width layout, per Kumar's note
   that mobile gets tested/tuned separately later. */
@media (min-width: 900px) {
  .app { max-width: none; width: 75%; }
}

header.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px 18px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, #5b6bf5, #8b7bf7);
  display: flex; align-items: center; justify-content: center; color: white; font-weight: 700;
}
.brand h1 { font-size: 17px; margin: 0; }
.brand p { margin: 0; font-size: 12px; color: var(--ink-soft); }
.brand-clickable { cursor: pointer; border-radius: 12px; padding: 4px; margin: -4px; }
.brand-clickable:hover { background: var(--accent-soft); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.subject-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 28px 16px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; text-align: center; transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.subject-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(31, 36, 48, 0.08); border-color: var(--accent); }
.subject-tile-mark {
  width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, #5b6bf5, #8b7bf7);
  color: white; font-weight: 700; font-size: 17px; display: flex; align-items: center; justify-content: center;
}
.subject-tile-media img { width: 100%; height: 100px; object-fit: cover; border-radius: 12px; display: block; }
.subject-tile-name { font-size: 14.5px; font-weight: 700; color: var(--ink); }

.font-size-control { display: flex; gap: 3px; border: 1px solid var(--border); border-radius: 999px; padding: 3px; background: var(--card); flex: none; }
.font-size-btn { border: none; background: transparent; padding: 6px 11px; border-radius: 999px; font-weight: 700; color: var(--ink-soft); cursor: pointer; line-height: 1; }
.font-size-btn.active { background: var(--ink); color: white; }
.font-size-btn[data-size="small"] { font-size: 11px; }
.font-size-btn[data-size="medium"] { font-size: 13px; }
.font-size-btn[data-size="large"] { font-size: 15px; }

.picker { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 18px; scrollbar-width: none; }
.picker::-webkit-scrollbar { display: none; }
.pick-chip {
  flex: none; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.pick-chip.active { background: var(--accent); color: white; border-color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.chapter-title { font-size: calc(20px * var(--font-scale)); font-weight: 700; margin: 0 0 4px; }
.chapter-sub { color: var(--ink-soft); font-size: calc(13px * var(--font-scale)); margin: 0 0 16px; }
.summary-text { font-size: calc(14.5px * var(--font-scale)); line-height: 1.65; }
.summary-text strong { color: var(--accent); }

.sections-toolbar { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.sections-toolbar .btn { padding: 7px 14px; font-size: 12px; }

.content-section { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.content-section:last-of-type { margin-bottom: 8px; }
.content-section h3 { margin: 0; }
.section-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 15px; background: var(--bg); border: none; cursor: pointer; text-align: left;
}
.section-heading { font-size: calc(13.5px * var(--font-scale)); font-weight: 700; color: var(--ink); text-transform: uppercase; letter-spacing: 0.02em; }
.section-toggle .chevron { flex: none; color: var(--ink-soft); font-size: 12px; transition: transform 0.15s ease; }
.content-section.open .section-toggle .chevron { transform: rotate(90deg); }
.section-body { display: none; padding: 14px 15px 16px; }
.content-section.open .section-body { display: block; }
.bullet-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.bullet-list li { line-height: 1.5; }
.bullet-list strong { color: var(--accent); }
.bullet-list li.bullet-main { font-size: calc(16.5px * var(--font-scale)); font-weight: 600; }
.sub-bullet-list { margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; list-style: circle; }
.sub-bullet-list li { font-size: calc(13px * var(--font-scale)); font-weight: 400; color: var(--ink-soft); line-height: 1.45; }

.visuals-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin: 16px 0; }
.visual-card { margin: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg); }
.visual-card img { width: 100%; height: 120px; object-fit: cover; display: block; }
.visual-card figcaption { font-size: calc(11.5px * var(--font-scale)); color: var(--ink-soft); padding: 7px 9px; line-height: 1.35; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.term-chip { background: var(--accent-soft); color: var(--accent); font-size: calc(12.5px * var(--font-scale)); font-weight: 600; padding: 6px 12px; border-radius: 999px; border: none; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab-btn { flex: 1; padding: 11px; border-radius: 12px; border: 1px solid var(--border); background: var(--card); font-weight: 600; font-size: 13px; color: var(--ink-soft); cursor: pointer; }
.tab-btn.active { background: var(--ink); color: white; border-color: var(--ink); }
.section { display: none; }
.section.active { display: block; }

.flash-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.flashcard {
  width: 100%; max-width: 480px; height: 190px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), #8b7bf7); color: white;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; font-size: calc(17px * var(--font-scale)); font-weight: 600; cursor: pointer; user-select: none;
}
.flashcard.flipped { background: linear-gradient(135deg, #1f2430, #3a4159); }
.flash-controls { display: flex; gap: 10px; }
.flash-progress { font-size: calc(12.5px * var(--font-scale)); color: var(--ink-soft); }
.btn { padding: 10px 18px; border-radius: 12px; border: none; background: var(--ink); color: white; font-weight: 600; font-size: 13.5px; cursor: pointer; }
.btn.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--border); }

.quiz-progress-bar { height: 6px; background: var(--accent-soft); border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.quiz-progress-fill { height: 100%; background: var(--accent); }
.quiz-count { font-size: calc(12px * var(--font-scale)); font-weight: 700; color: var(--accent); margin-bottom: 10px; }
.question-text { font-size: calc(15.5px * var(--font-scale)); font-weight: 600; margin-bottom: 14px; }
.options { display: flex; flex-direction: column; gap: 9px; }
.option { padding: 13px 15px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--card); font-size: calc(14px * var(--font-scale)); cursor: pointer; text-align: left; }
.option.correct { background: var(--good-soft); border-color: var(--good); color: var(--good); font-weight: 600; }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); font-weight: 600; }
.feedback { margin-top: 14px; padding: 12px 13px; border-radius: 10px; background: var(--accent-soft); }
.feedback-headline { margin: 0 0 8px; font-size: calc(13.5px * var(--font-scale)); font-weight: 700; }
.elimination-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.elim-item { display: flex; gap: 8px; align-items: flex-start; font-size: calc(13px * var(--font-scale)); line-height: 1.45; color: var(--ink-soft); }
.elim-item .elim-icon { flex: none; }
.elim-item.elim-correct { color: var(--good); }
.elim-item.elim-correct strong { color: var(--good); }
.elim-item.elim-wrong strong { color: var(--ink); }
.quiz-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; }
.quiz-nav .btn { flex: 1; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.quiz-result { text-align: center; padding: 20px 0; }
.quiz-result .score { font-size: calc(40px * var(--font-scale)); font-weight: 800; color: var(--accent); }
.quiz-result .quiz-nav { margin-top: 18px; }

.ask-box { display: flex; gap: 8px; margin-bottom: 14px; }
.ask-box input { flex: 1; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--border); font-size: calc(14px * var(--font-scale)); font-family: inherit; }
.chat-log { display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 12px 14px; border-radius: 12px; font-size: calc(14px * var(--font-scale)); line-height: 1.5; max-width: 90%; }
.msg.user { align-self: flex-end; background: var(--ink); color: white; }
.msg.bot { align-self: flex-start; background: var(--accent-soft); color: var(--ink); }

.auth-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  max-width: 380px; margin: 64px auto; padding: 32px 28px; text-align: center;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.auth-card .brand-mark.large { width: 52px; height: 52px; font-size: 18px; margin-bottom: 10px; }
.auth-card h1 { font-size: 19px; margin: 0; }
.auth-sub { margin: 0 0 20px; font-size: 13px; color: var(--ink-soft); }
.auth-card form { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.auth-card label { text-align: left; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-top: 4px; }
.auth-card input { padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--border); font-size: 14px; font-family: inherit; }
.auth-card .btn { margin-top: 8px; }
.link-btn { margin-top: 16px; background: none; border: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px; }
.error-text { color: var(--bad); font-size: 13px; margin: 4px 0 0; text-align: left; }

.header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.mock-badge { background: var(--bad-soft); color: var(--bad); font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.upload-row { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; padding-top: 14px; border-top: 1px solid var(--border); }
.upload-row input[type="file"] { font-size: 12.5px; color: var(--ink-soft); flex: 1; }
.upload-status { font-size: 12.5px; color: var(--ink-soft); }
