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

/* Prevent double-tap zoom while preserving scrolling and pinch zoom. */
html, body { touch-action: manipulation; }
body * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
body input, body textarea, body [contenteditable]:not([contenteditable="false"]) {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

body {
    overflow: hidden;
    background: #87ceeb;
    font-family: 'Quicksand', sans-serif;
    color: #f7eedb;
    user-select: none;
    -webkit-user-select: none;
}

#canvas-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1;
}

/* ===== MODAL ĐĂNG NHẬP / CHỌN PHÁP DANH ===== */
#login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at 50% 40%, rgba(45, 20, 10, 0.95), rgba(12, 7, 20, 0.98));
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: rgba(28, 16, 38, 0.92);
    border: 2px solid #eab308;
    box-shadow: 0 0 50px rgba(234, 179, 8, 0.4), inset 0 0 30px rgba(180, 83, 9, 0.3);
    border-radius: 28px;
    padding: 35px 30px;
    max-width: 440px;
    width: 100%;
    text-align: center;
    backdrop-filter: blur(16px);
}

.login-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: clamp(22px, 5vw, 30px);
    color: #fde047;
    font-weight: 900;
    text-shadow: 0 0 20px rgba(253, 224, 71, 0.6);
    margin-bottom: 6px;
}

.login-desc {
    font-size: 13.5px;
    color: #e2d4bc;
    margin-bottom: 22px;
    line-height: 1.5;
}

.input-group {
    margin-bottom: 20px;
    text-align: left;
}

.input-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #fbbf24;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.name-row {
    display: flex;
    gap: 10px;
}

.input-box {
    flex: 1;
    padding: 13px 18px;
    background: rgba(255, 255, 255, 0.08);
    border: 1.5px solid rgba(234, 179, 8, 0.5);
    border-radius: 14px;
    font-family: 'Quicksand', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: #fef08a;
    outline: none;
    transition: all 0.3s;
}

.input-box:focus {
    border-color: #fde047;
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 0 16px rgba(253, 224, 71, 0.4);
}

.dice-btn {
    background: rgba(234, 179, 8, 0.2);
    border: 1.5px solid rgba(234, 179, 8, 0.5);
    border-radius: 14px;
    color: #fde047;
    width: 50px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s;
}

.dice-btn:hover {
    background: rgba(234, 179, 8, 0.4);
    transform: rotate(180deg);
}

