:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #172033;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: #334155;
  --primary: #38bdf8;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --shadow: 0 20px 50px rgba(0,0,0,.22);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #111827 55%, #020617 100%);
  color: var(--text);
  overflow-x: hidden;
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(15,23,42,.86);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
}
.topbar-copy { min-width: 0; }
.topbar-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}
h1 { margin: 0 0 6px; font-size: 24px; line-height: 1.2; }
p { color: var(--muted); }
.topbar p { margin: 0; }
.badge,
.mobile-question-counter {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  white-space: nowrap;
}
.badge {
  color: var(--primary);
  background: rgba(56,189,248,.08);
}
.mobile-question-counter {
  display: none;
  color: #cbd5e1;
  background: rgba(148,163,184,.08);
}
.layout { padding: 22px; max-width: 1600px; margin: 0 auto; }
.panel {
  background: rgba(17,24,39,.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.controls { padding: 18px; margin-bottom: 18px; }
.control-grid {
  display: grid;
  grid-template-columns: 180px 200px minmax(260px, 1fr) 160px;
  gap: 12px;
}
label { color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
select, input[type="search"] {
  width: 100%;
  min-height: 46px;
  background: #020617;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
  font: inherit;
}
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 14px; }
.stat {
  background: rgba(2,6,23,.5);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.stat strong { display: block; font-size: 20px; margin-bottom: 4px; }
.stat span { color: var(--muted); font-size: 12px; }
.nav-row, .action-row, .manual-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
button, a#openPdfLink {
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  border-radius: 12px;
  padding: 11px 14px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 650;
  font: inherit;
}
button:hover, a#openPdfLink:hover { border-color: var(--primary); }
button.primary { background: var(--primary); color: #00111c; border-color: var(--primary); }
button.secondary { background: rgba(148,163,184,.08); }
button.danger { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.35); color: #fecaca; }
.workarea { display: grid; grid-template-columns: minmax(0, 1fr) 520px; gap: 18px; align-items: start; }
.question-card { padding: 22px; min-height: 680px; }
.question-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
}
.pill.auto { color: #bae6fd; border-color: rgba(56,189,248,.35); }
.pill.manual { color: #fde68a; border-color: rgba(245,158,11,.45); }
h2 { margin: 0 0 16px; line-height: 1.3; }
.prompt {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  line-height: 1.6;
  margin: 0 0 16px;
  padding: 16px;
  border-radius: 14px;
  background: rgba(2,6,23,.45);
  border: 1px solid var(--line);
}
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: start;
  background: rgba(2,6,23,.36);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
}
.option:hover { border-color: rgba(56,189,248,.45); }
.option input { margin-top: 2px; }
.option-text { white-space: pre-wrap; line-height: 1.5; }
.result, .manual-box {
  margin-top: 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 15px;
  background: rgba(2,6,23,.5);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.result.correct { border-color: rgba(34,197,94,.6); background: rgba(34,197,94,.08); }
.result.wrong { border-color: rgba(239,68,68,.65); background: rgba(239,68,68,.08); }
.result.revealed { border-color: rgba(56,189,248,.4); }
.hidden { display: none; }
.source-panel { padding: 16px; position: sticky; top: 104px; }
.source-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.source-head h3 { margin: 0 0 4px; }
.source-head p { margin: 0; font-size: 13px; }
iframe { width: 100%; height: 720px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
footer {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px 22px 36px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.mobile-tabs,
.mobile-quickbar {
  display: none;
}
.mobile-tabs {
  gap: 10px;
  margin: 0 0 14px;
}
.tab-btn {
  flex: 1;
  text-align: center;
  background: rgba(2,6,23,.58);
}
.tab-btn.active {
  background: rgba(56,189,248,.12);
  border-color: rgba(56,189,248,.45);
  color: #d8f3ff;
}
.mobile-quickbar {
  position: sticky;
  bottom: 0;
  z-index: 25;
  width: 100%;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: rgba(2,6,23,.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  gap: 10px;
}
.mobile-quickbar button {
  flex: 1;
}
@media (max-width: 1100px) {
  .workarea { grid-template-columns: 1fr; }
  .source-panel { position: static; }
  iframe { height: 620px; }
  .control-grid { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 800px) {
  body { padding-bottom: 82px; }
  .topbar {
    padding: 16px;
    gap: 12px;
    flex-direction: column;
    align-items: stretch;
  }
  .topbar-side {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .mobile-question-counter { display: inline-flex; }
  .layout { padding: 12px; }
  .controls { padding: 14px; }
  .control-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat strong { font-size: 18px; }
  .nav-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .nav-row button { width: 100%; }
  .question-card,
  .source-panel { padding: 16px; }
  .question-card { min-height: auto; }
  .source-head { align-items: flex-start; flex-direction: column; }
  iframe { height: 68vh; min-height: 460px; }
  footer { flex-direction: column; padding: 16px 12px 110px; }
  .mobile-tabs,
  .mobile-quickbar {
    display: flex;
  }
  #workarea.mobile-source #questionPanel {
    display: none;
  }
  #workarea.mobile-question #sourcePanel {
    display: none;
  }
}
@media (max-width: 520px) {
  h1 { font-size: 22px; }
  .badge,
  .mobile-question-counter { font-size: 12px; padding: 8px 12px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .nav-row { grid-template-columns: 1fr; }
  .action-row,
  .manual-actions { display: grid; grid-template-columns: 1fr; }
  .action-row button,
  .manual-actions button { width: 100%; }
  .option { grid-template-columns: 22px 1fr; padding: 12px; }
  .prompt { padding: 14px; }
  iframe { min-height: 380px; height: 60vh; }
}
