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

:root {
    --primary-color: #4a6fa5;
    --primary-hover: #3d5d8a;
    --secondary-color: #6c757d;
    --secondary-hover: #5a6268;
    --success-color: #28a745;
    --error-color: #dc3545;
    --warning-color: #ffc107;
    --background-color: #f8f9fa;
    --card-background: #ffffff;
    --text-color: #333333;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

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

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

/* Header Styles */
header {
    background: linear-gradient(135deg, var(--primary-color), #667eea);
    color: white;
    padding: 2rem 1rem;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

header .subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

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

/* Controls Section */
.controls {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.control-group {
    margin-bottom: 1rem;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.control-group select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    background-color: white;
    cursor: pointer;
    transition: var(--transition);
}

.control-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 111, 165, 0.2);
}

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    flex: 1;
    min-width: 140px;
}

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

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

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

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

.btn-secondary:hover:not(:disabled) {
    background-color: var(--secondary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* Puzzle Area */
.puzzle-area {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.puzzle-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

.placeholder {
    text-align: center;
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Sudoku Grid Styles */
.sudoku-grid {
    display: grid;
    gap: 0;
    border: 3px solid var(--text-color);
    background: var(--text-color);
}

.sudoku-grid.size-4 {
    grid-template-columns: repeat(4, 1fr);
}

.sudoku-grid.size-9 {
    grid-template-columns: repeat(9, 1fr);
}

.sudoku-cell {
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: white;
    font-size: 1.25rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
}

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

.sudoku-cell input:focus {
    outline: none;
    background-color: rgba(74, 111, 165, 0.1);
}

.sudoku-cell.given {
    background-color: #f0f0f0;
    color: var(--text-color);
}

.sudoku-cell.error {
    background-color: rgba(220, 53, 69, 0.2);
}

.sudoku-cell.correct {
    background-color: rgba(40, 167, 69, 0.2);
}

/* Sudoku 4x4 borders */
.sudoku-grid.size-4 .sudoku-cell:nth-child(2n) {
    border-right: 2px solid var(--text-color);
}

.sudoku-grid.size-4 .sudoku-cell:nth-child(n+5):nth-child(-n+8) {
    border-bottom: 2px solid var(--text-color);
}

/* Sudoku 9x9 borders */
.sudoku-grid.size-9 .sudoku-cell:nth-child(3n) {
    border-right: 2px solid var(--text-color);
}

.sudoku-grid.size-9 .sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-grid.size-9 .sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--text-color);
}

/* Nonogram Styles */
.nonogram-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.nonogram-wrapper {
    display: grid;
    gap: 0;
}

.nonogram-corner {
    background: var(--background-color);
}

.nonogram-col-hints {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding: 4px;
    background: var(--background-color);
    font-size: 0.8rem;
    font-weight: 600;
    min-height: 60px;
}

.nonogram-row-hints {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 4px 8px;
    background: var(--background-color);
    font-size: 0.8rem;
    font-weight: 600;
    gap: 4px;
    min-width: 60px;
}

.nonogram-grid {
    display: contents;
}

.nonogram-cell {
    width: 30px;
    height: 30px;
    background: white;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}

.nonogram-cell:hover {
    background-color: rgba(74, 111, 165, 0.1);
}

.nonogram-cell.filled {
    background-color: var(--text-color);
}

.nonogram-cell.marked {
    background-color: white;
    position: relative;
}

.nonogram-cell.marked::after {
    content: '×';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    color: var(--text-muted);
}

.nonogram-cell.error {
    background-color: var(--error-color) !important;
}

/* Logic Grid Styles */
.logic-grid-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.logic-grid-wrapper {
    overflow-x: auto;
}

.logic-grid {
    border-collapse: collapse;
    margin: 0 auto;
}

.logic-grid th,
.logic-grid td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: center;
    min-width: 40px;
}

.logic-grid th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

.logic-grid .category-header {
    background-color: var(--primary-hover);
}

.logic-grid .row-header {
    background-color: var(--background-color);
    font-weight: 600;
    text-align: left;
}

.logic-grid td:not(.row-header) {
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
}

.logic-grid td:not(.row-header):hover {
    background-color: rgba(74, 111, 165, 0.1);
}

.logic-grid td.true {
    background-color: rgba(40, 167, 69, 0.3);
    color: var(--success-color);
}

.logic-grid td.false {
    background-color: rgba(220, 53, 69, 0.1);
    color: var(--error-color);
}

/* Clues Container */
.clues-container {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: var(--background-color);
    border-radius: var(--border-radius);
}

.clues-container h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.clues-container ol {
    padding-left: 1.5rem;
}

.clues-container li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.clues-container.hidden {
    display: none;
}

/* Result Message */
.result-message {
    margin-top: 1.5rem;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    text-align: center;
    font-weight: 600;
}

.result-message.hidden {
    display: none;
}

.result-message.success {
    background-color: rgba(40, 167, 69, 0.2);
    color: var(--success-color);
    border: 2px solid var(--success-color);
}

.result-message.error {
    background-color: rgba(220, 53, 69, 0.2);
    color: var(--error-color);
    border: 2px solid var(--error-color);
}

.result-message.info {
    background-color: rgba(74, 111, 165, 0.2);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

/* Footer Styles */
footer {
    background-color: var(--text-color);
    color: white;
    text-align: center;
    padding: 1.5rem 1rem;
    margin-top: auto;
}

footer a {
    color: #87ceeb;
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

footer a:hover {
    color: white;
    text-decoration: underline;
}

/* Print Styles */
@media print {
    body {
        background: white;
    }

    header {
        background: none;
        color: var(--text-color);
        padding: 1rem 0;
    }

    .controls {
        display: none;
    }

    .puzzle-area {
        box-shadow: none;
        padding: 0;
    }

    .result-message {
        display: none !important;
    }

    footer {
        background: none;
        color: var(--text-color);
        border-top: 1px solid var(--border-color);
        padding: 1rem 0;
    }

    footer a {
        color: var(--text-color);
    }

    .sudoku-cell input {
        border: none;
    }

    .nonogram-cell {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.75rem;
    }

    header .subtitle {
        font-size: 0.95rem;
    }

    main {
        padding: 1rem;
    }

    .controls {
        padding: 1rem;
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .sudoku-cell {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }

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

    .nonogram-cell {
        width: 25px;
        height: 25px;
    }

    .nonogram-col-hints,
    .nonogram-row-hints {
        font-size: 0.7rem;
        min-height: 50px;
        min-width: 50px;
    }

    .logic-grid th,
    .logic-grid td {
        padding: 6px 8px;
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    header {
        padding: 1.5rem 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .sudoku-cell {
        width: 30px;
        height: 30px;
        font-size: 0.9rem;
    }

    .sudoku-cell input {
        font-size: 0.9rem;
    }

    .nonogram-cell {
        width: 22px;
        height: 22px;
    }

    .logic-grid th,
    .logic-grid td {
        padding: 4px 6px;
        font-size: 0.75rem;
        min-width: 30px;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.puzzle-container > *:not(.placeholder) {
    animation: fadeIn 0.3s ease-out;
}

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