:root {
  --bg: #f7f7f3;
  --surface: #ffffff;
  --surface-2: #f0f3ef;
  --text: #25312b;
  --muted: #68756e;
  --line: #dce4de;
  --accent: #2f765a;
  --accent-soft: #e2f1e9;
  --correct: #237a4b;
  --correct-soft: #e2f4e9;
  --wrong: #b84343;
  --wrong-soft: #f9e5e5;
  --focus: #2c6ea4;
  --shadow: 0 12px 35px rgba(39, 61, 50, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 0%, rgba(94, 155, 121, .10), transparent 28rem),
    radial-gradient(circle at 92% 18%, rgba(230, 185, 91, .09), transparent 24rem),
    var(--bg);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; }
button:focus-visible { outline: 4px solid rgba(44,110,164,.25); outline-offset: 3px; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.site-header {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand-button {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 8px 2px;
  font-weight: 800;
  letter-spacing: .03em;
}
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-size: 22px;
  box-shadow: 0 6px 16px rgba(47,118,90,.18);
}
.brand-text { font-size: clamp(17px, 2.6vw, 22px); }
.header-score {
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.75);
  color: var(--muted);
  font-weight: 800;
  font-size: 14px;
}
.main {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  flex: 1;
  padding: 18px 0 48px;
}
.main.is-quiz { padding-top: 4px; padding-bottom: 12px; }
.site-footer {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}
.answer-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  font-size: clamp(96px, 24vw, 196px);
  font-weight: 900;
  line-height: 1;
  user-select: none;
  text-shadow: 0 2px 10px rgba(255,255,255,.9), 0 3px 16px rgba(0,0,0,.2);
  transition: opacity .16s ease;
}
.answer-overlay.is-visible {
  visibility: visible;
  opacity: 1;
}
.answer-overlay.is-correct { color: var(--correct); }
.answer-overlay.is-wrong { color: var(--wrong); }

.hero { padding: 22px 0 26px; text-align: center; }
.eyebrow {
  display: inline-flex;
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
}
h1, h2, p { margin-top: 0; }
.hero h1 {
  margin: 14px auto 10px;
  font-size: clamp(30px, 6vw, 52px);
  letter-spacing: .04em;
  line-height: 1.22;
}
.hero p { margin-bottom: 0; color: var(--muted); font-size: clamp(15px, 2.3vw, 18px); }

