/* ===== Global top controls / mobile-safe header ===== */
:root {
    --bna-header-offset: 4.5rem;
}

/* Reusable top-controls pattern: fixed bar that can wrap on small screens */
.bna-top-controls {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
    box-sizing: border-box;
}

/* Auth container: flex-wrap + gap so buttons can wrap to second line */
#hub-auth-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    align-items: center;
}

#hub-auth-controls > div {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* Pages with fixed header: content starts below the top controls */
#app-hub {
    padding-top: calc(var(--bna-header-offset) + env(safe-area-inset-top));
}

#app-container {
    padding-top: calc(var(--bna-header-offset) + env(safe-area-inset-top));
    box-sizing: border-box;
}

/* Small-screen breakpoint (<= 480px): auth buttons smaller, header can be two rows */
@media (max-width: 480px) {
    .bna-top-controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
        padding-top: calc(0.5rem + env(safe-area-inset-top));
        padding-left: calc(0.75rem + env(safe-area-inset-left));
        padding-right: calc(0.75rem + env(safe-area-inset-right));
    }

    #hub-auth-controls .control-button,
    #hub-auth-controls .font-semibold {
        padding: 0.4rem 0.6rem;
        font-size: 0.8125rem;
    }

    #hub-auth-controls > div {
        padding: 0.35rem 0.5rem;
        gap: 0.35rem;
    }

    #back-to-menu-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
        min-height: 44px;
    }

    /* Slightly more offset on very small screens if header wraps to 2 rows */
    :root {
        --bna-header-offset: 5rem;
    }
}

/* Base styles */
body {
    background: linear-gradient(135deg, #f0f9ff 0%, #e1f4ff 100%);
    min-height: 100vh;
    font-family: 'Nunito', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* In-game layout tweaks (e.g. Star Machine) */
body.in-game {
    overflow: hidden;
    background: #020617;
}

body.in-game .bna-top-controls {
    display: none;
}

body.hub-mode .bna-top-controls {
    display: none;
}

body.in-game #hub-auth-controls {
    display: none;
}

body.in-game #app-container {
    padding-top: 0;
}

body.in-game #back-to-menu-btn {
    display: none !important;
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    transform: none !important;
}

/* BNA login: password field (match username padding/height, icon inside on right) */
#bna-login-root .bna-password-wrap {
    position: relative;
}
/* Same padding as username (px-3 py-2); extra right so text doesn't overlap icon */
#bna-login-root .bna-password-input {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    padding-left: 0.75rem;
    padding-right: 2.75rem;
    box-sizing: border-box;
}
#bna-login-root .bna-password-toggle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 0 0.5rem 0.5rem 0;
    opacity: 0.85;
    transition: opacity 0.15s ease;
}
#bna-login-root .bna-password-toggle:hover {
    opacity: 1;
}
#bna-login-root .bna-password-toggle:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px rgb(99 102 241);
}
#bna-login-root .bna-password-toggle-icon {
    width: 1.25rem;
    height: 1.25rem;
    pointer-events: none;
}
@media (max-width: 360px) {
    #bna-login-root .bna-password-toggle {
        width: 40px;
        min-width: 40px;
        min-height: 44px;
    }
    #bna-login-root .bna-password-toggle-icon {
        width: 1.1rem;
        height: 1.1rem;
    }
    #bna-login-root .bna-password-input {
        padding-right: 2.5rem;
    }
}

/* Hide scrollbar */
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Hub carousel rows: allow vertical scroll to pass through */
.bna-hub-row {
    overflow-x: auto;
    overflow-y: visible;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.2s ease-in-out 2;
}

@keyframes sparkle {
    0% { transform: scale(0) rotate(0deg); opacity: 0; }
    50% { transform: scale(1.2) rotate(180deg); opacity: 1; }
    100% { transform: scale(1) rotate(360deg); opacity: 1; }
}

.feedback-icon {
    animation: sparkle 0.3s ease-out forwards;
}

@keyframes fillProgress {
    from { width: 0; }
    to { width: var(--progress-width); }
}

.progress-fill {
    animation: fillProgress 0.5s ease-out forwards;
}

/* Magical Item Effects */
@keyframes magicalGlow {
    0% { box-shadow: 0 0 10px rgba(147, 51, 234, 0.5), inset 0 0 5px rgba(147, 51, 234, 0.3); }
    50% { box-shadow: 0 0 20px rgba(147, 51, 234, 0.7), inset 0 0 10px rgba(147, 51, 234, 0.5); }
    100% { box-shadow: 0 0 10px rgba(147, 51, 234, 0.5), inset 0 0 5px rgba(147, 51, 234, 0.3); }
}

/* Rarity Colors */
.magical-item[data-rarity="common"] {
    box-shadow: 0 0 10px rgba(147, 51, 234, 0.5);
}

.magical-item[data-rarity="rare"] {
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.7);
    animation: magicalGlow 2s ease-in-out infinite;
}

/* Estimation Stone Effect */
@keyframes estimationGlow {
    0% { box-shadow: 0 0 10px rgba(59, 130, 246, 0.3); filter: brightness(1); }
    50% { box-shadow: 0 0 20px rgba(59, 130, 246, 0.7); filter: brightness(1.2); }
    100% { box-shadow: 0 0 10px rgba(59, 130, 246, 0.3); filter: brightness(1); }
}

.estimation-glow {
    animation: estimationGlow 1s ease-in-out infinite;
}

/* Abacus Animation */
@keyframes abacusSlide {
    0% { transform: translateX(-20px); opacity: 0; }
    20% { transform: translateX(0); opacity: 1; }
    80% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(20px); opacity: 0; }
}

.abacus-bead {
    animation: abacusSlide 1s ease-in-out forwards;
}

