/* --- CORE CSS --- */
:root { 
    --bg-body: #0f172a; 
    --bg-card: #1e293b; 
    --border-color: rgba(255,255,255,0.08); 
    --primary: #6366f1; 
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --text-main: #f8fafc; 
    --text-muted: #94a3b8; 
    --success: #10b981; 
    --danger: #ef4444; 
    --warning: #f59e0b; 
}

body { 
    background: var(--bg-body); 
    color: var(--text-main); 
    font-family: 'Plus Jakarta Sans', sans-serif; 
    margin: 0; padding: 0; 
    -webkit-font-smoothing: antialiased; 
    -webkit-tap-highlight-color: transparent;
}

.container { max-width: 1200px; margin: 0 auto; padding: 30px 20px; }

/* HEADER */
.site-header { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 20px 0; border-bottom: 1px solid var(--border-color); margin-bottom: 30px; 
    flex-wrap: wrap; gap: 20px; 
}
.logo { 
    font-family: 'Plus Jakarta Sans', sans-serif; font-size: 1.8rem; font-weight: 800; color: white; 
    text-decoration: none; display: flex; align-items: center; gap: 10px; letter-spacing: -0.5px;
}
.logo-icon {
    width: 40px; height: 40px; background: var(--primary-gradient); border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem; color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}
.logo-text { background: -webkit-linear-gradient(0deg, #fff, #94a3b8); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo span { color: var(--primary); -webkit-text-fill-color: var(--primary); }

.header-info { text-align: right; display: flex; align-items: center; gap: 15px; }
.current-time { 
    font-size: 0.9rem; font-weight: 600; color: var(--text-muted); 
    background: rgba(255,255,255,0.03); padding: 8px 18px; border-radius: 50px; 
    display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--border-color);
    transition: 0.3s;
}
.current-time i { color: var(--primary); }

/* --- CARD DESIGN (SQUARE FIXED) --- */
.exam-grid { 
    display: grid; 
    /* Tăng min-width lên 280px-300px để đảm bảo hình vuông đủ rộng */
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); 
    gap: 25px; 
}

.exam-card { 
    background: var(--bg-card); 
    border: 1px solid var(--border-color); 
    border-radius: 24px; 
    padding: 20px; /* Giảm padding để tiết kiệm diện tích */
    display: flex; flex-direction: column; 
    justify-content: space-between;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative; overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    
    /* [IMPORTANT] Square Ratio Logic */
    aspect-ratio: 1 / 1; 
    height: auto;
    min-height: unset; /* Bỏ min-height cũ */
}
.exam-card:hover { transform: translateY(-5px); border-color: rgba(99, 102, 241, 0.5); box-shadow: 0 15px 30px -10px rgba(0, 0, 0, 0.4); }

/* Top Row */
.card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.status-badge { 
    font-size: 0.65rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
    padding: 5px 10px; border-radius: 6px; display: inline-block;
}
.st-open { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.2); }
.st-closed { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.2); }
.st-upcoming { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.2); }

.btn-share-round {
    width: 28px; height: 28px; border-radius: 8px; 
    background: rgba(255,255,255,0.05); border: 1px solid var(--border-color);
    color: var(--text-muted); display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s; font-size: 0.9rem;
    -webkit-tap-highlight-color: transparent;
}
.btn-share-round:hover { background: var(--primary); color: white; border-color: var(--primary); }

/* Middle Info Block */
.card-mid { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    gap: 4px; /* Khoảng cách rất nhỏ để tối ưu không gian */
    margin-bottom: 10px;
    overflow: hidden;
}

.exam-title { 
    font-family: 'Plus Jakarta Sans', sans-serif; font-size: 1.25rem; font-weight: 700; 
    line-height: 1.3; color: white; 
    /* [FIX] Cố định chiều cao cho 2 dòng text để căn hàng */
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    height: 2.6em; /* 1.3em * 2 dòng */
    margin-bottom: 6px;
}

/* Creator Info Styles */
.creator-info {
    display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
    text-decoration: none; width: fit-content;
}
.creator-avatar {
    width: 26px; height: 26px; border-radius: 50%; object-fit: cover;
    border: 1px solid var(--border-color); flex-shrink: 0;
}
.creator-name {
    font-size: 0.8rem; color: var(--text-muted); font-weight: 500;
    transition: 0.2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px;
}
.creator-info:hover .creator-name { color: var(--primary); }

