:root {
    --bg-gradient: linear-gradient(135deg, #e0f7fa 0%, #b2ebf2 50%, #e0f2f1 100%);
    --glass-bg: rgba(255, 255, 255, 0.82);
    --glass-border: rgba(255, 255, 255, 0.95);
    --primary-teal: #00796b;
    --primary-hover: #004d40;
    --accent-gold: #d4af37;
    --text-dark: #1e293b;
    --text-muted: #546e7a;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Montserrat', sans-serif;
}

body {
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    color: var(--text-dark);
}

.container {
    width: 100%;
    max-width: 960px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 20px 24px;
    box-shadow: 0 20px 40px rgba(0, 121, 107, 0.14);
}

.game-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(0, 121, 107, 0.15);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-teal), #009688);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 121, 107, 0.25);
    border: 1px solid rgba(212, 175, 55, 0.45);
}

.brand-text h1 {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--primary-teal);
}

.brand-text span {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--accent-gold);
    letter-spacing: 1px;
    margin-top: 2px;
}

.stats-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.stat-pill {
    background: #ffffff;
    border: 1px solid rgba(0, 121, 107, 0.18);
    padding: 6px 12px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-teal);
}

.stat-pill svg {
    width: 16px;
    height: 16px;
    color: var(--accent-gold);
}

.controls {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(0, 121, 107, 0.2);
    background: #ffffff;
    color: var(--primary-teal);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn svg {
    width: 19px;
    height: 19px;
    stroke-width: 2.2;
}

.icon-btn:hover {
    background: var(--primary-teal);
    color: #ffffff;
    transform: translateY(-2px);
}

.icon-btn-secondary {
    color: var(--text-muted);
}

.icon-btn-secondary:hover {
    background: #455a64;
    color: #ffffff;
}

/* Khung Canvas */
.game-wrapper {
    position: relative;
    width: 100%;
    border-radius: 18px;
    overflow: hidden;
    border: 2px solid rgba(212, 175, 55, 0.5);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15);
    background: #5c94fc;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
}

/* Thanh gõ chữ nổi phía dưới màn hình */
.typing-dock {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 420px;
    z-index: 10;
}

#typing-input {
    width: 100%;
    padding: 12px 20px;
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
    color: var(--primary-teal);
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid var(--accent-gold);
    border-radius: 999px;
    outline: none;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
    transition: border-color 0.2s, transform 0.1s;
}

#typing-input:focus {
    border-color: var(--primary-teal);
}

#typing-input.shake {
    animation: shake 0.3s ease;
    border-color: #ef4444;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* Overlay Bắt đầu / Kết thúc */
.overlay-screen {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    padding: 20px;
}

.overlay-screen.hidden {
    display: none;
}

.overlay-card {
    background: #ffffff;
    padding: 28px 32px;
    border-radius: 22px;
    text-align: center;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--accent-gold);
}

.overlay-card h2 {
    color: var(--primary-teal);
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.overlay-card p {
    color: var(--text-muted);
    font-size: 0.92rem;
    margin-bottom: 20px;
}

.level-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 22px;
}

.level-btn {
    padding: 10px 14px;
    border-radius: 12px;
    border: 1.5px solid #cbd5e1;
    background: #f8fafc;
    color: var(--text-dark);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s;
}

.level-btn.active {
    background: #e0f2f1;
    border-color: var(--primary-teal);
    color: var(--primary-teal);
}

.start-btn {
    width: 100%;
    padding: 13px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, var(--primary-teal), #009688);
    color: #ffffff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 20px rgba(0, 121, 107, 0.3);
    transition: transform 0.2s;
}

.start-btn:hover {
    transform: translateY(-2px);
}

.game-footer {
    margin-top: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.game-footer svg {
    width: 18px;
    height: 18px;
    color: var(--primary-teal);
}

/* Modal & Toast */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 16px;
}

.modal-overlay.hidden { display: none; }

.modal-card {
    background: #ffffff;
    border-radius: 20px;
    max-width: 520px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h2 {
    font-size: 1.1rem;
    color: var(--primary-teal);
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn-sm { width: 34px; height: 34px; }

.modal-body ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.modal-body li {
    background: #f0fdfa;
    padding: 10px 14px;
    border-radius: 10px;
    border-left: 3px solid var(--primary-teal);
}

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: rgba(15, 23, 42, 0.92);
    color: #ffffff;
    padding: 11px 16px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
    border-left: 4px solid var(--accent-gold);
    animation: slideIn 0.3s ease forwards;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}