.magical-item {
    position: relative;
    background: linear-gradient(135deg, rgba(255,255,255,0.05), rgba(255,255,255,0.1));
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(4px);
    animation: magicalGlow 2s ease-in-out infinite;
    transition: all 0.3s ease;
}

.magical-item:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0.3));
}

.magical-item:active {
    transform: translateY(0);
}

/* Pattern Seeker's Compass Effect */
@keyframes compassSpin {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(90deg); }
    50% { transform: rotate(180deg); }
    75% { transform: rotate(270deg); }
    100% { transform: rotate(360deg); }
}

.compass-effect {
    position: absolute;
    width: 40px;
    height: 40px;
    pointer-events: none;
    animation: compassSpin 2s linear infinite;
}

/* Number Highlight Effect */
@keyframes numberHighlight {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.1); filter: brightness(1.5); }
    100% { transform: scale(1); filter: brightness(1); }
}

.highlight-number {
    animation: numberHighlight 1s ease-in-out;
}

/* Magical Sparkles */
@keyframes floatUp {
    0% { transform: translateY(0) rotate(0); opacity: 1; }
    100% { transform: translateY(-50px) rotate(360deg); opacity: 0; }
}

.magical-sparkle {
    position: absolute;
    pointer-events: none;
    animation: floatUp 1s ease-out forwards;
}

/* Hint Pulse Animation */
@keyframes hintPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(255, 255, 255, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

.hint-pulse {
    animation: hintPulse 1s ease-in-out infinite;
    z-index: 10;
}

/* Brand typography helpers */
.app-card-title,
h1,
h2,
h3,
h4,
h5,
h6,
.number-display,
.section-title {
    font-family: 'Fredoka', 'Fredoka One', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* Make the main counter a bit bolder but still soft */
.number-display {
    font-weight: 700;
    text-shadow: 0 1px 0 rgba(0,0,0,0.02), 0 2px 6px rgba(0,0,0,0.05);
}

/* Sensory speed slider */
.speed-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 14px;
    border-radius: 9999px;
    background: linear-gradient(90deg, rgba(59,130,246,0.15), rgba(147,51,234,0.15));
    outline: none;
    position: relative;
}
.speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 9999px;
    background: white;
    border: 2px solid rgba(147,51,234,0.6);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: transform 0.1s ease;
}
.speed-slider::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border-radius: 9999px;
    background: white;
    border: 2px solid rgba(147,51,234,0.6);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.speed-slider:active::-webkit-slider-thumb { transform: scale(1.05); }
.speed-slider:active::-moz-range-thumb { transform: scale(1.05); }

/* Gentle pulse ring used on speed change */
.pulse-ring {
    box-shadow: 0 0 0 0 rgba(147,51,234,0.35);
    animation: pulseRing 600ms ease-out;
}
@keyframes pulseRing {
    0% { box-shadow: 0 0 0 0 rgba(147,51,234,0.35); }
    100% { box-shadow: 0 0 0 16px rgba(147,51,234,0); }
}

@media (prefers-reduced-motion: reduce) {
    .pulse-ring { animation: none; }
}

/* Space background animation - realistic starfield (GPU accelerated) */
.space-background {
    background: radial-gradient(ellipse at 50% 100%, #1a1a2e 0%, #16213e 30%, #0f0f23 70%, #050510 100%);
    position: relative;
    overflow: hidden;
}

/* Video background - covers the entire container */
.space-video {
    position: absolute;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    transform: translate(-50%, -50%);
    object-fit: cover;
    z-index: 0;
    pointer-events: none;
    transition: filter 0.5s ease;
}

/* Add motion blur at warp speeds for extra effect */
.space-background.warp-mode .space-video {
    filter: blur(2px) brightness(1.2);
}

/* Warp streaks overlay at high speed */
.space-background.warp-mode::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 30%, rgba(100, 150, 255, 0.1) 70%);
    pointer-events: none;
    z-index: 1;
}

/* Hide CSS stars when video is playing */
.space-background.has-video .stars,
.space-background.has-video .stars2,
.space-background.has-video .stars3 {
    display: none;
}

/* Center the number display when cockpit is hidden */
#number-display-container {
    transition: all 0.5s ease;
}

#number-display-container.centered-mode {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
}

/* Subtle nebula glow */
.space-background::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        radial-gradient(ellipse 80% 50% at 20% 60%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse 60% 40% at 80% 30%, rgba(168, 85, 247, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse 50% 30% at 50% 80%, rgba(59, 130, 246, 0.05) 0%, transparent 50%);
    pointer-events: none;
}

.stars, .stars2, .stars3 {
    position: absolute;
    top: -100%;
    left: -100%;
    width: 300%;
    height: 300%;
    pointer-events: none;
    will-change: transform;
    transform: translateZ(0);
}

