/* ===================================
   CỔ TIÊN KỶ ONLINE - Main Styles
   HD Xianxia Watercolor Remaster
   =================================== */

/* Google Fonts */
/* CSS Custom Properties / Design Tokens */
:root {
    /* Core Palette - Mystic Xianxia */
    --primary: #a78bfa;
    --primary-dark: #7c3aed;
    --primary-light: #c4b5fd;
    --secondary: #22d3ee;
    --secondary-dark: #06b6d4;
    --accent-gold: #f6c94e;
    --accent-rose: #f472b6;

    /* Faction Colors */
    --luc-color: #ef4444;
    --hoa-color: #f97316;
    --thuy-color: #3b82f6;
    --tho-color: #c49a3c;
    --moc-color: #22c55e;

    /* Background layers */
    --bg-deep: #06060f;
    --bg-dark: #0a0a1a;
    --bg-panel: rgba(8, 6, 22, 0.92);
    --bg-panel-light: rgba(18, 12, 40, 0.88);
    --bg-glass: rgba(12, 8, 28, 0.72);
    --bg-glass-light: rgba(22, 16, 48, 0.55);

    /* Border & Glow */
    --border-gold: rgba(246, 201, 78, 0.35);
    --border-glow: rgba(167, 139, 250, 0.35);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-ornament: rgba(246, 201, 78, 0.2);

    /* Text */
    --text-primary: #ede9fe;
    --text-secondary: #a1a1c7;
    --text-accent: #c4b5fd;
    --text-gold: #fcd34d;
    --text-dim: rgba(255, 255, 255, 0.4);

    /* HP/MP/XP */
    --hp-color: #ef4444;
    --hp-bg: rgba(69, 10, 10, 0.7);
    --mp-color: #3b82f6;
    --mp-bg: rgba(23, 37, 84, 0.7);
    --xp-color: #fbbf24;
    --xp-bg: rgba(69, 26, 3, 0.7);
    --stamina-color: #eab308;

    /* Effects */
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255,255,255,0.02);
    --shadow-glow: 0 0 24px rgba(167, 139, 250, 0.25), 0 0 60px rgba(167, 139, 250, 0.08);
    --shadow-gold: 0 0 20px rgba(246, 201, 78, 0.2), 0 0 50px rgba(246, 201, 78, 0.06);
    --glass-blur: blur(16px);

    /* Typography */
    --font-main: 'Inter', 'Segoe UI', system-ui, sans-serif;
    --font-title: 'Noto Serif SC', 'Georgia', serif;

    /* Sizing */
    --tile-size: 32px;
    --hud-padding: 10px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    font-family: var(--font-main);
    color: var(--text-primary);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.hidden {
    display: none !important;
}

/* ===================================
   LOADING SCREEN - Ink Wash Style
   =================================== */
#loading-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(120% 120% at 50% 35%, rgba(4, 3, 10, 0.05), rgba(4, 3, 10, 0.22) 70%, rgba(3, 2, 8, 0.50)),
        url('../assets/loading-bg.jpg') center / cover no-repeat scroll;
    z-index: 9999;
    overflow: hidden;
}

#loading-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5 L35 25 L55 30 L35 35 L30 55 L25 35 L5 30 L25 25 Z' fill='rgba(167,139,250,0.015)' /%3E%3C/svg%3E");
    opacity: 0.6;
    animation: subtleDrift 60s linear infinite;
}

.loading-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    z-index: 2;
}

.loading-bar-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding-bottom: 24px;
}

#loading-bar-canvas {
    display: block;
}

.loading-text {
    color: #b8893f;
    font-family: var(--font-title);
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 1.5px;
    min-height: 1.2em;
    margin-top: 6px;
    text-align: center;
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 0.8),
        1px -1px 0 rgba(0, 0, 0, 0.8),
        -1px 1px 0 rgba(0, 0, 0, 0.8),
        1px 1px 0 rgba(0, 0, 0, 0.8);
}

.loading-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* ===================================
   MAIN MENU - Ink Wash Painting
   =================================== */
#main-menu {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    overflow-y: auto;
    scrollbar-width: none;
}
#main-menu::-webkit-scrollbar { display: none; }

.menu-bg {
    position: absolute;
    inset: 0;
    background: url('../assets/menu-bg.jpg') center / cover no-repeat scroll;
    background-color: #14142b;
    filter: brightness(1.3) saturate(1.05);
}

/* Soft dark vignette over the image so menu text stays readable */
.menu-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: radial-gradient(120% 120% at 50% 30%, rgba(8, 6, 18, 0.02), rgba(6, 4, 14, 0.08) 65%, rgba(4, 2, 10, 0.32));
}

.menu-bg canvas {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
}

.menu-layout {
    position: relative;
    z-index: 2;
    width: min(620px, calc(100% - 48px));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* margin-top: 24vh; đẩy menu xuống thêm ~1cm (≈38px) để vừa tầm nhìn */
    margin-top: calc(25vh + 22px);
    padding: 28px 0;
}

.menu-content {
    text-align: center;
    padding: 32px 20px;
}

.menu-buttons {
    margin-top: 53px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.menu-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 36px;
    min-width: 280px;
    background: var(--bg-panel);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font-main);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: var(--glass-blur);
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.menu-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(246, 201, 78, 0.05) 0%, transparent 50%, rgba(167, 139, 250, 0.05) 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.menu-btn:hover::before { opacity: 1; }

.menu-btn:hover {
    border-color: var(--accent-gold);
    transform: translateY(-2px);
    box-shadow: var(--shadow-gold);
}

.menu-btn:active {
    transform: translateY(0);
}

.menu-btn.primary {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.6), rgba(167, 139, 250, 0.4));
    border-color: var(--primary-light);
    font-weight: 700;
}

