@layer base, layout, components;

@layer base {
  :root {
    color-scheme: light;
    --paper: #f6f4ed;
    --white: #fffdfa;
    --ink: #172b27;
    --muted: #526460;
    --green: #245448;
    --green-dark: #183d34;
    --line: #d9dfd6;
    --gold: #f9d598;
    --sky: #192a43;
    --burgundy: #95394c;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.5;
  }
  *, *::before, *::after { box-sizing: border-box; }
  body { margin: 0; }
  a { color: inherit; }
  button, input, textarea { font: inherit; }
  button { cursor: pointer; }
  button, a, input, textarea, summary { -webkit-tap-highlight-color: transparent; }
  :focus-visible { outline: 3px solid #b14e56; outline-offset: 4px; }
  [hidden] { display: none !important; }
  svg { display: block; width: 20px; height: 20px; flex: none; }
  p, h1, h2, h3, figure { margin: 0; }
  img { display: block; max-width: 100%; height: auto; }
  .sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

@layer layout {
  .shell { width: min(100% - 36px, 1000px); margin-inline: auto; }
  .top { border-bottom: 1px solid var(--line); background: #fdfbf7; }
  .top .shell { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 63px; }
  .nav { display: flex; align-items: center; gap: 6px; }
  .brand { display: inline-flex; min-height: 44px; align-items: center; gap: 9px; text-decoration: none; font-weight: 750; letter-spacing: -0.025em; }
  .brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--green-dark); color: var(--gold); }
  img.brand-mark { flex: none; border-radius: 0; background: transparent; image-rendering: pixelated; }
  .game { scroll-margin-top: 12px; }
  .intro { padding: 17px 0 15px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 8px 18px; }
  .intro h1 { font: 700 clamp(2rem, 4.5vw, 3.3rem)/1.02 Georgia, serif; letter-spacing: -0.045em; }
  .intro p { color: var(--muted); margin-bottom: 3px; }
  .quiz-preview .intro { display: block; padding: 24px 0 14px; }
  .quiz-preview .intro h1 { font-size: clamp(2rem, 5.2vw, 3.25rem); text-wrap: balance; }
  .quiz-preview .intro p { margin-top: 6px; font-size: .98rem; }
  .quiz-playable { width: min(100%, 920px, max(480px, calc((100svh - 220px) * 1.7778))); margin-inline: auto; }
  .quiz-preview.quiz-playable .intro { padding-block: 13px 10px; }
  .quiz-playable .intro h1 { font-size: clamp(1.65rem, 4vw, 2.5rem); }
  .preview-panel { overflow: clip; border: 1px solid #b7c8be; border-radius: 20px; background: var(--white); box-shadow: 0 12px 26px #172b2712; }
  .preview-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 14px; padding: 8px 13px; }
  .preview-bar p { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .91rem; font-weight: 650; }
  .preview-bar p svg { width: 17px; height: 17px; }
  .game-toolbar { display: grid; grid-template-columns: repeat(2, 44px); gap: 8px; margin-inline-start: auto; }
  .quiz-viewport { position: relative; aspect-ratio: 16 / 9; background: #172e2b; }
  .quiz-viewport iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
  .preview-panel:is(:fullscreen, [data-expanded]) { display: flex; flex-direction: column; width: 100%; height: 100%; border: 0; border-radius: 0; background: var(--white); }
  .preview-panel[data-expanded] { position: fixed; inset: 0; height: 100dvh; z-index: 10; }
  .preview-panel:is(:fullscreen, [data-expanded]) .quiz-viewport { flex: 1; min-height: 0; aspect-ratio: auto; }
  body.game-expanded { overflow: hidden; }
  .jump-nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; width: min(100%, 460px); margin: 12px auto 0; }
  .trivia-guide { max-width: 870px; margin-top: 36px; }
  .trivia-guide section { scroll-margin-top: 16px; }
  .trivia-guide h2 { text-wrap: balance; }
  .topic-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-block: 18px 22px; }
  .topic-card { display: grid; grid-template-rows: auto 1fr; min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--white); }
  .topic-card figure { height: auto; }
  .topic-card figure img { aspect-ratio: 8 / 5; border-radius: 0; }
  .topic-card figcaption { min-block-size: 3.9em; padding: 8px 14px; border-radius: 0; color: var(--muted); background: #eff3ee; text-align: justify; hyphens: auto; }
  .topic-copy { padding: 14px; }
  .topic-copy h3 { min-block-size: 2.6em; line-height: 1.3; }
  .topic-copy p { margin: 0; }
  .sample-notes { padding-inline-start: 22px; color: var(--muted); line-height: 1.6; text-align: justify; hyphens: auto; }
  .sample-notes li + li { margin-top: 6px; }
  .disclosure-list { display: grid; gap: 8px; margin-top: 13px; }
  .disclosure-list details { min-width: 0; background: var(--white); border: 1px solid var(--line); border-radius: 11px; }
  .disclosure-list summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 46px; padding: 10px 13px; cursor: pointer; font-weight: 700; list-style: none; }
  .disclosure-list summary:hover { background: #edf3ec; border-radius: 10px; }
  .disclosure-list summary::-webkit-details-marker { display: none; }
  .disclosure-list summary span { overflow-wrap: anywhere; }
  .disclosure-list summary::after { content: ""; width: 8px; height: 8px; margin-right: 3px; border-right: 2px solid var(--green); border-bottom: 2px solid var(--green); transform: translateY(-2px) rotate(45deg); }
  .disclosure-list details[open] > summary::after { transform: translateY(2px) rotate(225deg); }
  .disclosure-list details > p { margin: 0; padding: 0 13px 12px; }
  .disclosure-list details p a { color: var(--green-dark); text-underline-offset: .16em; }
  .game-window { background: var(--white); border: 1px solid #cad5ce; border-radius: 24px; overflow: clip; box-shadow: 0 16px 42px #172b2714; }
  .game-strip { display: grid; grid-template-columns: 1fr 1.25fr 1fr; align-items: center; gap: 10px; padding: 10px 17px; }
  .game-strip .label { display: flex; align-items: center; gap: 7px; font-size: .79rem; font-weight: 700; }
  .game-strip .label:last-child { justify-content: flex-end; }
  #score { font-size: 1.12rem; font-variant-numeric: tabular-nums; color: var(--green); }
  #stop-dots { display: flex; justify-content: center; align-items: center; min-width: 0; gap: clamp(2px, .65vw, 5px); }
  #stop-dots span { flex: 0 1 17px; min-width: 0; height: 6px; border-radius: 4px; background: #d8e1d8; }
  #stop-dots span[data-state="lit"] { background: #227463; }
  #stop-dots span[data-state="passed"] { background: #8d7282; }
  .village { aspect-ratio: 16 / 9; position: relative; overflow: hidden; isolation: isolate; background: var(--sky); }
  .village canvas, .village img { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
  .village canvas { opacity: 0; }
  .village[data-rendered] canvas { opacity: 1; }
  .start-layer { position: absolute; inset: 0; display: flex; align-items: end; padding: clamp(11px, 3.2vw, 32px); }
  .start-card { width: max-content; max-width: 100%; display: flex; align-items: center; gap: 22px; padding: 13px; border: 1px solid #e7f2ff40; border-radius: 16px; background: #142341ee; color: #fff7e8; box-shadow: 0 10px 24px #0a123355; }
  .start-card strong { font: 700 1.35rem/1.2 Georgia, serif; }
  .start-card p { color: #c6d7ec; font-size: .82rem; }
  .game-panel { padding: clamp(12px, 3vw, 22px); }
  .game-panel h2 { font: 700 clamp(1.4rem, 3vw, 2rem)/1.15 Georgia, serif; margin-bottom: 9px; }
  .game-panel h3 { margin: 13px 0 8px; font-size: 1rem; }
  .game-panel p { color: var(--muted); }
  .home-panel, .round-detail, .result-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
  .question-meta, .question-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  .question-meta { font-size: .84rem; color: var(--muted); font-weight: 700; }
  .timer-label { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
  .timer-label svg { width: 16px; height: 16px; }
  .time-track { height: 4px; background: #e3e9e3; border-radius: 4px; overflow: hidden; margin: 9px 0 15px; }
  .time-track span { display: block; height: 100%; transform-origin: left; background: #4d806e; }
  .answer-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(104px, auto); gap: 8px; }
  .answer-form input, textarea { width: 100%; min-width: 0; min-height: 46px; border: 1px solid #aebfb5; border-radius: 10px; background: #fff; color: var(--ink); padding: 8px 12px; font-size: 1rem; }
  .question-actions p { font-size: .91rem; }
  .eyebrow { font-size: .73rem; font-weight: 750; text-transform: uppercase; letter-spacing: .12em; margin-bottom: 5px; }
  .big-score { font-size: 1.6rem; color: var(--green); font-variant-numeric: tabular-nums; }
  .action-group { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .round-actions { flex: none; }
  .trial-question { margin-top: 14px; padding-top: 4px; border-top: 1px solid var(--line); }
  .trial-question p { margin-bottom: 8px; text-align: justify; }
  .trial-question label { display: block; margin: 10px 0 6px; font-weight: 650; }
  .trial-question [role="status"]:empty { display: none; }
  .trial-question textarea { min-height: 100px; }
  .review-list { list-style: none; margin: 0; padding: 0; }
  .review-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 54px; padding: 8px 0; border-top: 1px solid var(--line); }
  .review-list li strong { flex: none; }
  .review-list small { display: block; color: var(--muted); margin-left: 24px; }
  .review-number { display: inline-block; color: var(--green); min-width: 20px; font-variant-numeric: tabular-nums; font-weight: 750; }
  #copy-status { margin-top: 7px; }
  #share-text { min-height: 100px; resize: vertical; }
  .article { max-width: 790px; margin: 50px auto; }
  .article h2, .article h1 { font: 700 clamp(1.65rem, 3.8vw, 2.6rem)/1.13 Georgia, serif; letter-spacing: -.025em; }
  .article h3 { font-size: 1.16rem; }
  .article section { margin: 28px 0; }
  .article p { color: var(--muted); margin: 9px 0; line-height: 1.66; text-align: justify; hyphens: auto; }
  .article figure { margin: 0; height: 100%; display: grid; grid-template-rows: auto 1fr; }
  .article figure img { width: 100%; aspect-ratio: 16/9; object-fit: cover; image-rendering: pixelated; border-radius: 12px 12px 0 0; }
  .article figcaption { padding: 9px 11px; background: var(--white); border-radius: 0 0 12px 12px; color: var(--muted); font-size: .88rem; }
  .scene-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 17px 0; }
  .faq details { border-bottom: 1px solid var(--line); }
  .faq summary { cursor: pointer; min-height: 44px; align-content: center; font-weight: 700; padding: 8px 0; }
  footer { background: #182f2b; color: #f3f6ef; padding: 34px 0 15px; }
  .footer-main { display: grid; grid-template-columns: minmax(210px, 1fr) minmax(0, 2.2fr); gap: clamp(30px, 5vw, 64px); }
  .footer-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
  footer h2 { font-size: .94rem; }
  footer p, footer a { color: #d9e3dc; }
  footer p { margin-top: 8px; }
  footer .footer-links a { display: flex; align-items: center; min-height: 44px; text-decoration: none; }
  footer a:hover { text-decoration: underline; }
  .copyright { border-top: 1px solid #d7e7df30; padding-top: 12px; margin-top: 24px; font-size: .88rem; }
  dialog { width: min(100% - 32px, 410px); border: 1px solid var(--line); border-radius: 19px; background: var(--white); color: var(--ink); padding: 20px; }
  dialog::backdrop { background: #172b2777; }
  dialog p { margin: 10px 0 16px; color: var(--muted); }
  #game-share-dialog { max-height: calc(100dvh - 32px); }
  .share-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .share-heading h2 { line-height: 1.15; }
  .share-platforms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .share-link { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-block-start: 14px; }
  .share-link input { min-width: 0; min-height: 44px; padding-inline: 8px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); }
  #game-share-status { margin-bottom: 0; }
  #game-share-status:empty { display: none; }
}

@layer components {
  .button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 8px 13px; border: 1px solid transparent; border-radius: 11px; font-weight: 700; line-height: 1.2; text-decoration: none; text-align: center; transition: transform 130ms ease, background-color 130ms ease; }
  .button:active { transform: scale(.97); }
  .button.primary { color: #fff; background: var(--green); }
  .button.primary:hover { background: var(--green-dark); }
  .button.secondary { color: var(--green-dark); background: #eaf1ea; border-color: #d4e1d6; }
  .button.secondary:hover { background: #dfece2; }
  .button.plain { color: var(--green-dark); background: transparent; }
  .button.plain:hover { background: #ecf1eb; }
  .button.gold { color: #23291e; background: var(--gold); border-color: #fbe4bf; }
  .button.gold:hover { background: #ffe1ad; }
  .button svg { width: 17px; height: 17px; flex: none; }
  .button.icon-button { width: 44px; height: 44px; padding: 0; }
  .button.icon-button svg { width: 19px; height: 19px; }
  .share-platforms .button { justify-content: start; min-width: 0; padding-inline: 8px; font-size: .9rem; }
  #answer-feedback .button { margin-inline-start: 4px; }
}

@media (max-width: 760px) {
  .footer-main { grid-template-columns: 1fr; }
  .intro { align-items: start; flex-direction: column; }
}
@media (max-width: 640px) {
  .topic-grid { grid-template-columns: 1fr; }
  .topic-copy h3, .topic-card figcaption { min-block-size: 0; }
  .topic-copy p { margin-top: 5px; }
}
@media (max-width: 540px) {
  .shell { width: calc(100% - 24px); }
  .quiz-preview .intro { padding-top: 16px; }
  .preview-panel { border-radius: 15px; }
  .preview-bar { padding: 7px 10px; }
  .preview-bar .button { padding-inline: 8px; }
  .jump-nav .button { gap: 4px; padding-inline: 3px; font-size: .86rem; }
  .top .shell { min-height: 56px; }
  .nav .nav-help span { display: none; }
  .button.nav-help { min-width: 44px; }
  .game-window { border-radius: 17px; }
  .game-strip { padding: 7px 10px; gap: 5px; }
  .game-strip .label { font-size: .69rem; gap: 4px; }
  .game-strip .label svg { width: 16px; height: 16px; }
  .start-card { padding: 7px; border-radius: 13px; }
  .start-card .start-description { display: none; }
  .home-panel, .round-detail, .result-top { align-items: start; flex-direction: column; gap: 9px; }
  .round-detail > .button { width: 100%; }
  .action-group { width: 100%; }
  .scene-grid, .footer-links { grid-template-columns: 1fr; }
}
@media (max-width: 345px) {
  .nav .button { padding-inline: 7px; }
  .brand-mark { width: 29px; height: 29px; }
}
@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
}
