:root {
    --cell-size: 60px;
    --gap: 2px;
    --primary-color: #2c3e50;
    --highlight-color: #f39c12;
    --bg-color: #ecf0f1;
    --cell-bg: #ffffff;
    --cell-border: #bdc3c7;
    --header-height: 120px;
    --controls-height: 80px;
    --footer-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--primary-color);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0.5rem;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    flex-shrink: 0;
    padding: 0.5rem 0;
}

h1 {
    font-size: clamp(1.5rem, 4vmin, 2.5rem);
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.875rem;
    text-transform: uppercase;
    color: #7f8c8d;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
}

.loading {
    text-align: center;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    max-height: 100%;
    min-height: 0;
    flex-shrink: 1;
}

.game-grid {
    display: grid;
    gap: var(--gap);
    touch-action: none;
    user-select: none;
    cursor: grab;
    flex-shrink: 1;
    padding: 4px; /* Prevent border clipping on edge cells (2px border + rounding) */
}

.game-grid.dragging {
    cursor: grabbing;
}

.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--cell-size) * 0.5);
    font-weight: bold;
    background: var(--cell-bg);
    border: 2px solid var(--cell-border);
    border-radius: 4px;
    width: var(--cell-size);
    height: var(--cell-size);
    user-select: none;
    transition: background-color 0.2s, border-color 0.2s, transform 0.3s ease-out;
    text-transform: uppercase;
}

.cell.word {
    /* Color is set via inline styles for per-word coloring */
    /* Fallback color if no inline style is set */
    background-color: var(--highlight-color);
    border-color: darkorange;
    color: white;
}

.controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
}

.btn:hover:not(:disabled) {
    background-color: #34495e;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

footer {
    text-align: center;
    padding: 0.5rem 0;
    color: #7f8c8d;
    font-size: 0.875rem;
    flex-shrink: 0;
}

/* Mobile optimizations */
@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }
    
    .stats {
        gap: 1rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
}

/* Landscape mobile */
@media (max-width: 900px) and (orientation: landscape) {
    h1 {
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
    }
    
    .stats {
        gap: 1rem;
    }
    
    .stat-label {
        font-size: 0.625rem;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    header {
        padding: 0.25rem 0;
    }
    
    footer {
        padding: 0.25rem 0;
    }
    
    .game-container {
        gap: 0.5rem;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 1024px) {
    .container {
        padding: 0.75rem;
    }
}

/* Desktop */
@media (min-width: 1025px) {
    .container {
        padding: 1rem;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .cell {
        transition: none;
    }
}
