/* ============================================
   RESET & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overscroll-behavior: none;
    height: 100%;
    width: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #1e3c72 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: none;
}

body > #parent-view {
    display: block !important;
    visibility: visible !important;
    flex-shrink: 0;
}

/* Animated wave background */
body::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'%3E%3Cpath fill='%23ffffff' fill-opacity='0.1' d='M0,96L48,112C96,128,192,160,288,160C384,160,480,128,576,122.7C672,117,768,139,864,154.7C960,171,1056,181,1152,165.3C1248,149,1344,107,1392,85.3L1440,64L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E") no-repeat bottom;
    background-size: cover;
    animation: wave 20s linear infinite;
}

@keyframes wave {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50px); }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   ANCHOR ICON (Refresh Button in Title)
   ============================================ */
.anchor-icon {
    display: inline-block;
    cursor: pointer;
    transition: transform 0.3s ease, opacity 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.anchor-icon:hover {
    opacity: 0.8;
}

.anchor-icon:active {
    opacity: 0.6;
}

.anchor-icon.rotating {
    animation: anchorRotate 0.6s ease-in-out forwards;
}

@keyframes anchorRotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   LANGUAGE SELECTOR
   ============================================ */
.language-selector {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.language-btn {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    padding: 8px 16px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 100px;
    justify-content: center;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.3);
    touch-action: manipulation;
}

.language-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

.language-btn.active {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.6);
}

.language-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background: rgba(30, 60, 114, 0.95);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    padding: 10px 0;
    min-width: 150px;
    display: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: fadeInDown 0.3s ease-out;
}

.language-dropdown.show {
    display: block;
}

.language-option {
    padding: 12px 20px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.language-option:hover {
    background: rgba(255, 255, 255, 0.2);
}

.language-option.active {
    background: rgba(255, 255, 255, 0.15);
    font-weight: 600;
}

.language-flag {
    font-size: 1.2rem;
}

/* ============================================
   PWA STANDALONE MODE ADJUSTMENTS
   Move content closer to top since status bar takes space
   ============================================ */
@media (display-mode: standalone) {
    .language-selector {
        top: 15px !important;
    }
    .header {
        margin-top: -15px !important;
    }
}

.standalone-mode .language-selector {
    top: 15px !important;
}

.standalone-mode .header {
    margin-top: -15px !important;
}

@media (display-mode: standalone) and (max-width: 768px) {
    .language-selector {
        top: 10px !important;
    }
    .header {
        margin-top: -10px !important;
    }
}

@media (max-width: 768px) {
    .standalone-mode .language-selector {
        top: 10px !important;
    }
    .standalone-mode .header {
        margin-top: -10px !important;
    }
}

/* ============================================
   CONTAINER & HEADER
   ============================================ */
.container {
    max-width: 1200px;
    width: 100%;
    text-align: center;
    z-index: 1;
}

.header {
    margin-bottom: 60px;
    animation: fadeInDown 1s ease-out;
}

h1 {
    font-size: 4rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3);
    letter-spacing: 2px;
    word-break: keep-all;
    overflow-wrap: break-word;
}

/* Make title clickable for debug (double-click 3 times to show debug panel) */
#mainTitle {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    transition: opacity 0.2s;
}

#mainTitle:hover {
    opacity: 0.9;
}

.subtitle {
    font-size: 1.5rem;
    opacity: 0.9;
    font-weight: 300;
    margin-top: 10px;
}

/* ============================================
   GAMES CONTAINER & CARDS
   ============================================ */
.games-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    grid-template-rows: 1fr;
    grid-auto-flow: row;
    gap: 40px;
    margin-top: 60px;
    width: 100%;
    max-width: 100%;
    justify-items: stretch;
}

.game-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 40px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.2);
    text-decoration: none;
    color: inherit;
    display: block;
    animation: fadeInUp 1s ease-out;
    animation-fill-mode: both;
}

.game-card:nth-child(1) {
    animation-delay: 0.2s;
}

.game-card:nth-child(2) {
    animation-delay: 0.4s;
}

.game-card:hover {
    transform: translateY(-10px) scale(1.05);
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.game-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    display: block;
}

