/* Krokodil Game Styles */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;700;900&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-dark: #0f1016;
    --primary: #22c55e; /* Green Theme */
    --secondary: #10b981;
    --correct: #22c55e;
    --skip: #ef4444;
}

html, body {
    height: 100dvh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Outfit', sans-serif;
    background-color: #09090b;
    background-image: radial-gradient(circle at center, #064e3b, #09090b);
    background-attachment: fixed;
    color: white;
}

/* Screen wrapper toggles */
.screen {
    position: fixed;
    inset: 0;
    display: none; /* Prevent overlap touch intercepts */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: max(2rem, env(safe-area-inset-top)) max(2rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(2rem, env(safe-area-inset-left));
    z-index: 10;
}

.screen.active {
    display: flex; /* Show only when active */
    z-index: 20;
}

/* Glassmorphism containers */
.glass-panel {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(12px);
    border: 1px border rgba(255, 255, 255, 0.05);
    border-radius: 24px;
    padding: 2rem;
    width: 100%;
    max-width: 450px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Logo Styles */
.logo-container {
    background: #022c22;
    padding: 0.5rem;
    border-radius: 28px;
    width: 140px;
    height: 140px;
    margin: 0 auto 2rem auto;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 15px 35px rgba(0,0,0,0.15);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.main-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: brightness(0) invert(1);
}


/* Text styles */
h1 {
    font-size: clamp(2.3rem, 9vw, 3.5rem);
    font-weight: 900;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
    letter-spacing: -2px;
}

p.subtitle {
    color: #a1a1aa;
    margin-bottom: 2.5rem;
    font-size: 1.1rem;
}

/* Category Grid */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    margin-bottom: 2rem;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.category-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 1.25rem;
    border-radius: 16px;
    font-weight: 700;
    font-size: 1.05rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.category-btn.selected {
    border-color: var(--primary);
    background: rgba(192, 132, 252, 0.15);
    box-shadow: 0 0 20px rgba(192, 132, 252, 0.2);
}

/* Action Buttons */
.btn-primary {
    background: linear-gradient(135deg, #22c55e 0%, #15803d 100%);
    border: none;
    color: white;
    padding: 1.25rem 2rem;
    border-radius: 24px;
    font-weight: 800;
    font-size: 1.25rem;
    width: 100%;
    cursor: pointer;
    transition: transform 0.2s;
    box-shadow: 0 10px 25px -5px rgba(34, 197, 94, 0.4);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-subtle {
    background: transparent;
    border: none;
    color: #71717a;
    font-size: 0.9rem;
    cursor: pointer;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #a1a1aa;
    padding: 0.85rem 1.25rem;
    border-radius: 24px;
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    width: 100%;
    margin-top: 0.75rem;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transform: translateY(-1px);
}


/* Countdown */
#countdown-screen .circle-number {
    font-size: 8rem;
    font-weight: 900;
    color: var(--primary);
    text-shadow: 0 0 30px rgba(192, 132, 252, 0.4);
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(0.9); }
    100% { transform: scale(1.1); }
}

/* Game Screen */
#game-screen {
    background: #000;
    /* Restore safe-area padding but strip the 2rem menu padding */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    justify-content: space-between;
}

.game-header {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 1.5rem;
    font-weight: 700;
    color: #a1a1aa;
    z-index: 30;
}

#game-timer { justify-self: start; }
#game-score { justify-self: center; text-align: center; }
.btn-end-round { justify-self: end; }

#game-timer, #game-score {
    font-size: 1.4rem;
    color: white;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums; /* Prevent text moves on number update */
}

.word-display {
    text-align: center;
    padding: 1rem;
    z-index: 30;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.word-display h2 {
    font-size: 5rem;
    font-weight: 900;
    line-height: 1.1;
    word-break: normal; /* Do not break mid-word */
    overflow-wrap: normal; /* Do not break single words to wrap */
    letter-spacing: -1px;
    transition: opacity 0.2s ease;
    max-width: 100%;
    min-width: 0; /* Allow flex item to shrink below content size */
}

.game-feedback {
    position: absolute;
    inset: 0;
    z-index: 25;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.game-feedback.correct {
    background: radial-gradient(circle, rgba(34, 197, 94, 0.4) 0%, rgba(0,0,0,0.8) 100%);
    opacity: 1;
}

.game-feedback.skip {
    background: radial-gradient(circle, rgba(239, 68, 68, 0.4) 0%, rgba(0,0,0,0.8) 100%);
    opacity: 1;
}

/* Score Screen */
.score-summary {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 0.5rem;
    color: var(--correct);
    margin: 1rem 0 1.5rem 0;
}

.score-tally {
    font-size: 4rem;
    font-weight: 900;
    line-height: 1;
}

.score-label {
    font-size: 1.5rem;
    font-weight: 800;
}


.score-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

/* Responsive Font Scaling for Portrait Mode */
@media (orientation: portrait) {
    .word-display h2 {
        font-size: clamp(1.8rem, 14vw, 3.2rem); /* Scale to fit portrait viewports */
    }
}

/* Manual Controls Row alignment */
.manual-controls {
    display: flex;
    gap: 0.75rem; /* Tighter gap for 3 buttons */
    padding: 1.5rem;
    width: 100%;
    z-index: 30;
}

.btn-action {
    flex: 1;
    padding: 1.25rem 0.5rem; /* shorter height button */
    border-radius: 16px;
    border: none;
    font-size: 1.25rem;
    font-weight: 800;
    color: white;
    cursor: pointer;
    transition: transform 0.1s;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-action.skip {
    background: linear-gradient(135deg, #ef4444 0%, #991b1b 100%);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-action.correct {
    background: linear-gradient(135deg, #22c55e 0%, #166534 100%);
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.3);
}

.btn-action.hint {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-action:active {
    transform: scale(0.95);
}

/* Statistics list breakdown styles */
.stats-container {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 1rem;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 1.5rem;
    text-align: left;
}

.stats-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* Prevent horizontal overflow */
    gap: 0.5rem;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.95rem;
}

.stats-item:last-child {
    border-bottom: none;
}

.stats-item .word {
    font-weight: 700;
    color: #f4f4f5;
    flex: 1;
    min-width: 0;
    word-break: normal; /* Do not break mid-word in stats either */
}

.stats-item .status {
    font-weight: 800;
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
}

.stats-item .status.guessed { color: var(--correct); }
.stats-item .status.skipped { color: var(--skip); }
.stats-item .hint-badge {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.5rem;
}

/* Hint Container */
.hint-container {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 1rem;
    margin-top: 1.5rem;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

.hint-container p {
    color: #e4e4e7;
    font-size: 1.05rem;
    line-height: 1.4;
    font-weight: 400;
}

/* Backported styles from index.html */
.btn-end-round {
    margin: 0;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    font-weight: 700;
    background: rgba(220, 38, 38, 0.1);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.btn-end-round:active {
    background: rgba(220, 38, 38, 0.2);
    transform: scale(0.95);
}

.word-hidden {
    opacity: 0 !important;
    pointer-events: none;
}

/* Utils Helpers */
.hidden {
    display: none !important;
}

.carousel-wrapper {
    display: contents; /* Direct grid pass-through for portrait */
}

.carousel-btn {
    display: none; /* Hide in portrait default flow */
}

/* Landscape Orientation Refinements */
@media (orientation: landscape) {
    .logo-container {
        display: none !important;
    }

    /* Shrink page elements for low-height viewports */

    .glass-panel {
        padding: 1rem !important;
    }
    
    h1 {
        font-size: 1.5rem !important;
        margin-bottom: 0.5rem !important;
        margin-top: 0 !important;
    }

    .carousel-wrapper {
        display: grid !important;
        grid-template-columns: 50px 1fr 50px !important;
        align-items: center !important;
        gap: 0.5rem;
        width: 100%;
        max-width: 450px;
        margin: 0 auto;
        margin-bottom: 2rem !important;
    }

    /* Carousel Track for Categories */
    #menu-screen .category-list {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: hidden !important;
        scroll-snap-type: x mandatory !important;
        scroll-behavior: smooth;
        width: 100% !important;
        gap: 0 !important;
        max-height: none !important;
        padding: 0 !important; /* Removed vertical padding causing misalignment */
        margin-bottom: 0 !important;
    }

    .category-list::-webkit-scrollbar {
        display: none; /* Hide scrollbar fully for arrows setup */
    }

    .category-btn {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        flex: 0 0 100% !important; /* Fits perfectly, no margin leakage */
        scroll-snap-align: center !important;
        margin: 0 !important;
        padding: 0 1rem !important; /* Zero top/bottom padding to let height control */
        height: 50px !important; /* Force 50px high */
        box-sizing: border-box;
    }

    .category-btn:hover {
        transform: none !important;
        background: rgba(192, 132, 252, 0.15); /* Keep strict select coloring on hover */
    }

    .carousel-btn {
        display: flex !important;
        background: rgba(16, 185, 129, 0.2);
        border: 1px solid rgba(16, 185, 129, 0.4);
        color: white;
        border-radius: 16px !important;
        width: 100% !important;
        height: 50px !important; /* Match exactly category-btn height lock */
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer;
        font-weight: bold;
        flex-shrink: 0;
        margin: auto 0; /* Ensures strict vertical centering within grid cell */
    }
    
    #menu-screen .glass-panel, #mode-screen .glass-panel {
        max-width: 550px;
        padding: 1rem 1.5rem; /* Shrink panel padding to fit perfectly */
    }

    #menu-screen h1, #mode-screen h1 {
        font-size: 1.8rem; /* Shrink header font sizes */
        margin-bottom: 0.25rem;
    }

    #game-subtitle {
        font-size: 0.95rem !important; /* Scale small text */
        margin-bottom: 0.5rem !important;
    }

    /* Scoreboard Screen side-by-side layout */
    #score-screen .glass-panel {
        display: flex;
        flex-direction: row;
        max-width: 750px;
        gap: 2rem;
        text-align: left;
        align-items: stretch;
        padding: 2rem;
    }

    #score-screen .score-info {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    #score-screen .stats-container {
        flex: 1.2;
        max-height: 280px;
        margin-top: 0;
    }

    #score-screen h1 {
        font-size: 2.5rem;
        margin-bottom: 0.25rem;
    }

    #score-screen .score-tally {
        margin: 0.5rem 0;
    }
}

