/* ===========================
   CSS VARIABLES & RESET
   =========================== */

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

:root {
    --primary: #8b5cf6;
    --primary-dark: #7c3aed;
    --secondary: #10b981;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);
    --accent: #8b5cf6;
    --navbar-bg: #ffffff;
    --gradient: linear-gradient(135deg, #8b5cf6 0%, #10b981 100%);
    --code-bg: #1e1e1e;
    --code-text: #d4d4d4;
    --easy: #4ade80;
    --medium: #fbbf24;
    --hard: #f87171;
    --distractor: #94a3b8;
}

[data-theme="dark"] {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-card: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --border: #374151;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.5);
    --navbar-bg: #111827;
    --code-bg: #0f172a;
    --code-text: #cbd5e1;
    --distractor: #64748b;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
}

/* ===========================
   HERO SECTION
   =========================== */

.hero {
    background: var(--gradient);
    padding: 4rem 2rem;
    text-align: center;
    color: white;
    position: relative;
    overflow: hidden;
    border-bottom: 2px solid var(--border);
}

.hero-content {
    position: relative;
    z-index: 1;
    max-width: 800px;
    margin: 0 auto;
}

.hero-h1 {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.hero-para {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.hero-stats span {
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 20px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(10px);
}

[data-theme="dark"] .hero {
    background: linear-gradient(to right, #111827, #1f2937);
}

[data-theme="dark"] .hero-para {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

[data-theme="dark"] .hero-h1 {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

[data-theme="dark"] .hero-stats span {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    border: 1px solid #7c3aed;
}

/* ===========================
   MAIN CONTAINER
   =========================== */

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

/* ===========================
   GAME HEADER
   =========================== */

.game-header {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 30px;
    border: 2px solid var(--border);
    box-shadow: 0 4px 20px var(--shadow);
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 15px;
}

.difficulty-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.diff-btn {
    padding: 10px 20px;
    border: 2px solid var(--border);
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.diff-btn.easy { border-color: var(--easy); color: var(--easy); }
.diff-btn.medium { border-color: var(--medium); color: var(--medium); }
.diff-btn.hard { border-color: var(--hard); color: var(--hard); }

.diff-btn.active.easy { background: var(--easy); color: white; }
.diff-btn.active.medium { background: var(--medium); color: white; }
.diff-btn.active.hard { background: var(--hard); color: white; }

.diff-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.level-info {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--primary);
    text-align: center;
}

.score-display {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1.1em;
    font-weight: bold;
    flex-wrap: wrap;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-primary);
}

.new-puzzle-btn {
    padding: 12px 24px;
    background: var(--gradient);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.new-puzzle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 15px;
}

.progress-fill {
    height: 100%;
    background: var(--gradient);
    transition: width 0.5s;
}

/* ===========================
   EDITOR PANELS
   =========================== */

.game-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 30px;
}

.editor-panel {
    background: var(--bg-card);
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid var(--border);
    transition: transform 0.3s ease;
    box-shadow: 0 4px 20px var(--shadow);
    min-height: 400px;
}

.editor-panel:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.panel-header {
    padding: 18px 25px;
    background: rgba(139, 92, 246, 0.1);
    border-bottom: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 1.05em;
}

.panel-header span {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
}

.panel-btn {
    padding: 6px 12px;
    background: var(--gradient);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
}

.panel-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.panel-stats {
    display: flex;
    gap: 15px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.panel-stats span {
    background: var(--bg-secondary);
    padding: 4px 10px;
    border-radius: 20px;
}

/* ===========================
   CLAUSE POOL
   =========================== */

.clause-pool {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 350px;
    max-height: 350px;
    overflow-y: auto;
}

.empty-state {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 1.1em;
    text-align: center;
    padding: 40px 20px;
}

.sql-clause {
    background: var(--gradient);
    color: white;
    padding: 15px;
    border-radius: 10px;
    cursor: move;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.95em;
    box-shadow: 0 4px 6px var(--shadow);
    transition: all 0.3s;
    user-select: none;
    touch-action: none;
}

.sql-clause:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px var(--shadow);
}

.sql-clause.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
}

.sql-clause.distractor {
    background: linear-gradient(135deg, var(--distractor) 0%, var(--distractor) 100%);
}

/* ===========================
   DROP ZONE
   =========================== */

.drop-zone {
    padding: 20px;
    min-height: 350px;
    border: 3px dashed var(--border);
    border-radius: 10px;
    transition: all 0.3s;
    position: relative;
}

.drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.05);
}

.drop-zone.empty-state {
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-secondary);
    font-size: 1.1em;
    text-align: center;
}

.drop-zone .sql-clause {
    margin-bottom: 10px;
}

.drop-zone .sql-clause:last-child {
    margin-bottom: 0;
}

/* ===========================
   ASSEMBLED QUERY
   =========================== */

.assembled-query {
    font-family: 'Fira Code', 'Courier New', monospace;
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    margin: 15px 20px;
    white-space: pre-wrap;
    font-size: 0.95em;
    border: 2px solid var(--border);
    min-height: 100px;
    max-height: 150px;
    overflow-y: auto;
    color: var(--text-secondary);
}

.assembled-query.has-content {
    color: var(--text-primary);
    background: var(--bg-primary);
}

/* ===========================
   HINT BOX
   =========================== */

.hint-box {
    background: rgba(245, 158, 11, 0.1);
    padding: 12px 20px;
    border-radius: 8px;
    margin: 0 20px 15px;
    border-left: 4px solid #f59e0b;
    color: var(--text-primary);
    display: none;
}

.hint-box.show {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* ===========================
   ACTION BUTTONS
   =========================== */

.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 30px;
}

