:root {
    --bg: #0b0b0d;
    --panel: #16161a;
    --accent: #e74c3c;
    --text: #dcdde1;
    --btn: #35353f;
    --gold: #fdcb6e;
}

body {
    font-family: 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    gap: 15px;
    padding: 15px;
    height: 95vh;
    overflow: hidden;
    margin: 0;
    flex-direction: row;
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
        overflow-y: auto;
        height: auto;
    }

    .panel {
        flex: none !important;
    }
}

.panel {
    background: var(--panel);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
}

.stats-panel {
    flex: 1;
    min-width: 300px;
}

.controls-panel {
    flex: 2;
    overflow-y: auto;
}

.log-panel {
    flex: 1.5;
}

.stat-card {
    background: #1e1e24;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid #444;
}

.stat-card b {
    color: var(--gold);
    font-size: 1.2em;
}

/* Sửa lại container để tin nhắn mới nằm dưới cùng */
.log-container {
    flex-grow: 1;
    overflow-y: auto;
    background: #000;
    padding: 10px;
    font-family: 'Consolas', monospace;
    display: flex;
    flex-direction: column;
    /* Đổi từ column-reverse sang column */
    font-size: 0.82em;
    border-radius: 4px;
    border: 1px solid #222;
    min-height: 200px;
    scroll-behavior: smooth;
}

/* Hiệu ứng highlight cho tin nhắn mới nhất */
.log-entry {
    margin-bottom: 6px;
    border-left: 4px solid #555;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.02);
    animation: highlight-new 2s ease-out;
    /* Hiệu ứng highlight */
}

@keyframes highlight-new {
    0% {
        background: rgba(241, 196, 15, 0.2);
        transform: translateX(5px);
    }

    100% {
        background: rgba(255, 255, 255, 0.02);
        transform: translateX(0);
    }
}

/* Màu sắc cho từng loại log */
.log-action {
    border-color: #9b59b6;
    color: #d199ff;
}

.log-pos {
    border-color: #2ecc71;
    color: #55efc4;
}

.log-neg {
    border-color: #e74c3c;
    color: #ff7675;
}

.building-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.building-item {
    background: #1e1e24;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #333;
    position: relative;
}

.building-item.c2-main {
    border: 2px solid #3498db;
}

.type-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 0.7em;
    padding: 2px 5px;
    border-radius: 3px;
    background: #000;
    border: 1px solid #444;
}

.b-stats-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75em;
    margin-top: 5px;
    color: #aaa;
}

.b-stat-item {
    display: flex;
    align-items: center;
    gap: 3px;
}

.txt-acad {
    color: #3498db;
}

.txt-hap {
    color: #2ecc71;
}

.txt-gold {
    color: #fdcb6e;
}

.progress-bg {
    background: #000;
    height: 8px;
    border-radius: 4px;
    margin: 10px 0;
    overflow: hidden;
}

.progress-fill {
    background: #2ecc71;
    height: 100%;
    width: 0%;
    transition: width 0.2s linear;
}

.global-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
}

.mini-stat {
    background: #1e1e24;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.mini-stat label {
    font-size: 0.7em;
    text-transform: uppercase;
    color: #888;
    margin-bottom: 4px;
}

.mini-stat b {
    font-size: 1.2em;
    font-family: 'Consolas', monospace;
}

.val-gold {
    color: var(--gold);
}

.val-stud {
    color: #9b59b6;
}

.val-acad {
    color: #3498db;
}

.val-hap {
    color: #2ecc71;
}

.btn-group {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
}

button {
    background: var(--btn);
    color: white;
    border: 1px solid #444;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9em;
}

button:hover:not(:disabled) {
    border-color: var(--gold);
}

button.primary {
    background: #27ae60;
    border: none;
}

button.danger {
    background: #c0392b;
    border: none;
}

button:disabled {
    opacity: 0.3;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #25252b;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid #444;
}

input,
select {
    background: #000;
    color: var(--gold);
    border: 1px solid #555;
    padding: 5px;
    border-radius: 4px;
}

#critical-alert {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(231, 76, 60, 0.4);
    z-index: 3000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.alert-box {
    background: #16161a;
    padding: 30px;
    border-radius: 12px;
    border: 3px solid #e74c3c;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

#game-over {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.98);
    z-index: 2000;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* Container bọc nút để xác định vị trí tooltip */
.upgrade-btn-wrapper {
    position: relative;
    width: 100%;
}

/* Tooltip tùy chỉnh sử dụng thuộc tính title (hoặc bạn có thể đổi sang data-tooltip) */
/* Lưu ý: Cách đơn giản nhất là dùng title mặc định, nhưng nếu muốn CSS: */
.upgrade-btn-wrapper:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a1a;
    color: #fff;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #fdcb6e;
    font-size: 0.85em;
    white-space: pre-wrap; /* Quan trọng để hiển thị xuống dòng \n */
    width: 200px;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

/* Mũi tên nhỏ dưới tooltip */
.upgrade-btn-wrapper:hover::before {
    content: "";
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: #fdcb6e;
    z-index: 101;
}