/* Layer 1: Dense small stars (background) */
.stars {
    background: transparent url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><circle cx="15" cy="25" r="0.4" fill="%23ffffff" opacity="0.4"/><circle cx="45" cy="12" r="0.3" fill="%23e0e7ff" opacity="0.5"/><circle cx="78" cy="45" r="0.5" fill="%23ffffff" opacity="0.6"/><circle cx="120" cy="18" r="0.3" fill="%23fef3c7" opacity="0.4"/><circle cx="155" cy="55" r="0.4" fill="%23ffffff" opacity="0.5"/><circle cx="185" cy="32" r="0.3" fill="%23e0e7ff" opacity="0.4"/><circle cx="25" cy="75" r="0.5" fill="%23ffffff" opacity="0.5"/><circle cx="60" cy="95" r="0.3" fill="%23fef3c7" opacity="0.4"/><circle cx="95" cy="68" r="0.4" fill="%23ffffff" opacity="0.6"/><circle cx="135" cy="88" r="0.3" fill="%23e0e7ff" opacity="0.5"/><circle cx="170" cy="72" r="0.4" fill="%23ffffff" opacity="0.4"/><circle cx="10" cy="130" r="0.3" fill="%23ffffff" opacity="0.5"/><circle cx="55" cy="145" r="0.4" fill="%23e0e7ff" opacity="0.4"/><circle cx="88" cy="125" r="0.3" fill="%23fef3c7" opacity="0.5"/><circle cx="125" cy="155" r="0.5" fill="%23ffffff" opacity="0.6"/><circle cx="165" cy="138" r="0.3" fill="%23ffffff" opacity="0.4"/><circle cx="192" cy="160" r="0.4" fill="%23e0e7ff" opacity="0.5"/><circle cx="35" cy="178" r="0.3" fill="%23ffffff" opacity="0.4"/><circle cx="72" cy="192" r="0.4" fill="%23fef3c7" opacity="0.5"/><circle cx="108" cy="175" r="0.3" fill="%23ffffff" opacity="0.6"/><circle cx="148" cy="188" r="0.4" fill="%23e0e7ff" opacity="0.4"/><circle cx="180" cy="195" r="0.3" fill="%23ffffff" opacity="0.5"/></svg>') repeat;
    background-size: 200px 200px;
    animation: starDrift1 120s ease-in-out infinite alternate;
}

/* Layer 2: Medium stars */
.stars2 {
    background: transparent url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300"><circle cx="30" cy="40" r="0.8" fill="%23ffffff" opacity="0.7"/><circle cx="90" cy="25" r="0.6" fill="%23bfdbfe" opacity="0.6"/><circle cx="150" cy="70" r="1" fill="%23ffffff" opacity="0.8"/><circle cx="220" cy="35" r="0.7" fill="%23fef9c3" opacity="0.7"/><circle cx="270" cy="80" r="0.6" fill="%23ffffff" opacity="0.6"/><circle cx="50" cy="120" r="0.9" fill="%23ffffff" opacity="0.7"/><circle cx="130" cy="140" r="0.6" fill="%23e0e7ff" opacity="0.6"/><circle cx="200" cy="110" r="0.8" fill="%23ffffff" opacity="0.8"/><circle cx="260" cy="150" r="0.7" fill="%23bfdbfe" opacity="0.6"/><circle cx="20" cy="200" r="0.6" fill="%23fef9c3" opacity="0.7"/><circle cx="80" cy="230" r="0.8" fill="%23ffffff" opacity="0.7"/><circle cx="160" cy="210" r="0.7" fill="%23ffffff" opacity="0.6"/><circle cx="240" cy="240" r="0.9" fill="%23e0e7ff" opacity="0.8"/><circle cx="290" cy="200" r="0.6" fill="%23ffffff" opacity="0.6"/><circle cx="45" cy="280" r="0.7" fill="%23ffffff" opacity="0.7"/><circle cx="120" cy="270" r="0.8" fill="%23bfdbfe" opacity="0.7"/><circle cx="190" cy="290" r="0.6" fill="%23ffffff" opacity="0.6"/><circle cx="270" cy="275" r="0.9" fill="%23fef9c3" opacity="0.8"/></svg>') repeat;
    background-size: 300px 300px;
    animation: starDrift2 180s ease-in-out infinite alternate;
}

/* Layer 3: Bright prominent stars (foreground) */
.stars3 {
    background: transparent url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400"><circle cx="50" cy="60" r="1.2" fill="%23ffffff" opacity="0.9"/><circle cx="50" cy="60" r="2.5" fill="%23ffffff" opacity="0.15"/><circle cx="150" cy="100" r="1" fill="%23bfdbfe" opacity="0.8"/><circle cx="150" cy="100" r="2" fill="%23bfdbfe" opacity="0.1"/><circle cx="280" cy="50" r="1.4" fill="%23ffffff" opacity="0.9"/><circle cx="280" cy="50" r="3" fill="%23ffffff" opacity="0.12"/><circle cx="350" cy="130" r="0.9" fill="%23fef9c3" opacity="0.85"/><circle cx="80" cy="200" r="1.1" fill="%23ffffff" opacity="0.85"/><circle cx="80" cy="200" r="2.2" fill="%23ffffff" opacity="0.1"/><circle cx="200" cy="180" r="1.3" fill="%23e0e7ff" opacity="0.9"/><circle cx="200" cy="180" r="2.6" fill="%23e0e7ff" opacity="0.12"/><circle cx="320" cy="220" r="1" fill="%23ffffff" opacity="0.8"/><circle cx="380" cy="280" r="1.2" fill="%23bfdbfe" opacity="0.85"/><circle cx="380" cy="280" r="2.4" fill="%23bfdbfe" opacity="0.1"/><circle cx="40" cy="320" r="1.5" fill="%23ffffff" opacity="0.9"/><circle cx="40" cy="320" r="3.2" fill="%23ffffff" opacity="0.15"/><circle cx="130" cy="360" r="1" fill="%23fef9c3" opacity="0.8"/><circle cx="250" cy="300" r="1.3" fill="%23ffffff" opacity="0.9"/><circle cx="250" cy="300" r="2.6" fill="%23ffffff" opacity="0.12"/><circle cx="340" cy="370" r="1.1" fill="%23e0e7ff" opacity="0.85"/></svg>') repeat;
    background-size: 400px 400px;
    animation: starDrift3 240s ease-in-out infinite alternate;
}

/* GPU-accelerated transform animations - alternate direction for no reset jump */
@keyframes starDrift1 {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(20%, 15%, 0); }
}