.menu-btn.primary:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.7), rgba(196, 181, 253, 0.4));
    box-shadow: var(--shadow-glow);
    border-color: var(--primary-light);
}

.btn-icon {
    font-size: 1.3rem;
}

.menu-btn.bg-img {
    background: none;
    border: 0;
    padding: 0;
    min-width: 0;
    backdrop-filter: none;
    overflow: visible;
    box-shadow: none;
}

/* Các nút menu sole nhau: tạo nhân vật + tiếp tục đồng vị trí (phải),
   rồi từ trên xuống: phải, trái, phải, trái..., khoảng dịch nhỏ. */
.menu-buttons > .menu-btn:nth-child(1) img { transform: translateX(32px); }
.menu-buttons > .menu-btn:nth-child(2) img { transform: translateX(32px); }
.menu-buttons > .menu-btn:nth-child(3) img { transform: translateX(-32px); }
.menu-buttons > .menu-btn:nth-child(4) img { transform: translateX(32px); }
.menu-buttons > .menu-btn:nth-child(5) img { transform: translateX(-32px); }

.menu-btn.bg-img::before { display: none; }

.menu-btn.bg-img img {
    width: min(340px, 80vw);
    height: auto;
    display: block;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), filter 0.25s;
}

.menu-btn.bg-img:hover {
    border-color: transparent;
    transform: scale(1.04);
    box-shadow: none;
}

.menu-btn.bg-img:hover img {
    filter: brightness(1.12);
}

.menu-btn.bg-img:active {
    transform: scale(0.97);
}

.menu-version {
    margin-top: 40px;
    color: var(--text-dim);
    font-size: 0.72rem;
    letter-spacing: 2px;
}

.menu-onboarding {
    position: relative;
    overflow: hidden;
    text-align: left;
    padding: 26px;
    border: 1px solid rgba(246, 201, 78, 0.38);
    border-radius: 18px 6px 18px 6px;
    background:
        linear-gradient(145deg, rgba(33, 24, 15, 0.94), rgba(10, 14, 24, 0.94)),
        repeating-linear-gradient(0deg, transparent 0 27px, rgba(246, 201, 78, 0.035) 28px);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48), inset 0 0 0 1px rgba(255, 255, 255, 0.025);
    backdrop-filter: blur(18px);
    animation: menuGuideReveal 0.7s 0.15s both cubic-bezier(0.2, 0.8, 0.2, 1);
}

.menu-onboarding::after {
    content: '蠱';
    position: absolute;
    right: -18px;
    top: -44px;
    color: rgba(246, 201, 78, 0.055);
    font-family: var(--font-title);
    font-size: 12rem;
    line-height: 1;
    pointer-events: none;
}

.onboarding-eyebrow {
    color: #f6c94e;
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.28em;
}

.menu-onboarding h2 {
    margin: 6px 0 5px;
    color: #fff7d6;
    font-family: var(--font-title);
    font-size: clamp(1.5rem, 2.5vw, 2.15rem);
    letter-spacing: 0.04em;
}

.onboarding-lead {
    margin: 0 0 18px;
    color: #a9b2c2;
    font-size: 0.78rem;
    line-height: 1.55;
}

.onboarding-steps {
    display: grid;
    gap: 7px;
}

.onboarding-step {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 30px 1fr auto;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 7px 9px;
    border-left: 2px solid rgba(246, 201, 78, 0.46);
    background: linear-gradient(90deg, rgba(246, 201, 78, 0.075), rgba(255, 255, 255, 0.018));
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.onboarding-step:hover {
    transform: translateX(4px);
    border-color: #f6c94e;
    background: linear-gradient(90deg, rgba(246, 201, 78, 0.14), rgba(255, 255, 255, 0.03));
}

.onboarding-step > b {
    color: rgba(246, 201, 78, 0.52);
    font-family: var(--font-title);
    font-size: 1rem;
}

.onboarding-step span {
    color: #9ba6b7;
    font-size: 0.68rem;
    line-height: 1.35;
}

.onboarding-step strong {
    display: block;
    margin-bottom: 1px;
    color: #f1f5f9;
    font-size: 0.76rem;
}

.onboarding-step kbd {
    min-width: 34px;
    padding: 4px 6px;
    border: 1px solid rgba(246, 201, 78, 0.36);
    border-bottom-width: 3px;
    border-radius: 5px;
    background: #151820;
    color: #f6c94e;
    font: 700 0.58rem var(--font-main);
    text-align: center;
    white-space: nowrap;
}

.onboarding-step.danger {
    border-color: rgba(239, 68, 68, 0.62);
    background: linear-gradient(90deg, rgba(127, 29, 29, 0.18), rgba(255, 255, 255, 0.018));
}

.onboarding-more {
    position: relative;
    z-index: 1;
    width: 100%;
    margin-top: 14px;
    padding: 9px 12px;
    border: 0;
    border-top: 1px solid rgba(246, 201, 78, 0.25);
    background: transparent;
    color: #f6c94e;
    font: 700 0.72rem var(--font-main);
    letter-spacing: 0.04em;
    cursor: pointer;
}

@keyframes menuGuideReveal {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 900px) {
    #main-menu { align-items: flex-start; }
    .menu-layout {
        width: min(620px, calc(100% - 24px));
        gap: 4px;
        margin-top: 10vh;
        padding: 18px 0 28px;
    }
    .menu-content { padding: 14px 12px; }
    .menu-buttons { margin-top: 27px; }
    .menu-version { margin-top: 18px; }
}

@media (max-width: 520px) {
    .menu-btn { min-width: min(280px, 100%); }
}

/* ===================================
   CHARACTER CREATION
   =================================== */
#char-creation {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background:
        radial-gradient(ellipse 70% 50% at 50% 50%, rgba(124, 58, 237, 0.06) 0%, transparent 70%),
        linear-gradient(135deg, #06060f 0%, #0d0820 50%, #06060f 100%);
    z-index: 100;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 20px;
}

.creation-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-xl);
    padding: 32px;
    max-width: 900px;
    width: 100%;
    backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-lg);
    position: relative;
    margin: auto 0;
    touch-action: pan-y;
}