.game-title {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.game-description {
    font-size: 1rem;
    opacity: 0.8;
    line-height: 1.6;
}

/* ============================================
   PORTRAIT MODE (Single Column)
   ============================================ */
body.portrait-mode .games-container {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto !important;
    gap: 20px !important;
    margin-top: 20px !important;
}

body.portrait-mode .game-card {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 40px !important;
    min-height: 200px !important;
}

body.portrait-mode .container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 10px !important;
    padding-top: 20px !important;
}

body.portrait-mode .header {
    margin-bottom: 30px !important;
    margin-top: 0 !important;
}

body.portrait-mode h1 {
    margin-top: 0 !important;
    margin-bottom: 10px !important;
}

/* ============================================
   LANDSCAPE MODE (Single Row)
   ============================================ */
body.landscape-mode .games-container {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) !important;
    grid-template-rows: 1fr !important;
    grid-auto-flow: row !important;
}

/* ============================================
   STATE-BASED VIEW SWITCHING (SPA)
   ============================================ */
#parent-view {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 100% !important;
    min-height: 100px !important;
}

body > #parent-view:not(.hide),
#parent-view:not(.hide),
body #parent-view.container:not(.hide) {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 100% !important;
}

#parent-view.container {
    display: block !important;
    visibility: visible !important;
}

#parent-view.container.hide {
    display: none !important;
    visibility: hidden !important;
}

#parent-view.hide {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

#parent-view:not(.hide) {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

#child-view {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    flex-direction: column;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.25s ease-in-out;
}

#child-view.show {
    display: flex;
    opacity: 1;
}

.game-iframe {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.game-iframe.loaded {
    opacity: 1;
}

.game-view-header {
    position: relative;
    z-index: 2;
    padding: 10px;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* ============================================
   PWA PROMPT MODAL
   ============================================ */
.pwa-prompt-overlay {
    display: none;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.8) !important;
    z-index: 100000 !important;
    justify-content: center;
    align-items: center;
    padding: 15px;
    box-sizing: border-box;
}

.pwa-prompt-overlay.show {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.pwa-prompt-modal {
    position: relative;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border-radius: 20px;
    padding: 25px;
    max-width: 500px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    color: white;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: fadeInUp 0.3s ease-out;
    box-sizing: border-box;
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    transition: background 0.2s ease;
    padding: 0;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.4);
}

.pwa-prompt-modal h3 {
    font-size: clamp(1.2rem, 4.5vw, 1.8rem);
    margin-bottom: 12px;
    color: white;
}

.pwa-prompt-modal p {
    font-size: clamp(0.85rem, 3.5vw, 1rem);
    margin-bottom: 15px;
    line-height: 1.5;
    opacity: 0.9;
}

.pwa-instructions {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    margin: 15px 0;
    text-align: left;
}

.pwa-instructions ol {
    margin: 0;
    padding-left: 18px;
}

.pwa-instructions li {
    margin: 8px 0;
    line-height: 1.5;
    font-size: clamp(0.8rem, 3.2vw, 0.95rem);
}

.pwa-prompt-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
    flex-wrap: wrap;
}

