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

/* ── PIN Gate ────────────────────────────────────── */
#pin-gate {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.pin-box {
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.pin-box h2 { font-size: 1.4rem; margin-bottom: .5rem; }
.pin-box p  { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; line-height: 1.5; }

#pin-input {
  display: block;
  width: 100%;
  padding: .75rem;
  font-size: 1.6rem;
  letter-spacing: .4em;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .75rem;
  outline: none;
  transition: border-color .15s;
}
#pin-input:focus { border-color: var(--primary); }

#pin-submit {
  width: 100%;
  padding: .75rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  transition: background .15s;
}
#pin-submit:hover:not(:disabled) { background: var(--primary-dark); }
#pin-submit:disabled { opacity: .6; cursor: default; }

#pin-error {
  min-height: 1.4rem;
  margin-top: .6rem;
  font-size: .85rem;
  color: var(--wrong);
}

.pin-pay-link {
  display: block;
  margin-top: 1.25rem;
  font-size: .85rem;
  color: var(--primary);
  text-decoration: none;
}
.pin-pay-link:hover { text-decoration: underline; }

:root {
  --bg: #f5f5f0;
  --card-bg: #ffffff;
  --border: #e0e0d8;
  --text: #1a1a1a;
  --text-muted: #666;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --correct: #16a34a;
  --correct-bg: #dcfce7;
  --correct-border: #86efac;
  --wrong: #dc2626;
  --wrong-bg: #fee2e2;
  --wrong-border: #fca5a5;
  --neutral-hover: #f0f0ea;
  --radius: 8px;
}

body {
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────── */
header {
  background: var(--card-bg);
  color: var(--text);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
}

#progress-text {
  font-size: .85rem;
  white-space: nowrap;
  opacity: .9;
}

#progress-bar-wrap {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 4px;
  background: var(--border);
}

#progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width .3s;
  width: 0%;
}

/* ── Index / chapter select ──────────────────────── */
.index-wrap {
  max-width: 700px;
  margin: 3rem auto;
  padding: 0 1.5rem;
}

.index-wrap h1 {
  font-size: 2rem;
  margin-bottom: .5rem;
}

.index-wrap p {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.chapter-cards {
  display: grid;
  gap: 1rem;
}

.chapter-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  transition: box-shadow .15s, transform .15s;
}

.chapter-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
  transform: translateY(-2px);
}

.chapter-card .ch-num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  width: 3rem;
  text-align: center;
  flex-shrink: 0;
}

.chapter-card .ch-info h2 { font-size: 1.1rem; margin-bottom: .2rem; }
.chapter-card .ch-info p  { font-size: .85rem; color: var(--text-muted); }

/* ── Quiz page ───────────────────────────────────── */
.quiz-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* section filter bar */
.section-filter {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.section-filter button {
  padding: .4rem .9rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  cursor: pointer;
  font-size: .85rem;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}

.section-filter button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* question card */
.q-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
  transition: border-color .2s;
}

.q-card.answered-correct { border-color: var(--correct-border); }
.q-card.answered-wrong   { border-color: var(--wrong-border); }

.q-card.hidden { display: none; }

.q-header {
  padding: .75rem 1rem;
  background: #fafaf7;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
}

.q-num {
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.q-status-icon {
  margin-left: auto;
  font-size: 1.1rem;
  line-height: 1;
}

.q-body { padding: 1rem; }

.q-img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 4px;
  margin-bottom: .75rem;
  background: #f0f0ea;
}

.q-text {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  text-align: center;
}

/* answer grid */
.answers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
}

@media (max-width: 600px) {
  .answers { grid-template-columns: 1fr; }
}

.ans-btn {
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  cursor: pointer;
  font-size: .9rem;
  text-align: left;
  line-height: 1.4;
  transition: background .1s, border-color .1s, transform .1s;
  word-break: break-word;
}

.ans-btn:hover:not(:disabled) {
  background: var(--neutral-hover);
  border-color: #bbb;
}

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

.ans-btn.selected {
  font-weight: 700;
}

.ans-btn.reveal-correct {
  background: var(--correct-bg);
  border-color: var(--correct-border);
  color: var(--correct);
}

.ans-btn.reveal-wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong-border);
  color: var(--wrong);
}

.ans-btn:disabled { cursor: default; }

.ans-btn { display: flex; align-items: center; justify-content: space-between; gap: .4rem; }
.ans-text { flex: 1; }
.ans-icon { font-size: 1rem; flex-shrink: 0; min-width: 1rem; text-align: right; }
.reveal-correct .ans-icon { color: var(--correct); }
.reveal-wrong   .ans-icon { color: var(--wrong); }

/* feedback text */
.feedback-text {
  margin-top: .75rem;
  padding: .6rem .8rem;
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  font-size: .85rem;
  border-radius: 0 4px 4px 0;
}

/* ── Score panel ─────────────────────────────────── */
#score-panel {
  background: var(--card-bg);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  margin-bottom: 2rem;
  display: none;
}

#score-panel h2 { font-size: 1.5rem; margin-bottom: .5rem; }
#score-panel .score-big { font-size: 3rem; font-weight: 800; color: var(--primary); }
#score-panel .score-sub { color: var(--text-muted); margin-bottom: 1.5rem; }

.score-bar-wrap {
  background: var(--border);
  border-radius: 99px;
  height: 12px;
  margin: .75rem auto;
  max-width: 400px;
  overflow: hidden;
}
.score-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--correct);
  transition: width .6s ease;
}

#restart-btn {
  display: inline-block;
  margin-top: 1.25rem;
  padding: .65rem 1.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
#restart-btn:hover { background: var(--primary-dark); }

/* ── Sticky bottom bar ───────────────────────────── */
#bottom-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 99;
  box-shadow: 0 -2px 8px rgba(0,0,0,.07);
}

#answered-count {
  flex: 1;
  font-size: .9rem;
  color: var(--text-muted);
}

#see-score-btn {
  padding: .6rem 1.25rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
#see-score-btn:hover { background: var(--primary-dark); }
#see-score-btn:disabled { opacity: .5; cursor: default; }

/* spacer so content isn't hidden behind sticky bar */
.bottom-spacer { height: 70px; }

/* back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .85rem;
}
.back-link:hover { color: var(--text); }
