/**
 * Quran Word Game Styles
 * Responsive design with mobile-first approach
 */

/* Hide page header when plugin is present */
body:has(#quran-word-game) header,
body:has(#quran-word-game) .site-header,
body:has(#quran-word-game) .header,
body:has(#quran-word-game) .main-header,
body:has(#quran-word-game) .page-header,
body:has(#quran-word-game) .entry-header,
body:has(#quran-word-game) .site-branding,
body:has(#quran-word-game) .navbar,
body:has(#quran-word-game) nav.main-navigation,
body:has(#quran-word-game) .navigation-top {
    display: none !important;
}

/* Alternative fallback for browsers that don't support :has() */
.quran-word-game-page header,
.quran-word-game-page .site-header,
.quran-word-game-page .header,
.quran-word-game-page .main-header,
.quran-word-game-page .page-header,
.quran-word-game-page .entry-header,
.quran-word-game-page .site-branding,
.quran-word-game-page .navbar,
.quran-word-game-page nav.main-navigation,
.quran-word-game-page .navigation-top {
    display: none !important;
}

/* Position game at top of page */
body:has(#quran-word-game) .site-main,
body:has(#quran-word-game) .content-area,
body:has(#quran-word-game) .entry-content,
body:has(#quran-word-game) .page-content,
body:has(#quran-word-game) main,
body:has(#quran-word-game) article {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Alternative fallback */
.quran-word-game-page .site-main,
.quran-word-game-page .content-area,
.quran-word-game-page .entry-content,
.quran-word-game-page .page-content,
.quran-word-game-page main,
.quran-word-game-page article {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Ensure body has no top margin/padding when game is present */
body:has(#quran-word-game),
.quran-word-game-page {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Reset and base styles */
:root {
    /* Green palette tuned to match the screenshots */
    --qwg-green-50: #e5f6cf;
    --qwg-green-100: #c6ec9f;
    --qwg-green-200: #b5e38f;
    --qwg-green-300: #8fd067;
    --qwg-green-400: #6db84d;
    --qwg-green-text: #20351f;
}

#quran-word-game {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0 auto; /* Remove top margin to position at top */
    padding: 0;
    background: #c4ed9f; /* same darker green as start screen */
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    position: relative;
    min-height: 100vh; /* Full viewport height */
    height: auto;
    overflow: visible; /* allow sticky header to pin while page scrolls */
    border: 1px solid var(--qwg-green-50);
    font-size: 14px; /* 30% smaller than 20px */
    width: 100%; /* Use full available width from theme */
    max-width: none; /* Remove fixed max-width constraint */
    transition: max-width 0.3s ease; /* smooth transition */
}

#quran-word-game * {
    box-sizing: border-box;
}

/* Game screens */
.game-screen {
    display: none;
    width: 100%;
    min-height: 400px;
    height: auto;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.game-screen.active {
    display: flex;
    flex-direction: column;
    gap: 0;
    opacity: 1;
}

/* Start screen - standard width */
#start-screen {
    display: flex;
    flex-direction: column;
    justify-content: center; /* center all content in the middle */
    align-items: center;
    text-align: center;
    padding: 30px;
    min-height: 500px;
    background: #c4ed9f; /* uniform green color like in image */
    color: var(--qwg-green-text);
    position: relative;
    border: 10px solid #e5f6cb;
    box-sizing: border-box;
}

/* Mute button in top right corner */
.mute-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s ease;
    z-index: 10;
}

.mute-button:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.6);
}

.mute-icon {
    display: block;
    line-height: 1;
}

.mute-line {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 25px;
    background: #ff0000;
    transform: translate(-50%, -50%) rotate(45deg);
    display: none;
}

.mute-button.muted .mute-line {
    display: block;
}


/* When start screen is active, limit container size and match background */
#quran-word-game:has(#start-screen.active),
#quran-word-game.start-screen-active {
    max-width: 1000px; /* wider width for start screen */
    height: auto; /* allow natural height */
    margin: 20px auto; /* add some top margin */
    background: #e5f6cb; /* match border color */
}

/* When game screen is active, use full size */
#quran-word-game:has(#game-screen.active),
#quran-word-game.game-screen-active {
    max-width: none; /* full width for game screen */
    width: 100%;
    min-height: auto; /* let content determine height */
    height: auto; /* natural content height */
    margin: 0 auto; /* no top margin for game */
}

/* Text container positioned above middle */
.intro-text {
    text-align: center !important;
    margin-bottom: 60px; /* increased spacing pushes text higher in centered layout */
    padding-top: 0; /* remove extra padding since we're centering everything */
}

.intro-text p {
    color: var(--qwg-green-text);
    font-size: 1.38em; /* increased by 20% (1.15em * 1.2 = 1.38em) */
    line-height: 1.6;
    margin-bottom: 15px; /* space between paragraphs */
    max-width: 520px;
    font-weight: 400;
    text-align: center !important; /* ensure override */
    margin-left: auto;
    margin-right: auto;
    display: block; /* ensure proper block display */
}

.intro-text p:last-of-type {
    margin-bottom: 15px; /* normal spacing between paragraphs */
    font-weight: 700; /* make second paragraph ("Can you guess them correctly?") bold */
}

/* Button container positioned below middle */
.intro-button {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 0; /* no extra margin since parent is centering everything */
    padding-top: 0; /* no extra padding needed */
}

/* Retro metal/chrome 3D button */
.primary-button {
    background: linear-gradient(145deg, 
        #f8f8f8 0%, 
        #e8e8e8 15%, 
        #d0d0d0 35%, 
        #c0c0c0 50%, 
        #b8b8b8 65%, 
        #a8a8a8 85%, 
        #989898 100%);
    color: #4a4a4a; /* darker gray text for embossed effect */
    border: 3px solid #888888;
    border-top-color: #cccccc;
    border-left-color: #cccccc;
    border-right-color: #666666;
    border-bottom-color: #666666;
    padding: 18px 21px;
    font-size: 2.84em;
    font-weight: 900; /* very bold for embossed look */
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 2px; /* wider spacing for retro look */
    min-width: 277px;
    white-space: nowrap;
    text-shadow: 
        1px 1px 0 rgba(255,255,255,0.8), /* light emboss highlight */
        -1px -1px 0 rgba(0,0,0,0.3); /* dark emboss shadow */
    box-shadow: 
        inset 4px 4px 8px rgba(255,255,255,0.6), /* top-left bevel */
        inset -4px -4px 8px rgba(0,0,0,0.4), /* bottom-right bevel */
        inset 2px 2px 4px rgba(255,255,255,0.9), /* inner top highlight */
        inset -2px -2px 4px rgba(0,0,0,0.2), /* inner bottom shadow */
        0 6px 12px rgba(0,0,0,0.3), /* outer drop shadow */
        0 2px 4px rgba(0,0,0,0.2); /* subtle outer shadow */
    margin-top: 0;
}

.primary-button:hover {
    transform: translateY(-1px);
    background: linear-gradient(145deg, 
        #fafafa 0%, 
        #eeeeee 15%, 
        #d8d8d8 35%, 
        #c8c8c8 50%, 
        #c0c0c0 65%, 
        #b0b0b0 85%, 
        #a0a0a0 100%);
    text-shadow: 
        1px 1px 0 rgba(255,255,255,0.9), 
        -1px -1px 0 rgba(0,0,0,0.4);
    box-shadow: 
        inset 5px 5px 10px rgba(255,255,255,0.7), 
        inset -5px -5px 10px rgba(0,0,0,0.5), 
        inset 3px 3px 6px rgba(255,255,255,0.95), 
        inset -3px -3px 6px rgba(0,0,0,0.3), 
        0 8px 16px rgba(0,0,0,0.35), 
        0 4px 8px rgba(0,0,0,0.25);
}

.primary-button:active {
    transform: translateY(2px);
    background: linear-gradient(145deg, 
        #d0d0d0 0%, 
        #c0c0c0 15%, 
        #a8a8a8 35%, 
        #989898 50%, 
        #909090 65%, 
        #808080 85%, 
        #707070 100%);
    border-top-color: #666666;
    border-left-color: #666666;
    border-right-color: #cccccc;
    border-bottom-color: #cccccc;
    text-shadow: 
        -1px -1px 0 rgba(255,255,255,0.5), 
        1px 1px 0 rgba(0,0,0,0.6);
    box-shadow: 
        inset -2px -2px 4px rgba(255,255,255,0.4), 
        inset 2px 2px 4px rgba(0,0,0,0.6), 
        inset -1px -1px 2px rgba(255,255,255,0.7), 
        inset 1px 1px 2px rgba(0,0,0,0.4), 
        0 2px 4px rgba(0,0,0,0.2);
}

/* Top bar */
#top-bar {
    background: var(--qwg-green-300);
    color: #0f2a12;
    padding: 4px 20px; /* slightly thinner - reduced from 6px to 4px */
    margin: 0; /* no auto margin for sticky positioning */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.25);
    border-radius: 8px; /* rounded corners like Exit button */
    position: sticky; /* back to sticky to respect container width */
    top: 0; /* stick to top of container */
    width: 100%; /* use full container width, not viewport */
    z-index: 999999; /* extremely high z-index */
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.top-bar-left,
.top-bar-right {
    flex: 1;
}

.top-bar-center {
    flex: 0 0 auto; /* don't grow or shrink */
    display: flex;
    justify-content: center;
}

.top-bar-right {
    display: flex;
    justify-content: flex-end;
}

.icon-button {
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #0f2a12;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.125em; /* increased by 25% (0.9em * 1.25 = 1.125em) */
    transition: all 0.2s ease;
    font-weight: 600;
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.7);
}

/* Score percentage in center - lighter green background */
#score-percentage {
    font-weight: 700;
    font-size: 1.1875em; /* increased by 25% (0.95em * 1.25 = 1.1875em) */
    color: #0f2a12;
    background: var(--qwg-green-100); /* lighter green background */
    padding: 8px 20px; /* More padding for prominence */
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.65);
    white-space: nowrap; /* Prevent text wrapping */
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Score fraction on the right */
#score-fraction {
    font-weight: 700;
    font-size: 1.1875em; /* same size as percentage */
    color: #0f2a12;
    background: rgba(255, 255, 255, 0.5);
    padding: 6px 16px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.65);
    white-space: nowrap;
    text-align: center;
}

/* Game content */
#game-content {
    background: var(--qwg-green-50);
    padding-top: 62px; /* slightly reduced padding for thinner top bar */
    padding-left: 20px;
    padding-right: 20px;
    padding-bottom: 28px;
    min-height: 200px;
    max-height: none;
    height: auto;
    position: relative;
    z-index: 1; /* lower than top bar */
}

/* Loading state */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    font-size: 1.2em;
    color: #666;
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Surah content */
#surah-title {
    color: var(--qwg-green-text);
    font-size: 19.2px !important; /* decreased by 20% (24px * 0.8 = 19.2px) */
    font-weight: 700;
    margin-bottom: 24px;
    text-align: center;
    padding: 12px 18px;
    background: var(--qwg-green-100);
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

#verses-container {
    line-height: 1.62; /* 10% tighter than 1.8 */
    font-size: 1.404em; /* increased by 20% (1.17em * 1.2 = 1.404em) */
    color: #1f2937;
    position: relative;
    z-index: 2; /* below top bar but above background */
}

.verse {
    margin-bottom: 2px; /* Much closer spacing between verses */
    padding: 0;
    background: transparent;
    border-radius: 0;
    border: none;
}

.verse-marker {
    font-weight: 700;
    color: #2f6f37;
    background: rgba(47, 111, 55, 0.12);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Word inputs */
.word-input {
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1em; /* inherit 14px */
    font-family: inherit;
    background: #ffffff;
    min-width: 80px;
    max-width: none; /* allow expansion for long revealed words */
    width: auto;
    margin: 0 4px 4px 0;
    transition: all 0.3s ease;
    display: inline-block;
    position: relative;
    z-index: 3; /* below top bar but above other content */
    cursor: text;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    white-space: nowrap; /* prevent line wrap inside input */
}

.word-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
}

/* Feedback states */
.word-input.correct {
    background-color: #f0fdf4 !important;
    border-color: #22c55e !important;
    color: #15803d;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.1);
}

.word-input.incorrect {
    background-color: #fef2f2 !important;
    border-color: #ef4444 !important;
    color: #000000 !important; /* black text for incorrect answers */
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
}

.word-input:read-only {
    cursor: default;
    background-color: #f8fafc;
}

/* Responsive Design */

/* Mobile phones (up to 480px) */
@media (max-width: 480px) {
    #quran-word-game {
        padding: 10px;
        margin: 10px;
        border-radius: 8px;
        min-height: 300px;
    }
    
    #start-screen {
        border: 1px solid #e5f6cb; /* 1px border on mobile */
    }
    
    /* Make header full width on mobile to match content area */
    #top-bar {
        position: fixed;
        left: 0;
        right: 0;
        width: 100vw;
        margin: 0;
        /* Fix Chrome mobile hiding header issue */
        transform: translateZ(0); /* Force hardware acceleration */
        will-change: transform; /* Hint browser to optimize */
        -webkit-transform: translateZ(0); /* WebKit prefix for older browsers */
        /* Additional Chrome mobile fixes */
        -webkit-backface-visibility: hidden; /* Prevent flicker */
        backface-visibility: hidden;
        /* Use device pixels instead of viewport units */
        top: env(safe-area-inset-top, 0); /* Respect safe areas */
    }
    
    .intro-content h2 {
        font-size: 1.6em;
    }
    
    .intro-content p {
        font-size: 0.95em;
    }
    
    .primary-button {
        padding: 14px 29px;
        font-size: 2.27em;
        min-width: 204px;
    }
    
    #top-bar {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    #game-content {
        padding: 20px 8px; /* reduced horizontal padding for wider text area */
        min-height: 150px;
    }
    
    #surah-title {
        font-size: 19.2px !important; /* decreased by 20% to match desktop */
        margin-bottom: 20px;
    }
    
    #verses-container {
        font-size: 1.404em; /* increased by 20% to match desktop */
        line-height: 1.62; /* Match desktop line spacing */
    }
    
    .verse {
        margin-bottom: 2px; /* Match desktop - much closer spacing */
        padding: 10px 0;
    }
    
    .word-input {
        min-width: 60px;
        max-width: none;
        padding: 6px;
        font-size: 1em; /* inherit 14px */
        margin: 2px 1px;
    }
}

/* Desktop screens - fix start screen height */
@media (min-width: 481px) {
    #quran-word-game:has(#start-screen.active),
    #quran-word-game.start-screen-active {
        min-height: auto; /* remove fixed height for natural sizing */
    }
}

