/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --cell-selected: #dbeafe;
    --cell-highlighted: #eff6ff;
    --cell-correct: #dcfce7;
    --cell-incorrect: #fee2e2;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header Styles */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.date-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.daily-badge {
    background: linear-gradient(135deg, var(--primary-color), #7c3aed);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.game-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 1024px) {
    .game-container {
        grid-template-columns: auto 1fr;
    }
}

/* Puzzle Section */
.puzzle-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background: var(--background);
    color: var(--text-primary);
}

/* Crossword Grid */
.grid-wrapper {
    display: flex;
    justify-content: center;
    overflow-x: auto;
    padding: 0.5rem;
}

.crossword-grid {
    display: grid;
    gap: 2px;
    background: var(--text-primary);
    padding: 2px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.cell {
    width: 40px;
    height: 40px;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

.cell.blocked {
    background: var(--text-primary);
    cursor: default;
}

.cell-number {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1;
}

.cell-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 1.25rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-primary);
    cursor: pointer;
    caret-color: var(--primary-color);
}

.cell-input:focus {
    outline: none;
}

.cell.selected {
    background: var(--cell-selected);
}

.cell.highlighted {
    background: var(--cell-highlighted);
}

.cell.correct .cell-input {
    color: var(--success-color);
}

.cell.incorrect {
    background: var(--cell-incorrect);
}

.cell.incorrect .cell-input {
    color: var(--error-color);
}

.cell.revealed .cell-input {
    color: var(--secondary-color);
    font-style: italic;
}

/* Current Clue Display */
.current-clue-display {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.875rem 1rem;
    min-height: 3.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
}

.clue-direction {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.clue-direction:empty {
    display: none;
}

.clue-text {
    color: var(--text-primary);
    font-size: 0.9375rem;
}

/* Clues Section */
.clues-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.clues-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}

@media (max-width: 640px) {
    .clues-container {
        grid-template-columns: 1fr;
    }
}

.clues-column {
    padding: 1.25rem;
}

.clues-column:first-child {
    border-right: 1px solid var(--border-color);
}

@media (max-width: 640px) {
    .clues-column:first-child {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
}

.clues-column h3 {
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-color);
    display: inline-block;
}

.clue-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.clue-item {
    display: flex;
    gap: 0.625rem;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 0.15s ease;
    font-size: 0.875rem;
}

.clue-item:hover {
    background: var(--background);
}

.clue-item.active {
    background: var(--cell-highlighted);
}

.clue-item.completed {
    opacity: 0.6;
}

.clue-item.completed .clue-item-text {
    text-decoration: line-through;
}

.clue-number {
    font-weight: 700;
    color: var(--primary-color);
    min-width: 1.5rem;
}

.clue-item-text {
    color: var(--text-primary);
    line-height: 1.4;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.2s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.modal-icon.success {
    background: var(--cell-correct);
    color: var(--success-color);
}

.modal-icon.error {
    background: var(--cell-incorrect);
    color: var(--error-color);
}

.modal-icon.info {
    background: var(--cell-highlighted);
    color: var(--primary-color);
}

#modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

#modal-message {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* Footer */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: 1.25rem;
    text-align: center;
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.15s ease;
}

.footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Responsive Adjustments */
@media (max-width: 480px) {
    .header {
        padding: 0.75rem 1rem;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .logo {
        width: 32px;
        height: 32px;
    }

    .main-content {
        padding: 1rem;
    }

    .cell {
        width: 32px;
        height: 32px;
    }

    .cell-number {
        font-size: 0.5rem;
    }

    .cell-input {
        font-size: 1rem;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .btn svg {
        width: 16px;
        height: 16px;
    }

    .toolbar .btn span {
        display: none;
    }

    .clues-column {
        padding: 1rem;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .cell {
        width: 36px;
        height: 36px;
    }
}

/* Print Styles */
@media print {
    .header, .toolbar, .footer, .modal {
        display: none;
    }

    .main-content {
        padding: 0;
    }

    .cell-input {
        color: transparent;
    }

    .cell.blocked {
        background: #000;
    }
}

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

/* Focus visible for keyboard navigation */
.cell:focus-within {
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
        --text-secondary: #000;
    }

    .cell {
        border: 1px solid #000;
    }
}