@keyframes starDrift2 {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(15%, 20%, 0); }
}

@keyframes starDrift3 {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(10%, 12%, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .stars, .stars2, .stars3 { animation: none; }
    .space-background::before { display: none; }
}

/* Hide controls functionality */
.controls-section {
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Space-themed speed meter dots */
.space-background .speed-meter .dot {
    background: rgba(255, 255, 255, 0.4);
}

.space-background .speed-meter .dot.active {
    background: #60a5fa;
    box-shadow: 0 0 8px rgba(96, 165, 250, 0.8);
}

/* Subtle color tint layer we can adjust from JS */
.space-tint {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at center, rgba(96,165,250,0.18), transparent 70%);
    mix-blend-mode: screen;
    opacity: 0.9;
}

/* Nebula glow behind the number */
.nebula-glow {
    position: absolute;
    width: 32rem;
    height: 32rem;
    border-radius: 9999px;
    background: radial-gradient(circle at 30% 20%, rgba(196,181,253,0.9), transparent 55%), 
                radial-gradient(circle at 70% 80%, rgba(56,189,248,0.7), transparent 60%);
    filter: blur(40px);
    opacity: 0.6;
    animation: nebulaShift 40s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes nebulaShift {
    0% { transform: translate3d(-10px, 10px, 0) scale(1); opacity: 0.5; }
    50% { transform: translate3d(10px, -5px, 0) scale(1.05); opacity: 0.7; }
    100% { transform: translate3d(-5px, -15px, 0) scale(1.1); opacity: 0.6; }
}

/* Shooting stars */
.shooting-star {
    position: fixed;
    width: 120px;
    height: 2px;
    background: linear-gradient(90deg, rgba(255,255,255,0.9), rgba(255,255,255,0));
    opacity: 0;
    pointer-events: none;
    z-index: 5;
    transform: translate3d(0,0,0);
    animation: shootingStar 0.9s ease-out forwards;
}

@keyframes shootingStar {
    0% { opacity: 0; transform: translate3d(-10vw, 0, 0) scaleX(0.4); }
    10% { opacity: 1; }
    100% { opacity: 0; transform: translate3d(110vw, -20vh, 0) scaleX(1); }
}

/* Warp effect on number at high speeds */
.number-display.warp {
    text-shadow: 0 0 30px rgba(255,255,255,0.9), 0 0 60px rgba(129,140,248,0.8);
    animation: warpPulse 1.2s ease-in-out infinite;
}

@keyframes warpPulse {
    0%,100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

/* Warp rings around play button */
.play-pause-btn.warp-rings::before,
.play-pause-btn.warp-rings::after {
    content: \"\";
    position: absolute;
    inset: -6px;
    border-radius: 9999px;
    border: 2px solid rgba(168,85,247,0.7);
    opacity: 0;
    animation: warpRingExpand 1.4s ease-out infinite;
}

.play-pause-btn.warp-rings::after {
    animation-delay: 0.35s;
}

@keyframes warpRingExpand {
    0% { transform: scale(0.8); opacity: 0.6; }
    100% { transform: scale(1.3); opacity: 0; }
}

/* Calm dimming when paused */
.space-background.paused .stars,
.space-background.paused .stars2,
.space-background.paused .stars3 {
    opacity: 0.4;
    transition: opacity 0.8s ease;
}

/* Ensure all controls text is readable on space background */
.space-background .controls-section,
.space-background .controls-section p,
.space-background .controls-section span,
.space-background .controls-section button {
    color: #e5e7eb;
}

/* Space-themed input styling to keep text visible */
.space-input {
    background-color: rgba(15, 23, 42, 0.9); /* slate-900 with some transparency */
    color: #e5e7eb; /* text-slate-200 */
    border-color: rgba(248, 250, 252, 0.35); /* soft border */
    caret-color: #a855f7; /* purple accent */
}

.space-input::placeholder {
    color: rgba(229, 231, 235, 0.6); /* slate-200 / 60% */
}

.space-input:focus {
    outline: none;
    border-color: transparent;
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.9);
}

/* Mobile improvements for Number Quest */
.pt-safe-top {
    padding-top: env(safe-area-inset-top, 0);
}

.pb-safe-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Better touch targets for Number Quest tiles */
.number-tile {
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.2);
    min-width: 64px;
    min-height: 64px;
}

/* Prevent text selection on mobile during gameplay */
.number-quest-container {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Improved mobile spacing for Number Quest */
@media (max-width: 768px) {
    #game-world {
        padding: 1rem;
        padding-top: 4rem;
        padding-bottom: 5rem;
    }
    
    .number-tile {
        min-width: 72px;
        min-height: 72px;
    }
    
    /* Larger text on mobile for better readability */
    .number-tile span {
        font-size: 1.75rem;
    }
    
    /* Prevent accidental scrolling when tapping tiles */
    body.number-quest-active {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
    
    /* Make items button more prominent */
    #inventory-toggle-mobile {
        animation: gentlePulse 2s ease-in-out infinite;
        position: relative;
    }
    
    #inventory-toggle-mobile::after {
        content: '';
        position: absolute;
        inset: -2px;
        border-radius: 0.5rem;
        border: 2px solid rgba(251, 191, 36, 0.6);
        animation: glowPulse 2s ease-in-out infinite;
        pointer-events: none;
    }
}

@keyframes gentlePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes glowPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* Floating Action Button for Items */
#inventory-fab {
    box-shadow: 0 8px 24px rgba(147, 51, 234, 0.4);
}

#inventory-fab:active {
    transform: scale(0.95);
}

/* Drawer styling */
#inventory-drawer,
#inventory-drawer-desktop {
    backdrop-filter: blur(8px);
}