#char-creation input,
#char-creation select,
#char-creation button {
    touch-action: manipulation;
}

#char-creation input {
    user-select: text;
    -webkit-user-select: text;
}

/* Corner ornaments */
.creation-panel::before,
.creation-panel::after {
    content: '❖';
    position: absolute;
    font-size: 0.7rem;
    color: var(--accent-gold);
    opacity: 0.4;
}
.creation-panel::before { top: 10px; left: 14px; }
.creation-panel::after { bottom: 10px; right: 14px; }

.creation-panel h2 {
    text-align: center;
    font-family: var(--font-title);
    font-size: 1.8rem;
    background: linear-gradient(135deg, var(--accent-gold), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 24px;
    letter-spacing: 2px;
}

.creation-name {
    margin-bottom: 24px;
}

.creation-name label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.creation-name input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font-main);
    outline: none;
    transition: all 0.3s;
}

.creation-name input:focus {
    border-color: var(--accent-gold);
    box-shadow: 0 0 16px rgba(246, 201, 78, 0.15);
}

.creation-name input::placeholder {
    color: var(--text-secondary);
    opacity: 0.4;
}

.creation-name input:invalid:not(:placeholder-shown) {
    border-color: #ef4444;
    box-shadow: 0 0 14px rgba(239, 68, 68, 0.18);
}

.creation-name-hint {
    min-height: 18px;
    margin-top: 7px;
    color: #94a3b8;
    font-size: 0.75rem;
}

.creation-name-hint.error {
    color: #f87171;
}

.creation-faction h3 {
    color: var(--text-accent);
    margin-bottom: 16px;
    font-size: 1.05rem;
}

.faction-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.faction-card {
    background: rgba(0, 0, 0, 0.35);
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 18px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.faction-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 0%, rgba(246, 201, 78, 0.08) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.3s;
}

.faction-card:hover::before { opacity: 1; }

.faction-card:hover {
    border-color: var(--border-gold);
    background: rgba(246, 201, 78, 0.04);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.faction-card.selected {
    border-color: var(--accent-gold);
    background: rgba(246, 201, 78, 0.06);
    box-shadow: var(--shadow-gold);
}

.faction-card[data-faction="luc"].selected { border-color: var(--luc-color); box-shadow: 0 0 24px rgba(239, 68, 68, 0.15); }
.faction-card[data-faction="hoa"].selected { border-color: var(--hoa-color); box-shadow: 0 0 24px rgba(249, 115, 22, 0.15); }
.faction-card[data-faction="thuy"].selected { border-color: var(--thuy-color); box-shadow: 0 0 24px rgba(59, 130, 246, 0.15); }
.faction-card[data-faction="tho"].selected { border-color: var(--tho-color); box-shadow: 0 0 24px rgba(196, 154, 60, 0.15); }
.faction-card[data-faction="moc"].selected { border-color: var(--moc-color); box-shadow: 0 0 24px rgba(34, 197, 94, 0.15); }

.faction-icon {
    font-size: 2.4rem;
    margin-bottom: 8px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.faction-name {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.faction-element {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 8px;
}

.faction-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.creation-preview {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

#preview-canvas {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-lg);
    box-shadow: inset 0 0 30px rgba(0,0,0,0.3);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.creation-stats {
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 24px;
    border: 1px solid var(--border-subtle);
}

.creation-stats h3 {
    color: var(--text-accent);
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.creation-start-location {
    margin-bottom: 24px;
}

.creation-start-location > h3 {
    color: var(--text-accent);
    margin-bottom: 4px;
    font-size: 0.95rem;
}

.creation-start-location-hint {
    color: #94a3b8;
    font-size: 0.72rem;
    margin-bottom: 12px;
}

.start-location-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.start-location-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
    padding: 12px;
    text-align: left;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.38);
    border: 1px solid var(--border-subtle);
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.start-location-card:hover {
    transform: translateY(-2px);
    border-color: var(--loc-color, var(--accent-gold));
}

.start-location-card.selected {
    border: 1px solid var(--loc-color, var(--accent-gold));
    background: color-mix(in srgb, var(--loc-color, var(--accent-gold)) 12%, rgba(0, 0, 0, 0.5));
    box-shadow: 0 0 14px color-mix(in srgb, var(--loc-color, var(--accent-gold)) 35%, transparent);
}

.start-location-card.unavailable {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.6);
}

.start-location-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--loc-color, var(--accent-gold));
    box-shadow: 0 0 8px var(--loc-color, var(--accent-gold));
}

.start-location-name {
    font-weight: 800;
    font-size: 0.95rem;
    background: linear-gradient(135deg, #fff, color-mix(in srgb, var(--loc-color, var(--accent-gold)) 80%, #fff));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.start-location-map {
    color: #94a3b8;
    font-size: 0.7rem;
    line-height: 1.35;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    font-size: 0.88rem;
}

.stat-row span:last-child {
    color: var(--text-gold);
    font-weight: 700;
    text-shadow: 0 0 8px rgba(246, 201, 78, 0.2);
}

.creation-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.character-customizer {
    display: grid;
    grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1.15fr);
    gap: 24px;
    align-items: start;
}

.character-customizer .creation-preview {
    position: sticky;
    top: 12px;
    margin: 0;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.preview-note {
    max-width: 280px;
    color: #94a3b8;
    font-size: 0.72rem;
    line-height: 1.5;
    text-align: center;
}

.appearance-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 18px;
    border: 1px solid rgba(246, 201, 78, 0.18);
    border-radius: var(--radius-lg);
    background: linear-gradient(145deg, rgba(15,23,42,0.78), rgba(32,15,45,0.62));
}

.appearance-controls > h3,
.appearance-controls .creation-stats,
.appearance-controls .randomize-appearance {
    grid-column: 1 / -1;
}

.appearance-controls > h3 { color: var(--text-accent); font-size: 1.05rem; margin-bottom: 2px; }
.appearance-controls label { display: grid; gap: 6px; color: #cbd5e1; font-size: 0.74rem; }
.appearance-controls select,
.appearance-controls input[type="color"] {
    width: 100%;
    min-height: 39px;
    padding: 7px 10px;
    color: #f8fafc;
    border: 1px solid rgba(148,163,184,0.28);
    border-radius: 8px;
    outline: none;
    background: rgba(2,6,23,0.72);
}
.appearance-controls input[type="color"] { padding: 4px; cursor: pointer; }
.appearance-controls select:focus,
.appearance-controls input:focus { border-color: var(--accent-gold); box-shadow: 0 0 12px rgba(246,201,78,0.12); }
.randomize-appearance {
    min-height: 40px;
    color: #fef3c7;
    border: 1px solid rgba(251,191,36,0.45);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(120,53,15,0.82), rgba(124,58,237,0.55));
    cursor: pointer;
}
.appearance-controls .creation-stats { margin: 2px 0 0; }
.appearance-controls .creation-stats small { display: block; margin-top: 8px; color: #94a3b8; font-size: 0.66rem; line-height: 1.4; }

@media (max-width: 760px) {
    #char-creation { padding: 12px 10px 28px; }
    .creation-panel { padding: 22px 14px; margin: 0; }
    .character-customizer { grid-template-columns: 1fr; }
    .character-customizer .creation-preview { position: static; }
    #preview-canvas { width: 220px; height: 300px; }
}

@media (max-width: 460px) {
    .appearance-controls { grid-template-columns: 1fr; padding: 13px; }
    .appearance-controls > h3,
    .appearance-controls .creation-stats,
    .appearance-controls .randomize-appearance { grid-column: 1; }
}

/* ===================================
   GAME CANVAS
   =================================== */
#game-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    z-index: 1;
}

/* ===================================
   GAME HUD - Premium Xianxia Style
   =================================== */
#game-ui {
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

#game-ui > * {
    pointer-events: auto;
}

