/* Shared styles for Math Pokemon app */

:root {
    --poke-yellow: #FFDE00;
    --poke-blue: #3B4CCA;
    --poke-red: #CC0000;
    --sky: #e0f2fe;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --nav-h: 4.5rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Fredoka', sans-serif;
    background-color: var(--sky);
    background-image: radial-gradient(#bae6fd 20%, transparent 20%), radial-gradient(#bae6fd 20%, transparent 20%);
    background-position: 0 0, 25px 25px;
    background-size: 50px 50px;
    margin: 0;
    min-height: 100dvh;
    padding:
        calc(0.75rem + var(--safe-top))
        calc(0.75rem + var(--safe-right))
        calc(var(--nav-h) + 1rem + var(--safe-bottom))
        calc(0.75rem + var(--safe-left));
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

@media (min-width: 768px) {
    body {
        padding:
            calc(1.25rem + var(--safe-top))
            calc(1.5rem + var(--safe-right))
            calc(var(--nav-h) + 1.5rem + var(--safe-bottom))
            calc(1.5rem + var(--safe-left));
    }
}

.app-shell {
    width: 100%;
    max-width: 56rem;
    margin: 0 auto;
}

.app-card {
    background: #fff;
    border-radius: 1.5rem;
    border: 4px solid #facc15;
    box-shadow: 0 20px 40px rgba(59, 76, 202, 0.12);
    padding: 1rem;
    text-align: center;
    position: relative;
    width: 100%;
    min-width: 0;
    overflow: visible;
}

@media (min-width: 640px) {
    .app-card {
        padding: 1.5rem;
        border-radius: 1.75rem;
    }
}

@media (min-width: 768px) {
    .app-card {
        padding: 2rem 2.5rem;
    }
}

@media (min-width: 1024px) {
    .app-card {
        padding: 2.5rem 3rem;
        max-width: 58rem;
    }
}

/* Kid-friendly bottom tab nav */
.app-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    padding:
        0.55rem 0.75rem
        calc(0.55rem + var(--safe-bottom));
    padding-left: calc(0.75rem + var(--safe-left));
    padding-right: calc(0.75rem + var(--safe-right));
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 3px solid #fde047;
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
}

.app-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: 3.4rem;
    padding: 0.45rem 0.5rem;
    border-radius: 1rem;
    border: 3px solid transparent;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.8rem;
    color: #64748b;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    -webkit-user-select: none;
    user-select: none;
}

.app-nav a .nav-icon {
    font-size: 1.35rem;
    line-height: 1;
}

.app-nav a:active {
    transform: scale(0.96);
}

.app-nav a.is-active {
    background: #FFDE00;
    border-color: #3B4CCA;
    color: #1e3a8a;
    box-shadow: 0 4px 0 rgba(59, 76, 202, 0.2);
}

.app-nav a:not(.is-active):hover {
    background: #f1f5f9;
    color: #3B4CCA;
}

@media (min-width: 768px) {
    .app-nav {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(28rem, calc(100% - 2rem));
        bottom: calc(0.75rem + var(--safe-bottom));
        border: 3px solid #fde047;
        border-radius: 1.5rem;
        padding: 0.55rem;
        box-shadow: 0 12px 32px rgba(15, 23, 42, 0.15);
    }

    .app-nav a {
        font-size: 0.95rem;
        min-height: 3.6rem;
        flex-direction: row;
        gap: 0.5rem;
        border-radius: 1.15rem;
    }

    .app-nav a .nav-icon {
        font-size: 1.25rem;
    }
}

.poke-yellow { background-color: var(--poke-yellow); }
.poke-blue { color: var(--poke-blue); }
.poke-red { background-color: var(--poke-red); }

.touch-btn {
    min-height: 3rem;
    touch-action: manipulation;
}

.number-input {
    appearance: none;
    -moz-appearance: textfield;
    text-align: center;
    font-size: 2rem;
}
.number-input::-webkit-outer-spin-button,
.number-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

@media (min-width: 768px) {
    .number-input {
        font-size: 2.5rem;
    }
}

/* Intelligent aligned multiplication grid */
.poke-grid-scroll {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x pan-y;
    padding-bottom: 0.45rem;
    scrollbar-width: thin;
    scrollbar-color: #f59e0b #fef3c7;
}