#inventory-drawer #inventory-mobile .magical-item,
#inventory-drawer-desktop #inventory-desktop-drawer .magical-item {
    background: linear-gradient(135deg, rgba(250, 245, 255, 1), rgba(238, 242, 255, 1));
    border-radius: 1rem;
    border: 1px solid rgba(129, 140, 248, 0.3);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
    padding: 1rem;
}

#inventory-drawer #inventory-mobile .magical-item .font-semibold,
#inventory-drawer #inventory-mobile .magical-item .text-sm,
#inventory-drawer #inventory-mobile .magical-item .text-xs,
#inventory-drawer-desktop #inventory-desktop-drawer .magical-item .font-semibold,
#inventory-drawer-desktop #inventory-desktop-drawer .magical-item .text-sm,
#inventory-drawer-desktop #inventory-desktop-drawer .magical-item .text-xs {
    color: #374151;
}

/* Speed meter dots inside the chip */
.speed-meter { display: inline-flex; align-items: center; gap: 2px; margin-right: 4px; }
.speed-meter .dot { width: 6px; height: 6px; border-radius: 50%; background: #9ca3af; display: inline-block; }
.speed-meter .dot.active { background: #10b981; }

/* Auto-hide animation for status row (gentle fade/slide) */
.status-row { transition: opacity 0.4s ease, transform 0.4s ease; }
.status-row.hidden-soft { opacity: 0; transform: translateY(-6px); pointer-events: none; }

/* Play/Pause button styling - larger and more prominent on mobile */
.play-pause-btn {
    width: 64px;
    height: 64px;
    font-size: 24px;
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.3);
}

.play-pause-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 6px rgba(147, 51, 234, 0.4);
}

@media (min-width: 640px) {
    .play-pause-btn {
        width: 72px;
        height: 72px;
        font-size: 28px;
    }
}

/* Mobile layout fixes */
@media (max-width: 480px) {
    /* Auth compact (global top-controls handles layout) */
    #hub-auth-controls > div span:first-child { display: none; }

    /* Ensure play/pause button is prominent and easy to tap */
    .play-pause-btn { 
        width: 68px !important; 
        height: 68px !important; 
        font-size: 26px;
        box-shadow: 0 6px 16px rgba(147, 51, 234, 0.35);
    }
    .speed-slider { height: 16px; }
    .status-row { margin-top: 12px !important; }
}

/* Mobile landscape congestion fixes */
@media (orientation: landscape) and (max-height: 420px) {
    #hub-auth-controls > div { gap: 4px; padding: 4px 6px; }
    #hub-auth-controls > div span:first-child { display: none; }
    #hub-auth-controls .control-button { padding: 6px 8px; font-size: 12px; }
    #back-to-menu-btn { padding: 6px 10px; font-size: 14px; }
    /* Hide floating stats icon to avoid clutter; progress is in menu */
    .stats-fab, #progress-toggle-btn ~ .stats-fab { display: none !important; }
}

/* Buttons use Fredoka for a friendly, bold look */
.control-button {
    font-family: 'Fredoka', 'Fredoka One', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    letter-spacing: 0.2px;
}

/* Inline SVG icon sizing */
.icon-inline {
    width: 1em;
    height: 1em;
    display: inline-block;
    vertical-align: -0.15em;
}
.icon-inline--sm { width: 0.9em; height: 0.9em; }
.icon-inline--md { width: 1.25em; height: 1.25em; }
.icon-inline--lg { width: 1.5em; height: 1.5em; }
.icon-inline--xl { width: 2em; height: 2em; }

/* Hub header layout for logo + quick links */
.hub-header {
    padding: 0 16px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 24px;
}

.hub-header__row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.hub-header__row--bottom {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.hub-header__brand {
    display: flex;
    align-items: center;
}

.hub-header__logo {
    width: auto;
    max-width: 280px;
    height: 64px;
    object-fit: contain;
}

.hub-header__account {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.hub-header__account #hub-auth-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.hub-header__tools {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.hub-header__tools .control-button {
    min-height: 44px;
    border-radius: 14px;
}

.hub-header__privacy {
    font-size: 0.875rem;
    color: #6b7280;
    text-decoration: none;
    opacity: 0.85;
}

.hub-header__privacy:hover {
    text-decoration: underline;
    opacity: 1;
}

/* Auth checking state */
.app-card.is-gated {
    pointer-events: none;
    opacity: 0.8;
    filter: saturate(0.9);
}

.bna-auth-status {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    padding: 8px 12px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.bna-auth-status__name {
    font-weight: 600;
    color: #1f2937;
    font-size: 0.9rem;
}

.bna-auth-status__detail {
    font-size: 0.75rem;
    color: #64748b;
}

.bna-auth-avatar {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(148, 163, 184, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #334155;
}

.bna-auth-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.bna-auth-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

@media (min-width: 768px) {
    .hub-header {
        gap: 16px;
        margin-bottom: 28px;
    }

    .hub-header__logo {
        max-width: 320px;
        height: 72px;
    }
}

@media (max-width: 640px) {
    .hub-header__row--top {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .hub-header__account,
    .hub-header__account-inner {
        width: 100%;
        justify-content: flex-start;
    }

    .hub-header__logo {
        height: 56px;
    }
}

/* === Hub game cards: screenshot-led, calm, consistent === */
.bna-game-card {
    padding: 0;
    overflow: hidden;
    border-radius: 24px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    background: #fff;
    display: flex;
    flex-direction: column;
    height: 300px;
    text-align: left;
    transition: box-shadow 0.18s ease, transform 0.18s ease;
}

/* Videos cards (hub) */
.bna-video-card--disabled {
    cursor: default;
    opacity: 0.85;
}

.bna-video-card__cta {
    background: #0d9488;
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 0.85rem;
    font-weight: 600;
}

.bna-video-card__badge {
    display: inline-block;
    background: #f1f5f9;
    color: #64748b;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.bna-video-card-media {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: #f1f5f9;
}

.bna-video-card-media--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
}

.bna-video-card-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.bna-video-card-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(100, 116, 139, 0.85);
    pointer-events: none;
}

.bna-video-card-play svg {
    width: 48px;
    height: 48px;
}

/* Videos modal */
.bna-videos-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(env(safe-area-inset-top, 0px) + 1rem) 1rem 1.5rem;
}

.bna-videos-modal.hidden {
    display: none;
}

.bna-videos-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
}

