/* ==========================================================================
   E-Note Learning Application Package (ELAP)
   Mobile-first stylesheet.  Plain CSS3 -- no framework, no build step.
   ========================================================================== */

:root {
  --navy:      #1e3a8a;
  --blue:      #1d4ed8;
  --blue-soft: #eff6ff;
  --teal:      #0f766e;   /* darkened: #0d9488 gave white text only 3.74:1 */
  --teal-soft: #f0fdfa;
  --amber:     #d97706;
  --amber-text:#b45309;   /* amber dark enough for body text on white */
  --amber-soft:#fffbeb;
  --rose:      #e11d48;
  --rose-soft: #fff1f2;

  --ink:       #0f172a;
  --body:      #334155;
  --muted:     #4b5a6e;   /* darkened: #64748b measured only 4.34:1 on white */
  --line:      #e2e8f0;
  --card:      #ffffff;
  --page:      #f1f5f9;
  --focus:     #1d4ed8;

  /* Fluid type scale (Utopia method), 360px -> 1240px viewport.
     Sizes grow with the screen instead of jumping at a breakpoint, and the
     floor is set for a small Android phone read in daylight. */
  --step--2:   clamp(0.750rem, 0.7244rem + 0.1136vw, 0.8125rem);  /* 12 -> 13 */
  --step--1:   clamp(0.844rem, 0.8182rem + 0.1136vw, 0.9063rem);  /* 13.5 -> 14.5 */
  --step-0:    clamp(1.000rem, 0.9744rem + 0.1136vw, 1.0625rem);  /* 16 -> 17 */
  --step-1:    clamp(1.094rem, 1.0554rem + 0.1705vw, 1.1875rem);  /* 17.5 -> 19 */
  --step-2:    clamp(1.188rem, 1.1364rem + 0.2273vw, 1.3125rem);  /* 19 -> 21 */
  --step-3:    clamp(1.375rem, 1.2983rem + 0.3409vw, 1.5625rem);  /* 22 -> 25 */
  --step-4:    clamp(1.563rem, 1.4347rem + 0.5682vw, 1.8750rem);  /* 25 -> 30 */

  --radius:    14px;
  --shadow:    0 1px 2px rgba(15,23,42,.06), 0 6px 20px rgba(15,23,42,.06);
  --tabbar-h:  62px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: var(--step-0);
  line-height: 1.6;
  color: var(--body);
  background: var(--page);
  overscroll-behavior-y: none;
  /* the default blue flash on Android looks unfinished; :active states below
     provide the feedback instead */
  -webkit-tap-highlight-color: transparent;
}

::selection { background: #bfdbfe; color: var(--ink); }

/* Keyboard focus. A box-shadow ring is used rather than an outline so that it
   follows the border radius. Only shown for keyboard users, never on tap. */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--focus);
  border-radius: 8px;
}
.topbar :focus-visible { box-shadow: 0 0 0 3px var(--navy), 0 0 0 5px #fff; }

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

h1, h2, h3, h4 { color: var(--ink); line-height: 1.3; margin: 0 0 .5em; }

[hidden] { display: none !important; }

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; background: var(--navy); color: #dbeafe;
}
.splash-mark {
  font-weight: 800; letter-spacing: .16em; font-size: 30px; color: #fff;
  border: 3px solid rgba(255,255,255,.35); border-radius: 16px; padding: 12px 22px;
}
.splash p { margin: 0; font-size: 14px; }

/* ---------- Auth ---------- */
.auth-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 22px 16px;
  background: linear-gradient(160deg, #1e3a8a 0%, #1d4ed8 55%, #0d9488 100%);
}
.auth-card {
  width: 100%; max-width: 430px; background: var(--card);
  border-radius: 20px; padding: 26px 22px 28px; box-shadow: 0 24px 60px rgba(2,6,23,.28);
}
.brand { text-align: center; margin-bottom: 20px; }
.brand h1 { font-size: var(--step-4); color: var(--navy); margin: 0 0 6px; }
.brand-name { margin: 0 0 4px; font-size: var(--step-1); font-weight: 700; color: var(--ink); }
.brand-sub { margin: 0; font-size: var(--step--1); color: var(--muted); }

.tabs {
  display: flex; gap: 6px; background: var(--page);
  border-radius: 11px; padding: 5px; margin-bottom: 18px;
}
.tab {
  flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 8px;
  font: inherit; font-size: var(--step--1); font-weight: 600; color: var(--muted); cursor: pointer;
}
.tab.is-active { background: var(--card); color: var(--navy); box-shadow: var(--shadow); }

