:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe2ea;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --amber: #b45309;
  --amber-soft: #fef3c7;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(191, 219, 254, 0.55), transparent 26%),
    radial-gradient(circle at top right, rgba(253, 230, 138, 0.3), transparent 20%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 24%, #eef3f8 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
.meme-cats {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.cat-sticker {
  position: fixed;
  width: 132px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  opacity: 0.94;
  border-radius: 24px;
  border: 4px solid rgba(255, 255, 255, 0.96);
  background: #fff;
  box-shadow: 0 16px 28px rgba(15, 23, 42, 0.18);
  animation: catFloat 4.8s ease-in-out infinite;
}
.cat-left-top {
  left: 12px;
  top: 92px;
  transform: rotate(-7deg);
}
.cat-right-top {
  right: 12px;
  top: 104px;
  transform: rotate(7deg);
  animation-delay: -1.2s;
}
.cat-left-bottom {
  left: 20px;
  bottom: 36px;
  transform: rotate(-4deg);
  animation-delay: -2.3s;
}
.cat-right-bottom {
  right: 20px;
  bottom: 34px;
  transform: rotate(5deg);
  animation-delay: -3.1s;
}
@keyframes catFloat {
  0%, 100% { transform: translateY(0) rotate(var(--cat-rot, 0deg)); }
  50% { transform: translateY(-8px) rotate(calc(var(--cat-rot, 0deg) + 1deg)); }
}
.cat-left-top { --cat-rot: -7deg; }
.cat-right-top { --cat-rot: 7deg; }
.cat-left-bottom { --cat-rot: -4deg; }
.cat-right-bottom { --cat-rot: 5deg; }
.app {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 120px;
  position: relative;
  z-index: 1;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.title-block { min-width: 0; }
h1 {
  margin: 0 0 6px;
  font-size: 30px;
  line-height: 1.2;
}
.sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.mobile-only {
  display: none;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.04);
}
.intro { margin-bottom: 16px; }
.intro summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}
.intro summary::-webkit-details-marker { display: none; }
.intro[open] summary { margin-bottom: 14px; }
.intro-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.value {
  font-size: 24px;
  font-weight: 700;
}
.value.small {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
}
.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  position: relative;
}
.sidebar, .main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.drawer-overlay {
  display: none;
}
.section-title, .subheading {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.sidebar-head .section-title { margin-bottom: 0; }
.question-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.grid-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  min-height: 40px;
  cursor: pointer;
  font-weight: 600;
}
.grid-btn.current { outline: 2px solid var(--blue); }
.grid-btn.answered { background: var(--blue-soft); border-color: #93c5fd; }
.grid-btn.correct { background: var(--green-soft); border-color: #86efac; }
.grid-btn.wrong { background: var(--red-soft); border-color: #fca5a5; }
.grid-btn.unanswered-after-submit { background: var(--amber-soft); border-color: #fcd34d; }
.section-counts {
  display: grid;
  gap: 8px;
}
.section-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}
.question-shell {
  padding: 18px;
  position: relative;
}
.result-panel {
  padding: 18px;
}
.progress-strip {
  height: 7px;
  border-radius: 999px;
  background: #e7edf5;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #60a5fa, #1d4ed8);
  transition: width 0.18s ease;
}
.question-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.question-head {
  text-align: center;
  flex: 1;
}
.question-index {
  font-weight: 700;
  margin-bottom: 6px;
}
.question-meta {
  display: flex;
  justify-content: center;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}
.qid {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.question-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.question-prompt-fallback {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #bfdbfe;
  background: linear-gradient(180deg, #eff6ff 0%, #f8fbff 100%);
  color: var(--text);
  line-height: 1.65;
  font-size: 15px;
}
.image-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: auto;
  min-height: 300px;
}
.image-wrap.compact {
  min-height: auto;
  max-height: min(60svh, 760px);
}
.image-wrap img {
  width: 100%;
  max-width: 980px;
  height: auto;
  display: block;
  transition: transform 0.16s ease;
}
.image-wrap.compact img {
  width: auto;
  max-width: 100%;
  max-height: calc(min(60svh, 760px) - 24px);
}
.sticky-answer-shell {
  margin-top: 16px;
}
.choice-wrap {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.choice-btn {
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.choice-btn.selected {
  background: var(--blue-soft);
  border-color: #60a5fa;
  color: var(--blue);
}
.choice-btn.correct {
  background: var(--green-soft);
  border-color: #4ade80;
  color: var(--green);
}
.choice-btn.wrong {
  background: var(--red-soft);
  border-color: #f87171;
  color: var(--red);
}
.choice-btn.missed-correct {
  background: var(--green-soft);
  border-color: #4ade80;
  color: var(--green);
}
.answer-state {
  min-height: 24px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}
button.primary, button.ghost {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
button.primary {
  background: var(--blue);
  color: #fff;
  border: none;
}
button.ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}
.small-btn {
  min-height: 36px !important;
  padding: 0 12px !important;
  font-size: 12px !important;
  border-radius: 10px !important;
}
.nav-btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.mobile-nav-row {
  display: none;
  gap: 8px;
  margin-top: 10px;
}
.mobile-nav-row .nav-btn {
  flex: 1;
}
.hidden { display: none; }
.score-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.result-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.result-panel-sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.result-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
  margin: 18px 0;
}
.result-columns {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
}
.section-result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.section-result-table th,
.section-result-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
}
.recommend-card, .wrong-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}
.recommend-card strong,
.wrong-item strong { display: block; margin-bottom: 6px; }
.wrong-list { margin-top: 8px; }
.link-btn {
  margin-top: 8px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

@media (max-width: 1180px) {
  .cat-sticker {
    width: 96px;
    opacity: 0.82;
  }
  .cat-left-top,
  .cat-right-top {
    top: 76px;
  }
  .cat-left-bottom,
  .cat-right-bottom {
    bottom: 120px;
  }
  .layout { grid-template-columns: 1fr; }
  .intro-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar {
    position: fixed;
    inset: auto 12px 12px 12px;
    z-index: 30;
    max-height: 78svh;
    overflow: auto;
    transform: translateY(calc(100% + 18px));
    transition: transform 0.2s ease;
  }
  .sidebar.open {
    transform: translateY(0);
  }
  .drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    z-index: 20;
    display: block;
  }
  .drawer-overlay.hidden {
    display: none;
  }
  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}
@media (max-width: 720px) {
  .cat-left-top {
    left: 8px;
    top: 74px;
    width: 78px;
    opacity: 0.72;
  }
  .cat-right-top {
    right: 8px;
    top: 78px;
    width: 78px;
    opacity: 0.72;
  }
  .cat-left-bottom,
  .cat-right-bottom {
    display: none;
  }
  .app { padding: 12px; padding-bottom: 148px; }
  .topbar { flex-direction: column; }
  h1 { font-size: 24px; }
  .intro-grid { grid-template-columns: 1fr; }
  .question-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .result-columns, .score-summary { grid-template-columns: 1fr; }
  .card { padding: 14px; border-radius: 16px; }
  .question-shell { padding: 14px; }
  .question-nav {
    gap: 8px;
    align-items: center;
  }
  .question-head {
    min-width: 0;
  }
  .question-index {
    font-size: 18px;
    margin-bottom: 4px;
  }
  .question-meta {
    gap: 6px;
  }
  .badge {
    font-size: 11px;
    padding: 5px 8px;
  }
  .qid {
    font-size: 11px;
  }
  .question-tools {
    gap: 6px;
  }
  .question-prompt-fallback {
    font-size: 14px;
    padding: 11px 12px;
  }
  .small-btn {
    flex: 1;
    min-width: 0;
  }
  .image-wrap {
    padding: 8px;
    border-radius: 12px;
    min-height: 200px;
  }
  .image-wrap.compact {
    max-height: 47svh;
  }
  .image-wrap.compact img {
    max-height: calc(47svh - 16px);
  }
  .sticky-answer-shell {
    position: sticky;
    bottom: 10px;
    z-index: 15;
    margin-top: 12px;
    background: rgba(243, 245, 249, 0.92);
    backdrop-filter: blur(10px);
    padding-top: 8px;
  }
  .choice-wrap {
    gap: 8px;
  }
  .choice-btn {
    min-height: 56px;
    font-size: 17px;
    border-radius: 14px;
  }
  .mobile-nav-row {
    display: flex;
  }
  .question-nav .nav-btn {
    display: none;
  }
  .sidebar {
    inset: auto 8px 8px 8px;
    max-height: 82svh;
  }
}
@media (max-width: 420px) {
  .cat-left-top,
  .cat-right-top {
    width: 64px;
    opacity: 0.64;
  }
  .choice-btn {
    min-height: 52px;
    font-size: 16px;
  }
  .question-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