.bna-videos-modal__panel {
    position: relative;
    width: min(720px, 100%);
    background: #fff;
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1;
}

.bna-videos-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bna-videos-modal__title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.bna-videos-modal__close {
    border: none;
    background: #f1f5f9;
    color: #0f172a;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.bna-videos-modal__content {
    width: 100%;
    position: relative;
    padding-top: 56.25%;
}

.bna-videos-modal__iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 14px;
}

.bna-modal-open {
    overflow: hidden;
}

/* Away from the Screen cards */
.bna-offline-card {
    padding: 0;
}

.bna-offline-card__media {
    position: relative;
    width: 100%;
    height: 160px;
    overflow: hidden;
    background: #f8fafc;
}

.bna-offline-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.bna-offline-card__body {
    padding: 14px 16px 18px;
    text-align: center;
}

@media (max-width: 767px) {
    .bna-offline-card__media {
        height: 150px;
    }
    .bna-offline-card__body {
        padding: 12px 14px 16px;
    }
}

/* Away from the Screen modal */
.bna-offline-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(env(safe-area-inset-top, 0px) + 1rem) 1rem 1.5rem;
}

.bna-offline-modal.hidden {
    display: none;
}

.bna-offline-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
}

.bna-offline-modal__panel {
    position: relative;
    width: min(560px, 100%);
    background: #fff;
    border-radius: 20px;
    padding: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1;
}

.bna-offline-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bna-offline-modal__title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.bna-offline-modal__close {
    border: none;
    background: #f1f5f9;
    color: #0f172a;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.bna-offline-modal__content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bna-offline-modal__preview {
    width: 100%;
    background: #f8fafc;
    border: 1px dashed #e2e8f0;
    border-radius: 14px;
    padding: 36px 16px;
    text-align: center;
    color: #94a3b8;
    font-weight: 600;
}

.bna-offline-modal__preview-img {
    width: 100%;
    height: auto;
    border-radius: 12px;
    display: block;
    object-fit: cover;
}

.bna-offline-modal__description {
    margin: 0;
    color: #475569;
    line-height: 1.5;
}

.bna-offline-modal__cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #0d9488;
    color: #fff;
    border-radius: 999px;
    padding: 10px 18px;
    font-weight: 600;
    text-decoration: none;
    align-self: flex-start;
}

/* Help modal */
.bna-help-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(env(safe-area-inset-top, 0px) + 1rem) 1rem 1.5rem;
}

.bna-help-modal.hidden {
    display: none;
}

.bna-help-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
}

.bna-help-modal__panel {
    position: relative;
    width: min(560px, 100%);
    background: #fff;
    border-radius: 20px;
    padding: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1;
}

.bna-help-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bna-help-modal__title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.bna-help-modal__close {
    border: none;
    background: #f1f5f9;
    color: #0f172a;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.bna-help-modal__content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    color: #475569;
    line-height: 1.5;
}

.bna-help-modal__divider {
    width: 100%;
    height: 1px;
    background: #e2e8f0;
    margin: 4px 0;
}

.bna-help-modal__subtitle {
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 2px 0 0;
}

/* Service worker update toast */
.bna-sw-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.92);
    color: #0f172a;
    border-radius: 999px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
    z-index: 60;
    font-size: 0.9rem;
}

.bna-sw-toast.hidden {
    display: none;
}

.bna-sw-toast button {
    border: none;
    background: #0ea5e9;
    color: #fff;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
}

@media (max-width: 480px) {
    .bna-sw-toast {
        width: calc(100% - 2rem);
        justify-content: space-between;
        bottom: 16px;
    }
}

/* Number Grid Explorer */
.number-grid-container {
    background: linear-gradient(135deg, #312e81 0%, #581c87 50%, #4c1d95 100%);
    min-height: 100vh;
}

.number-grid-title {
    font-size: 1.7rem;
    font-weight: 800;
    color: #ffffff;
}

.number-grid-subtext {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.7);
}

.number-grid-card {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 16px 30px rgba(15, 23, 42, 0.2);
}

.number-grid-display {
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    text-align: center;
}

.number-grid-value {
    font-size: 2.6rem;
    font-weight: 800;
    color: #fde047;
    min-width: 3rem;
}

.number-grid-label {
    font-size: 1rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.55);
    text-transform: lowercase;
}

.number-grid-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.number-grid-toggle,
.number-grid-clear {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.15);
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.number-grid-clear {
    cursor: pointer;
}

.number-grid-scroll {
    height: min(70vh, 640px);
    overflow: auto;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 0.75rem;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.number-grid {
    --grid-cell-size: 64px;
    display: grid;
    gap: 8px;
}

.number-grid-cell {
    width: var(--grid-cell-size);
    height: var(--grid-cell-size);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.75);
    font-weight: 600;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.number-grid-cell:hover {
    transform: translateY(-1px) scale(1.01);
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.25);
}