/* Tablets (481px to 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    #quran-word-game {
        padding: 15px;
        margin: 15px;
    }
    
    .intro-content h2 {
        font-size: 2em;
    }
    
    #game-content {
        padding: 25px 20px;
    }
    
    #surah-title {
        font-size: 1.6em;
    }
    
    .word-input {
        min-width: 70px;
        max-width: 130px;
    }
}

/* Small desktops (769px to 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Use full theme width - no max-width constraint */
}

/* Large desktops (1025px and up) */
@media (min-width: 1025px) {
    /* Use full theme width - no max-width constraint */
    
    .intro-content h2 {
        font-size: 2.2em;
    }
    
    .intro-content p {
        font-size: 1.05em;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .word-input {
        border-width: 1px;
    }
    
    .verse-marker {
        padding: 3px 7px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .primary-button,
    .icon-button {
        min-height: 44px;
        min-width: 44px;
    }
    
    .word-input {
        min-height: 40px;
        font-size: 1em; /* inherit 14px */
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #start-screen {
        padding: 20px;
    }
    
    .intro-content h2 {
        font-size: 1.6em;
        margin-bottom: 15px;
    }
    
    .intro-content p {
        font-size: 0.95em;
        margin-bottom: 20px;
    }
    
    #game-content {
        padding: 15px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #quran-word-game {
        background: #2c3e50;
        color: #ecf0f1;
    }
    
    #game-content {
        background: #34495e;
        color: #ecf0f1;
    }
    
    #surah-title {
        color: #ecf0f1;
        border-bottom-color: #4a5f7a;
    }
    
    #verses-container {
        color: #bdc3c7;
    }
    
    .word-input {
        background: #4a5f7a;
        border-color: #5a6f8a;
        color: #ecf0f1;
    }
    
    .word-input:focus {
        border-color: #667eea;
        background: #5a6f8a;
    }
    
    .intro-content h2 {
        color: #ecf0f1;
    }
    
    .intro-content p {
        color: #bdc3c7;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus indicators for keyboard navigation */
.word-input:focus-visible,
.primary-button:focus-visible,
.icon-button:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* Completion Screen */
#completion-screen {
    /* Styles are now inline in HTML for better reliability */
}