.poke-grid-scroll::-webkit-scrollbar { height: 8px; }
.poke-grid-scroll::-webkit-scrollbar-track {
    background: #fef3c7;
    border-radius: 999px;
}
.poke-grid-scroll::-webkit-scrollbar-thumb {
    background: #f59e0b;
    border-radius: 999px;
}

.align-board {
    --cell-size: 56px;
    --cell-gap: 0.35rem;
    --track-pad: 0.4rem;
    --gutter: 2.5rem;
    --sum-col: 3.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    width: max-content;
    min-width: 100%;
    padding-right: 0.15rem;
}

.align-board.is-large {
    --cell-size: 68px;
    --sum-col: 4.25rem;
}

.align-board.is-xlarge {
    --cell-size: 78px;
    --sum-col: 4.5rem;
}

.align-board.is-compact {
    --cell-size: 48px;
    --sum-col: 3.5rem;
}

.align-row {
    display: grid;
    grid-template-columns: var(--gutter) max-content var(--sum-col);
    gap: 0.5rem;
    align-items: center;
    width: max-content;
    min-width: 100%;
}

.align-gutter {
    display: flex;
    align-items: center;
    justify-content: center;
    position: sticky;
    left: 0;
    z-index: 3;
    background: #fff;
}

.align-track {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: var(--track-pad);
    border-radius: 0.9rem;
    box-sizing: border-box;
}

.align-track.is-ruler {
    background: transparent;
    border: 3px solid transparent;
    padding-bottom: 0;
}

.align-track.is-owner {
    background: rgba(254, 252, 232, 0.95);
    border: 3px solid #f59e0b;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65);
}

.align-track-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: #1e40af;
    text-align: left;
    line-height: 1.2;
    margin: 0 0 0.15rem;
    padding-left: 0.1rem;
}

.align-cells {
    display: grid;
    grid-template-columns: repeat(var(--cells), var(--cell-size));
    gap: var(--cell-gap);
    align-items: center;
    justify-items: center;
}

.align-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
}

.align-cell.is-num {
    height: auto;
    min-height: 1.4rem;
    font-weight: 800;
    font-size: clamp(0.9rem, 2.8vw, 1.15rem);
    color: #dc2626;
    font-family: 'Fredoka', sans-serif;
}

.align-board .poke-sprite {
    width: calc(var(--cell-size) - 8px);
    max-width: calc(var(--cell-size) - 8px);
    height: auto;
    flex: none;
}

.align-sum {
    position: sticky;
    right: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    min-width: var(--sum-col);
    min-height: 2.75rem;
    padding: 0.35rem 0.4rem;
    border-radius: 0.85rem;
    background: #fff1f2;
    border: 3px solid #f87171;
    color: #b91c1c;
    box-shadow: -6px 0 10px rgba(255, 255, 255, 0.9);
    font-family: 'Fredoka', sans-serif;
}

.align-sum-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: #e11d48;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    line-height: 1;
}

.align-sum-value {
    font-size: clamp(1.15rem, 4vw, 1.55rem);
    font-weight: 800;
    line-height: 1;
}

.align-sum.is-header {
    background: #fff7ed;
    border-color: #fdba74;
    color: #c2410c;
    min-height: 2.1rem;
}

.align-sum.is-header .align-sum-value {
    font-size: 0.85rem;
    font-weight: 800;
}

.side-num.is-owner {
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 999px;
    background: #dbeafe;
    color: #1e40af;
    font-size: 1rem;
    font-weight: 800;
    border: 2px solid #93c5fd;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Columns orientation: owners as vertical tracks */
.align-board.is-cols {
    display: grid;
    grid-template-columns: var(--gutter) repeat(var(--owners), max-content);
    grid-auto-rows: auto;
    gap: 0.45rem 0.5rem;
    align-items: start;
    width: max-content;
    min-width: 100%;
}

.align-board.is-cols .col-owner-head {
    display: flex;
    justify-content: center;
    position: sticky;
    top: 0;
}

.align-board.is-cols .col-track {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: var(--track-pad);
    background: rgba(254, 252, 232, 0.95);
    border: 3px solid #f59e0b;
    border-radius: 0.9rem;
    width: calc(var(--cell-size) + (var(--track-pad) * 2));
    box-sizing: border-box;
}

.align-board.is-cols .col-cells {
    display: grid;
    grid-template-rows: repeat(var(--cells), var(--cell-size));
    gap: var(--cell-gap);
    justify-items: center;
    align-items: center;
}

.align-board.is-cols .item-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: var(--track-pad);
    box-sizing: border-box;
}