.enter-btn {
    width: 100%;
    margin-top: 15px;
    padding: 16px;
    background: linear-gradient(135deg, #d97706, #b45309);
    border: 2px solid #fde047;
    border-radius: 16px;
    font-family: 'Quicksand', sans-serif;
    font-size: 17px;
    font-weight: 700;
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(217, 119, 6, 0.5);
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.enter-btn:hover {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(245, 158, 11, 0.6);
}

/* ===== IN-GAME HUD ===== */
#game-hud {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
    display: none;
}

.top-bar {
    position: absolute;
    top: 16px; left: 16px; right: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.temple-badge {
    background: rgba(24, 14, 34, 0.82);
    border: 1.5px solid rgba(234, 179, 8, 0.6);
    border-radius: 20px;
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    backdrop-filter: blur(10px);
    pointer-events: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.temple-name {
    font-family: 'Cinzel Decorative', serif;
    font-size: 15px;
    font-weight: 900;
    color: #fef08a;
    letter-spacing: 0.5px;
}

.online-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    color: #4ade80;
    background: rgba(74, 222, 128, 0.15);
    padding: 3px 10px;
    border-radius: 12px;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0% { transform: scale(0.9); opacity: 0.7; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(0.9); opacity: 0.7; }
}

.top-actions {
    display: flex;
    gap: 8px;
    pointer-events: auto;
    flex-wrap: wrap;
}

.quality-control {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid rgba(234, 179, 8, 0.55);
    border-radius: 16px;
    background: rgba(24, 14, 34, 0.85);
    color: #fef08a;
    font: 700 12px 'Quicksand', sans-serif;
    backdrop-filter: blur(10px);
}
.quality-control select {
    border: 0;
    border-radius: 9px;
    padding: 3px 5px;
    background: rgba(255, 248, 220, 0.95);
    color: #2d1a10;
    font: 700 12px 'Quicksand', sans-serif;
}

.hud-btn {
    background: rgba(24, 14, 34, 0.85);
    border: 1.5px solid rgba(234, 179, 8, 0.6);
    border-radius: 18px;
    padding: 8px 16px;
    color: #fef08a;
    font-family: 'Quicksand', sans-serif;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.25s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 6px;
}

.hud-btn:hover {
    background: rgba(234, 179, 8, 0.25);
    border-color: #fde047;
    transform: translateY(-2px);
}

.hud-btn.green {
    border-color: #4ade80;
    color: #bbf7d0;
    background: rgba(20, 50, 30, 0.85);
}

.hud-btn.green:hover {
    background: rgba(74, 222, 128, 0.25);
}

.merit-counter {
    background: rgba(24, 14, 34, 0.85);
    border: 1.5px solid rgba(234, 179, 8, 0.6);
    border-radius: 18px;
    padding: 8px 16px;
    font-size: 13.5px;
    font-weight: 700;
    color: #fde047;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* ===== ĐÈN NGUYỆN PANEL ===== */
.lantern-panel {
    position: absolute;
    top: 75px;
    right: 16px;
    width: 310px;
    background: rgba(28, 18, 38, 0.88);
    border: 1.5px solid rgba(234, 179, 8, 0.6);
    border-radius: 20px;
    padding: 14px 16px;
    backdrop-filter: blur(12px);
    pointer-events: auto;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: calc(100vh - 220px);
    transition: all 0.3s;
}

.lantern-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(234, 179, 8, 0.3);
    padding-bottom: 8px;
}

.lantern-title {
    font-size: 14.5px;
    font-weight: 700;
    color: #fde047;
    display: flex;
    align-items: center;
    gap: 6px;
}

.lantern-count-badge {
    font-size: 11.5px;
    background: rgba(234, 179, 8, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    color: #fef08a;
}

.lantern-list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 240px;
    padding-right: 4px;
}

.lantern-list::-webkit-scrollbar { width: 4px; }
.lantern-list::-webkit-scrollbar-thumb {
    background: rgba(234, 179, 8, 0.4);
    border-radius: 4px;
}

.lantern-card {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(234, 179, 8, 0.25);
    border-radius: 12px;
    padding: 8px 10px;
    font-size: 12.5px;
}

.lantern-wish {
    color: #fef08a;
    font-weight: 600;
    margin-bottom: 3px;
    line-height: 1.35;
}

.lantern-meta {
    display: flex;
    justify-content: space-between;
    color: #cbd5e1;
    font-size: 11px;
}

.btn-release-lantern {
    background: linear-gradient(135deg, #d97706, #b45309);
    border: 1.5px solid #fde047;
    border-radius: 14px;
    color: #ffffff;
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 14px;
    padding: 10px 14px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(217, 119, 6, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-release-lantern:hover {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    transform: translateY(-2px);
}

/* Modal nhập lời nguyện đèn */
#wish-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.65);
    z-index: 120;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    pointer-events: auto;
}

.wish-modal {
    background: rgba(28, 16, 38, 0.95);
    border: 2px solid #eab308;
    border-radius: 22px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: 0 0 40px rgba(234, 179, 8, 0.4);
}

/* ===== BOTTOM ACTIONS & CHAT ===== */
.bottom-container {
    position: absolute;
    bottom: 16px; left: 16px; right: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    pointer-events: none;
}

.chat-widget {
    background: rgba(24, 14, 34, 0.85);
    border: 1.5px solid rgba(234, 179, 8, 0.5);
    border-radius: 20px;
    width: clamp(280px, 32vw, 380px);
    padding: 12px 14px;
    backdrop-filter: blur(12px);
    pointer-events: auto;
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-messages {
    height: 120px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    padding-right: 4px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(234, 179, 8, 0.4);
    border-radius: 4px;
}

.chat-item { line-height: 1.35; word-break: break-word; }
.chat-item.system { color: #fbbf24; font-style: italic; font-size: 12px; }
.chat-item .author { color: #fde047; font-weight: 700; }

.quick-prayers {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
}
.quick-prayers::-webkit-scrollbar { display: none; }

.prayer-pill {
    background: rgba(234, 179, 8, 0.15);
    border: 1px solid rgba(234, 179, 8, 0.4);
    border-radius: 12px;
    color: #fef08a;
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 10px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}
.prayer-pill:hover { background: rgba(234, 179, 8, 0.35); }

.chat-input-row { display: flex; gap: 8px; }

.chat-input {
    flex: 1;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(234, 179, 8, 0.4);
    border-radius: 12px;
    font-family: 'Quicksand', sans-serif;
    font-size: 13px;
    color: #ffffff;
    outline: none;
}

.chat-send-btn {
    background: #d97706;
    border: none;
    border-radius: 12px;
    color: #ffffff;
    font-weight: 700;
    font-size: 13px;
    padding: 0 14px;
    cursor: pointer;
}

/* Action Toolbar */
.action-toolbar {
    display: flex;
    gap: 8px;
    pointer-events: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.action-btn {
    background: rgba(24, 14, 34, 0.85);
    border: 1.5px solid rgba(234, 179, 8, 0.6);
    border-radius: 18px;
    padding: 10px 14px;
    color: #fef08a;
    font-family: 'Quicksand', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    min-width: 68px;
}

.action-btn span.icon { font-size: 22px; }
.action-btn:hover {
    background: rgba(234, 179, 8, 0.25);
    border-color: #fde047;
    transform: translateY(-3px);
}
.action-btn.btn-woodblock {
    border-color: #f59e0b;
    background: rgba(180, 83, 9, 0.4);
}
.action-btn.active-toggle {
    background: rgba(234, 179, 8, 0.30) !important;
    border-color: #fde047 !important;
    box-shadow: 0 0 12px rgba(234, 179, 8, 0.5);
}

/* Virtual Floating Joystick */
#virtual-joystick-zone {
    position: fixed;
    top: 70px;
    left: 0;
    width: 55%;
    height: calc(100% - 70px);
    z-index: 25;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
}

#joystick-base {
    position: fixed;
    width: 124px;
    height: 124px;
    margin-left: -62px;
    margin-top: -62px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(254, 240, 138, 0.25) 0%, rgba(217, 119, 6, 0.35) 60%, rgba(20, 10, 30, 0.65) 100%);
    border: 2px solid rgba(253, 224, 71, 0.85);
    box-shadow: 0 0 25px rgba(234, 179, 8, 0.5), inset 0 0 15px rgba(234, 179, 8, 0.3);
    display: none;
    pointer-events: none;
    z-index: 30;
}

#joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 52px;
    height: 52px;
    margin-left: -26px;
    margin-top: -26px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fffbeb 0%, #facc15 50%, #b45309 100%);
    border: 2.5px solid #ffffff;
    box-shadow: 0 0 16px rgba(253, 224, 71, 0.9), 0 4px 10px rgba(0,0,0,0.5);
    pointer-events: none;
}

@media (max-width: 768px) {
    .chat-widget {
        display: none;
        width: 100%;
        max-width: 360px;
    }
    .chat-widget.active {
        display: flex !important;
        position: absolute;
        bottom: 85px;
        left: 12px;
        right: 12px;
        z-index: 60;
        box-shadow: 0 0 35px rgba(0,0,0,0.7);
    }
    .lantern-panel { display: none; }
    .bottom-container {
        flex-direction: column-reverse;
        align-items: stretch;
        pointer-events: none;
    }
    .action-toolbar {
        justify-content: center;
        gap: 6px;
    }
    .action-btn {
        padding: 7px 10px;
        min-width: 56px;
        font-size: 11.5px;
        border-radius: 14px;
    }
    .action-btn span.icon { font-size: 18px; }
}

/* Disable expensive live backdrop-filter blur over WebGL canvas on phones/touch devices. */
@media (max-width: 900px), (hover: none) {
    .login-card,
    .temple-badge,
    .quality-control,
    .hud-btn,
    .merit-counter,
    .lantern-panel,
    .chat-widget,
    .action-btn,
    dialog::backdrop {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
}

/* Hiệu ứng nổi chữ công đức */
.merit-float {
    position: fixed;
    transform: translate(-50%, -50%);
    font-family: 'Cinzel Decorative', serif;
    font-size: 24px;
    font-weight: 900;
    color: #fde047;
    text-shadow: 0 0 20px #eab308, 0 0 10px #ffffff;
    pointer-events: none;
    z-index: 99;
    animation: floatUp 1.2s ease-out forwards;
}

@keyframes floatUp {
    0% { opacity: 0; transform: translate(-50%, 0) scale(0.7); }
    30% { opacity: 1; transform: translate(-50%, -30px) scale(1.15); }
    100% { opacity: 0; transform: translate(-50%, -70px) scale(1.0); }
}