.number-grid-cell.is-active {
    background: rgba(255, 255, 255, 0.24);
    border: 2px solid rgba(253, 224, 71, 0.7);
    box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.25), 0 10px 22px rgba(0, 0, 0, 0.25);
    color: #ffffff;
    font-weight: 700;
}

.number-grid-cell.is-multiple {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.2), 0 8px 18px rgba(0, 0, 0, 0.25);
    color: #f8fafc;
    font-weight: 700;
}

.number-grid--has-selection .number-grid-cell:not(.is-active):not(.is-multiple) {
    opacity: 0.65;
}

.number-grid--hide-labels .number-grid-cell {
    color: transparent;
}

@media (max-width: 640px) {
    .number-grid-title {
        font-size: 1.5rem;
    }

    .number-grid-value {
        font-size: 2.2rem;
    }

    .number-grid-scroll {
        height: min(70vh, 560px);
    }

    .number-grid {
        --grid-cell-size: 54px;
    }
}

/* Avatar picker */
.bna-avatar-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
}

.bna-avatar-option {
    position: relative;
    border-radius: 16px;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.7);
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.bna-avatar-option img {
    width: 56px;
    height: 56px;
    border-radius: 999px;
    object-fit: cover;
}

.bna-avatar-option:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.6);
    outline-offset: 2px;
}

.bna-avatar-option:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.12);
}

.bna-avatar-option.is-selected {
    border-color: rgba(99, 102, 241, 0.8);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.bna-avatar-check {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(99, 102, 241, 0.9);
    color: #fff;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    font-size: 12px;
    display: none;
    align-items: center;
    justify-content: center;
}

.bna-avatar-option.is-selected .bna-avatar-check {
    display: inline-flex;
}

.bna-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 999px;
    object-fit: cover;
}

@media (max-width: 900px) {
    .bna-avatar-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .bna-avatar-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.bna-game-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 10px -1px rgba(0,0,0,0.12), 0 4px 6px -2px rgba(0,0,0,0.1);
}

.bna-game-card:active {
    transform: scale(0.99);
}

.bna-game-card-media {
    position: relative;
    width: 100%;
    height: 170px;
    overflow: hidden;
}

.bna-game-card-media::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0) 60%, rgba(255,255,255,0.25) 100%);
    pointer-events: none;
}

.bna-game-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.bna-game-card-body {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bna-game-card .app-card-title {
    font-size: 1.05rem;
    color: #1f2937;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bna-game-card p {
    margin: 0;
    color: #6b7280;
    font-size: 0.9rem;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 767px) {
    .bna-game-card {
        height: 280px;
    }
    .bna-game-card-media {
        height: 160px;
    }
    .bna-game-card-body {
        padding: 10px 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bna-game-card,
    .bna-game-card:hover {
        transition: none;
        transform: none;
    }
}

/* === Number Stories: storybook cover cards (hub only) === */
.bna-story-card {
    position: relative;
    background: var(--bna-story-gradient, linear-gradient(135deg, #E8F1FF, #D6E6FF));
    border-radius: 26px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    overflow: hidden;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 320px;
    padding: 32px 24px;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.bna-story-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.25);
    pointer-events: none;
}

.bna-story-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 18% 20%, rgba(255,255,255,0.45) 0%, rgba(255,255,255,0) 42%),
        radial-gradient(circle at 80% 28%, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0) 40%),
        radial-gradient(circle at 35% 78%, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0) 45%);
    opacity: 0.7;
    pointer-events: none;
}

.bna-story-card .bna-story-chip {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 2;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(17, 24, 39, 0.7);
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}

.bna-story-card .icon-container {
    position: relative;
    opacity: 0.95;
    margin-bottom: 18px;
    width: 66px;
    height: 66px;
    margin-left: auto;
    margin-right: auto;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.65);
    box-shadow: 0 10px 18px rgba(15, 23, 42, 0.08);
}

.bna-story-card .icon-container svg {
    color: rgba(17, 24, 39, 0.7);
}

.bna-story-card .icon-container .bna-story-icon {
    width: 34px;
    height: 34px;
    opacity: 0.85;
}

.bna-story-card .app-card-title {
    position: relative;
    color: #111827;
    font-size: 1.4rem;
    line-height: 1.2;
    margin-bottom: 0.6rem;
    text-shadow: 0 1px 2px rgba(255,255,255,0.4);
}

.bna-story-card p {
    position: relative;
    color: rgba(17, 24, 39, 0.75);
    max-width: 28ch;
    margin: 0 auto;
    line-height: 1.45;
}

.bna-story-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
}

.bna-story-card:active {
    transform: scale(0.98);
}