.align-board.is-cols .item-side .align-cell.is-num {
    width: var(--cell-size);
    height: var(--cell-size);
}

.align-board.is-cols .col-sum {
    margin-top: 0.15rem;
}

.array-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem 1.25rem;
    margin-top: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    width: 100%;
}

.array-legend span strong { color: #1e40af; }
.array-legend .legend-total strong { color: #b91c1c; }

.rotate-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.75rem;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    border: 3px solid #93c5fd;
    background: #eff6ff;
    color: #1e40af;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.15s ease, background 0.15s ease;
}

.rotate-btn:active { transform: scale(0.96); }

.rotate-btn .rotate-icon {
    display: inline-block;
    transition: transform 0.35s ease;
    font-size: 1.1rem;
}

.rotate-btn.is-rotated .rotate-icon {
    transform: rotate(90deg);
}

.orient-hint {
    font-size: 0.75rem;
    font-weight: 700;
    color: #64748b;
    margin-top: 0.35rem;
}

/* Family-friendly UI helpers */
.parent-tip {
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
    text-align: left;
    background: linear-gradient(135deg, #eff6ff, #fefce8);
    border: 2px solid #bfdbfe;
    border-radius: 1rem;
    padding: 0.75rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    line-height: 1.35;
}

.parent-tip .tip-icon {
    flex-shrink: 0;
    font-size: 1.25rem;
    line-height: 1;
}

.step-block {
    margin-bottom: 1.1rem;
    padding: 0.85rem 0.75rem;
    border-radius: 1.15rem;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
}

.step-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    background: #3B4CCA;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 700;
    flex-shrink: 0;
}

.step-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

.stepper {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.stepper-btn {
    width: 3rem;
    height: 3rem;
    border-radius: 999px;
    border: 3px solid #3B4CCA;
    background: #FFDE00;
    color: #1e3a8a;
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 0 rgba(59, 76, 202, 0.25);
}

.stepper-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

.stepper-btn.is-red {
    border-color: #b91c1c;
    background: #fecaca;
    color: #7f1d1d;
    box-shadow: 0 3px 0 rgba(185, 28, 28, 0.2);
}

.stepper .number-input {
    width: 4.25rem;
    height: 3.25rem;
    border-radius: 0.9rem;
    border: 3px solid #93c5fd;
    font-size: 1.75rem;
    font-weight: 700;
    color: #0f172a;
}

.stepper.is-red .number-input {
    border-color: #fca5a5;
}

.primary-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 22rem;
    min-height: 3.5rem;
    padding: 0.85rem 1.25rem;
    border-radius: 999px;
    border: 4px solid #3B4CCA;
    background: #FFDE00;
    color: #1e3a8a;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    box-shadow: 0 6px 0 rgba(59, 76, 202, 0.28);
    cursor: pointer;
    touch-action: manipulation;
}

.primary-cta:active {
    transform: translateY(3px);
    box-shadow: 0 3px 0 rgba(59, 76, 202, 0.28);
}

.primary-cta.is-reveal {
    background: #CC0000;
    color: #fff;
    border-color: #facc15;
    box-shadow: 0 6px 0 rgba(127, 29, 29, 0.25);
}

.more-options {
    margin-top: 0.75rem;
    border-radius: 1rem;
    border: 2px dashed #cbd5e1;
    background: #fff;
    overflow: hidden;
    text-align: left;
}

.more-options > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.75rem 1rem;
    font-weight: 700;
    font-size: 0.9rem;
    color: #475569;
    touch-action: manipulation;
    user-select: none;
}

.more-options > summary::-webkit-details-marker {
    display: none;
}

.more-options > summary::before {
    content: '▸ ';
    color: #3B4CCA;
}

.more-options[open] > summary::before {
    content: '▾ ';
}

.more-options .more-body {
    padding: 0 0.85rem 0.9rem;
}

.scroll-hint {
    font-size: 0.75rem;
    font-weight: 700;
    color: #64748b;
    margin: 0.35rem 0 0;
}

.eq-big {
    font-size: clamp(1.6rem, 7vw, 2.75rem);
    font-weight: 700;
    color: #0f172a;
}

.app-nav a span:last-child {
    font-size: 0.78rem;
}

@media (min-width: 768px) {
    .app-nav a span:last-child {
        font-size: 0.95rem;
    }
    .primary-cta {
        font-size: 1.35rem;
        min-height: 3.75rem;
    }
}