/* Detailed Info Grid in Card - COMPACT */
.info-box {
    background: rgba(0,0,0,0.2); border-radius: 12px; padding: 10px;
    display: flex; flex-direction: column; gap: 6px; 
    margin-top: auto; /* Đẩy xuống đáy vùng mid */
}
.info-row-card { display: flex; justify-content: space-between; font-size: 0.8rem; align-items: center; }
.info-row-card span:first-child { color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.info-row-card span:first-child i { color: var(--primary); width: 14px; text-align: center; font-size: 0.8rem; }
.info-row-card span.val { color: var(--text-main); font-weight: 600; font-family: 'Plus Jakarta Sans', sans-serif; }
.info-divider { height: 1px; background: var(--border-color); opacity: 0.5; margin: 0; }

/* Bottom Action */
.btn-enter { 
    width: 100%; padding: 12px; 
    background: var(--primary-gradient); color: white; border: none; border-radius: 12px; 
    font-weight: 700; font-size: 0.9rem; cursor: pointer; transition: 0.3s; 
    display: flex; align-items: center; justify-content: center; gap: 8px;
    -webkit-tap-highlight-color: transparent;
    margin-top: auto; 
    flex-shrink: 0;
}
.btn-enter:hover { filter: brightness(1.1); transform: translateY(-2px); }
.btn-disabled { background: rgba(255,255,255,0.05); color: #64748b; cursor: not-allowed; }
.btn-disabled:hover { transform: none; }
.reason-text { font-size:0.7rem; font-weight: 500; color:var(--danger); text-align:center; height: 1.1em; margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- TOAST & MODALS (Giữ nguyên hoặc chỉnh nhẹ) --- */
.toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px);
    background: rgba(30, 41, 59, 0.95); backdrop-filter: blur(10px);
    border: 1px solid rgba(16,185,129,0.3); color: #34d399; padding: 12px 24px; 
    border-radius: 50px; box-shadow: 0 10px 40px -10px rgba(0,0,0,0.6); 
    opacity: 0; transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 10000; 
    font-weight: 600; display: flex; align-items: center; gap: 10px;
    max-width: 90%; width: max-content; white-space: nowrap; 
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(2, 6, 23, 0.9); backdrop-filter: blur(5px); z-index: 9999; display: none; align-items: center; justify-content: center; padding: 20px; box-sizing: border-box; }
.modal-overlay.open { display: flex; animation: modalFadeIn 0.3s ease-out; }
.modal-box { background: var(--bg-card); width: 100%; max-width: 450px; border-radius: 24px; padding: 35px; border: 1px solid var(--border-color); position: relative; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.6); transform: scale(0.95); transition: 0.3s; }
.modal-overlay.open .modal-box { transform: scale(1); }
@keyframes modalFadeIn { from{opacity:0;} to{opacity:1;} }

.info-grid-modal { display: grid; grid-template-columns: 1fr; gap: 15px; margin: 25px 0; background: rgba(255,255,255,0.03); padding: 20px; border-radius: 16px; border: 1px solid var(--border-color); }
.info-row-modal { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border-color); padding-bottom: 8px; margin-bottom: 8px; }
.info-row-modal:last-child { border-bottom: none; margin-bottom: 0; }
.info-label { font-size: 0.9rem; color: var(--text-muted); font-weight: 600; }
.info-value { font-size: 0.95rem; color: white; font-weight: 600; font-family: 'Plus Jakarta Sans', sans-serif; }

.form-input { width: 100%; padding: 14px; background: #020617; border: 1px solid var(--border-color); color: white; border-radius: 10px; outline: none; box-sizing: border-box; font-size: 1rem; margin-bottom: 15px; }
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15); }
.form-label { display: block; margin-bottom: 8px; color: var(--text-muted); font-size: 0.8rem; font-weight: 700; text-transform: uppercase; }
.login-error { color: #f87171; font-size: 0.9rem; text-align: center; margin-bottom: 20px; display: none; background: rgba(239,68,68,0.1); padding: 10px; border-radius: 8px; }
.info-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed var(--border-color); color: var(--text-main); font-size: 0.9rem; }

/* --- MOBILE ADJUSTMENTS --- */
@media (max-width: 600px) {
    .container { padding: 15px; }
    .site-header { margin-bottom: 20px; gap: 10px; }
    
    /* Trên mobile có thể bỏ chế độ hình vuông bắt buộc để hiển thị tốt hơn nếu cần, 
       nhưng ở đây vẫn giữ logic compact */
    .exam-grid { grid-template-columns: 1fr; gap: 20px; }
    
    .exam-card { 
        padding: 20px; 
        aspect-ratio: auto; /* Mobile không cần vuông */
        min-height: auto; 
    }
    
    .exam-title { font-size: 1.25rem; height: auto; -webkit-line-clamp: 3; }
    .btn-enter { padding: 14px; font-size: 1rem; }
    .modal-box { padding: 25px 20px; width: 90%; }
    .toast { font-size: 0.9rem; padding: 10px 20px; bottom: 20px; }
}