:root {
    --bg: #f6f8fb;
    --card: #ffffff;
    --muted: #6b7280;
    --accent: #6aad91;
    --accent-600: #47704c;
    --text-color: #000000;
}

* {
    box-sizing: border-box;
}

body {
    font-family: Inter, Segoe UI, Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text-color);
    margin: 0;
    min-height: 100vh;
}

.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

.site-header {
    width: 100%;
    min-height: 60px; /* Reduced from 80px for mobile friendliness */
    background: var(--accent);
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
}

.site-header h1 {
    font-size: 1.5rem; /* Explicit size tracking for consistency across devices */
    margin: 0;
}

main {
    flex: 1;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.hero {
    width: 100%;
    max-width: 1200px; 
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-shell {
    border-radius: 8px;
    background-color: var(--accent-600);
    width: 100%; 
    max-width: 600px; /* Allows the card to grow wider on PC */
    height: auto;
    padding-bottom: 1.5rem;
    display: flex;
    align-items: center;
    flex-direction: column;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.game-header {
    width: 100%;
    min-height: 50px;
    background: var(--accent);
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-content {
    width: 100%;
    padding: 12px; /* Snugger layout frames */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

/* Score Panel Mobile Grid Realignment */
.score-display-panel {
    display: grid !important; /* Forces a tidy layout even if overriden by inline styling */
    grid-template-columns: repeat(2, 1fr); /* 2x2 grid layout format */
    gap: 10px !important;
    width: 100%;
    font-size: 0.9rem !important; /* Shrinks fonts down to prevent clumsy line-breaks */
    text-align: center;
}

.Crossword-Rand {
    background: #000000;
    width: 100%;
    max-width: 500px; /* Expanded from 100% so it's not tiny on PC */
    aspect-ratio: 1 / 1; 
    display: grid;
    grid-template-columns: repeat(var(--grid-cols), 1fr);
    grid-template-rows: repeat(var(--grid-rows), 1fr);
    gap: 1px;
    border: 4px solid #000000;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    margin: 20px auto;
    box-sizing: border-box;
    position: relative;
}

.crossword-cell {
    background-color: #000000;
    position: relative;
    aspect-ratio: 1 / 1; 
}

.crossword-cell.active {
    background-color: var(--card);
}

.crossword-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--text-color);
    outline: none;
    padding: 0;
    caret-color: transparent;
    -webkit-appearance: none;
    appearance: none;         
    border-radius: 0;
}

.crossword-input:focus {
    background-color: #fef08a;
}

.crossword-cell.valid-word {
    background-color: #d1fae5 !important;
}

.crossword-cell.valid-word .crossword-input {
    background-color: #d1fae5 !important;
}

.crossword-cell.valid-word .crossword-input:focus {
    background-color: #fef08a !important;
}

.cell-number {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 0.55rem;
    color: #475569;
    font-weight: bold;
    line-height: 1;
    pointer-events: none;
    z-index: 2; /* Ensures visibility over highlighted blocks */
}

/* Full frame victory celebration splash container overlay screen */
#victory-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.97);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    text-align: center;
    z-index: 12;
    border-radius: 4px;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

#victory-overlay.show-win {
    opacity: 1;
    pointer-events: auto;
}

#play-again-btn {
    padding: 12px 30px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #ffffff;
    background: #10b981;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    margin-top: 20px;
    transition: background 0.2s ease, transform 0.1s ease;
}

#play-again-btn:hover {
    background: #059669;
}

#play-again-btn:active {
    transform: scale(0.98);
}

.site-footer {
    display: flex;
    align-items: center;
    gap: 0.35rem;        
    font-size: 0.8rem;
    color: #64748b;
    width: 100%;
    justify-content: center;
    padding: 1.5rem 0;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    background: var(--bg);
}

.site-footer a {
    color: #38bdf8;
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}

#start-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.96);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    text-align: center;
    z-index: 20; /* Raised from 10 to clear all baseline grid elements */
    border-radius: 4px;
    padding: 20px;
    box-sizing: border-box;
    pointer-events: auto; /* Explicitly forces mobile tap layers to register clicks */
}


#start-btn {
    padding: 12px 30px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #ffffff;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    transition: background 0.2s ease, transform 0.1s ease;
}

#start-btn:hover {
    background: var(--accent-600);
}

#start-btn:active {
    transform: scale(0.98);
}

.theme-badge-container {
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    font-size: 0.9rem !important; /* Prevents overflow inside narrow spaces */
}

#start-btn, #play-again-btn {
    touch-action: manipulation; /* Removes mobile double-tap delay for immediate activation */
    -webkit-tap-highlight-color: transparent; /* Removes blue flashing block on mobile taps */
}

@media (min-width: 650px) {
    /* Main wrapper setup */
    main {
        padding: 1.5rem; /* Reduced to pull layout up and avoid vertical scrolling */
        height: calc(100vh - 60px); /* Locks content height dynamically into standard browser screens */
        display: flex;
        align-items: center;
    }

    .game-shell {
        width: 90%; /* Expands container footprint horizontally to fill the viewport width */
        max-width: 950px; /* Wider landscape layout profile */
        padding-bottom: 1.5rem;
        padding-top: 1rem;
    }

    .game-content {
        padding: 20px 40px; 
        gap: 15px; /* Tighter layout gap structures to maintain alignment visibility */
    }

    .theme-badge-container {
        font-size: 1.2rem !important; 
        padding: 8px 20px !important;
    }

    .score-display-panel {
        display: flex !important;
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
        max-width: 600px; /* Centered metric balance profiles */
        font-size: 1.2rem !important; 
        margin: 5px 0;
    }
    
    .Crossword-Rand {
        width: 100%;
        max-width: 520px; /* Constrains vertical height to completely prevent scrolling */
        border: 5px solid #000000;
        margin: 5px auto;
    }

    .crossword-input {
        font-size: 1.4rem; 
    }

    .cell-number {
        font-size: 0.7rem; 
        top: 2px;
        left: 3px;
    }

    .site-header h1 {
        font-size: 2.2rem;
    }
}
