/* ============================================================================
   DeeDee base styles
   Reset, typography, the .screen system, shared buttons, the shared game
   header (.gh), shared result stats, keyframes, focus and reduced motion.
   Game-specific rules live in css/<game>.css; the hub in css/hub.css.
   ============================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    color: var(--c-ink);
    background: var(--c-sky);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.45;
    overflow-x: hidden;
    position: relative;
}

img, svg, canvas { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--c-brand-dark); }
b, strong { font-weight: 800; }
h1, h2, h3 { line-height: 1.2; font-weight: 900; }

/* ---- Utilities ---- */
.hidden { display: none !important; }
.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---- Focus: one visible ring everywhere ---- */
:focus-visible {
    outline: 3px solid var(--c-focus);
    outline-offset: 3px;
}
.gh--dark :focus-visible,
.gh--dark:focus-visible { outline-color: #FFFFFF; }

/* ---- Celebration canvas (drawn over everything) ---- */
#celebrationCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

/* ---- Screens: the hub is a normal document; games are fixed, full-height layers ---- */
.screen {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    justify-content: center;
    align-items: center;
    padding: var(--sp-4);
    z-index: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: linear-gradient(180deg, var(--c-sky-top) 0%, var(--c-sky) 55%, var(--c-sky-bottom) 100%);
}
.screen.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

/* ---- DeeDee scene: the hub's sky with two grassy hills and a cloud.
   Add .scene to a game screen. Painted as backgrounds of the screen itself,
   so they sit behind every child and stay put while the screen scrolls. */
.screen.scene {
    padding-bottom: 72px;
    background:
        radial-gradient(60px 22px at 82% 12%, var(--c-cloud) 98%, transparent 100%),
        radial-gradient(42px 16px at 74% 13.5%, var(--c-cloud) 98%, transparent 100%),
        radial-gradient(48px 18px at 14% 22%, var(--c-cloud) 98%, transparent 100%),
        radial-gradient(75% 56px at 20% 100%, var(--c-grass) 98%, transparent 100%) bottom / 100% 56px no-repeat,
        radial-gradient(80% 76px at 85% 100%, var(--c-grass-light) 98%, transparent 100%) bottom / 100% 76px no-repeat,
        linear-gradient(180deg, var(--c-sky-top) 0%, var(--c-sky) 55%, var(--c-sky-bottom) 100%);
}

/* ---- Shared game header: Back · title · stat pills ----
   <header class="gh"><button class="btn-back">← Back</button><h2 class="gh-title">…</h2>
     <div class="gh-stats"><span class="gh-pill">⭐ <b>0</b></span></div></header>
   Add .gh--dark on dark game screens. */
.gh {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: var(--sp-2) 0;
    position: relative;
    z-index: 30;              /* above start/game-over overlays so Back always works */
    flex-shrink: 0;
}
.gh-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: var(--fs-lg);
    font-weight: 900;
    color: var(--c-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gh-stats {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-left: auto;
    flex-shrink: 0;
}
.gh-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 36px;
    padding: 4px 10px;
    border-radius: var(--r-pill);
    background: var(--c-surface);
    border: 2px solid var(--c-line);
    font-weight: 800;
    font-size: var(--fs-sm);
    color: var(--c-ink);
    white-space: nowrap;
}
.btn-back {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: var(--tap);
    min-width: var(--tap);
    padding: 0 var(--sp-4);
    border-radius: var(--r-pill);
    border: 2px solid var(--c-line);
    background: var(--c-surface);
    color: var(--c-ink);
    font-weight: 800;
    font-size: var(--fs-md);
    transition: background var(--t-fast), transform var(--t-fast);
}
.btn-back:hover { background: var(--c-surface-soft); }
.btn-back:active { transform: scale(0.96); }

/* Dark variant for the arcade (translucent on photos/canvas, light text) */
.gh--dark .gh-title { color: var(--c-ink-on-dark); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.gh--dark .gh-pill {
    background: rgba(0, 0, 0, 0.35);
    border-color: rgba(255, 255, 255, 0.35);
    color: var(--c-ink-on-dark);
}
.gh--dark .btn-back {
    background: rgba(0, 0, 0, 0.35);
    border-color: rgba(255, 255, 255, 0.45);
    color: var(--c-ink-on-dark);
}
.gh--dark .btn-back:hover { background: rgba(0, 0, 0, 0.5); }

/* Phones: the title drops to its own line so it never truncates; .gh--compact hides it (canvas games) */
@media (max-width: 520px) {
    .gh { flex-wrap: wrap; gap: 6px; }
    .gh-title { order: 3; flex: 1 1 100%; white-space: normal; font-size: var(--fs-md); padding: 0 4px; }
    .gh--compact .gh-title { display: none; }
    .btn-back { padding: 0 var(--sp-3); font-size: var(--fs-sm); }
    .gh-pill { padding: 4px 8px; font-size: var(--fs-xs); }
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: var(--tap);
    padding: 0.7rem 1.4rem;
    border: none;
    border-radius: var(--r-pill);
    font-weight: 900;
    font-size: var(--fs-lg);
    text-decoration: none;
    -webkit-user-select: none;
    user-select: none;
    transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.btn:active { transform: translateY(2px); }
.btn-play-again,
.btn-primary {
    background: linear-gradient(135deg, var(--c-grass-light), var(--c-success));
    color: var(--c-ink-on-dark);
    box-shadow: 0 4px 0 var(--c-success-dark);
}
.btn-play-again:active, .btn-primary:active { box-shadow: 0 2px 0 var(--c-success-dark); }
.btn-home,
.btn-secondary {
    background: var(--c-surface);
    color: var(--c-ink);
    border: 2px solid var(--c-line);
    box-shadow: 0 4px 0 var(--c-line);
}
.btn-home:active, .btn-secondary:active { box-shadow: 0 2px 0 var(--c-line); }
.results-buttons { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.results-buttons .btn { flex: 1 1 140px; }

/* ---- Shared result stats ---- */
.results-stats {
    display: flex;
    justify-content: center;
    gap: var(--sp-6);
    margin-bottom: var(--sp-6);
}
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-value { font-size: 2rem; font-weight: 900; color: var(--c-ink); line-height: 1.1; }
.stat-label { font-size: var(--fs-xs); color: var(--c-ink-soft); font-weight: 700; }

/* ---- Shared overlay card (start / game over / results) ---- */
.overlay-card {
    background: var(--c-surface);
    border-radius: var(--r-lg);
    border: 3px solid var(--c-line);
    padding: var(--sp-6) var(--sp-5);
    text-align: center;
    box-shadow: var(--sh-pop);
    width: 100%;
    max-width: 340px;
    animation: fadeIn 0.35s ease;
}
.overlay-card h2 { font-size: var(--fs-xl); margin: var(--sp-2) 0 var(--sp-2); }
.overlay-card p { color: var(--c-ink-soft); font-weight: 600; margin-bottom: var(--sp-4); }
.overlay-card .btn { margin: 0 auto; }

/* ---- Shared start / results overlay: scrim + .overlay-card + DeeDee ----
   <div class="game-overlay"><div class="overlay-card">
     <div class="overlay-hero"><img class="overlay-dog" …><span class="overlay-badge">🏆</span></div>
     <h2>…</h2><p>…</p><div class="results-buttons">…</div></div></div>
   z-index 20 keeps it under the screen's .gh header, so Back always works. */
.game-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    background: var(--c-scrim);
    z-index: 20;
    animation: fadeIn 0.3s ease;
}
.overlay-hero {
    position: relative;
    width: max-content;
    margin: calc(-1 * var(--sp-12)) auto var(--sp-1);
}
.overlay-dog {
    height: 104px;
    width: auto;
    transform-origin: 50% 90%;
    animation: mascotBounce 1.5s ease-in-out infinite;
    filter: drop-shadow(0 6px 10px rgba(26, 43, 74, 0.2));
}
.overlay-badge {
    position: absolute;
    right: -22px;
    bottom: 2px;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--c-surface);
    border: 3px solid var(--gold-line);
    font-size: 1.6rem;
    line-height: 1;
    box-shadow: var(--sh-card);
    animation: badgePop 0.5s 0.15s cubic-bezier(.17, .67, .3, 1.3) both;
}
.overlay-badge:empty { display: none; }
.overlay-card .results-stats { margin-bottom: var(--sp-5); }
.overlay-card .results-buttons { margin-top: var(--sp-2); flex-direction: column; }
.overlay-card .results-buttons .btn { flex: 0 0 auto; width: 100%; }
/* A card with DeeDee on top needs room for her to stand on it */
.overlay-card:has(.overlay-hero) { padding-top: var(--sp-2); margin-top: var(--sp-12); }

/* DeeDee's head (images/logo_deedee_icon.webp): trim a stray paw from its bottom-left corner */
.deedee-head { clip-path: polygon(0 0, 100% 0, 100% 100%, 8% 100%, 8% 82%, 0 82%); }

/* DeeDee reacts: a happy hop on a win / right answer, a puzzled tilt on a miss */
.deedee-happy { animation: deedeeHop 0.6s ease !important; }
.deedee-oops  { animation: deedeeTilt 0.6s ease !important; }
@keyframes deedeeHop {
    0%, 100% { transform: translateY(0) rotate(0); }
    35% { transform: translateY(-14px) rotate(-6deg); }
    65% { transform: translateY(-4px) rotate(4deg); }
}
@keyframes deedeeTilt {
    0%, 100% { transform: rotate(0); }
    30% { transform: rotate(-12deg); }
    70% { transform: rotate(8deg); }
}

/* ---- Keyframes shared by several games ---- */
@keyframes badgePop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes correctPop {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}
@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}
@keyframes mascotBounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-8px); }
}
@keyframes resultsBounce {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-5deg); }
    75% { transform: scale(1.1) rotate(5deg); }
}

/* ---- Respect "reduce motion" ---- */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