/* Top HUD Bar */
.hud-top {
    position: fixed;
    top: 12px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    z-index: 2000;
    pointer-events: none;
}

.hud-player-info {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    background: url('../assets/character-stats-panel.png') no-repeat center / 100% 100%;
    background-origin: border-box;
    border: none;
    border-radius: 10px;
    padding: 42px 22px;
    width: 518px;
    min-width: 468px;
    box-sizing: border-box;
    position: relative;
    left: -0.5cm;
    top: -0.5cm;
}

.hud-avatar {
    width: 100px;
    height: 100px;
    margin-left: 1cm;
    position: relative;
    top: -14px;
    left: 2px;
    border-radius: 50%;
    background: rgba(10, 6, 24, 0.45);
    border: 2px solid #e0b95e;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.85), 0 0 10px rgba(246, 201, 78, 0.35);
    overflow: hidden;
}

.hud-avatar canvas,
.dialog-portrait canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.hud-bars {
    flex: 1;
    min-width: 0;
}

.hud-name {
    font-weight: 800;
    font-size: 0.85rem;
    color: #f8fafc;
    margin-left: 4px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 0.85),
        1px -1px 0 rgba(0, 0, 0, 0.85),
        -1px 1px 0 rgba(0, 0, 0, 0.85),
        1px 1px 0 rgba(0, 0, 0, 0.85);
}

.hud-cultivation {
    font-size: 0.65rem;
    color: var(--text-gold);
    margin-left: 4px;
    text-align: center;
    margin-bottom: 2px;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.75);
}

.hud-luck,
.hud-map-name,
#hud-gold-text,
.bar-text {
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
}

.bar-container {
    width: calc(83.33% + 3px);
    height: 14px;
    margin-left: 13px;
    padding: 0 6px;
    background: var(--hp-bg);
    border-radius: 8px;
    margin-bottom: 2px;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(246, 201, 78, 0.5);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.45), 0 0 1px rgba(0,0,0,0.6);
}

.bar-container.mp-bar { background: var(--mp-bg); }
.bar-container.stamina-bar { background: rgba(139, 90, 43, 0.18); border-color: rgba(205, 127, 50, 0.35); }
.bar-container.xp-bar { background: var(--xp-bg); }

.bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

/* Faint ancient cloud watermark inside all colored bars */
.bar-fill::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='36'%3E%3Cg fill='rgba(255,255,255,0.18)'%3E%3Ccircle cx='18' cy='20' r='9'/%3E%3Ccircle cx='30' cy='13' r='11'/%3E%3Ccircle cx='44' cy='20' r='9'/%3E%3Crect x='16' y='20' width='30' height='9' rx='4.5'/%3E%3Ccircle cx='86' cy='18' r='7'/%3E%3Ccircle cx='97' cy='12' r='9'/%3E%3Ccircle cx='108' cy='18' r='7'/%3E%3Crect x='84' y='18' width='26' height='7' rx='3.5'/%3E%3C/g%3E%3C/svg%3E") repeat;
    background-size: 120px 40px;
    opacity: 0.4;
    pointer-events: none;
}

/* Shimmer effect on all bars */
.bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.15) 50%, transparent 100%);
    animation: barShimmer 3s ease-in-out infinite;
}