.action-buttons button {
    padding: 14px 30px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.action-buttons button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.action-buttons button:hover::before {
    width: 300px;
    height: 300px;
}

.action-buttons button span {
    position: relative;
    z-index: 1;
}

.btn-format {
    background: var(--gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.btn-format:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

.btn-copy {
    background: rgba(52, 211, 153, 0.15);
    color: var(--secondary);
    border: 2px solid var(--secondary);
}

.btn-copy:hover {
    background: rgba(52, 211, 153, 0.25);
    transform: translateY(-2px);
}

.btn-download {
    background: rgba(251, 146, 60, 0.15);
    color: #fb923c;
    border: 2px solid #fb923c;
}

.btn-download:hover {
    background: rgba(251, 146, 60, 0.25);
    transform: translateY(-2px);
}

.btn-clear {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 2px solid #ef4444;
}

.btn-clear:hover {
    background: rgba(239, 68, 68, 0.25);
    transform: translateY(-2px);
}

.btn-share {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 2px solid #3b82f6;
}

.btn-share:hover {
    background: rgba(59, 130, 246, 0.25);
    transform: translateY(-2px);
}

/* ===========================
   FEEDBACK PANEL
   =========================== */

.feedback-panel {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 0;
    margin-bottom: 30px;
    border: 2px solid var(--border);
    box-shadow: 0 4px 20px var(--shadow);
    overflow: hidden;
}

.feedback {
    padding: 30px;
    display: block;
    animation: slideIn 0.5s ease;
}

.feedback.success {
    background: rgba(16, 185, 129, 0.1);
    border-top: 4px solid var(--secondary);
}

.feedback.error {
    background: rgba(239, 68, 68, 0.1);
    border-top: 4px solid #ef4444;
}

.feedback-icon {
    font-size: 3em;
    margin-bottom: 15px;
    text-align: center;
}

.feedback-title {
    font-size: 1.5em;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--text-primary);
    text-align: center;
}

.feedback-message {
    font-size: 1.1em;
    margin-bottom: 20px;
    color: var(--text-secondary);
    text-align: center;
}

.learning-tip {
    background: rgba(139, 92, 246, 0.1);
    padding: 20px;
    border-radius: 10px;
    margin-top: 20px;
    border-left: 4px solid var(--primary);
}

.learning-tip-title {
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1em;
}

/* ===========================
   CELEBRATION
   =========================== */

.celebration {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 5em;
    pointer-events: none;
    animation: celebrate 1s ease;
    display: none;
    z-index: 1000;
}

.celebration-text {
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: bold;
    font-size: 4rem;
}

@keyframes celebrate {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.5) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1) rotate(360deg);
        opacity: 0;
    }
}

/* ===========================
   NOTIFICATION
   =========================== */

/* ===========================
   NOTIFICATION
   =========================== */

.notification {
    position: fixed;
    top: 80px; /* Changed from 20px to position below navbar */
    right: 20px;
    padding: 16px 24px;
    background: var(--gradient);
    color: white;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
    transform: translateX(400px);
    transition: transform 0.4s ease;
    z-index: 999; /* Lower than navbar (usually 1000+) */
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 400px;
}

.notification.show {
    transform: translateX(0);
}

/* Adjust for mobile */
@media (max-width: 768px) {
    .notification {
        top: 70px;
        left: 10px;
        right: 10px;
        width: calc(100% - 20px);
        max-width: none;
        transform: translateY(-100px); /* Changed from translateX */
    }
    
    .notification.show {
        transform: translateY(0);
    }
}

.notification.error {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.notification.success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.notification.warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

/* ===========================
   ANIMATIONS
   =========================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===========================
   RESPONSIVE DESIGN
   =========================== */

@media (max-width: 968px) {
    .game-area {
        grid-template-columns: 1fr;
    }
    
    .editor-panel {
        min-height: 300px;
    }
    
    .clause-pool, .drop-zone {
        min-height: 250px;
        max-height: 250px;
    }
}

@media (max-width: 768px) {
    .hero-h1 {
        font-size: 2rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .hero-para {
        font-size: 1rem;
    }

    .hero-stats {
        gap: 1rem;
    }

    .hero-stats span {
        padding: 6px 15px;
        font-size: 0.9rem;
    }

    .container {
        padding: 2rem 1rem;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .difficulty-selector {
        justify-content: center;
    }
    
    .score-display {
        justify-content: center;
    }
    
    .level-info {
        text-align: center;
        width: 100%;
    }
    
    .panel-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .panel-header span {
        font-size: 1rem;
    }
    
    .panel-btn {
        width: 100%;
        justify-content: center;
    }
    
    .panel-stats {
        width: 100%;
        justify-content: space-between;
    }
    
    .action-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .action-buttons button {
        width: 100%;
        max-width: 300px;
        justify-content: center;
    }
    
    .notification {
        left: 10px;
        right: 10px;
        width: calc(100% - 20px);
        transform: translateY(-100px);
    }
    
    .notification.show {
        transform: translateY(0);
    }
}

@media (max-width: 480px) {
    .container {
        padding: 1.5rem 1rem;
    }
    
    .editor-panel {
        min-height: 250px;
    }
    
    .clause-pool, .drop-zone {
        min-height: 200px;
        max-height: 200px;
        padding: 15px;
    }
    
    .sql-clause {
        padding: 12px;
        font-size: 0.9em;
    }
    
    .assembled-query {
        margin: 10px;
        padding: 10px;
        font-size: 0.85em;
    }
    
    .feedback {
        padding: 20px;
    }
    
    .feedback-icon {
        font-size: 2em;
    }
    
    .feedback-title {
        font-size: 1.2em;
    }
    
    .feedback-message {
        font-size: 1em;
    }
    
    .celebration-text {
        font-size: 3rem;
    }
}