/* Modern, clean styling for CrossWordGrid Generator */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

linkset {
    display: flex;
    gap: 1rem;
}

linkset a {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.2);
    border-radius: 5px;
    transition: background 0.3s;
}

linkset a:hover {
    background: rgba(255,255,255,0.3);
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.workflow-container {
    background: white;
    border-radius: 10px;
    padding: 2rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

/* Mobile-first: Portrait layout (column) */
.workflow-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.workflow-container > section,
.workflow-container > .preview-section,
.workflow-container > .candidates-section,
.workflow-container > .word-list-section,
.workflow-container > .grid-controls-section {
    flex: 1;
}

/* Landscape layout for larger viewports */
@media (min-width: 768px) {
    .workflow-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "header header"
            "wordlist preview"
            "controls preview"
            "message preview"
            "candidates candidates";
        gap: 2rem;
    }
    
    header {
        grid-area: header;
    }
    
    .word-list-section {
        grid-area: wordlist;
    }
    
    .grid-controls-section {
        grid-area: controls;
    }
    
    .message-section {
        grid-area: message;
    }
    
    .preview-section {
        grid-area: preview;
    }
    
    .candidates-section {
        grid-area: candidates;
    }
}

h3 {
    color: #667eea;
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

/* Word List */
.word-list {
    list-style: none;
    margin-bottom: 1rem;
    min-height: 50px;
}

.word-list:empty::after {
    content: "No words yet. Add some words to get started.";
    color: #999;
    font-style: italic;
    display: block;
    padding: 1rem;
}

.word-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-radius: 5px;
    border-left: 3px solid #667eea;
    cursor: move;
    transition: all 0.2s;
}

.word-item:hover {
    background: #e9ecef;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.word-item.dragging {
    opacity: 0.5;
}

.word-drag-handle {
    color: #aaa;
    margin-right: 0.75rem;
    cursor: grab;
    user-select: none;
}

.word-value {
    flex: 1;
    font-weight: 500;
    font-size: 1.1rem;
}

.remove-word-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
}

.remove-word-btn:hover:not(:disabled) {
    background: #c82333;
}

.remove-word-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.add-word {
    display: flex;
    gap: 0.5rem;
}

#new-word-input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

#new-word-input:focus {
    outline: none;
    border-color: #667eea;
}

#add-word-btn, #start-generation-btn, #select-crossword-btn {
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

#add-word-btn:hover:not(:disabled),
#start-generation-btn:hover:not(:disabled),
#select-crossword-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Grid Controls */
.grid-size-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.grid-size-controls label {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.grid-size-controls input {
    padding: 0.5rem;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
}

/* Progress Bar */
.progress-section {
    margin: 1rem 0;
}

.progress-bar {
    width: 100%;
    height: 30px;
    background: #e9ecef;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
}

/* Message Area */
.message-area {
    padding: 1rem;
    background: #e7f3ff;
    border-left: 4px solid #2196f3;
    border-radius: 5px;
    margin: 1rem 0;
}

.message-area p {
    margin: 0.25rem 0;
}

/* Candidates Grid */
.candidates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.candidate-thumbnail {
    border: 2px solid #ddd;
    border-radius: 5px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    aspect-ratio: 1;
}

.candidate-thumbnail:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.candidate-thumbnail.focused {
    border-color: #667eea;
    background: #f0f4ff;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* Word Grid Rendering */
.word-grid {
    display: grid;
    gap: 2px;
    background: #ddd;
    border: 2px solid #333;
    margin: 1rem auto;
    max-width: 100%;
}

.word-grid.large {
    max-height: 40vh;
    max-width: 40vh;
    aspect-ratio: 1;
}

.word-grid.thumbnail {
    max-height: 8vh;
    max-width: 8vh;
    aspect-ratio: 1;
}

.grid-cell {
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    aspect-ratio: 1;
    min-width: 0;
    min-height: 0;
}

.word-grid.thumbnail .grid-cell {
    font-size: 0.5rem;
}

.grid-cell.empty-cell {
    background: #f0f0f0;
}

.grid-cell.black-cell {
    background: #000;
    color: #000;
}

/* Preview Section */
.preview-container {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-grid {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* Print Styling */
@media print {
    body.final_grid_only header,
    body.final_grid_only linkset,
    body.final_grid_only .word-list-section,
    body.final_grid_only .grid-controls-section,
    body.final_grid_only .message-section,
    body.final_grid_only .candidates-section {
        display: none !important;
    }
    
    body.final_grid_only .preview-section {
        display: block !important;
        page-break-inside: avoid;
    }
    
    body.final_grid_only .word-grid {
        max-width: 100%;
        max-height: 100vh;
    }
    
    body.final_grid_only .grid-cell.black-cell {
        background: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
