/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #f0f4ff;
  color: #1e293b;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ===== Layout ===== */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 280px;
  min-width: 260px;
  background: #1e3a5f;
  color: #e2eaf5;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1.5rem 1.2rem 1rem;
  border-bottom: 1px solid #2d4f7c;
}

.badge {
  display: inline-block;
  background: #3b82f6;
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 0.5rem;
}

.sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.3;
  color: #ffffff;
  margin: 0.3rem 0 0.2rem;
}

.subtitle {
  font-size: 0.78rem;
  color: #93b4d3;
}

.back-link {
  display: inline-block;
  color: #7eb8f5;
  font-size: 0.82rem;
  margin-bottom: 0.6rem;
  transition: color 0.15s;
}
.back-link:hover { color: white; }

nav { padding: 0.5rem 0 1.5rem; }

.nav-item {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.65rem 1.2rem;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}
.nav-item:hover {
  background: rgba(255,255,255,0.07);
  border-left-color: #3b82f6;
}
.nav-sub { font-size: 0.85rem; }

.nav-num {
  flex-shrink: 0;
  background: #2d4f7c;
  color: #93b4d3;
  font-size: 0.7rem;
  font-weight: 700;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.nav-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 0.83rem;
  color: #cde0f5;
}
.nav-text strong { color: #ffffff; font-size: 0.87rem; }
.nav-text small  { color: #7eaad3; font-size: 0.72rem; }

/* ===== Home main ===== */
.home-main {
  flex: 1;
  padding: 2.5rem 2rem;
  max-width: 960px;
}

.hero-card {
  background: white;
  border-radius: 16px;
  padding: 2rem 2.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 4px 20px rgba(30,64,175,0.07);
}

.hero-card h1 {
  font-size: 1.8rem;
  margin-bottom: 0.8rem;
  color: #1e3a5f;
}
.hero-card p { color: #475569; line-height: 1.6; margin-bottom: 0.7rem; }

.feature-list {
  list-style: none;
  margin: 0.8rem 0 1rem;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.feature-list li {
  background: #f0f7ff;
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  color: #1e3a5f;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.chapter-card {
  background: white;
  border-radius: 12px;
  padding: 1.2rem 1.3rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 2px 10px rgba(30,64,175,0.06);
  transition: transform 0.15s, box-shadow 0.15s;
}
.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(30,64,175,0.12);
}
.chapter-num {
  flex-shrink: 0;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.chapter-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chapter-info strong { font-size: 0.92rem; color: #1e293b; }
.chapter-info span   { font-size: 0.76rem; color: #64748b; }

/* ===== Chapter main ===== */
.chapter-main {
  flex: 1;
  padding: 2rem 2.5rem;
  overflow-y: auto;
}

.chapter-header {
  margin-bottom: 2rem;
}
.week-badge {
  display: inline-block;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  margin-bottom: 0.4rem;
  letter-spacing: 0.04em;
}

.chapter-header h1 {
  font-size: 1.8rem;
  color: #1e3a5f;
  margin-bottom: 0.3rem;
}
.chapter-header p {
  color: #64748b;
  font-size: 0.9rem;
  margin-bottom: 0.8rem;
}

.nav-arrows { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.btn-outline {
  display: inline-block;
  border: 1.5px solid #3b82f6;
  color: #2563eb;
  border-radius: 8px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.btn-outline:hover { background: #3b82f6; color: white; }

/* ===== Sub-topic card ===== */
.subtopic-card {
  background: white;
  border-radius: 14px;
  box-shadow: 0 3px 14px rgba(30,64,175,0.07);
  margin-bottom: 2rem;
  overflow: hidden;
}

.st-header {
  background: linear-gradient(90deg, #1e3a5f, #2d5b8a);
  color: white;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
}
.st-header h2 { font-size: 1.1rem; font-weight: 700; margin: 0; }

.pdf-jump-btn {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.45);
  color: #fff;
  font-size: .8rem;
  padding: .3rem .75rem;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s;
}
.pdf-jump-btn:hover { background: rgba(255,255,255,0.35); }


/* ===== Lecturer summary block ===== */
.summary-block {
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
  border-left: 4px solid #3b82f6;
  padding: 1rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.summary-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #2563eb;
}

.summary-text {
  font-size: 0.93rem;
  line-height: 1.75;
  color: #334155;
  margin: 0;
}

/* ===== Question blocks ===== */
.block {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid #f1f5f9;
}
.block:last-child { border-bottom: none; }

.block h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.9rem;
  color: #1e3a5f;
}

.pdf-block {
  background: #0f172a;
  padding: 0;
  border-radius: 0;
  overflow: hidden;
}

/* ── Sticky floating mini PDF viewer ── */
#pdfFloating {
  display: none;
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  width: 480px;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  z-index: 999;
  border: 1px solid #334155;
}
#pdfFloating.visible { display: block; }
#pdfFloating .pdf-topbar {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  cursor: move;
  user-select: none;
}
#pdfFloating .pdf-title { font-size: 0.8rem; }
#pdfFloating .pdfjs-wrap {
  height: 300px;
  min-height: unset;
}
#pdfFloating .pdf-controls {
  padding: 0.4rem 0.8rem;
  gap: 0.8rem;
}
#pdfFloating .pdf-btn {
  padding: 0.3rem 0.9rem;
  font-size: 0.82rem;
}
#pdfFloating .pdf-page-info {
  font-size: 0.82rem;
  min-width: 80px;
}
#floatClose {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 0 0 0.4rem;
  line-height: 1;
}
#floatClose:hover { color: #f87171; }

.pdf-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.2rem;
  background: #1e293b;
  gap: 1rem;
}

