:root {
  color-scheme: light;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color: #46363c;
  background: #f6edf0;
  font-synthesis: none;
  --green: #17653b;
  --red: #a72a35;
  --muted: #74626b;
  --gold-line: rgba(143,95,32,.58);
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100svh; background: #f6edf0 url('../assets/images/game-background.jpeg') center / cover fixed no-repeat; }
body[data-screen="home"] { background-image: none; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible { outline: 3px solid #b45d78; outline-offset: 4px; }
[hidden] { display: none !important; }
h1:focus, h2:focus { outline: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.shell { min-height: 100svh; }

.stage { min-height: 100svh; display: flex; justify-content: center; align-items: center; padding: 124px clamp(24px, 5vw, 96px) 36px; }
.content { width: min(100%, 1040px); }
body[data-screen='home'] .stage { padding: 0; }
body[data-screen='home'] .content { width: 100%; max-width: none; margin: 0; }
#home { position: relative; height: 100svh; height: 100dvh; min-height: 100svh; isolation: isolate; overflow: hidden; }
#home::before { content: ''; position: absolute; z-index: -2; inset: -48px; background: url('./assets/home-background.jpg') center / cover no-repeat; filter: blur(32px); pointer-events: none; }
.home-art { position: absolute; z-index: -1; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.home-actions { position: absolute; bottom: max(5.5svh, 20px); left: 0; width: 100%; text-align: center; padding: 0 20px; }
.primary { min-height: 48px; padding: 12px 30px; border: 1px solid var(--gold-line); border-radius: 999px; color: #573814; background: linear-gradient(180deg,#fff2c8,#e7b95d); box-shadow: inset 0 1px 0 #ffffffd9,0 8px 22px #6c461445; font-weight: 600; transition: transform .18s ease, box-shadow .18s ease; }
.primary:hover:not(:disabled) { transform: translateY(-2px); background: linear-gradient(180deg,#fff8dc,#dca53e); box-shadow: inset 0 1px 0 #ffffffe6,0 10px 28px #6c461452; }
.primary:disabled { opacity: .5; }
#start { min-width: 240px; min-height: 58px; font-size: clamp(18px,1.5vw,24px); letter-spacing: .15em; }
#question-count { margin: 12px 0 0; color: #573814; text-shadow: 0 1px 4px #fff; font-size: 13px; }
#game, #result { padding: clamp(24px,3vw,42px); border: 1px solid #ddc59dd9; border-radius: 24px; background: rgba(255,252,251,.77); box-shadow: 0 18px 60px #361c2833, inset 0 0 0 5px #fff8eb7a; }
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.quiet { min-height: 42px; padding: 10px 19px; border: 1px solid #70445429; border-radius: 999px; color: #46363c; background: rgba(255,252,251,.78); }
.quiet:hover { background: #fff; }
.page-heading { position: absolute; top: 26px; left: clamp(24px, 4vw, 70px); }
body[data-screen='home'] .page-heading { display: none; }
.game-title { margin: 0; font-family: 'Kaiti SC','STKaiti','KaiTi','Songti SC',serif; font-weight: 900; font-size: clamp(30px,3.2vw,48px); line-height: 1.4; color: #fff0bf; letter-spacing: .09em; -webkit-text-stroke: .6px #97632b; text-shadow: 0 1px 0 #fff9e9, 1px 2px 0 #ad793c, 2px 3px 0 #825124, 3px 5px 8px #3d281866; }
#game { min-height: 650px; }
#question-title { margin: 34px 0 30px; min-height: 88px; display: flex; align-items: center; font-size: clamp(25px,2.5vw,36px); }
#game .options { gap: 16px; }
#game .option { min-height: 72px; font-size: 20px; }
#game #next { margin-top: 26px; }

progress { display: block; width: 100%; height: 5px; border: 0; border-radius: 9px; overflow: hidden; margin-top: 18px; accent-color: #b68c47; }
progress::-webkit-progress-bar { background: #eadfd4; }
progress::-webkit-progress-value { background: #b68c47; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.7; }
h2 { font-size: clamp(20px,1.8vw,27px); line-height: 1.6; margin: 22px 0; overflow-wrap: anywhere; }
p { line-height: 1.8; }
.options { display: grid; gap: 12px; }
.option { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 62px; padding: 12px 16px; border: 1.5px solid #aa8754; border-radius: 14px; text-align: left; color: #503820; background: transparent; box-shadow: 0 2px 8px #4028171a; text-shadow: 0 1px 2px #fffaf2; transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.option:hover:not(:disabled) { border-color: #e6c998; background: transparent; box-shadow: 0 0 0 2px rgba(255,255,255,.94),0 0 15px 4px rgba(255,255,255,.78),0 0 30px 9px rgba(230,201,152,.68); transform: translateY(-2px); }
.letter { display: grid; place-items: center; flex-shrink: 0; width: 32px; height: 32px; border: 1px solid currentColor; border-radius: 50%; font-weight: 700; }
.option-label { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.5; }
.option-status { font-size: 14px; flex-shrink: 0; }
.option.correct { border: 2px solid var(--green); background: transparent; color: var(--green); box-shadow: 0 0 0 2px #80b99091; }
.option.wrong { border: 2px solid var(--red); background: transparent; color: var(--red); box-shadow: 0 0 0 2px #e39da493; }
.feedback { font-size: 14px; min-height: 26px; margin: 18px 0; }
.success-text { color: var(--green); }.error-text { color: var(--red); }
#next { display: block; margin-left: auto; min-width: 150px; }
#result { text-align: center; }
#result-title { font-family: 'Songti SC','STSong',serif; font-size: 32px; color: #754e26; }
.score { font-size: 88px; line-height: 1.2; color: #9c6d2c; margin: 28px 0; font-weight: 700; }
.score small { font-size: 32px; margin-left: 8px; }
.note { font-size: 13px; color: var(--muted); margin: 24px 0; }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
@media (max-aspect-ratio: 3/2) {
  .home-art {
    top: 6svh; bottom: auto; height: auto; object-fit: contain;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 18%, #000 74%, transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0%, #000 18%, #000 74%, transparent 100%);
  }
  .home-actions { bottom: 13svh; }
}
@media (max-width: 760px) {
  .stage { padding: 112px 16px 24px; align-items: center; }
  .content { width: 100%; max-width: 580px; margin: auto; }
  body { background-position: 38% top; background-attachment: scroll; }
  #game, #result { padding: 24px 20px; border-radius: 20px; }
  .page-heading { top: 24px; left: 20px; }
  .game-title { font-size: clamp(27px,6.8vw,38px); }
  #game { min-height: 0; }
  #question-title { min-height: 70px; margin: 26px 0; font-size: 25px; }
  #game .option { font-size: 17px; min-height: 66px; }

  .home-actions { bottom: 18svh; }
  .option { flex-wrap: wrap; gap: 10px; padding: 12px; }
  .option-status:not(:empty) { width: 100%; padding-left: 42px; }
  .result-actions { flex-direction: column; }
}
@media (max-height: 650px) and (min-width: 761px) {
  .stage { padding-top: 100px; } #game { padding: 24px; min-height: 0; } #question-title { min-height: 54px; margin: 20px 0; } #game .options { gap: 10px; } #game .option { min-height: 54px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Keep the entire answer flow inside the viewport, including the reveal area. */
body[data-screen='game'] .stage {
  min-height: 100svh; min-height: 100dvh;
  padding: 100px clamp(20px, 5vw, 80px) 20px;
}
body[data-screen='game'] .content { margin: 0; }
#game {
  min-height: min(740px, calc(100dvh - 120px)); padding: clamp(18px, 2.6vh, 30px) clamp(20px, 3vw, 42px);
  display: grid; grid-template-rows: auto 4px auto 1fr auto;
  gap: clamp(10px, 1.8vh, 18px);
}
.game-title {
  display: inline-block; padding: 4px 18px 7px; border: 1px solid #f7e5bf;
  border-radius: 16px; background: rgba(19, 47, 75, .92); color: #fff5d9;
  -webkit-text-stroke: 0; text-shadow: 0 2px 3px #091e34;
  box-shadow: 0 5px 20px #09243c66;
}
#game progress { margin: 0; height: 4px; }
#game #question-title { margin: 0; min-width: 0; min-height: 0; font-size: clamp(23px, 2.5vw, 34px); line-height: 1.45; overflow-wrap: anywhere; }
#game .options { gap: clamp(8px, 1.3vh, 14px); grid-template-rows: repeat(4, minmax(64px, auto)); }
#game .option { min-height: 64px; padding: 8px 16px; font-size: clamp(16px, 1.6vw, 20px); }
#game .option-label { white-space: normal; overflow-wrap: anywhere; word-break: break-word; }
.answer-footer { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-width: 0; }
#game #next { margin: 0 0 0 auto; flex-shrink: 0; }
.explanation { min-width: 0; max-width: 740px; padding-left: 14px; border-left: 2px solid #af8d7c; color: #59434b; }
.explanation strong { font-size: 14px; font-weight: 600; letter-spacing: .08em; }
.explanation p { margin: 4px 0 0; font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.explanation-more { color: #76525e; background: none; border: 0; padding: 3px 0 0; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
#explanation-dialog { width: min(620px, calc(100vw - 32px)); max-height: 80dvh; padding: 24px; border: 1px solid #cfb79e; border-radius: 20px; background: #fff9f3; color: #46363c; box-shadow: 0 24px 80px #291b3055; }
#explanation-dialog::backdrop { background: #30212f77; }
#explanation-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
#explanation-dialog h2 { margin: 0; font-size: 22px; }
#full-explanation { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .page-heading { top: 16px; }
  body[data-screen='game'] .stage { padding: 78px 12px 12px; }
  #game { padding: 18px 16px; gap: 10px; }
  #game .game-top .quiet { min-height: 36px; padding: 6px 14px; }
  #game #question-title { font-size: clamp(20px, 5.4vw, 25px); }
  #game .option { flex-wrap: nowrap; gap: 9px; padding: 6px 10px; }
  #game .option-status:not(:empty) { width: auto; padding: 0; font-size: 12px; }
  #game .letter { width: 27px; height: 27px; font-size: 14px; }
  .answer-footer { gap: 12px; }
  .explanation { padding-left: 10px; }
  .explanation strong { font-size: 12px; }
  .explanation p { font-size: 13px; }
  #game #next { min-width: 96px; min-height: 42px; padding: 9px 16px; font-size: 14px; }
}
@media (max-height: 500px) and (min-width: 761px) {
  .page-heading { top: 8px; }.game-title { font-size: 28px; }
  body[data-screen='game'] .stage { padding-top: 58px; padding-bottom: 8px; }
  #game { padding: 12px 24px; gap: 8px; }
  #game .game-top .quiet { min-height: 30px; padding: 4px 14px; }
  #game #question-title { font-size: 21px; }
  #game .options { grid-template-columns: repeat(2,minmax(0,1fr)); grid-template-rows: repeat(2,minmax(64px,auto)); }
}
@media (min-width: 761px) and (min-height: 501px) and (max-height: 700px) {
  #game { padding: 14px 24px; gap: 8px; }
  #game .game-top .quiet { min-height: 36px; padding: 6px 14px; }
  #game #question-title { font-size: 24px; }
  #game .options { gap: 8px; }
  #game .letter { width: 26px; height: 26px; }
}
.question-row { display: flex; align-items: center; gap: 20px; min-height: 0; }
#game #question-title { flex: 1; }
#open-explanation { flex-shrink: 0; color: #76525e; border-color: #b99685; background: #fff8ebbd; }
#open-explanation:disabled { opacity: .45; }
.answer-footer { justify-content: flex-end; gap: 14px; }
#game #next { margin-left: 0; }
#explanation-dialog {
  width: min(1500px, calc(100vw - 24px), calc((100dvh - 40px) * 1.77778));
  max-width: none; max-height: calc(100dvh - 24px); padding: 0; border: 0; border-radius: 0;
  background: transparent; box-shadow: none; overflow: visible; color: #193956;
}
#explanation-dialog::backdrop { background: rgba(32,53,80,.4); backdrop-filter: blur(2px); }
.analysis-ticket { position: relative; width: 78%; aspect-ratio: 16 / 9; container-type: inline-size; }
.analysis-art { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
#explanation-heading { position: absolute; top: 54%; left: 15.5%; width: 20%; height: 28%; margin: 0; display: flex; align-items: center; justify-content: center; transform: translate(-50%, -50%) rotate(-12deg); text-align: center; font: 800 3.8cqw/1.2 'Songti SC',serif; color: #24456c; }
#analysis-number { position: absolute; top: 54%; left: 84%; width: 22%; height: 28%; display: flex; align-items: center; justify-content: center; transform: translate(-50%, -50%) rotate(16deg); text-align: center; font: 800 3.2cqw/1.5 'Songti SC',serif; color: #fff0cd; }
.analysis-body { position: absolute; left: 31%; top: 35%; width: 38%; height: 25%; overflow: auto; scrollbar-width: thin; text-align: center; }
#full-explanation { margin: 0; font-size: clamp(16px,1.8cqw,23px); line-height: 1.65; color: #193956; white-space: pre-wrap; overflow-wrap: anywhere; }
#close-explanation { position: absolute; left: 37%; top: 62%; width: 26%; height: 12%; padding: 0; border: 0; border-radius: 999px; background: transparent; color: #fff6db; font: 800 2.6cqw 'Songti SC',serif; text-shadow: 0 2px 3px #7b481b; }
.analysis-portrait { position: absolute; right: 0; bottom: 10%; width: 27%; height: 88%; object-fit: contain; object-position: bottom; pointer-events: none; filter: drop-shadow(0 12px 28px #0004); mask-image: linear-gradient(to bottom,#000 80%,transparent); }
#review-dialog { width: min(820px,calc(100vw - 28px)); max-height: 85dvh; padding: 24px; border: 1px solid #cfb79e; border-radius: 22px; background: #fff9f3; color: #46363c; overflow: hidden; }
#review-dialog::backdrop { background: #30212f77; backdrop-filter: blur(2px); }
.review-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.review-heading h2 { margin: 0; font-family: 'Songti SC',serif; color: #76525e; }
#review-content { max-height: calc(85dvh - 110px); overflow: auto; padding-right: 8px; }
.review-question { padding: 20px 0; border-bottom: 1px solid #dbcabc; }
.review-question:last-child { border-bottom: 0; }
.review-question h3 { margin: 0 0 12px; font-size: 20px; }
.review-option { padding: 8px 12px; margin: 8px 0; border-radius: 8px; background: #f4ede5; overflow-wrap: anywhere; }
.review-correct { background: #e4f5e9; color: var(--green); }.review-wrong { background: #fdebed; color: var(--red); }
@media (max-width:760px) {
  .question-row { gap: 10px; } #open-explanation { padding: 8px 10px; font-size: 12px; min-height: 36px; }
  #game #question-title { font-size: clamp(18px,5vw,23px); }
  #explanation-dialog { width: calc(100vw - 24px); padding: 0 0 16px; border: 2px solid #d9ae6e; border-radius: 24px; background: linear-gradient(#edf4ff,#fff6e5); box-shadow: inset 0 0 0 5px #fffc; overflow: hidden; }
  .analysis-ticket { width: 100%; aspect-ratio: auto; padding: 108px 22px 76px; }
  .analysis-art { position: absolute; top: -22px; left: 0; width: 100%; height: 200px; object-fit: cover; opacity: .55; mask-image: linear-gradient(#000 50%,transparent); }
  #explanation-heading { top: 30px; left: 22px; width: auto; height: auto; font-size: 27px; line-height: 1.3; transform: none; }
  #explanation-heading br { display: none; }
  #analysis-number { top: 32px; left: auto; right: 24px; width: auto; height: auto; font-size: 18px; color: #24456c; transform: none; }
  .analysis-body { position: relative; left: auto; top: auto; width: 100%; height: auto; max-height: 42dvh; min-height: 100px; }
  #full-explanation { font-size: 17px; }
  #close-explanation { top: auto; bottom: 6px; left: 22%; width: 56%; height: 46px; border: 1px solid #ad7b39; font-size: 18px; background: linear-gradient(#fff0c0,#dbaa55); color: #573814; text-shadow: none; }
  .analysis-portrait { display: none; }
  #review-dialog { padding: 20px; }
}
#explanation-dialog #explanation-heading { font-size: 3.8cqw; }
.analysis-body { display: flex; flex-direction: column; }
#full-explanation { flex-shrink: 0; margin-block: auto; }
@media (max-width:760px) { #explanation-dialog #explanation-heading { font-size: 27px; } }

/* Keep the title in document flow so the answer card always starts below it. */
body[data-screen='game'] .shell { display: flex; flex-direction: column; }
body[data-screen='game'] .page-heading {
  position: relative; top: auto; left: auto;
  padding: 16px clamp(12px, 4vw, 70px) 0;
}
body[data-screen='game'] .stage {
  flex: 1 0 auto;
  padding-top: 14px;
}

/* Fit the quiz within one viewport; use compact spacing on small screens. */
body[data-screen='game'] { overflow: hidden; }
body[data-screen='game'] .shell { height: 100svh; height: 100dvh; min-height: 0; }
body[data-screen='game'] .page-heading { flex: 0 0 auto; padding-top: 8px; }
body[data-screen='game'] .game-title { font-size: clamp(20px, 2.2vw, 30px); line-height: 1.2; padding: 3px 12px 5px; }
body[data-screen='game'] .stage { flex: 1 1 auto; min-height: 0; padding: 7px clamp(10px, 4vw, 70px) 8px; }
body[data-screen='game'] .content { height: 100%; }
#game { height: 100%; min-height: 0; grid-template-rows: auto 4px auto minmax(0, 1fr) auto; }
#game .options { min-height: 0; grid-template-rows: repeat(4, minmax(0, 1fr)); }
#game .option { min-height: 0; }
.ending-message { font-size: clamp(20px, 3vw, 30px); color: #754e26; margin: 24px 0 36px; }
#result { max-width: 700px; margin-inline: auto; }
.analysis-body { height: 30%; }
#full-explanation { font-size: clamp(21px, 2.5cqw, 31px); line-height: 1.55; }
@media (max-width: 760px) {
  body[data-screen='game'] .game-title { font-size: clamp(19px, 5vw, 25px); }
  #result-title { font-size: clamp(23px, 5vw, 28px); }
  #game { padding: 12px; gap: 6px; }
  #game #question-title { font-size: clamp(16px, 4.4vw, 21px); line-height: 1.3; }
  #game .options { gap: 6px; }
  #game .option { padding: 5px 8px; font-size: clamp(12px, 3.8vw, 16px); line-height: 1.25; }
  #game .option-label { line-height: 1.25; }
  #game .letter { width: 24px; height: 24px; font-size: 12px; }
  #game .option-status:not(:empty) { font-size: 12px; }
  #game .answer-footer { gap: 6px; }
  #game .answer-footer .quiet, #game #next { min-height: 34px; padding: 6px 10px; font-size: 12px; }
  #explanation-dialog .analysis-body { max-height: 48dvh; }
  #explanation-dialog #full-explanation { font-size: 20px; line-height: 1.55; }
}
@media (max-height: 620px) {
  body[data-screen='game'] .page-heading { padding-top: 5px; }
  body[data-screen='game'] .stage { padding-top: 5px; padding-bottom: 5px; }
  #game { padding-block: 8px; gap: 4px; }
  #game .options { gap: 4px; }
  #game .option { padding-block: 3px; }
  #game #question-title { font-size: clamp(15px, 3.8vw, 19px); }
}

.question-picker-trigger { font-size: inherit; white-space: nowrap; min-height: 34px; padding: 6px 12px; }
#question-picker {
  width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 20px; border: 1px solid #d5b784; border-radius: 20px;
  background: #fff9ef; color: #46363c; box-shadow: 0 24px 70px #241b2c66;
}
#question-picker::backdrop { background: #14273a99; backdrop-filter: blur(3px); }
.picker-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.picker-heading h2 { margin: 0; font-size: 23px; }
.picker-heading .quiet { min-height: 34px; padding: 6px 12px; }
.picker-hint { margin: 8px 0 16px; font-size: 13px; color: #715e65; }
.question-picker-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 9px; }
.picker-number { min-width: 0; aspect-ratio: 1; border: 1px solid #c8ab7f; border-radius: 12px; background: #fff; color: #573f28; font-size: 17px; font-weight: 700; }
.picker-number.is-answered { background: #e4f5e9; border-color: #77ae89; color: #17653b; }
.picker-number.is-current { outline: 3px solid #9e6c3c; outline-offset: 1px; }
.picker-number:hover { background: #fff0cf; }
@media (max-width: 380px), (max-height: 620px) {
  #question-picker { padding: 14px; }
  .picker-heading h2 { font-size: 20px; }
  .picker-hint { margin: 5px 0 10px; }
  .question-picker-grid { gap: 6px; }
  .picker-number { font-size: 15px; }
}

/* Keep the full width while shortening each answer row through larger vertical gaps. */
#game .options { width: 100%; margin: 8px auto 0; gap: clamp(14px, 2vh, 20px); }
#game #reset-test { background: rgba(255,252,251,.72); white-space: nowrap; }
@media (max-width: 760px) {
  #game .options { margin-top: 6px; gap: 11px; }
  #game .answer-footer { justify-content: space-between; }
  #game #reset-test { padding-inline: 8px; }
}
@media (max-height: 620px) {
  #game .options { margin-top: 4px; gap: 9px; }
}
@media (max-width: 380px) {
  #game .answer-footer .quiet { padding-inline: 5px; font-size: 11px; white-space: nowrap; }
  #game #next { min-width: 72px; }
}
