/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px;
    margin: 0;
    overflow-x: hidden;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    color: white;
    padding: 15px 20px;
    text-align: center;
}

header h1 {
    font-size: 1.8em;
    margin-bottom: 5px;
    font-weight: 700;
}

header p {
    font-size: 0.9em;
    opacity: 0.9;
    margin: 0;
}

/* Phase containers */
.phase {
    padding: 15px 20px;
}

/* Center game phase content */
#game-phase {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Keep setup phase inputs full width */
#setup-phase {
    text-align: left;
}

#setup-phase h2 {
    text-align: center;
}

.hidden {
    display: none !important;
}

/* Category input styling */
.categories-input {
    display: grid;
    gap: 12px;
    margin-bottom: 15px;
}

.category-input {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.category-input label {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.95em;
}

.category-input input {
    padding: 8px 12px;
    border: 2px solid #e0e6ed;
    border-radius: 6px;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.category-input input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Creativity slider styling */
.creativity-slider-container {
    margin-bottom: 20px;
}

.slider-label {
    display: block;
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.95em;
    margin-bottom: 8px;
}

.slider-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.slider-min, .slider-max {
    font-size: 0.85em;
    color: #7f8c8d;
    font-weight: 500;
    min-width: 50px;
}

.creativity-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e0e6ed;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.creativity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3498db, #2980b9);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.creativity-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3498db, #2980b9);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.creativity-description {
    text-align: center;
    font-size: 0.85em;
    color: #3498db;
    font-weight: 600;
    font-style: italic;
}

/* Setup buttons */
.setup-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
}

/* Editing controls */
.editing-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* Checkbox styling */
.checkbox-container {
    margin-bottom: 20px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    color: #2c3e50;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #3498db;
}

.checkbox-label:hover {
    color: #1f4e79;
}

