/* CSS Variables */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --radius-lg: 12px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

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

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

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

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

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

/* Configuration Panel */
.config-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.config-panel h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.config-item label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.config-item select {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.config-item select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Buttons */
.button-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.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: #4b5563;
}

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

.btn-success:hover {
    background: #059669;
}

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

.btn-warning:hover {
    background: #d97706;
}

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

.btn-danger:hover {
    background: #dc2626;
}

/* Puzzle Area */
.puzzle-area {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.puzzle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.puzzle-header h2 {
    font-size: 1.25rem;
}

.puzzle-info {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.difficulty-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
}

.difficulty-badge.easy {
    background: #d1fae5;
    color: #065f46;
}

.difficulty-badge.medium {
    background: #fef3c7;
    color: #92400e;
}

.difficulty-badge.hard {
    background: #fee2e2;
    color: #991b1b;
}

.difficulty-badge.expert {
    background: #ede9fe;
    color: #5b21b6;
}

.timer {
    font-family: 'Courier New', monospace;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Story Box */
.story-box {
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    border-left: 4px solid var(--primary-color);
}

.story-box h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.story-box p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Clues Section */
.clues-section {
    margin-bottom: 1.5rem;
}

.clues-section h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
}

.clues-list {
    list-style-position: inside;
    padding: 1rem;
    background: #f8fafc;
    border-radius: var(--radius);
}

.clues-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}

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

.clue-used {
    opacity: 0.5;
    text-decoration: line-through;
}

/* Grid Container */
.grid-container {
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.grid-container h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
}

.grid-wrapper {
    overflow-x: auto;
    padding-bottom: 1rem;
}

/* Logic Grid */
.logic-grid {
    display: inline-block;
    border-collapse: collapse;
    font-size: 0.75rem;
}

.logic-grid table {
    border-collapse: collapse;
}

.logic-grid th,
.logic-grid td {
    border: 1px solid var(--border-color);
    padding: 0.25rem;
    text-align: center;
    min-width: 30px;
    height: 30px;
}

.logic-grid th {
    background: #f1f5f9;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.7rem;
    white-space: nowrap;
    padding: 0.5rem 0.25rem;
}

.logic-grid th.category-header {
    background: var(--primary-color);
    color: white;
    font-size: 0.75rem;
}

.logic-grid th.row-header {
    text-align: right;
    padding-right: 0.5rem;
    background: #f8fafc;
}

.logic-grid td {
    cursor: pointer;
    transition: background 0.15s;
    font-size: 1rem;
    font-weight: 600;
}

.logic-grid td:hover {
    background: #e0f2fe;
}

.logic-grid td.marked-x {
    color: var(--danger-color);
    background: #fef2f2;
}

.logic-grid td.marked-o {
    color: var(--success-color);
    background: #ecfdf5;
}

.logic-grid td.disabled {
    background: #e5e7eb;
    cursor: not-allowed;
}

/* Solution Section */
.solution-section {
    margin-bottom: 1.5rem;
}

.solution-section h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
}

.solution-grid {
    overflow-x: auto;
}

.solution-grid table {
    width: 100%;
    border-collapse: collapse;
    min-width: 400px;
}

.solution-grid th,
.solution-grid td {
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    text-align: left;
}

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

.solution-grid td select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.solution-grid tr:nth-child(even) {
    background: #f8fafc;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

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

.result-message.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.result-message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

.result-message.hint {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

/* Instructions */
.instructions {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.instructions h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.instructions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.instruction-card {
    text-align: center;
    padding: 1rem;
}

.instruction-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.75rem;
    font-weight: 700;
}

.instruction-card h4 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

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

/* Footer */
footer {
    background: var(--text-primary);
    color: white;
    padding: 1.5rem;
    text-align: center;
}

footer a {
    color: #93c5fd;
    text-decoration: none;
    font-weight: 500;
}

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

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

    .subtitle {
        font-size: 0.95rem;
    }

    main {
        padding: 1rem;
    }

    .config-panel,
    .puzzle-area,
    .instructions {
        padding: 1rem;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }

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

    .btn {
        width: 100%;
    }

    .puzzle-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }

    .logic-grid th,
    .logic-grid td {
        min-width: 25px;
        height: 25px;
        font-size: 0.65rem;
    }

    .logic-grid td {
        font-size: 0.85rem;
    }

    .instructions-grid {
        grid-template-columns: 1fr 1fr;
    }
}

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

    header h1 {
        font-size: 1.25rem;
    }

    .instructions-grid {
        grid-template-columns: 1fr;
    }

    .logic-grid th,
    .logic-grid td {
        min-width: 22px;
        height: 22px;
        padding: 0.15rem;
    }
}

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

.puzzle-area {
    animation: fadeIn 0.3s ease-out;
}

/* Print Styles */
@media print {
    .config-panel,
    .action-buttons,
    footer {
        display: none;
    }

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