.hp-bar .bar-fill {
    background: linear-gradient(90deg, #7f1d1d, #dc2626, #ef4444);
    width: 100%;
    box-shadow: 0 0 10px rgba(248, 113, 113, 0.5), inset 0 0 8px rgba(255, 255, 255, 0.15);
}

.mp-bar .bar-fill {
    background: linear-gradient(90deg, #1e3a8a, #0ea5e9, #22d3ee);
    width: 100%;
    box-shadow: 0 0 10px rgba(34, 211, 238, 0.45), inset 0 0 8px rgba(255, 255, 255, 0.15);
}

.stamina-bar .bar-fill {
    background: linear-gradient(90deg, #5a3a1a, #8b5a2b 30%, #c9883f 55%, #e0a05a 72%, #a06a2e 100%);
    width: 100%;
    box-shadow: 0 0 8px rgba(205, 127, 50, 0.4), inset 0 0 8px rgba(255, 230, 180, 0.25);
}

.xp-bar .bar-fill {
    background-image:
        radial-gradient(circle 6px at calc(100% - 4px) 50%, #fffbe6 0%, #fcd34d 25%, #f59e0b 50%, rgba(245, 158, 11, 0) 78%),
        linear-gradient(90deg, #7c2d12, #b45309 40%, #f59e0b 70%, #fbbf24);
    width: 0%;
    box-shadow: 0 0 14px rgba(251, 191, 36, 0.85), 0 0 30px rgba(245, 158, 11, 0.45), inset 0 0 10px rgba(255, 255, 255, 0.25);
}

.xp-bar .bar-text {
    color: #fff7cc;
    font-weight: 900;
    -webkit-text-stroke: 0.8px #7c2d12;
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 0.95),
        1px -1px 0 rgba(0, 0, 0, 0.95),
        -1px 1px 0 rgba(0, 0, 0, 0.95),
        1px 1px 0 rgba(0, 0, 0, 0.95);
}

.bar-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    font-size: 0.6rem;
    font-weight: 800;
    color: #fde68a;
    letter-spacing: 0.3px;
    font-weight: 900;
    -webkit-text-stroke: 0.8px #000;
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 0.95),
        1px -1px 0 rgba(0, 0, 0, 0.95),
        -1px 1px 0 rgba(0, 0, 0, 0.95),
        1px 1px 0 rgba(0, 0, 0, 0.95);
    pointer-events: none;
}

.hud-map-name {
    background: var(--bg-glass);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-sm);
    padding: 3px 10px;
    font-size: 0.68rem;
    color: var(--text-gold);
    backdrop-filter: var(--glass-blur);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(320px, 36vw);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.hud-top-buttons {
    position: fixed;
    top: 190px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: var(--bg-glass);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-md);
    padding: 5px;
    backdrop-filter: var(--glass-blur);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    max-height: calc(100dvh - 210px);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
}

.hud-btn {
    width: 38px;
    height: 38px;
    border: 1px solid rgba(246, 201, 78, 0.12);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.35);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.hud-btn:hover {
    background: rgba(246, 201, 78, 0.12);
    border-color: var(--accent-gold);
    transform: scale(1.12);
    box-shadow: 0 0 12px rgba(246, 201, 78, 0.15);
}

.hud-btn:active {
    transform: scale(0.95);
}

.immortal-aperture-btn {
    position: relative;
    background: radial-gradient(circle at 35% 25%, rgba(103, 232, 249, 0.5), rgba(8, 47, 73, 0.92)) !important;
    border-color: #67e8f9 !important;
    box-shadow: inset 0 0 12px rgba(34, 211, 238, 0.25), 0 0 12px rgba(34, 211, 238, 0.2);
}

.immortal-aperture-btn.daily-ready {
    animation: aperture-ready-pulse 1.7s ease-in-out infinite;
}

.aperture-ready-mark {
    position: absolute;
    top: -6px;
    right: -5px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #fbbf24;
    color: #422006;
    font: 900 12px/17px Georgia, serif;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.9);
}

@keyframes aperture-ready-pulse {
    0%, 100% { transform: translateY(0); box-shadow: 0 0 10px rgba(34, 211, 238, 0.28); }
    50% { transform: translateY(-2px); box-shadow: 0 0 22px rgba(103, 232, 249, 0.75); }
}

/* Minimap */
.hud-minimap {
    position: fixed !important;
    top: 12px !important;
    right: 16px !important;
    background: var(--bg-glass);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-md);
    padding: 4px;
    backdrop-filter: var(--glass-blur);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 2000;
    cursor: pointer;
}

.hud-minimap:hover {
    border-color: var(--accent-gold);
    box-shadow: 0 0 22px rgba(246, 201, 78, 0.28);
}

.world-map-panel {
    width: min(1120px, calc(100vw - 28px));
    max-width: 1120px;
    height: min(820px, calc(100vh - 28px));
}

.world-map-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(246, 201, 78, 0.2);
    background: linear-gradient(90deg, rgba(20, 32, 25, 0.9), rgba(43, 30, 18, 0.86));
    color: #d6c7a1;
    font-size: 0.76rem;
}

#world-map-search {
    flex: 1;
    min-width: 180px;
    padding: 9px 12px;
    color: #f8fafc;
    background: rgba(3, 10, 8, 0.72);
    border: 1px solid rgba(246, 201, 78, 0.32);
    border-radius: 8px;
    outline: none;
}

#world-map-search:focus { border-color: #f6c94e; }

