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

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #64748b;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #475569;
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #1a1a2e 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

#app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

header h1 {
    font-size: 1.5rem;
    background: linear-gradient(90deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stats {
    display: flex;
    gap: 1.5rem;
    font-size: 0.95rem;
}

.stats span {
    padding: 0.5rem 1rem;
    background: var(--bg-input);
    border-radius: 6px;
    font-weight: 500;
}

main {
    display: grid;
    gap: 1rem;
}

.panel {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid var(--border);
}

.panel h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

#story-panel {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, var(--bg-card) 0%, #1e3a5f 100%);
}

#theory-panel {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, #1e293b 0%, #134e4a 100%);
}

#game-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 1rem;
}

#story-content {
    font-size: 1.1rem;
    line-height: 1.8;
}

#story-content .character {
    color: #60a5fa;
    font-weight: 600;
}

#story-content .highlight {
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 600;
}

#story-content .danger {
    color: #f87171;
    font-weight: 600;
}

#story-content .success {
    color: #4ade80;
    font-weight: 600;
}

#game-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 1rem;
}

#schema-panel {
    grid-column: 1;
    grid-row: 1 / 3;
}

#editor-panel {
    grid-column: 2;
    grid-row: 1;
}

#result-panel {
    grid-column: 2;
    grid-row: 2;
}

#sql-input {
    width: 100%;
    min-height: 120px;
    background: var(--bg-dark);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.95rem;
    resize: vertical;
    transition: border-color 0.3s;
}

#sql-input:focus {
    outline: none;
    border-color: var(--primary);
}

.editor-controls {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn.primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn.secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

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

#schema-content {
    max-height: 400px;
    overflow-y: auto;
}

.schema-table {
    margin-bottom: 1rem;
}

.schema-table h4 {
    color: #60a5fa;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.schema-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.schema-table th,
.schema-table td {
    padding: 0.5rem;
    text-align: left;
    border: 1px solid var(--border);
}

.schema-table th {
    background: var(--bg-input);
    color: #94a3b8;
}

.schema-table .pk {
    color: #fbbf24;
}

.schema-table .fk {
    color: #a78bfa;
}

#result-content {
    max-height: 300px;
    overflow: auto;
}

#result-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

#result-content th,
#result-content td {
    padding: 0.5rem;
    text-align: left;
    border: 1px solid var(--border);
}

#result-content th {
    background: var(--primary);
    color: white;
}

#result-content tr:nth-child(even) {
    background: var(--bg-input);
}

#result-content .error {
    color: var(--danger);
    padding: 1rem;
}

#result-content .success-msg {
    color: var(--success);
    padding: 1rem;
    font-weight: 500;
}

#result-content .empty {
    color: var(--text-secondary);
    padding: 1rem;
    font-style: italic;
}

#objectives-panel {
    grid-column: 1 / -1;
}

#objectives-content {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.objective {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border-radius: 8px;
    font-size: 0.9rem;
}

.objective.completed {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid var(--success);
}

.objective.completed::before {
    content: '✅';
}

.objective.pending::before {
    content: '⬜';
}

#learn-panel {
    grid-column: 1 / -1;
}

#learn-content {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

#theory-panel {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, #1e293b 0%, #134e4a 100%);
}

#theory-content {
    font-size: 0.95rem;
    line-height: 1.7;
}

#theory-content h3 {
    color: #2dd4bf;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

#theory-content ul {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

#theory-content li {
    margin: 0.4rem 0;
}

#theory-content pre {
    background: #0f172a;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75rem 0;
    border: 1px solid #334155;
}

#theory-content code {
    font-family: var(--font-mono);
    color: #e2e8f0;
}

#theory-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.85rem;
}

#theory-content th,
#theory-content td {
    padding: 0.5rem;
    text-align: left;
    border: 1px solid var(--border);
}

#theory-content th {
    background: #334155;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: #475569;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    margin-left: 1rem;
}

.btn-small:hover {
    background: #64748b;
}

.theory-hidden #theory-content {
    display: none;
}

.concept-badge {
    padding: 0.4rem 0.8rem;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 16px;
    max-width: 500px;
    text-align: center;
    border: 2px solid var(--primary);
    animation: modalIn 0.3s ease;
}

.modal-content.victory {
    border-color: var(--success);
    background: linear-gradient(135deg, var(--bg-card) 0%, #1e3a5f 100%);
}

@keyframes modalIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content h2 {
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.modal-content p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

#final-stats {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--bg-input);
    border-radius: 8px;
}

#final-stats p {
    margin: 0.5rem 0;
}

.hint-box {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid var(--warning);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
}

.hint-box h4 {
    color: var(--warning);
    margin-bottom: 0.5rem;
}

.hint-box code {
    background: var(--bg-dark);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: var(--font-mono);
}

@media (max-width: 900px) {
    #game-area {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }
    
    #schema-panel {
        grid-column: 1;
        grid-row: 1;
    }
    
    #editor-panel {
        grid-column: 1;
        grid-row: 2;
    }
    
    #result-panel {
        grid-column: 1;
        grid-row: 3;
    }
    
    header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .stats {
        flex-wrap: wrap;
        justify-content: center;
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.running {
    animation: pulse 1s infinite;
}

.typing-effect {
    overflow: hidden;
    border-right: 2px solid var(--primary);
    animation: typing 2s steps(40, end), blink-caret 0.75s step-end infinite;
}

@keyframes typing {
    from { width: 0 }
    to { width: 100% }
}

@keyframes blink-caret {
    from, to { border-color: transparent }
    50% { border-color: var(--primary) }
}
