/* --- BIẾN HỆ THỐNG --- */
:root {
    --primary: #3b82f6; 
    --accent: #8b5cf6; 
    --bg: #020617;
    --sidebar: #0f172a; 
    --card: #1e293b; 
    --border: rgba(255,255,255,0.1);
    --term-bg: #000000; 
    --term-text: #4ade80;
    --header-height: 70px;
}

/* --- THIẾT LẬP CHUNG --- */
* { 
    box-sizing: border-box; 
    transition: all 0.2s ease; 
}

body { 
    margin: 0; 
    font-family: 'Inter', -apple-system, sans-serif; 
    background: var(--bg); 
    color: #fff; 
    overflow: hidden; 
    height: 100vh; 
    -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* --- HỆ THỐNG VIEW --- */
.view { 
    display: none; 
    opacity: 0; 
    height: 100%; 
    transition: opacity 0.3s ease;
}

.view.active { 
    display: block !important; 
    opacity: 1; 
}

#view-start {
    display: none;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: 9999;
    background: var(--bg);
}

#view-start.active { display: flex !important; }

.hidden { display: none !important; }

/* --- NÚT BẤM --- */
button { 
    cursor: pointer; 
    border: none; 
    font-weight: 700; 
    border-radius: 8px; 
    padding: 10px 20px; 
    font-size: 13px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #2563eb; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(59,130,246,0.3); }
.btn-success { background: #10b981; color: white; }
.btn-success:hover { background: #059669; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(16,185,129,0.3); }
.btn-danger { background: #f43f5e; color: white; }
.btn-danger:hover { background: #e11d48; transform: translateY(-2px); }
.btn-outline { 
    background: rgba(255,255,255,0.05); 
    border: 1px solid var(--border); 
    color: #94a3b8; 
}
.btn-outline:hover { 
    color: white; 
    border-color: var(--primary); 
    background: rgba(59, 130, 246, 0.1); 
    transform: translateY(-2px);
}

/* --- LAYOUT CHÍNH --- */
.app-layout { 
    display: flex; 
    height: 100vh; 
    width: 100vw; 
}

.sidebar { 
    width: 280px; 
    background: var(--sidebar); 
    padding: 30px; 
    border-right: 1px solid var(--border); 
    display: flex; 
    flex-direction: column; 
    flex-shrink: 0; 
}

.sidebar h1 {
    font-size: 24px;
    margin-bottom: 40px;
    background: linear-gradient(to right, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.main-body { 
    flex: 1; 
    padding: 25px; 
    overflow-y: auto; 
    background: var(--bg); 
}

/* --- DANH SÁCH BÀI TẬP --- */
.grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); 
    gap: 20px; 
}

.problem-card {
    cursor: pointer;
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    padding: 25px;
    border-radius: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.problem-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    background: linear-gradient(145deg, var(--card), #111827);
}

.prob-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 800;
    margin-bottom: 12px;
    text-transform: uppercase;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* --- IDE CONTAINER --- */
.ide-container { 
    display: grid; 
    grid-template-columns: 380px 1fr; 
    gap: 20px; 
    height: calc(100vh - 100px); 
    margin-top: 15px; 
}

.ide-left { 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    overflow-y: auto; 
    padding-right: 5px;
}

.ide-right { 
    display: grid; 
    grid-template-rows: 1fr 220px; 
    gap: 15px; 
    overflow: hidden; 
}

/* --- EDITOR --- */
.editor-section { 
    position: relative; 
    background: #0d1117; 
    border-radius: 12px; 
    border: 1px solid #30363d; 
    overflow: hidden; 
    display: flex; 
    flex-direction: column; 
    transition: border-color 0.2s, box-shadow 0.2s;
}

.editor-section:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,0.2); }

.editor-wrapper { 
    flex: 1; 
    position: relative; 
}

#code-editor, #highlighting-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    padding: 20px; 
    font-family: 'Fira Code', 'Cascadia Code', monospace; 
    font-size: 14px; 
    line-height: 1.6;
    border: none !important; 
    outline: none !important; 
    margin: 0; 
    white-space: pre; 
    overflow: auto;
    tab-size: 4;
}

#code-editor { 
    color: transparent !important; 
    background: transparent !important; 
    caret-color: white; 
    z-index: 2; 
    resize: none; 
}

#highlighting-layer { z-index: 1; pointer-events: none; }

/* --- TERMINAL --- */
.pane-header { 
    background: #1e293b; 
    padding: 12px 18px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: 11px; 
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8; 
    border-bottom: 1px solid #334155;
}

.terminal-body { 
    background: var(--term-bg); 
    color: var(--term-text); 
    padding: 15px; 
    font-family: 'JetBrains Mono', 'Consolas', monospace; 
    flex: 1; 
    overflow-y: auto; 
    font-size: 13px; 
    line-height: 1.5; 
    border-top: 1px solid #333; 
}

.terminal-body .test-row {
    margin-bottom: 12px;
    border-left: 3px solid #334155;
    padding-left: 12px;
    transition: all 0.2s;
}

.terminal-body .test-header {
    font-weight: bold;
    color: #94a3b8;
    margin-bottom: 4px;
}

.terminal-body .test-status {
    display: inline-block;
    margin-left: 10px;
}

.terminal-body .test-detail {
    font-size: 12px;
    color: #aaa;
    margin-top: 4px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- ADMIN & INPUT --- */
.input-modern { 
    width: 100%; 
    padding: 14px; 
    background: #0f172a; 
    border: 1px solid #334155; 
    border-radius: 8px; 
    color: white; 
    margin-bottom: 12px; 
    outline: none; 
    transition: border 0.2s, box-shadow 0.2s;
}

.input-modern:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,0.2); }

.testcase-row { 
    display: grid; 
    grid-template-columns: 1fr 1fr 100px; 
    gap: 12px; 
    background: rgba(255,255,255,0.03); 
    padding: 15px; 
    border-radius: 12px; 
    margin-bottom: 12px; 
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.testcase-row:hover {
    background: rgba(255,255,255,0.07);
    border-color: var(--primary);
}

/* --- RESPONSIVE (MOBILE TỐI ƯU) --- */
@media (max-width: 768px) {
    body { overflow-y: auto; height: auto; }
    
    .app-layout { flex-direction: column; }
    
    .sidebar { 
        width: 100%; 
        height: auto; 
        padding: 10px 15px; 
        flex-direction: row; 
        align-items: center; 
        justify-content: space-between; 
        position: sticky; 
        top: 0; 
        z-index: 1000;
        border-right: none; 
        border-bottom: 1px solid var(--border);
    }

    .sidebar h1 { font-size: 18px; margin-bottom: 0; }

    .sidebar nav { 
        display: flex !important;
        flex-direction: row !important; 
        gap: 8px; 
    }
    
    .sidebar button {
        padding: 8px 12px;
        font-size: 12px;
    }

    .sidebar div#current-code-display, 
    .sidebar .footer-info { display: none; }

    .main-body { padding: 15px; padding-top: 20px; }
    
    .ide-container { 
        grid-template-columns: 1fr; 
        height: auto; 
    }

    .ide-right { 
        grid-template-rows: 450px 300px; 
    }
    
    .grid { grid-template-columns: 1fr; }
    
    #code-editor, #highlighting-layer { 
        font-size: 16px; /* Chống auto-zoom trên iPhone */
    }

    .testcase-row {
        grid-template-columns: 1fr;
    }
}

/* Đảm bảo 2 lớp đè khít lên nhau */
#code-editor, #highlighting-layer, #highlighting-content {
    font-family: 'Fira Code', 'Consolas', monospace !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    padding: 20px !important;
    box-sizing: border-box !important;
    tab-size: 4;
    white-space: pre !important; 
    word-wrap: normal !important;
}

/* Ẩn chữ trong textarea nhưng vẫn giữ con trỏ gõ */
#code-editor {
    color: transparent !important;
    caret-color: white !important;
    background: transparent !important;
}

.firework-particle {
    position: fixed;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000;
}

#congrats-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid var(--primary);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    z-index: 10001;
    display: none;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 0 50px rgba(59, 130, 246, 0.5);
    backdrop-filter: blur(5px);
}

#congrats-modal.active {
    display: block !important;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Triệt tiêu mọi khoảng cách mặc định có thể gây lệch dòng đầu */
#highlighting-layer, 
#highlighting-content {
    margin: 0 !important;
    padding: 0 !important;
    display: block;
}

#highlighting-layer {
    padding: 20px !important;
    box-sizing: border-box !important;
}

/* Hiệu ứng loading cho nút */
.btn-success.loading {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

/* Animation cho terminal */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.terminal-body .test-row {
    animation: fadeIn 0.2s ease-out;
}