.world-map-waypoint-info {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.world-map-waypoint-chip {
    color: #a7f3d0;
    background: rgba(6, 78, 59, 0.55);
    border: 1px solid rgba(74, 222, 128, 0.5);
    border-radius: 8px;
    padding: 4px 9px;
}
.world-map-waypoint-chip b { color: #d1fae5; }
.world-map-clear-btn {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(248, 113, 113, 0.6);
    color: #fecaca;
    padding: 4px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
}
.world-map-clear-btn:hover { background: rgba(239, 68, 68, 0.4); }
.world-map-waypoint-hint { color: #94a3b8; font-style: italic; }

.world-map-body {
    background:
        radial-gradient(circle at 20% 15%, rgba(44, 95, 61, 0.16), transparent 34%),
        radial-gradient(circle at 82% 72%, rgba(135, 86, 32, 0.15), transparent 38%),
        repeating-linear-gradient(0deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 22px),
        #090d0b;
}

.world-region {
    margin-bottom: 18px;
    padding: 12px;
    border: 1px solid color-mix(in srgb, var(--region-color) 42%, transparent);
    border-radius: 12px;
    background: color-mix(in srgb, var(--region-color) 7%, rgba(7, 12, 10, 0.88));
}

.world-region > header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    color: var(--region-color);
    font: 800 0.95rem Georgia, serif;
    letter-spacing: 0.08em;
}

.world-region > header small { color: #94a3b8; font: 500 0.7rem sans-serif; }

.world-map-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 9px;
}

.world-map-node {
    min-height: 130px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    color: #e7e5e4;
    background: linear-gradient(145deg, rgba(25, 31, 27, 0.96), rgba(12, 18, 15, 0.96));
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 9px;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.world-map-node:hover { transform: translateY(-2px); border-color: var(--accent-gold); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }
.world-map-node.current { border-color: #4ade80; background: linear-gradient(145deg, rgba(21, 72, 45, 0.85), rgba(10, 35, 23, 0.94)); cursor: default; }
.world-map-node.quest-target { box-shadow: inset 0 0 0 1px rgba(251,191,36,0.55); }
.world-map-node.waypoint-target { border-color: #4ade80; box-shadow: inset 0 0 0 2px rgba(74, 222, 128, 0.9), 0 0 14px rgba(74, 222, 128, 0.45); }
.world-map-node-title { color: #f8fafc; font-weight: 800; line-height: 1.2; }
.world-map-node-meta { color: #94a3b8; font-size: 0.68rem; margin-top: 5px; }
.world-map-node-quest { color: #fbbf24; font-size: 0.7rem; font-weight: 700; margin-top: 7px; }
.world-map-node-monsters { color: #cbd5e1; font-size: 0.65rem; line-height: 1.3; margin-top: 6px; opacity: 0.82; }
.world-map-node-action { margin-top: auto; padding-top: 8px; color: var(--region-color); font-size: 0.68rem; font-weight: 800; text-transform: uppercase; }
.quest-guide { margin-top: 5px; padding: 4px 6px; border-left: 2px solid #fbbf24; background: rgba(251,191,36,0.08); color: #fde68a; font-size: 0.68rem; }

@media (max-width: 700px) {
    .world-map-panel { width: calc(100vw - 10px); height: calc(100vh - 10px); }
    .world-map-toolbar { align-items: stretch; flex-direction: column; gap: 6px; }
    .world-map-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .world-map-node { min-height: 118px; }
}

/* Compass corner dots */
.hud-minimap::before {
    content: '◈';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.5rem;
    color: var(--accent-gold);
    opacity: 0.5;
    z-index: 2;
}

#minimap-canvas {
    border-radius: var(--radius-sm);
    display: block;
}

/* Skill Bar - Premium */
.hud-skills {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    background: url('../assets/panelhotkey.png') no-repeat center / 100% 100%;
    background-color: transparent;
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.35);
    image-rendering: auto;
}

/* Thu gọn các nút phím hotkey (B, K, P, V...): chỉ giữ lại nút Menu ☰ */
.hud-top-buttons.collapsed .hud-btn:not(#btn-menu-ig) {
    display: none;
}

.skill-slot {
    width: 50px;
    height: 50px;
    background: url('../assets/hotkey-slot.png') no-repeat center / 100% 100%;
    background-color: transparent;
    border: none;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* Inner light overlay */
.skill-slot::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    background: radial-gradient(circle at 50% 30%, rgba(255,255,255,0.06) 0%, transparent 60%);
    pointer-events: none;
}

.skill-slot:hover {
    background: url('../assets/hotkey-slot.png') no-repeat center / 100% 100%;
    filter: brightness(1.18);
    transform: translateY(-4px) scale(1.08);
    box-shadow: 0 4px 16px rgba(246, 201, 78, 0.2), 0 0 20px rgba(246, 201, 78, 0.1);
}

.skill-slot.mobile-selected {
    border-color: #38bdf8;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.28), 0 0 18px rgba(56, 189, 248, 0.45);
}

/* Basic Attack (Space) slot: distinct but integrated with the hotbar */
.skill-attack-slot {
    width: 58px;
    height: 58px;
    border: none;
    background: url('../assets/hotkey-slot.png') no-repeat center / 100% 100%;
    background-color: transparent;
    border-radius: 8px;
    margin-right: 4px;
    filter: brightness(1.06) saturate(1.1);
}

.skill-attack-slot::after {
    content: '';
    position: absolute;
    top: 3px;
    right: 3px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-gold);
    box-shadow: 0 0 8px rgba(246, 201, 78, 0.9);
}

.skill-attack-slot .skill-key {
    top: 4px;
    left: 8px;
    color: #d4af37;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.skill-attack-slot .skill-icon {
    font-size: 1.55rem;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.7));
}

.skill-attack-slot:hover {
    background: url('../assets/hotkey-slot.png') no-repeat center / 100% 100%;
    filter: brightness(1.22) saturate(1.12);
    box-shadow: 0 4px 18px rgba(246, 201, 78, 0.3), 0 0 24px rgba(246, 201, 78, 0.18);
}

.skill-key {
    position: absolute;
    top: 2px;
    left: 6px;
    font-size: 0.58rem;
    color: #d4af37;
    font-weight: 700;
}

.skill-icon {
    font-size: 1.35rem;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

.gu-visual-icon {
    display: inline-block;
    flex: 0 0 auto;
    vertical-align: middle;
    background-repeat: no-repeat;
    image-rendering: auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.65));
}

.gu-image-icon,
.gu-common-image-icon,
.gu-immortal-image-icon {
    border-radius: 6px;
    background-color: rgba(15, 23, 42, 0.72);
    box-shadow: inset 0 0 0 1px rgba(248, 250, 252, 0.12);
}

.skill-cooldown {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    display: none;
}

/* ===================================
   MOBILE CONTROLS
   =================================== */
.mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    display: none;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
}

.mobile-controls > * {
    pointer-events: auto;
}

.joystick-container {
    position: relative;
    width: 130px;
    height: 130px;
}

.joystick-base {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.04);
    border: 2px solid rgba(246, 201, 78, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.3);
}

.joystick-stick {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(246, 201, 78, 0.35), rgba(167, 139, 250, 0.2));
    border: 2px solid rgba(246, 201, 78, 0.3);
    position: absolute;
    transition: none;
    box-shadow: 0 0 12px rgba(246, 201, 78, 0.15);
}

.mobile-action-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.action-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid rgba(246, 201, 78, 0.2);
    background: rgba(0, 0, 0, 0.45);
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.15s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.action-btn:active {
    transform: scale(0.9);
    background: rgba(246, 201, 78, 0.2);
}

.attack-btn { border-color: rgba(239, 68, 68, 0.4); }
.dodge-btn { border-color: rgba(6, 182, 212, 0.4); }
.skill-btn { border-color: rgba(167, 139, 250, 0.4); }
.beast-btn { border-color: rgba(34, 197, 94, 0.4); }

/* ===================================
   DIALOG BOX
   =================================== */
.dialog-box {
    position: fixed;
    bottom: 85px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    background: var(--bg-panel);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    gap: 12px;
    backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-lg);
    animation: dialogSlideUp 0.3s ease-out;
    z-index: 16;
}

