@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary: #3b82f6;
    --primary-dark: #1d4ed8;
    --accent: #6366f1;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-dark: #0f172a;
    --bg-card: rgba(255,255,255,0.08);
    --glass: rgba(255,255,255,0.1);
    --glass-border: rgba(255,255,255,0.15);
}

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

body {
    font-family: 'Kanit', sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    color: #e2e8f0;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

/* ===== SCREEN MANAGEMENT ===== */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ===== WELCOME SCREEN ===== */
#welcome-screen {
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}

.welcome-bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
    animation: orbFloat 8s ease-in-out infinite;
}
.orb-1 { width: 300px; height: 300px; background: #6366f1; top: -100px; left: -80px; }
.orb-2 { width: 250px; height: 250px; background: #3b82f6; bottom: -60px; right: -60px; animation-delay: -3s; }
.orb-3 { width: 200px; height: 200px; background: #8b5cf6; top: 40%; left: 60%; animation-delay: -5s; }

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, -20px) scale(1.1); }
}

.welcome-content {
    text-align: center;
    z-index: 1;
    max-width: 600px;
    width: 100%;
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, #6366f1, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 10px rgba(99,102,241,0.3)); }
    50% { filter: drop-shadow(0 0 25px rgba(99,102,241,0.6)); }
}

.welcome-title {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.welcome-subtitle {
    font-size: 0.95rem;
    color: #94a3b8;
    margin-bottom: 2rem;
    font-weight: 300;
}

/* ===== SCENARIO CARDS ===== */
.scenario-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.scenario-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    position: relative;
    overflow: hidden;
}

.scenario-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: linear-gradient(135deg, transparent 60%, rgba(99,102,241,0.1));
    opacity: 0;
    transition: opacity 0.3s;
}

.scenario-card:hover, .scenario-card:active {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(59,130,246,0.2);
}
.scenario-card:hover::before, .scenario-card:active::before { opacity: 1; }

.scenario-card-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
}

.scenario-card-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: #f1f5f9;
    margin-bottom: 0.25rem;
}

.scenario-card-desc {
    font-size: 0.8rem;
    color: #94a3b8;
    font-weight: 300;
    line-height: 1.5;
}

.scenario-card-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 999px;
    margin-top: 0.75rem;
    font-weight: 500;
}

/* ===== GAME SCREEN ===== */
#game-screen { min-height: 100vh; }

.game-header {
    background: rgba(15,23,42,0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 30;
}

.game-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.back-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    color: #94a3b8;
    border-radius: 10px;
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.1rem;
}
.back-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }

