/**
 * @author      Mike Fairbrother <mike@fairbrother.me>
 * @copyright   2024-2026 Mike Fairbrother. All rights reserved.
 * @license     PROPRIETARY - No rights to copy, modify, distribute, or reuse
 *              any part of this code without explicit written permission from the author.
 */
/**
 * Shared Game Platform Styles
 *
 * Extracted from Emoji Drop - the visual reference for the entire games platform.
 * All games should import this file for consistent design tokens, shell layout,
 * buttons, overlays, HUD, footer, and responsive behaviour.
 */

/* ---- Design Tokens ---- */
:root {
    --gp-bg-dark: #221b4a;
    --gp-bg-mid: #2e2564;
    --gp-bg-surface: rgba(255, 255, 255, 0.10);
    --gp-text-primary: #fff;
    --gp-text-secondary: rgba(255, 255, 255, 0.75);
    --gp-accent: #ffe04a;
    --gp-accent-glow: rgba(255, 224, 74, 0.45);
    --gp-danger: #ff5a6a;
    --gp-success: #3de882;
    --gp-fire-a: #ff7e7e;
    --gp-fire-b: #ffb05a;
    --gp-radius-sm: 10px;
    --gp-radius-md: 16px;
    --gp-radius-lg: 20px;
    --gp-radius-xl: 24px;
    --gp-transition-fast: 150ms;
    --gp-transition-normal: 300ms;
    --gp-font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --gp-max-width: 420px;
    --safe-top: 0px;
    --safe-bottom: 0px;
    --gameplay-top-inset: 0px;
    --gameplay-bottom-inset: 0px;
}

/* ---- Reset ---- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    background: var(--gp-bg-dark);
    color: var(--gp-text-primary);
    font-family: var(--gp-font-stack);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

/* ---- App Shell ---- */
.gp-shell {
    position: relative;
    width: 100%;
    max-width: var(--gp-max-width);
    min-height: 100vh;
    min-height: 100dvh;
    min-height: var(--vh, 100dvh);
    margin: 0 auto;
    background: linear-gradient(170deg, #2e2564 0%, #221b4a 40%, #332768 100%);
    overflow-x: hidden;
}

/* Game shell: fixed viewport for gameplay */
.gp-game-shell {
    position: relative;
    width: 100%;
    max-width: var(--gp-max-width);
    height: 100vh;
    height: 100dvh;
    height: var(--vh, 100dvh);
    margin: 0 auto;
    overflow: hidden;
    background: linear-gradient(170deg, #2e2564 0%, #221b4a 40%, #332768 100%);
}

/* ---- Screen System ---- */
.gp-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1;
}
.gp-screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}
.gp-screen-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    overflow-y: auto;
}

/* ---- Buttons ---- */
.gp-btn {
    display: block;
    width: 220px;
    padding: 16px 32px;
    border: none;
    border-radius: var(--gp-radius-md);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: transform var(--gp-transition-fast), box-shadow var(--gp-transition-fast);
    letter-spacing: 0.5px;
    font-family: var(--gp-font-stack);
    text-decoration: none;
    text-align: center;
}
.gp-btn:active { transform: scale(0.95); }

.gp-btn-primary {
    background: linear-gradient(135deg, #ffd93d, #ff9f43);
    color: #1a1640;
    box-shadow: 0 4px 20px rgba(255, 217, 61, 0.3);
}
.gp-btn-primary:active { box-shadow: 0 2px 10px rgba(255, 217, 61, 0.2); }

.gp-btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--gp-text-secondary);
    margin-top: 12px;
    font-size: 16px;
    padding: 12px 32px;
}

.gp-icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--gp-radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: var(--gp-text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--gp-transition-fast);
    flex-shrink: 0;
}
.gp-icon-btn:active { background: rgba(255, 255, 255, 0.15); }

