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

:root {
  --blue: #21468b;
  --blue-dark: #1a3870;
  --orange: #e87722;
  --orange-dark: #c9611a;
  --white: #fafaf8;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e0ddd8;
  --green: #1a7a5e;
  --rose: #c0392b;
  --card-bg: #ffffff;
  --bg: #f5f3ee;
  --nav-h: 88px;
}

body {
  font-family: "DM Sans", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: var(--nav-h);
}

/* ── Header ── */
header {
  background: var(--blue);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.flag {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.9;
  transition:
    opacity 0.15s,
    background 0.15s;
}
.flag:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}
.flag span {
  width: 6px;
  height: 28px;
  border-radius: 2px;
}
.flag .r {
  background: #ae1c28;
}
.flag .w {
  background: #fff;
  opacity: 0.9;
}
.flag .b {
  background: #4a7fd4;
}

.header-info {
  flex: 1;
  min-width: 0;
}
.header-info h1 {
  font-family: "DM Serif Display", serif;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-info p {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.75rem;
  margin-top: 1px;
}

.header-icon-btn {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.header-icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.timer-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 6px 12px;
  flex-shrink: 0;
  transition:
    background 0.3s,
    color 0.3s;
}
.timer-wrap.timer-warning {
  background: rgba(232, 119, 34, 0.3);
  color: #ffd580;
}
.timer-wrap.timer-danger {
  background: rgba(192, 57, 43, 0.5);
  color: #fff;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* ── Main ── */
main {
  max-width: 700px;
  margin: 0 auto;
  padding: 2rem 1.25rem 1.5rem;
}

/* ── Info screen ── */
#info-screen {
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.info-section {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}
.info-section:last-child {
  border-bottom: none;
}

.info-heading {
  font-family: "DM Serif Display", serif;
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--blue);
  margin-bottom: 0.6rem;
}

.info-intro {
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 0.75rem;
}
.info-body {
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.65;
}
.info-body code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.info-theme-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-radius: 10px;
  overflow: hidden;
  margin: 2rem 0;
}

.info-theme-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
}
.info-theme-row:last-child {
  border-bottom: none;
}
.info-theme-row:nth-child(even) {
  background: var(--bg);
}
.info-theme-name {
  color: var(--ink);
}
.info-theme-name strong {
  color: var(--blue);
  margin-right: 6px;
  font-weight: 500;
}
.info-theme-count {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
}

.info-link {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px solid rgba(33, 70, 139, 0.3);
  padding-bottom: 1px;
  transition:
    border-color 0.15s,
    color 0.15s;
}
.info-link:hover {
  color: var(--blue-dark);
  border-color: var(--blue-dark);
}

.info-body ul,
.info-body ol {
  margin: 0.65rem 0 0;
  padding-left: 0;
  list-style: none;
  padding-top: 0.2rem;
}

.info-body li {
  position: relative;
  margin-bottom: 0.75rem;
  padding-left: 1.6rem;
  padding-top: 0.2rem;
}

.info-body ul li::before,
.info-body ol li::before {
  position: absolute;
  left: 0;
  top: 0.95rem;
  transform: translateY(-50%);
  font-weight: 700;
  color: var(--blue);
}

.info-body ul li::before {
  content: "";
  width: 0.34rem;
  height: 0.34rem;
  border-radius: 50%;
  background: var(--blue);
  opacity: 0.32;
}

.info-body ol {
  counter-reset: step-counter;
}

.info-body ol li::before {
  content: counter(step-counter) ".";
  counter-increment: step-counter;
  font-size: 0.9rem;
}

.info-theme-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-radius: 10px;
  overflow: hidden;
  margin: 2rem 0;
}

.info-theme-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
}
.info-theme-row:last-child {
  border-bottom: none;
}
.info-theme-row:nth-child(even) {
  background: var(--bg);
}
.info-theme-name {
  color: var(--ink);
}
.info-theme-name strong {
  color: var(--blue);
  margin-right: 6px;
  font-weight: 500;
}
.info-theme-count {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
}

.info-link {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px solid rgba(33, 70, 139, 0.3);
  padding-bottom: 1px;
  transition:
    border-color 0.15s,
    color 0.15s;
}
.info-link:hover {
  color: var(--blue-dark);
  border-color: var(--blue-dark);
}

/* ── Start screen ── */
.start-heading {
  font-family: "DM Serif Display", serif;
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 0.2rem;
}

.start-sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

.mode-grid {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.mode-card {
  border-bottom: 1px solid var(--border);
}
.mode-card:last-child {
  border-bottom: none;
}

.mc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
}
.mc-header:hover {
  background: rgba(0, 0, 0, 0.02);
}
.mode-card.expanded .mc-header {
  background: rgba(33, 70, 139, 0.04);
}

.mc-chevron {
  display: inline-block;
  color: var(--muted);
  font-size: 1rem;
  flex-shrink: 0;
  margin-left: 8px;
  transition: transform 0.2s;
}
.mode-card.expanded .mc-chevron {
  transform: rotate(90deg);
}

.mc-num {
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 1px;
}
.mc-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
}
.mode-card.featured .mc-title {
  color: var(--blue);
}
.mc-sub {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

.mc-expand {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
}
.mode-card.expanded .mc-expand {
  display: flex;
}

.mc-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.mc-start-btn {
  background: transparent;
  border: none;
  color: var(--blue);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.mc-start-btn:hover {
  color: var(--blue-dark);
  text-decoration: underline;
}

.mc-start-btn:focus-visible {
  outline: 2px dashed rgba(33, 70, 139, 0.45);
  outline-offset: 2px;
}

/* ── Card ── */
.card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 2rem;
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.06),
    0 6px 24px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.question-num {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--blue);
}