.pwa-prompt-btn {
    padding: 10px 24px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: clamp(0.85rem, 3.5vw, 1rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.pwa-prompt-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

.pwa-prompt-btn.primary {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.pwa-prompt-btn.primary:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */
@media (max-width: 768px) {
    .language-selector {
        top: 10px;
        right: 10px;
        z-index: 10001;
    }

    .language-btn {
        padding: 0 !important;
        min-width: 44px !important;
        min-height: 44px !important;
        width: 44px !important;
        height: 44px !important;
        max-width: 44px !important;
        max-height: 44px !important;
        border-radius: 50% !important;
        background: rgba(255, 255, 255, 0.15) !important;
        border: 2px solid rgba(255, 255, 255, 0.3) !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 0 !important;
        flex-shrink: 0 !important;
    }

    .language-btn:active {
        background: rgba(255, 255, 255, 0.25);
        transform: scale(0.95);
    }

    .language-btn #languageText,
    .language-btn span:last-child {
        display: none;
    }

    .language-dropdown {
        min-width: 140px;
        right: 0;
        margin-top: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }

    .language-option {
        padding: 14px 20px;
        min-height: 44px;
    }

    .language-option:active {
        background: rgba(255, 255, 255, 0.3);
    }

    .language-flag {
        font-size: 1.6rem;
    }

    h1 {
        font-size: 2.5rem;
    }

    .subtitle {
        font-size: 1.2rem;
    }

    #gameIdRow {
        justify-content: center !important;
    }

    #gameIdDisplay {
        text-align: center !important;
        margin-right: 0 !important;
        margin-bottom: 10px;
    }

    .games-container {
        grid-template-columns: 1fr;
        gap: 30px;
    }

    .game-card {
        padding: 30px;
    }
}

@media (max-width: 480px) {
    .language-selector {
        top: 8px;
        right: 8px;
    }

    .language-btn {
        padding: 0 !important;
        min-width: 44px !important;
        min-height: 44px !important;
        width: 44px !important;
        height: 44px !important;
        max-width: 44px !important;
        max-height: 44px !important;
        border-radius: 50% !important;
        background: rgba(255, 255, 255, 0.15) !important;
        border: 2px solid rgba(255, 255, 255, 0.3) !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 0 !important;
        flex-shrink: 0 !important;
    }

    .language-btn #languageText,
    .language-btn span:last-child {
        display: none !important;
    }

    .language-flag {
        font-size: 1.6rem;
    }

    /* Adaptive modal for small Android screens */
    .pwa-prompt-overlay {
        padding: 10px !important;
    }

    .pwa-prompt-modal {
        padding: 18px !important;
        border-radius: 16px !important;
        max-height: 88vh !important;
    }

    .pwa-prompt-modal h3 {
        font-size: 1.15rem !important;
        margin-bottom: 8px !important;
    }

    .pwa-prompt-modal p {
        font-size: 0.85rem !important;
        margin-bottom: 10px !important;
    }

    .pwa-instructions {
        padding: 12px !important;
        margin: 10px 0 !important;
        border-radius: 10px !important;
    }

    .pwa-instructions li {
        margin: 6px 0 !important;
        font-size: 0.82rem !important;
        line-height: 1.4 !important;
    }

    .pwa-prompt-buttons {
        margin-top: 10px !important;
        gap: 8px !important;
    }

    .pwa-prompt-btn {
        padding: 8px 18px !important;
        font-size: 0.85rem !important;
    }
}

/* Extra small screens (shorter Android phones, e.g. < 640px height) */
@media (max-height: 640px) {
    .pwa-prompt-modal {
        padding: 14px !important;
        max-height: 90vh !important;
    }

    .pwa-prompt-modal h3 {
        font-size: 1.05rem !important;
        margin-bottom: 6px !important;
    }

    .pwa-prompt-modal p {
        font-size: 0.8rem !important;
        margin-bottom: 8px !important;
    }

    .pwa-instructions {
        padding: 10px !important;
        margin: 8px 0 !important;
    }

    .pwa-instructions li {
        margin: 4px 0 !important;
        font-size: 0.78rem !important;
        line-height: 1.3 !important;
    }

    .pwa-prompt-buttons {
        margin-top: 8px !important;
    }

    .pwa-prompt-btn {
        padding: 7px 14px !important;
        font-size: 0.8rem !important;
    }
}

@media screen and (max-width: 1500px) {
    .container {
        max-width: 100% !important;
        padding: 10px !important;
    }
}

@media (hover: none) and (pointer: coarse), (max-width: 768px), (max-height: 1024px) and (orientation: portrait) {
    .container {
        max-width: 100% !important;
        padding: 10px !important;
    }

    h1 {
        font-size: 2.5rem !important;
    }

    .game-card {
        padding: 25px !important;
        min-width: auto !important;
    }

    .game-icon {
        font-size: 3rem !important;
    }

    .game-title {
        font-size: 1.5rem !important;
    }
}

@media (orientation: landscape) {
    .container {
        max-width: 100% !important;
    }
}