/* ---- HUD System ---- */
.gp-hud {
    display: flex;
    align-items: center;
    padding: 10px 12px 6px;
    gap: 8px;
    min-height: 52px;
}
.gp-stat {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.gp-stat-right { align-items: flex-end; }
.gp-stat-label {
    font-size: 10px;
    color: var(--gp-text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}
.gp-stat-value {
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

/* ---- Overlay System ---- */
.gp-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.gp-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.gp-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.gp-overlay-title {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 20px;
}

/* ---- Modal System ---- */
.gp-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: 20px;
}
.gp-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.gp-modal-content {
    background: linear-gradient(170deg, #332870, #261e58);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--gp-radius-lg);
    padding: 28px 24px;
    max-width: 360px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    transform: scale(0.9);
    transition: transform 0.25s ease;
}
.gp-modal-overlay.active .gp-modal-content {
    transform: scale(1);
}
.gp-modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--gp-text-secondary);
    font-size: 20px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.gp-modal-title {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 20px;
}

/* ---- Toast System ---- */
.gp-toasts {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    pointer-events: none;
    width: 300px;
}
.gp-toast {
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: rgba(50, 38, 90, 0.94);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    opacity: 0;
    transform: translateY(-10px) scale(0.9);
    transition: opacity 0.25s ease, transform 0.25s ease;
    white-space: nowrap;
}
.gp-toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ---- Footer Credit ---- */
.gp-footer {
    margin-top: 24px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.32);
    letter-spacing: 0.5px;
    font-weight: 500;
    text-align: center;
    padding: 12px;
}
.gp-footer a,
.gp-footer a:visited,
.gp-footer a:hover,
.gp-footer a:active {
    color: inherit;
    text-decoration: none;
}

/* ---- Back to Games Link (pill button with arrow) ---- */
.gp-back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    padding: 8px 18px 8px 14px;
    border-radius: 50px;
    background: linear-gradient(135deg, rgba(255,217,61,0.18), rgba(255,159,67,0.14));
    border: 1px solid rgba(255,217,61,0.25);
    transition: transform var(--gp-transition-fast), background var(--gp-transition-fast), box-shadow var(--gp-transition-fast);
    letter-spacing: 0.3px;
    margin-bottom: 23px;
    box-shadow: 0 2px 8px rgba(255,217,61,0.1);
}
.gp-back-link::before {
    content: "\2190";
    font-size: 15px;
    line-height: 1;
}
.gp-back-link:visited {
    color: #fff;
}
.gp-back-link:active {
    transform: scale(0.96);
    background: linear-gradient(135deg, rgba(255,217,61,0.28), rgba(255,159,67,0.22));
    box-shadow: 0 1px 4px rgba(255,217,61,0.15);
}

/* ---- Gameplay Footer (persistent, subtle) ---- */
.gp-footer-gameplay {
    position: absolute;
    bottom: 4px;
    left: 0;
    right: 0;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.15);
    letter-spacing: 0.5px;
    font-weight: 500;
    text-align: center;
    padding: 4px;
    pointer-events: auto;
    z-index: 5;
}
.gp-footer-gameplay a,
.gp-footer-gameplay a:visited,
.gp-footer-gameplay a:hover,
.gp-footer-gameplay a:active {
    color: inherit;
    text-decoration: none;
}

/* ---- Daily Leaderboard ---- */
.gp-leaderboard {
    width: 100%;
    max-width: 340px;
    margin-top: 16px;
    background: rgba(255,255,255,0.04);
    border-radius: 16px;
    padding: 16px;
}
.gp-lb-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--gp-accent);
    text-align: center;
}
.gp-lb-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.gp-lb-loading {
    text-align: center;
    color: rgba(255,255,255,0.4);
    padding: 16px;
    font-size: 0.85rem;
}
.gp-lb-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    transition: background 0.2s;
}
.gp-lb-entry.gp-lb-me {
    background: rgba(255,224,74,0.1);
    border: 1px solid rgba(255,224,74,0.25);
}
.gp-lb-rank {
    font-size: 0.85rem;
    font-weight: 700;
    color: rgba(255,255,255,0.4);
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}
.gp-lb-entry:nth-child(1) .gp-lb-rank { color: #ffe04a; }
.gp-lb-entry:nth-child(2) .gp-lb-rank { color: #c0c0c0; }
.gp-lb-entry:nth-child(3) .gp-lb-rank { color: #cd7f32; }
.gp-lb-name {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gp-lb-time {
    font-size: 0.8rem;
    color: var(--gp-accent);
    font-weight: 600;
    flex-shrink: 0;
}
.gp-lb-score {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    flex-shrink: 0;
}
.gp-lb-separator {
    text-align: center;
    color: rgba(255,255,255,0.2);
    font-size: 0.7rem;
    letter-spacing: 4px;
    padding: 4px 0;
}

/* ---- Daily Done Screen ---- */
.gp-done-icon {
    font-size: 64px;
    margin-bottom: 8px;
}
.gp-done-title {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 8px;
    color: #fff;
}
.gp-done-badge {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gp-accent);
    padding: 4px 10px;
    background: rgba(255,217,61,0.12);
    border-radius: 6px;
    margin-bottom: 12px;
    display: inline-block;
}
.gp-done-msg {
    color: rgba(255,255,255,0.6);
    font-size: 0.95rem;
    margin-bottom: 12px;
    display: inline-block;
}
.gp-done-stats {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin: 12px 0;
}
.gp-done-stat {
    text-align: center;
}
.gp-done-stat-num {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--gp-accent);
    display: block;
}
.gp-done-stat-lbl {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.5);
}

/* ---- Particles Container ---- */
.gp-particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}