/* Language Toggle Styles */
.language-toggle {
    position: fixed;
    top: max(1.5rem, calc(env(safe-area-inset-top) + 0.5rem));
    right: max(1.5rem, env(safe-area-inset-right));
    display: flex;
    gap: 0.25rem;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.3rem;
    border-radius: 25px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: opacity 0.3s ease;
}

.lang-btn {
    background: transparent;
    border: none;
    color: #a1a1aa;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.5px;
}

.lang-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

.lang-btn.active {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

/* Manage List Styles (Mobile Responsive) */
.manage-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    gap: 1rem;
}

.manage-list-info {
    flex: 1;
    min-width: 0;
}

.manage-list-info h3 {
    margin-bottom: 0.25rem;
    word-break: break-all;
}

.manage-list-info span {
    font-size: 0.8rem;
    color: #a1a1aa;
}

.manage-list-actions {
    display: flex;
    gap: 0.5rem;
}

.manage-list-actions button {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: bold;
}

.btn-view-cat { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.btn-toggle-hide { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.btn-delete-cat { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

@media (max-width: 480px) {
    .manage-list-item {
        flex-direction: column;
        align-items: stretch;
    }
    
    .manage-list-actions {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
    }
    
    .manage-list-actions button {
        padding: 0.75rem 0.25rem;
        font-size: 0.9rem;
    }
}

/* Hide toggle during active gameplay to prevent clutter */
.language-toggle.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Responsive adjustments for mobile portrait across all devices */
@media (orientation: portrait) {
    .manual-controls {
        gap: 0.5rem !important;
        padding: 1rem !important;
    }
    .btn-action {
        font-size: clamp(0.9rem, 3.8vw, 1.15rem) !important;
        padding: 1rem 0.25rem !important;
        min-width: 0 !important;
    }
}

/* Animations for Gemini Loading State */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.98); }
}

/* Manage Screen Position Adjustment */
#manage-screen {
    justify-content: flex-start !important;
    padding-top: calc(max(2rem, env(safe-area-inset-top)) + 3.5rem) !important;
}

#manage-screen .glass-panel {
    max-height: calc(100dvh - (max(2rem, env(safe-area-inset-top)) + 4.5rem)) !important;
}

/* Manage Actions Spacing */
.manage-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

@media (orientation: landscape) {
    .manage-actions {
        flex-direction: row !important;
    }
    .manage-actions button {
        flex: 1;
        padding: 0.75rem !important; /* Shrink padding a bit more to save vert space */
        font-size: 1rem !important;
    }
    #manage-screen .glass-panel h1 {
        font-size: 1.5rem !important;
    }
    #manage-screen .glass-panel {
        max-width: 650px !important;
    }
    .manage-lang-toggle {
        margin-bottom: 0.5rem !important; /* Save space */
    }
}

