/* Styling for the Math Games page. Self-contained (does not rely on
   uncompiled Tailwind utilities) so the games look right on every screen. */

#math-games-root {
    --mg-ink: #2a2622;
    --mg-line: rgba(0, 0, 0, 0.08);
}

/* ---------- Practice / Challenge mode toolbar ---------- */
.mg-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.mg-mode-hint {
    font-size: 0.95rem;
    color: #6b6258;
}
.mg-modebar {
    display: inline-flex;
    padding: 4px;
    background: #efe9e2;
    border-radius: 999px;
    gap: 2px;
}
.mg-mode-btn {
    border: none;
    background: transparent;
    color: #6b6258;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-mode-btn:hover { color: var(--mg-ink); }
.mg-mode-btn.active {
    background: #fff;
    color: var(--mg-ink);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.mg-stage-mode {
    margin-left: auto;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    white-space: nowrap;
}
.mg-stage-mode.is-practice { background: #e8f3ea; color: #2f7d4f; }
.mg-stage-mode.is-challenge { background: #fdeede; color: #b46a16; }
.mg-stage-mode.is-voice { background: #eef4ff; color: #2f5fd0; margin-left: 0.4rem; }

/* ---------- Voice mode toggle ---------- */
.mg-voice-toggle {
    border: 1px solid var(--mg-line);
    background: #fff;
    color: var(--mg-ink);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.5rem 0.95rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.18s ease, box-shadow 0.18s ease, color 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-voice-toggle:hover:not(:disabled) { box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12); }
.mg-voice-toggle.is-on {
    background: #eef4ff;
    border-color: #b9d0ff;
    color: #2f5fd0;
}
.mg-voice-toggle:disabled { opacity: 0.55; cursor: default; }
.mg-voice-hint {
    flex-basis: 100%;
    font-size: 0.9rem;
    color: #6b6258;
    margin-top: 0.25rem;
}
.mg-voice-hint.is-hidden { display: none; }

.mg-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}
.mg-lb-open {
    border: 1px solid var(--mg-line);
    background: #fff;
    color: var(--mg-ink);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.5rem 0.95rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.18s ease, box-shadow 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-lb-open:hover { background: #faf7f2; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); }
.mg-lb-open:active { transform: scale(0.97); }

/* ---------- Leaderboards ---------- */
.mg-lb-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}
.mg-lb-tab {
    border: 1px solid var(--mg-line);
    background: #fff;
    color: #6b6258;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-lb-tab:hover { color: var(--mg-ink); }
.mg-lb-tab.active {
    background: var(--mg-ink);
    border-color: var(--mg-ink);
    color: #fff;
}
.mg-lb-board { width: 100%; max-width: 460px; }
.mg-lb-loading, .mg-lb-empty {
    text-align: center;
    color: #6b6258;
    padding: 1.5rem 0;
}
.mg-lb-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.mg-lb-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.9rem;
    background: #fff;
    border: 1px solid var(--mg-line);
    border-radius: 0.7rem;
}
.mg-lb-row.is-you {
    background: #fff6e6;
    border-color: #f0c46b;
    box-shadow: 0 2px 8px rgba(214, 158, 46, 0.18);
}
.mg-lb-rank {
    flex: 0 0 2rem;
    text-align: center;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--mg-ink);
}
.mg-lb-name {
    flex: 1 1 auto;
    font-weight: 600;
    color: var(--mg-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mg-lb-score {
    flex: 0 0 auto;
    font-weight: 800;
    color: #b46a16;
    font-variant-numeric: tabular-nums;
}

/* end-of-challenge actions + name entry */
.mg-done-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    justify-content: center;
}
.mg-btn-ghost {
    background: #fff;
    color: var(--mg-ink);
    border: 1px solid var(--mg-line);
}
.mg-lb-formwrap { width: 100%; max-width: 420px; }
.mg-lb-congrats {
    text-align: center;
    font-weight: 700;
    color: #2f7d4f;
    margin-bottom: 0.6rem;
}
.mg-lb-form {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}
.mg-lb-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--mg-line);
    border-radius: 0.6rem;
    font-size: 1rem;
    font-family: inherit;
}
.mg-lb-input:focus {
    outline: none;
    border-color: #f0c46b;
    box-shadow: 0 0 0 3px rgba(240, 196, 107, 0.3);
}
.mg-lb-note {
    text-align: center;
    font-size: 0.85rem;
    color: #6b6258;
    margin-top: 0.4rem;
    min-height: 1rem;
}
.mg-lb-note.bad { color: #b3261e; }


.mg-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
    align-items: start;
}
.mg-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: 0.4rem;
    padding: 1.5rem;
    min-height: 190px;
    border: 1px solid transparent;
    border-radius: 1rem;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-card:hover,
.mg-card:focus-visible {
    transform: translateY(-4px);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.18);
    outline: none;
    border-color: #f0c46b; /* subtle gold highlight on hover */
}
.mg-card:active {
    transform: translateY(-1px) scale(0.99);
}
.mg-card-emoji {
    font-size: 2.75rem;
    line-height: 1;
}
.mg-card-title {
    font-family: "Playfair Display", serif;
    font-size: 1.4rem;
    font-weight: 700;
}
.mg-card-desc {
    font-size: 0.9rem;
    opacity: 0.92;
}
.mg-card-play {
    margin-top: auto;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    background: rgba(255, 255, 255, 0.22);
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
}

/* Per-game accent colors */
.mg-c-add   { background: linear-gradient(150deg, #7ba428, #5d7e1c); }
.mg-c-sub   { background: linear-gradient(150deg, #e98b6e, #d2664a); }
.mg-c-ten   { background: linear-gradient(150deg, #5697cf, #3d72ad); }
.mg-c-skip  { background: linear-gradient(150deg, #9b78be, #7a559e); }
.mg-c-times { background: linear-gradient(150deg, #e8b15f, #cf8f3a); }
.mg-c-puzzle { background: linear-gradient(150deg, #d96fa6, #b34a83); }

/* ---------- Expanded game stage ---------- */
.mg-stage {
    width: 100%;
}
.mg-stage-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.mg-back {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.6rem 1.1rem;
    border: 1px solid var(--mg-line);
    background: #fff;
    color: var(--mg-ink);
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color 0.18s ease, transform 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-back:hover { background: #f3efe9; }
.mg-back:active { transform: scale(0.97); }
.mg-stage-title {
    font-family: "Playfair Display", serif;
    font-size: clamp(1.5rem, 3vw, 2.1rem);
    font-weight: 700;
    color: var(--mg-ink);
}

.mg-stage-body {
    position: relative;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 1.5rem;
    padding: 1.5rem;
    background: #faf8f5;
    border: 1px solid var(--mg-line);
    border-radius: 1.25rem;
}

/* ---------- Challenge "3..2..1..Go!" countdown intro ---------- */
/* A small, transparent badge in the top-left corner so the question stays
   fully visible while the countdown runs. */
.mg-countdown {
    position: absolute;
    top: 0.5rem;
    left: 0.9rem;
    z-index: 20;
    pointer-events: none;
}
.mg-countdown-num {
    font-family: "Playfair Display", "Inter", serif;
    font-weight: 800;
    font-size: clamp(2.75rem, 10vw, 5rem);
    line-height: 1;
    color: var(--mg-ink);
    opacity: 0.62;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
}
.mg-countdown-num.is-go {
    color: #2f7d4f;
    opacity: 0.72;
}
.mg-countdown-pop {
    animation: mg-countdown-pop 0.6s ease-out;
}
@keyframes mg-countdown-pop {
    0%   { transform: scale(0.4); opacity: 0; }
    35%  { transform: scale(1.15); opacity: 0.7; }
    60%  { transform: scale(1); }
    100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    .mg-countdown-pop { animation-duration: 0.01s; }
}
.mg-progress {
    position: relative;
    font-weight: 600;
    color: #6b6258;
    letter-spacing: 0.01em;
}
.mg-progress.mg-timer { display: inline-block; }
.mg-timebonus {
    position: absolute;
    left: 100%;
    top: 50%;
    margin-left: 0.5rem;
    transform: translateY(-50%);
    color: #2f7d4f;
    font-weight: 800;
    font-size: 1rem;
    white-space: nowrap;
    pointer-events: none;
    animation: mg-bonus-float 1s ease-out forwards;
}
.mg-bonus-pulse { animation: mg-timer-pulse 0.5s ease; }
@keyframes mg-bonus-float {
    0% { opacity: 0; transform: translateY(-50%) translateX(-0.3rem) scale(0.7); }
    25% { opacity: 1; transform: translateY(-90%) translateX(0) scale(1.15); }
    100% { opacity: 0; transform: translateY(-180%) translateX(0.2rem) scale(1); }
}
@keyframes mg-timer-pulse {
    0% { transform: scale(1); }
    35% { transform: scale(1.16); color: #2f7d4f; }
    100% { transform: scale(1); }
}
.mg-stars {
    font-size: 1.4rem;
    letter-spacing: 0.15rem;
    min-height: 1.6rem;
}
.mg-prompt {
    font-family: "Playfair Display", serif;
    font-weight: 700;
    color: var(--mg-ink);
    font-size: clamp(2rem, 6vw, 3.4rem);
    text-align: center;
    line-height: 1.15;
}
.mg-prompt small {
    display: block;
    font-family: "Inter", sans-serif;
    font-weight: 500;
    font-size: 1.1rem;
    color: #6b6258;
    margin-top: 0.5rem;
}

/* Word problems need readable paragraph-sized text, not the giant numerals. */
.mg-word {
    display: block;
    font-family: "Crimson Pro", serif;
    font-weight: 500;
    font-size: clamp(1.25rem, 2.6vw, 1.7rem);
    line-height: 1.45;
    color: var(--mg-ink);
    max-width: 640px;
    margin: 0 auto;
}

.mg-choices {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 1rem;
    width: 100%;
    max-width: 520px;
}
.mg-choice {
    font-family: "Playfair Display", serif;
    font-size: clamp(1.8rem, 5vw, 2.6rem);
    font-weight: 700;
    color: var(--mg-ink);
    background: #fff;
    border: 2px solid var(--mg-line);
    border-radius: 1rem;
    min-height: 92px;
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.18s ease,
        border-color 0.18s ease, color 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-choice:hover { border-color: #c9a96a; }
.mg-choice:active { transform: scale(0.96); }
.mg-choice.correct {
    background: #5d7e1c;
    border-color: #5d7e1c;
    color: #fff;
    animation: mg-pop 0.35s ease;
}
.mg-choice.wrong {
    background: #f6d6cd;
    border-color: #d2664a;
    color: #a23c22;
    animation: mg-shake 0.35s ease;
}

.mg-feedback {
    min-height: 1.8rem;
    font-weight: 700;
    font-size: 1.25rem;
}
.mg-feedback.good { color: #5d7e1c; }
.mg-feedback.bad { color: #cf6a4a; }

/* dot array for the multiplication game */
.mg-array {
    display: inline-grid;
    gap: 0.6rem;
    padding: 1rem 1.25rem;
    background: #fff;
    border: 2px solid var(--mg-line);
    border-radius: 1rem;
}
.mg-array-row { display: flex; gap: 0.6rem; }
.mg-dot {
    width: clamp(18px, 4.5vw, 30px);
    height: clamp(18px, 4.5vw, 30px);
    border-radius: 50%;
    background: #e0a458;
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}

/* make-ten board */
.mg-board {
    display: grid;
    grid-template-columns: repeat(4, minmax(70px, 1fr));
    gap: 0.9rem;
    width: 100%;
    max-width: 560px;
}
.mg-tile {
    font-family: "Playfair Display", serif;
    font-size: clamp(1.8rem, 5vw, 2.6rem);
    font-weight: 700;
    color: var(--mg-ink);
    background: #fff;
    border: 2px solid var(--mg-line);
    border-radius: 1rem;
    min-height: 84px;
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.18s ease,
        border-color 0.18s ease, color 0.18s ease, opacity 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-tile:active { transform: scale(0.96); }
.mg-tile.sel {
    background: #5697cf;
    border-color: #3d72ad;
    color: #fff;
}
.mg-tile.hit {
    background: #5d7e1c;
    border-color: #5d7e1c;
    color: #fff;
    animation: mg-pop 0.35s ease;
}
.mg-tile.miss { animation: mg-shake 0.35s ease; }

/* win / done card */
.mg-done {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}
.mg-done-emoji { font-size: 4rem; line-height: 1; }
.mg-done-title {
    font-family: "Playfair Display", serif;
    font-size: clamp(1.8rem, 5vw, 2.6rem);
    font-weight: 800;
    color: var(--mg-ink);
}
.mg-done-score { font-size: 1.25rem; color: #6b6258; }
.mg-btn {
    padding: 0.85rem 1.6rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
    background: #6b8e23;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color 0.18s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}
.mg-btn:hover { background: #5d7e1c; }
.mg-btn:active { transform: scale(0.97); }

@keyframes mg-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}
@keyframes mg-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}
@media (prefers-reduced-motion: reduce) {
    .mg-choice, .mg-tile, .mg-card, .mg-back, .mg-btn { transition: none; }
    .mg-choice.correct, .mg-choice.wrong, .mg-tile.hit, .mg-tile.miss { animation: none; }
    .mg-timebonus { animation: none; opacity: 1; }
    .mg-bonus-pulse { animation: none; }
}

@media (max-width: 640px) {
    /* Make the play area fill the phone screen so the question, score/timer and
       answers are all visible without scrolling. math.css only loads on this
       page, so these overrides are scoped to the Patrick math page. */
    #root main.flex-grow > section.py-16 {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
    .text-center.mb-10 { margin-bottom: 1rem; }

    .mg-stage-bar { margin-bottom: 0.75rem; }

    .mg-stage-body {
        /* Fill the viewport below the fixed header + stage bar. dvh tracks the
           mobile browser's dynamic chrome; vh is the fallback. */
        min-height: calc(100vh - 9.5rem);
        min-height: calc(100dvh - 9.5rem);
        justify-content: space-evenly;
        gap: 0.75rem;
        padding: 1rem;
    }
    /* The end-of-game / leaderboard panels read better top-aligned than spread. */
    .mg-stage-body:has(.mg-done),
    .mg-stage-body:has(.mg-lb-tabs) {
        justify-content: flex-start;
        gap: 1.25rem;
    }
    .mg-choice { min-height: 72px; }
}

/* Phone held sideways: hide the top menu bar and snap the play area to fill the
   whole screen. Gated on short viewports so tablets/desktops are unaffected. */
@media (orientation: landscape) and (max-height: 600px) {
    #site-header { display: none !important; }
    #root main.flex-grow.pt-16 { padding-top: 0 !important; }
    #root main.flex-grow > section.py-16 {
        padding-top: 0.4rem;
        padding-bottom: 0.4rem;
    }
    /* Drop the page title/subtitle so the game owns the full screen. */
    .text-center.mb-10 { display: none; }

    .mg-stage-bar { margin-bottom: 0.4rem; }

    .mg-stage-body {
        min-height: calc(100vh - 4.5rem);
        min-height: calc(100dvh - 4.5rem);
        justify-content: space-evenly;
        gap: 0.4rem;
        padding: 0.6rem 1rem;
    }
    .mg-stage-body:has(.mg-done),
    .mg-stage-body:has(.mg-lb-tabs) {
        justify-content: flex-start;
        gap: 0.75rem;
    }
    /* Put all four answers on one row so they don't push the question off-screen. */
    .mg-choices {
        grid-template-columns: repeat(4, minmax(72px, 1fr));
        max-width: 760px;
        gap: 0.6rem;
    }
    .mg-choice { min-height: 56px; }
    .mg-prompt { font-size: clamp(1.8rem, 7vh, 3rem); }
}

@media (max-width: 480px) {
    .mg-board { grid-template-columns: repeat(3, minmax(64px, 1fr)); }
}