/* ---- Score Popup ---- */
.gp-score-popup {
    position: absolute;
    font-size: 18px;
    font-weight: 800;
    color: var(--gp-accent);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 20;
    animation: gp-score-float 0.9s ease-out forwards;
    white-space: nowrap;
    transform: translateX(-50%);
}
@keyframes gp-score-float {
    0%   { transform: translateX(-50%) translateY(0) scale(0.5); opacity: 0; }
    20%  { transform: translateX(-50%) translateY(-10px) scale(1.1); opacity: 1; }
    100% { transform: translateX(-50%) translateY(-60px) scale(0.9); opacity: 0; }
}

/* ---- Shared Animations ---- */
@keyframes gp-badge-pop {
    0%  { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes gp-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Gen 1 Compatibility (bare class names alias to gp- equivalents) ---- */
/* These ensure all Gen 1 games using non-prefixed classes get identical styling */
#app {
    position: relative;
    width: 100%;
    max-width: var(--gp-max-width);
    height: 100vh;
    height: 100dvh;
    height: var(--vh, 100dvh);
    margin: 0 auto;
    overflow: hidden;
    background: linear-gradient(170deg, #2e2564 0%, #221b4a 40%, #332768 100%);
}
#app .screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1;
}
#app .screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}
#app .screen-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    overflow-y: auto;
}
.btn {
    display: block;
    width: 220px;
    padding: 16px 32px;
    border: none;
    border-radius: var(--gp-radius-md);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: transform var(--gp-transition-fast), box-shadow var(--gp-transition-fast);
    letter-spacing: 0.5px;
    font-family: var(--gp-font-stack);
    text-decoration: none;
    text-align: center;
}
.btn:active { transform: scale(0.95); }
.btn-primary, .btn.btn-primary {
    background: linear-gradient(135deg, #ffd93d, #ff9f43);
    color: #1a1640;
    box-shadow: 0 4px 20px rgba(255, 217, 61, 0.3);
}
.btn-secondary, .btn.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--gp-text-secondary);
    margin-top: 12px;
    font-size: 16px;
    padding: 12px 32px;
}
.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--gp-radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: var(--gp-text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--gp-transition-fast);
    flex-shrink: 0;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }
.game-overlay, #app .overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.game-overlay.active, #app .overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

/* ---- Hidden Utility ---- */
.gp-hidden { display: none !important; }

/* ---- Responsive: Desktop Frame ---- */
@media (min-width: 421px) {
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        background: #181438;
    }
    .gp-game-shell, #app {
        border-radius: var(--gp-radius-xl);
        box-shadow: 0 0 60px rgba(30, 20, 80, 0.5);
        border: 1px solid rgba(255, 255, 255, 0.05);
        max-height: 900px;
    }
    .gp-shell {
        border-radius: var(--gp-radius-xl);
        box-shadow: 0 0 60px rgba(30, 20, 80, 0.5);
        border: 1px solid rgba(255, 255, 255, 0.05);
    }
}

/* ---- Safe Area Support (browser, non-standalone) ---- */
@supports (padding-top: env(safe-area-inset-top)) {
    .gp-hud {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
    .gp-screen {
        padding-bottom: env(safe-area-inset-bottom);
    }
    #app .screen {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .gp-footer {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
    .gp-footer-gameplay {
        bottom: calc(4px + env(safe-area-inset-bottom));
    }
}

/* ---- PWA standalone: shrink screens for status bar / nav bar ---- */
/* JS in sw-update.js adds .pwa-standalone to <html> and sets --vh.  */
/* This is more reliable than @media (display-mode: standalone) +    */
/* env(safe-area-inset-*) which returns 0 on most Android devices.   */
.pwa-standalone .gp-shell {
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}
.pwa-standalone .gp-game-shell,
.pwa-standalone #app {
    height: var(--vh, 100dvh);
}
/* Offset absolute-positioned screens so content shrinks to fit */
.pwa-standalone .gp-screen {
    top: var(--safe-top);
    bottom: var(--safe-bottom);
    padding-top: 0;
    padding-bottom: 0;
}
.pwa-standalone #app .screen {
    top: var(--safe-top);
    bottom: var(--safe-bottom);
    padding-top: 0;
    padding-bottom: 0;
}
.pwa-standalone #screen-game {
    top: 0;
    bottom: 0;
    padding-top: calc(var(--safe-top) + var(--gameplay-top-inset, 0px));
    padding-bottom: calc(var(--safe-bottom) + var(--gameplay-bottom-inset, 0px));
}
.pwa-standalone .gp-hud {
    padding-top: 10px;
}
.pwa-standalone #screen-game .gp-hud,
.pwa-standalone #screen-game #game-header,
.pwa-standalone #screen-game .game-header,
.pwa-standalone #screen-game header {
    padding-top: 10px !important;
}
.pwa-standalone .gp-footer-gameplay {
    display: none;
}
.pwa-standalone .gp-footer {
    padding-bottom: calc(8px + var(--safe-bottom));
}
