:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --text: #0f172a;
  --primary: #2563eb;
  --ok: #16a34a;
  --bad: #dc2626;
  --muted: #64748b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  padding: 16px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.topbar p {
  margin: 0;
  opacity: 0.95;
}

main { margin-top: 12px; }

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 12px;
  align-items: start;
}

.content-col { min-width: 0; }
.content-col { position: relative; }

.panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  margin-bottom: 12px;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#reviewWrongModeBtn {
  background: #f59e0b;
}

#reviewWrongModeBtn:disabled {
  background: #94a3b8;
  color: #e2e8f0;
}

#resetBtn {
  margin-left: auto;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  background: #0ea5e9;
  color: #fff;
  font-weight: 600;
}

button:hover { filter: brightness(0.95); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.controls button.mode-active {
  border: 3px solid #0f172a;
  box-shadow: 0 0 0 2px #fff inset;
}

.hidden { display: none; }

.nav-panel h3 {
  margin: 0 0 10px;
  color: var(--muted);
}

.chapter-select {
  width: 100%;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

.nav-panel .chapter-select {
  position: sticky;
  top: 0;
  z-index: 5;
}

.question-nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.chapter-sep {
  grid-column: 1 / -1;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #cbd5e1;
  font-size: 12px;
  color: #475569;
  font-weight: 700;
}

.qnav-btn {
  background: #e2e8f0;
  color: #0f172a;
  padding: 8px 0;
}

.qnav-btn.active {
  background: var(--primary);
  color: #fff;
}

.qnav-btn.answered {
  background: #86efac;
  color: #14532d;
}

.qnav-btn.wrong {
  background: #fca5a5;
  color: #7f1d1d;
}

.qnav-btn.active.answered {
  background: #22c55e;
  color: #fff;
}

.qnav-btn.active.wrong {
  background: #dc2626;
  color: #fff;
}

.qhead {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  color: var(--muted);
}

#qText {
  margin: 12px 0;
  font-size: 20px;
  line-height: 1.4;
}

#qImage {
  max-width: 100%;
  border-radius: 8px;
  margin-bottom: 10px;
}

.options {
  display: grid;
  gap: 8px;
}

.option {
  text-align: left;
  background: #e0f2fe;
  color: #0c4a6e;
}

.option.selected { outline: 2px solid #0369a1; }
.option.correct { background: var(--ok); color: #fff; }
.option.wrong { background: var(--bad); color: #fff; }

.actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.explain {
  margin-top: 10px;
  padding: 10px;
  background: #f8fafc;
  border-left: 4px solid var(--primary);
  line-height: 1.5;
}

.blurred {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.exam-start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.exam-start-overlay.hidden {
  display: none;
}

.exam-start-btn {
  font-size: 24px;
  padding: 16px 24px;
  border-radius: 12px;
  background: #2563eb;
}

.exam-info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.exam-submit-top {
  align-self: flex-start;
  white-space: nowrap;
}

.timer-box {
  margin-top: 0;
  border: 2px solid #93c5fd;
  border-radius: 10px;
  padding: 10px 12px;
  background: #eff6ff;
  display: inline-block;
}

.timer-label {
  font-size: 12px;
  color: #1e3a8a;
  font-weight: 700;
}

.timer {
  margin-top: 4px;
  font-weight: 800;
  color: #0f172a;
  font-size: 34px;
  letter-spacing: 1px;
}

.timer-box.danger .timer {
  color: #dc2626;
}

#resultBox h3 { margin: 0 0 8px; }
#resultBox p { margin: 6px 0; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .nav-panel {
    max-height: 26vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
  }
  .nav-panel h3 {
    margin-bottom: 6px;
    font-size: 14px;
  }
  .nav-panel .chapter-select {
    top: -1px;
    margin-bottom: 6px;
    padding: 6px 8px;
    font-size: 14px;
  }
  .question-nav {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
  }
  .qnav-btn {
    padding: 7px 0;
    min-height: 36px;
    font-size: 13px;
  }
  #questionCard {
    margin-top: 6px;
  }
  .exam-info-row {
    flex-direction: column;
    align-items: stretch;
  }
  .exam-submit-top {
    align-self: flex-end;
  }
}

@media (max-width: 600px) {
  .nav-panel {
    max-height: 20vh;
  }
  .question-nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .qnav-btn {
    min-height: 34px;
    font-size: 12px;
  }
}