.auth-form label,
.tutor-form label { display: block; margin-bottom: 13px; font-size: var(--step--1); font-weight: 600; color: var(--ink); }
.field-row { display: flex; gap: 11px; }
.field-row label { flex: 1; }
.req { color: var(--rose); }
.opt { color: var(--muted); font-weight: 400; }

input, select, textarea {
  width: 100%; margin-top: 6px; padding: 12px 13px;
  border: 1.5px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 16px; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
textarea { resize: vertical; }

.form-error {
  display: none; margin: 0 0 12px; padding: 10px 12px; border-radius: 9px;
  background: var(--rose-soft); color: #9f1239; font-size: var(--step--1);
  border: 1px solid #fecdd3;
}
.form-error.is-shown { display: block; }
.hint { font-size: var(--step--1); color: var(--muted); margin: 12px 0 0; }
.hint-top { margin: 0 0 14px; }
.hint-center { text-align: center; }
.link-btn {
  border: 0; background: none; padding: 6px 4px; font: inherit; font-weight: 600;
  color: var(--blue); text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 11px; padding: 13px 18px; font: inherit;
  font-size: var(--step-0); font-weight: 650; cursor: pointer;
  transition: opacity .15s, transform .06s, box-shadow .15s;
  min-height: 48px;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-block { width: 100%; display: block; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-teal    { background: var(--teal); color: #fff; }
.btn-quiet   { background: var(--page); color: var(--ink); margin-top: 9px; }
.btn-danger  { background: var(--rose-soft); color: #9f1239; margin-top: 9px; }
.btn-ghost   { background: #fff; color: var(--blue); border: 1.5px solid var(--line); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--navy); color: #fff;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title strong { display: block; font-size: var(--step-0); line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title span { font-size: var(--step--2); color: #dbeafe; }
.icon-btn {
  border: 0; background: rgba(255,255,255,.14); color: #fff;
  width: 44px; height: 44px; border-radius: 11px; font-size: 17px; cursor: pointer;
  flex: none;
}

/* ---------- Sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.5);
  display: flex; align-items: flex-end; justify-content: center; padding: 16px;
}
.sheet-card {
  width: 100%; max-width: 430px; background: #fff; border-radius: 18px; padding: 20px;
}
.sheet-id, .sheet-code { margin: 0 0 6px; font-size: 14px; }
.sheet-code { margin-bottom: 16px; color: var(--muted); }
.sheet-code strong { color: var(--blue); letter-spacing: .04em; }

/* ---------- Layout ---------- */
#main { padding: 16px 14px calc(var(--tabbar-h) + 26px); max-width: 720px; margin: 0 auto; }
.page-title { font-size: var(--step-3); margin-bottom: 4px; }
.page-sub { margin: 0 0 16px; font-size: var(--step--1); color: var(--muted); }
.section-heading { font-size: var(--step--1); text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 22px 0 11px; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(150deg, var(--navy), var(--blue));
  color: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.hero h2 { color: #fff; font-size: var(--step-3); margin-bottom: 8px; }
.hero p { margin: 0; font-size: var(--step--1); color: #dbeafe; }
.overview-audio {
  margin-top: 16px; padding: 13px; border-radius: 12px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
}
.hero .overview-audio-title { margin: 0 0 9px; font-size: var(--step-0); font-weight: 700; color: #fff; }
.overview-audio audio { display: block; width: 100%; }
.hero .overview-audio-cost { margin: 7px 0 0; font-size: var(--step--2); }
.overview-audio details { margin-top: 9px; }
.overview-audio summary { cursor: pointer; font-size: var(--step--1); font-weight: 600; color: #fff; }
.hero .overview-audio details p { margin-top: 8px; color: #eff6ff; }
.hero-stats { display: flex; gap: 10px; margin-top: 18px; }
.hero-stats div {
  flex: 1; background: rgba(255,255,255,.14); border-radius: 11px; padding: 10px 8px; text-align: center;
}
.hero-stats strong { display: block; font-size: var(--step-2); color: #fff; }
.hero-stats span { font-size: var(--step--2); color: #dbeafe; }

/* ---------- Module cards ---------- */
.module-list { display: grid; gap: 11px; }
.module-card {
  display: flex; gap: 13px; align-items: flex-start; text-align: left; width: 100%;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 14px; cursor: pointer; font: inherit; color: inherit;
}
.module-card:active { background: var(--blue-soft); }
.module-card.is-done { border-color: #99f6e4; background: var(--teal-soft); }
.module-num {
  flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--blue-soft);
  color: var(--blue); font-weight: 700; font-size: 14.5px;
  display: flex; align-items: center; justify-content: center;
}
.module-card.is-done .module-num { background: var(--teal); color: #fff; }
.module-info { flex: 1; min-width: 0; }
.module-info h4 { font-size: var(--step-1); margin: 0 0 3px; }
.module-info p { margin: 0 0 8px; font-size: var(--step--1); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: var(--step--2); padding: 4px 9px; border-radius: 20px;
  background: var(--page); color: var(--muted);
}
.chip-score { background: var(--teal-soft); color: #0f766e; font-weight: 650; }

/* ---------- Lesson ---------- */
.lesson h2 { font-size: var(--step-3); }
.lesson .lesson-meta { font-size: var(--step--1); color: var(--muted); margin: 0 0 16px; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 17px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h3 { font-size: var(--step-2); }
.card p { margin: 0 0 12px; }
.card p:last-child { margin-bottom: 0; }

.objectives { background: var(--blue-soft); border: 1.5px solid #bfdbfe; }
.objectives h3 { color: var(--navy); font-size: var(--step--1); text-transform: uppercase; letter-spacing: .05em; }
.objectives .objectives-lead { margin: 0 0 8px; font-weight: 600; color: var(--ink); }
.objectives ol { margin: 0; padding-left: 28px; font-size: var(--step-0); list-style-type: lower-roman; }
.objectives li { margin-bottom: 6px; padding-left: 4px; }

/* A section written for one learning objective carries its numeral, so the
   notes can be read against the objectives list above them. */
.objective-tag {
  display: inline-block; margin-bottom: 6px; padding: 3px 9px; border-radius: 999px;
  background: var(--blue-soft); color: var(--navy); font-size: var(--step--2);
  font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}
.card .figure { margin: 14px 0; }

/* Comparison tables inside the lesson notes. These are short and must wrap on
   a phone, unlike the wide researcher tables further down. */
.lesson-table-wrap { overflow-x: auto; margin: 4px 0 14px; }
.lesson-table { min-width: 0; font-size: var(--step--1); border: 1.5px solid var(--line); }
.lesson-table th, .lesson-table td { white-space: normal; vertical-align: top; border: 1px solid var(--line); }
.lesson-table th { position: static; color: var(--navy); background: var(--blue-soft); }
.lesson-table tbody th { text-transform: none; letter-spacing: 0; font-size: var(--step--1); }

.figure { background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 14px; overflow-x: auto; }
/* Browsers give <figure> 40px side margins by default; on a phone that is
   width the diagram needs. */
.figure { margin: 0 0 14px; }
.figure > a { display: block; }
.figure img { display: block; width: 100%; min-width: 520px; height: auto; }
.figure figcaption { font-size: var(--step--1); color: var(--muted); margin-top: 9px; text-align: center; }
.figure-scroll { font-size: var(--step--1); color: var(--amber-text); text-align: center; margin: 6px 0 0; }

.keypoints { background: var(--amber-soft); border: 1.5px solid #fde68a; border-radius: 12px;
  padding: 14px; margin-top: 4px; }
.keypoints strong { display: block; font-size: var(--step--2); text-transform: uppercase;
  letter-spacing: .06em; color: #92400e; margin-bottom: 8px; }
.keypoints ul { margin: 0; padding-left: 18px; font-size: var(--step-0); color: #78350f; }
.keypoints li { margin-bottom: 5px; }

.video-figure video {
  display: block; width: 100%; height: auto; border-radius: 10px;
  background: #0f172a; min-width: 0;
}
.video-figure figcaption { text-align: left; }
.video-cost {
  display: block; margin-top: 6px; font-size: var(--step--2);
  color: var(--muted);
}

.mnemonic {
  background: #f5f3ff; border: 1.5px solid #ddd6fe; border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.mnemonic strong { display: block; font-size: var(--step--2); text-transform: uppercase;
  letter-spacing: .06em; color: #6d28d9; margin-bottom: 8px; }
.mnemonic p { margin: 0; font-size: var(--step-0); color: #4c1d95; }
.mnemonic-hook {
  font-size: var(--step-2) !important; font-weight: 700; color: #5b21b6 !important;
  margin-bottom: 8px !important; line-height: 1.35;
}

.lesson-actions { display: grid; gap: 10px; margin: 20px 0 8px; }

/* ---------- Quiz ---------- */
.quiz h2 { font-size: var(--step-3); }
.q-card { background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 13px; }
.q-num { font-size: var(--step--2); font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em; }
.q-text { font-size: var(--step-1); font-weight: 600; color: var(--ink); margin: 5px 0 13px; }

.opt-row {
  display: flex; gap: 11px; align-items: flex-start; width: 100%; text-align: left;
  border: 1.5px solid var(--line); background: #fff; border-radius: 11px;
  padding: 13px; margin-bottom: 8px; font: inherit; font-size: var(--step-0);
  min-height: 48px; align-items: center;
  color: var(--body); cursor: pointer;
}
.opt-row:last-child { margin-bottom: 0; }
.opt-row.is-picked { border-color: var(--blue); background: var(--blue-soft); }
.opt-letter {
  flex: none; width: 25px; height: 25px; border-radius: 7px; background: var(--page);
  color: var(--muted); font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.opt-row.is-picked .opt-letter { background: var(--blue); color: #fff; }
.opt-row.is-right { border-color: var(--teal); background: var(--teal-soft); }
.opt-row.is-right .opt-letter { background: var(--teal); color: #fff; }
.opt-row.is-wrong { border-color: var(--rose); background: var(--rose-soft); }
.opt-row.is-wrong .opt-letter { background: var(--rose); color: #fff; }
.opt-row[disabled] { cursor: default; }

.explain { margin-top: 11px; padding: 12px; border-radius: 10px;
  background: var(--page); font-size: var(--step--1); color: var(--body); }
.explain strong { color: var(--ink); }

.score-card { text-align: center; background: var(--card); border-radius: var(--radius);
  padding: 24px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.score-ring { font-size: 42px; font-weight: 800; color: var(--blue); line-height: 1; }
.score-card p { margin: 8px 0 0; color: var(--muted); font-size: var(--step-0); }
.score-card.is-pass .score-ring { color: var(--teal); }

/* ---------- Progress ---------- */
.prog-row { background: var(--card); border-radius: 12px; padding: 13px 15px;
  margin-bottom: 9px; box-shadow: var(--shadow); }
.prog-row h4 { font-size: var(--step-1); margin: 0 0 8px; }
.bar { height: 8px; border-radius: 6px; background: var(--page); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--teal); border-radius: 6px; }
.prog-meta { display: flex; justify-content: space-between; font-size: var(--step--1);
  color: var(--muted); margin-top: 7px; }

/* ---------- Tutor ---------- */
.thread { display: grid; gap: 11px; margin-bottom: 14px; }
.bubble { border-radius: 14px; padding: 13px 15px; font-size: var(--step-0); white-space: pre-wrap; }
.bubble-you { background: var(--blue); color: #fff; margin-left: 34px; border-bottom-right-radius: 4px; }
.bubble-ai  { background: var(--card); color: var(--body); margin-right: 22px;
  border: 1.5px solid var(--line); border-bottom-left-radius: 4px; }
.bubble-ai b { color: var(--ink); }
.tutor-form { display: flex; gap: 9px; align-items: flex-end; }
.tutor-form textarea { margin: 0; }
.tutor-form .btn { flex: none; }

.notice { background: var(--amber-soft); border: 1.5px solid #fde68a; color: #78350f;
  border-radius: 11px; padding: 12px 14px; font-size: var(--step--1); margin-bottom: 14px; }

.mode-switch { margin-bottom: 12px; }
.context-chip {
  display: inline-block; background: var(--blue-soft); color: var(--navy);
  border: 1.5px solid #bfdbfe; border-radius: 20px;
  padding: 6px 14px; font-size: var(--step--1); font-weight: 600; margin-bottom: 14px;
}

.empty { text-align: center; color: var(--muted); font-size: var(--step-0); padding: 30px 10px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; background: #fff; border-top: 1.5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  flex: 1; border: 0; background: transparent; font: inherit; font-size: var(--step--2);
  font-weight: 600; color: var(--muted); padding: 9px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  height: var(--tabbar-h);
}
.tabicon { font-size: 18px; line-height: 1.2; }
.tabbtn.is-active { color: var(--blue); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 18px); z-index: 80;
  background: var(--ink); color: #fff; font-size: var(--step--1);
  padding: 11px 17px; border-radius: 11px; max-width: 90%; text-align: center;
  box-shadow: 0 10px 30px rgba(2,6,23,.3);
}

/* ---------- Researcher dashboard ---------- */
.dash { max-width: 1080px; margin: 0 auto; padding: 22px 16px 60px; }
.dash-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  justify-content: space-between; margin-bottom: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 11px; margin-bottom: 22px; }
.stat { background: var(--card); border-radius: 12px; padding: 15px; box-shadow: var(--shadow); }
.stat strong { display: block; font-size: 25px; color: var(--navy); line-height: 1.2; }
.stat span { font-size: 12.5px; color: var(--muted); }
.table-wrap { overflow-x: auto; background: var(--card); border-radius: 12px;
  box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; min-width: 860px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--page); font-size: 12px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
.export-row { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 18px; }
.export-row a { text-decoration: none; }

@media (min-width: 640px) {
  #main { padding-left: 20px; padding-right: 20px; }
  .lesson-actions { grid-template-columns: 1fr 1fr; }
  .figure img { min-width: 0; }
}