.genre-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.genre-card {
  appearance: none;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow);
  min-height: 154px;
  padding: 22px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 16px;
  align-items: center;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.genre-card:hover { transform: translateY(-3px); border-color: #b9cdc1; box-shadow: 0 18px 42px rgba(39,61,50,.12); }
.genre-icon {
  width: 58px; height: 58px; border-radius: 18px;
  display: grid; place-items: center;
  background: var(--surface-2);
  font-size: 31px;
}
.genre-icon.has-generated-icon { overflow: visible; background: transparent; }
.genre-icon.has-generated-icon img {
  display: block;
  width: 100%; height: 100%;
  object-fit: contain;
  padding: 0;
}
.genre-name { display: block; font-size: 22px; font-weight: 900; margin-bottom: 5px; }
.genre-count { display: block; color: var(--muted); font-size: 14px; font-weight: 700; }
.genre-arrow { display: inline-block; margin-top: 9px; color: var(--accent); font-size: 13px; font-weight: 900; }

.panel {
  max-width: 720px;
  margin: 24px auto 0;
  background: rgba(255,255,255,.94);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: clamp(24px, 5vw, 42px);
}
.panel-title { text-align: center; margin-bottom: 8px; font-size: clamp(26px, 5vw, 38px); }
.panel-subtitle { text-align: center; color: var(--muted); margin-bottom: 26px; }
.selected-genre {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-bottom: 28px;
}
.selected-genre .genre-icon { width: 50px; height: 50px; font-size: 26px; }
.selected-genre strong { font-size: 22px; }
.section-label { font-weight: 900; margin-bottom: 12px; }
.count-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 28px; }
.count-button {
  border: 1px solid var(--line);
  background: var(--surface);
  min-height: 52px;
  border-radius: 15px;
  font-weight: 900;
  color: var(--text);
  cursor: pointer;
}
.count-button.is-selected { background: var(--accent-soft); border-color: #97bca8; color: var(--accent); }
.primary-button, .secondary-button {
  width: 100%; min-height: 58px; border-radius: 17px; cursor: pointer; font-weight: 900; font-size: 17px;
}
.primary-button { border: 0; background: var(--accent); color: white; box-shadow: 0 10px 22px rgba(47,118,90,.18); }
.primary-button:hover { filter: brightness(.96); }
.secondary-button { margin-top: 10px; border: 1px solid var(--line); background: white; color: var(--text); }

.quiz-wrap { max-width: 820px; margin: 4px auto 0; }
.main.is-quiz .quiz-wrap { margin-top: 0; }
.quiz-topline { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.main.is-quiz .quiz-topline { margin-bottom: clamp(8px, 1.8svh, 14px); }
.progress-track { height: 10px; flex: 1; background: #e4e8e5; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .25s ease; }
.progress-label { min-width: 70px; text-align: right; color: var(--muted); font-weight: 900; font-size: 14px; }
.question-card {
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 4vw, 32px);
}
.main.is-quiz .question-card { padding: clamp(12px, 2.5svh, 24px); }
.question-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.main.is-quiz .question-meta { margin-bottom: clamp(6px, 1.5svh, 12px); }
.question-genre { color: var(--accent); font-weight: 900; }
.question-genre-icon {
  display: inline-block;
  width: 1.55em; height: 1.55em;
  margin-right: .25em;
  object-fit: contain;
  vertical-align: -.4em;
}
.question-number { color: var(--muted); font-size: 14px; font-weight: 800; }
.question-title { text-align: center; font-size: clamp(23px, 4vw, 31px); margin-bottom: 18px; letter-spacing: .04em; }
.main.is-quiz .question-title { margin-bottom: clamp(8px, 1.5svh, 14px); }
.image-frame {
  position: relative;
  width: min(100%, 410px);
  aspect-ratio: 1 / 1;
  margin: 0 auto 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  background: #f4f5f1;
  display: grid; place-items: center;
}
.main.is-quiz .image-frame {
  width: min(100%, 410px, 36svh, max(112px, calc(100svh - 440px)));
  margin-bottom: clamp(8px, 1.6svh, 16px);
}
.quiz-image { width: 100%; height: 100%; object-fit: contain; display: block; background: white; }
.quiz-image.minecraft-image { background: #e4e8e4; }
.image-placeholder {
  position: absolute; inset: 0;
  display: none;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  background: linear-gradient(135deg, #f5f6f2, #edf1ed);
}
.image-placeholder.is-visible { display: grid; }
.placeholder-symbol {
  width: 66px; height: 66px; display: grid; place-items: center;
  margin: 0 auto 10px; border-radius: 20px; background: white; border: 1px solid var(--line);
  font-size: 30px;
}
.image-placeholder strong { display: block; color: var(--text); margin-bottom: 6px; font-size: 18px; }
.image-placeholder small { display: block; font-size: 12px; line-height: 1.5; }

.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.choice-button {
  min-height: 72px;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: white;
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
  font-size: clamp(17px, 3vw, 21px);
  padding: 12px 16px;
  transition: transform .1s ease, border-color .15s ease, background .15s ease;
}
.choice-button:hover:not(:disabled) { transform: translateY(-1px); border-color: #a9c5b5; }
.choice-button:disabled { cursor: default; }
.choice-button.is-correct { border-color: #65a780; background: var(--correct-soft); color: var(--correct); }
.choice-button.is-wrong { border-color: #d99999; background: var(--wrong-soft); color: var(--wrong); }

.feedback-box {
  margin-top: 16px; border-radius: 17px; padding: 15px 17px; display: none;
  align-items: center; justify-content: space-between; gap: 14px;
}
.feedback-box.is-visible { display: flex; }
.feedback-box.correct { background: var(--correct-soft); color: var(--correct); }
.feedback-box.wrong { background: var(--wrong-soft); color: var(--wrong); }
.feedback-content { flex: 1; min-width: 0; }
.feedback-text { font-weight: 900; line-height: 1.5; }
.trivia-note {
  margin-top: 10px;
  scroll-margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.72);
  color: var(--text);
}
.trivia-note strong { display: block; margin-bottom: 3px; color: var(--accent); font-size: 13px; }
.trivia-note p { margin: 0; font-size: 14px; font-weight: 500; line-height: 1.65; }
.next-button {
  border: 0; border-radius: 13px; background: var(--text); color: white; font-weight: 900; padding: 12px 19px; cursor: pointer; white-space: nowrap;
}

.result-badge {
  width: 104px; height: 104px; border-radius: 50%; margin: 0 auto 18px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 42px; font-weight: 900;
}
.result-score { text-align: center; font-size: clamp(32px, 7vw, 52px); font-weight: 900; margin-bottom: 6px; }
.result-message { text-align: center; color: var(--muted); font-size: 17px; margin-bottom: 25px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 26px; }
.stat { border-radius: 16px; background: var(--surface-2); padding: 14px 8px; text-align: center; }
.stat strong { display: block; font-size: 23px; }
.stat span { color: var(--muted); font-size: 12px; font-weight: 800; }

.dev-note {
  margin: 14px auto 0; max-width: 560px; padding: 10px 13px; border-radius: 13px;
  background: #fff6de; color: #715d28; font-size: 12px; line-height: 1.55;
}

@media (max-width: 800px) {
  .genre-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .genre-card { min-height: 136px; padding: 18px; grid-template-columns: 50px 1fr; }
  .genre-icon { width: 50px; height: 50px; font-size: 27px; }
  .genre-name { font-size: 19px; }
}
@media (max-width: 560px) {
  .site-header, .main, .site-footer { width: min(100% - 22px, 1100px); }
  .site-header { min-height: 66px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .genre-grid { grid-template-columns: 1fr; gap: 11px; }
  .genre-card { min-height: 104px; padding: 15px 17px; border-radius: 18px; }
  .genre-arrow { display: none; }
  .panel { margin-top: 10px; border-radius: 22px; }
  .count-options { grid-template-columns: repeat(2, 1fr); }
  .question-card { border-radius: 22px; padding: 16px; }
  .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .choice-button { min-height: 56px; border-radius: 15px; padding: 8px; font-size: clamp(14px, 4vw, 18px); }
  .feedback-box { align-items: stretch; flex-direction: column; }
  .next-button { width: 100%; }
  .result-stats { gap: 6px; }
  .stat strong { font-size: 20px; }
}

/* Preserve each source image's aspect ratio inside the square quiz frame. */
.image-frame > .quiz-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
}

.genre-card { position: relative; }
.genre-card.has-medal { padding-right: 58px; }
.count-button { position: relative; }
.achievement-medal {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 8px rgba(39, 61, 50, .16);
  font-size: 22px;
  line-height: 1;
}
.achievement-medal.medal-gold { border: 1px solid #e6bd51; }
.achievement-medal.medal-silver { border: 1px solid #b8c4d0; }
.count-button .achievement-medal { top: 3px; right: 3px; width: 25px; height: 25px; font-size: 17px; }
.result-badge { position: relative; }
.result-medal {
  position: absolute;
  top: -5px;
  right: -7px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 8px rgba(39, 61, 50, .2);
  font-size: 29px;
  line-height: 1;
}
@media (max-width: 800px) {
  .genre-card.has-medal { padding-right: 58px; }
}
@media (max-width: 560px) {
  .genre-card.has-medal { padding-right: 58px; }
}

.answer-mark {
  position: relative;
  z-index: 1;
  display: inline-block;
}
.answer-overlay.is-correct::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at center, rgba(255, 250, 218, .82) 0%, rgba(255, 219, 104, .36) 16%, rgba(255, 219, 104, .12) 34%, transparent 58%);
  animation: answer-screen-flash .62s ease-out both;
}
.answer-overlay.is-correct .answer-mark {
  animation: answer-mark-pop .78s cubic-bezier(.18, .86, .24, 1.22) both;
}
.answer-burst, .medal-burst { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.answer-burst-particle, .medal-burst-particle {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  color: #ffd34e;
  font-size: clamp(18px, 5vw, 28px);
  line-height: 1;
  opacity: 0;
  text-shadow: 0 1px 4px rgba(100, 73, 7, .24), 0 0 12px rgba(255, 255, 255, .86);
  transform: translate(-50%, -50%);
  animation: burst-particle .92s cubic-bezier(.12, .72, .3, 1) var(--burst-delay) both;
}
.answer-burst-particle:nth-child(4n + 2) { color: #ff75aa; font-size: clamp(17px, 4.2vw, 25px); }
.answer-burst-particle:nth-child(4n + 3) { color: #fff6ce; font-size: clamp(13px, 3.4vw, 21px); }
.answer-burst-particle:nth-child(4n) { color: #68d7d1; font-size: clamp(16px, 4vw, 24px); }
.choice-button.correct-hit { animation: correct-choice-hit .8s cubic-bezier(.18, .84, .22, 1.14) both; }

.result-badge.medal-earned {
  isolation: isolate;
  animation: medal-badge-land .82s cubic-bezier(.2, .85, .28, 1.16) both;
  box-shadow: 0 0 0 7px var(--medal-ring), 0 0 42px var(--medal-glow), 0 0 86px var(--medal-glow);
}
.result-badge.medal-gold { --medal-ring: rgba(238, 183, 48, .54); --medal-glow: rgba(255, 195, 44, .5); --medal-ray: rgba(255, 218, 101, .82); background: #fff2c2; color: #9c6800; }
.result-badge.medal-silver { --medal-ring: rgba(145, 166, 186, .54); --medal-glow: rgba(145, 166, 186, .36); --medal-ray: rgba(203, 222, 239, .78); background: #edf2f7; color: #526b81; }
.result-badge.medal-earned::before {
  content: "";
  position: absolute;
  z-index: 0;
  inset: -10px;
  border: 2px solid var(--medal-ring);
  border-radius: 50%;
  box-shadow: 0 0 24px var(--medal-glow);
  pointer-events: none;
  animation: medal-halo 1.08s .06s ease-out both;
}
.result-badge.medal-earned::after {
  content: "";
  position: absolute;
  inset: -34px;
  z-index: 0;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  background: repeating-conic-gradient(from -8deg, transparent 0deg 13deg, var(--medal-ray) 13deg 17deg, transparent 17deg 25deg);
  mask-image: radial-gradient(circle, transparent 0 36%, #000 43% 67%, transparent 76%);
  -webkit-mask-image: radial-gradient(circle, transparent 0 36%, #000 43% 67%, transparent 76%);
  animation: medal-rays 1.1s .04s ease-out both;
}
.result-badge.medal-earned .result-mark { position: relative; z-index: 1; animation: result-mark-pop .62s .08s cubic-bezier(.2, .82, .25, 1.16) both; }
.result-badge.medal-earned .result-medal { z-index: 2; animation: medal-icon-land .82s .08s cubic-bezier(.16, .84, .25, 1.18) both; }
.medal-burst { z-index: 3; }
.medal-burst-particle { font-size: 16px; }
.medal-burst-particle:nth-child(4n + 2) { color: #65c997; font-size: 19px; }
.medal-burst-particle:nth-child(4n + 3) { color: #fff9df; font-size: 12px; }
.medal-burst-particle:nth-child(4n) { color: #ff8eb5; font-size: 15px; }
.result-badge.medal-silver .medal-burst-particle { color: #9baebf; text-shadow: 0 1px 5px rgba(69, 91, 112, .28); }

@keyframes answer-mark-pop {
  0% { opacity: 0; transform: scale(.3) rotate(-18deg); text-shadow: 0 0 0 rgba(255, 210, 72, 0); }
  20% { opacity: 1; transform: scale(1.28) rotate(9deg); text-shadow: 0 0 30px rgba(255, 210, 72, .96), 0 4px 20px rgba(0,0,0,.18); }
  42% { transform: scale(.9) rotate(-4deg); }
  66% { transform: scale(1.08) rotate(2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); text-shadow: 0 2px 10px rgba(255,255,255,.9), 0 3px 16px rgba(0,0,0,.2); }
}
@keyframes answer-screen-flash {
  0% { opacity: 0; }
  12% { opacity: .92; }
  42% { opacity: .48; }
  100% { opacity: 0; }
}
@keyframes burst-particle {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--burst-angle)) translateX(0) scale(.2); }
  16% { opacity: 1; }
  58% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(calc(var(--burst-angle) + 100deg)) translateX(var(--burst-distance)) scale(.48); }
}
@keyframes medal-rays {
  0% { opacity: 0; transform: scale(.46) rotate(-12deg); }
  28% { opacity: .9; }
  100% { opacity: 0; transform: scale(1.18) rotate(18deg); }
}
@keyframes correct-choice-hit {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(35, 122, 75, .18); }
  28% { transform: scale(1.1); box-shadow: 0 0 0 11px rgba(35, 122, 75, .2); }
  58% { transform: scale(.96); box-shadow: 0 0 0 4px rgba(35, 122, 75, .09); }
  78% { transform: scale(1.04); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(35, 122, 75, 0); }
}
@keyframes medal-badge-land {
  0% { transform: scale(.48) rotate(-12deg); }
  54% { transform: scale(1.16) rotate(4deg); }
  76% { transform: scale(.96) rotate(-1.5deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes medal-halo {
  0% { opacity: .95; transform: scale(.72); }
  100% { opacity: 0; transform: scale(1.34); }
}
@keyframes result-mark-pop {
  0% { transform: scale(.54) rotate(-12deg); }
  48% { transform: scale(1.18) rotate(7deg); }
  72% { transform: scale(.94) rotate(-2deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes medal-icon-land {
  0% { opacity: 0; transform: translate(8px, -17px) rotate(-95deg) scale(.3); }
  58% { opacity: 1; transform: translate(-1px, 3px) rotate(14deg) scale(1.2); }
  78% { transform: translate(0, -1px) rotate(-5deg) scale(.96); }
  100% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .answer-mark,
  .answer-overlay.is-correct::after,
  .answer-burst-particle,
  .choice-button.correct-hit,
  .result-badge.medal-earned,
  .result-badge.medal-earned::before,
  .result-badge.medal-earned::after,
  .result-badge.medal-earned .result-mark,
  .result-badge.medal-earned .result-medal,
  .medal-burst-particle {
    animation: none !important;
    transition: none !important;
  }
  .answer-burst, .medal-burst { display: none !important; }
}
