/* Crossword Game Styles */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f8f9fa;
    color: #333;
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.header {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
}

.header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.home-link {
    color: #007bff;
    text-decoration: none;
}

.home-link:hover {
    text-decoration: underline;
}

.separator {
    margin: 0 0.5rem;
    color: #666;
}

.game-title {
    color: #333;
}

.nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.nav-btn:hover {
    background: #f0f0f0;
    border-color: #999;
}

.nav-btn:active {
    transform: translateY(1px);
}

/* Main Content */
.main {
    padding: 2rem 0;
    min-height: 100vh;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 4rem 0;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error State */
.error {
    text-align: center;
    padding: 4rem 0;
    color: #dc3545;
}

.error h2 {
    margin-bottom: 1rem;
}

/* Hidden State */
.hidden {
    display: none !important;
}

/* Game Container */
.game-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Puzzle Info */
.puzzle-info {
    text-align: center;
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.puzzle-title {
    margin: 0 0 0.5rem 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: #333;
}

.puzzle-meta {
    margin: 0 0 1rem 0;
    color: #666;
    font-size: 0.95rem;
}

.puzzle-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    font-size: 0.9rem;
}

.stat {
    padding: 0.25rem 0.75rem;
    background: #f8f9fa;
    border-radius: 4px;
    color: #495057;
}

/* Game Controls */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Game Area */
.game-area {
    display: grid;
    grid-template-columns: minmax(400px, 500px) 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Grid Container */
.grid-container {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
}

.crossword-grid {
    display: grid;
    gap: 1px;
    background: #333;
    border: 2px solid #333;
    width: 100%;
    max-width: 450px;
    aspect-ratio: 1;
}

.grid-cell {
    position: relative;
    background: white;
    aspect-ratio: 1;
    min-width: 25px;
    min-height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.black-cell {
    background: #333 !important;
}

.grid-cell.highlighted {
    background: #e3f2fd !important;
}

.grid-cell.current {
    background: #2196f3 !important;
}

.grid-cell.current .cell-input {
    background: #2196f3;
    color: white;
}

.cell-number {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
    color: #333;
    z-index: 2;
}

.cell-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    outline: none;
    text-transform: uppercase;
}

.cell-input:focus {
    background: #fff3cd;
}

.circled-cell {
    border-radius: 50%;
    overflow: hidden;
}

.circled-cell .cell-input {
    border-radius: 50%;
}

/* Clues Container */
.clues-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    height: fit-content;
    max-height: 70vh;
}

/* Clues Section */
.clues-section {
    border-bottom: 1px solid #e0e0e0;
}

.clues-section:last-child {
    border-bottom: none;
}

.clues-header {
    padding: 0.75rem 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    font-weight: 600;
    color: #333;
}

.clues-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.clues-content {
    flex: 1;
    overflow: hidden;
}

.clues-list {
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.9rem;
}

.clue-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 0.25rem;
}

.clue-item:hover {
    background: #f8f9fa;
}

.clue-item.selected {
    background: #e3f2fd;
    color: #1976d2;
}

.clue-number {
    font-weight: 600;
    color: #666;
    min-width: 2rem;
    text-align: right;
}

.clue-text {
    flex: 1;
    line-height: 1.4;
}

/* Current Clue Display */
.current-clue {
    padding: 1.5rem;
    background: #e3f2fd;
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: 1px solid #bbdefb;
}

.current-clue .clue-number {
    font-weight: 700;
    color: #1976d2;
    font-size: 1.2rem;
    min-width: 3rem;
    background: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    text-align: center;
}

.current-clue .clue-text {
    flex: 1;
    font-size: 1rem;
    line-height: 1.5;
    font-weight: 500;
    color: #333;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    max-width: 400px;
    margin: 1rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.modal-content h2 {
    margin: 0 0 1rem 0;
    color: #28a745;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: #007bff;
    color: white;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header .container {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .nav {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .game-area {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .crossword-grid {
        max-width: 90vw;
    }
    
    .grid-container {
        padding: 1rem;
    }
    
    .crossword-grid {
        max-width: 90vw;
    }
    
    .grid-cell {
        min-width: 22px;
        min-height: 22px;
    }
    
    .cell-input {
        font-size: 0.9rem;
    }
    
    .cell-number {
        font-size: 0.6rem;
    }
    
    .clues-container {
        max-height: 50vh;
    }
    
    .puzzle-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.5rem;
    }
    
    .main {
        padding: 1rem 0;
    }
    
    .puzzle-info {
        padding: 1rem;
    }
    
    .puzzle-title {
        font-size: 1.2rem;
    }
    
    .grid-cell {
        min-width: 20px;
        min-height: 20px;
    }
    
    .cell-input {
        font-size: 0.8rem;
    }
    
    .nav-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .modal-content {
        padding: 1.5rem;
        margin: 0.5rem;
    }
    
    .modal-actions {
        flex-direction: column;
    }
}

/* Print Styles */
@media print {
    .header .nav,
    .modal,
    .current-clue {
        display: none !important;
    }
    
    .main {
        padding: 0;
    }
    
    .game-area {
        display: block;
    }
    
    .grid-container {
        box-shadow: none;
        border: 2px solid #333;
        margin-bottom: 1rem;
        page-break-inside: avoid;
    }
    
    .clues-container {
        box-shadow: none;
        border: 1px solid #333;
        max-height: none;
        overflow: visible;
    }
    
    .clues-list {
        max-height: none;
        overflow: visible;
        page-break-inside: avoid;
    }
    
    .clues-section {
        page-break-inside: avoid;
        margin-bottom: 1rem;
    }
    
    .crossword-grid {
        border: 2px solid #333;
    }
    
    .grid-cell {
        border: 1px solid #333;
    }
    
    .cell-input {
        background: white !important;
        color: #333 !important;
    }
    
    /* Hide user input for blank puzzle */
    .print-blank .cell-input {
        color: transparent !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .grid-cell {
        border: 1px solid #000;
    }
    
    .grid-cell.highlighted {
        background: #ffff00 !important;
        color: #000 !important;
    }
    
    .grid-cell.current {
        background: #0000ff !important;
        color: #fff !important;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}