.bna-story-card[data-story-category="time-self"] {
    --bna-story-gradient: linear-gradient(135deg, #E8F1FF, #D6E6FF);
}

.bna-story-card[data-story-category="scale-wonder"] {
    --bna-story-gradient: linear-gradient(135deg, #F3E8FF, #E4D4FF);
}

.bna-story-card[data-story-category="infinity-limits"] {
    --bna-story-gradient: linear-gradient(135deg, #E9F7F2, #D6F0E6);
}

.bna-story-card[data-story-category="patterns-structure"] {
    --bna-story-gradient: linear-gradient(135deg, #FFF6E5, #FFE8B8);
}

@media (max-width: 767px) {
    .bna-story-card {
        min-height: 260px;
        padding: 28px 22px;
    }
    .bna-story-card p {
        max-width: 32ch;
    }
    .bna-story-card .icon-container {
        width: 58px;
        height: 58px;
        margin-bottom: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bna-story-card,
    .bna-story-card:hover {
        transition: none;
        transform: none;
    }
}

/* Hub mobile: comfortable padding for section headings and cards */
@media (max-width: 480px) {
    #app-hub .hub-header {
        margin-bottom: 1.25rem;
        padding-left: 0;
        padding-right: 0;
    }

    #main-menu h2 {
        padding-left: 1rem;
        padding-right: 1rem;
        margin-bottom: 0.75rem;
    }

    #main-menu .flex.overflow-x-auto {
        padding-left: 1rem;
        padding-right: 1rem;
        margin-left: -1rem;
        margin-right: -1rem;
    }

    #main-menu .flex.gap-6 {
        padding-bottom: 0.5rem;
    }
}

/* Inline SVG icon sizing */
.icon-inline {
    width: 1em;
    height: 1em;
    display: inline-block;
    vertical-align: -0.15em;
}

.icon-inline--sm { width: 0.9em; height: 0.9em; }
.icon-inline--md { width: 1.1em; height: 1.1em; }
.icon-inline--lg { width: 1.5em; height: 1.5em; }
.icon-inline--xl { width: 2em; height: 2em; }
.icon-inline--2xl { width: 3em; height: 3em; }

/* Math Miner (Grid) layout + controls */
.math-miner-container {
    background: radial-gradient(circle at top, #1f2937 0%, #0f172a 55%, #0b1220 100%);
    color: #f8fafc;
    font-family: 'Fredoka', 'Fredoka One', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.math-miner-card {
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 18px;
    padding: 16px 20px;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.25);
}

.math-miner-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.math-miner-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #fef3c7;
}

.math-miner-question {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 8px 0 10px;
    color: #e2e8f0;
}

.math-miner-status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}

.math-miner-pill {
    background: rgba(30, 41, 59, 0.6);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #f8fafc;
}

.math-miner-hint {
    font-size: 0.85rem;
    color: rgba(226, 232, 240, 0.75);
}

.math-miner-canvas-wrap {
    display: flex;
    justify-content: center;
    margin-top: 18px;
    position: relative;
}

.math-miner-canvas-wrap canvas {
    width: min(100%, 720px);
    height: auto;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: #0b1220;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.4);
}

.math-miner-loading {
    width: min(100%, 720px);
    height: 360px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: #0b1220;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(226, 232, 240, 0.8);
    font-size: 1rem;
    font-weight: 600;
}

.math-miner-hidden {
    display: none;
}

.math-miner-footer-spacer {
    flex: 1;
    min-height: 24px;
}

.math-miner-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(15, 23, 42, 0.85), rgba(15, 23, 42, 0.05));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 12;
}

.math-miner-controls__row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    justify-content: center;
}

.math-miner-dpad {
    display: grid;
    gap: 8px;
    justify-items: center;
}

.math-miner-dpad__mid {
    display: flex;
    gap: 8px;
}

.math-miner-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.math-miner-control-btn {
    min-width: 64px;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(226, 232, 240, 0.15);
    border: 1px solid rgba(148, 163, 184, 0.4);
    color: #f8fafc;
    font-size: 0.9rem;
    font-weight: 600;
    transition: transform 0.1s ease, background 0.2s ease;
    touch-action: manipulation;
}

.math-miner-control-btn:active {
    transform: scale(0.96);
    background: rgba(226, 232, 240, 0.25);
}

.math-miner-control-btn--accent {
    background: rgba(16, 185, 129, 0.75);
    border-color: rgba(110, 231, 183, 0.6);
}

.math-miner-control-btn--secondary {
    background: rgba(245, 158, 11, 0.65);
    border-color: rgba(253, 224, 71, 0.6);
}

.math-miner-controls__hint {
    font-size: 0.75rem;
    color: rgba(226, 232, 240, 0.7);
    text-align: center;
}

/* Number Explorer navigation emphasis */
.number-explorer-nav-btn {
    width: 4.5rem;
    height: 4.5rem;
    font-size: 2rem;
}

.number-explorer-nav-btn.hint-pulse-once {
    animation: hintArrowPulse 0.9s ease-out 1;
}

@keyframes hintArrowPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(129, 140, 248, 0.4); }
    50% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(129, 140, 248, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(129, 140, 248, 0); }
}

/* Extra breathing room above Number Explorer stats bar */
.number-explorer-stats {
    margin-top: 1.25rem; /* ~mt-5 */
}

/* Star Filler: keep / export toolbar – lift above mobile browser chrome */
.star-filler-toolbar {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
}

@media (min-width: 768px) {
    .star-filler-toolbar {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 1.25rem);
    }
}

/* Global game header layout: reserve space for account bar */
.game-header,
.game-topbar,
.starfield-topbar {
    padding-right: calc(var(--account-bar-w, 0px) + 1rem + env(safe-area-inset-right, 0px)) !important;
    padding-left: calc(1rem + env(safe-area-inset-left, 0px)) !important;
    max-width: 100%;
    box-sizing: border-box;
}

/* Ensure game controls stay within bounds */
.game-header > *,
.game-topbar > *,
.starfield-topbar > * {
    max-width: 100%;
    overflow: visible;
}

/* Mobile: reduce padding, account bar is compact */
@media (max-width: 768px) {
    .game-header,
    .game-topbar,
    .starfield-topbar {
        padding-right: calc(var(--account-bar-w, 0px) + 0.75rem + env(safe-area-inset-right, 0px)) !important;
    }
}

/* Very small screens: account bar collapses, minimal padding */
@media (max-width: 480px) {
    .game-header,
    .game-topbar,
    .starfield-topbar {
        padding-right: calc(0.5rem + env(safe-area-inset-right, 0px)) !important;
    }
}

@media (min-width: 768px) {
    .math-miner-controls {
        position: sticky;
        background: none;
        padding-bottom: 24px;
    }

    .math-miner-actions {
        flex-direction: row;
    }
}