.dialog-portrait {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.15), rgba(124, 58, 237, 0.2));
    border: 2px solid var(--accent-gold);
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 0 18px rgba(246, 201, 78, 0.18);
}

.dialog-content {
    flex: 1;
}

.dialog-name {
    font-weight: 700;
    color: var(--text-gold);
    margin-bottom: 6px;
    font-size: 0.9rem;
    text-shadow: 0 0 8px rgba(246, 201, 78, 0.2);
}

.dialog-text {
    color: var(--text-primary);
    font-size: 0.84rem;
    line-height: 1.55;
    white-space: pre-line;
}

.dialog-options {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 42vh;
    overflow-y: auto;
    padding-right: 4px;
}

.dialog-option {
    padding: 8px 12px;
    background: rgba(246, 201, 78, 0.04);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.82rem;
    transition: all 0.2s;
}

.dialog-option:hover {
    background: rgba(246, 201, 78, 0.1);
    border-color: var(--accent-gold);
    transform: translateX(4px);
}

.dialog-next {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-gold);
    background: rgba(246, 201, 78, 0.1);
    color: var(--text-gold);
    cursor: pointer;
    align-self: flex-end;
    transition: all 0.2s;
    font-size: 1rem;
}

.dialog-next:hover {
    background: rgba(246, 201, 78, 0.25);
    box-shadow: 0 0 10px rgba(246, 201, 78, 0.2);
}

/* ===================================
   MODAL OVERLAY (Path / Gu Refine / Cultivation)
   =================================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
    animation: overlayFadeIn 0.2s ease-out;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: overlayFadeIn 0.2s ease-out;
}

.window-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-xl);
    backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-lg);
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: panelFadeIn 0.25s ease-out;
    position: relative;
}

.window-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(246, 201, 78, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

.window-header h3 {
    font-family: var(--font-title);
    font-size: 1.05rem;
    color: var(--text-gold);
    letter-spacing: 1px;
    text-shadow: 0 0 10px rgba(246, 201, 78, 0.15);
}

.close-btn {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
}

.window-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

/* Path Items */
.path-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.path-item:hover {
    border-color: var(--border-gold);
    background: rgba(246, 201, 78, 0.03);
}

.path-icon { font-size: 1.2rem; }
.path-name { font-weight: 600; font-size: 0.85rem; min-width: 60px; }
.path-bar { flex: 1; height: 8px; background: rgba(255,255,255,0.06); border-radius: 4px; overflow: hidden; }
.path-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent-gold)); border-radius: 4px; transition: width 0.3s; }
.path-points { font-size: 0.75rem; color: var(--text-gold); font-weight: 600; min-width: 40px; text-align: right; }

.btn-add-path-point {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-gold);
    border-radius: 4px;
    background: rgba(246, 201, 78, 0.1);
    color: var(--text-gold);
    font-weight: 700;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.btn-add-path-point:hover {
    background: rgba(246, 201, 78, 0.25);
}

/* ===================================
   NOTIFICATIONS
   =================================== */
.notification-area {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    z-index: 3000;
    max-width: min(320px, calc(100vw - 24px));
}

.notification {
    padding: 7px 11px;
    background: var(--bg-panel);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.74rem;
    backdrop-filter: var(--glass-blur);
    animation: notifySlideDown 0.3s ease-out;
    white-space: normal;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    max-width: 100%;
}

.notification.success { border-color: var(--moc-color); box-shadow: 0 0 12px rgba(34, 197, 94, 0.15); }
.notification.error { border-color: var(--luc-color); box-shadow: 0 0 12px rgba(239, 68, 68, 0.15); }
.notification.warning { border-color: var(--text-gold); box-shadow: 0 0 12px rgba(246, 201, 78, 0.15); }

/* ===================================
   RESPONSIVE
   =================================== */