.bookmark-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition:
    border-color 0.15s,
    color 0.15s,
    background 0.15s;
  flex-shrink: 0;
}
.bookmark-btn:hover {
  border-color: var(--orange);
  color: var(--orange);
}
.bookmark-btn.active {
  border-color: var(--orange);
  color: var(--orange);
  background: rgba(232, 119, 34, 0.08);
}
.bookmark-btn.active svg {
  fill: var(--orange);
}
.question-text {
  font-family: "DM Serif Display", serif;
  font-size: 1.2rem;
  line-height: 1.55;
  color: var(--ink);
  margin-bottom: 1.5rem;
  font-weight: 400;
}

/* ── Options ── */
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    transform 0.1s;
  user-select: none;
}
.option:hover {
  border-color: #b0aaa0;
  background: #faf9f7;
  transform: translateX(2px);
}
.option.selected {
  border-color: var(--blue);
  background: rgba(33, 70, 139, 0.07);
}

.badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  color: var(--muted);
  transition: all 0.15s;
}
.option.selected .badge {
  border-color: var(--blue);
  color: var(--blue);
  background: rgba(33, 70, 139, 0.08);
}
.option-text {
  font-size: 0.93rem;
  color: var(--ink);
  line-height: 1.4;
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--blue);
  display: flex;
  flex-direction: column;
  padding: 10px 1.25rem 12px;
  gap: 8px;
  z-index: 20;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.18);
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.progress-track {
  flex: 1;
  height: 5px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--orange);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-label {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  min-width: 36px;
  text-align: right;
}

.nav-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.nav-btn {
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 10px 22px;
  font-size: 0.9rem;
  font-family: "DM Sans", sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s,
    opacity 0.15s;
  min-width: 110px;
  text-align: center;
}
.nav-btn:hover:not(:disabled) {
  background: var(--orange-dark);
  transform: translateY(-1px);
}
.nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}
.nav-btn.finish-btn {
  background: var(--green);
}
.nav-btn.finish-btn:hover {
  background: #155f49;
}

.summary-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
}
.summary-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ── Summary overlay ── */
#summary-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 30;
  align-items: flex-end;
  justify-content: center;
}
#summary-overlay.open {
  display: flex;
}

.summary-panel {
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 1.5rem;
  width: 100%;
  max-width: 700px;
  max-height: 70vh;
  overflow-y: auto;
}
.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.summary-header h2 {
  font-family: "DM Serif Display", serif;
  font-size: 1.2rem;
  font-weight: 400;
}
.summary-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}
.summary-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 1rem;
}
.leg {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
}
.leg-unanswered {
  background: #e8e5e0;
}
.leg-answered {
  background: var(--blue);
}
.leg-bookmarked {
  background: #e8e5e0;
  border: 2px solid var(--orange);
}

#summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
  margin-bottom: 1.25rem;
}
.summary-q {
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    transform 0.1s,
    opacity 0.1s;
}
.summary-q:hover {
  transform: scale(1.1);
}
.sq-unanswered {
  background: #e8e5e0;
  color: var(--muted);
}
.sq-answered {
  background: var(--blue);
  color: #fff;
}
.sq-correct {
  background: var(--green);
  color: #fff;
}
.sq-wrong {
  background: var(--rose);
  color: #fff;
}
.sq-active {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}
.sq-bookmarked {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

.summary-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
#summary-stats {
  font-size: 0.85rem;
  color: var(--muted);
}

/* ── Buttons ── */
.btn-primary {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 0.9rem;
  font-family: "DM Sans", sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
}
.btn-primary:hover {
  background: var(--blue-dark);
  transform: translateY(-1px);
}

/* ── Secondary button ── */
.btn-secondary {
  background: transparent;
  color: var(--blue);
  border: 1.5px solid var(--blue);
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 0.9rem;
  font-family: "DM Sans", sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
}
.btn-secondary:hover {
  background: rgba(33, 70, 139, 0.06);
  transform: translateY(-1px);
}

/* ── Score screen ── */
.score-hero {
  text-align: center;
  padding: 2.5rem 2rem;
  background: var(--card-bg);
  border-radius: 16px;
  border: 1px solid var(--border);
  margin-bottom: 2rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.05);
}
.score-number {
  font-family: "DM Serif Display", serif;
  font-size: 5rem;
  color: var(--blue);
  line-height: 1;
}
.score-denom {
  font-size: 1.5rem;
  color: var(--muted);
}
.score-msg {
  font-size: 1rem;
  color: var(--muted);
  margin: 0.75rem 0 1.25rem;
}
.score-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.review-title {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 1rem;
}
.review-item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
}
.review-item.correct-item {
  border-left-color: var(--green);
}
.review-item.wrong-item {
  border-left-color: var(--rose);
}
.review-q {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 5px;
  line-height: 1.4;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.review-bookmark {
  font-size: 0.85em;
}
.review-verdict {
  font-size: 0.8rem;
  margin-bottom: 2px;
}
.review-correct-ans {
  font-size: 0.8rem;
  color: var(--green);
  margin-bottom: 4px;
}
.review-exp {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  header {
    padding: 0.75rem 1rem;
  }
  .header-info h1 {
    font-size: 0.95rem;
  }
  main {
    padding: 1.25rem 0.75rem 1rem;
  }
  .card {
    padding: 1.25rem;
  }
  .start-card {
    padding: 1.75rem 1.25rem;
  }
  .question-text {
    font-size: 1.05rem;
  }
  .score-number {
    font-size: 3.5rem;
  }
  .nav-btn {
    min-width: 90px;
    padding: 10px 14px;
    font-size: 0.85rem;
  }
}
