*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --blue:        #2563EB;
  --blue-dark:   #1D4ED8;
  --blue-light:  #EFF6FF;
  --green:       #16A34A;
  --green-light: #DCFCE7;
  --red:         #DC2626;
  --bg:          #F1F5F9;
  --white:       #FFFFFF;
  --text:        #0F172A;
  --muted:       #64748B;
  --border:      #E2E8F0;
  --radius:      14px;
  --shadow:      0 1px 3px rgba(0,0,0,.07), 0 4px 14px rgba(0,0,0,.06);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* ── Top nav ───────────────────────────────────────────────────────────────── */

.top-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 11px 16px;
  display: flex;
  align-items: center;
}

.top-nav.hidden { display: none !important; }

.top-nav-logout {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .8125rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.top-nav-logout:active { color: var(--red); }

.top-nav-link {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--blue);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Screens ───────────────────────────────────────────────────────────────── */

.screen { animation: fadeUp .22s ease both; }
.screen.hidden { display: none !important; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Loading / Submitting ──────────────────────────────────────────────────── */

.center-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Progress bar ──────────────────────────────────────────────────────────── */

.progress-bar {
  height: 4px;
  background: var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.progress-bar .fill {
  height: 100%;
  background: var(--blue);
  transition: width .5s ease;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */

.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 22px 20px;
  margin: 14px 14px 0;
  box-shadow: var(--shadow);
}

/* ── Typography ────────────────────────────────────────────────────────────── */

h1 {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 4px;
}

h2 {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 6px;
}

h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.muted  { color: var(--muted); }
.small  { font-size: .875rem; }

.step-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--blue);
  margin-bottom: 6px;
}

/* ── Badge & divider ───────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  background: var(--blue-light);
  color: var(--blue);
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 8px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

/* ── Text inputs ───────────────────────────────────────────────────────────── */

input[type="text"] {
  display: block;
  width: 100%;
  padding: 13px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color .2s;
  margin-top: 14px;
  letter-spacing: .05em;
}

input[type="text"]:focus { border-color: var(--blue); }

.text-input {
  display: block;
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: .9375rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  resize: vertical;
  transition: border-color .2s;
  line-height: 1.5;
}

.text-input:focus { border-color: var(--blue); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */

.btn {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 10px;
  font-size: .9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .1s;
  text-align: center;
  line-height: 1.2;
  margin-top: 16px;
}

.btn:active:not(:disabled) { transform: scale(.98); }

.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--blue-dark); }

.btn.primary:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.btn.primary.unlocked {
  background: var(--green);
  animation: pulse .45s ease;
}

@keyframes pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.025); }
  100% { transform: scale(1); }
}

/* ── Field errors ──────────────────────────────────────────────────────────── */

.field-error {
  color: var(--red);
  font-size: .8125rem;
  margin-top: 6px;
}

.field-error.hidden { display: none; }

.video-error {
  color: var(--red);
  font-size: .875rem;
  text-align: center;
  padding: 24px 16px;
}

/* ── Icon circles ──────────────────────────────────────────────────────────── */

.icon-circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 auto 14px;
}

.icon-circle.success { background: var(--green-light); color: var(--green); }
.icon-circle.error   { background: #FEE2E2;            color: var(--red);   }

/* ── Question blocks ───────────────────────────────────────────────────────── */

.question-block {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.question-block:first-child  { padding-top: 4px; }
.question-block:last-child   { border-bottom: none; padding-bottom: 0; }

.q-header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.q-num {
  flex-shrink: 0;
  background: var(--blue);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  margin-top: 3px;
}

.q-text {
  font-size: .9375rem;
  font-weight: 500;
  line-height: 1.5;
}

.q-inputs { margin-top: 2px; }

/* ── Options (MCQ + multiselect) ───────────────────────────────────────────── */

.option-label {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  margin-bottom: 7px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.option-label:last-child { margin-bottom: 0; }

.option-label.selected {
  border-color: var(--blue);
  background: var(--blue-light);
}

.option-label input[type="radio"],
.option-label input[type="checkbox"] {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  accent-color: var(--blue);
  cursor: pointer;
}

.option-text {
  font-size: .9375rem;
  line-height: 1.45;
}

/* ── Rating ────────────────────────────────────────────────────────────────── */

.rating-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.rating-btn {
  flex: 1;
  padding: 12px 0;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}

.rating-btn.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.rating-btn:active { transform: scale(.93); }

.rating-labels {
  display: flex;
  justify-content: space-between;
  font-size: .7rem;
  color: var(--muted);
  padding: 0 2px;
}

/* ── YouTube player ────────────────────────────────────────────────────────── */

#yt-player-wrap {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  margin: 12px 0 8px;
}

#yt-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.video-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .25s;
  -webkit-tap-highlight-color: transparent;
}

.video-overlay.paused  { background: rgba(0, 0, 0, .42); }
.video-overlay.playing { background: transparent; }

.play-pause-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--blue);
  pointer-events: none;
  transition: opacity .25s, transform .15s;
  padding-left: 4px; /* optical centre for ▶ */
}

.video-overlay.playing .play-pause-btn { opacity: 0; }

.video-overlay:active .play-pause-btn  { transform: scale(.9); }

.fs-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: none;
  background: rgba(0,0,0,.55);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
  padding: 0;
}

.fs-btn:active { background: rgba(0,0,0,.8); }

/* ── Video controls (speed + rewind) ──────────────────────────────────────── */

.video-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0 4px;
  gap: 8px;
}

