:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --header-bg: #1e293b;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
.app-header {
  background: var(--header-bg);
  color: white;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: white;
}
.back-link {
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  white-space: nowrap;
}
.back-link:hover { color: white; text-decoration: none; }

/* ── Product tabs ── */
.product-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  background: white;
  overflow-x: auto;
}
.tab-btn {
  padding: 12px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.15s;
}
.tab-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}
.tab-btn.pending { opacity: 0.45; cursor: not-allowed; }
.pending-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  font-size: 10px;
  background: #f1f5f9;
  border-radius: 4px;
  color: var(--muted);
}

/* ── Main content wrapper ── */
.main-content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.lesson-count { font-size: 13px; color: var(--muted); }
#search {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  width: 240px;
  background: white;
  outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79,70,229,0.12); }

/* ── Lesson grid ── */
.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(188px, 1fr));
  gap: 12px;
}
.lesson-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s, border-color 0.15s;
  box-shadow: var(--shadow);
}
.lesson-card:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
  border-color: var(--accent);
}
.lesson-card .lesson-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.activity-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.pill {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

/* ── Viewer layout ── */
.viewer-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.nav-link { font-size: 13px; }
.nav-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s;
}
.nav-btn:hover:not(:disabled) { background: var(--bg); }
.nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.nav-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  text-align: center;
}
.lesson-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  font-size: 13px;
  cursor: pointer;
}

.viewer-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: start;
}

/* ── Sidebar ── */
.activity-sidebar {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}
.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 4px 10px 10px;
}
.activity-list-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 2px;
  transition: background 0.1s;
  line-height: 1.4;
}
.activity-list-item:hover { background: var(--bg); }
.activity-list-item.active {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

/* ── Content area ── */
.content-area {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  min-height: 400px;
}

/* ── Shared activity elements ── */
.act-header { margin-bottom: 24px; }
.act-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 10px;
  background: rgba(79, 70, 229, 0.1);
  color: var(--accent);
}
.act-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
}
.instruction-text { color: var(--muted); margin: 8px 0 0; font-size: 14px; }
.score-badge { font-size: 13px; color: var(--muted); margin-left: 12px; vertical-align: middle; }

/* ── Video ── */
.video-wrap { width: 100%; margin-bottom: 24px; }
.video-wrap video {
  width: 100%;
  border-radius: var(--radius);
  max-height: 560px;
  background: #000;
  display: block;
}

/* ── Lesson Intro extras ── */
.intro-images {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.intro-images img {
  max-height: 180px;
  max-width: 300px;
  border-radius: var(--radius);
  object-fit: contain;
  border: 1px solid var(--border);
}

/* ── Quiz cards ── */
.quiz-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 20px;
}
.round-counter {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 12px;
}
.question-text {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 20px;
  line-height: 1.5;
}
.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.answer-btn {
  padding: 13px 15px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: white;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  line-height: 1.4;
  transition: border-color 0.12s, background 0.12s;
}
.answer-btn:hover:not(:disabled) { border-color: var(--accent); background: #f8f7ff; }
.answer-btn.correct  { border-color: #16a34a; background: #f0fdf4; color: #14532d; }
.answer-btn.wrong    { border-color: #dc2626; background: #fef2f2; color: #7f1d1d; }
.answer-btn:disabled { cursor: default; }

/* ── EOLQ ── */
.eolq-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
.paragraph-card {
  background: #fffbf0;
  border-left: 4px solid var(--accent);
  padding: 16px 18px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-wrap;
}

/* ── Rounds activity (generic) ── */
.rounds-count {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}
.rounds-list { display: flex; flex-direction: column; gap: 12px; }
.round-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.round-idx {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
}
.round-field { margin-bottom: 8px; }
.round-field:last-child { margin-bottom: 0; }
.field-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}
.field-value { font-size: 14px; line-height: 1.5; }
.field-value.main-q { font-size: 15px; font-weight: 600; }
.answer-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin: 2px 3px 2px 0;
  line-height: 1.4;
}
.correct-tag { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }
.distractor-tag { background: #f1f5f9; color: var(--muted); border: 1px solid var(--border); }

/* ── Reading placeholder ── */
.reading-placeholder {
  text-align: center;
  padding: 48px 24px 32px;
}
.placeholder-icon { font-size: 56px; margin-bottom: 16px; line-height: 1; }
.reading-placeholder h3 { font-size: 18px; margin: 0 0 10px; }
.reading-placeholder p { color: var(--muted); margin: 6px 0; }
.reading-placeholder code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.reading-images {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 24px;
}
.reading-images img {
  max-width: 200px;
  max-height: 150px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 1px solid var(--border);
}

/* ── Default fallback renderer ── */
.section { margin-bottom: 24px; }
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}
.asset-thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.asset-thumb img {
  width: 96px;
  height: 72px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border);
  display: block;
}
.audio-list { display: flex; flex-direction: column; gap: 8px; }
.audio-item { display: flex; align-items: center; gap: 10px; }
.audio-item audio { height: 32px; }
.audio-name { font-size: 11px; color: var(--muted); word-break: break-all; }

/* Words list (word-wipeout, define-it, etc.) */
.words-list { display: flex; flex-direction: column; gap: 10px; }
.word-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.word-label { font-size: 16px; font-weight: 700; color: var(--accent); }
.word-sentence { font-size: 14px; font-style: italic; color: var(--text); }
.word-def { font-size: 13px; color: var(--muted); }

/* Var dump */
.var-list { display: flex; flex-direction: column; gap: 6px; }
.var-row { display: flex; gap: 12px; font-size: 12px; }
.var-key { font-weight: 600; color: var(--accent); white-space: nowrap; }
.var-val { color: var(--muted); word-break: break-all; }

/* ── Score screen ── */
.score-screen { text-align: center; padding: 48px 24px; }
.final-score {
  font-size: 72px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 12px;
}
.score-msg { font-size: 18px; color: var(--muted); margin-bottom: 28px; }
.restart-btn {
  padding: 12px 28px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.12s;
}
.restart-btn:hover { opacity: 0.85; }

/* ── Debug panel ── */
.debug-panel {
  margin-top: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.debug-panel summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 11px;
  color: var(--muted);
  user-select: none;
}
.debug-panel summary:hover { background: var(--bg); }
.debug-panel pre {
  margin: 0;
  padding: 14px;
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
  background: #f8f9fa;
  border-top: 1px solid var(--border);
  max-height: 320px;
  overflow-y: auto;
}

/* ── Loading / error / empty states ── */
.loading { text-align: center; padding: 56px 24px; color: var(--muted); font-size: 14px; }
.error   { text-align: center; padding: 40px; color: #dc2626; font-size: 14px; }
.no-media {
  background: #f8f9fa;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.no-results { text-align: center; padding: 40px; color: var(--muted); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .viewer-layout { grid-template-columns: 1fr; }
  .activity-sidebar { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .eolq-body  { grid-template-columns: 1fr; }
  .answer-grid { grid-template-columns: 1fr; }
  .main-content { padding: 14px; }
  .final-score { font-size: 52px; }
}
