:root {
    --main-gradient: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    --accent: #00d2ff;
    --grid-blocked: rgba(0, 0, 0, 0.6);
    --cell-bg: #ffffff;
    --text-dark: #2c3e50;
    --highlight-word: #e0f7fa;
    --highlight-cell: #ffd54f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
    background: var(--main-gradient);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px; /* Reduced padding for mobile */
    overflow-x: hidden;
}

header { 
    width: 100%; 
    max-width: 600px; 
    text-align: center; 
    margin-bottom: 20px; 
}

h1 { font-size: clamp(1.5rem, 5vw, 2.5rem); margin-bottom: 10px; }

.controls {
    display: flex; 
    flex-wrap: wrap;
    gap: 10px; 
    justify-content: center; 
    background: rgba(255,255,255,0.1); 
    padding: 10px; 
    border-radius: 12px; 
    backdrop-filter: blur(10px);
}

select, button {
    padding: 8px 15px; 
    border-radius: 6px; 
    border: none; 
    font-weight: bold; 
    cursor: pointer;
    font-size: 0.9rem;
}

/* THE RESPONSIVE ENGINE */
.game-container { 
    display: flex; 
    flex-direction: row; /* Desktop default */
    gap: 20px; 
    width: 100%; 
    max-width: 1200px;
    justify-content: center;
}

.grid-section { 
    flex: 2;
    max-width: 600px; /* Prevents board from becoming giant on huge monitors */
    width: 100%;
    position: relative;
}

.grid-board {
    display: grid; 
    background: var(--grid-blocked); 
    padding: 5px;
    border-radius: 8px; 
    gap: 1.5px; /* Thinner lines for better fit */
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    width: 100%; /* Fills the grid-section */
}

.cell { 
    width: 100%; 
    aspect-ratio: 1 / 1; /* Magic: Keeps cells perfectly square regardless of width */
    background: var(--cell-bg); 
    position: relative; 
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell.blocked { background: transparent; }

.cell-input {
    width: 100%; 
    height: 100%; 
    border: none; 
    text-align: center;
    font-size: clamp(0.8rem, 3vw, 1.3rem); /* Text scales with cell size */
    font-weight: bold; 
    text-transform: uppercase;
    background: transparent; 
    outline: none; 
    color: var(--text-dark);
}

.clue-number {
    position: absolute; 
    top: 1px; 
    left: 2px; 
    font-size: clamp(0.5rem, 1.5vw, 0.7rem); 
    color: #7f8c8d;
    pointer-events: none;
}

/* CLUE SECTION RESPONSIVENESS */
.clues-section {
    flex: 1; 
    background: rgba(255,255,255,0.95); 
    color: var(--text-dark);
    padding: 15px; 
    border-radius: 12px; 
    max-height: 600px; 
    overflow-y: auto;
    width: 100%;
}

.clue-column h3 { 
    border-bottom: 2px solid var(--accent); 
    margin: 15px 0 10px 0; 
    color: #2c5364; 
    font-size: 1.1rem;
}

.clue-item { 
    padding: 8px; 
    border-radius: 4px; 
    cursor: pointer; 
    font-size: 0.85rem;
    border-bottom: 1px solid #eee;
}

.clue-item.active-clue { background: var(--accent); color: white; }

/* SELECTION STATES */
.cell.highlight-word { background: var(--highlight-word); }
.cell.active { background: var(--highlight-cell); }

/* MOBILE BREAKPOINT */
@media (max-width: 800px) {
    .game-container { 
        flex-direction: column; /* Grid on top, clues on bottom */
        align-items: center; 
    }
    
    .grid-section {
        max-width: 95vw; /* Grid takes almost full width on phone */
    }

    .clues-section {
        max-height: 300px; /* Shorter clue list on mobile to save space */
    }
}

/* UTILITIES */
.loading-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.8); display: flex; flex-direction: column;
    justify-content: center; align-items: center; z-index: 5;
}

.hidden { display: none !important; }