.pdf-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-download {
  flex-shrink: 0;
  background: #2563eb;
  color: white;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  border-radius: 7px;
  white-space: nowrap;
  transition: background 0.15s;
}
.pdf-download:hover { background: #1d4ed8; color: white; }

/* Canvas area – height = viewport minus header/footer */
.pdfjs-wrap {
  position: relative;
  width: 100%;
  height: calc(100vh - 220px);
  min-height: 480px;
  background: #1e1e2e;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#pdfCanvas {
  max-width: 100%;
  max-height: 100%;
  width: auto !important;
  height: auto !important;
  object-fit: contain;
  display: block;
  transition: opacity 0.2s;
  box-shadow: 0 4px 32px rgba(0,0,0,0.5);
}

.pdf-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.9rem;
  background: #1e1e2e;
  z-index: 10;
}

.pdf-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 0.6rem 1rem;
  background: #1e293b;
}

.pdf-btn {
  background: #334155;
  color: #e2e8f0;
  border: none;
  border-radius: 7px;
  padding: 0.4rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.pdf-btn:hover:not(:disabled) { background: #2563eb; }
.pdf-btn:disabled { opacity: 0.35; cursor: default; }

.pdf-page-info {
  font-size: 0.85rem;
  color: #94a3b8;
  min-width: 100px;
  text-align: center;
}

.question {
  margin-bottom: 1.1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  border: 1.5px solid transparent;
  transition: background 0.2s, border-color 0.2s;
  position: relative;
}
.question.solved {
  background: #f0fdf4;
  border-color: #86efac;
}
.question.solved .q-prompt {
  text-decoration: line-through;
  color: #94a3b8;
}
.solved-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  user-select: none;
  float: right;
  margin-left: 0.5rem;
}
.solved-label:hover { color: #16a34a; }
.solved-cb {
  width: 16px;
  height: 16px;
  accent-color: #16a34a;
  cursor: pointer;
}
.question.solved .solved-label { color: #16a34a; }

.q-prompt {
  font-size: 0.88rem;
  color: #1e293b;
  line-height: 1.55;
  margin-bottom: 0.5rem;
}

.options {
  list-style: none;
  margin: 0.3rem 0 0.5rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.options li {
  background: #f8faff;
  border: 1px solid #e2eaf5;
  border-radius: 6px;
  padding: 0.35rem 0.8rem;
  font-size: 0.86rem;
  color: #334155;
}

details.answer-box {
  margin-top: 0.4rem;
}
details.answer-box summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: #3b82f6;
  user-select: none;
}
details.answer-box summary:hover { color: #1d4ed8; }

.answer-text {
  display: inline-block;
  margin-top: 0.4rem;
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  border-radius: 6px;
  padding: 0.4rem 0.9rem;
  font-size: 0.84rem;
  font-weight: 600;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .chapter-main, .home-main { padding: 1.2rem 1rem; }
  .feature-list { grid-template-columns: 1fr; }
}