@media (max-width: 768px) {
    .hud-top {
        top: calc(6px + env(safe-area-inset-top));
        left: calc(6px + env(safe-area-inset-left));
        right: 108px;
        gap: 5px;
        align-items: flex-start;
    }

    .hud-map-name {
        display: block;
        max-width: 46vw;
        padding: 4px 8px;
        overflow: hidden;
        font-size: 0.68rem;
        letter-spacing: 0.35px;
        text-overflow: ellipsis;
    }

    .hud-gold {
        min-height: 26px;
        padding: 3px 7px !important;
        font-size: 0.68rem !important;
        white-space: nowrap;
    }

    .hud-minimap {
        display: block;
        top: calc(6px + env(safe-area-inset-top)) !important;
        right: calc(6px + env(safe-area-inset-right)) !important;
        padding: 3px;
    }

    #minimap-canvas {
        width: 92px;
        height: 92px;
    }

    .skill-key { display: block; }

    .hud-skills {
        right: calc(6px + env(safe-area-inset-right));
        bottom: calc(132px + env(safe-area-inset-bottom));
        left: calc(6px + env(safe-area-inset-left));
        transform: none;
        display: flex;
        max-width: none;
        gap: 5px;
        padding: 5px 7px;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        touch-action: pan-x;
        scrollbar-width: none;
    }

    .hud-skills::-webkit-scrollbar,
    .hud-top-buttons::-webkit-scrollbar { display: none; }

    .skill-slot {
        width: 42px;
        height: 42px;
        flex: 0 0 42px;
    }

    .skill-icon { font-size: 1.15rem; }
    .mobile-controls { display: flex; }

    .hud-player-info {
        width: 100%;
        min-width: 0;
        padding: 8px 15px;
        gap: 10px;
    }

    .hud-avatar {
        width: 48px;
        height: 48px;
        margin-left: 0.5cm;
    }

    .hud-top-buttons {
        position: fixed;
        top: calc(150px + env(safe-area-inset-top));
        right: calc(6px + env(safe-area-inset-right));
        left: auto;
        padding: 3px;
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
        scrollbar-width: none;
        max-height: calc(100dvh - 200px - env(safe-area-inset-bottom));
    }

    .hud-btn {
        width: 36px;
        height: 36px;
        flex: 0 0 36px;
        font-size: 0.9rem;
    }

    .mobile-controls {
        padding: 10px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
    }

    .joystick-container { width: 112px; height: 112px; }
    .joystick-base { width: 108px; height: 108px; }
    .mobile-action-buttons { grid-template-columns: repeat(3, 52px); gap: 7px; }
    .action-btn { width: 52px; height: 52px; }

    #admin-panel .admin-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        touch-action: pan-x;
    }

    #admin-panel .admin-tab { flex: 0 0 auto; }
    #admin-panel .panel-body { max-height: calc(100dvh - 122px) !important; }

    .faction-list {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
}

@media (max-width: 480px) {
    .hud-player-info {
        padding: 8px 12px;
    }

    .hud-avatar {
        width: 40px;
        height: 40px;
    }

    .hud-name { font-size: 0.94rem; }
    .hud-cultivation { font-size: 0.7rem; }
    .bar-container { height: 11px; margin-bottom: 3px; }
    .bar-text { font-size: 0.62rem; padding: 0 6px; }
}

/* Touch device detection */
@media (hover: none) and (pointer: coarse) {
    .mobile-controls { display: flex; }
    .hud-skills { display: flex; }
    .hud-minimap { display: block; }
}

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .hud-top {
        right: auto;
        width: 180px;
    }

    .hud-player-info { box-sizing: border-box; padding: 5px 12px; width: auto; min-width: 0; max-width: 215px; }
    .hud-avatar { width: 38px; height: 38px; }
    .hud-cultivation { margin-bottom: 1px; font-size: 0.68rem; }
    .bar-container { height: 9px; margin-bottom: 1px; }
    .bar-text { font-size: 0.6rem; }
    .hud-map-name { max-width: 90px; font-size: 0.6rem; padding: 2px 6px; }

    .hud-top-buttons {
        position: fixed;
        top: calc(160px + env(safe-area-inset-top));
        right: calc(6px + env(safe-area-inset-right));
        left: auto;
        padding: 3px;
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
        touch-action: pan-y;
        max-height: calc(100dvh - 190px - env(safe-area-inset-bottom));
    }

    .hud-btn { width: 34px; height: 34px; flex-basis: 34px; }

    .hud-minimap {
        top: calc(6px + env(safe-area-inset-top)) !important;
    }

    #minimap-canvas { width: 66px; height: 66px; }

    .hud-skills {
        top: calc(50px + env(safe-area-inset-top));
        right: calc(98px + env(safe-area-inset-right));
        bottom: auto;
        left: calc(202px + env(safe-area-inset-left));
        transform: none;
        gap: 5px;
        padding: 5px 7px;
        overflow-x: auto;
        overflow-y: hidden;
        touch-action: pan-x;
    }

    .skill-slot { width: 36px; height: 36px; flex-basis: 36px; }
    .mobile-controls { padding: 6px 8px calc(5px + env(safe-area-inset-bottom)); }
    .joystick-container { width: 92px; height: 92px; }
    .joystick-base { width: 88px; height: 88px; }
    .joystick-stick { width: 40px; height: 40px; }
    .mobile-action-buttons { grid-template-columns: repeat(3, 44px); gap: 5px; }
    .action-btn { width: 44px; height: 44px; font-size: 1rem; }

    #admin-panel {
        width: calc(100vw - 12px) !important;
        max-height: calc(100dvh - 12px);
    }
}

/* ===================================
   KEYFRAME ANIMATIONS (Shared)
   =================================== */
@keyframes shimmerGold {
    0% { background-position: 200% center; }
    100% { background-position: -200% center; }
}

@keyframes barShimmer {
    0% { left: -100%; }
    100% { left: 200%; }
}

@keyframes subtleDrift {
    0% { transform: translateX(0) translateY(0); }
    50% { transform: translateX(-30px) translateY(-15px); }
    100% { transform: translateX(0) translateY(0); }
}