.rewind-btn {
  background: var(--blue-light);
  color: var(--blue);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.rewind-btn:active { transform: scale(.93); background: #DBEAFE; }

.speed-btns {
  display: flex;
  gap: 6px;
}

.speed-btn {
  background: var(--white);
  color: var(--muted);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}

.speed-btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.speed-btn:active { transform: scale(.93); }

.watch-status {
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.2em;
  margin-bottom: 2px;
}

/* ── Results screen ────────────────────────────────────────────────────────── */

.score-box {
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  margin: 14px 0 20px;
}

.score-box.score-good  { background: var(--green-light); }
.score-box.score-ok    { background: #FEF9C3; }
.score-box.score-low   { background: #FEE2E2; }

.score-number {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1;
}

.score-box.score-good .score-number { color: var(--green); }
.score-box.score-ok   .score-number { color: #92400E; }
.score-box.score-low  .score-number { color: var(--red); }

.score-label {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 4px;
}

.results-rewatch-prompt {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 18px;
  text-align: center;
}

.results-rewatch-prompt p {
  font-size: .875rem;
  color: #991B1B;
  line-height: 1.45;
  margin-bottom: 12px;
}

.btn.rewatch-btn {
  display: inline-block;
  width: auto;
  background: var(--red);
  color: #fff;
  padding: 11px 22px;
  margin-top: 0;
}

.btn.rewatch-btn:active { transform: scale(.97); }

.results-praise {
  background: var(--green-light);
  border: 1px solid #BBF7D0;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 18px;
  text-align: center;
  font-size: .875rem;
  font-weight: 600;
  color: #15803D;
  line-height: 1.5;
}

.result-item {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}

.result-item:last-child { border-bottom: none; }

.result-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.result-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 800;
  flex-shrink: 0;
  color: #fff;
}

.result-badge.correct   { background: var(--green); }
.result-badge.incorrect { background: var(--red); }
.result-badge.open      { background: var(--muted); font-size: .75rem; }

.result-qnum {
  font-size: .8125rem;
  font-weight: 700;
}

.result-header.correct   .result-qnum { color: var(--green); }
.result-header.incorrect .result-qnum { color: var(--red); }
.result-header.open      .result-qnum { color: var(--muted); }

.result-qtext {
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 10px;
}

.result-answer {
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 6px;
}

.result-answer.correct       { background: var(--green-light); }
.result-answer.incorrect     { background: #FEE2E2; }
.result-answer.correct-answer{ background: var(--green-light); }
.result-answer.open          { background: var(--blue-light); }

.result-label {
  display: block;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 3px;
}

.result-answer.correct   .result-label { color: var(--green); }
.result-answer.incorrect .result-label { color: var(--red); }
.result-answer.correct-answer .result-label { color: var(--green); }
.result-answer.open      .result-label { color: var(--blue); }

.result-value {
  font-size: .875rem;
  color: var(--text);
  line-height: 1.4;
}

.result-rationale {
  display: flex;
  gap: 8px;
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 6px;
  font-size: .8125rem;
  color: #92400E;
  line-height: 1.5;
}

.rationale-icon { flex-shrink: 0; }

/* ── Completion screen ─────────────────────────────────────────────────────── */

.completion-hero {
  background: linear-gradient(160deg, #1e3a8a 0%, #2563EB 60%, #3b82f6 100%);
  text-align: center;
  padding: 44px 24px 36px;
  color: #fff;
}

.completion-badge {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 16px;
  animation: popIn .4s cubic-bezier(.175,.885,.32,1.275) both;
}

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.completion-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.03em;
  color: #fff;
  margin-bottom: 6px;
}

.completion-sub {
  font-size: .875rem;
  color: rgba(255,255,255,.7);
  margin-bottom: 6px;
}

.completion-course-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  margin-bottom: 14px;
  padding: 0 8px;
}

.completion-student {
  font-size: .875rem;
  color: rgba(255,255,255,.75);
  margin-bottom: 10px;
}

.completion-school-chip {
  display: inline-block;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: .8rem;
  color: rgba(255,255,255,.9);
  margin-bottom: 28px;
}

.completion-home-btn {
  display: inline-block;
  width: auto;
  padding: 13px 28px;
  background: #fff;
  color: var(--blue);
  border-radius: 10px;
  font-weight: 700;
  font-size: .9375rem;
  text-decoration: none;
  margin-top: 0;
  transition: background .15s, transform .1s;
}

.completion-home-btn:active { transform: scale(.97); background: #f0f7ff; }

.info-chip {
  margin-top: 12px;
  background: var(--blue-light);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .875rem;
  color: var(--blue);
  font-weight: 500;
}

/* ── Completed courses ─────────────────────────────────────────────────────── */

.cat-group { margin-bottom: 16px; }
.cat-group:last-child { margin-bottom: 0; }

.cat-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.course-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  font-size: .9375rem;
  border-bottom: 1px solid var(--border);
}

.course-item:last-child { border-bottom: none; }

/* ── Resume screen ─────────────────────────────────────────────────────────── */

.resume-icon {
  font-size: 2.6rem;
  margin-bottom: 14px;
}

.btn.secondary {
  background: transparent;
  color: var(--muted);
  border: 2px solid var(--border);
  margin-top: 10px;
}

.btn.secondary:hover:not(:disabled) {
  border-color: var(--muted);
  color: var(--text);
}

/* ── Completed courses ─────────────────────────────────────────────────────── */

.tick {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--green-light);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  flex-shrink: 0;
}
