        * {
            box-sizing: border-box;
        }

        :root {
	--color1: #f54b73; /* Pink */
            --bg-color: #121212;
            --foreground-color: #1e1e1e;
            --sidebar-bg: #1e1e1e;
            --accent-color: #4f46e5;
            --mint: #61eb93;
            --text-color: #e5e5e5;
            --border-color: #333;
            --sidebar-width: 250px;
            --sidebar-collapsed-width: 70px;
            --current-sidebar-width: var(--sidebar-width);
        }

        body.sidebar-collapsed #sidebar {
            --current-sidebar-width: var(--sidebar-collapsed-width);
        }

        body, html {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
            background-color: var(--bg-color);
            color: var(--text-color);
            font-family: 'Zhcn', 'Montserrat', sans-serif;
        }

        #app {
            display: flex;
            width: 100vw;
            height: calc(100vh - 60px);
            margin-top: 60px;
        }

        #sidebar {
            width: var(--current-sidebar-width);
            background-color: var(--sidebar-bg);
            border-right: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            padding: 20px;
            z-index: 1000;
            transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
            overflow-x: hidden;
            position: relative;
        }

        body.sidebar-collapsed #sidebar {
            padding: 20px 10px;
        }

        .sidebar-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 2rem;
            min-height: 30px;
        }

        .icon-btn {
            background: transparent;
            border: none;
            color: #888;
            cursor: pointer;
            font-size: 1.2rem;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 5px;
            border-radius: 4px;
            transition: all 0.2s;
        }

        .icon-btn:hover {
            color: var(--text-color);
            background: rgba(255,255,255,0.05);
        }

        body.sidebar-collapsed #sidebar .sidebar-header {
            justify-content: center;
        }

        body.sidebar-collapsed #sidebar h1 {
            display: none;
        }

        body.sidebar-collapsed #sidebar #sidebar-toggle i {
            transform: rotate(180deg);
        }

        body.sidebar-collapsed #sidebar span,
        body.sidebar-collapsed #sidebar .instructions {
            display: none;
        }

        body.sidebar-collapsed #sidebar .btn {
            justify-content: center;
            padding: 12px 0;
            width: 50px;
            margin: 0 auto;
        }

        body.sidebar-collapsed #sidebar .btn i {
            margin: 0;
        }

        body.sidebar-collapsed #sidebar .tool-group {
            align-items: center;
        }

        body.sidebar-collapsed #sidebar #build-submenu {
            align-items: center;
        }

         #build-submenu {
            background-color: #13131387;
            padding-left: 16px;
            border-radius: 5px;
            padding: 8px;
        }

        /* Level Controls Responsive */
        .level-controls {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin: 15px 10px;
            color: #ccc;
            font-size: 14px;
            transition: all 0.3s ease;
        }

        .level-selector {
            display: flex;
            align-items: center;
            gap: 8px;
            transition: all 0.3s ease;
        }

        .level-selector i {
            cursor: pointer;
            font-size: 20px;
        }

        .cell-counter-container {
            font-size: 13px;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        body.sidebar-collapsed #sidebar .level-controls {
            flex-direction: column;
            gap: 15px;
            margin: 15px 0;
            align-items: center;
        }

        body.sidebar-collapsed #sidebar .level-selector {
            flex-direction: column-reverse; /* Up on top, Down on bottom */
            gap: 5px;
        }

        body.sidebar-collapsed #sidebar .level-selector i {
            font-size: 18px !important;
        }

        body.sidebar-collapsed #sidebar #level-counter,
        body.sidebar-collapsed #sidebar #cell-counter {
            display: inline-block !important; /* Override general span hiding */
            font-size: 14px;
        }

        body.sidebar-collapsed #sidebar .cell-counter-container {
            font-size: 11px;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 2px;
            border-top: 1px solid rgba(255,255,255,0.05);
            padding-top: 10px;
            width: 100%;
        }

        /* Mobile specific 'small menu icon only' look */
        @media (max-width: 768px) {

            /* Override inline height:100vh — dvh accounts for the mobile browser chrome
               (address bar, nav bar) so content is never clipped below the fold */
            #welcomePopupcontainer {
                height: 100dvh !important;
                min-height: 100dvh;
            }

            /* Inner wrapper also uses inline height:100vh — override it too */
            #welcomePopupcontainer > div {
                height: 100dvh !important;
                width: 100vw !important;
                position: relative;
            }

            /* Anchor the bottom panel to the actual bottom of the visible viewport
               so the CONTINUE button is always within thumb reach */
            #bottom-welcome {
                position: absolute !important;
                bottom: 0;
                left: 0;
                right: 0;
                z-index: 2;
                border-radius: 18px 18px 0 0;
                box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.7);
                margin-top: 0 !important;
            }

            /* Portrait: extend full height behind the bottom panel so the
               character's lower body is visible underneath the UI */
            #portrait {
                background-position: center top !important;
                background-size: cover !important;
                flex: none !important;
                height: 100dvh;
            }

            /* Override solid background with a gradient so the portrait
               image peeks through at the top of the bottom panel */
            #bottom-welcome {
                background: linear-gradient(
                    to bottom,
                    rgba(10, 0, 20, 0.649) 0%,
                    rgba(10, 0, 20, 0.923) 30%,
                    rgba(10, 0, 20, 0.97) 60%
                ) !important;
            }



            body.sidebar-collapsed #sidebar {
                padding: 10px 5px;
            }
            body.sidebar-collapsed #sidebar .sidebar-header {
                margin-bottom: 1.5rem;
            }
            body.sidebar-collapsed #sidebar #sidebar-toggle {
                font-size: 1.2rem;
                color: var(--accent-color);
            }
            body.sidebar-collapsed #sidebar .tool-group {
                gap: 15px; /* Better spacing for touch icons */
            }
            body.sidebar-collapsed #sidebar .btn {
                width: 44px; /* Slightly smaller to fit 60px padding */
                height: 44px;
                padding: 0;
                justify-content: center;
            }
        }

        h1 {
            font-size: 1.2rem;
            margin-top: 0;
            margin-bottom: 2rem;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .tool-group {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .btn {
            background: #2a2a2a;
            border: 1px solid var(--border-color);
            color: var(--text-color);
            padding: 12px;
            border-radius: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 10px;
            transition: all 0.2s ease;
            font-size: 0.9rem;
        }

        .btn:hover {
            background: #333;
        }

        .btn.active {
            background: var(--accent-color);
            border-color: var(--accent-color);
        }

        .btn i {
            font-size: 1.2rem;
        }

        #canvas-container {
            flex-grow: 1;
            position: relative;
            overflow: hidden;
            cursor: crosshair;
            isolation: isolate;
        }

        canvas {
            display: block;
            touch-action: none;
            filter: brightness(0.85) contrast(1.05);
            image-rendering: -moz-crisp-edges;
            image-rendering: -webkit-optimize-contrast;
            image-rendering: pixelated;
            image-rendering: crisp-edges;
        }

        #canvas-container canvas {
            filter: none;
        }

        #canvas-container::after {
            content: '';
            position: absolute;
            inset: 0;
            pointer-events: none;
            background: radial-gradient(circle, transparent 40%, rgba(0, 0, 0, 0.15) 100%);
            box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.2);
            z-index: 20;
        }

        #canvas-container::after {
            content: none;
        }

        .instructions {
            margin-top: auto;
            font-size: 0.8rem;
            color: #888;
            line-height: 1.4;
        }

        /* Furniture Picker styles */
        #furniture-panel, #floor-tiles-panel {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: rgba(20, 20, 20, 0.95);
            backdrop-filter: blur(15px);
            z-index: 2000;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 40px;
            overflow-y: auto;
            border: none;
            border-radius: 0;
            user-select: none;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        .furniture-grid {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 25px;
            width: 100%;
            max-width: 1200px;
            padding: 20px;
            overflow: visible;
        }

        .category-divider {
            width: 100%;
            max-width: 1200px;
            margin: 40px 0 10px 0;
            padding: 10px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            color: #888;
            font-size: 0.9rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .category-divider::after {
            content: '';
            flex-grow: 1;
            height: 1px;
            background: rgba(255, 255, 255, 0.05);
        }

        .furniture-item {
            flex: 0 0 120px;
            height: 180px; /* Taller to fit header */
            background: #2a2a2a;
            border: 2px solid transparent;
            border-bottom: 3px solid #444; /* Default shadow */
            border-radius: 8px;
            cursor: pointer;
            overflow: hidden;
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
            position: relative;
        }

        .floor-tile-item {
            flex: 0 0 100px;
            height: 100px;
            background: #2a2a2a;
            border: 2px solid #333;
            border-radius: 8px;
            cursor: pointer;
            overflow: hidden;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .floor-tile-item:hover {
            border-color: var(--accent-color);
            transform: scale(1.05);
            box-shadow: 0 0 15px rgba(79, 70, 229, 0.3);
        }

        .tiling-tab-btn.active, .tiling-tool-btn.active {
            background: var(--accent-color) !important;
            color: #fff !important;
            box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
        }

        .tiling-tab-btn:hover:not(.active), .tiling-tool-btn:hover:not(.active) {
            background: rgba(255, 255, 255, 0.05) !important;
            color: #ccc !important;
        }

        .floor-tile-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .furniture-item[data-tier="1"] { border-bottom-color: #666; }
        .furniture-item[data-tier="2"] { border-bottom-color: #2e7d32; }
        .furniture-item[data-tier="3"] { border-bottom-color: #1565c0; }
        .furniture-item[data-tier="4"] { border-bottom-color: #7b1fa2; }
        .furniture-item[data-tier="5"] { 
            border-bottom-color: #fbc02d; 
            box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.1);
        }

        .furniture-item:hover {
            background: #333;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }

        .furniture-item.selected {
            border-color: var(--accent-color);
            background: rgba(79, 70, 229, 0.1);
        }

        .furniture-item img {
            width: 80%;
            height: 80px;
            margin-top: 5px;
            object-fit: contain;
            filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
            -webkit-user-drag: none;
            pointer-events: none;
        }

        .info-bar {
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 10px;
            margin-top: auto;
            background: rgba(0, 0, 0, 0.3);
        }

        .buy-badge {
            background: transparent;
            color: #fbc02d; /* Yellow */
            font-size: 1rem;
            padding: 0;
            border: none;
            border-radius: 0;
            font-weight: 700;
            box-shadow: none;
            z-index: 10;
            cursor: pointer;
            transition: all 0.1s;
            white-space: nowrap;
        }

        .buy-badge:hover {
            color: #27de64;
        }

        .buy-badge.unaffordable,
        .buy-badge.unaffordable:hover {
            color: #8a8a8a;
        }

        .inventory-badge {
            background: rgba(0, 0, 0, 0);
            color: var(--text-color);
            font-size: 0.9rem;
            padding: 1px 4px;
            font-weight: 600;
            z-index: 2;
            pointer-events: none;
        }

        .item-header {
            width: 100%;
            height: 42px; /* Fixed height for 2 lines */
            background: rgba(0, 0, 0, 0.4);
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 4px 6px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        }

        .item-name {
            color: #ccc;
            font-size: 0.75rem;
            text-align: center;
            opacity: 1;
            transition: all 0.2s;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
            text-overflow: ellipsis;
            pointer-events: none;
            user-select: none;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            line-height: 1.2;
        }

        .furniture-item:hover .item-name {
            color: #fff;
        }

        .furniture-item:hover .item-header {
            background: rgba(0, 0, 0, 0.6);
        }

        /* Custom scrollbar */
        .furniture-grid::-webkit-scrollbar {
            height: 6px;
        }

        .furniture-grid::-webkit-scrollbar-track {
            background: transparent;
        }

        .furniture-grid::-webkit-scrollbar-thumb {
            background: #444;
            border-radius: 3px;
        }

        .furniture-grid::-webkit-scrollbar-thumb:hover {
            background: var(--accent-color);
        }

        /* Furniture Shadow Layer (behind furniture) */
        .furniture-shadows-layer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 4;
        }

        .furniture-shadow {
            position: absolute;
            background: #000;
            opacity: 0.4;
            pointer-events: none;
            -webkit-mask-size: contain;
            mask-size: contain;
            -webkit-mask-repeat: no-repeat;
            mask-repeat: no-repeat;
            -webkit-mask-position: center;
            mask-position: center;
        }

        /* Furniture & Lighting Layer */
        #furniture-layer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none; /* Allow clicks to reach canvas */
            z-index: 5;
        }

        .cancel-badge {
            position: fixed;
            top: 70px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(80, 35, 35, 0.448);
            color: white;
            padding: 8px 20px;
            border-radius: 20px;
            font-size: 0.7rem;
            cursor: pointer;
            z-index: 110;
            box-shadow: 0 4px 12px rgba(0,0,0,0.5);
            display: flex; /* usually hidden by inline style, flex when visible */
            align-items: center;
            gap: 6px;
            transition: all 0.2s;
            font-weight: 500;
        }

        .cancel-badge:hover {
            background: #ef4444;
        }

        @keyframes floatUpFade {
            0% { transform: translate(-50%, 0); opacity: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5)); }
            100% { transform: translate(-50%, -40px); opacity: 0; filter: drop-shadow(0 2px 4px rgba(0,0,0,0)); }
        }

        .floating-particle {
            position: fixed; /* so it can overlay everything based on exact clientX/Y */
            z-index: 9999;
            pointer-events: none;
            font-size: 1rem;
            font-weight: bold;
            text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
            animation: floatUpFade 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
            /* the specific color (yellow or red) and duration are injected individually via style */
        }

        @keyframes flashBuy {
            0% { transform: scale(1) translateY(0); border-color: transparent; }
            50% { transform: scale(1.08) translateY(-4px); border-color: #fbc02d; box-shadow: 0 10px 20px rgba(255, 215, 0, 0.4); z-index: 50; }
            100% { transform: scale(1) translateY(0); border-color: transparent; }
        }

        .furniture-item.flash-buy {
            animation: flashBuy 0.3s ease-out;
        }

        @keyframes popPlace {
            0% { transform: scale(0.5); opacity: 0; filter: brightness(2); }
            60% { transform: scale(1.15); opacity: 1; filter: brightness(1.2); }
            100% { transform: scale(1); opacity: 1; filter: brightness(0.8); }
        }

        .furniture-sprite.pop-place {
            animation: popPlace 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }

        .furniture-sprite {
            position: absolute;
            image-rendering: pixelated; /* Sharp pixel art */
            transition: opacity 0.2s ease, filter 0.2s ease;
            filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4)) brightness(0.8) contrast(1.05);
        }

        .furniture-sprite.delete-hover {
            filter: drop-shadow(0 0 0 red) drop-shadow(0 0 4px red) brightness(1.2);
            outline: 2px dashed #ff4444;
            outline-offset: 4px;
            cursor: pointer;
        }

        .furniture-sprite.active-selected {
            outline: 2px dashed #22c55e;
            outline-offset: 4px;
            filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.5)) brightness(1.0) contrast(1.05);
        }

        .furniture-sprite.active-selected.moving {
            animation: pulseGreenOutline 1s ease-in-out infinite;
        }

        @keyframes pulseGreenOutline {
            0%, 100% { outline-color: #22c55e; filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.5)) brightness(1.0); }
            50% { outline-color: #86efac; filter: drop-shadow(0 0 12px rgba(34, 197, 94, 0.7)) brightness(1.1); }
        }

        .furniture-move-icon {
            position: absolute;
            transform: translate(-50%, -50%);
            width: 28px;
            height: 28px;
            background: rgba(0, 0, 0, 0.7);
            border: 2px solid #22c55e;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #22c55e;
            font-size: 14px;
            pointer-events: none;
            z-index: 10;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
        }

        .furniture-move-hint {
            display: block;
            font-size: 9px;
            color: #86efac;
            font-style: italic;
            margin-top: 2px;
            opacity: 0.8;
        }

        .furniture-sprite.ghost {
            opacity: 0.6;
            filter: none;
        }

        .torch-light {
            position: absolute;
            border-radius: 50%;
            pointer-events: none;
            mix-blend-mode: plus-lighter;
            /* Fallback if plus-lighter is unsupported */
            background: radial-gradient(circle, rgba(255, 160, 40, 0.25) 0%, rgba(200, 80, 0, 0.08) 60%, transparent 100%);
            transform: translate(-50%, -50%);
            z-index: 6;
        }

        /* Responsive */
        @media (max-width: 768px) {
            #sidebar {
                position: absolute;
                height: 100%;
                background-color: transparent;
                border-right: none;
                pointer-events: none;
                z-index: 1000;
            }
            
            #sidebar * {
                pointer-events: auto; /* Re-enable for buttons and header */
            }
            
            body.sidebar-collapsed #sidebar {
                --sidebar-collapsed-width: 60px;
            }

            .sidebar-header {
                margin-bottom: 1rem;
            }

            #furniture-panel {
                padding: 20px 10px;
            }

            .furniture-grid {
                gap: 15px;
                padding: 10px;
            }

            .furniture-item {
                flex: 0 0 100px;
                height: 120px; 
            }
            .furniture-item img {
                height: 50px;
                margin-top: 2px;
            }
            .info-bar {
                padding: 4px 6px;
            }
            .buy-badge {
                font-size: 0.85rem;
            }
            .inventory-badge {
                font-size: 0.75rem;
            }

         
        }

        /* Room Confirm / Reject bar */
        #room-confirm-bar {
            position: fixed;
            top: 72px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 10px;
            z-index: 200;
            animation: slideDown 0.25s ease-out;
        }

        @keyframes slideDown {
            from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
            to   { transform: translateX(-50%) translateY(0); opacity: 1; }
        }

        .room-confirm-btn {
            padding: 8px 22px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 0.85rem;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 6px;
            color: #fff;
            transition: all 0.15s ease;
            box-shadow: 0 4px 14px rgba(0,0,0,0.4);
        }

        .room-confirm-btn.reject {
            background: rgba(120, 30, 30, 0.75);
            backdrop-filter: blur(6px);
        }
        .room-confirm-btn.reject:hover {
            background: #ef4444;
        }

        .room-confirm-btn.confirm {
            background: rgba(25, 100, 50, 0.75);
            backdrop-filter: blur(6px);
        }
        .room-confirm-btn.confirm:hover {
            background: #22c55e;
        }

        /* ===== Waifu Drawer Panel ===== */
        #waifu-drawer-panel {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: rgba(20, 20, 20, 0.95);
            backdrop-filter: blur(15px);
            z-index: 2000;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 40px;
            overflow-y: auto;
            animation: fadeIn 0.3s ease;
            user-select: none;
        }

        /* ===== Spells Panel ===== */
        #spells-panel {
            position: fixed;
            inset: 0;
            background: rgba(20, 20, 20, 0.95);
            backdrop-filter: blur(15px);
            z-index: 2000;
            flex-direction: column;
            align-items: center;
            padding: 40px 20px;
            overflow-y: auto;
            animation: fadeIn 0.3s ease;
            user-select: none;
        }

        .spells-panel-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;
            max-width: 900px;
            padding: 0 0 18px;
            border-bottom: 1px solid #333;
            margin-bottom: 20px;
        }

        .spells-panel-header h2 {
            margin: 0;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
            gap: 10px;
            color: #e5e5e5;
        }

        .spells-list {
            width: 100%;
            max-width: 900px;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
            gap: 14px;
        }

        .spells-character-preview {
            width: 100%;
            max-width: 900px;
            margin: 0 0 16px;
        }

        .spells-character-preview:empty {
            display: none;
        }

        .spells-character-card {
            max-width: 560px;
            margin: 0 auto;
        }

        .spell-card {
            min-height: 142px;
            background: #2a2a2a;
            border: 2px solid transparent;
            border-radius: 8px;
            padding: 16px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            gap: 16px;
            position: relative;
            overflow: hidden;
            isolation: isolate;
            transition: all 0.2s ease;
        }

        .spell-card > * {
            position: relative;
            z-index: 2;
        }

        .spell-card:hover {
            background: #333;
            border-color: #555;
        }

        .spell-card-main {
            display: flex;
            align-items: flex-start;
            gap: 12px;
        }

        .spell-element-dot {
            width: 16px;
            height: 16px;
            flex: 0 0 16px;
            margin-top: 4px;
            border-radius: 50%;
            border: 2px solid #555;
            background: transparent;
            box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.16);
        }

          .spell-element-nature {
            background: #1a7e2e;
            border-color: #3ba556;
            box-shadow: 0 0 14px rgba(49, 99, 72, 0.5);
        }

        .spell-element-fire {
            background: #ef4444;
            border-color: #ff8a8a;
            box-shadow: 0 0 14px rgba(239, 68, 68, 0.5);
        }

        .spell-element-water {
            background: #38bdf8;
            border-color: #9be5ff;
            box-shadow: 0 0 14px rgba(56, 189, 248, 0.48);
        }

        .spell-element-lightning {
            background: #facc15;
            border-color: #fff08a;
            box-shadow: 0 0 14px rgba(250, 204, 21, 0.5);
        }

        .spell-element-ice {
            background: #a5f3fc;
            border-color: #e0fbff;
            box-shadow: 0 0 14px rgba(165, 243, 252, 0.48);
        }

        .spell-element-void {
            background: #8b5cf6;
            border-color: #c4b5fd;
            box-shadow: 0 0 14px rgba(139, 92, 246, 0.52);
        }

        .spell-card-copy {
            min-width: 0;
        }

        .spell-card-copy h3 {
            margin: 0 0 8px;
            color: #f1f1f1;
            font-size: 1rem;
            line-height: 1.2;
        }

        .spell-card-copy p {
            margin: 0;
            color: #aaa;
            font-size: 0.85rem;
            line-height: 1.45;
        }

        .spell-upgrade-button {
            align-self: flex-end;
            min-width: 96px;
            min-height: 36px;
            border: 0px solid #444;
            border-radius: 8px;
            background: #3b9f45;
            color: #ffffff;
            font: inherit;
            font-size: 15px;
            font-weight: 700;
            text-shadow: 1px 1px 1px 1px black;
        }

        .spell-upgrade-fx,
        .spell-upgrade-fx-drop,
        .spell-level-up-ripple {
            position: absolute;
            left: var(--spell-fx-x);
            top: var(--spell-fx-y);
            pointer-events: none;
            z-index: 1;
        }

        .spell-upgrade-fx {
            width: 24px;
            height: 24px;
            border-radius: 50%;
            background:
                radial-gradient(circle, rgba(255, 255, 255, 0.48) 0 8%, transparent 9%),
                radial-gradient(circle, var(--spell-fx-core, rgba(56, 189, 248, 0.42)) 0 28%, var(--spell-fx-glow, rgba(56, 189, 248, 0.14)) 54%, transparent 72%);
            filter: blur(0.2px);
            transform: translate(-50%, -50%) scale(0);
            animation: spellUpgradeExpand 0.72s cubic-bezier(0.18, 0.72, 0.18, 1) forwards;
        }

        .spell-upgrade-fx-drop {
            width: 16px;
            height: 20px;
            border-radius: 58% 58% 64% 64%;
            background: linear-gradient(155deg, rgba(255, 255, 255, 0.95), var(--spell-fx-drop, #9be5ff) 44%, rgba(56, 189, 248, 0.62));
            box-shadow: 0 0 18px var(--spell-fx-core, rgba(56, 189, 248, 0.58));
            transform: translate(-50%, -50%) scale(0.35) rotate(45deg);
            animation: spellUpgradeDrop 0.52s cubic-bezier(0.2, 0.9, 0.2, 1) forwards;
        }

        .spell-card-upgraded {
            animation: spellCardUpgradePulse 0.72s ease-out;
        }

        .spell-card-level-up {
            animation: spellCardLevelUpPulse 0.9s ease-out;
        }

        .spell-level-up-ripple {
            width: var(--spell-ripple-width, 84px);
            height: 18px;
            border: 2px solid var(--spell-fx-drop, #9be5ff);
            border-top-color: rgba(255, 255, 255, 0.9);
            border-bottom-color: var(--spell-fx-core, rgba(56, 189, 248, 0.42));
            border-radius: 50%;
            box-shadow:
                0 0 16px var(--spell-fx-core, rgba(56, 189, 248, 0.42)),
                inset 0 0 12px var(--spell-fx-glow, rgba(56, 189, 248, 0.14));
            opacity: 0;
            transform: translate(-50%, -50%) scale(0.26);
            animation: spellLevelUpRipple 0.74s cubic-bezier(0.16, 0.76, 0.2, 1) var(--spell-ripple-delay, 0s) forwards;
        }

        .spell-upgrade-fx-fire {
            --spell-fx-core: rgba(239, 68, 68, 0.42);
            --spell-fx-glow: rgba(251, 146, 60, 0.18);
            --spell-fx-drop: #ffb36f;
        }

        .spell-upgrade-fx-water {
            --spell-fx-core: rgba(56, 189, 248, 0.42);
            --spell-fx-glow: rgba(14, 165, 233, 0.18);
            --spell-fx-drop: #9be5ff;
        }

        .spell-upgrade-fx-lightning {
            --spell-fx-core: rgba(250, 204, 21, 0.42);
            --spell-fx-glow: rgba(234, 179, 8, 0.16);
            --spell-fx-drop: #fff08a;
        }

        .spell-upgrade-fx-ice {
            --spell-fx-core: rgba(165, 243, 252, 0.42);
            --spell-fx-glow: rgba(103, 232, 249, 0.16);
            --spell-fx-drop: #e0fbff;
        }

        .spell-upgrade-fx-void,
        .spell-upgrade-fx-arcane {
            --spell-fx-core: rgba(139, 92, 246, 0.42);
            --spell-fx-glow: rgba(99, 102, 241, 0.16);
            --spell-fx-drop: #c4b5fd;
        }

        @keyframes spellUpgradeExpand {
            0% {
                opacity: 0;
                transform: translate(-50%, -50%) scale(0);
            }
            18% {
                opacity: 1;
            }
            78% {
                opacity: 0.72;
            }
            100% {
                opacity: 0;
                transform: translate(-50%, -50%) scale(22);
            }
        }

        @keyframes spellUpgradeDrop {
            0% {
                opacity: 0;
                transform: translate(-50%, -160%) scale(0.35) rotate(45deg);
            }
            42% {
                opacity: 1;
                transform: translate(-50%, -50%) scale(1) rotate(45deg);
            }
            100% {
                opacity: 0;
                transform: translate(-50%, -50%) scale(1.85) rotate(45deg);
            }
        }

        @keyframes spellCardUpgradePulse {
            0% {
                border-color: transparent;
                box-shadow: none;
            }
            36% {
                border-color: rgba(155, 229, 255, 0.75);
                box-shadow: 0 0 26px rgba(56, 189, 248, 0.22);
            }
            100% {
                border-color: transparent;
                box-shadow: none;
            }
        }

        @keyframes spellLevelUpRipple {
            0% {
                opacity: 0;
                transform: translate(-50%, 24px) scale(0.28);
                filter: blur(0);
            }
            18% {
                opacity: 0.95;
            }
            100% {
                opacity: 0;
                transform: translate(-50%, -92px) scale(1.18);
                filter: blur(1.4px);
            }
        }

        @keyframes spellCardLevelUpPulse {
            0% {
                border-color: transparent;
                box-shadow: none;
            }
            34% {
                border-color: rgba(255, 255, 255, 0.55);
                box-shadow:
                    0 0 20px rgba(56, 189, 248, 0.2),
                    inset 0 0 22px rgba(255, 255, 255, 0.05);
            }
            100% {
                border-color: transparent;
                box-shadow: none;
            }
        }

        @keyframes adventureBattleHudLevelUpRipple {
            0% {
                opacity: 0;
                transform: translate(-50%, 18px) scale(0.28);
                box-shadow:
                    0 0 0 0 rgba(34, 197, 94, 0),
                    0 0 0 0 rgba(34, 197, 94, 0),
                    inset 0 0 10px rgba(34, 197, 94, 0.1);
            }
            18% {
                opacity: 0.95;
            }
            42% {
                box-shadow:
                    0 -12px 0 -8px rgba(34, 197, 94, 0.48),
                    0 -24px 0 -14px rgba(34, 197, 94, 0.28),
                    inset 0 0 12px rgba(34, 197, 94, 0.16);
            }
            70% {
                opacity: 0.62;
                box-shadow:
                    0 -18px 0 -10px rgba(34, 197, 94, 0.36),
                    0 -36px 0 -18px rgba(34, 197, 94, 0.22),
                    0 -54px 0 -26px rgba(34, 197, 94, 0.14),
                    inset 0 0 12px rgba(34, 197, 94, 0.12);
            }
            100% {
                opacity: 0;
                transform: translate(-50%, -42px) scale(1.12);
                box-shadow:
                    0 -18px 0 -12px rgba(34, 197, 94, 0),
                    0 -36px 0 -20px rgba(34, 197, 94, 0),
                    0 -54px 0 -28px rgba(34, 197, 94, 0),
                    inset 0 0 12px rgba(34, 197, 94, 0);
            }
        }

        /* ===== World Map Panel ===== */
        /* World Map: fullscreen overlay with full-canvas map */
        #world-map-panel {
            position: fixed;
            inset: 0;
            background: rgba(15, 15, 15, 0.98);
            backdrop-filter: blur(20px);
            z-index: 2500;
            display: flex;
            align-items: stretch;
            justify-content: center;
            padding: 0;
            overflow: hidden;
            animation: fadeIn 0.3s ease;
            user-select: none;
        }

        /* container stretches and centers canvas */
        #world-map-container.worldmap-full {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
        }

        /* canvas fills the available space entirely */
        #worldMapCanvas {
            width: 100%;
            height: 100%;
            display: block;
            background: #1a1a1a;
            border: none;
            border-radius: 0;
            box-shadow: none;
            max-width: none;
            max-height: none;
            /* Override the generic canvas pixelated rule.
             Smoothing is handled in JS per-draw-call instead. */
            image-rendering: auto;
        }

        #quests-panel {
            position: fixed;
            inset: 0;
            background: rgba(20, 20, 20, 0.96);
            backdrop-filter: blur(15px);
            z-index: 2400;
            flex-direction: column;
            align-items: center;
            padding: 40px 20px;
            overflow-y: auto;
        }

        .dungeon-quests-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;
            max-width: 900px;
            padding-bottom: 16px;
            border-bottom: 1px solid #333;
            margin-bottom: 16px;
        }

        .dungeon-quests-header h2 {
            margin: 0;
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 1.5rem;
        }

        .quests-tabs {
            width: 100%;
            max-width: 900px;
            display: flex;
            gap: 8px;
            padding: 5px;
            border: 1px solid #333;
            border-radius: 8px;
            background: #181818;
            margin-bottom: 16px;
        }

        .quest-tab {
            flex: 1;
            min-height: 40px;
            border: 0;
            border-radius: 6px;
            background: transparent;
            color: #aaa;
            cursor: pointer;
            font: inherit;
            font-weight: 700;
        }

        .quest-tab:hover {
            color: #e5e5e5;
            background: rgba(255, 255, 255, 0.05);
        }

        .quest-tab.active {
            color: #fff;
            background: var(--accent-color);
        }

        .quests-list {
            width: 100%;
            max-width: 900px;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
            gap: 14px;
        }

        .quest-group-divider {
            grid-column: 1 / -1;
            display: flex;
            align-items: center;
            gap: 12px;
            color: #aaa;
            font-size: 0.78rem;
            font-weight: 700;
            text-transform: uppercase;
        }

        .quest-group-divider::after {
            content: "";
            height: 1px;
            flex: 1;
            background: #333;
        }

        .quest-card {
            background: #242424;
            border: 1px solid #333;
            border-radius: 8px;
            padding: 16px;
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .quest-card.done {
            background: #242424ef;
        }

        .quest-card.selectable {
            cursor: pointer;
        }

        .quest-card.selectable:hover {
            background: #2c2c2c;
            border-color: #555;
        }

        .quest-card h3 {
            margin: 0;
            font-size: 1rem;
        }

        .quest-card p {
            margin: 0;
            color: #bbb;
            font-size: 0.9rem;
            line-height: 1.45;
        }

        .quest-meta {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 8px 14px;
            color: #ddd;
            font-size: 0.82rem;
            font-weight: 600;
        }

        .quest-rewards {
            width: 100%;
            display: flex;
            gap: 14px;
            margin-top: 2px;
        }

        .quest-progress {
            width: 100%;
            padding: 10px 8px;
            border-radius: 999px;
            background-color: #1e1e1e;
        }

        .quest-progress-track {
            width: 100%;
            height: 9px;
            overflow: hidden;
            border-radius: 999px;
            background: #000;
        }

        .quest-progress-fill {
            width: 0;
            height: 100%;
            border-radius: inherit;
            background: #86efac;
            transition: width 0.25s linear;
        }

        .quest-complete-banner {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 10px;
            padding: 12px;
            border: 1px solid rgba(134, 239, 172, 0.45);
            border-radius: 8px;
            background: rgba(134, 239, 172, 0.08);
            color: #e5e5e5;
        }

        .quest-complete-banner strong {
            color: #86efac;
            font-size: 0.9rem;
        }

        .quest-claim-button {
            font-family: inherit;
            display: flex;          /* Enables flexbox */
    align-items: center;    /* Vertically centers children */
    gap: 4px;              /* Adds space between icon and text */
            align-self: center;
            border-radius: 28px;
            padding: 10px 15px;
            background:  var(--accent-color);
            color: #ffffff;
            cursor: pointer;
            font-weight: 600;
            font-size: 0.95rem;
            margin-top: 6px;
            margin-bottom: 6px;
        }

        .quest-claim-button i {
            text-align: center;
            line-height: 0;
            font-size: 1rem;
        }

        .quest-claim-button:disabled {
            cursor: default;
            opacity: 0.6;
        }

        .quest-item-reward {
            color: #86efac;
        }

        .quest-level {
            color: #fff;
            margin-right: 12px;
        }

         .quest-karma {
            color: #ffd700;
            text-shadow: 0 0 10px rgba(255, 215, 0, 0.5), 1px 1px 2px rgba(0, 0, 0, 0.8);
            margin-right: 12px;
        }

        .quest-duration i {
            font-size: 0.9rem;
            vertical-align: middle;
            margin-right: 2px;
        }

        .quest-xp {
            color: #2c87ff;
            text-shadow: 0 0 10px rgba(77, 119, 255, 0.5), 1px 1px 2px rgba(0, 0, 0, 0.8);
            min-width: 25px;
        }

        .quest-done-status {
            align-self: flex-start;
            border: 1px solid #4ade80;
            border-radius: 999px;
            padding: 4px 8px;
            color: #86efac;
            font-size: 0.78rem;
        }

            .quest-rewards {
            align-self: flex-start;
            border: 0px solid #444;
            border-radius: 999px;
            padding: 9px 17px;
            color: #ddd;
            font-size: 0.78rem;
            background-color: #1e1e1e;
            justify-content: space-between;
        }

        .quest-active-waifu {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-top: 10px;
            min-width: 100%;
        }

        .quest-active-waifu-avatar {
            width: 38px;
            height: 38px;
            border: 1px solid #555;
            border-radius: 50%;
            object-fit: cover;
            background: #1e1e1e;
        }

        .quest-active-waifu-pill {
            border-radius: 999px;
            padding: 7px 20px;
            background: #3a3a3a;
            color: #e5e5e5;
            width: 100%;
        }

        .quest-active-waifu-info {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
        }

        .quest-active-waifu-name {
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-size: 0.78rem;
            font-weight: 700;
        }

        .quest-active-waifu-level {
            display: inline-block;
            flex: 0 0 auto;
            border-radius: 999px;
            padding: 2px 6px;
            background: rgba(78, 70, 229, 0.835);
            color: #c7d2fe;
            font-size: 0.68rem;
            font-weight: 800;
        }

        .quest-active-waifu-level.level-up {
            animation: quest-level-pop 0.6s ease;
            background: #16a34a;
            color: #fff;
        }

        .quest-waifu-xp-progress {
            position: relative;
            display: none;
            height: 20px;
            margin-top: 6px;
            overflow: hidden;
            border-radius: 999px;
            background: #202020;
        }

        .quest-active-waifu.claiming-xp .quest-waifu-xp-progress {
            display: block;
        }

        .quest-waifu-xp-fill {
            width: 0;
            height: 100%;
            border-radius: inherit;
            background: linear-gradient(90deg, #2563eb, #60a5fa);
            transition: width 0.72s cubic-bezier(0.22, 1, 0.36, 1);
        }

        .quest-waifu-xp-gain {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 0.55rem;
            font-weight: 800;
            line-height: 1;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
        }

        @keyframes quest-level-pop {
            0% { transform: scale(1); }
            45% { transform: scale(1.16); }
            100% { transform: scale(1); }
        }

        .quest-waifu-selection {
            grid-column: 1 / -1;
            display: flex;
            flex-direction: column;
            gap: 16px;
        }

        .quest-back-button {
            align-self: flex-start;
            background: #2a2a2a;
            border: 1px solid #444;
            color: #e5e5e5;
            border-radius: 8px;
            padding: 10px 12px;
            cursor: pointer;
        }

        .quest-selected-card .quest-card {
            cursor: default;
        }

        .quest-waifu-list.waifu-drawer-grid {
            display: flex;
            flex-direction: column;
            align-items: stretch;
            justify-content: flex-start;
            gap: 10px;
        }

        .quest-waifu-card.waifu-drawer-card {
            position: relative;
            width: 98%;
            height: auto;
            min-height: 86px;
            flex: none;
            flex-direction: row;
            align-items: center;
            justify-content: flex-start;
            padding: 10px 14px;
            cursor: default;
        }

        .quest-waifu-card.waifu-drawer-card img {
            width: 56px;
            height: 56px;
            margin-top: 0;
            margin-right: 12px;
        }

        .quest-waifu-details {
            flex: 1;
            display: flex;
            min-width: 0;
            flex-direction: column;
            align-items: flex-start;
            justify-content: center;
            gap: 7px;
        }

        .quest-waifu-card .waifu-card-name {
            margin-top: 0;
            width: 100%;
            min-width: 0;
            font-size: 0.95rem;
            text-align: left;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .quest-waifu-action-row {
            display: flex;
            width: 100%;
            min-width: 0;
            align-items: center;
            gap: 8px;
        }

        .quest-waifu-card.waifu-drawer-card.busy {
            cursor: not-allowed;
            opacity: 0.55;
            filter: grayscale(1);
            border-color: #555;
            background: #242424;
        }

        .quest-waifu-card.waifu-drawer-card.busy:hover {
            transform: none;
            border-color: #555;
            box-shadow: none;
        }

        .quest-waifu-card.waifu-drawer-card.level-locked {
            opacity: 0.7;
        }

        .quest-waifu-card.waifu-drawer-card.level-locked:hover {
            transform: none;
            border-color: #555;
            box-shadow: none;
        }

        .quest-waifu-card .waifu-on-map-badge.level-locked {
            background: #5f6368;
            color: #e5e5e5;
        }

        .quest-waifu-card .waifu-on-map-badge {
            position: static;
            align-self: flex-start;
            text-transform: none;
        }

        .quest-waifu-busy-pill {
            flex: 0 0 auto;
            margin-left: auto;
            border: 1px solid #666;
            border-radius: 999px;
            padding: 4px 8px;
            color: #d1d5db;
            background: #333;
            font-size: 0.72rem;
            line-height: 1;
            white-space: nowrap;
        }

        .quest-waifu-send-pill,
        .quest-waifu-confirm-pill,
        .quest-waifu-cancel-pill {
            flex: 0 0 auto;
            border: 0;
            border-radius: 999px;
            padding: 8px 10px;
            color: #fff;
            font-size: 15px;
            line-height: 1;
            white-space: nowrap;
            cursor: pointer;
            font-family: inherit;
        }

        .quest-waifu-send-pill {
            margin-left: auto;
            background: var(--accent-color);
            min-width: 66px;
            font-size: 16px;
            padding: 8px 10px;
            color: #fff;
            font-size: 15px;
        }

        .quest-waifu-send-confirm {
            display: flex;
            flex: 0 0 auto;
            flex-wrap: wrap;
            justify-content: flex-end;
            gap: 6px;
            margin-left: auto;
        }

        .quest-waifu-confirm-pill {
            background: #16a34a;
        }

        .quest-waifu-cancel-pill {
            background: #555;
        }

        .quest-waifu-send-pill:hover,
        .quest-waifu-confirm-pill:hover,
        .quest-waifu-cancel-pill:hover {
            filter: brightness(1.12);
        }

        .quest-waifu-send-pill:disabled {
            cursor: not-allowed;
            opacity: 0.65;
            filter: grayscale(1);
        }

        /* floating close button for the map */
        #close-world-map.worldmap-close {
            position: absolute;
            top: 12px;
            right: 12px;
            z-index: 2600;
            background: rgba(0,0,0,0.45);
            border: 1px solid rgba(255,255,255,0.06);
            color: #fff;
            padding: 8px;
            border-radius: 999px;
            font-size: 1.1rem;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 6px 18px rgba(0,0,0,0.5);
        }

        #close-world-map.worldmap-close:hover {
            background: rgba(0,0,0,0.6);
            transform: translateY(-1px);
        }

        /* ===== Interior View Panel ===== */
        #interior-view-panel {
            position: fixed;
            inset: 0;
            background: rgba(10, 10, 10, 0.98);
            backdrop-filter: blur(20px);
            z-index: 2500;
            display: flex;
            align-items: stretch;
            justify-content: center;
            padding: 0;
            overflow: hidden;
            animation: fadeIn 0.3s ease;
            user-select: none;
        }



        .waifu-drawer-grid {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 14px;
            width: 100%;
            max-width: 1200px;
            padding: 0px;
        }

        .furniture-label {
            position: fixed;
            z-index: 1000;
            background: rgba(0, 0, 0, 0.8);
            color: #fff;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: 600;
            pointer-events: none;
            border: 1px solid rgba(255, 255, 255, 0.2);
            white-space: nowrap;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
            pointer-events: auto;
        }

        .furniture-label::after {
            content: '';
            position: absolute;
            bottom: -6px;
            left: 50%;
            transform: translateX(-50%);
            border-left: 6px solid transparent;
            border-right: 6px solid transparent;
            border-top: 6px solid rgba(0, 0, 0, 0.8);
        }

        .waifu-drawer-card {
            flex: 0 0 140px;
            height: 350px;
            background: linear-gradient(168deg, #2e2e34 0%, #232328 100%);
            border: 2px solid rgba(255,255,255,0.06);
            border-radius: 12px;
            cursor: pointer;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
            position: relative;
            padding-top: 6px;
            transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
        }

        .waifu-drawer-card:hover {
            border-color: rgba(120, 110, 230, 0.45);
            box-shadow: 0 4px 16px rgba(78, 70, 229, 0.15);
        }

        .waifu-drawer-actions {
            display: flex;
            gap: 8px;
            width: 100%;
            justify-content: center;
            margin-top: auto;
            padding: 10px 8px 8px;
            flex-wrap: wrap;
            box-sizing: border-box;
        }

        .waifu-drawer-action-btn {
            flex: 1 1 48%;
            min-width: 48%;
            border: none;
            border-radius: 8px;
            padding: 4px 7px;
            font-size: 11px;
            font-weight: 700;
            color: #fff;
            background: #4e46e5b8;
            cursor: pointer;
            transition: background 0.2s ease, transform 0.15s ease;
        }


        .waifu-drawer-action-btn.remove-button {
            background: #b43a3a5b;
        }


        .waifu-drawer-action-btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            background: #333;
        }


        .waifu-drawer-card img {
            width: 80px;
            height: 80px;
            margin-top: 8px;
            object-fit: cover;
            border-radius: 50%;
            border: 2.5px solid rgba(255,255,255,0.12);
            pointer-events: none;
            box-shadow: 0 2px 8px rgba(0,0,0,0.35);
        }

        .waifu-card-name {
            margin-top: 10px;
            font-size: 0.82rem;
            font-weight: 600;
            color: #f0f0f0;
            text-align: center;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 200px;
            padding: 0 6px;
            letter-spacing: 0.01em;
        }

        #waifu-drawer-list .waifu-card-name {
            width: 100%;
            max-width: 100%;
            line-height: 1.2;
            min-height: 1.8rem;
            white-space: normal;
            overflow-wrap: anywhere;
            word-break: break-word;
            text-overflow: clip;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }

        #waifu-drawer-list .waifu-drawer-level-badge {
            margin-top: 6px;
            align-self: center;
            border-radius: 6px;
            padding: 4px 10px;
            background: linear-gradient(135deg, #5a4ee5cc 0%, #4338cacc 100%);
            color: #fff;
            font-size: 0.7rem;
            font-weight: 700;
            line-height: 1;
            text-shadow: #111 0 1px 1px;
            white-space: nowrap;
            letter-spacing: 0.02em;
        }

        .waifu-drag-ghost {
            position: absolute;
            top: -9999px;
            left: -9999px;
            width: 40px;
            height: 40px;
            pointer-events: none;
        }

        .waifu-drag-ghost img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            object-fit: cover;
        }

        /* ===== Waifu Profile Sidebar ===== */
        .waifu-profile-popup {
            position: fixed;
            top: 0;
            right: 0;
            width: 340px; 
            height: 100vh;
            background: rgba(22, 22, 22, 0.95);
            backdrop-filter: blur(15px);
            border-left: 1px solid rgba(255, 255, 255, 0.1);
            z-index: 3000;
            box-shadow: -10px 0 30px rgba(0, 0, 0, 0.7);
            overflow-y: auto;
            animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            font-family: 'Zhcn';
            display: flex;
            flex-direction: column;
        }

        @keyframes slideInRight {
            from { transform: translateX(100%); }
            to { transform: translateX(0); }
        }


        .waifu-profile-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 12px;
            background: rgba(0, 0, 0, 0.3);
            border-bottom: 1px solid #333;
        }

        .waifu-profile-name {
            font-weight: 600;
            font-size: 18px;
            color: #e5e5e5;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 240px;
        }

        .waifu-profile-close {
            background: none;
            border: none;
            color: #888;
            font-size: 1.3rem;
            cursor: pointer;
            padding: 0;
            line-height: 1;
        }

        .waifu-profile-close:hover {
            color: #fff;
        }

        .waifu-profile-pic {
            width: 100%;
            height: 160px;
            object-fit: cover;
        }

        .waifu-profile-about {
            padding: 10px 12px;
            font-size: 10px;
            color: #aaa;
            line-height: 1.4;
            max-height: 80px;
            overflow-y: auto;
            margin: 0;
            margin-bottom: 8px;
        }

        .sprite-editor-container {
            display: flex;
            justify-content: space-around;
            align-items: center;
            padding: 10px 15px;
            background: rgba(0, 0, 0, 0.2);
            border-top: 1px solid #333;
            border-bottom: 1px solid #333;
            margin-bottom: 12px;
        }

        .sprite-nav {
            background: none;
            border: none;
            color: #e5e5e5;
            font-size: 1.5rem;
            cursor: pointer;
            width: 44px;
            height: 44px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            flex: 0 0 44px;
            padding: 0;
            line-height: 1;
            transition: color 0.15s, background-color 0.15s;
        }

        .sprite-nav:hover {
            color: #fff;
            background-color: rgba(255, 255, 255, 0.08);
        }

        .sprite-preview-box {
            width: 128px;
            height: 238px;
            overflow: hidden;
            position: relative;
            background: #111;
            border-radius: 4px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
            border: 1px solid #444;
        }

        .sprite-preview {
            width: 100%;
            height: 100%;
            background-repeat: no-repeat;
            image-rendering: -moz-crisp-edges;
            image-rendering: -webkit-optimize-contrast;
            image-rendering: crisp-edges;
            image-rendering: pixelated;
        }

        .sprite-save-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            width: calc(100% - 24px);
            min-height: 36px;
            margin: 0 12px 12px 12px;
            padding: 8px;
            background: #4f46e5;
            color: #fff;
            border: none;
            border-radius: 4px;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.15s;
            font-size: 0.85rem;
            text-align: center;
        }

        .sprite-save-btn:hover {
            background: #4338ca;
        }

        .sprite-save-btn:disabled {
            background: #444;
            cursor: not-allowed;
            color: #aaa;
        }

        .waifu-profile-remove {
            width: 30px;
            padding: 8px;
            background: rgba(120, 30, 30, 0.6);
            color: #fff;
            border: none;
            border-top: 1px solid #333;
            cursor: pointer;
            font-size: 0.8rem;
            font-weight: 500;
            transition: background 0.15s;
            border-radius: 100px;
        }

        .waifu-profile-remove:hover {
            background: #ef4444;
        }

        /* Floating quick-actions toolbar (market/shop items) */
        .quick-actions-toolbar {
            position: fixed;
            left: calc(var(--current-sidebar-width) + 0px);
            right: 0;
            width: calc(100% - var(--current-sidebar-width) - 6px);
            bottom: 0;
            height: 155px;
            z-index: 120;
            background: rgba(10, 10, 12, 0.82);
            border-top: 1px solid rgba(255, 255, 255, 0.08);
            box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.65);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            display: flex;
            flex-direction: column;
            padding: 6px 8px 12px 8px;
            gap: 4px;
        }

        .quick-actions-toolbar.hidden {
            display: none;
        }

        .quick-actions-toolbar.battle-targeting {
            left: 50%;
            right: auto;
            bottom: 118px;
            width: min(768px, calc(100vw - 92px));
            height: 112px;
            transform: translateX(-50%);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            padding: 6px 8px 8px;
            z-index: 980;
        }

        .quick-actions-toolbar.battle-targeting .quick-actions-toolbar-header {
            display: none;
        }

        .quick-actions-toolbar.battle-targeting .quick-actions-strip {
            padding-bottom: 4px;
        }

        .quick-actions-toolbar.battle-targeting .quick-actions-strip .furniture-item {
            flex-basis: 82px;
            height: 96px;
            display: grid;
            grid-template-rows: 24px 48px 18px;
            align-items: center;
            overflow: hidden;
                 border-bottom-color: rgba(22, 163, 74, 0.62);
            border-bottom-width: 0px;
        }

        .quick-actions-toolbar.battle-targeting .quick-actions-strip .item-header {
            height: 24px;
        }

        .quick-actions-toolbar.battle-targeting .quick-actions-strip .furniture-item img {
            max-height: 36px;
            grid-row: 2;
            align-self: center;
            justify-self: center;
            margin-top: 0;
        }

        .quick-actions-toolbar.battle-targeting .quick-actions-strip .battle-item-effect-label {
            position: static;
            grid-row: 3;
            align-self: stretch;
            left: auto;
            right: auto;
            bottom: auto;
            width: auto;
            justify-content: center;
            font-size: 10px;
            margin: 0 0px 0px;
        }

        .quick-actions-toolbar.battle-targeting .quick-actions-strip [data-item-amount-label] {
            bottom: 22px !important;
        }

        .quick-actions-toolbar-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
        }

        .quick-actions-toolbar-title {
            display: flex;
            align-items: center;
            gap: 10px;
            color: #ddd;
            font-weight: 600;
            font-size: 0.82rem;
            letter-spacing: 0.3px;
            user-select: none;
        }

        .quick-actions-strip {
            display: flex;
            flex-wrap: nowrap;
            justify-content: flex-start;
            align-items: flex-start;
            gap: 12px;
            overflow-x: auto;
            overflow-y: hidden;
            padding: 2px 2px 16px 2px;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none;
        }

        .quick-actions-strip .empty-message {
            color: #888;
            font-size: 0.9rem;
            padding: 12px;
        }

        /* Compact cards inside the toolbar (scoped so furniture panel is unaffected) */
        .quick-actions-strip .furniture-item {
            flex: 0 0 96px;
            height: 104px;
        }

        .quick-actions-strip .battle-item-effect-label {
            position: absolute;
            left: 0;
            right: 0;
            bottom: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 16px;
            padding: 2px 5px;
            border-radius: 4px;
            background: #2cae59b8;
            color: #e7ffe8;
            font-size: 10px;
            font-weight: 800;
            line-height: 1;
            text-shadow: 0 1px 2px #000;
            pointer-events: none;
            z-index: 2;
            margin-top: 10px;
       
        }

        .quick-actions-strip .item-header {
            height: 28px;
            padding: 2px 4px;
        }

        .quick-actions-strip .item-name {
            font-size: 8px;
            letter-spacing: 0.35px;
        }

        .quick-actions-strip .furniture-item img {
            height: 50px;
            margin-top: 4px;
        }

        .quick-actions-strip::-webkit-scrollbar {
            display: none;
        }

        .quick-actions-strip::-webkit-scrollbar-track {
            background: transparent;
        }

        .quick-actions-strip::-webkit-scrollbar-thumb {
            background: #444;
            border-radius: 4px;
        }

        .quick-actions-strip::-webkit-scrollbar-thumb:hover {
            background: var(--accent-color);
        }

        body.adventure-party-modal-open {
            overflow: hidden;
        }

        .adventure-party-modal[hidden] {
            display: none !important;
        }

        .adventure-party-modal {
            position: fixed;
            inset: 0;
            z-index: 3600;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 24px;
            background: rgba(0, 0, 0, 0.72);
            backdrop-filter: blur(10px);
        }

      .adventure-party-dialog {
    width: min(760px, 100%);
    /* 1. Change min-height to height to force it to use the full available space */
    height: min(calc(100vh - 48px), 100%); 
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px;
    border: 0px solid #3a3a3a;
    border-radius: 8px;
    background: rgba(22, 22, 22, 0.98);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.7);
}



        .adventure-party-header {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            padding: 0 0 12px 0;
            margin: 0;
            width: 100%;
            border-bottom: 1px solid #333;
        }

        .adventure-party-header h2 {
            margin: 0;
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 1.2rem;
        }

        .adventure-party-summary {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 16px;
            color: #d6d6d6;
            font-size: 0.9rem;
            padding: 0 2px;
        }

        /* The party modal's user header is populated by updateUserMiniCard()
           in adventureSessionManager.js before the companion cards render. */
        .user-mini-card-profile {
            display: flex;
            align-items: center;
            gap: 10px;
            min-width: 0;
        }

        .user-mini-card-avatar {
            width: 44px;
            height: 44px;
            flex: 0 0 44px;
            border: 2px solid #3c8f55;
            border-radius: 50%;
            object-fit: cover;
            background: #242424;
        }

        .user-mini-card-identity {
            display: flex;
            flex-direction: column;
            gap: 2px;
            min-width: 0;
        }

        #username-mini-card {
            overflow: hidden;
            color: #f2f2f2;
            font-size: 1rem;
            font-weight: 700;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        #waifu-drawer-list .waifu-nature-details {
            width: calc(100% - 16px);
            margin-top: 6px;
            color: #b9b5ff;
            font-size: 0.66rem;
            line-height: 1.3;
            text-align: center;
        }

        .recruitment-modal[hidden] {
            display: none;
        }

        .recruitment-modal {
            position: fixed;
            inset: 0;
            z-index: 12000;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
            background:
                radial-gradient(circle at 50% 35%, rgba(83, 55, 190, 0.18), transparent 36%),
                rgba(3, 3, 9, 0.88);
            backdrop-filter: blur(10px) saturate(0.65);
            animation: recruitment-backdrop-in 260ms ease-out both;
        }

        .recruitment-dialog {
            --recruitment-accent: #745cff;
            position: relative;
            isolation: isolate;
            width: min(440px, 100%);
            max-height: calc(100vh - 40px);
            overflow-x: hidden;
            overflow-y: auto;
            box-sizing: border-box;
            padding: 30px;
            border: 1px solid rgba(131, 105, 255, 0.8);
            border-radius: 20px;
            background: transparent;
            color: #fff;
            text-align: center;
            box-shadow:
                0 30px 100px rgba(0, 0, 0, 0.82),
                0 0 35px rgba(91, 63, 255, 0.16),
                inset 0 0 35px rgba(111, 82, 255, 0.06);
            animation: recruitment-dialog-in 420ms cubic-bezier(0.2, 0.85, 0.25, 1.15) both;
        }

        /* These layers provide the animated anime-style energy field without
           adding decorative elements to dungeon.html's accessible dialog. */
        .recruitment-dialog::before {
            content: "";
            position: absolute;
            z-index: -2;
            /* Negative inset made this decoration part of the dialog's scroll
               overflow, creating a large empty area below the real content. */
            inset: 0;
            pointer-events: none;
            background: conic-gradient(
                from 0deg,
                transparent 0 25%,
                rgba(113, 77, 255, 0.32) 31%,
                transparent 38% 61%,
                rgba(48, 189, 255, 0.22) 68%,
                transparent 75%
            );
            opacity: 0.34;
            transform: scale(1.8);
            animation: recruitment-energy-spin 12s linear infinite;
        }

        .recruitment-dialog::after {
            content: "";
            position: absolute;
            z-index: -1;
            inset: 1px;
            pointer-events: none;
            border-radius: 19px;
            background:
                linear-gradient(120deg, rgba(255, 255, 255, 0.035), transparent 28%),
                radial-gradient(circle at 50% 0, rgba(96, 69, 212, 0.18), transparent 36%),
                linear-gradient(165deg, #171721 0%, #0e0e16 58%, #15131d 100%);
        }

        .recruitment-dialog.is-pulling::before {
            opacity: 0.75;
            animation-duration: 2.2s;
        }

        .recruitment-close {
            position: absolute;
            top: 12px;
            right: 12px;
            z-index: 4;
            color: #aaa9bb;
            transition: color 160ms ease, transform 160ms ease, filter 160ms ease;
        }

        .recruitment-close:hover {
            color: #fff;
            filter: drop-shadow(0 0 7px var(--recruitment-accent));
            transform: rotate(90deg);
        }

        .recruitment-character-image {
            width: 104px;
            height: 104px;
            object-fit: cover;
            border: 3px solid #765eff;
            border-radius: 50%;
            background: #09090f;
            box-shadow:
                0 0 0 5px rgba(91, 68, 219, 0.18),
                0 0 26px rgba(111, 82, 255, 0.45);
            transition: filter 200ms ease, box-shadow 200ms ease;
        }

        .recruitment-dialog.is-pulling .recruitment-character-image {
            animation: recruitment-portrait-charge 900ms ease-in-out infinite alternate;
        }

        .recruitment-dialog h2 {
            margin: 16px 0 4px;
            font-size: 1.62rem;
            letter-spacing: 0.025em;
            text-shadow:
                0 2px 0 #08080c,
                0 0 18px rgba(255, 255, 255, 0.12);
        }

        .recruitment-character-name {
            margin: 0;
            color: #c9c0ff;
            font-weight: 700;
            text-shadow: 0 0 14px rgba(128, 95, 255, 0.38);
        }

        .recruitment-explanation {
            max-width: 350px;
            margin: 4px auto 0;
            color: #a7a6b2;
            line-height: 1.45;
        }

        .recruitment-quote {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin: 20px 0 9px;
        }

        .recruitment-quote span {
            position: relative;
            overflow: hidden;
            padding: 11px;
            border: 1px solid rgba(132, 122, 176, 0.14);
            border-radius: 12px;
            background: linear-gradient(145deg, rgba(43, 42, 57, 0.96), rgba(29, 29, 40, 0.96));
            color: #aaa9b4;
            font-size: 0.8rem;
            box-shadow: inset 0 1px rgba(255, 255, 255, 0.025);
        }

        .recruitment-quote strong {
            display: block;
            margin-top: 3px;
            color: #fff;
            font-size: 1.08rem;
            text-shadow: 0 0 12px rgba(255, 255, 255, 0.16);
        }

        .recruitment-status {
            min-height: 1.2em;
            margin: 7px 0;
            color: #f6c85e;
            font-size: 0.82rem;
            letter-spacing: 0.015em;
            text-shadow: 0 0 12px rgba(246, 200, 94, 0.28);
        }

        .recruitment-dialog.is-pulling .recruitment-status {
            animation: recruitment-status-pulse 800ms ease-in-out infinite alternate;
        }

        .recruitment-result {
            --nature-accent: #8b5cf6;
            position: relative;
            isolation: isolate;
            overflow: hidden;
            margin-top: 14px;
            padding: 17px 18px;
            border: 1px solid var(--nature-accent);
            border-radius: 15px;
            background:
                radial-gradient(circle at 50% -30%, color-mix(in srgb, var(--nature-accent) 26%, transparent), transparent 54%),
                linear-gradient(145deg, #22212c, #15151d);
            text-align: left;
            box-shadow:
                0 0 24px color-mix(in srgb, var(--nature-accent) 20%, transparent),
                inset 0 0 28px rgba(0, 0, 0, 0.26);
            transition: border-color 100ms linear, box-shadow 100ms linear;
        }

        .recruitment-result::before,
        .recruitment-result::after {
            content: "";
            position: absolute;
            z-index: -1;
            pointer-events: none;
        }

        .recruitment-result::before {
            inset: 0;
            background: linear-gradient(
                110deg,
                transparent 12%,
                color-mix(in srgb, var(--nature-accent) 16%, transparent) 48%,
                transparent 72%
            );
            transform: translateX(-120%);
        }

        .recruitment-result.is-rolling::before {
            animation: recruitment-card-scan 700ms linear infinite;
        }

        .recruitment-result::after {
            inset: 5px;
            border: 1px solid color-mix(in srgb, var(--nature-accent) 18%, transparent);
            border-radius: 10px;
        }

        .recruitment-result-aura {
            position: absolute;
            z-index: -1;
            top: -80px;
            left: 50%;
            width: 210px;
            height: 210px;
            border: 1px solid color-mix(in srgb, var(--nature-accent) 45%, transparent);
            border-radius: 42%;
            opacity: 0.35;
            filter: blur(1px);
            transform: translateX(-50%) rotate(0deg);
        }

        .recruitment-result.is-rolling .recruitment-result-aura {
            animation: recruitment-aura-spin 1.6s linear infinite;
        }

        .recruitment-roll-window {
            min-height: 75px;
            display: flex;
            align-items: center;
            overflow: hidden;
            text-align: center;
        }

        .recruitment-roll-value {
            width: 100%;
            will-change: transform, opacity, filter;
        }

        .recruitment-roll-value.is-ticking {
            animation: recruitment-nature-roll-up 210ms cubic-bezier(0.2, 0.75, 0.25, 1) both;
        }

        .recruitment-result-rarity {
            display: inline-block;
            padding: 3px 8px;
            border: 1px solid rgba(177, 176, 194, 0.2);
            border-radius: 999px;
            color: #9998a8;
            background: rgba(5, 5, 10, 0.34);
            font-size: 0.65rem;
            font-weight: 800;
            letter-spacing: 0.12em;
            text-transform: uppercase;
        }

        #recruitment-result-name {
            margin: 5px 0 0;
            color: var(--nature-accent);
            font-size: 1.85rem;
            letter-spacing: 0.025em;
            line-height: 1.05;
            text-align: center;
            text-shadow:
                0 0 10px color-mix(in srgb, var(--nature-accent) 70%, transparent),
                0 0 24px color-mix(in srgb, var(--nature-accent) 30%, transparent);
            filter: saturate(1.15);
        }

        .recruitment-result.is-settled #recruitment-result-name {
            animation: recruitment-nature-settle 650ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
        }

        .recruitment-result-details {
            max-height: 0;
            overflow: hidden;
            opacity: 0;
            transform: translateY(12px);
        }

        .recruitment-result.is-details-visible .recruitment-result-details {
            max-height: 300px;
            animation: recruitment-details-in 520ms ease-out both;
        }

        .recruitment-result p,
        .recruitment-result ul {
            margin: 7px 0 0;
            color: #c9c8d2;
            font-size: 0.82rem;
            line-height: 1.4;
        }

        .recruitment-result p {
            padding-top: 11px;
            border-top: 1px solid color-mix(in srgb, var(--nature-accent) 22%, transparent);
        }

        .recruitment-result ul {
            padding-left: 18px;
        }

        .recruitment-result li::marker {
            color: var(--nature-accent);
        }

        .recruitment-actions {
            display: flex;
            gap: 10px;
            margin-top: 20px;
        }

        /* The display:flex rule above otherwise overrides the browser's native
           hidden attribute after waifuDrawer.js receives recruitment success. */
        .recruitment-actions[hidden] {
            display: none;
        }

        .recruitment-actions button {
            flex: 1;
            border: 1px solid rgba(255, 255, 255, 0.06);
            border-radius: 11px;
            padding: 11px 12px;
            color: #fff;
            background: linear-gradient(145deg, #393846, #292833);
            font-weight: 700;
            cursor: pointer;
            box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
            transition: transform 150ms ease, filter 150ms ease, box-shadow 150ms ease;
        }

        .recruitment-actions button:not(:disabled):hover {
            filter: brightness(1.13);
            transform: translateY(-2px);
        }

        .recruitment-actions button:not(:disabled):active {
            transform: translateY(0) scale(0.98);
        }

        #recruitment-confirm {
            border-color: rgba(145, 119, 255, 0.34);
            background: linear-gradient(135deg, #4930c8, #7250ec 55%, #3c2aaa);
            box-shadow:
                0 9px 24px rgba(73, 48, 200, 0.32),
                inset 0 1px rgba(255, 255, 255, 0.12);
        }

        .recruitment-actions button:disabled {
            opacity: 0.45;
            cursor: not-allowed;
        }

        @keyframes recruitment-backdrop-in {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        @keyframes recruitment-dialog-in {
            from { opacity: 0; transform: translateY(18px) scale(0.94); }
            to { opacity: 1; transform: translateY(0) scale(1); }
        }

        @keyframes recruitment-energy-spin {
            from { transform: scale(1.8) rotate(0deg); }
            to { transform: scale(1.8) rotate(360deg); }
        }

        @keyframes recruitment-portrait-charge {
            from {
                filter: brightness(1) saturate(1);
                box-shadow: 0 0 0 5px rgba(91, 68, 219, 0.18), 0 0 18px rgba(111, 82, 255, 0.4);
            }
            to {
                filter: brightness(1.15) saturate(1.3);
                box-shadow: 0 0 0 7px rgba(91, 68, 219, 0.12), 0 0 38px rgba(111, 82, 255, 0.85);
            }
        }

        @keyframes recruitment-status-pulse {
            from { opacity: 0.58; }
            to { opacity: 1; text-shadow: 0 0 18px rgba(246, 200, 94, 0.65); }
        }

        @keyframes recruitment-card-scan {
            to { transform: translateX(120%); }
        }

        @keyframes recruitment-aura-spin {
            from { transform: translateX(-50%) rotate(0deg) scale(0.88); }
            50% { transform: translateX(-50%) rotate(180deg) scale(1.08); }
            to { transform: translateX(-50%) rotate(360deg) scale(0.88); }
        }

        @keyframes recruitment-nature-roll-up {
            0% { opacity: 0; transform: translateY(42px) scale(0.92); filter: blur(5px); }
            45% { opacity: 1; filter: blur(0); }
            100% { opacity: 0.88; transform: translateY(-7px) scale(1); filter: blur(0); }
        }

        @keyframes recruitment-nature-settle {
            0% { opacity: 0; transform: scale(1.35); filter: blur(4px) brightness(2); }
            55% { opacity: 1; transform: scale(0.96); filter: blur(0) brightness(1.4); }
            100% { opacity: 1; transform: scale(1); filter: blur(0) brightness(1); }
        }

        @keyframes recruitment-details-in {
            from { opacity: 0; transform: translateY(12px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @media (max-width: 520px) {
            .recruitment-modal {
                padding: 12px;
            }

            .recruitment-dialog {
                max-height: calc(100vh - 24px);
                padding: 25px 18px 20px;
            }

            .recruitment-character-image {
                width: 88px;
                height: 88px;
            }

            #recruitment-result-name {
                font-size: 1.58rem;
            }
        }

        @media (prefers-reduced-motion: reduce) {
            .recruitment-modal,
            .recruitment-dialog,
            .recruitment-dialog::before,
            .recruitment-dialog.is-pulling .recruitment-character-image,
            .recruitment-dialog.is-pulling .recruitment-status,
            .recruitment-result.is-settled #recruitment-result-name {
                animation: none;
            }

            /* Keep the required recruitment reel visible, but remove blur and
               scaling for players whose operating system reduces motion. */
            .recruitment-roll-value.is-ticking {
                animation-name: recruitment-nature-roll-up-reduced;
            }
        }

        @keyframes recruitment-nature-roll-up-reduced {
            from { opacity: 0; transform: translateY(12px); }
            to { opacity: 1; transform: translateY(0); }
        }

        #userlevel-mini-card {
            color: #999;
            font-size: 0.78rem;
            font-weight: 600;
        }

        #adventure-party-count {
            flex: 0 0 auto;
            font-weight: 700;
        }

       .adventure-party-list {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
    
    /* 2. Tell the list to take up all remaining vertical space */
    flex-grow: 1; 
    
    /* 3. Remove or comment out the hardcoded max-height */
    /* max-height: 460px; */ 
    
    width: 100%;
    max-width: none;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

        .adventure-party-card {
            width: 100%;
            cursor: default;
        }

        /* Keeps both adventure-card actions grouped against the card's right edge. */
        .adventure-party-card .quest-waifu-action-row {
            justify-content: flex-end;
            gap: 5px;
        }

        /* The shared button style uses auto margins; adventure-card buttons must stay together. */
        .adventure-party-card .quest-waifu-action-row .quest-waifu-send-pill {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 4px;
            margin-left: 0;
        }

        .adventure-party-card .quest-waifu-action-row .quest-waifu-send-pill i {
            display: block;
            line-height: 1;
        }

        .adventure-party-card-heading {
            display: flex;
            align-items: center;
            gap: 8px;
            width: 100%;
            min-width: 0;
            font-size: 15px;
        
        }

        .adventure-party-card-heading .waifu-drawer-level-badge {
            flex: 0 0 auto;
            margin: 0;
        }

        .adventure-party-card-heading .waifu-card-name {
            flex: 1 1 auto;
            min-width: 0;
            white-space: normal;
            overflow: visible;
            text-overflow: clip;
            text-align: left;
        }

        .adventure-party-card-nature-level {
            white-space: normal;
            display: inline-block;
        }

        .adventure-party-stat-bars {
            display: flex;
            flex-direction: column;
            gap: 5px;
            width: 100%;
            max-width: 99%;
            margin: 7px 0 8px 0;
        }

        .adventure-party-stat-row {
            display: grid;
            grid-template-columns: 24px minmax(80px, 1fr);
            align-items: center;
            gap: 7px;
            width: 100%;
            min-width: 0;
            color: #d1d5db;
            font-size: 0.7rem;
            line-height: 1;
        }

        .adventure-party-stat-label,
        .adventure-party-stat-value {
            white-space: nowrap;
        }

        .adventure-party-stat-label {
            font-weight: 800;
            color: #a7a7a7;
        }

        .adventure-party-stat-value {
            font-size: 15px;
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: flex-end;
            padding: 0 8px;
            font-variant-numeric: tabular-nums;
            color: #ffffff;
            pointer-events: none;
            z-index: 1;
        }

        .adventure-party-stat-track {
            position: relative;
            width: 100%;
            height: 16px;
            overflow: hidden;
            border-radius: 999px;
            background: #4b5563;
        }

        .adventure-party-stat-fill {
            height: 100%;
            min-width: 0;
            border-radius: inherit;
        }

        .adventure-party-stat-fill-hp {
            background: #be2f2f;
        }

        .adventure-party-stat-fill-mp {
            background: var(--accent-color);
        }

        .adventure-party-list .adventure-party-stat-fill-xp {
            background: var(--mint);
        }

        .adventure-battle-party-status {
            position: fixed;
            left: 50%;
            bottom: max(10px, env(safe-area-inset-bottom));
            z-index: 950;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
            gap: 7px;
            width: min(720px, calc(100vw - 18px));
            padding: 7px;
            border-radius: 8px;
            transform: translateX(-50%);
            pointer-events: none;
        }

        .adventure-battle-party-status.holding-item {
            pointer-events: auto;
        }

        .adventure-battle-party-status[hidden] {
            display: none;
        }

        .adventure-battle-party-status-card {
            display: grid;
            grid-template-columns: 36px minmax(0, 1fr);
            align-items: center;
            gap: 7px;
            min-width: 0;
            padding: 6px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 6px;
            background: rgba(24, 24, 27, 0.9);
            position: relative;
            overflow: visible;
            pointer-events: auto;
            cursor: pointer;
        }

        .adventure-battle-party-status-card.active-target {
            border-color: rgba(34, 197, 94, 0.88);
            box-shadow:
                0 0 0 1px rgba(34, 197, 94, 0.45),
                0 0 18px rgba(34, 197, 94, 0.24);
        }

        .adventure-battle-party-status.holding-item .adventure-battle-party-status-card {
            cursor: pointer;
        }

        .adventure-battle-holding-item-prompt {
            position: absolute;
            left: 0;
            top: -34px;
            display: flex;
            align-items: center;
            gap: 7px;
            max-width: min(270px, calc(100vw - 24px));
            padding: 6px 8px;
            border: 1px solid rgba(255, 255, 255, 0.16);
            border-radius: 6px;
            background: rgba(12, 12, 14, 0.94);
            color: #f4f4f5;
            font-size: 12px;
            font-weight: 700;
            line-height: 1;
            white-space: nowrap;
            box-shadow: 0 8px 18px rgba(0, 0, 0, 0.36);
            z-index: 4;
        }

        .adventure-battle-holding-item-prompt span {
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .adventure-battle-holding-item-cancel {
            width: 18px;
            height: 18px;
            flex: 0 0 18px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0;
            border: 0;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.12);
            color: #f4f4f5;
            cursor: pointer;
        }

        .adventure-battle-party-status-card.level-up {
            animation: spellCardLevelUpPulse 0.9s ease-out;
        }

        .adventure-battle-party-status-card.level-up::before,
        .adventure-battle-party-status-card.level-up::after {
            content: '';
            position: absolute;
            left: 50%;
            bottom: 8px;
            width: 82%;
            height: 18px;
            border: 2px solid rgba(34, 197, 94, 0.72);
            border-top-color: rgba(187, 247, 208, 0.95);
            border-bottom-color: rgba(22, 163, 74, 0.62);
            border-radius: 50%;
            box-shadow:
                0 0 14px rgba(34, 197, 94, 0.42),
                inset 0 0 10px rgba(34, 197, 94, 0.14);
            pointer-events: none;
            opacity: 0;
            transform: translate(-50%, 18px) scale(0.28);
            animation: adventureBattleHudLevelUpRipple 0.86s cubic-bezier(0.2, 0.9, 0.2, 1) forwards;
        }

        .adventure-battle-party-status-card.level-up::after {
            animation-delay: 0.16s;
        }

        .adventure-battle-party-status-card.defeated .adventure-battle-party-status-avatar {
            filter: grayscale(1);
            opacity: 0.62;
        }

        .adventure-battle-party-status-avatar {
            width: 36px;
            height: 36px;
            border-radius: 6px;
            object-fit: cover;
            background: #27272a;
        }

        .adventure-battle-party-status-details {
            min-width: 0;
            /* Positioning context so the level-up floater can be placed
               absolutely inside this panel and float upward out of it. */
            position: relative;
            overflow: visible;
        }

        /* Floating "Lvl Up!" label that rises above the character's HUD card.
           Spawned by showLevelUpFloater() in adventurePartyAutoExplore.js
           when the 'adventure-character-level-ups' event fires. */
        .adventure-hud-level-up-floater {
            position: absolute;
            /* Sit just above the details panel and centered horizontally. */
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            /* Ensure it renders on top of adjacent cards. */
            z-index: 10;
            pointer-events: none;
            white-space: nowrap;
            font-size: 0.72rem;
            font-weight: 900;
            letter-spacing: 0.04em;
            color: #86efac;           /* green-300 – matches the existing level-up ring colour */
            text-shadow:
                0 0 8px rgba(34, 197, 94, 0.85),
                0 1px 3px rgba(0, 0, 0, 0.7);
            animation: adventureHudLevelUpFloat 1.2s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
        }

        @keyframes adventureHudLevelUpFloat {
            0%   { opacity: 0;    transform: translateX(-50%) translateY(4px)  scale(0.7); }
            18%  { opacity: 1;    transform: translateX(-50%) translateY(0px)  scale(1.1); }
            45%  { opacity: 1;    transform: translateX(-50%) translateY(-8px) scale(1);   }
            100% { opacity: 0;    transform: translateX(-50%) translateY(-28px) scale(0.9); }
        }

        .adventure-battle-party-status-name-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 6px;
            margin-bottom: 4px;
            min-width: 0;
            line-height: 1;
        }

        .adventure-battle-party-status-name-group {
            display: flex;
            align-items: center;
            gap: 4px;
            min-width: 0;
        }

        .adventure-battle-party-status-name {
            min-width: 0;
            overflow: hidden;
            color: #f3f4f6;
            font-size: 0.68rem;
            font-weight: 800;
            line-height: 1;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .adventure-battle-party-status-level {
            flex: 0 0 auto;
            color: #e5e7eb;
            font-size: 0.58rem;
            font-weight: 800;
            line-height: 1;
            white-space: nowrap;
        }

        .adventure-battle-party-status .adventure-party-stat-bars {
            gap: 3px;
            margin: 0;
        }

        .adventure-battle-party-status .adventure-party-stat-row {
            grid-template-columns: 18px minmax(34px, 1fr) 44px;
            gap: 4px;
            font-size: 0.58rem;
        }

        .adventure-battle-party-status .adventure-party-stat-track {
            height: 6px;
        }

        .adventure-battle-party-status .adventure-party-stat-value {
            position: static;
            inset: auto;
            display: block;
            padding: 0;
            text-align: right;
            color: #e5e7eb;
            font-size: 8px;
        }

        .adventure-battle-party-status-nature {
            font-size: 9px;
        }

        .adventure-party-spell-label {
            display: block;
            margin: 0 0 5px;
            color: #8f8f92;
            font-size: 10px;
            font-weight: 600;
            line-height: 1;
        }

        .adventure-party-spell-list {
            display: flex;
            flex-flow: row wrap;
            align-items: center;
            justify-content: flex-start;
            gap: 5px;
            width: 100%;
            margin: 0 0 8px 0;
            overflow: visible;
        }

        .adventure-party-spell-list.empty {
            display: flex;
            align-items: center;
            gap: 7px;
            min-height: 24px;
        }

        .adventure-party-spell-pill {
            min-width: 0;
            border-radius: 999px;
            padding: 8px 10px;
            background: #4d4d4e17;
            border: 1px solid rgb(188 188 188 / 12%);
            color: #d4d4d8;
            font-size: 10px;
            line-height: 1;
            text-align: center;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: fit-content;
        }

        .adventure-party-spell-pill.spell-element-nature {
            color: var(--mint);
        }

        .adventure-party-spell-pill.spell-element-fire {
            background: #ef4444;
            color: #fff1f2;
        }

        .adventure-party-spell-pill.spell-element-water {
            background: #38bdf8;
            color: #eff8ff;
        }

        .adventure-party-spell-pill.spell-element-lightning {
            background: #facc15;
            color: #1f2937;
        }

        .adventure-party-spell-pill.spell-element-ice {
            background: #a5f3fc;
            color: #0f172a;
        }

        .adventure-party-spell-pill.spell-element-void {
            background: #8b5cf6;
            color: #ede9fe;
        }

        .adventure-party-no-spells-text {
            color: #9ca3af;
            font-size: 0.7rem;
            line-height: 1;
        }

        .adventure-party-open-spells-pill {
            border: 1px solid #4f46e5;
            border-radius: 999px;
            padding: 4px 8px;
            background: rgba(79, 70, 229, 0.18);
            color: #dbeafe;
            font-size: 0.68rem;
            line-height: 1;
            cursor: pointer;
            white-space: nowrap;
        }

        .spell-upgrade-requirements {
            border: 0px solid #4f46e5;
            border-radius: 999px;
            margin-top: 5px;
            margin-bottom: 5px;
            padding: 4px 8px;
            background: rgba(98, 91, 220, 0.18);
            color: #dbeafe;
            font-size: 0.68rem;
            line-height: 1;
            cursor: pointer;
            white-space: nowrap;
        }

        .adventure-party-open-spells-pill:hover {
            background: rgba(79, 70, 229, 0.32);
        }

        .adventure-party-card.selected {
            border-color: #236e3e;
        }

        @media (max-width: 700px) {
            .adventure-battle-party-status {
                grid-template-columns: repeat(2, minmax(0, 1fr));
                width: calc(100vw - 12px);
                gap: 5px;
                padding: 5px;
            }

            .adventure-battle-party-status-card {
                grid-template-columns: 32px minmax(0, 1fr);
                gap: 5px;
                padding: 5px;
            }

            .adventure-battle-party-status-avatar {
                width: 32px;
                height: 32px;
            }

            .adventure-battle-party-status-name {
                font-size: 0.62rem;
            }

            .adventure-battle-party-status-level {
                font-size: 0.54rem;
            }

            .adventure-battle-party-status .adventure-party-stat-row {
                grid-template-columns: 17px minmax(28px, 1fr) 39px;
                gap: 3px;
                font-size: 0.54rem;
            }
        }

        .adventure-party-card.selected:hover {
            border-color: #22c55e;
        }

        .adventure-party-toggle:disabled {
            cursor: not-allowed;
            opacity: 0.55;
            filter: grayscale(1);
        }

        .adventure-party-toggle-dismiss {
            background: color-mix(in srgb, var(--accent-color) 58%, #252525);
        }

        .adventure-party-empty {
            width: 100%;
            color: #888;
            text-align: center;
            padding: 24px 0;
        }

        .adventure-party-actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
            padding-top: 4px;
        }

        .adventure-party-start {
            border: 0;
            border-radius: 8px;
            padding: 14px 22px;
            background: var(--mint);
            color: #fff;
            font-size: 1rem;
            font-weight: 800;
            cursor: pointer;
            font-family: inherit;
        }

        .adventure-party-start:hover {
            background: #22c55e;
        }

        .adventure-party-start:disabled,
        .adventure-party-start:disabled:hover {
            cursor: not-allowed;
            opacity: 0.55;
            filter: grayscale(1);
            background: #16a34a;
        }

        .adventure-summary-overlay {
            position: fixed;
            inset: 0;
            z-index: 100001;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100dvh;
            padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
            background: rgba(0, 0, 0, 0.92);
            color: var(--text-color);
        }

        .adventure-summary-modal {
            width: min(520px, 100%);
            max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
            min-height: 0;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            background: var(--bg-color);
            box-shadow: 0 0 28px rgba(0, 0, 0, 0.5);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .adventure-summary-header {
            position: relative;
            flex: 0 0 auto;
            padding: 18px 48px 12px 16px;
            border-bottom: 1px solid var(--border-color);
        }

        .adventure-summary-header h2 {
            margin: 0 0 5px;
            font-size: 1.35rem;
            line-height: 1.1;
            font-weight: 800;
            letter-spacing: 0;
        }

        .adventure-summary-header p {
            margin: 0;
            color: color-mix(in srgb, var(--text-color) 72%, transparent);
            font-size: 0.82rem;
            line-height: 1.35;
        }

        .adventure-summary-close {
            position: absolute;
            top: 12px;
            right: 12px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 30px;
            height: 30px;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            background: var(--sidebar-bg);
            color: var(--text-color);
            cursor: pointer;
        }

        .adventure-summary-close:hover,
        .adventure-summary-close:focus-visible {
            background: var(--foreground-color);
            outline: 0;
        }

        .adventure-summary-content {
            min-height: 0;
            display: flex;
            flex: 1 1 auto;
            flex-direction: column;
            gap: 12px;
            overflow-y: auto;
            padding: 12px;
        }

        .adventure-summary-stats {
            display: grid;
            /* adventureSummaryModal.js renders three run totals here. Keep them
               in one compact row so the detailed level-up list stays visible. */
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 8px;
            padding: 0;
            border-radius: 6px;
        }

        .adventure-summary-stat {
            min-width: 0;
            padding: 8px;
            background: var(--sidebar-bg);
            border: 1px solid var(--border-color);
            border-radius: 6px;
        }

        .adventure-summary-stat strong {
            display: block;
            color: #86efac;
            font-size: 1.25rem;
            line-height: 1.1;
            font-weight: 800;
            overflow-wrap: anywhere;
        }

        .adventure-summary-stat span {
            display: block;
            margin-top: 4px;
            color: color-mix(in srgb, var(--text-color) 72%, transparent);
            font-size: 0.68rem;
            line-height: 1.2;
            text-transform: uppercase;
        }

        .adventure-summary-section {
            min-height: 0;
            flex: 0 0 auto;
            display: flex;
            flex-direction: column;
            padding: 0;
        }

        .adventure-summary-section h3 {
            margin: 4px 0 8px;
            font-size: 0.86rem;
            line-height: 1.2;
            color: var(--text-color);
            text-transform: uppercase;
        }

        .adventure-summary-level-up-list,
        .adventure-summary-loot-list {
            min-height: 0;
            max-height: min(30dvh, 260px);
            overflow-y: auto;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            background: var(--sidebar-bg);
        }

        .adventure-summary-level-up-list {
            display: flex;
            flex-direction: column;
            gap: 8px;
            padding: 8px;
        }

        .adventure-summary-level-up-card.quest-waifu-card.waifu-drawer-card {
            width: 100%;
            height: auto;
            min-height: 86px;
            flex: 0 0 auto;
            display: grid;
            grid-template-columns: 58px minmax(0, 1fr);
            align-items: center;
            gap: 10px;
            padding: 10px;
            border: 1px solid var(--border-color);
            background: var(--foreground-color);
            cursor: default;
        }

        .adventure-summary-level-up-card.quest-waifu-card.waifu-drawer-card img {
            width: 48px;
            height: 48px;
            margin: 0;
            border-radius: 50%;
            border: 2px solid var(--border-color);
            object-fit: cover;
        }

        .adventure-summary-level-up-details {
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 6px;
        }

        .adventure-summary-level-up-heading {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            min-width: 0;
        }

        .adventure-summary-level-up-heading .waifu-card-name {
            margin: 0;
            padding: 0;
            max-width: none;
            text-align: left;
        }

        .adventure-summary-level-up-badge {
            flex: 0 0 auto;
            color: #facc15;
            font-size: 0.72rem;
            font-weight: 800;
            white-space: nowrap;
        }

        .adventure-summary-level-up-level {
            color: color-mix(in srgb, var(--text-color) 72%, transparent);
            font-size: 0.72rem;
            font-weight: 700;
            line-height: 1;
        }

        .adventure-summary-level-up-card .adventure-party-stat-row {
            grid-template-columns: 24px minmax(70px, 1fr) 58px;
            margin: 0;
        }

        .adventure-summary-level-up-card .adventure-party-stat-fill-xp {
            background: #22c55e;
        }

        .adventure-summary-loot-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            min-height: 38px;
            padding: 8px 10px;
            border-bottom: 1px solid var(--border-color);
            font-size: 0.86rem;
            line-height: 1.2;
        }

        .adventure-summary-loot-row span {
            min-width: 0;
            overflow-wrap: anywhere;
        }

        .adventure-summary-loot-row strong {
            flex: 0 0 auto;
            color: #86efac;
        }

        .adventure-summary-empty {
            margin: 0;
            padding: 16px 10px;
            color: color-mix(in srgb, var(--text-color) 72%, transparent);
            font-size: 0.86rem;
            line-height: 1.35;
        }



           /* Mobile specific 'small menu icon only' look */
        @media (max-width: 768px) {

            #adventure-party-modal {
                min-width: 100vw;
                border-radius: 0px;
                border: 0px;
                margin: 0px;
                padding: 0px;
                max-height: 100dvh;
            }

            .adventure-party-dialog {
                    min-width: 100vw;
                border-radius: 0px;
                border: 0px;
                margin: 0px;
                padding: 4px;
                height: 100vh;
                max-height: 100dvh;
            }

            .adventure-summary-overlay {
                align-items: stretch;
                padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
            }

            .adventure-summary-modal {
                width: 100vw;
                max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
                border-radius: 0;
            }

            .adventure-summary-level-up-list,
            .adventure-summary-loot-list {
                max-height: 24dvh;
            }
        }

        /* Procedural Dungeon Generation Loading Screen */
        @keyframes loading-pulse {
            0%, 100% {
                transform: scale(1);
                opacity: 0.8;
                box-shadow: 0 0 20px rgba(0, 255, 136, 0.4), inset 0 0 15px rgba(0, 255, 136, 0.2);
            }
            50% {
                transform: scale(1.08);
                opacity: 1;
                box-shadow: 0 0 35px rgba(0, 255, 136, 0.7), inset 0 0 25px rgba(0, 255, 136, 0.4);
            }
        }

        @keyframes loading-cube {
            0% {
                transform: rotate(0deg) scale(1);
            }
            50% {
                transform: rotate(180deg) scale(0.8);
                border-radius: 50%;
            }
            100% {
                transform: rotate(360deg) scale(1);
            }
        }

        @keyframes loading-text-fade {
            0%, 100% {
                opacity: 0.5;
                letter-spacing: 0.12em;
            }
            50% {
                opacity: 1;
                letter-spacing: 0.18em;
                color: #00ff88;
                text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
            }
        }

        #dungeon-loading-overlay {
            position: fixed;
            left: 50%;
            transform: translateX(-50%);
            bottom: calc(max(10px, env(safe-area-inset-bottom)) + 90px);
            z-index: 100000;
            display: none;
            flex-direction: row;
            align-items: center;
            color: #ffffff;
            font-family: 'Inter', sans-serif;
            opacity: 0;
            transition: opacity 0.5s ease-in-out;
            pointer-events: none;
            
            background: rgba(10, 10, 12, 0.85);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(0, 255, 136, 0.25);
            border-radius: 8px;
            padding: 8px 16px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 0 0 15px rgba(0, 255, 136, 0.1);
            gap: 12px;
            max-width: calc(100vw - 24px);
        }

        @media (max-width: 700px) {
            #dungeon-loading-overlay {
                bottom: calc(max(10px, env(safe-area-inset-bottom)) + 145px);
            }
        }

        .dungeon-loading-icon-container {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: radial-gradient(circle, rgba(0,255,136,0.15) 0%, rgba(0,0,0,0) 70%);
            border: 2px solid #00ff88;
            animation: loading-pulse 2s infinite ease-in-out;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }

        .dungeon-loading-icon-inner {
            width: 10px;
            height: 10px;
            border-radius: 2px;
            background: #00ff88;
            box-shadow: 0 0 8px #00ff88;
            animation: loading-cube 2s infinite ease-in-out;
        }

        .dungeon-loading-text-container {
            display: flex;
            flex-direction: column;
            justify-content: center;
            min-width: 0;
        }

        .dungeon-loading-title {
            font-size: 0.95rem;
            font-weight: 600;
            margin: 0;
            color: #ffffff;
            letter-spacing: -0.01em;
            text-shadow: 0 0 10px rgba(0, 255, 136, 0.2);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .dungeon-loading-subtitle {
            font-size: 0.7rem;
            color: #a0aec0;
            margin: 0;
            font-weight: 600;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            animation: loading-text-fade 1.5s infinite ease-in-out;
            white-space: nowrap;
        }

        /* Level Cleared / Max Level Reached Banner styles */
        .clear-banner-container {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%) scale(0.8);
            z-index: 1000000;
            pointer-events: none;
            opacity: 0;
            transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }

        .clear-banner-container.show {
            opacity: 1;
            transform: translate(-50%, -50%) scale(1);
            pointer-events: auto;
        }

        .clear-banner-card {
            background: rgba(18, 10, 28, 0.85);
            border: 2px solid rgba(0, 255, 136, 0.4);
            box-shadow: 0 8px 32px 0 rgba(0, 255, 136, 0.25), 
                        inset 0 0 20px rgba(0, 255, 136, 0.15);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border-radius: 24px;
            padding: 35px 60px;
            text-align: center;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 18px;
            position: relative;
            overflow: hidden;
            animation: bannerPulse 3s infinite alternate ease-in-out;
        }

        .clear-banner-card.max-level {
            border-color: rgba(234, 179, 8, 0.5);
            box-shadow: 0 8px 32px 0 rgba(234, 179, 8, 0.3), 
                        inset 0 0 20px rgba(234, 179, 8, 0.2);
        }

        @keyframes bannerPulse {
            0% { box-shadow: 0 8px 32px 0 rgba(0, 255, 136, 0.25); }
            100% { box-shadow: 0 12px 40px 10px rgba(0, 255, 136, 0.45); }
        }

        .clear-banner-card.max-level {
            animation: bannerPulseMax 3s infinite alternate ease-in-out;
        }

        @keyframes bannerPulseMax {
            0% { box-shadow: 0 8px 32px 0 rgba(234, 179, 8, 0.3); }
            100% { box-shadow: 0 12px 40px 10px rgba(234, 179, 8, 0.5); }
        }

        .clear-banner-glow {
            position: absolute;
            width: 200px;
            height: 200px;
            background: radial-gradient(circle, rgba(0, 255, 136, 0.3) 0%, rgba(0, 0, 0, 0) 70%);
            top: -70px;
            left: -70px;
            pointer-events: none;
            mix-blend-mode: screen;
        }

        .clear-banner-card.max-level .clear-banner-glow {
            background: radial-gradient(circle, rgba(234, 179, 8, 0.4) 0%, rgba(0, 0, 0, 0) 70%);
        }

        .clear-banner-badge {
            background: linear-gradient(135deg, #00ff88 0%, #00b0ff 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-size: 14px;
            font-weight: 800;
            letter-spacing: 4px;
            text-transform: uppercase;
            margin-bottom: 2px;
        }

        .clear-banner-card.max-level .clear-banner-badge {
            background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .clear-banner-title {
            font-size: 34px;
            font-weight: 800;
            color: #ffffff;
            margin: 0;
            text-shadow: 0 0 15px rgba(255, 255, 255, 0.35);
            letter-spacing: 0.5px;
        }

        .clear-banner-card.max-level .clear-banner-title {
            color: #fef08a;
            text-shadow: 0 0 20px rgba(234, 179, 8, 0.6);
        }

        .clear-banner-subtitle {
            font-size: 16px;
            color: #94a3b8;
            margin: 0;
            max-width: 340px;
            line-height: 1.5;
        }

        .clear-banner-btn {
            margin-top: 12px;
            background: linear-gradient(135deg, #00ff88 0%, #00b0ff 100%);
            border: none;
            border-radius: 12px;
            color: #022c22;
            font-weight: 800;
            padding: 12px 34px;
            font-size: 16px;
            cursor: pointer;
            box-shadow: 0 4px 15px rgba(0, 255, 136, 0.3);
            transition: all 0.2s ease;
            pointer-events: auto;
        }

        .clear-banner-card.max-level .clear-banner-btn {
            background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
            color: #1e1b4b;
            box-shadow: 0 4px 15px rgba(234, 179, 8, 0.4);
        }

        .clear-banner-btn:hover {
            transform: translateY(-2px) scale(1.04);
            filter: brightness(1.15);
        }

        .clear-banner-btn:active {
            transform: translateY(1px);
        }

        /* ===== Chat Panel (companion iframe) ===== */
        #chat-panel {
            position: fixed;
            top: 60px;
            left: var(--current-sidebar-width);
            width: calc(100vw - var(--current-sidebar-width));
            height: calc(100vh - 60px);
            z-index: 1500;
            display: none;
            flex-direction: column;
            background: rgba(15, 15, 20, 0.98);
            padding: 0px;
            box-sizing: border-box;
            overflow: hidden;
        }
        #chat-panel iframe {
            width: 100%;
            flex: 1;
            border: none;
            border-radius: 8px;
            background: #111;
        }

        /* ===== Floating Tavern Chat Input Overlay ===== */
        #tavern-chat-overlay {
            position: absolute;
            bottom: 24px;
            left: 50%;
            transform: translateX(-50%);
            z-index: 100;
            display: flex;
            align-items: center;
            gap: 8px;
            background: rgba(15, 15, 20, 0.78);
            backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.08);
            border-radius: 999px;
            padding: 6px 12px 6px 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 1px rgba(255, 255, 255, 0.2);
            width: min(450px, 90vw);
            box-sizing: border-box;
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
        }

        #tavern-chat-overlay:focus-within {
            border-color: rgba(0, 255, 136, 0.35);
            box-shadow: 0 8px 32px rgba(0, 255, 136, 0.12), 0 0 1px rgba(0, 255, 136, 0.4);
        }

        #tavern-chat-input {
            flex: 1;
            background: transparent;
            border: none;
            outline: none;
            color: #f3f4f6;
            font-size: 14px;
            font-family: 'Inter', sans-serif;
            font-weight: 500;
            padding: 8px 0;
        }

        #tavern-chat-input::placeholder {
            color: #6b7280;
            font-weight: 400;
        }

        #tavern-chat-send-btn {
            background: #00ff88;
            border: none;
            outline: none;
            color: #022c22;
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            padding: 10px;
            box-shadow: 0 4px 12px rgba(0, 255, 136, 0.25);
            transition: transform 0.2s ease, filter 0.2s ease;
        }

        #tavern-chat-send-btn:hover {
            transform: scale(1.06);
            filter: brightness(1.12);
        }

        #tavern-chat-send-btn:active {
            transform: scale(0.96);
        }
