:root {
    --ink: #22334d;
    --muted: #65748a;
    --paper: rgba(255, 255, 255, 0.94);
    --blue: #4988f2;
    --blue-soft: #dbe9ff;
    --yellow: #ffd761;
    --green: #36b77f;
    --coral: #f6786a;
    --shadow: 0 14px 30px rgba(39, 69, 112, 0.16);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    color: var(--ink);
    font-family: "Fredoka", system-ui, sans-serif;
    background: linear-gradient(180deg, #83d6ff 0%, #e4f7ff 55%, #b7e995 100%);
}

button, a { font: inherit; }
button { cursor: pointer; }

.sky { position: fixed; inset: 0; z-index: -2; overflow: hidden; pointer-events: none; }
.sun { position: absolute; top: 4vh; right: 8vw; font-size: clamp(2.6rem, 6vw, 5rem); }
.cloud { position: absolute; opacity: 0.78; font-size: clamp(2.5rem, 5vw, 4.4rem); animation: float 34s linear infinite; }
.cloud-one { top: 17vh; left: -10vw; }
.cloud-two { top: 30vh; left: -24vw; font-size: clamp(2rem, 4vw, 3.6rem); animation-duration: 48s; animation-delay: -12s; }
.hill { position: absolute; border-radius: 50% 50% 0 0; }
.hill-back { width: 130vw; height: 24vh; bottom: -10vh; left: -15vw; background: #88ce79; }
.hill-front { width: 150vw; height: 19vh; bottom: -12vh; left: -24vw; background: #5ab565; }
@keyframes float { from { transform: translateX(0); } to { transform: translateX(130vw); } }

.topbar {
    width: min(1100px, calc(100% - 32px));
    margin: 14px auto 8px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
}

.home-button, .sound-button, .replay-button, .learn-button {
    display: grid;
    place-items: center;
    border: 0;
    color: var(--ink);
    background: var(--paper);
    box-shadow: var(--shadow);
    text-decoration: none;
}
.home-button, .sound-button { width: 58px; height: 58px; border-radius: 17px; font-size: 1.65rem; }
.sound-button { background: #fff9dd; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.learn-button { min-height: 58px; padding: 0 18px; border-radius: 17px; color: #2b4f92; background: #e9f2ff; font-size: 1.1rem; font-weight: 700; }
.learn-button:active, .sound-button:active, .replay-button:active { transform: scale(0.96); }
.title-block { min-width: 0; }
.eyebrow { color: #3374d9; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
h1 { margin: 2px 0 0; font-size: clamp(1.65rem, 4vw, 2.75rem); line-height: 1.02; }
.practice-modes { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.mode-button { min-height: 35px; padding: 6px 11px; border: 2px solid rgba(255, 255, 255, 0.75); border-radius: 12px; color: #405b7f; background: rgba(255, 255, 255, 0.64); font-size: 0.88rem; font-weight: 700; }
.mode-button.active { border-color: var(--blue); color: #1f5eb9; background: #e7f0ff; box-shadow: 0 4px 10px rgba(49, 101, 181, 0.16); }
.mode-button:active { transform: scale(0.97); }

.game-shell { width: min(1100px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 12px; }
.prompt-panel {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 14px 18px;
    border: 4px solid rgba(255, 255, 255, 0.75);
    border-radius: 24px;
    background: var(--paper);
    box-shadow: var(--shadow);
}
.replay-button { width: 58px; height: 58px; border-radius: 50%; font-size: 1.45rem; background: var(--blue-soft); }
.replay-button:disabled { opacity: 0.45; cursor: not-allowed; }
.prompt-copy { min-width: 0; }
.round-count { margin: 0 0 2px; color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.instruction { margin: 0; font-size: clamp(1.25rem, 2.6vw, 1.8rem); line-height: 1.15; font-weight: 700; }
.trail { display: flex; align-items: center; gap: 5px; color: var(--blue); font-size: 1.1rem; }
.trail-step { color: var(--yellow); text-shadow: 0 1px 0 #c49222; }
.trail-arrow { color: #8da1b9; }

.choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: 18px; }
.choice-card {
    min-width: 0;
    min-height: 260px;
    padding: 10px;
    border: 4px solid rgba(255, 255, 255, 0.84);
    border-radius: 24px;
    color: var(--ink);
    background: var(--paper);
    box-shadow: var(--shadow);
    animation: arrive 360ms both ease-out;
    transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}
.choice-card:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }
.choice-card:not(.disabled):hover { transform: translateY(-4px); box-shadow: 0 19px 35px rgba(39, 69, 112, 0.22); }
.choice-card:not(.disabled):active { transform: translateY(2px) scale(0.98); }
.choice-card.correct { border-color: var(--green); background: #e8fff4; transform: scale(1.03); }
.choice-card.retry { border-color: var(--yellow); background: #fff9df; }
.choice-card.disabled {
  cursor: default;
  opacity: 0.38;
  filter: grayscale(0.82) saturate(0.3);
  transform: none;
}
.choice-card.disabled.correct {
  opacity: 1;
  filter: none;
}
.choice-card.teaching, .choice-card.disabled.teaching {
  border-color: var(--yellow);
  background: #fff9df;
  opacity: 1;
  filter: none;
  transform: translateY(-5px) scale(1.035);
  box-shadow: 0 0 0 5px rgba(255, 215, 97, 0.34), 0 19px 35px rgba(39, 69, 112, 0.22);
}
.choice-art { display: grid; place-items: center; height: 185px; overflow: hidden; border-radius: 16px; background: linear-gradient(145deg, #dbeeff, #f5fcff); }
.choice-art img { width: 100%; height: 100%; object-fit: cover; }
.choice-art.fallback { font-size: clamp(4.6rem, 8vw, 6.4rem); text-shadow: 0 8px 12px rgba(50, 80, 116, 0.16); }
.choice-label { display: block; margin: 10px 6px 3px; font-size: clamp(1rem, 2vw, 1.25rem); line-height: 1.05; font-weight: 700; }
@keyframes arrive { from { opacity: 0; transform: translateY(16px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }

.feedback { min-height: 2.2em; margin: 14px 8px 0; text-align: center; font-size: clamp(1.1rem, 2.2vw, 1.35rem); font-weight: 700; }
.feedback.good { color: #16865a; }
.feedback.retry-copy { color: #9b6900; }
.feedback.reminder { color: #3b67aa; }

.learn-panel { position: fixed; inset: 0; z-index: 12; display: none; place-items: center; padding: 20px; background: rgba(25, 47, 78, 0.54); backdrop-filter: blur(5px); }
.learn-panel.active { display: grid; }
.learn-card { position: relative; width: min(900px, 100%); padding: 24px 28px 28px; border: 5px solid white; border-radius: 30px; text-align: center; background: #fffdf6; box-shadow: 0 28px 72px rgba(20, 39, 66, 0.36); }
.learn-close { position: absolute; top: 13px; right: 15px; width: 44px; height: 44px; border: 0; border-radius: 50%; color: #64738b; background: #edf3fb; font-size: 2rem; line-height: 1; }
.learn-emoji { font-size: 3rem; }
.learn-kicker { margin: 2px 0 0; color: #3374d9; font-size: 0.86rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.learn-card h2 { margin: 4px 46px 6px; font-size: clamp(1.55rem, 3.6vw, 2.4rem); line-height: 1.08; }
.learn-copy { max-width: 660px; margin: 0 auto 17px; color: #4b5d75; font-size: clamp(1.08rem, 2.3vw, 1.4rem); font-weight: 600; }
.learn-example { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 176px; }
.learn-step { position: relative; width: min(25vw, 205px); aspect-ratio: 1.18; overflow: hidden; border: 4px solid #dce8f6; border-radius: 19px; background: #eaf4ff; box-shadow: 0 6px 14px rgba(41, 71, 111, 0.12); }
.learn-step.focus { border-color: var(--yellow); box-shadow: 0 0 0 5px rgba(255, 215, 97, 0.34), 0 9px 18px rgba(41, 71, 111, 0.16); transform: translateY(-4px); }
.learn-step img { width: 100%; height: 100%; object-fit: cover; }
.learn-step-marker { position: absolute; top: 8px; left: 8px; display: grid; place-items: center; width: 33px; height: 33px; border-radius: 50%; color: var(--ink); background: rgba(255, 255, 255, 0.94); font-size: 1.05rem; font-weight: 700; }
.learn-step.focus .learn-step-marker { background: var(--yellow); }
.learn-arrow { color: #6681a5; font-size: clamp(1.5rem, 4vw, 2.4rem); font-weight: 700; }
.learn-hint { margin: 13px 0 15px; color: #59708e; font-size: 1.05rem; font-weight: 700; }
.learn-actions { display: flex; justify-content: center; gap: 12px; }
.learn-play-button, .learn-try-button { min-height: 54px; padding: 10px 20px; border: 0; border-radius: 17px; color: var(--ink); font-weight: 700; font-size: 1.1rem; }
.learn-play-button { background: #e7f1ff; }
.learn-try-button { background: var(--yellow); box-shadow: 0 5px 0 #d6a83f; }
.learn-try-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #d6a83f; }

.finish, .loading { position: fixed; inset: 0; z-index: 10; display: none; place-items: center; padding: 22px; background: rgba(29, 48, 76, 0.45); backdrop-filter: blur(4px); }
.finish.active, .loading.active { display: grid; }
.finish-card, .loading-card { width: min(410px, 100%); padding: 30px; border-radius: 28px; text-align: center; background: white; box-shadow: 0 25px 70px rgba(23, 43, 70, 0.28); }
.finish-emoji, .loading-card span { display: block; font-size: 4rem; }
.finish-card h2 { margin: 6px 0; font-size: 2rem; }
.finish-card p { margin: 0 0 18px; font-size: 1.15rem; }
.finish-card button, .finish-card a { display: block; width: 100%; padding: 13px; border: 0; border-radius: 15px; color: var(--ink); background: var(--yellow); text-decoration: none; font-weight: 700; }
.finish-card a { margin-top: 10px; background: #e7f1ff; }
.loading { display: grid; background: rgba(235, 248, 255, 0.82); }
.loading:not(.active) { display: none; }
.loading-card { color: var(--ink); }

@media (max-width: 760px) {
    .topbar, .game-shell { width: min(100% - 20px, 620px); }
    .topbar { margin-top: 8px; gap: 8px; }
    .home-button, .sound-button { width: 48px; height: 48px; border-radius: 14px; font-size: 1.35rem; }
    .top-actions { gap: 6px; }
    .learn-button { min-height: 48px; padding: 0 12px; border-radius: 14px; font-size: 1rem; }
    .practice-modes { margin-top: 6px; gap: 5px; }
    .mode-button { min-height: 31px; padding: 4px 8px; border-radius: 10px; font-size: 0.76rem; }
    .prompt-panel { grid-template-columns: auto minmax(0, 1fr); padding: 11px; gap: 10px; }
    .trail { display: none; }
    .replay-button { width: 50px; height: 50px; }
    .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
    .choice-card { min-height: 178px; padding: 7px; border-radius: 18px; }
    .choice-art { height: 122px; border-radius: 12px; }
    .choice-label { margin: 7px 3px 2px; }
    .learn-card { padding: 20px 14px 18px; border-radius: 24px; }
    .learn-example { gap: 6px; min-height: 118px; }
    .learn-step { width: min(26vw, 165px); border-width: 3px; border-radius: 14px; }
    .learn-arrow { font-size: 1.3rem; }
    .learn-actions { gap: 8px; }
    .learn-play-button, .learn-try-button { min-height: 48px; padding: 8px 12px; border-radius: 14px; font-size: 1rem; }
}

@media (orientation: landscape) and (max-height: 650px) {
    .topbar { margin-top: 6px; }
    .home-button, .sound-button { width: 44px; height: 44px; }
    .learn-button { min-height: 44px; padding: 0 11px; }
    .learn-button span { display: none; }
    .prompt-panel { padding: 8px 12px; }
    .replay-button { width: 45px; height: 45px; }
    .choices { gap: 10px; margin-top: 10px; }
    .choice-card { min-height: 145px; }
    .choice-art { height: 92px; }
    .feedback { margin-top: 7px; min-height: 1.4em; }
    .practice-modes { margin-top: 4px; }
    .mode-button { min-height: 28px; padding: 3px 8px; font-size: 0.72rem; }
    .learn-card { width: min(760px, 100%); padding: 14px 20px 16px; }
    .learn-emoji { font-size: 2.1rem; }
    .learn-kicker { font-size: 0.72rem; }
    .learn-card h2 { margin-top: 2px; font-size: 1.55rem; }
    .learn-copy { margin-bottom: 9px; font-size: 1rem; }
    .learn-example { min-height: 104px; }
    .learn-step { width: min(20vw, 152px); }
    .learn-hint { margin: 8px 0; font-size: 0.94rem; }
    .learn-play-button, .learn-try-button { min-height: 43px; padding: 6px 13px; font-size: 0.96rem; }
}

/* iPad landscape: one calm, no-scroll learning surface. */
@media (min-width: 721px) and (max-width: 1366px) and (orientation: landscape) {
    html, body { height: 100dvh; min-height: 100dvh; overflow: hidden; }
    body { display: flow-root; }
    .topbar { margin: 10px auto 6px; }
    .game-shell { height: calc(100dvh - 148px); overflow: hidden; padding-bottom: 8px; }
    .prompt-panel { padding: 10px 14px; border-radius: 20px; }
    .replay-button { width: 50px; height: 50px; }
    .choices { margin-top: 12px; gap: 12px; }
    .choice-card { min-height: 0; padding: 8px; border-radius: 19px; }
    .choice-art { height: min(22dvh, 165px); }
    .choice-label { margin-top: 7px; font-size: 1rem; }
    .feedback { margin-top: 9px; font-size: 1.08rem; }
}