#completion-screen.active {
    display: flex !important;
}

.completion-content {
    background: #ffffff;
    border-radius: 16px;
    padding: 60px 40px;
    text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
    border: 3px solid #8fd067; /* Fallback */
    border: 3px solid var(--qwg-green-300);
    max-width: 450px;
    width: 100%;
}

#completion-title {
    color: var(--qwg-green-text);
    font-size: 2.2em;
    font-weight: 700;
    margin-bottom: 30px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.completion-score {
    margin: 30px 0 40px;
}

.completion-score p {
    color: var(--qwg-green-text);
    font-size: 1.8em;
    font-weight: 600;
    margin: 0;
}

#completion-percentage {
    color: var(--qwg-green-400);
    font-size: 1.3em;
    font-weight: 800;
}

.secondary-button {
    background: linear-gradient(145deg, #f8f9fa, #e9ecef);
    color: #495057;
    border: 2px solid #dee2e6;
    padding: 12px 24px;
    font-size: 1.1em;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 15px;
    width: 100%;
}

.secondary-button:hover {
    background: linear-gradient(145deg, #e9ecef, #dee2e6);
    border-color: #adb5bd;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.secondary-button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Mobile responsiveness for completion screen */
@media (max-width: 480px) {
    .completion-content {
        padding: 40px 20px;
        margin: 10px;
    }
    
    #completion-title {
        font-size: 1.8em;
    }
    
    .completion-score p {
        font-size: 1.5em;
    }
    
    #completion-percentage {
        font-size: 1.2em;
    }
    
    .primary-button {
        font-size: 1.8em;
        padding: 14px 20px;
    }
    
    .secondary-button {
        font-size: 1em;
        padding: 10px 16px;
    }
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