/* Button styling */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn.primary {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

.btn.primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #2980b9, #1f4e79);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.btn.secondary {
    background: linear-gradient(135deg, #27ae60, #219a52);
    color: white;
}

.btn.secondary:hover:not(:disabled) {
    background: linear-gradient(135deg, #219a52, #1e8449);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
}

.btn.tertiary {
    background: #95a5a6;
    color: white;
}

.btn.tertiary:hover {
    background: #7f8c8d;
}

.btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Word grid styling */
.word-grid {
    display: grid;
    gap: 5px;
    margin: 0 auto 15px auto;
    max-width: 384px;  /* 480px * 0.8 = 384px */
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

/* Editing phase grid layout with headers */
.word-grid.editing {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: auto auto auto auto auto auto auto auto auto auto auto auto auto auto auto auto auto auto auto auto;
}

/* Playing phase grid layout */
.word-grid.playing {
    grid-template-columns: repeat(4, 1fr);
}

.word-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    font-weight: 600;
    font-size: 0.75em;  /* 0.8em * 0.9 = 0.72em, rounded to 0.75em */
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    text-align: center;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    padding: 2px;
    min-height: 44px;  /* 55px * 0.8 = 44px */
    text-transform: uppercase;
    box-sizing: border-box;
    overflow: hidden;
}

/* Category headers */
.category-header {
    grid-column: 1 / -1;
    padding: 8px;
    margin: 5px 0;
    border-radius: 5px;
    font-weight: 700;
    font-size: 0.9em;
    text-align: center;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.category-header.yellow {
    background: linear-gradient(135deg, #f1c40f, #f39c12);
}

.category-header.green {
    background: linear-gradient(135deg, #27ae60, #229954);
}

.category-header.blue {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

.category-header.purple {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

/* Editing phase colors */
.word-grid.editing .word-cell {
    cursor: text;
}

.word-cell.yellow {
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    color: white;
}

.word-cell.green {
    background: linear-gradient(135deg, #27ae60, #229954);
    color: white;
}

.word-cell.blue {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

.word-cell.purple {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    color: white;
}

/* Playing phase styling */
.word-grid.playing .word-cell {
    background: #ecf0f1;
    color: #2c3e50;
    border: 2px solid #bdc3c7;
}

.word-grid.playing .word-cell:hover {
    background: #d5dbdb;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.word-cell.selected {
    background: #3498db !important;
    color: white !important;
    border-color: #2980b9 !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.word-cell.correct {
    color: white !important;
    animation: correctPulse 1.5s ease;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.word-cell.correct.yellow {
    background: linear-gradient(135deg, #f1c40f, #f39c12) !important;
}

.word-cell.correct.green {
    background: linear-gradient(135deg, #27ae60, #229954) !important;
}

.word-cell.correct.blue {
    background: linear-gradient(135deg, #3498db, #2980b9) !important;
}

.word-cell.correct.purple {
    background: linear-gradient(135deg, #9b59b6, #8e44ad) !important;
}

.word-cell.incorrect {
    background: #e74c3c !important;
    color: white !important;
    animation: incorrectShake 0.6s ease;
}

/* Completed groups */
.completed-groups {
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.completed-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px;
    margin-bottom: 5px;
    border-radius: 5px;
    font-weight: 600;
    font-size: 0.8em;
    color: white;
    animation: slideIn 0.5s ease;
    width: 100%;
    max-width: 384px;  /* Match the grid width */
    text-align: center;
}

.completed-group.yellow {
    background: linear-gradient(135deg, #f1c40f, #f39c12);
}

.completed-group.green {
    background: linear-gradient(135deg, #27ae60, #229954);
}

.completed-group.blue {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

.completed-group.purple {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

/* Game controls */
.game-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
    max-width: 384px;
    width: 100%;
}

#mistakes-count {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9em;
}

/* Messages */
.message {
    padding: 10px;
    border-radius: 6px;
    margin-top: 10px;
    font-weight: 600;
    font-size: 0.9em;
    text-align: center;
    transition: all 0.3s ease;
    min-height: 20px;
}

.message.success {
    background: #d5f4e6;
    color: #27ae60;
    border: 2px solid #27ae60;
}

.message.error {
    background: #fadbd8;
    color: #e74c3c;
    border: 2px solid #e74c3c;
}

.message.info {
    background: #fff3cd;
    color: #856404;
    border: 2px solid #ffc107;
}

/* Loading state */
.loading {
    text-align: center;
    padding: 20px;
    font-style: italic;
    color: #7f8c8d;
}

/* Animations */
@keyframes correctPulse {
    0% { transform: scale(1.05); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1.05); }
}

@keyframes incorrectShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes slideIn {
    0% { transform: translateY(-20px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* Input styling for editable cells */
.word-cell input {
    background: transparent;
    border: none;
    color: inherit;
    font: inherit;
    text-align: center;
    width: 100%;
    outline: none;
    text-transform: uppercase;
}

.word-cell input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        padding: 8px;
        overflow-x: hidden;
    }
    
    .container {
        margin: 0;
        border-radius: 8px;
        max-width: 100vw;
        box-sizing: border-box;
    }
    
    header {
        padding: 12px 15px;
    }
    
    header h1 {
        font-size: 1.6em;
    }
    
    header p {
        font-size: 0.85em;
    }
    
    .phase {
        padding: 15px 12px;
        box-sizing: border-box;
    }
    
    .word-grid {
        max-width: calc(100vw - 40px);
        width: 100%;
        gap: 6px;
        margin: 0 auto 15px auto;
        box-sizing: border-box;
    }
    
    .word-cell {
        font-size: 0.7em;
        padding: 4px 2px;
        min-height: 42px;
        line-height: 1.2;
        border-radius: 6px;
    }
    
    .game-controls {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 8px;
        margin-bottom: 15px;
        max-width: calc(100vw - 40px);
        width: 100%;
    }
    
    .btn {
        flex: 1;
        min-width: 80px;
        max-width: 120px;
        margin-bottom: 0;
        padding: 8px 10px;
        font-size: 0.75em;
        white-space: nowrap;
    }
    
    #mistakes-count {
        flex: 0 0 auto;
        font-size: 0.8em;
        margin: 0;
    }
    
    .checkbox-container {
        margin-bottom: 15px;
    }
    
    .checkbox-label {
        font-size: 0.85em;
    }
    
    .creativity-slider-container {
        margin-bottom: 15px;
    }
    
    .slider-label {
        font-size: 0.85em;
    }
    
    .creativity-description {
        font-size: 0.8em;
    }
    
    .editing-controls {
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }
    
    .editing-controls .btn {
        width: 100%;
        max-width: none;
        flex: none;
    }
    
    .setup-buttons {
        flex-direction: column;
        gap: 12px;
    }
    
    .setup-buttons .btn {
        width: 100%;
        max-width: none;
        flex: none;
    }
    
    .completed-group {
        padding: 8px;
        font-size: 0.8em;
        margin-bottom: 6px;
        max-width: calc(100vw - 40px);
        width: 100%;
        box-sizing: border-box;
    }
    
    .category-header {
        padding: 8px;
        font-size: 0.85em;
        margin: 5px 0;
    }
    
    .message {
        padding: 10px;
        font-size: 0.85em;
        margin-top: 10px;
        max-width: calc(100vw - 40px);
        width: 100%;
        box-sizing: border-box;
    }
}

@media (max-width: 480px) {
    body {
        padding: 4px;
    }
    
    .container {
        margin: 0;
        border-radius: 6px;
    }
    
    .phase {
        padding: 12px 8px;
    }
    
    .word-grid {
        max-width: calc(100vw - 24px);
        gap: 4px;
        margin: 0 auto 12px auto;
    }
    
    .word-cell {
        font-size: 0.65em;
        min-height: 38px;
        padding: 3px 1px;
        border-radius: 4px;
        line-height: 1.1;
    }
    
    header h1 {
        font-size: 1.4em;
    }
    
    header p {
        font-size: 0.8em;
    }
    
    .btn {
        font-size: 0.7em;
        padding: 6px 8px;
        min-width: 70px;
        max-width: 100px;
    }
    
    .game-controls {
        max-width: calc(100vw - 24px);
        gap: 6px;
    }
    
    #mistakes-count {
        font-size: 0.75em;
    }
    
    .completed-group {
        max-width: calc(100vw - 24px);
        padding: 6px;
        font-size: 0.75em;
    }
    
    .message {
        max-width: calc(100vw - 24px);
        padding: 8px;
        font-size: 0.8em;
    }
}

/* New Game button styling */
#new-game-btn {
    display: block;
    margin: 20px auto 0;
    text-align: center;
}

/* Large screens - make grid a bit bigger */
@media (min-width: 1024px) {
    .word-grid {
        max-width: 480px;  /* 600px * 0.8 = 480px */
    }
    
    .word-cell {
        font-size: 0.85em;  /* 0.9em * 0.94 ≈ 0.85em */
        min-height: 56px;   /* 70px * 0.8 = 56px */
    }
}
