:root {
  --green: #0f8f69;
  --green-dark: #08684d;
  --yellow: #ffd447;
  --orange: #ff9d3f;
  --blue: #4fa8ff;
  --red: #e25555;
  --cream: #fff9e8;
  --ink: #20312b;
  --white: #ffffff;
  --shadow: 0 16px 40px rgba(21, 83, 65, .15);
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  min-height: 100%;
}
html {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
}
body {
  margin: 0;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(#aee7ff 0 42%, #dff5c9 42% 100%);
  min-height: 100vh;
  min-height: 100dvh;
  min-height: var(--app-height, 100dvh);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
}
body::after {
  content: "";
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 28vh;
  background:
    radial-gradient(circle at 10% 100%, #7cc95d 0 18%, transparent 19%),
    radial-gradient(circle at 33% 100%, #58b94a 0 25%, transparent 26%),
    radial-gradient(circle at 67% 100%, #83cd61 0 20%, transparent 21%),
    radial-gradient(circle at 90% 100%, #56b447 0 27%, transparent 28%);
  z-index: -2;
}
button { font: inherit; }
button:focus-visible { outline: 4px solid #233bff; outline-offset: 3px; }

.cloud {
  position: fixed;
  width: 150px;
  height: 48px;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  z-index: -1;
  animation: drift 18s linear infinite;
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}
.cloud::before { width: 62px; height: 62px; left: 25px; top: -27px; }
.cloud::after { width: 76px; height: 76px; right: 20px; top: -35px; }
.cloud-a { top: 10vh; left: -180px; }
.cloud-b { top: 24vh; left: -260px; animation-delay: -8s; transform: scale(.75); }
@keyframes drift { to { left: 110vw; } }

.app-shell { width: min(1100px, 100%); min-height: 100vh; min-height: 100dvh; min-height: var(--app-height, 100dvh); margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 18px max(40px, env(safe-area-inset-bottom)); overflow: visible; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.88); border-radius: 20px; padding: 8px 14px; box-shadow: var(--shadow); }
.brand-badge { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; background: var(--yellow); font-weight: 900; transform: rotate(-4deg); }
.brand strong, .brand span { display: block; }
.brand strong { color: var(--green-dark); font-size: 1.05rem; }
.brand span { font-size: .9rem; }
.top-actions { display: flex; gap: 8px; }
.icon-btn { width: 48px; height: 48px; border: 0; border-radius: 16px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); font-size: 1.45rem; cursor: pointer; }

.screen { display: none; }
.screen.active { display: block; width: 100%; min-width: 0; animation: popIn .35s ease; }
@keyframes popIn { from { opacity: 0; transform: translateY(12px) scale(.985); } }

.hero-card, .question-card, .result-card, .panel-card {
  background: rgba(255,255,255,.95);
  border: 5px solid rgba(255,255,255,.7);
  box-shadow: var(--shadow);
}
.hero-card { display: flex; align-items: center; gap: 24px; border-radius: 32px; padding: 28px; }
.mascot { font-size: clamp(4rem, 12vw, 7rem); animation: bounce 2.2s ease-in-out infinite; }
@keyframes bounce { 50% { transform: translateY(-8px) rotate(3deg); } }
.eyebrow { margin: 0 0 5px; text-transform: uppercase; letter-spacing: .09em; font-weight: 900; color: var(--green); font-size: .8rem; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2rem, 6vw, 3.7rem); line-height: 1; color: var(--green-dark); }
.hero-copy p:last-child { margin: 0; font-size: 1.08rem; }

.age-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 22px 0; }
.age-card {
  min-height: 220px;
  border: 0;
  border-radius: 28px;
  padding: 20px;
  background: var(--white);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
}
.age-card:nth-child(1) { border-bottom: 12px solid var(--yellow); }
.age-card:nth-child(2) { border-bottom: 12px solid var(--orange); }
.age-card:nth-child(3) { border-bottom: 12px solid var(--blue); }
.age-card:hover, .age-card:active { transform: translateY(-7px) scale(1.02); box-shadow: 0 22px 45px rgba(21,83,65,.22); }
.age-number { display: block; font-size: 5rem; font-weight: 1000; line-height: .9; color: var(--green-dark); }
.age-label { display: block; font-size: 1.35rem; font-weight: 900; margin: 8px 0 12px; }
.age-card small { display: block; font-size: .95rem; line-height: 1.35; color: #53645e; }
.home-actions, .result-actions, .report-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.primary-btn, .secondary-btn, .danger-btn {
  border: 0; border-radius: 18px; min-height: 52px; padding: 12px 22px; font-weight: 900; cursor: pointer; box-shadow: 0 8px 18px rgba(23,66,54,.12);
}
.primary-btn { background: var(--green); color: white; }
.secondary-btn { background: white; color: var(--green-dark); }
.danger-btn { background: #ffe7e7; color: #8d2424; }

.game-status { display: grid; grid-template-columns: 50px 1fr auto; align-items: center; gap: 14px; margin-bottom: 14px; }
.back-btn { font-size: 1.8rem; }
.progress-wrap { height: 22px; background: rgba(255,255,255,.76); border-radius: 999px; padding: 4px; box-shadow: inset 0 2px 6px rgba(0,0,0,.12); overflow: hidden; }
.progress-bar { height: 100%; width: 10%; background: linear-gradient(90deg, var(--yellow), var(--orange)); border-radius: inherit; transition: width .35s ease; }
.star-score { min-width: 86px; height: 50px; display: flex; align-items: center; justify-content: center; gap: 5px; border-radius: 18px; background: white; box-shadow: var(--shadow); font-size: 1.3rem; }
.question-card { border-radius: 32px; padding: clamp(18px, 4vw, 34px); text-align: center; min-height: max(0px, calc(var(--app-height, 100dvh) - 138px)); overflow: visible; }
.question-meta { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.pill { display: inline-flex; align-items: center; min-height: 34px; padding: 6px 12px; border-radius: 999px; background: #dff7eb; color: var(--green-dark); font-size: .9rem; font-weight: 900; }
.pill.muted { background: #eef2ef; color: #59665f; }
.question-card h2 { font-size: clamp(1.65rem, 4.6vw, 2.65rem); margin-bottom: 10px; }
.listen-btn { border: 0; border-radius: 999px; background: #eef8ff; color: #265e89; font-weight: 800; padding: 9px 16px; cursor: pointer; }
.visual-area { width: 100%; min-width: 0; min-height: clamp(120px, 30dvh, 240px); display: grid; place-items: center; padding: clamp(6px, 2vh, 18px) 8px; overflow: visible; }
.object-grid { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: clamp(5px, 1.5vmin, 15px); width: 100%; max-width: 720px; min-width: 0; }
.count-object { font-size: clamp(1.75rem, 7vmin, 4.6rem); filter: drop-shadow(0 4px 2px rgba(0,0,0,.08)); animation: objectPop .35s backwards; }
@keyframes objectPop { from { opacity: 0; transform: scale(.45) rotate(-10deg); } }
.math-expression { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: clamp(7px, 2vmin, 15px); font-size: clamp(2.2rem, 10vmin, 7rem); font-weight: 1000; color: var(--green-dark); }
.sequence { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.sequence span { min-width: clamp(48px, 12vmin, 74px); padding: clamp(8px, 2vmin, 14px); border-radius: 20px; background: #f2f7f4; font-size: clamp(1.7rem, 6.5vmin, 4rem); font-weight: 1000; }
.sequence .missing { background: var(--yellow); }
.compare-boxes { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: clamp(5px, 1.5vmin, 14px); align-items: center; }
.compare-group { min-width: 0; min-height: clamp(105px, 24dvh, 190px); display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 8px; border-radius: 24px; background: #f3f9f5; padding: 12px; }
.compare-vs { font-weight: 1000; color: var(--orange); font-size: clamp(.85rem, 3vmin, 1.6rem); }
.compare-group .count-object { font-size: clamp(1.15rem, 4.5vmin, 2.7rem); }
.object-grid.dense .count-object { font-size: clamp(1.35rem, 5.2vmin, 3.1rem); }
.object-grid.very-dense .count-object { font-size: clamp(1.1rem, 4.4vmin, 2.6rem); }
.answers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(7px, 1.8vmin, 14px); width: 100%; max-width: 680px; min-width: 0; margin: 0 auto; }
.answer-btn {
  min-width: 0; min-height: clamp(58px, 11dvh, 86px); border: 0; border-radius: 22px; padding: 6px; background: #fff7cf; color: var(--ink); font-size: clamp(1.6rem, 6vmin, 3.7rem); font-weight: 1000; box-shadow: 0 8px 0 #e5bc32; cursor: pointer; transition: transform .1s ease;
}
.answer-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #e5bc32; }
.answer-btn.correct { background: #c9f5d5; box-shadow: 0 8px 0 #70bf82; animation: correctPulse .6s ease; }
.answer-btn.wrong { background: #ffe0e0; box-shadow: 0 8px 0 #df8a8a; animation: shake .35s ease; }
@keyframes correctPulse { 50% { transform: scale(1.08); } }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.feedback { min-height: 32px; margin: 22px 0 0; font-size: 1.25rem; font-weight: 900; color: var(--green-dark); }

.result-card, .panel-card { max-width: 820px; margin: 0 auto; border-radius: 32px; padding: clamp(24px, 5vw, 42px); text-align: center; }
.result-emoji { font-size: 6rem; animation: bounce 1.5s infinite; }
.result-card h2 { font-size: clamp(2.3rem, 7vw, 4rem); margin-bottom: 8px; color: var(--green-dark); }
.big-score { display: inline-flex; flex-direction: column; padding: 18px 36px; border-radius: 25px; background: var(--yellow); margin: 16px 0 20px; }
.big-score span { font-size: 3.5rem; font-weight: 1000; line-height: 1; }
.big-score small { font-weight: 900; }
.award-row { min-height: 66px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 24px; font-size: 2.4rem; }
.panel-heading { display: flex; align-items: center; text-align: left; gap: 16px; margin-bottom: 20px; }
.panel-heading h2 { margin: 0; color: var(--green-dark); }
.report-content { display: grid; gap: 12px; text-align: left; margin-bottom: 22px; }
.report-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 17px; border-radius: 20px; background: #f2f8f4; }
.report-item strong { color: var(--green-dark); }
.report-empty { padding: 30px; text-align: center; border: 3px dashed #b8d7c7; border-radius: 22px; color: #5b6d64; }

#helpDialog { border: 0; border-radius: 28px; padding: 0; width: min(500px, calc(100% - 30px)); max-height: calc(var(--app-height, 100dvh) - 24px); overflow-y: auto; box-shadow: 0 25px 80px rgba(0,0,0,.25); }
#helpDialog::backdrop { background: rgba(8,43,33,.6); }
.dialog-card { position: relative; padding: 30px; text-align: center; }
.dialog-close { position: absolute; right: 12px; top: 10px; width: 42px; height: 42px; border: 0; border-radius: 50%; background: #eef1ef; font-size: 1.8rem; cursor: pointer; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 99; }
.confetti-piece { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: confettiFall 1.8s linear forwards; }
@keyframes confettiFall { to { transform: translate(var(--drift), 110vh) rotate(720deg); } }

@media (max-width: 720px) {
  .age-grid { grid-template-columns: 1fr; }
  .age-card { min-height: 145px; display: grid; grid-template-columns: 90px 1fr; grid-template-rows: auto auto; text-align: left; align-items: center; }
  .age-number { grid-row: 1 / 3; }
  .age-label { margin: 0; }
  .hero-card { align-items: flex-start; }
  .mascot { font-size: 4rem; }
  .answers { grid-template-columns: repeat(3, 1fr); }
  .compare-boxes { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .compare-vs { transform: none; writing-mode: vertical-rl; }
}

@media (max-width: 430px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .brand span { display: none; }
  .hero-card { padding: 20px; }
  .question-card { border-radius: 24px; }
  .visual-area { min-height: 215px; }
  .answer-btn { min-height: 72px; border-radius: 18px; }
}


@media (max-width: 520px) {
  .topbar { gap: 8px; margin-bottom: 12px; }
  .brand { min-width: 0; padding: 7px 10px; }
  .brand-badge { width: 42px; height: 42px; }
  .icon-btn { width: 42px; height: 42px; border-radius: 14px; }
  .hero-card { gap: 12px; }
  .question-meta { gap: 5px; }
  .pill { min-height: 30px; padding: 5px 9px; font-size: .78rem; }
  .feedback { margin-top: 13px; font-size: 1.05rem; }
}

@media (max-width: 340px) {
  .app-shell { padding-left: 7px; padding-right: 7px; }
  .brand { padding: 5px 7px; }
  .brand-badge { width: 38px; height: 38px; font-size: .86rem; }
  .brand strong { font-size: .9rem; }
  .top-actions { gap: 5px; }
  .icon-btn { width: 38px; height: 38px; font-size: 1.15rem; }
  .hero-card { padding: 14px; border-radius: 23px; }
  .mascot { font-size: 3rem; }
  h1 { font-size: 1.65rem; }
  .age-card { grid-template-columns: 66px 1fr; padding: 12px; }
  .age-number { font-size: 3.5rem; }
  .answers { gap: 5px; }
  .answer-btn { border-radius: 15px; padding: 4px; }
  .question-card { padding-left: 9px; padding-right: 9px; }
  .question-meta { flex-wrap: wrap; }
}

@media (max-height: 720px) {
  .app-shell { padding-top: max(7px, env(safe-area-inset-top)); padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .topbar { margin-bottom: 8px; }
  .brand { padding-top: 5px; padding-bottom: 5px; }
  .brand-badge, .icon-btn { width: 40px; height: 40px; }
  .hero-card { padding: 14px 18px; border-radius: 25px; }
  .mascot { font-size: clamp(3rem, 10vmin, 4rem); }
  .hero-card h1 { font-size: clamp(1.55rem, 5.5vmin, 2.6rem); }
  .hero-copy p:last-child { font-size: .92rem; }
  .age-grid { gap: 10px; margin: 10px 0; }
  .age-card { min-height: 120px; padding: 12px; border-radius: 21px; }
  .age-number { font-size: 3.6rem; }
  .age-label { font-size: 1.05rem; margin-top: 4px; margin-bottom: 5px; }
  .age-card small { font-size: .78rem; }
  .primary-btn, .secondary-btn, .danger-btn { min-height: 42px; padding: 8px 15px; }
  .game-status { grid-template-columns: 40px 1fr auto; gap: 8px; margin-bottom: 7px; }
  .progress-wrap { height: 16px; padding: 3px; }
  .star-score { min-width: 72px; height: 40px; font-size: 1.05rem; }
  .question-card { min-height: max(0px, calc(var(--app-height, 100dvh) - 96px)); padding: 11px 14px; border-width: 3px; border-radius: 24px; }
  .question-meta { margin-bottom: 5px; }
  .question-card h2 { font-size: clamp(1.18rem, 4.2vmin, 1.9rem); margin-bottom: 5px; }
  .listen-btn { padding: 6px 12px; font-size: .84rem; }
  .visual-area { min-height: clamp(85px, 25dvh, 160px); padding: 5px 4px; }
  .compare-group { min-height: clamp(78px, 22dvh, 135px); padding: 7px; }
  .answer-btn { min-height: clamp(48px, 10dvh, 68px); border-radius: 17px; box-shadow: 0 6px 0 #e5bc32; }
  .answer-btn.correct { box-shadow: 0 6px 0 #70bf82; }
  .answer-btn.wrong { box-shadow: 0 6px 0 #df8a8a; }
  .feedback { min-height: 23px; margin-top: 9px; font-size: .96rem; }
  .result-card, .panel-card { padding: 20px; }
  .result-emoji { font-size: 4rem; }
  .result-card h2 { font-size: 2.2rem; }
  .big-score { margin: 8px 0 12px; padding: 12px 27px; }
  .big-score span { font-size: 2.7rem; }
  .award-row { min-height: 44px; margin-bottom: 14px; font-size: 1.9rem; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app-shell { padding: max(4px, env(safe-area-inset-top)) 9px max(7px, env(safe-area-inset-bottom)); }
  .topbar { margin-bottom: 4px; }
  .brand { padding: 3px 8px; border-radius: 13px; }
  .brand-badge { width: 34px; height: 34px; border-radius: 10px; font-size: .75rem; }
  .brand strong { font-size: .82rem; }
  .brand span { font-size: .7rem; }
  .icon-btn { width: 34px; height: 34px; border-radius: 11px; font-size: 1rem; }
  .hero-card { min-height: 66px; gap: 10px; padding: 8px 13px; border-width: 3px; border-radius: 19px; }
  .mascot { font-size: 2.7rem; }
  .eyebrow { margin-bottom: 2px; font-size: .63rem; }
  .hero-card h1 { margin-bottom: 3px; font-size: clamp(1.25rem, 5vmin, 1.85rem); }
  .hero-copy p:last-child { font-size: .72rem; }
  .age-grid { gap: 7px; margin: 7px 0; }
  .age-card { min-height: 82px; padding: 7px; border-radius: 16px; border-bottom-width: 7px !important; }
  .age-number { font-size: 2.8rem; }
  .age-label { font-size: .88rem; margin: 2px 0; }
  .age-card small { font-size: .64rem; line-height: 1.15; }
  .home-actions { gap: 7px; }
  .primary-btn, .secondary-btn, .danger-btn { min-height: 34px; padding: 5px 11px; border-radius: 12px; font-size: .76rem; }
  .game-status { grid-template-columns: 34px 1fr auto; gap: 6px; margin-bottom: 4px; }
  .progress-wrap { height: 13px; }
  .star-score { min-width: 62px; height: 34px; border-radius: 11px; font-size: .9rem; }
  .question-card { min-height: max(0px, calc(var(--app-height, 100dvh) - 78px)); padding: 7px 10px; border-radius: 18px; }
  .question-meta { margin-bottom: 2px; }
  .pill { min-height: 22px; padding: 3px 7px; font-size: .63rem; }
  .question-card h2 { margin-bottom: 2px; font-size: clamp(1rem, 4vmin, 1.35rem); }
  .listen-btn { padding: 4px 9px; font-size: .68rem; }
  .visual-area { min-height: clamp(62px, 22dvh, 105px); padding: 2px; }
  .count-object { font-size: clamp(1.25rem, 6vmin, 2.4rem); }
  .object-grid.dense .count-object { font-size: clamp(1.05rem, 5vmin, 1.9rem); }
  .object-grid.very-dense .count-object { font-size: clamp(.92rem, 4.3vmin, 1.65rem); }
  .math-expression { font-size: clamp(1.8rem, 9vmin, 3.4rem); }
  .sequence { gap: 6px; }
  .sequence span { min-width: 39px; padding: 5px; border-radius: 11px; font-size: clamp(1.3rem, 6vmin, 2rem); }
  .compare-group { min-height: clamp(58px, 20dvh, 92px); padding: 4px; gap: 3px; border-radius: 13px; }
  .compare-group .count-object { font-size: clamp(.9rem, 4vmin, 1.55rem); }
  .compare-vs { font-size: .67rem; }
  .answers { gap: 6px; }
  .answer-btn { min-height: clamp(42px, 11dvh, 55px); border-radius: 13px; font-size: clamp(1.3rem, 6vmin, 2.2rem); box-shadow: 0 4px 0 #e5bc32; }
  .answer-btn.correct { box-shadow: 0 4px 0 #70bf82; }
  .answer-btn.wrong { box-shadow: 0 4px 0 #df8a8a; }
  .feedback { min-height: 17px; margin-top: 5px; font-size: .76rem; }
}

@media (orientation: landscape) and (max-height: 400px) {
  .brand span { display: none; }
  .question-card { padding-top: 5px; padding-bottom: 5px; }
  .visual-area { min-height: 54px; }
  .feedback { margin-top: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

@media print {
  body { background: white; }
  body::after, .cloud, .topbar, .report-actions { display: none !important; }
  .app-shell { width: 100%; padding: 0; }
  .screen { display: none !important; }
  #reportScreen { display: block !important; }
  .panel-card { box-shadow: none; border: 0; max-width: none; }
}

/* Final safety rules for very narrow embeds and browser game portals. */
.hero-card, .question-card, .result-card, .panel-card,
.age-grid, .game-status, .answers, .visual-area {
  max-width: 100%;
  min-width: 0;
}
.hero-copy, .panel-heading > div, .age-card, .answer-btn {
  min-width: 0;
}
.hero-copy, .age-card small, .question-card h2, .feedback, .report-item {
  overflow-wrap: anywhere;
}
.compare-group.dense .count-object {
  font-size: clamp(.95rem, 3.8vmin, 2.15rem);
}
