:root {
  --lab-ink: #263736;
  --lab-muted: #667673;
  --lab-green: #2f7d69;
  --lab-green-dark: #1f6654;
  --lab-mint: #edf8f4;
  --lab-line: #dbe8e3;
  --lab-cream: #fff8ed;
  --lab-paper: #ffffff;
  --lab-shadow: 0 18px 50px rgba(42, 91, 76, .08);
}

body.lab-page { margin: 0; color: #263332; font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif; font-size: 16px; line-height: 1.8; background: linear-gradient(180deg, #fbfdfc 0, #f4faf7 33rem, #fbfcfb 70rem); }
.lab-main > :not(#quiz-comments) :is(img, svg, canvas) { max-width: 100%; }
.skip-link { position: fixed; z-index: 20; top: .5rem; left: .5rem; transform: translateY(-160%); padding: .65rem 1rem; color: white; background: var(--lab-green-dark); border-radius: 8px; text-decoration: none; font-weight: 800; }
.skip-link:focus { transform: translateY(0); }

.lab-header { background: rgba(255,255,255,.94); border-bottom: 1px solid rgba(219,232,227,.8); }
.lab-header-inner { width: min(calc(100% - 2.5rem), 1120px); min-height: 72px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.lab-brand { display: inline-flex; min-height: 44px; align-items: center; color: var(--lab-green); text-decoration: none; font-size: .82rem; font-weight: 900; letter-spacing: .14em; }
.lab-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: clamp(.35rem, 2vw, 1.25rem); }
.lab-nav a { display: inline-flex; min-height: 44px; align-items: center; color: var(--lab-muted); text-decoration: none; font-size: .88rem; font-weight: 700; white-space: nowrap; }
.lab-nav a:hover { color: var(--lab-green-dark); }

.lab-main { width: min(1120px, calc(100% - 32px)); margin-inline: auto; }
.lab-main > :not(#quiz-comments) { color: var(--lab-ink); line-height: 1.65; }
.lab-hero { width: 100%; min-height: 430px; margin: 0 auto; padding: clamp(4.5rem, 9vw, 7.5rem) 0 clamp(3.5rem, 8vw, 6rem); display: grid; grid-template-columns: minmax(0, 1fr) minmax(310px, .9fr); align-items: center; gap: clamp(2rem, 7vw, 6rem); }
.lab-eyebrow { margin: 0 0 .75rem; color: var(--lab-green); font-size: .76rem; font-weight: 900; letter-spacing: .15em; }
.lab-hero h1 { margin: 0; color: var(--lab-ink); font-family: "Yu Mincho", "Hiragino Mincho ProN", Georgia, serif; font-size: clamp(2.8rem, 7vw, 5rem); font-weight: 700; letter-spacing: .04em; line-height: 1.13; }
.lab-hero h1 span { display: inline-block; }
.lab-hero-copy > p:last-child { max-width: 38rem; margin: 1.5rem 0 0; color: var(--lab-muted); font-size: clamp(1rem, 1.5vw, 1.12rem); line-height: 2; }

.history-visual { position: relative; min-height: 260px; isolation: isolate; }
.history-visual::before { content: ""; position: absolute; inset: 10% 0 0 4%; z-index: -2; background: radial-gradient(circle at 60% 45%, #e9f6f1 0 3px, transparent 4px) 0 0 / 18px 18px; mask-image: radial-gradient(ellipse, black 34%, transparent 72%); }
.history-visual::after { content: ""; position: absolute; inset: 14% 2% 8%; z-index: -1; border-radius: 50%; background: rgba(237,248,244,.7); box-shadow: 0 25px 70px rgba(47,125,105,.08); transform: rotate(-4deg); }
.history-line { position: absolute; left: 8%; right: 8%; top: 55%; height: 2px; background: #a7cbbf; }
.history-line::before, .history-line::after { content: ""; position: absolute; top: 50%; width: 10px; height: 10px; border-radius: 50%; background: var(--lab-green); transform: translateY(-50%); }
.history-line::before { left: 0; }.history-line::after { right: 0; }
.history-card { position: absolute; display: grid; place-items: center; width: 104px; aspect-ratio: 4 / 5; color: var(--lab-green-dark); background: rgba(255,255,255,.94); border: 1px solid var(--lab-line); border-radius: 14px; box-shadow: var(--lab-shadow); font-family: Georgia, "Yu Mincho", serif; font-size: 2.3rem; font-weight: 700; }
.history-card-a { left: 7%; top: 18%; transform: rotate(-7deg); }
.history-card-b { left: 38%; top: 7%; transform: rotate(3deg); }
.history-card-c { right: 7%; top: 26%; transform: rotate(8deg); }

.game-stage { width: 100%; margin: 0 auto; }
.game-stage-heading { display: flex; align-items: end; justify-content: space-between; gap: 1.5rem; margin-bottom: 1rem; }
.game-stage-heading h2, .game-description > h2, .lab-subhero h1 { margin: 0; color: var(--lab-ink); font-family: "Yu Mincho", "Hiragino Mincho ProN", Georgia, serif; line-height: 1.3; }
.game-stage-heading h2 { font-size: clamp(1.55rem, 3vw, 2.1rem); }
.game-stage-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
.lab-outline-link { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: .55rem 1rem; color: var(--lab-green-dark); background: white; border: 1px solid #9ecabd; border-radius: 999px; text-decoration: none; font-size: .9rem; font-weight: 800; white-space: nowrap; }
.lab-outline-link:hover { background: var(--lab-mint); }
.lab-game-shell { width: min(100%, 820px); margin: 0 auto; }
.lab-game-shell .quiz-card { border-color: var(--lab-line); box-shadow: var(--lab-shadow); }
.lab-game-shell .quiz-card::before { background: linear-gradient(90deg, #c56d55 0 28%, var(--lab-green) 28% 100%); }
.lab-game-shell .quiz-card h2, .lab-game-shell .quiz-card h3 { margin: 0 0 .75rem; color: var(--navy-950); font-size: clamp(1.45rem, 4.5vw, 2.1rem); line-height: 1.45; letter-spacing: .01em; overflow-wrap: anywhere; }

.return-nav { width: 100%; margin: 1.25rem auto clamp(4rem, 8vw, 7rem); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .65rem 1.5rem; }
.return-nav a { display: inline-flex; min-height: 44px; align-items: center; color: var(--lab-green-dark); text-decoration-thickness: 1px; text-underline-offset: .28rem; font-weight: 800; }

.quiz-breadcrumb { display: flex; flex-wrap: wrap; column-gap: 8px; padding-top: .75rem; font-size: .875rem; color: #52665f; }
.quiz-breadcrumb a { color: #236c58; }
.game-description { width: 100%; margin: 0 auto 16px; padding: clamp(10px, 2vw, 20px); background: var(--lab-paper); border: 1px solid var(--lab-line); border-radius: 12px; }
.game-description > h2 { margin: 0 0 8px; font-family: inherit; font-size: 1.2rem; line-height: 1.5; }
.game-description p { margin: 0; overflow-wrap: anywhere; }
.game-guide { min-width: 0; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--lab-line); }
.game-guide h3 { margin: 0 0 6px; font-size: 1rem; }
.game-guide p + p { margin-top: .35rem; }
.game-guide .lab-outline-link { margin-top: .25rem; }

.lab-footer { color: #63716d; background: #f2f6f4; border-top: 1px solid var(--lab-line); }
.lab-footer-inner { width: min(calc(100% - 2.5rem), 1120px); min-height: 118px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; }
.lab-footer a { display: inline-flex; min-height: 44px; align-items: center; color: inherit; }
.lab-footer-brand { color: var(--lab-green-dark) !important; font-weight: 900; }
.lab-footer nav { display: flex; flex-wrap: wrap; gap: .2rem 1.2rem; font-size: .84rem; }

.lab-utility-page { min-height: calc(100vh - 191px); }
.lab-subhero { width: min(calc(100% - 2.5rem), 960px); margin: 0 auto; padding: clamp(3rem, 7vw, 5.5rem) 0 clamp(2rem, 5vw, 3.5rem); }
.lab-subhero h1 { font-size: clamp(2rem, 5vw, 3.4rem); }
.lab-subhero > p:last-child { max-width: 42rem; margin: 1rem 0 0; color: var(--lab-muted); }
.lab-utility-page .return-nav { margin-bottom: clamp(3rem, 7vw, 6rem); }
.lab-admin-shell { margin-top: 0; }
.lab-admin-shell .admin-heading h2 { margin: 0; color: var(--navy-950); font-size: clamp(1.45rem, 4vw, 2.1rem); line-height: 1.4; }
.lab-main > :not(#quiz-comments) details > summary { min-height: 44px; }

.lab-main > :not(#quiz-comments) :focus-visible { outline-color: #116eae; outline-offset: 4px; }

.lab-page .lab-hero {
  display: block;
  min-height: 0;
  width: 100%;
  padding: clamp(1.5rem, 4vw, 3rem) 0 1.5rem;
}
.lab-page .lab-hero h1 { font-size: clamp(1.85rem, 5vw, 3.25rem); }
.lab-page .lab-hero-copy > p:last-child { margin-top: .5rem; line-height: 1.6; }
.lab-page #start-view .primary-button { margin-top: .75rem; }
.rank-form { display: grid; gap: .45rem; margin: 1rem 0; }
.rank-form input { min-width: 0; min-height: 44px; padding: .5rem; font: inherit; }
.rank-form p { margin: 0; }
.ranking { margin-top: 1.5rem; }
.ranking ol { list-style: none; padding-left: 0; margin-bottom: 0; overflow-wrap: anywhere; }
.ranking li + li { margin-top: .5rem; }
.site-comments form { display: grid; gap: .5rem; margin-top: 1rem; }
.site-comments form :is(input, textarea) { min-width: 0; min-height: 44px; padding: .6rem; font: inherit; }
.site-comments form textarea { resize: vertical; }
.site-comments form p { margin: 0; }
.site-comments form button { justify-self: start; }

@media (max-width: 720px) {
  .lab-header-inner { width: min(calc(100% - 2rem), 1120px); min-height: 64px; }
  .lab-brand { max-width: 8.8rem; font-size: .68rem; line-height: 1.25; }
  .lab-nav { gap: .25rem; }
  .lab-nav a { padding-inline: .35rem; font-size: .78rem; }
  .lab-hero { min-height: 0; padding: 3.25rem 0 2.75rem; grid-template-columns: 1fr; gap: 1.25rem; }
  .lab-hero h1 { font-size: clamp(2.55rem, 14vw, 4rem); }
  .lab-hero-copy > p:last-child { margin-top: 1rem; line-height: 1.8; }
  .history-visual { min-height: 150px; }
  .history-card { width: 68px; border-radius: 10px; font-size: 1.5rem; }
  .history-card-a { left: 14%; }.history-card-b { left: 42%; }.history-card-c { right: 12%; }
  .lab-subhero { width: min(calc(100% - 2rem), 960px); }
  .game-stage-heading { align-items: flex-start; flex-direction: column; gap: .75rem; }
  .game-stage-actions { width: 100%; display: grid; grid-template-columns: 1fr; }
  .lab-footer-inner { width: min(calc(100% - 2rem), 1120px); padding: 1.25rem 0; align-items: flex-start; flex-direction: column; gap: .5rem; }
}

@media (max-width: 640px) {
  .lab-main { width: min(1120px, calc(100% - 24px)); }
}

@media (max-width: 430px) {
  .game-stage-actions { grid-template-columns: 1fr; }
  .lab-hero { padding-top: 2.5rem; }
  .return-nav { align-items: stretch; flex-direction: column; }
  .return-nav a { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* Keep quiz controls in the same frame while long questions can scroll inside. */
.lab-page .game-stage > .game-shell {
  box-sizing: border-box;
  width: min(100%, 720px);
  height: clamp(225px, 78svh, 570px);
  margin-inline: auto;
  overflow: auto;
  overscroll-behavior: contain;
}
#rank-confirmation button { margin-block: .2rem; }

.lab-page { overflow-anchor: none; }