.game-header-title { font-weight: 600; font-size: 1rem; color: #f1f5f9; }
.game-header-sub { font-size: 0.7rem; color: #64748b; font-weight: 300; }

/* Stats bar */
.stats-bar {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(30,41,59,0.5);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    color: #94a3b8;
}
.stat-chip i { font-size: 0.9rem; }
.stat-chip .val { color: #f1f5f9; font-weight: 600; }

.timer-chip { color: #fbbf24; border-color: rgba(251,191,36,0.2); background: rgba(251,191,36,0.08); }
.timer-chip.danger { color: #f87171; border-color: rgba(248,113,113,0.3); background: rgba(248,113,113,0.1); animation: timer-pulse 1s infinite; }

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

/* Scenario brief */
.scenario-brief {
    margin: 1rem;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1rem 1.25rem;
    position: relative;
    overflow: hidden;
}
.scenario-brief::before {
    content: '';
    position: absolute;
    left: 0; top: 0;
    width: 4px; height: 100%;
    background: linear-gradient(to bottom, var(--primary), var(--accent));
    border-radius: 4px 0 0 4px;
}

.scenario-brief-title { font-weight: 600; font-size: 1rem; color: #f1f5f9; margin-bottom: 0.35rem; }
.scenario-brief-text { font-size: 0.8rem; color: #94a3b8; line-height: 1.6; font-weight: 300; }
.scenario-brief-text strong { color: #c7d2fe; font-weight: 500; }

/* Game layout */
.game-body { flex: 1; padding: 0 1rem 7rem; }

.section-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 1rem 0 0.5rem;
}
.section-label h3 {
    font-size: 0.85rem;
    font-weight: 500;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 6px;
}
.section-label h3 i { font-size: 1rem; }
.count-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    color: #64748b;
}

/* Block containers */
.block-container {
    min-height: 120px;
    border-radius: 0.75rem;
    padding: 0.5rem;
    transition: all 0.3s;
}

.available-zone {
    background: rgba(255,255,255,0.03);
    border: 1px dashed rgba(255,255,255,0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.workflow-zone {
    background: rgba(99,102,241,0.04);
    border: 1px solid rgba(99,102,241,0.15);
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Step blocks */
.step-block {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.75rem;
    border-radius: 0.6rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.82rem;
    font-weight: 400;
    position: relative;
}

.step-block:active { transform: scale(0.97); }

/* Available blocks */
.avail-block {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: #cbd5e1;
    flex: 0 0 calc(50% - 0.25rem);
}
.avail-block:hover { border-color: var(--primary); background: rgba(59,130,246,0.08); }

.avail-block .block-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.06);
    color: #94a3b8;
    font-size: 1rem;
    flex-shrink: 0;
}
.avail-block .block-text { flex: 1; line-height: 1.35; }
.avail-block .block-add { color: #3b82f6; font-size: 1.1rem; flex-shrink: 0; }

/* Selected blocks */
.selected-block {
    background: rgba(99,102,241,0.08);
    border: 1px solid rgba(99,102,241,0.25);
    color: #e0e7ff;
    margin-bottom: 0;
}
.selected-block:hover { border-color: rgba(99,102,241,0.5); }

.step-num {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.selected-block .block-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(99,102,241,0.15);
    color: #a5b4fc;
    font-size: 1rem;
    flex-shrink: 0;
}
.selected-block .block-text { flex: 1; line-height: 1.35; }

.block-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.block-controls button {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.15s;
}
.block-controls button:hover { color: #a5b4fc; background: rgba(99,102,241,0.15); }
.block-controls button:disabled { opacity: 0.25; cursor: default; }
.block-controls .remove-btn:hover { color: #fca5a5; background: rgba(239,68,68,0.15); }

/* Connector arrow */
.connector {
    display: flex;
    justify-content: center;
    padding: 2px 0;
    color: rgba(99,102,241,0.3);
    font-size: 0.8rem;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1rem;
    color: #475569;
    text-align: center;
}
.empty-state i { font-size: 2rem; margin-bottom: 0.5rem; }
.empty-state p { font-size: 0.8rem; }

/* ===== BOTTOM BAR ===== */
.bottom-bar {
    position: fixed;
    bottom: 0; left: 0;
    width: 100%;
    padding: 1rem;
    background: rgba(15,23,42,0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255,255,255,0.08);
    z-index: 20;
}

.submit-btn {
    width: 100%;
    padding: 0.85rem;
    border: none;
    border-radius: 0.75rem;
    font-family: 'Kanit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: 0 4px 20px rgba(99,102,241,0.3);
}
.submit-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 30px rgba(99,102,241,0.4); }
.submit-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(8px);
    z-index: 50;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.show { display: flex; }

.modal-card {
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.1);
    width: 100%;
    max-width: 480px;
    border-radius: 1.25rem 1.25rem 0.75rem 0.75rem;
    overflow: hidden;
    animation: modalSlideUp 0.35s ease-out;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

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

.modal-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.modal-header.success { background: linear-gradient(135deg, #059669, #10b981); }
.modal-header.warning { background: linear-gradient(135deg, #d97706, #f59e0b); }
.modal-header.error { background: linear-gradient(135deg, #dc2626, #ef4444); }

.modal-header-icon {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    color: #fff;
    flex-shrink: 0;
}
.modal-header-title { font-weight: 700; font-size: 1.1rem; color: #fff; flex: 1; }
.modal-close {
    background: none; border: none;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 1.3rem;
    padding: 4px;
    transition: color 0.2s;
}
.modal-close:hover { color: #fff; }

.modal-body {
    padding: 1.25rem 1.5rem;
    overflow-y: auto;
    color: #cbd5e1;
    font-size: 0.9rem;
    line-height: 1.7;
}
.modal-body strong { color: #f1f5f9; }

.hint-box {
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    background: rgba(255,255,255,0.04);
    border-left: 3px solid #fbbf24;
    border-radius: 0 0.5rem 0.5rem 0;
}
.hint-box-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #fbbf24;
    margin-bottom: 0.35rem;
    display: flex;
    align-items: center;
    gap: 5px;
}
.hint-box-text { font-size: 0.82rem; color: #94a3b8; line-height: 1.6; }
.hint-box-text strong { color: #e2e8f0; }

.score-display {
    margin-top: 1rem;
    text-align: center;
    padding: 1rem;
    background: rgba(16,185,129,0.08);
    border: 1px solid rgba(16,185,129,0.2);
    border-radius: 0.75rem;
}
.score-number { font-size: 2.5rem; font-weight: 800; color: #34d399; }
.score-label { font-size: 0.75rem; color: #6ee7b7; }

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    gap: 0.5rem;
}
.modal-footer button {
    flex: 1;
    padding: 0.7rem;
    border: none;
    border-radius: 0.6rem;
    font-family: 'Kanit', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.modal-btn-secondary {
    background: rgba(255,255,255,0.06);
    color: #94a3b8;
    border: 1px solid rgba(255,255,255,0.1) !important;
}
.modal-btn-secondary:hover { background: rgba(255,255,255,0.1); }
.modal-btn-primary { color: #fff; }
.modal-btn-primary.green { background: #10b981; }
.modal-btn-primary.green:hover { background: #059669; }
.modal-btn-primary.yellow { background: #f59e0b; }
.modal-btn-primary.yellow:hover { background: #d97706; }
.modal-btn-primary.red { background: #ef4444; }
.modal-btn-primary.red:hover { background: #dc2626; }

/* ===== CONFETTI ===== */
.confetti-piece {
    position: fixed;
    width: 10px;
    height: 10px;
    z-index: 100;
    animation: confettiFall 3s ease-in forwards;
}
@keyframes confettiFall {
    0% { opacity: 1; transform: translateY(0) rotate(0deg); }
    100% { opacity: 0; transform: translateY(100vh) rotate(720deg); }
}

/* ===== RESPONSIVE ===== */
@media (min-width: 768px) {
    .welcome-title { font-size: 2.8rem; }
    .scenario-grid { flex-direction: row; }
    .scenario-card { flex: 1; }
    .game-columns { display: flex; gap: 1.5rem; }
    .game-col { flex: 1; }
    .avail-block { flex: 0 0 calc(50% - 0.25rem); }
    .modal-overlay { align-items: center; }
    .modal-card { border-radius: 1.25rem; }
    .submit-btn { max-width: 400px; margin: 0 auto; }
}

/* scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
