:root {
    --quick-panel-slot: 57.6px; /* Button width - no gap */
}


/* Settings grid for 2-column layout */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    width: 100%;
    box-sizing: border-box;
}

.settings-grid .setting {
    margin-bottom: 0;
    width: 100%;
    min-width: 0; /* Allow grid items to shrink below content size */
    box-sizing: border-box;
    padding: 0.5rem;
}

/* Settings that should span full width (dropdowns, switches, containers) */
.settings-grid .setting:has(select),
.settings-grid .setting:has(.switches-container) {
    grid-column: 1 / -1; /* Span all three columns */
}

/* Ensure select elements are always clickable */
.settings-grid select,
#enemy-settings-tab select {
    pointer-events: auto !important;
    cursor: pointer !important;
    -webkit-user-select: auto !important;
    user-select: auto !important;
}

/* Boss and enemy settings containers should use contents for grid */
.settings-grid #boss_settings_container,
.settings-grid #enemy_settings_container {
    display: contents; /* Make container transparent to grid */
    width: 100%;
    box-sizing: border-box;
}


/* Ensure boss sliders container also uses grid when inside settings-grid */
.settings-grid #boss_sliders_container,
.settings-grid #sprite_sliders_container {
    display: contents; /* Make container transparent to grid */
    width: 100%;
    box-sizing: border-box;
}

.settings-grid #boss_sliders_container .setting,
.settings-grid #sprite_sliders_container .setting {
    margin-bottom: 0;
    width: 100%;
    box-sizing: border-box;
}

/* Make slider-label-edge work for parameter labels - match glow size/color style */
.textbox-setting .slider-label-edge {
    /* Neon effect with centered text */
    display: block;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0;
    padding: 0;
    background: none;
    border: none;
    position: static;
    transform: none;
    text-align: center;
}

/* Emoji - no glow effect */
.textbox-setting .slider-label-edge .param-emoji {
    display: inline-block;
    margin-right: 4px;
    text-shadow: none;
    filter: none;
}

/* Text - no glow effect (disabled for performance) */
.textbox-setting .slider-label-edge .param-text {
    display: inline-block;
    color: white;
    /* Glow effect removed for performance */
    text-shadow: none;
    animation: none;
}

/* Ensure enemy settings tab takes full width */
#enemy-settings-tab.settings-grid {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

body[data-game-mode="game"] #menu-button,
body[data-game-mode="game"] #side-panel {
    display: none !important;
}

.hidden-in-game {
    display: none !important;
}

/* App toast (same mechanics as now-playing toast, different look) */
#top-toast {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translate(-50%, calc(-100% - 8px));
    /* Above smithing / inventory modals (e.g. 10028) so confirmations stay visible */
    z-index: 10100;
    pointer-events: none;
    opacity: 0;
    display: flex;
    justify-content: center;
    width: 90vw;
    max-width: 90vw;
    transition:
        transform 0.32s cubic-bezier(0.22, 1.15, 0.36, 1),
        opacity 0.22s ease;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.45));
}

#top-toast.show {
    transform: translate(-50%, 10px);
    opacity: 1;
}

#top-toast .top-toast-card {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem 0.55rem;
    max-width: 100%;
    box-sizing: border-box;
    padding: 8px 14px 9px;
    border-radius: 10px;
    background: rgba(2, 6, 23, 0.78);
    border: 1px solid rgba(99, 102, 241, 0.35);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 0 0 1px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Arial, sans-serif;
}

#top-toast .top-toast-kicker {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(199, 210, 254, 0.95);
}

#top-toast .top-toast-text {
    font-size: 0.95rem;
    font-weight: 700;
    color: #ffffff;
    max-width: 100%;
    word-break: break-word;
}

/* Loot stash — retro notification (text only, pixel font, faint panel) */
#top-toast.top-toast--retro {
    filter: none;
}

#top-toast.top-toast--retro .top-toast-kicker {
    display: none !important;
}

#top-toast.top-toast--retro .top-toast-card {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 12px 7px;
    border-radius: 0;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(0, 0, 0, 0.48);
}

#top-toast.top-toast--retro .top-toast-text {
    font-family: 'VT323', 'Press Start 2P', 'Courier New', monospace;
    font-size: 1.35rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #f8f0c8;
    text-shadow:
        2px 2px 0 rgba(0, 0, 0, 0.85),
        -1px -1px 0 rgba(0, 0, 0, 0.5);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Compact “now playing” toast — animated shine */
@keyframes now-playing-kicker-shift {
    0%, 100% { color: #2dd4bf; }
    50% { color: #60a5fa; }
}

@keyframes now-playing-title-gradient {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 200% 50%;
    }
}

@keyframes now-playing-card-pulse {
    0%, 100% {
        border-color: rgba(201, 162, 39, 0.45);
        box-shadow:
            0 0 10px rgba(251, 191, 36, 0.2),
            inset 0 1px 0 rgba(255, 255, 255, 0.12);
    }
    50% {
        border-color: rgba(253, 224, 71, 0.75);
        box-shadow:
            0 0 18px rgba(252, 211, 77, 0.45),
            inset 0 1px 0 rgba(255, 255, 255, 0.22);
    }
}

#now-playing-toast {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translate(-50%, calc(-100% - 8px));
    z-index: 2100;
    pointer-events: none;
    opacity: 0;
    display: flex;
    justify-content: center;
    width: 90vw;
    max-width: 90vw;
    transition:
        transform 0.32s cubic-bezier(0.22, 1.15, 0.36, 1),
        opacity 0.22s ease;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
}

#now-playing-toast.show {
    transform: translate(-50%, 6px);
    opacity: 1;
    animation: now-playing-toast-glow 2.4s ease-in-out infinite;
}

@keyframes now-playing-toast-glow {
    0%, 100% {
        filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4)) drop-shadow(0 0 10px rgba(251, 191, 36, 0.25));
    }
    50% {
        filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 16px rgba(252, 211, 77, 0.4));
    }
}

#now-playing-toast .now-playing-card {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
    max-width: 100%;
    box-sizing: border-box;
    font-family: 'VT323', 'Press Start 2P', monospace;
    background: rgba(13, 2, 4, 0.5);
    border: 1px solid rgba(201, 162, 39, 0.45);
    border-radius: 4px;
    position: relative;
    padding: 6px 10px 6px;
    line-height: 1.2;
    min-height: 0;
    animation: now-playing-card-pulse 2.2s ease-in-out infinite;
}

#now-playing-toast .now-playing-line {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    max-width: 100%;
}

#now-playing-toast .now-playing-note {
    flex: 0 0 auto;
    opacity: 0.9;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
}

@keyframes now-playing-title-shimmer {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

/* Unify artist + title look/animation */
#now-playing-toast .now-playing-text {
    font-size: 1.14rem;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 76vw;
    background: linear-gradient(
        100deg,
        #fef3c7 0%,
        #fffbeb 18%,
        #fcd34d 38%,
        #f9a8d4 58%,
        #a5b4fc 78%,
        #fef3c7 100%
    );
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: now-playing-title-shimmer 4.6s linear infinite;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
    text-shadow: none;
}

/* Main Styles */
body, .tab, label, span, p, h1, h2, h3, h4, h5, h6, .setting, .slider-label-edge, button, input, select, .info-panel, .tick-time-overlay, #top-notification, .tabs {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

body {
    margin: 0;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    background-color: #111827; /* bg-gray-900 */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    /* Prevent zooming and scrolling on mobile */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

#canvas-container {
    position: relative; /* Needed for absolute positioning of the health bar */
    width: 100%;
    height: 100%;
    display: flex;
    /* We let JavaScript handle alignment now, so center is not needed */
    justify-content: flex-start;
    align-items: flex-start;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#canvas-container.game-active {
    opacity: 1;
}


.lobby-player-names-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: visible;
    display: none;
    z-index: 5; /* Above uiCanvas (z-index: 2) so NPC and names are visible */
}

.lobby-player-names-overlay.visible {
    display: block;
}

/* Floating quest "!" centered above mayor name chip — yellow fill, black outline. */
.lobby-npc-mayor-quest-marker {
    position: absolute;
    pointer-events: none;
    display: grid;
    place-items: center;
    width: 2.65vmin;
    height: 2.65vmin;
    box-sizing: border-box;
    /* Same anchor as .lobby-npc-mayor-label; sit above the name box */
    transform: translate(-50%, calc(-100% - 1.55vmin));
    animation: lobby-npc-quest-float 0.9s ease-in-out infinite;
    z-index: 2;
}

.lobby-npc-mayor-quest-marker-bang {
    display: block;
    margin: 0;
    padding: 0;
    line-height: 1;
    font-family: "Press Start 2P", "VT323", "Courier New", monospace;
    font-size: 1.35vmin;
    font-weight: bold;
    color: #ffea00;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: unset;
    font-smooth: never;
    text-rendering: geometricPrecision;
    -webkit-text-stroke: 0;
    paint-order: normal;
    text-shadow:
        1px 0 0 #000,
        -1px 0 0 #000,
        0 1px 0 #000,
        0 -1px 0 #000;
    transform: translate(1px, 1px);
}

.lobby-npc-mayor-quest-marker::before {
    content: '';
    position: absolute;
    inset: 12.5%;
    border-radius: 50%;
    border: 0.16vmin solid #7f1d1d;
    box-shadow: 0 0 0 1px #000;
    background: #dc2626;
    pointer-events: none;
    z-index: -1;
}

.lobby-npc-mayor-quest-marker[hidden] {
    display: none !important;
}

@keyframes lobby-npc-quest-float {
    0%, 100% {
        transform: translate(-50%, calc(-100% - 1.55vmin)) scale(1);
    }
    50% {
        transform: translate(-50%, calc(-100% - 1.9vmin)) scale(1.12);
    }
}

.lobby-player-name {
    position: absolute;
    transform: translate(-50%, -100%);
    margin-top: 25px;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.95);
    font-family: "Press Start 2P", "VT323", "Courier New", monospace;
    font-size: 0.9vmin;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9);
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: auto;
    cursor: pointer;
}

.lobby-player-name.local {
    color: #87CEEB;
}

/* Lobby player name labels are HTML overlays above the WebGL canvas. */

canvas {
    display: block;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    cursor: grab;
    /* Important: Prevents CSS from adding extra space that can cause sub-pixel issues */
    position: absolute; 
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    /* Prevent unwanted touch behaviors on mobile */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Ensure canvas maintains rendering priority even when inputs are focused */
    will-change: contents;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

canvas:active {
    cursor: grabbing;
}

/*
 * Global `canvas {}` above targets full-screen game layers (grabbable, absolute).
 * Inventory / smithing UI canvases must stay in normal flow or previews blow up / misalign.
 */
#equipment-player-preview-canvas,
button.armor-icon-frame-btn canvas,
.armor-sheet-icon-canvas,
button.sprite-pixel-editor-stamp-slot canvas,
canvas.sprite-pixel-editor-stamp-thumb {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    -webkit-transform: none !important;
    will-change: auto !important;
    backface-visibility: visible !important;
    -webkit-backface-visibility: visible !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    cursor: default !important;
    touch-action: auto !important;
}

.info-panel {
    position: fixed;
    color: white;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    pointer-events: none;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#stats { 
    top: 0 !important; 
    left: 1rem; 
    z-index: 10001; /* Above button bars and other UI */
    border-radius: 0 0 0.5rem 0; /* Rounded bottom corners only */
}
#instructions { bottom: 1rem; left: 50%; transform: translateX(-50%); }

#tick-time-display {
    display: flex !important;
}

.tick-time-overlay {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: #10b981;
    /* Small dark background behind shadowed text */
    background-color: rgba(17, 24, 39, 0.92); /* darker gray */
    padding: 1px 8px; /* even smaller height, same text size */
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    font-family: 'Courier New', monospace;
    pointer-events: auto; /* Capture clicks: in editor expands debugger, in game clears bullets */
    cursor: pointer;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 1000; /* Above #room-info-display (999); below modals (>= 1000) */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap; /* Prevent text wrapping */
    overflow: hidden; /* Hide overflow */
    max-width: 100vw; /* Never exceed viewport width */
    min-width: 0; /* Allow flex shrinking */
}

.tick-time-overlay--breakdown {
    white-space: normal;
    overflow: visible;
    flex-direction: column;
    align-items: stretch;
    padding: 4px 10px 5px;
    max-width: min(96vw, 520px);
}

.tick-time-overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1px;
    min-width: 0;
}

.tick-time-breakdown {
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1.25;
    color: rgba(209, 213, 219, 0.92);
    white-space: normal;
    word-break: break-word;
}

/* Lobby room strip sits at top center (z-index 999); offset perf bar below it */
body[data-game-mode="game"][data-in-lobby="true"] .tick-time-overlay {
    top: calc(1rem + 2.5rem);
}

/* Lobby perf bar: admins only (data-user-is-admin synced from game.js) */
body[data-game-mode="game"][data-in-lobby="true"]:not([data-user-is-admin="true"]) #tick-time-display {
    display: none !important;
}

body[data-game-mode="game"][data-in-lobby="true"] .code-children-debugger-panel {
    top: calc(1rem + 5rem);
}

#tick-time-text {
    white-space: nowrap; /* Prevent text wrapping */
    overflow: hidden; /* Hide overflow */
    text-overflow: ellipsis; /* Show ellipsis if text is too long */
    flex-shrink: 1; /* Allow text to shrink if needed */
    min-width: 0; /* Allow flex shrinking */
}

/* Code children debugger panel (expandable from tick bar in editor) */
.code-children-debugger-panel {
    position: fixed;
    top: calc(1rem + 2.5rem);
    left: 50%;
    transform: translateX(-50%);
    width: min(90vw, 560px);
    max-height: 60vh;
    background-color: rgba(17, 24, 39, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: #e5e7eb;
    pointer-events: auto;
}
.code-children-debugger-content {
    display: flex;
    flex: 1;
    min-height: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.code-children-debugger-list {
    width: 42%;
    min-width: 0;
    overflow-y: auto;
    padding: 6px 4px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 252px; /* ~9 items (padding + margin + line per item) */
}
.code-children-debugger-list-item {
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.code-children-debugger-list-item:hover {
    background: rgba(16, 185, 129, 0.2);
}
.code-children-debugger-list-item.selected {
    background: rgba(16, 185, 129, 0.35);
    color: #10b981;
}
.code-children-debugger-right {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    max-height: 252px;
}
.code-children-debugger-params-header {
    flex-shrink: 0;
    padding: 4px 8px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.code-children-debugger-breakpoint-btn {
    padding: 4px 10px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    background: rgba(31, 41, 55, 0.9);
    color: #e5e7eb;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
}
.code-children-debugger-breakpoint-btn:hover {
    background: rgba(55, 65, 81, 0.95);
    border-color: rgba(239, 68, 68, 0.5);
}
.code-children-debugger-breakpoint-btn.active {
    background: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
    color: #fca5a5;
}
.code-children-debugger-panel.code-children-debugger-panel--breakpoint-hit {
    background-color: rgba(127, 29, 29, 0.97);
    border-color: rgba(239, 68, 68, 0.4);
    box-shadow: 0 8px 24px rgba(127, 29, 29, 0.5);
}
.code-children-debugger-params {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 6px 8px;
}
.code-children-debugger-param {
    padding: 4px 6px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
    word-break: break-all;
    font-size: 0.8rem;
}
.code-children-debugger-param:hover {
    background: rgba(59, 130, 246, 0.2);
}
.code-children-debugger-tick-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.code-children-debugger-tick-label {
    color: #9ca3af;
    font-size: 0.8rem;
}
.code-children-debugger-tick-btn {
    min-width: 36px;
    padding: 4px 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: rgba(31, 41, 55, 0.9);
    color: #e5e7eb;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}
.code-children-debugger-tick-btn:hover {
    background: rgba(55, 65, 81, 0.95);
    border-color: rgba(16, 185, 129, 0.4);
}
.code-children-debugger-tick-btn.active {
    background: rgba(16, 185, 129, 0.3);
    border-color: #10b981;
    color: #10b981;
}

/* Side Panel Styles */
#side-panel {
    position: fixed;
    top: 0;
    right: -320px;
    left: auto;
    width: 320px;
    height: 100vh;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    transition: right 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 850; /* Above keyboard/code editor, below modals */
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

#side-panel.open {
    right: 0;
}

/* In-game side panel: +20% button height vs default .game-control-btn padding */
#side-panel .game-control-btn {
    padding: 0.9rem 1.2rem; /* was 0.75rem 1rem */
}

#stage-editor-side-panel {
    position: fixed;
    top: 0;
    right: calc(-1 * var(--stage-side-panel-w, 70%)); /* Initially hidden */
    left: auto;
    width: var(--stage-side-panel-w, 70%);
    height: 100vh; /* legacy */
    height: 100dvh; /* full viewport; keeps inner stack reachable on mobile */
    min-height: 0;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    transition: right 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10050 !important; /* Above code editor (9998), button panel (10000), and keyboard (10003), below modals */
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow: hidden; /* Never scrollable */
}

/* Default (touch/mobile): wide drawer. PC/mouse: compact. */
:root {
    --stage-side-panel-w: 70%;
}
@media (hover: hover) and (pointer: fine) {
    :root {
        --stage-side-panel-w: 360px;
    }
}

#stage-editor-side-panel.open {
    right: 0;
}

/* Stage editor: file tree (VS Code-ish); fills space above bottom button stack */
#stage-editor-files-section {
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#stage-editor-files-tree.stage-editor-files-tree {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.10);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 10px;
    line-height: 24px;
}

/* Full-bleed tree inside stage side panel: no horizontal padding/margins, square sides */
#stage-editor-side-panel #stage-editor-files-tree.stage-editor-files-tree {
    padding: 8px 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    gap: 0;
    font-size: 10px;
    line-height: 24px;
}

/* 24px rows: thumbnail + label (filesystem) */
#stage-editor-side-panel #stage-editor-files-tree .stage-files-row {
    gap: 4px;
    padding: 0 4px;
    min-height: 24px;
    height: 24px;
    max-height: 24px;
    box-sizing: border-box;
    border-radius: 2px;
}
#stage-editor-side-panel #stage-editor-files-tree .stage-files-row .twisty {
    width: 12px;
    flex: 0 0 12px;
    font-size: 9px;
    line-height: 24px;
    align-self: center;
}
#stage-editor-side-panel #stage-editor-files-tree .stage-files-row .icon {
    width: 24px;
    min-width: 24px;
    flex: 0 0 24px;
    height: 24px;
    line-height: 0;
    font-size: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
#stage-editor-side-panel #stage-editor-files-tree .stage-files-row .icon svg {
    width: 24px;
    height: 24px;
    display: block;
}
#stage-editor-side-panel #stage-editor-files-tree .stage-files-row .stage-files-thumb-wrap {
    background: repeating-conic-gradient(#1e293b 0% 25%, #0f172a 50% 50%) 50% / 12px 12px;
    border-radius: 2px;
}
#stage-editor-side-panel #stage-editor-files-tree .stage-files-thumb-wrap .stage-files-thumb {
    width: 24px;
    height: 24px;
    max-width: 24px;
    max-height: 24px;
    object-fit: contain;
    object-position: center;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
#stage-editor-side-panel #stage-editor-files-tree .stage-files-row .name {
    line-height: 24px;
    font-size: 10px;
}
#stage-editor-side-panel #stage-editor-files-tree .stage-files-indent {
    margin-left: 8px; /* was 14px per tree level */
    padding-left: 4px; /* was 8px */
}
#stage-editor-side-panel #stage-editor-files-tree .stage-files-empty {
    padding: 4px 6px; /* was 8px */
    font-size: 0.95em;
}
.stage-files-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 5px;
    box-sizing: border-box;
    min-height: 24px;
    height: 24px;
    max-height: 24px;
    border-radius: 4px;
    color: rgba(229, 231, 235, 0.95);
    user-select: none;
}
.stage-files-row:hover {
    background: rgba(59, 130, 246, 0.18);
}
.stage-files-row .twisty {
    width: 14px;
    color: rgba(156, 163, 175, 0.95);
    flex: 0 0 14px;
    text-align: center;
    line-height: 24px;
    font-size: 9px;
    align-self: center;
}
.stage-files-row .icon {
    width: 24px;
    min-width: 24px;
    flex: 0 0 24px;
    height: 24px;
    text-align: center;
    opacity: 0.95;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}
.stage-files-row .icon svg {
    width: 24px;
    height: 24px;
    display: block;
}
.stage-files-row .stage-files-thumb-wrap {
    background: repeating-conic-gradient(#1e293b 0% 25%, #0f172a 50% 50%) 50% / 12px 12px;
    border-radius: 2px;
}
.stage-files-row .stage-files-thumb-wrap .stage-files-thumb {
    width: 24px;
    height: 24px;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
}
.stage-files-row .name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 24px;
    font-size: 10px;
}
.stage-files-row.file .name {
    color: rgba(243, 244, 246, 0.95);
}
.stage-files-row.folder .name {
    color: rgba(209, 213, 219, 0.95);
    font-weight: 700;
}
.stage-files-indent {
    margin-left: 14px;
    padding-left: 8px;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}
.stage-files-empty {
    padding: 8px;
    color: rgba(156, 163, 175, 0.95);
}
/* Code Objects Panel for Stage Editor */
#code-objects-panel {
    position: fixed;
    bottom: 36px !important; /* Above button bar - force with !important */
    left: 0;
    right: 0;
    min-height: 100px;
    max-height: calc(80vh - 36px); /* Account for button bar */
    background: linear-gradient(135deg, rgba(17, 24, 39, 0.5) 0%, rgba(31, 41, 55, 0.5) 100%);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(15px);
    z-index: 9998; /* Below button bar (10000) */
    display: flex;
    flex-direction: column;
    padding: 10px;
    box-sizing: border-box;
    box-shadow: 0 -10px 25px -5px rgba(0, 0, 0, 0.3);
    transition: height 0.2s ease;
}

/* Ensure text in code objects panel is fully opaque */
#code-objects-panel * {
    opacity: 1;
}

.code-objects-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 5px;
    box-sizing: border-box;
    overflow-y: auto;
    max-height: calc(80vh - 20px); /* Account for padding */
}

.code-object-item {
    background: linear-gradient(135deg, rgba(55, 65, 81, 0.8) 0%, rgba(31, 41, 55, 0.8) 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 0;
    overflow: hidden;
    box-sizing: border-box;
}

.code-object-item:hover {
    background: linear-gradient(135deg, rgba(75, 85, 99, 0.9) 0%, rgba(55, 65, 81, 0.9) 100%);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.code-object-name {
    color: white;
    font-size: calc(0.75rem * 0.75);
    font-weight: 500;
    text-align: center;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    width: 100%;
}

.add-code-object-btn {
    position: fixed;
    bottom: 36px; /* Above button bar */
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50% 50% 0 0;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 -4px 12px rgba(59, 130, 246, 0.4);
    z-index: 9998; /* Below button bar (10000) */
}

.add-code-object-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    box-shadow: 0 -6px 16px rgba(59, 130, 246, 0.6);
}

.add-code-object-btn:active {
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
}

/* Code Object Editor Panel */
#code-object-editor-panel {
    position: fixed;
    bottom: 36px !important; /* Above button bar - force with !important */
    left: 0;
    right: 0;
    height: 50vh;
    max-height: calc(100vh - 136px); /* Account for button bar (36px) and top buttons (100px) */
    background: linear-gradient(135deg, rgba(17, 24, 39, 0.8) 0%, rgba(31, 41, 55, 0.8) 100%);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(15px);
    z-index: 9998; /* Below button bar (10000) and keyboard (9999) */
    display: flex;
    flex-direction: column;
    box-shadow: 0 -10px 25px -5px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

/* PC: floating window (drag + resize) — tabs/header look identical to Android */
#code-object-editor-panel.code-editor-floating {
    bottom: auto !important;
    right: auto !important;
    left: 8px;
    top: 8px; /* JS sets vertical center via applyCodeEditorFloatRect */
    width: min(612px, calc(100vw * 0.55 * 0.85));
    height: min(82.5vh, calc(100vh - 52px)); /* ~2× previous default height */
    max-height: none;
    border-radius: 10px;
    box-shadow: 0 16px 40px -8px rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.22);
    overflow: visible; /* let tabs stick out like on Android */
}
#code-object-editor-panel.code-editor-floating .code-editor-header {
    cursor: move;
    user-select: none;
    align-items: flex-end;
    gap: 4px;
    padding-right: 4px;
    min-width: 0;
}
/* Tabs scroll; action buttons stay fixed on the right — no collision */
#code-object-editor-panel.code-editor-floating .code-editor-tabs {
    flex: 1 1 0;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
}
#code-object-editor-panel.code-editor-floating .code-editor-close-btn {
    display: none !important;
}
.code-editor-header-actions {
    display: none;
    flex: 0 0 auto;
    align-items: center;
    align-self: center;
    gap: 4px;
    padding: 0 2px;
    z-index: 3;
}
#code-object-editor-panel.code-editor-floating .code-editor-header-actions {
    display: flex;
}
.code-editor-header-action-btn {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 22px;
    padding: 0 7px;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer !important;
    white-space: nowrap;
    flex-shrink: 0;
    box-sizing: border-box;
}
.code-editor-header-action-btn .hdr-emoji {
    display: none;
}
.code-editor-header-action-btn .hdr-label {
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1;
}
.code-editor-header-action-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}
#code-editor-header-spaces-btn {
    background: rgba(14, 165, 233, 0.28);
    border-color: rgba(56, 189, 248, 0.4);
}
#code-editor-header-spaces-btn:hover {
    background: rgba(14, 165, 233, 0.45);
}
#code-editor-header-test-btn {
    background: rgba(16, 185, 129, 0.28);
    border-color: rgba(52, 211, 153, 0.4);
}
#code-editor-header-test-btn:hover {
    background: rgba(16, 185, 129, 0.45);
}
#code-editor-header-test-btn.test-object-stopping {
    background: rgba(239, 68, 68, 0.4);
    border-color: rgba(248, 113, 113, 0.5);
}
#code-object-editor-panel.code-editor-floating #code-object-editor-container {
    overflow: hidden;
    border-radius: 0 0 10px 10px;
    flex: 1;
    min-height: 0;
}
#code-object-editor-panel.code-editor-floating #code-editor-problems-strip {
    border-radius: 0 0 10px 10px;
}
/* Signature + quick-help docked inside floating PC editor (move with the window) */
#code-object-editor-panel.code-editor-floating #keyboard-suggestions-black-bar.hosted-in-editor {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    z-index: 6;
    border-radius: 0 0 10px 10px;
}
#code-object-editor-panel.code-editor-floating #function-quick-help.hosted-in-editor {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    z-index: 7;
    box-sizing: border-box;
}
#code-object-editor-panel.code-editor-floating #function-quick-help.hosted-in-editor.expanded {
    max-height: min(40vh, 280px);
}
#code-object-editor-panel .code-editor-resize-handle {
    display: none;
}
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle {
    display: block;
    position: absolute;
    z-index: 5;
    background: transparent;
}
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.n,
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.s {
    left: 8px;
    right: 8px;
    height: 6px;
    cursor: ns-resize;
}
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.e,
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.w {
    top: 8px;
    bottom: 8px;
    width: 6px;
    cursor: ew-resize;
}
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.n { top: 0; }
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.s { bottom: 0; }
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.e { right: 0; }
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.w { left: 0; }
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.nw,
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.ne,
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.sw,
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.se {
    width: 12px;
    height: 12px;
}
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.nw { top: 0; left: 0; cursor: nwse-resize; }
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.ne { top: 0; right: 0; cursor: nesw-resize; }
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.sw { bottom: 0; left: 0; cursor: nesw-resize; }
#code-object-editor-panel.code-editor-floating .code-editor-resize-handle.se { bottom: 0; right: 0; cursor: nwse-resize; }

/* Floating mode: left rail buttons stay above the window */
body:has(#code-object-editor-panel.code-editor-floating) #code-editor-spaces-btn,
body:has(#code-object-editor-panel.code-editor-floating) #code-editor-add-point-btn,
body:has(#code-object-editor-panel.code-editor-floating) #code-editor-delete-point-btn,
body:has(#code-object-editor-panel.code-editor-floating) #code-editor-directions-btn,
body:has(#code-object-editor-panel.code-editor-floating) #stage-editor-menu-btn {
    z-index: 10020;
}

/* Function help strip: fixed at top of screen, same multi-color HTML styling as forum thread, smaller font. */
.function-help-strip {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10001;
    max-width: 100%;
    max-height: 28vh;
    overflow: auto;
    padding: 6px 10px 8px;
    font-size: 0.7rem;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.9);
    font-family: system-ui, sans-serif;
    white-space: pre-wrap;
    word-break: break-word;
    pointer-events: none;
    display: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.97) 0%, rgba(31, 41, 55, 0.95) 100%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.function-help-strip:not(:empty) {
    display: block;
}
/* Forum-style colors (same as forum post content) */
.function-help-strip .fn-name { color: #a5b4fc; font-weight: 600; }
.function-help-strip .fn-params { color: rgba(255, 255, 255, 0.85); }
.function-help-strip .returns-label { color: #ffd580; font-weight: bold; }
.function-help-strip a { color: #60a5fa; text-decoration: underline; }
.function-help-strip .help-strip-code { display: block; margin: 4px 0; padding: 4px 6px; background: rgba(0,0,0,0.3); border-radius: 4px; font-family: 'Courier New', monospace; font-size: 0.65rem; white-space: pre-wrap; }

/* Quick help: full-width black bar exactly above function signature line, same styling as signature */
.function-quick-help {
    position: fixed;
    z-index: 10010;
    padding: 0 12px;
    box-sizing: border-box;
    font-size: 0.875rem;
    line-height: 1.15;
    color: rgba(255, 255, 255, 0.9);
    font-family: 'Courier New', monospace;
    background: #000;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.function-quick-help.expanded {
    flex-direction: column-reverse;
    align-items: stretch;
    justify-content: flex-end;
    white-space: normal;
    max-height: 50vh;
    overflow: auto;
    pointer-events: auto;
    flex-wrap: nowrap;
}
.function-quick-help.expanded .function-quick-help-line {
    display: none;
}
.function-quick-help.expanded .function-quick-help-full {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}
.function-quick-help .function-quick-help-line {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.function-quick-help-expand-btn {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.function-quick-help-expand-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}
.function-quick-help .function-quick-help-full {
    width: 100%;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 0.7rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}
.function-quick-help .function-quick-help-full .fn-name { color: #a5b4fc; font-weight: 600; }
.function-quick-help .function-quick-help-full .fn-params { color: rgba(255, 255, 255, 0.85); }
.function-quick-help .function-quick-help-full .returns-label { color: #ffd580; font-weight: bold; }
.function-quick-help .function-quick-help-full .help-strip-code { display: block; margin: 4px 0; padding: 4px 6px; background: rgba(0,0,0,0.3); border-radius: 4px; font-family: 'Courier New', monospace; font-size: 0.65rem; white-space: pre-wrap; }

/* Ensure text in code editor panel is fully opaque */
#code-object-editor-panel * {
    opacity: 1;
}

.code-editor-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 0;
    background: transparent; /* No background under tabs */
    flex-shrink: 0;
    gap: 8px;
    position: relative;
    z-index: 1;
    height: 25px; /* Match unselected tab height */
    min-height: 25px;
    pointer-events: auto;
}

/* Floating breakpoint circle overlay (drawn on top, does not affect text) */
.code-editor-breakpoint-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;
}
.code-editor-breakpoint-circle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
}

.code-editor-test-btn {
    position: fixed;
    padding: 10px 20px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    box-sizing: border-box;
    z-index: 202; /* Above code editor panel (z-index 142) and top buttons (201) */
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    left: 1rem;
    opacity: 0.6; /* 40% transparency */
    pointer-events: auto !important; /* Ensure button is always clickable */
    touch-action: manipulation; /* Better touch handling on Android */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px; /* match top button layout */
}

/* Floating Quick Test: mobile left rail (under Spaces). PC uses bottom-bar / header Test Object. */
#code-editor-test-btn {
    width: 43.2px;
    height: 48px;
    padding: 4px;
    left: 0;
    right: auto;
    top: auto;
    /* bottom is controlled by JavaScript */
    transform: translateY(-30px);
    border-radius: 0 12px 12px 0;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    font-size: 1.1rem;
    z-index: 900;
    transition: none;
    opacity: 1;
}
#code-editor-test-btn .panel-btn-emoji { font-size: 1.25rem; line-height: 1; }
#code-editor-test-btn .panel-btn-label { font-size: 0.65rem; font-weight: 500; line-height: 1; }
#code-editor-test-btn:hover {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}
#code-editor-test-btn:active {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}
#code-editor-test-btn.test-object-stopping {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.45) !important;
}
body:not([data-game-mode="stageEditor"]) #code-editor-test-btn {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* PC: floating Quick Test off — use bottom-bar / header Test Object */
@media (hover: hover) and (pointer: fine) {
    #code-editor-test-btn {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}

/* Mobile: no bottom-bar Test Object — floating Quick Test under Spaces */
@media not ((hover: hover) and (pointer: fine)) {
    #stage-editor-test-object-btn {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
    body.stage-side-panel-open #code-editor-test-btn {
        display: none !important;
    }
}

/* Bottom-bar Test Object (PC) */
#stage-editor-test-object-btn.test-object-active {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%) !important;
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.45) !important;
}
#stage-editor-test-object-btn.test-object-stopping {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.45) !important;
}

.code-editor-test-btn:hover {
    /* No hover animation - keep same state */
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.code-editor-test-btn:active {
    /* No click animation - keep same state */
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.code-editor-tabs {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 0 12px;
    overflow-x: auto;
    overflow-y: hidden; /* never show vertical scrollbar on tabs */
    flex: 1;
    min-width: 0;
}

/* PC: ensure no vertical scrollbar gutter on the tab strip */
@media (hover: hover) and (pointer: fine) {
    .code-editor-tabs {
        overflow-y: hidden;
        scrollbar-width: thin; /* horizontal only when needed */
    }
    .code-editor-tabs::-webkit-scrollbar {
        height: 4px;
        width: 0; /* no vertical scrollbar */
    }
    .code-editor-tabs::-webkit-scrollbar:vertical {
        display: none;
        width: 0;
        height: 0;
    }
    .code-editor-tabs::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.15);
        border-radius: 4px;
    }
}

/* Code editor scrollbar: darker / less bright than OS default */
#code-object-editor-panel textarea,
#code_object_editor,
#code_object_editor_wrapper textarea {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.16) rgba(0, 0, 0, 0.35);
}
#code-object-editor-panel textarea::-webkit-scrollbar,
#code_object_editor::-webkit-scrollbar,
#code_object_editor_wrapper textarea::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
#code-object-editor-panel textarea::-webkit-scrollbar-track,
#code_object_editor::-webkit-scrollbar-track,
#code_object_editor_wrapper textarea::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
}
#code-object-editor-panel textarea::-webkit-scrollbar-thumb,
#code_object_editor::-webkit-scrollbar-thumb,
#code_object_editor_wrapper textarea::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
#code-object-editor-panel textarea::-webkit-scrollbar-thumb:hover,
#code_object_editor::-webkit-scrollbar-thumb:hover,
#code_object_editor_wrapper textarea::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.24);
    background-clip: padding-box;
}
#code-object-editor-panel textarea::-webkit-scrollbar-corner,
#code_object_editor::-webkit-scrollbar-corner,
#code_object_editor_wrapper textarea::-webkit-scrollbar-corner {
    background: rgba(0, 0, 0, 0.4);
}

.code-editor-tab {
    padding: 6px 6px;
    background: rgba(55, 65, 81, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    color: rgba(255, 255, 255, 0.7);
    font-size: calc(0.875rem * 0.75 * 1.1);
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    flex-shrink: 0;
    height: 25px; /* 30% smaller than active tab */
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

.code-editor-tab:hover {
    background: rgba(75, 85, 99, 0.8);
    color: white;
}

.code-editor-tab.active {
    background: rgba(31, 41, 55, 0.9);
    border-color: rgba(255, 255, 255, 0.3);
    border-bottom-color: transparent;
    border-radius: 6px 6px 0 0; /* Ensure proper corner rounding */
    color: white;
    position: relative;
    z-index: 2; /* Active tab appears above others */
    height: 36px; /* Keep original height */
}

/* More visible active state for instance parameter tabs */
#instance-parameter-tabs .code-editor-tab.active {
    background: rgba(59, 130, 246, 0.9) !important;
    border-color: rgba(59, 130, 246, 0.8) !important;
    border-width: 2px !important;
    color: white !important;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6) !important;
    transform: translateY(-2px) !important;
}

.code-editor-tab.testing {
    background: rgba(16, 185, 129, 0.8) !important;
    border-color: rgba(16, 185, 129, 0.5) !important;
    color: white !important;
}

.code-editor-tab.testing.active {
    background: rgba(16, 185, 129, 0.9) !important;
    border-color: rgba(16, 185, 129, 0.6) !important;
}

.code-editor-tab.testing:hover {
    background: rgba(16, 185, 129, 0.9) !important;
    border-color: rgba(16, 185, 129, 0.6) !important;
}

/* Object functions mode: tab turns blue, (Functions) label under name */
.code-editor-tab.code-editor-tab-functions {
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 4px 6px;
    white-space: nowrap;
    background: rgba(59, 130, 246, 0.55) !important;
    border-color: rgba(59, 130, 246, 0.6) !important;
    color: rgba(255, 255, 255, 0.95) !important;
}
.code-editor-tab.code-editor-tab-functions .code-editor-tab-name {
    display: block;
    line-height: 1.2;
}
.code-editor-tab.code-editor-tab-functions .code-editor-tab-functions-label {
    display: block;
    font-size: 0.7em;
    font-weight: 800;
    color: rgba(156, 163, 175, 0.95);
    opacity: 1;
    line-height: 1.2;
}
.code-editor-tab.code-editor-tab-functions:hover {
    background: rgba(59, 130, 246, 0.75) !important;
    border-color: rgba(59, 130, 246, 0.8) !important;
}
.code-editor-tab.code-editor-tab-functions.active {
    background: rgba(59, 130, 246, 0.7) !important;
    border-color: rgba(59, 130, 246, 0.9) !important;
    color: white !important;
}

.code-editor-tab.code-editor-tab-functions:has(.code-editor-tab-close) {
    padding-right: 22px;
}

/* Object left on Functions section while another tab is focused: keep blue (inactive tab height). */
.code-editor-tab.code-editor-tab-functions-dormant {
    background: rgba(59, 130, 246, 0.45) !important;
    border-color: rgba(59, 130, 246, 0.55) !important;
    color: rgba(255, 255, 255, 0.95) !important;
}
.code-editor-tab.code-editor-tab-functions-dormant:hover {
    background: rgba(59, 130, 246, 0.65) !important;
    border-color: rgba(59, 130, 246, 0.75) !important;
    color: white !important;
}

/* Main object shaders mode: fuchsia tab, active shader label under name */
.code-editor-tab.code-editor-tab-shaders {
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 4px 6px;
    white-space: nowrap;
    background: rgba(217, 70, 239, 0.55) !important;
    border-color: rgba(217, 70, 239, 0.65) !important;
    color: rgba(255, 255, 255, 0.95) !important;
}
.code-editor-tab.code-editor-tab-shaders .code-editor-tab-name {
    display: block;
    line-height: 1.2;
}
.code-editor-tab.code-editor-tab-shaders .code-editor-tab-shaders-label {
    display: block;
    font-size: 0.7em;
    font-weight: 800;
    color: rgba(250, 232, 255, 0.95);
    opacity: 1;
    line-height: 1.2;
}
.code-editor-tab.code-editor-tab-shaders:hover {
    background: rgba(217, 70, 239, 0.75) !important;
    border-color: rgba(217, 70, 239, 0.85) !important;
}
.code-editor-tab.code-editor-tab-shaders.active {
    background: rgba(217, 70, 239, 0.7) !important;
    border-color: rgba(217, 70, 239, 0.9) !important;
    color: white !important;
}
.code-editor-tab.code-editor-tab-shaders:has(.code-editor-tab-close) {
    padding-right: 22px;
}
.code-editor-tab.code-editor-tab-shaders-dormant {
    background: rgba(217, 70, 239, 0.45) !important;
    border-color: rgba(217, 70, 239, 0.55) !important;
    color: rgba(255, 255, 255, 0.95) !important;
}
.code-editor-tab.code-editor-tab-shaders-dormant:hover {
    background: rgba(217, 70, 239, 0.65) !important;
    border-color: rgba(217, 70, 239, 0.75) !important;
    color: white !important;
}

/* Root/non-child object tab: object name on first line, (template) on second */
.code-editor-tab.code-editor-tab-template {
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    height: auto;
    padding: 4px 6px;
    white-space: nowrap;
}
.code-editor-tab.code-editor-tab-template .code-editor-tab-name {
    display: block;
    line-height: 1.2;
}
.code-editor-tab.code-editor-tab-template .code-editor-tab-template-label {
    display: block;
    font-size: 0.7em;
    font-family: Arial, sans-serif;
    font-weight: 900 !important;
    color: rgba(156, 163, 175, 0.95);
    opacity: 1;
    letter-spacing: 0.02em;
    line-height: 1.2;
}
.code-editor-tab.code-editor-tab-template:has(.code-editor-tab-close) {
    padding-right: 22px;
}

/* Creation code tab: object id on first line, (creation) on second */
.code-editor-tab.code-editor-tab-creation {
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    height: auto;
    padding: 4px 6px;
    white-space: nowrap;
}
.code-editor-tab.code-editor-tab-creation .code-editor-tab-name {
    display: block;
    line-height: 1.2;
}
.code-editor-tab.code-editor-tab-creation .code-editor-tab-creation-label {
    display: block;
    font-size: 0.7em;
    font-weight: 500;
    opacity: 0.95;
    line-height: 1.2;
}

.code-editor-tab.code-editor-tab-creation:has(.code-editor-tab-close) {
    padding-right: 22px;
}

/* Active tabs (custom function editing, closeable) – light blue */
.code-editor-tab.code-editor-active-tab {
    background: rgba(125, 211, 252, 0.5) !important;
    border-color: rgba(56, 189, 248, 0.5) !important;
    color: rgba(255, 255, 255, 0.95) !important;
}

.code-editor-tab.code-editor-active-tab:hover {
    background: rgba(125, 211, 252, 0.7) !important;
    border-color: rgba(56, 189, 248, 0.7) !important;
    color: white !important;
}

.code-editor-tab.code-editor-active-tab.active {
    background: rgba(56, 189, 248, 0.6) !important;
    border-color: rgba(56, 189, 248, 0.8) !important;
    color: white !important;
}

.code-editor-add-tab {
    background: rgba(34, 197, 94, 0.6) !important;
    border-color: rgba(34, 197, 94, 0.3) !important;
    border-bottom: none !important;
    color: white !important;
    font-size: calc(1.2rem * 1.1) !important;
    font-weight: bold !important;
    padding: 6px 6px !important;
    height: 25px !important; /* Match unselected tabs height */
    display: flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
}

.code-editor-add-tab:hover {
    background: rgba(34, 197, 94, 0.8) !important;
    border-color: rgba(34, 197, 94, 0.5) !important;
}

.code-editor-universal-tab {
    background: rgba(59, 130, 246, 0.6) !important;
    border-color: rgba(59, 130, 246, 0.3) !important;
    border-bottom: none !important;
    color: white !important;
    font-size: calc(1.2rem * 1.1) !important;
    font-weight: bold !important;
    padding: 6px 6px !important;
    height: 25px !important; /* Match unselected tabs height */
    display: flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
}

.code-editor-universal-tab:hover {
    background: rgba(59, 130, 246, 0.8) !important;
    border-color: rgba(59, 130, 246, 0.5) !important;
}

.code-editor-close-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 25px; /* Match header/unselected tab height */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    margin-bottom: 0; /* Align with tabs */
    align-self: flex-end; /* Align to bottom of header */
}

.code-editor-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

#code-object-editor-container {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-top: 1px solid rgba(255, 255, 255, 0.1); /* Border at top to connect with tabs */
}

/* Code object action menu (tab context menu): scrollable, max 7.5 items visible */
#code-object-action-menu {
    max-height: 248px !important; /* ~7.5 items (30px per item + padding) */
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* Types submenu (tab context menu): same color as code editor tab when not quick test */
#code-object-types-submenu {
    background: rgba(40, 40, 40, 0.8) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    padding: 8px 0 !important;
    min-width: 112px !important; /* 25% smaller than 150px */
    max-height: 220px !important; /* fit title + 5 items */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5) !important;
}
#code-object-types-submenu > div:first-child {
    padding: 2px 10px 3px !important;
    color: #fff !important;
    font-size: 11px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
}
#code-object-types-submenu > div:nth-child(2) {
    padding: 0 !important;
    max-height: 190px !important; /* ~5 items visible (8+16px padding + 14px font per row) */
}
#code-object-types-submenu > div:nth-child(2) > div {
    padding: 8px 16px !important;
    font-size: 14px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.2) !important;
}
#code-object-types-submenu > div:nth-child(2) > div:first-child {
    border-top: none !important;
}

/* Spaces mode: free-form canvas with draggable def cards */
#code-editor-spaces-canvas {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.12);
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
}
#code-editor-spaces-canvas.panning {
    cursor: grabbing;
}
#code-editor-spaces-canvas.pinching {
    cursor: zoom-in;
}
#code-editor-spaces-canvas.visible {
    display: block;
    z-index: 20;
}
.code-editor-spaces-world {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-width: 100%;
    min-height: 100%;
    transform-origin: 0 0;
    pointer-events: none;
    contain: layout paint;
}
.code-editor-spaces-if-block {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    pointer-events: none;
    z-index: 2;
    position: absolute;
}
.code-editor-spaces-if-block.nested {
    margin-top: 0;
    margin-bottom: 0;
}
.code-editor-spaces-if-block.dragging {
    z-index: 130;
}
.code-editor-spaces-container .spaces-container-content .code-editor-spaces-if-block,
.code-editor-spaces-if-slot .spaces-if-slot-content .code-editor-spaces-if-block {
    pointer-events: none;
}
.code-editor-spaces-container .spaces-container-content .code-editor-spaces-if-block,
.code-editor-spaces-if-slot .spaces-if-slot-content .code-editor-spaces-if-block,
.code-editor-spaces-container .spaces-container-content .code-editor-spaces-fn-block,
.code-editor-spaces-if-slot .spaces-if-slot-content .code-editor-spaces-fn-block {
    pointer-events: none;
}
.code-editor-spaces-container .spaces-container-content .code-editor-spaces-if-block .spaces-if-bar,
.code-editor-spaces-if-slot .spaces-if-slot-content .code-editor-spaces-if-block .spaces-if-bar,
.code-editor-spaces-container .spaces-container-content .code-editor-spaces-fn-block .spaces-fn-bar,
.code-editor-spaces-if-slot .spaces-if-slot-content .code-editor-spaces-fn-block .spaces-fn-bar,
.code-editor-spaces-container .spaces-container-content .code-editor-spaces-fn-block .spaces-fn-args-slot .code-editor-spaces-card,
.code-editor-spaces-container .spaces-container-content .code-editor-spaces-fn-block .spaces-fn-args-slot .spaces-if-slot-resize-handle,
.code-editor-spaces-if-case-row .code-editor-spaces-card {
    pointer-events: auto;
}
.spaces-if-bar {
    box-sizing: border-box;
    width: 100%;
    min-width: 200px;
    min-height: 37px;
    padding: 0 8px;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 6px;
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid rgba(251, 191, 36, 0.85);
    border-radius: 4px;
    color: #fde68a;
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: visible;
    pointer-events: auto;
    cursor: grab;
    user-select: none;
    touch-action: none;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}
.spaces-if-bar-label {
    flex-shrink: 0;
    line-height: 1;
    pointer-events: none;
    font-size: 0.875rem; /* 0.7rem × 1.25 */
    margin-top: 8px;
}
.spaces-if-case-row {
    position: relative;
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    overflow: visible;
    pointer-events: none;
}
.spaces-if-case-row .code-editor-spaces-card,
.spaces-if-case-row .code-editor-spaces-card.in-if-case-row {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    margin: 0;
    /* zoom (not transform) so grid gap is real visual spacing between cards */
    zoom: 0.75;
    transform: none;
    pointer-events: auto;
    z-index: 3;
}
.code-editor-spaces-if-block.dragging .spaces-if-bar {
    cursor: grabbing;
}
.code-editor-spaces-fn-block {
    position: absolute;
    z-index: 2;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
.code-editor-spaces-fn-block .spaces-fn-bar {
    pointer-events: auto;
}
.code-editor-spaces-fn-block .spaces-fn-args-slot {
    pointer-events: none;
    order: 0;
    margin-top: 0;
    /* Tabs tuck under fn bar (fn bar wins z-index when they overlap). */
    margin-bottom: -20px;
    z-index: 1;
    background: transparent;
    border: none;
    min-height: 28px;
    overflow: visible;
}
.code-editor-spaces-fn-block .spaces-fn-args-slot.resizing {
    border: none;
}
.code-editor-spaces-fn-block .spaces-fn-args-slot .spaces-if-slot-resize-handle {
    display: none;
}
.code-editor-spaces-fn-block .spaces-fn-args-slot .spaces-if-slot-content .code-editor-spaces-card {
    pointer-events: auto;
    position: relative;
    z-index: 1;
    border-radius: 7px 7px 0 0;
    border-color: rgba(200, 120, 220, 0.85);
    border-bottom-color: transparent;
    background: rgba(30, 15, 36, 0.98);
    box-shadow: none;
}
.spaces-fn-bar {
    box-sizing: border-box;
    width: 100%;
    min-width: 200px;
    height: 37px;
    min-height: 37px;
    max-height: 37px;
    padding: 0 8px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(30, 15, 36, 1);
    border: 1px solid rgba(255, 0, 255, 0.9);
    border-radius: 4px;
    color: #00ff00;
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: visible;
    pointer-events: auto;
    cursor: grab;
    user-select: none;
    touch-action: none;
    flex-shrink: 0;
    position: relative;
    z-index: 3;
    order: 1;
}
.spaces-fn-bar-label {
    flex: 1 1 auto;
    width: 100%;
    line-height: 1;
    pointer-events: none;
    color: inherit;
    font-size: 0.875rem; /* 0.7rem × 1.25 */
    text-align: center;
}
.spaces-fn-bar-label span {
    font-family: inherit;
    font-size: inherit;
}
.code-editor-spaces-fn-block.dragging .spaces-fn-bar {
    cursor: grabbing;
}
.code-editor-spaces-if-slot {
    position: relative;
    box-sizing: border-box;
    width: 200px;
    min-width: 80px;
    min-height: 48px;
    padding: 0;
    margin-top: -10px;
    background: rgba(15, 23, 42, 0.35);
    border: 1.5px solid rgba(250, 204, 21, 0.55);
    border-radius: 3px;
    pointer-events: none;
    overflow: visible;
    z-index: 1;
}
.code-editor-spaces-if-slot .spaces-if-slot-resize-handle {
    display: block;
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 4.5px;
    height: 4.5px;
    margin: 0;
    border-radius: 0 0 2px 0;
    background: linear-gradient(135deg, transparent 0%, transparent 45%, rgba(250, 204, 21, 0.75) 45%, rgba(250, 204, 21, 0.75) 100%);
    cursor: nwse-resize;
    touch-action: none;
    pointer-events: auto;
    opacity: 0.7;
    transition: opacity 0.12s ease;
    z-index: 5;
}
.code-editor-spaces-if-slot .spaces-if-slot-resize-handle::after {
    content: '';
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 16px;
    height: 16px;
}
.code-editor-spaces-if-slot.resizing {
    border-color: rgba(250, 204, 21, 0.75);
}
.code-editor-spaces-if-slot:hover .spaces-if-slot-resize-handle,
.code-editor-spaces-if-slot.resizing .spaces-if-slot-resize-handle {
    opacity: 1;
    background: linear-gradient(135deg, transparent 0%, transparent 40%, rgba(250, 204, 21, 0.85) 40%, rgba(250, 204, 21, 0.85) 100%);
}
.code-editor-spaces-if-slot .spaces-if-slot-content {
    position: absolute;
    top: 6px;
    left: 6px;
    overflow: visible;
    pointer-events: none;
    transform: scale(0.75);
    transform-origin: top left;
    /* width/height set in JS to inner/0.75 (paired with 0.75 scale) */
}
.code-editor-spaces-if-slot .spaces-if-slot-content .code-editor-spaces-card {
    pointer-events: auto;
}
.code-editor-spaces-if-slot .spaces-if-slot-content .code-editor-spaces-if-block {
    pointer-events: none;
}
.code-editor-spaces-if-slot .spaces-if-slot-content .code-editor-spaces-if-block .spaces-if-bar {
    pointer-events: auto;
}
.code-editor-spaces-card-condition {
    border-color: rgba(251, 191, 36, 0.75);
}
.code-editor-spaces-card-assign {
    border-color: rgba(52, 211, 153, 0.75);
}
.code-editor-spaces-container {
    position: absolute;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    background: rgba(15, 23, 42, 0.35);
    border: 1.5px solid rgba(100, 116, 139, 0.65);
    border-radius: 3.5px;
    pointer-events: auto;
    touch-action: none;
    cursor: default;
    z-index: 0;
    min-width: 80px;
    min-height: 60px;
    overflow: visible;
}
.code-editor-spaces-container .spaces-container-label,
.code-editor-spaces-container .spaces-container-resize-handle {
    pointer-events: auto;
}
.code-editor-spaces-container .spaces-container-label {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    min-width: 0;
    z-index: 8;
    /* Sit above the body; overlap top border so upper outline hides under the label */
    transform: translateY(calc(-100% + 2px));
    box-sizing: border-box;
    padding: 4px 10px 5px;
    pointer-events: auto;
    cursor: grab;
    user-select: none;
    touch-action: none;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.35));
    background: linear-gradient(168deg, rgba(71, 85, 105, 0.98) 0%, rgba(51, 65, 85, 0.98) 38%, rgba(30, 41, 59, 0.98) 100%);
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-bottom: none;
    border-radius: 3.5px 3.5px 0 0;
    transition: filter 0.12s ease, background 0.12s ease;
}
.code-editor-spaces-container .spaces-container-label::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
    border-radius: 3.5px 3.5px 0 0;
    pointer-events: none;
}
.code-editor-spaces-container .spaces-container-label-text {
    display: block;
    font-size: 10px;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1.25;
    color: #f8fafc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
.code-editor-spaces-container .spaces-container-label:hover {
    filter: drop-shadow(0 3px 7px rgba(0, 0, 0, 0.42));
    background: linear-gradient(168deg, rgba(82, 98, 120, 0.98) 0%, rgba(59, 73, 94, 0.98) 38%, rgba(37, 51, 71, 0.98) 100%);
}
.code-editor-spaces-container .spaces-container-label.holding {
    filter: drop-shadow(0 2px 8px rgba(250, 204, 21, 0.35));
    background: linear-gradient(168deg, rgba(120, 98, 40, 0.98) 0%, rgba(92, 75, 28, 0.98) 45%, rgba(68, 56, 22, 0.98) 100%);
    border-color: rgba(250, 204, 21, 0.75);
}
.code-editor-spaces-container .spaces-container-label.holding .spaces-container-label-text {
    color: #fef9c3;
}
.code-editor-spaces-container.dragging .spaces-container-label {
    cursor: grabbing;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
}
.code-editor-spaces-container.dragging,
.code-editor-spaces-container.resizing {
    cursor: grabbing;
}
.code-editor-spaces-container.resizing {
    border-color: rgba(250, 204, 21, 0.75);
    border-style: solid;
}
.code-editor-spaces-container .spaces-container-content {
    position: absolute;
    top: 6px;
    left: 6px;
    overflow: visible;
    pointer-events: auto;
    touch-action: none;
    transform: scale(0.75);
    transform-origin: top left;
    /* width/height set in JS to inner/0.75 (paired with 0.75 scale) */
}
.code-editor-spaces-canvas.marquee-holding {
    cursor: progress;
}
.code-editor-spaces-canvas.marquee-armed {
    cursor: crosshair;
}
.code-editor-spaces-container .spaces-container-content.marquee-holding {
    cursor: progress;
}
.code-editor-spaces-container .spaces-container-content.marquee-armed {
    cursor: crosshair;
}
.spaces-marquee-select {
    position: absolute;
    z-index: 250;
    box-sizing: border-box;
    pointer-events: none;
    border: 1px solid rgba(56, 189, 248, 0.95);
    background: rgba(56, 189, 248, 0.18);
}
.code-editor-spaces-container.spaces-container-grid-mode .spaces-container-content {
    background: rgba(15, 23, 42, 0.35);
}
.code-editor-spaces-container .spaces-container-content .code-editor-spaces-card {
    pointer-events: auto;
}
.code-editor-spaces-container .spaces-container-resize-handle {
    display: block;
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 4.5px;
    height: 4.5px;
    margin: 0;
    border-radius: 0 0 2px 0;
    background: linear-gradient(135deg, transparent 0%, transparent 45%, rgba(250, 204, 21, 0.75) 45%, rgba(250, 204, 21, 0.75) 100%);
    cursor: nwse-resize;
    touch-action: none;
    pointer-events: auto;
    opacity: 0.7;
    transition: opacity 0.12s ease;
    z-index: 5;
}
.code-editor-spaces-container .spaces-container-resize-handle::after {
    content: '';
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 16px;
    height: 16px;
}
.code-editor-spaces-container:hover .spaces-container-resize-handle,
.code-editor-spaces-container.resizing .spaces-container-resize-handle {
    opacity: 1;
    background: linear-gradient(135deg, transparent 0%, transparent 40%, rgba(250, 204, 21, 0.85) 40%, rgba(250, 204, 21, 0.85) 100%);
}
.code-editor-spaces-card {
    position: absolute;
    padding: 10px 14px;
    margin: 0;
    background: rgba(12, 20, 36, 0.98);
    border: 1px solid rgba(56, 189, 248, 0.8);
    border-radius: 8px;
    color: #c5e8c5;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.35;
    cursor: grab;
    user-select: none;
    touch-action: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    white-space: nowrap;
    box-sizing: border-box;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    z-index: 1;
    transform-origin: top left;
}
.code-editor-spaces-card.dragging {
    z-index: 120;
}
.code-editor-spaces-card .spaces-card-header {
    display: block;
    min-width: 0;
}
.code-editor-spaces-card .spaces-card-header-line {
    color: #00ff00;
}
.code-editor-spaces-card-fn {
    border-color: rgba(192, 132, 252, 0.9);
    background: rgba(24, 12, 38, 0.98);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(216, 180, 254, 0.06);
}
.code-editor-spaces-card-fn .spaces-card-header-line {
    color: #00ff00;
}
.code-editor-spaces-card-fn.selected {
    border-color: rgba(250, 204, 21, 0.95);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(250, 204, 21, 0.35);
}
.code-editor-spaces-card.selected.expanded .spaces-card-header {
    display: none;
}
.code-editor-spaces-card .spaces-card-expand {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    min-width: 0;
    gap: 8px;
    white-space: normal;
}
.code-editor-spaces-card.selected.expanded .spaces-card-expand {
    display: flex;
}
.code-editor-spaces-card.selected.expanded {
    white-space: normal;
    width: auto;
    max-width: none;
}
#code-editor-spaces-canvas .spaces-card-value-input {
    width: 100%;
    min-width: 0;
    max-width: none;
    height: 32px;
    padding: 4px 8px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(0, 255, 0, 0.35);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.95);
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    text-align: left;
    cursor: text;
    touch-action: manipulation;
    user-select: text;
    -webkit-user-select: text;
}
#code-editor-spaces-canvas .spaces-card-value-input:read-only {
    cursor: pointer;
    opacity: 0.92;
}
#code-editor-spaces-canvas .spaces-card-value-input:focus {
    outline: none;
    border-color: rgba(0, 255, 0, 0.7);
    box-shadow: 0 0 0 2px rgba(0, 255, 0, 0.2);
    opacity: 1;
}
#code-editor-spaces-canvas .spaces-card-slide.def-var-slide {
    width: 100%;
    min-width: 0;
    height: 28px;
    min-height: 28px;
    flex: none;
    position: relative;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    column-gap: 6px;
    padding: 0 6px;
    cursor: ew-resize;
    user-select: none;
    touch-action: none;
    background: rgba(0, 255, 0, 0.08);
    border: 1px solid rgba(0, 255, 0, 0.3);
    border-radius: 6px;
    color: rgba(0, 255, 0, 0.6);
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1;
}
#code-editor-spaces-canvas .spaces-card-slide.def-var-slide:hover {
    background: rgba(0, 255, 0, 0.12);
    color: rgba(0, 255, 0, 0.85);
}
#code-editor-spaces-canvas .spaces-card-slide.def-var-slide.dragging {
    border-color: #b8860b;
    background: rgba(0, 255, 0, 0.14);
}
#code-editor-spaces-canvas .spaces-card-slide .def-var-slide-mark {
    font-weight: 600;
    font-size: inherit;
    color: rgba(0, 255, 0, 0.55);
    pointer-events: none;
}
#code-editor-spaces-canvas .spaces-card-slide .def-var-slide-mark:first-child {
    justify-self: start;
}
#code-editor-spaces-canvas .spaces-card-slide .def-var-slide-mark:last-child {
    justify-self: end;
}
#code-editor-spaces-canvas .spaces-card-slide .def-var-slide-value {
    justify-self: center;
    min-width: 0;
    text-align: center;
    font-weight: 600;
    font-size: inherit;
    color: rgba(0, 255, 0, 0.75);
    pointer-events: none;
}
.code-editor-spaces-card:active,
.code-editor-spaces-card.dragging {
    cursor: grabbing;
    border-color: rgba(14, 165, 233, 0.75);
    box-shadow: 0 4px 16px rgba(14, 165, 233, 0.25);
}
.code-editor-spaces-card.selected {
    border-color: rgba(250, 204, 21, 0.95);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(250, 204, 21, 0.35);
    cursor: grab;
}
.code-editor-spaces-card.selected.dragging {
    border-color: rgba(250, 204, 21, 0.95);
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(250, 204, 21, 0.45);
}

.spaces-add-menu {
    position: fixed;
    z-index: 10050;
    background: rgba(0, 0, 0, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    padding: 4px 0;
    min-width: 148px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    touch-action: manipulation;
}

/* Def vars list (Slider mode): scrollable list of def variables with slide areas, full width. On top when visible. */
#code-editor-def-vars-list {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    margin: 0;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 20px;
    box-sizing: border-box;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    pointer-events: auto;
}
#code-editor-def-vars-list.visible {
    display: flex;
    z-index: 20;
}
#code-editor-def-vars-list.def-vars-read-only {
    opacity: 0.85;
    pointer-events: none;
}
#code-editor-def-vars-list.def-vars-read-only .def-var-value-input,
#code-editor-def-vars-list.def-vars-read-only .def-var-bool-checkbox {
    pointer-events: none;
}
#code-editor-def-vars-list .def-var-separator {
    width: 100%;
    padding: 10px 0 6px 50px;
    margin-top: 4px;
    border-bottom: 1px solid rgba(0, 255, 0, 0.25);
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 1), 0 0 4px rgba(0, 0, 0, 1);
    pointer-events: none;
    flex-shrink: 0;
}

/* JSON/array tree editor (Slider mode only — under #code-editor-def-vars-list) */
#code-editor-def-vars-list .def-json-tree2 {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-top: 8px;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.25);
    box-sizing: border-box;
}
#code-editor-def-vars-list .def-json-tree2-root {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.92);
    margin-bottom: 6px;
}
#code-editor-def-vars-list .def-json-tree2-node {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    min-width: 0;
    gap: 2px;
}
#code-editor-def-vars-list .def-json-tree2-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 4px;
    column-gap: 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 4px 4px;
    border-radius: 8px;
}
#code-editor-def-vars-list .def-json-tree2-row:hover {
    background: rgba(99, 102, 241, 0.12);
}
#code-editor-def-vars-list .def-json-tree2-caret {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 10px;
    padding: 0;
}
#code-editor-def-vars-list .def-json-tree2-caret.spacer {
    opacity: 0.35;
    cursor: default;
}
#code-editor-def-vars-list .def-json-tree2-key {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    color: #d4af37;
    min-width: 0;
    flex: 0 1 auto;
    max-width: min(42%, 9rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#code-editor-def-vars-list .def-json-tree2-type {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(0,0,0,0.25);
    color: rgba(255,255,255,0.75);
    flex-shrink: 0;
}
#code-editor-def-vars-list .def-json-tree2-mini {
    margin-left: auto;
    display: inline-flex;
    gap: 4px;
}
#code-editor-def-vars-list .def-json-tree2-mini-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 7px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(16,185,129,0.22);
    color: rgba(255,255,255,0.92);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    line-height: 1;
}
#code-editor-def-vars-list .def-json-tree2-mini-btn.danger {
    background: rgba(239,68,68,0.22);
}
#code-editor-def-vars-list .def-json-tree2-children {
    margin-left: 10px;
    padding-left: 10px;
    border-left: 1px solid rgba(255,255,255,0.12);
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}
#code-editor-def-vars-list .def-json-tree2-leaf {
    padding: 4px 0 8px 0;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}
#code-editor-def-vars-list .def-json-tree2-leaf-line {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
    min-height: 36px;
    padding: 6px 4px;
    box-sizing: border-box;
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}
#code-editor-def-vars-list .def-json-tree2-leaf-line:hover {
    background: rgba(99, 102, 241, 0.08);
}
#code-editor-def-vars-list .def-json-tree2-leaf-line .def-json-tree2-mini {
    margin-left: auto;
    flex-shrink: 0;
}
/* Nested JSON tree: override top-level .def-var-slide (absolute name, fixed height) */
#code-editor-def-vars-list .def-json-tree2 .def-json-tree2-leaf-line .def-json-tree2-num-slide.def-var-slide {
    flex: 0 0 clamp(70px, 22%, 120px);
    height: 32px;
    min-height: 32px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
#code-editor-def-vars-list .def-json-tree2 .def-json-tree2-leaf-line .def-json-tree2-num-slide.def-var-slide::after {
    content: '↔';
    font-size: 11px;
    color: rgba(0, 255, 0, 0.45);
    pointer-events: none;
}
#code-editor-def-vars-list .def-json-tree2 .def-json-tree2-leaf-line .def-var-value-input {
    flex: 1 1 80px;
    min-width: 72px;
    max-width: none;
    width: auto;
    height: 32px;
    flex-shrink: 1;
}
#code-editor-def-vars-list .def-json-tree2 .def-json-tree2-leaf-line .def-json-tree2-string-inp {
    flex: 1 1 120px;
    min-width: 72px;
    text-align: left;
}
/* Bool switch in tree rows: do not use margin-left:auto (meant for top-level def rows only) */
#code-editor-def-vars-list .def-json-tree2-leaf-line .def-var-bool-switch {
    margin-left: 0;
    flex-shrink: 0;
}
#code-editor-def-vars-list .def-json-tree2-leafpad {
    margin-left: 18px;
    padding-left: 8px;
    border-left: 1px solid rgba(255,255,255,0.10);
}

#code-editor-def-vars-list .def-var-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: calc(44px * 0.7);
    padding: calc(6px * 0.7) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    gap: 12px;
}
#code-editor-def-vars-list .def-var-slide {
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    flex: 1;
    min-width: 0;
    height: calc(36px * 0.7);
    cursor: ew-resize;
    user-select: none;
    touch-action: none;
    -webkit-user-select: none;
    background: rgba(0, 255, 0, 0.08);
    border: 1px solid rgba(0, 255, 0, 0.3);
    border-radius: 6px;
    color: rgba(0, 255, 0, 0.6);
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    position: relative;
}
#code-editor-def-vars-list .def-var-slide-name {
    position: absolute;
    left: 8px;
    bottom: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    color: #daa520;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 4px rgba(0, 0, 0, 0.7), 1px 1px 0 rgba(0, 0, 0, 0.8);
    pointer-events: none;
    line-height: 1;
}
#code-editor-def-vars-list .def-var-slide-hint {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(0, 255, 0, 0.85);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    line-height: 1;
}
#code-editor-def-vars-list .def-var-slide:hover {
    background: rgba(0, 255, 0, 0.12);
    color: rgba(0, 255, 0, 0.85);
}
#code-editor-def-vars-list .def-var-slide-spacer {
    flex: 1;
    min-width: 0;
    pointer-events: none;
}
#code-editor-def-vars-list .def-var-slide .def-var-help-btn {
    margin-left: auto;
    align-self: center;
    flex-shrink: 0;
}
#code-editor-def-vars-list .def-var-slide-non-numeric {
    cursor: default;
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.6);
}
#code-editor-def-vars-list .def-var-slide-non-numeric .def-var-slide-name {
    color: #daa520;
}
#code-editor-def-vars-list .def-var-bool-name {
    color: #daa520;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    flex-shrink: 0;
}
/* Boolean toggle switch in def vars list */
#code-editor-def-vars-list .def-var-bool-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
    margin-left: auto;
}
#code-editor-def-vars-list .def-var-bool-checkbox {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
#code-editor-def-vars-list .def-var-bool-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.2);
    transition: all 0.25s ease;
    border-radius: 24px;
    border: 1px solid rgba(0, 255, 0, 0.35);
}
#code-editor-def-vars-list .def-var-bool-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: all 0.25s ease;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}
#code-editor-def-vars-list .def-var-bool-checkbox:checked + .def-var-bool-slider {
    background: linear-gradient(135deg, rgba(0, 255, 0, 0.7) 0%, rgba(0, 200, 0, 0.85) 100%);
    border-color: rgba(0, 255, 0, 0.6);
}
#code-editor-def-vars-list .def-var-bool-checkbox:checked + .def-var-bool-slider:before {
    transform: translateX(20px);
}
#code-editor-def-vars-list .def-var-bool-checkbox:focus + .def-var-bool-slider {
    box-shadow: 0 0 0 2px rgba(0, 255, 0, 0.3);
}
#code-editor-def-vars-list .def-var-bool-switch:hover .def-var-bool-slider {
    background-color: rgba(255, 255, 255, 0.28);
    border-color: rgba(0, 255, 0, 0.5);
}
#code-editor-def-vars-list .def-var-bool-checkbox:checked:hover + .def-var-bool-slider {
    background: linear-gradient(135deg, rgba(0, 255, 0, 0.85) 0%, rgba(0, 255, 0, 0.7) 100%);
}
#code-editor-def-vars-list .def-var-value-input {
    width: 72px;
    min-width: 72px;
    height: calc(32px * 0.7);
    padding: calc(4px * 0.7) 8px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(0, 255, 0, 0.35);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.95);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    text-align: right;
    flex-shrink: 0;
}
#code-editor-def-vars-list .def-var-value-input:focus {
    outline: none;
    border-color: rgba(0, 255, 0, 0.7);
    box-shadow: 0 0 0 2px rgba(0, 255, 0, 0.2);
}
#code-editor-def-vars-list .def-var-value {
    color: rgba(255, 255, 255, 0.5);
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    flex-shrink: 0;
}

#code-editor-def-vars-list .def-var-color-hash {
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.25);
}
#code-editor-def-vars-list .def-var-color-hash:hover {
    border-color: rgba(0, 255, 0, 0.5);
    box-shadow: 0 0 0 1px rgba(0, 255, 0, 0.3);
}

#code-editor-def-vars-list .def-var-sprite-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
}
#code-editor-def-vars-list .def-var-sprite-btn:hover {
    background: rgba(0, 255, 0, 0.2);
    border-color: rgba(0, 255, 0, 0.5);
}

#code-editor-def-vars-list .def-var-help-btn {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    padding: 0;
    border: 1px solid rgba(0, 255, 0, 0.4);
    border-radius: 50%;
    background: rgba(0, 255, 0, 0.15);
    color: rgba(0, 255, 0, 0.9);
    font-size: 0.75rem;
    font-weight: 700;
    font-style: italic;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}
#code-editor-def-vars-list .def-var-help-btn:hover {
    background: rgba(0, 255, 0, 0.25);
    border-color: rgba(0, 255, 0, 0.6);
}

/* Popover may be in def list or moved to body for correct fixed positioning */
#code-editor-def-vars-list .def-var-help-popover,
.def-var-help-popover {
    position: fixed;
    max-width: 260px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.92);
    border: 1px solid rgba(0, 255, 0, 0.4);
    border-radius: 6px;
    color: #e2e8f0;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.35;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 10020;
    white-space: pre-wrap;
    word-break: break-word;
}

/* SFX picker: above editor bottom bars (10000), keyboard/console (10001+), stage menu (10005), side panel when open (10100), def-var popovers (10020) */
#sfx-selection-modal-overlay {
    z-index: 10200 !important;
}

/* Slider mode button: hidden (Spaces only) */
#code-editor-edit-btn {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Spaces mode button: directly above Quick Test on mobile left rail */
#code-editor-spaces-btn {
    width: 43.2px;
    height: 48px;
    padding: 4px;
    left: 0;
    right: auto;
    top: auto;
    transform: translateY(-30px);
    border-radius: 0 12px 12px 0;
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
    font-size: 1.1rem;
    z-index: 900;
    transition: none;
}
#code-editor-spaces-btn .panel-btn-emoji { font-size: 1.25rem; line-height: 1; }
#code-editor-spaces-btn .panel-btn-label { font-size: 0.65rem; font-weight: 500; line-height: 1; }
#code-editor-spaces-btn:hover { background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%); }
#code-editor-spaces-btn:active { background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%); }
body:not([data-game-mode="stageEditor"]) #code-editor-spaces-btn {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}
/* Mobile only: hide floating Spaces while the stage drawer covers the left rail */
@media not ((hover: hover) and (pointer: fine)) {
    body.stage-side-panel-open #code-editor-spaces-btn {
        display: none !important;
    }
}

/* Hide buttons container for code object editor (Run button and dropdowns) */
#code_object_editor_buttons_container {
    display: none !important;
}

/* Code area grows; Problems strip stays visible at bottom (not clipped by overflow:hidden parent) */
#code_object_editor_wrapper {
    flex: 1 !important;
    min-height: 0 !important;
    height: auto !important;
}

/* Shared scroll host: highlight + textarea move together (native scroll = costless).
   A hidden <pre> sizer drives content width/height so long lines are not clipped. */
.code-editor-scroll-host {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}
.code-editor-layers {
    position: relative;
    min-width: 100%;
    min-height: 100%;
    width: max-content;
    box-sizing: border-box;
}
.code-editor-sizer {
    margin: 0;
    padding: 4px;
    box-sizing: border-box;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.15;
    white-space: pre;
    tab-size: 4;
    visibility: hidden;
    pointer-events: none;
    display: block;
}
.code-editor-highlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
}
.code-editor-highlight-layer .highlight-inner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
.code-editor-scroll-host textarea.code-editor-textarea {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden !important;
    resize: none;
    z-index: 2;
}

/* Highlight lines use flat HTML in .highlight-inner (white-space: pre). */

/* Android code editor: ~4 lines of scroll room past last line (no fake newlines in the file) */
textarea.code-editor-android-scroll-pad,
pre.code-editor-sizer.code-editor-android-scroll-pad {
    padding-bottom: calc(4px + 1.15em * 4) !important;
}
.highlight-inner.code-editor-android-scroll-pad-inner {
    padding-bottom: calc(4px + 1.15em * 4) !important;
}

/* Scrollbar on shared host */
#code_object_editor_wrapper .code-editor-scroll-host,
#code-object-editor-panel .code-editor-scroll-host {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.16) rgba(0, 0, 0, 0.35);
}
#code_object_editor_wrapper .code-editor-scroll-host::-webkit-scrollbar,
#code-object-editor-panel .code-editor-scroll-host::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
#code_object_editor_wrapper .code-editor-scroll-host::-webkit-scrollbar-track,
#code-object-editor-panel .code-editor-scroll-host::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
}
#code_object_editor_wrapper .code-editor-scroll-host::-webkit-scrollbar-thumb,
#code-object-editor-panel .code-editor-scroll-host::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* Make code object editor container fill 100% */
#code_object_editor_container {
    height: 100% !important;
    flex: 1 !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Compile problems use #code-editor-problems-strip on the panel — hide duplicate in-editor bar */
#code_object_editor_error_display {
    display: none !important;
}

/* Compile problems: max 2 lines at bottom of code editor panel */
.code-editor-problems-strip {
    flex-shrink: 0;
    display: none;
    padding: 6px 12px;
    margin: 0;
    background: rgba(127, 29, 29, 0.95);
    border-top: 2px solid #ef4444;
    color: #fecaca;
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1.3;
    text-align: left;
    white-space: pre-line;
    word-break: break-word;
    max-height: calc(1.3em * 2 + 12px);
    overflow: hidden;
    z-index: 25;
}

.code-editor-problem-line-overlay {
    position: absolute;
    left: 0;
    right: 0;
    pointer-events: none;
    z-index: 1;
    background: rgba(239, 68, 68, 0.35);
    box-shadow: inset 3px 0 0 #ef4444;
    display: none;
}

/* Shift enemy editor top-left buttons when side panel is open */
body.side-panel-open #menu-button,
body.side-panel-open #attacks-button,
body.side-panel-open #enemy-settings-btn,
body.side-panel-open #clear-bullets-btn {
    margin-left: 0 !important; /* panel opens on right now */
}

/* Shift stage editor top-left buttons when side panel is open */
body.stage-side-panel-open #stage-editor-menu-btn,
body.stage-side-panel-open #stage-editor-help-btn,
body.stage-side-panel-open #stage-editor-portal-btn,
body.stage-side-panel-open #add-spawner-btn,
body.stage-side-panel-open #test-stage-btn {
    margin-left: 0 !important; /* panel opens on right now */
}

@media (max-width: 768px) {
    /* Match smaller panel width from responsive rules */
    body.side-panel-open #menu-button,
    body.side-panel-open #attacks-button,
    body.side-panel-open #enemy-settings-btn,
    body.side-panel-open #clear-bullets-btn {
        margin-left: 0 !important; /* panel opens on right now */
    }
    
    body.stage-side-panel-open #stage-editor-menu-btn,
    body.stage-side-panel-open #stage-editor-help-btn,
    body.stage-side-panel-open #stage-editor-portal-btn,
    body.stage-side-panel-open #add-spawner-btn,
    body.stage-side-panel-open #test-stage-btn {
        margin-left: 0 !important; /* panel opens on right now */
    }
}

.side-panel-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
}

.side-panel-title {
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.side-panel-content {
    padding: 1.5rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Stage editor: filesystem grows; control stack pinned to bottom (margin-top: auto) */
#stage-editor-side-panel .side-panel-content {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.5rem;
    overflow: hidden;
    /* less bottom padding so buttons sit visually at the “bottom” of the panel */
    padding: 1.5rem 1.5rem max(0.4rem, env(safe-area-inset-bottom, 0px)) 1.5rem;
    box-sizing: border-box;
}

#stage-editor-side-panel .side-panel-section {
    margin-bottom: 0; /* override global 2rem; gap handles spacing */
}

#stage-editor-side-panel .stage-editor-side-panel-split--controls {
    flex: 0 0 auto;
    min-height: 0;
    margin-top: auto; /* always flush to bottom of .side-panel-content */
    overflow: visible;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-self: stretch;
    width: 100%;
}

#stage-editor-side-panel .stage-editor-side-panel-split--files {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    align-self: stretch;
    width: 100%;
    /* full width of side panel: cancel .side-panel-content horizontal padding (1.5rem) */
    margin-left: -1.5rem;
    margin-right: -1.5rem;
    width: calc(100% + 3rem);
    box-sizing: border-box;
}

#stage-editor-side-panel .stage-editor-side-panel-split--controls .side-panel-section h3 {
    margin: 0 0 0.4rem 0;
}

#stage-editor-side-panel .stage-editor-side-panel-split--files .side-panel-section h3 {
    flex-shrink: 0;
    margin: 0 0 0.35rem 0;
    padding: 0 0.75rem;
    box-sizing: border-box;
}

/* Stage editor: objects section consumes remaining height */
#stage-editor-side-panel .stage-objects-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.side-panel-section {
    margin-bottom: 2rem;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden; /* Prevent overflow */
}

.stage-controls-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    width: 100%;
    box-sizing: border-box;
    flex-wrap: wrap; /* Allow wrapping if needed */
}

/* Stage editor side panel: vertical list of buttons */
.stage-controls-list {
    list-style: none;
    list-style-type: none;
    padding: 0;
    padding-inline-start: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    box-sizing: border-box;
}

/* Plain list: no bullets/markers (editor side menu) */
.stage-controls-list-plain li,
.stage-controls-list-plain {
    list-style: none;
    list-style-type: none;
}

.stage-controls-list-plain li::marker {
    content: none;
}

.stage-controls-list li {
    list-style: none;
    list-style-type: none;
    margin: 0;
    padding: 0;
    width: 100%;
}

#stage-editor-side-panel .stage-controls-list {
    gap: 0.375rem; /* 0.3125rem +20% */
}

#stage-editor-side-panel .stage-controls-list-tools {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    width: 100%;
    box-sizing: border-box;
}

#stage-editor-side-panel .stage-controls-row {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    width: 100%;
    box-sizing: border-box;
    gap: 7px;
    flex-wrap: nowrap;
}

#stage-editor-side-panel .game-control-btn {
    width: 100%;
    min-width: 0;
    margin-bottom: 0;
    min-height: 36px; /* 30px +20% */
    padding: 7px 11px; /* 6×9px +20% */
    font-size: 0.8rem;
    border-radius: 6px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 7px; /* 6px +20% */
    text-align: left;
    box-sizing: border-box;
    overflow: hidden;
}

#stage-editor-side-panel .panel-btn-emoji {
    font-size: 0.9rem;
    line-height: 1;
    flex-shrink: 0;
}

#stage-editor-side-panel .panel-btn-label {
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.2;
    opacity: 0.95;
    flex: 1 1 0;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#stage-editor-side-panel .game-control-btn.stage-editor-dragonbones-btn {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
}

#stage-editor-side-panel .game-control-btn.stage-editor-dragonbones-btn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

/* PC: no floating Spaces — use header Spaces in the floating code editor */
@media (hover: hover) and (pointer: fine) {
    #code-editor-spaces-btn {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}

#stage-editor-side-panel .stage-controls-row:not(.stage-controls-row--full) .game-control-btn {
    flex: 1;
    width: auto;
    min-width: 0;
}

#stage-editor-side-panel .stage-controls-row.stage-controls-row--full .game-control-btn {
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
}

.side-panel-section h3 {
    color: #d1d5db;
    font-size: 1rem;
    font-weight: 500;
    margin: 0 0 1rem 0;
}

.game-control-btn {
    width: 100%;
    max-width: 100%; /* Never exceed container width */
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0.75rem;
    box-sizing: border-box;
    overflow: hidden; /* Prevent content overflow */
}

.game-control-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.game-control-btn.danger {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
}

.game-control-btn.danger:hover {
    background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.game-control-btn.secondary {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
}

.game-control-btn.secondary:hover {
    background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
    box-shadow: 0 4px 12px rgba(107, 114, 128, 0.3);
}

/* Mode-aware visibility for quick panel buttons */
body:not([data-game-mode="editor"]) #menu-button,
body:not([data-game-mode="editor"]) #attacks-button,
body:not([data-game-mode="editor"]) #enemy-settings-btn,
body:not([data-game-mode="editor"]) #clear-bullets-btn {
    display: none !important;
}

/* Hide and disable settings panels in title screen/menu mode */
body[data-game-mode="title"] #enemy-settings-panel,
body:has(#title-screen[style*="flex"]) #enemy-settings-panel,
body.title-screen-visible #enemy-settings-panel {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Hide code editor panel and tabs in title screen/menu mode */
body[data-game-mode="title"] #code-object-editor-panel,
body:has(#title-screen[style*="flex"]) #code-object-editor-panel,
body.title-screen-visible #code-object-editor-panel,
body[data-game-mode="title"] #code-editor-tabs,
body:has(#title-screen[style*="flex"]) #code-editor-tabs,
body.title-screen-visible #code-editor-tabs {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Town lobby (data-in-lobby): never show code editor UI */
body[data-in-lobby="true"] #code-object-editor-panel,
body[data-in-lobby="true"] #code-object-editor-container,
body[data-in-lobby="true"] #code-editor-tabs,
body[data-in-lobby="true"] #code-editor-close-btn,
body[data-in-lobby="true"] #code-editor-test-btn,
body[data-in-lobby="true"] #code-editor-edit-btn,
body[data-in-lobby="true"] #code-editor-spaces-btn,
body[data-in-lobby="true"] #code-editor-add-point-btn,
body[data-in-lobby="true"] #code-editor-directions-btn,
body[data-in-lobby="true"] #code-editor-delete-point-btn {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Never show code-object editor UI outside editor/stageEditor modes */
body:not([data-game-mode="editor"]):not([data-game-mode="stageEditor"]) #code-object-editor-panel,
body:not([data-game-mode="editor"]):not([data-game-mode="stageEditor"]) #code-object-editor-container,
body:not([data-game-mode="editor"]):not([data-game-mode="stageEditor"]) #code-editor-tabs {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Allow settings panels to be shown in editor mode (override title screen rules) */
/* Visibility controlled by JavaScript in editor modes */

/* Editor Buttons Bar Container - Always visible at bottom */
#editor-buttons-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 36px;
    display: none; /* Hidden by default, shown in editor mode */
    flex-direction: row;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none; /* Firefox - hide scrollbar */
    -ms-overflow-style: none; /* IE and Edge - hide scrollbar */
    z-index: 10000; /* Above keyboard and other UI */
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%); /* Purple to purple-blue gradient */
    border-top: 2px solid rgba(255, 255, 255, 0.2); /* Outline at top */
    pointer-events: none;
    padding-left: 38.4px; /* Reserve space for fixed console button */
    padding-right: 38.4px; /* Reserve space for fixed keyboard button */
    box-sizing: border-box;
}

/* Custom scrollbar styling for button bars - hidden */
#editor-buttons-bar::-webkit-scrollbar,
#stage-editor-buttons-bar::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera - hide scrollbar */
    width: 0;
    height: 0;
    background: transparent;
}

body[data-game-mode="editor"] #editor-buttons-bar {
    display: flex !important;
}

/* Stage Editor Buttons Bar Container - Always visible at bottom */
#stage-editor-buttons-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 36px;
    display: none; /* Hidden by default, shown in stage editor mode */
    flex-direction: row;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none; /* Firefox - hide scrollbar */
    -ms-overflow-style: none; /* IE and Edge - hide scrollbar */
    z-index: 10000; /* Above keyboard and other UI */
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%); /* Purple to purple-blue gradient */
    border-top: 2px solid rgba(255, 255, 255, 0.2); /* Outline at top */
    pointer-events: none;
    padding-left: 38.4px; /* Reserve space for fixed console button */
    padding-right: 38.4px; /* Reserve space for fixed keyboard button */
    box-sizing: border-box;
}

body[data-game-mode="stageEditor"] #stage-editor-buttons-bar {
    display: flex !important;
}

/* PC: solid bottom bar (inline HTML sets transparent; gaps between buttons looked empty) */
@media (hover: hover) and (pointer: fine) {
    #editor-buttons-bar,
    #stage-editor-buttons-bar {
        background: linear-gradient(135deg, #1f2937 0%, #111827 100%) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.18) !important;
    }
}

/* Shared base styles for buttons in bars - 25% smaller height, icon left to text */
#editor-buttons-bar button,
#stage-editor-buttons-bar button {
    position: relative;
    flex: 0 0 auto;
    height: 100%; /* Stretch to fill bar height */
    min-height: 36px; /* Minimum height */
    min-width: fit-content;
    white-space: nowrap;
    border: none;
    border-radius: 0;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    margin: 0;
    box-sizing: border-box;
    pointer-events: auto !important;
    touch-action: manipulation;
    font-family: inherit;
    outline: none;
}


/* No rounded corners on buttons */
#editor-buttons-bar button,
#stage-editor-buttons-bar button {
    border-radius: 0;
}

/* Button emoji and text side by side styling */
.button-emoji {
    font-size: 1.1rem;
    line-height: 1;
}

.button-text {
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Hide text in console buttons - show only emoji */
#console-button .button-text,
#stage-editor-console-btn .button-text,
#test-stage-btn .button-text {
    display: none;
}

/* Make console buttons fixed on the left side (not scrollable) */
#console-button,
#stage-editor-console-btn,
#test-stage-btn {
    position: fixed !important;
    left: 0 !important;
    bottom: 0 !important;
    height: 36px !important;
    flex: 0 0 auto !important;
    width: 38.4px !important;
    min-width: 38.4px !important;
    z-index: 10001 !important; /* Above scrollable buttons */
    background: #1f2937 !important; /* Match other buttons in bar */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    border-top: 2px solid rgba(255, 255, 255, 0.2) !important; /* Match button bar border */
    pointer-events: auto !important;
    cursor: pointer !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 0 12px !important;
    box-sizing: border-box !important;
    touch-action: manipulation !important;
    transition: all 0.2s ease !important;
}

#test-stage-btn {
    left: auto !important;
    right: 0 !important; /* Flush to right edge */
    z-index: 10002 !important; /* Keep visible above neighboring fixed controls */
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

#test-stage-btn .button-emoji {
    display: inline-block !important;
}

/* Reserve room for fixed console + fixed test-stage buttons */
#stage-editor-buttons-bar {
    padding-left: 38.4px !important; /* Fixed console button on the left */
    padding-right: 76.8px !important; /* Fixed test-stage + keyboard buttons on the right */
}

/* PC: Test Stage is a normal bar button next to Search (not fixed on the right) */
@media (hover: hover) and (pointer: fine) {
    #test-stage-btn {
        position: relative !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        width: auto !important;
        min-width: fit-content !important;
        height: 100% !important;
        z-index: auto !important;
        box-shadow: none !important;
        border-top: none !important;
        transform: none !important;
    }
    #test-stage-btn .button-text {
        display: inline !important;
    }
    #test-stage-btn:hover,
    #test-stage-btn:active {
        transform: none !important;
    }
    #stage-editor-buttons-bar {
        padding-right: 38.4px !important; /* only keyboard reserve if present */
    }
}

/* Console button hover states */
#console-button:hover,
#stage-editor-console-btn:hover,
#test-stage-btn:hover {
    transform: translateY(-1px) !important;
    filter: brightness(1.1) !important;
    background: #374151 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
}

#console-button:active,
#stage-editor-console-btn:active,
#test-stage-btn:active {
    transform: translateY(0) !important;
    filter: brightness(0.95) !important;
}

/* Test Stage running: green background (Stop Test) */
#test-stage-btn.test-stage-active {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%) !important;
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.45) !important;
    border-top-color: rgba(255, 255, 255, 0.25) !important;
}

#test-stage-btn.test-stage-active:hover {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%) !important;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.5) !important;
}

#test-stage-btn.test-stage-active:active {
    filter: brightness(0.95) !important;
}

/* Make console button red when there are unseen errors */
#console-button.has-unseen-errors,
#stage-editor-console-btn.has-unseen-errors {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4) !important;
    animation: pulse-red 2s ease-in-out infinite;
}

#console-button.has-unseen-errors:hover,
#stage-editor-console-btn.has-unseen-errors:hover {
    background: linear-gradient(135deg, #f87171 0%, #ef4444 100%) !important;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.6) !important;
}

/* Manual Keyboard Button (Fixed on right) */
#manual-keyboard-btn {
    position: fixed !important;
    right: 0 !important;
    bottom: 0 !important;
    height: 36px !important;
    flex: 0 0 auto !important;
    width: 38.4px !important;
    min-width: 38.4px !important;
    z-index: 10001 !important;
    background: #1f2937 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    border-top: 2px solid rgba(255, 255, 255, 0.2) !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    display: none; /* Controlled by JS */
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 0 12px !important;
    box-sizing: border-box !important;
    touch-action: manipulation !important;
    transition: all 0.2s ease !important;
    border-radius: 0 !important;
    border: none !important;
    border-top: 2px solid rgba(255, 255, 255, 0.2) !important;
}

#manual-keyboard-btn:hover {
    transform: translateY(-1px) !important;
    filter: brightness(1.1) !important;
    background: #374151 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
}

#manual-keyboard-btn:active {
    transform: translateY(0) !important;
    filter: brightness(0.95) !important;
}

@keyframes pulse-red {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    }
    50% {
        box-shadow: 0 2px 12px rgba(239, 68, 68, 0.7);
    }
}

/* Individual button colors - all buttons use same solid color as code editor bar (fully opaque, no gradient) */
#editor-buttons-bar button,
#stage-editor-buttons-bar button {
    background: #1f2937;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Stage Editor Menu Button (separate, floating) */
#stage-editor-menu-btn {
    position: fixed;
    left: auto;
    right: 0;
    top: auto;
    /* bottom is controlled by JavaScript in updateCodeEditorPosition() */
    transform: translateY(-30px); /* Move 30px higher (was -80px, adjusted down 50px) */
    width: 43.2px;
    height: 48px;
    border: none;
    border-radius: 12px 0 0 12px;
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
    z-index: 10005; /* Above side panel (10004), below modals */
    opacity: 0.6;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    transition: none; /* No animations */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px;
    box-sizing: border-box;
    margin: 0;
    pointer-events: auto !important;
    touch-action: manipulation;
}

/* Side panels now open from the right: align menu button with panel left edge, full opacity */
body.stage-side-panel-open #stage-editor-menu-btn {
    right: var(--stage-side-panel-w, 70%) !important; /* Align with panel left edge */
    display: flex !important; /* Ensure menu button is visible */
    opacity: 1 !important;
}

@media (max-width: 768px) {
    body.stage-side-panel-open #stage-editor-menu-btn {
        right: var(--stage-side-panel-w, 70%) !important;
        display: flex !important;
        opacity: 1 !important;
    }
}

/* +Spawner button removed from top UI (moved to code-object context menu) */
#add-spawner-btn {
    display: none !important;
}

/* Hover states for buttons in bars */
#editor-buttons-bar button:hover,
#stage-editor-buttons-bar button:hover {
    transform: translateY(-1px);
    filter: brightness(1.1);
}

#editor-buttons-bar button:active,
#stage-editor-buttons-bar button:active {
    transform: translateY(0);
    filter: brightness(0.95);
}

/* Hover colors - slightly lighter version of code editor bar color (fully opaque, no gradient) */
#editor-buttons-bar button:hover,
#stage-editor-buttons-bar button:hover {
    background: #374151;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Stage editor menu button hover - no animations */
#stage-editor-menu-btn:hover {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%); /* Same as default */
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3); /* Same as default */
    transform: translateY(-30px); /* Same as default */
}

#stage-editor-menu-btn:active {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%); /* Same as default */
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3); /* Same as default */
    transform: translateY(-30px); /* Same as default */
}

/* Other button hover states */
#new-emitter-button:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    box-shadow: 0 8px 20px rgba(245, 158, 11, 0.4);
}

/* Visibility rules for stage editor buttons */
body:not([data-game-mode="stageEditor"]) #stage-editor-menu-btn,
body:not([data-game-mode="stageEditor"]) #stage-editor-buttons-bar {
    display: none !important;
}

body[data-game-mode="stageEditor"] #stage-editor-menu-btn {
    display: flex !important;
}

/* Hide individual buttons when not in their respective modes */
body:not([data-game-mode="editor"]) #editor-buttons-bar {
    display: none !important;
}

body:not([data-game-mode="stageEditor"]) #stage-editor-buttons-bar {
    display: none !important;
}

/* Objects button in bottom bar: never change color (no state/hover/active) */
#stage-editor-objects-btn,
#stage-editor-objects-btn:hover,
#stage-editor-objects-btn:active {
    background: #1f2937 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    transform: none !important;
    filter: none !important;
}

/* Stage editor: place-objects panel — docked to bottom, above buttons bar / manual KB (covers bottom UI) */
#objects-placing-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    z-index: 10100;
    max-height: min(280px, 48vh);
    box-sizing: border-box;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    box-shadow:
        0 -8px 32px rgba(0, 0, 0, 0.5),
        0 -2px 0 rgba(255, 255, 255, 0.06) inset;
    background: linear-gradient(135deg, rgba(17, 24, 39, 0.8) 0%, rgba(31, 41, 55, 0.8) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

#objects-placing-panel::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

#objects-placing-panel::-webkit-scrollbar-track {
    background: transparent;
}

#objects-placing-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 4px;
}

#objects-placing-panel .objects-placing-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    flex-shrink: 0;
}

#objects-placing-panel .objects-placing-title {
    flex: 1;
    margin: 0;
    padding: 0 8px 0 0;
    color: #f1f5f9;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.25;
}

#objects-placing-panel .objects-placing-close {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    padding: 0;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
}

#objects-placing-panel .objects-placing-close:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.32);
}

#objects-placing-panel #objects-placing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    grid-template-rows: repeat(2, minmax(60px, auto));
    gap: 8px;
    max-width: 100%;
}

#objects-placing-panel .objects-placing-tile {
    box-sizing: border-box;
    min-height: 44px;
    padding: clamp(8px, 2vw, 12px) clamp(4px, 1.5vw, 8px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    color: #e2e8f0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: clamp(11px, 3vw, 13px);
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    word-break: break-word;
    overflow-wrap: break-word;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

#objects-placing-panel .objects-placing-tile:hover:not(.objects-placing-tile--selected) {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
}

#objects-placing-panel .objects-placing-tile--selected {
    background: rgba(16, 185, 129, 0.42);
    border-color: rgba(16, 185, 129, 0.75);
    color: #f0fdf4;
    box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.35);
}

@media (max-width: 480px) {
    #objects-placing-panel #objects-placing-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        grid-template-rows: repeat(2, minmax(56px, auto));
        gap: 6px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    #objects-placing-panel #objects-placing-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    }
}

@media (min-width: 769px) {
    #objects-placing-panel #objects-placing-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

/* +Spawner button is permanently removed from UI */
body[data-game-mode="stageEditor"] #add-spawner-btn,
#add-spawner-btn {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Forum contenteditable editor placeholder */
.forum-editor-empty::before {
    content: attr(data-placeholder);
    color: rgba(255, 255, 255, 0.5);
    pointer-events: none;
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
}

#forum-thread-content-input.forum-editor-empty::before {
    top: 1.5rem;
    left: 1.5rem;
}

.forum-editor-empty:focus::before {
    display: none;
}









/* Settings Panel Styles - Removed (emitter system removed) */

.tabs { 
    display: flex; 
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px 12px 0 0;
    overflow: hidden; /* Prevent tabs from scrolling */
    flex-shrink: 0; /* Prevent tabs from shrinking */
}

.tab {
    padding: 0.75rem 1rem;
    cursor: pointer;
    color: #9ca3af;
    background-color: transparent;
    border: none;
    outline: none;
    flex-grow: 1;
    font-weight: 500;
    transition: all 0.2s ease;
    border-radius: 12px 12px 0 0;
}

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

.tab.active {
    color: white;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(7.5px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.tab-content { 
    padding: 1.5rem; 
    max-height: calc(37.5vh - 60px); /* Account for tabs height */
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1; /* Take remaining space */
    min-height: 0; /* Allow flex item to shrink below content size */
    width: 100%;
    box-sizing: border-box;
}

/* Emitter code editor styles removed - emitter system removed */

/* Ensure tab panes take full width */
.tab-pane {
    width: 100%;
    box-sizing: border-box;
}

/* Custom scrollbar styling with 0.2 opacity */
.tab-content::-webkit-scrollbar {
    width: 8px;
}

.tab-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.tab-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.tab-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Firefox scrollbar styling */
.tab-content {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.05);
}

/* Enemy settings panel - same structure as settings panel */
#enemy-settings-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, rgba(17, 24, 39, 0.5) 0%, rgba(31, 41, 55, 0.5) 100%);
    color: white;
    border-radius: 12px 12px 0 0;
    backdrop-filter: blur(7.5px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-bottom: none;
    width: 100%;
    max-height: 37.5vh;
    font-size: 0.875rem;
    box-shadow: 0 -20px 25px -5px rgba(0, 0, 0, 0.3), 0 -10px 10px -5px rgba(0, 0, 0, 0.2);
    z-index: 150;
    overflow: hidden; /* Prevent panel from scrolling - only tab-content scrolls */
    opacity: 1;
}

/* When enemy settings panel is visible, use flex layout and ensure it's on-screen */
#enemy-settings-panel:not([style*="display: none"]) {
    display: flex;
    flex-direction: column;
    transform: translateY(0);
    bottom: 0;
}

/* When enemy settings panel is hidden, override to none and ensure it's off-screen */
#enemy-settings-panel[style*="display: none"] {
    display: none !important;
    pointer-events: none !important;
    transform: translateY(100%) !important;
    bottom: -100vh !important;
}

/* Ensure enemy settings panel tab-content also scrolls properly */
#enemy-settings-panel .tab-content {
    padding: 1.5rem; 
    max-height: calc(37.5vh - 60px); /* Account for cancel button space */
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1; /* Take remaining space */
    min-height: 0; /* Allow flex item to shrink below content size */
    width: 100%;
    box-sizing: border-box;
}

/* Ensure enemy settings tab takes full width */
#enemy-settings-tab {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Floating cancel button for enemy settings panel - always visible */
#enemy-settings-panel-cancel-btn {
    position: fixed !important;
    bottom: 10px !important;
    right: 10px !important;
    z-index: 151 !important;
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%) !important;
    color: #d1d5db !important;
    border: none !important;
    border-radius: 8px !important;
    padding: 10px 20px !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.2s ease !important;
}

#enemy-settings-panel-cancel-btn:hover {
    background: linear-gradient(135deg, #4b5563 0%, #374151 100%) !important;
    transform: scale(1.05) !important;
}

#enemy-settings-panel-cancel-btn:active {
    transform: scale(0.95) !important;
}

/* Hide cancel button when panel is hidden */
#enemy-settings-panel[style*="display: none"] #enemy-settings-panel-cancel-btn {
    display: none !important;
}

.tab-pane { 
    display: none !important; 
    visibility: hidden !important;
}
.tab-pane.active { 
    display: block !important; 
    visibility: visible !important;
}

/* Ensure tab panes with settings-grid use grid layout */
.tab-pane.settings-grid.active,
.tab-pane.settings-grid[style*="display: grid"],
#enemy-settings-tab.settings-grid,
#enemy-settings-tab.settings-grid.active {
    display: grid !important;
    visibility: visible !important;
}

/* Override any inline block styles for settings-grid tabs */
.tab-pane.settings-grid[style*="display: block"] {
    display: grid !important;
}

.setting { 
    margin-bottom: 1rem; 
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

.setting.setting-selected {
    border-color: rgba(248, 113, 113, 0.9);
    background: rgba(248, 113, 113, 0.12);
.setting.setting-selected::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 6px;
    border: 1px solid rgba(248, 113, 113, 0.7);
    pointer-events: none;
}

.setting-setting-sensitivity {
    font-size: 0.7rem;
    color: rgba(248, 113, 113, 0.75);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 4px;
    display: none;
}

.setting.setting-selected .setting-setting-sensitivity {
    display: block;
}
    box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.3), 0 8px 20px rgba(248, 113, 113, 0.2);
}

.setting .label-line { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 0.5rem; 
}

.setting .input-group { 
    display: flex; 
    align-items: center; 
    gap: 6px; 
}

.setting label { 
    color: #d1d5db; 
    font-size: 0.875rem; 
    font-weight: 500;
}

.setting input[type="range"] {
    width: 100%;
    -webkit-appearance: none; 
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 9999px; 
    height: 8px; 
    outline: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.setting input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; 
    appearance: none;
    width: 18px; 
    height: 18px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    cursor: pointer; 
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    border: 2px solid white;
    margin-top: -7px;
    box-sizing: border-box;
}

.setting input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    cursor: pointer;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    border: 2px solid white;
    box-sizing: border-box;
}

.setting input[type="range"]::-ms-thumb {
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    cursor: pointer;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    border: 2px solid white;
    margin-top: -7px;
    box-sizing: border-box;
}

.setting input[type="number"] {
    background: rgba(255, 255, 255, 0.1); 
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px; 
    color: white; 
    width: 45px;
    text-align: right; 
    font-size: 0.875rem; 
    padding: 4px 8px;
    transition: all 0.2s ease;
}

.setting input[type="number"]:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; margin: 0; 
}

input[type=number] { 
    -moz-appearance: textfield;
    appearance: textfield;
}

.textbox-setting {
    position: relative;
    padding: 0.75rem;
}


.textbox-setting .textbox-input-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.textbox-setting .textbox-input-group input[type="number"] {
    flex: 1;
    min-width: 0;
}

.textbox-setting .decrement-btn,
.textbox-setting .increment-btn-simple {
    flex-shrink: 0;
    min-width: 32px;
}

/* Settings container - 2 parameters per row */
/* Removed - now using .settings-grid class for grid layout */

.slider-setting {
    position: relative;
    padding: 0.4rem 0.75rem;
    display: flex;
    align-items: center;
}

.slider-setting .slider-label-edge {
    position: absolute;
    top: 0;
    left: 16px;
    transform: translateY(-60%);
    background: rgba(17, 24, 39, 0.95);
    border: 1px solid rgba(59, 130, 246, 0.4);
    color: #bfdbfe;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.slider-setting .slider-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.slider-setting .slider-range-wrapper {
    position: relative;
    flex: 1;
    height: 8px;
    display: flex;
    align-items: center;
}

.slider-setting .slider-range-wrapper::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

.slider-setting .slider-range-wrapper input[type="range"] {
    flex: 1;
    margin: 0;
    position: relative;
    z-index: 1;
    height: 4px;
    background: none;
    border: none;
}

.slider-setting .slider-range-wrapper input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: transparent;
    border: none;
}

.slider-setting .slider-range-wrapper input[type="range"]::-moz-range-track {
    height: 4px;
    background: transparent;
    border: none;
}

.slider-setting .slider-range-wrapper input[type="range"]::-ms-track {
    height: 4px;
    background: transparent;
    border: none;
    color: transparent;
}

.slider-setting .slider-input-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.slider-setting .slider-input-group input[type="number"] {
    width: 50px;
}

.increment-btn {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    color: white; 
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px; 
    padding: 6px 10px; 
    font-size: 0.75rem; 
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.increment-btn:hover {
    background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
    transform: translateY(-1px);
}

/* Double Slider Styles */
.double-slider { 
    position: relative; 
    height: 24px; 
    display: flex; 
    align-items: center; 
    margin-top: 8px; 
}

.double-slider .track { 
    position: absolute; 
    height: 8px; 
    width: 100%; 
    background: rgba(255, 255, 255, 0.1); 
    border-radius: 9999px; 
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.double-slider .range { 
    position: absolute; 
    height: 8px; 
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-radius: 9999px; 
}

.double-slider input[type="range"] {
    -webkit-appearance: none; 
    appearance: none; 
    position: absolute;
    width: 100%; 
    height: 8px; 
    background: none; 
    pointer-events: none; 
    margin: 0;
}

.double-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; 
    appearance: none; 
    width: 18px; 
    height: 18px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    cursor: pointer; 
    border-radius: 50%; 
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    border: 2px solid white;
    margin-top: -5px;
    box-sizing: border-box;
}

.double-slider input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    cursor: pointer;
    border-radius: 50%;
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    border: 2px solid white;
    box-sizing: border-box;
}

.double-slider input[type="range"]::-ms-thumb {
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    cursor: pointer;
    border-radius: 50%;
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    border: 2px solid white;
    margin-top: -5px;
    box-sizing: border-box;
}

input[type="color"] {
    -webkit-appearance: none; 
    -moz-appearance: none; 
    appearance: none;
    width: 32px; 
    height: 32px; 
    background-color: transparent;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    cursor: pointer; 
    padding: 0;
    transition: all 0.2s ease;
}

input[type="color"]:hover {
    border-color: #3b82f6;
    transform: scale(1.05);
}

input[type="color"]::-webkit-color-swatch {
    border-radius: 4px; 
    border: none;
}

.color-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.color-suggestions .color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: transparent;
    cursor: pointer;
    padding: 0;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.color-suggestions .color-swatch::before {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: currentColor;
}

.color-suggestions .color-swatch:hover,
.color-suggestions .color-swatch:focus-visible {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.35);
}

.color-suggestions .color-swatch.is-active {
    border-color: #ffffff;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
}

/* Bullet shape buttons */
.bullet-shape-group {
    gap: 6px;
}
.bullet-shape-btn {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.6);
    color: #e5e7eb;
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.bullet-shape-btn:hover {
    background: rgba(139, 92, 246, 0.4) !important;
    border-color: rgba(139, 92, 246, 0.6) !important;
    transform: translateY(-1px);
}
.bullet-shape-btn.is-active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.5) 0%, rgba(124, 58, 237, 0.4) 100%) !important;
    border-color: rgba(196, 181, 253, 1) !important;
    box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.7), 0 0 8px rgba(124, 58, 237, 0.75);
    transform: translateY(-1px);
}

.bullet-particles-shape-btn:hover {
    background: rgba(236, 72, 153, 0.4) !important;
    border-color: rgba(236, 72, 153, 0.6) !important;
    transform: translateY(-1px);
}
.bullet-particles-shape-btn.is-active {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.5) 0%, rgba(219, 39, 119, 0.4) 100%) !important;
    border-color: rgba(251, 207, 232, 1) !important;
    box-shadow: 0 0 0 1px rgba(236, 72, 153, 0.7), 0 0 8px rgba(219, 39, 119, 0.75);
    transform: translateY(-1px);
}

.color-picker-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Modal Styles */

#action-settings-content {
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 4px;
}

.action-settings-row {
    box-sizing: border-box;
}

.action-settings-row input[type="number"] {
    width: 100%;
    box-sizing: border-box;
}

.action-modal-mode-toggle {
    min-width: 240px;
}

#action-settings-new-btn {
    min-width: 240px;
}


.waves-list-container {
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.wave-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.wave-item:last-child {
    margin-bottom: 0;
}

.wave-item:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.wave-item.selected {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-color: #3b82f6;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.wave-item.selected .delete-wave-btn {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.wave-item.selected::before {
    content: '▶';
    margin-right: 0.75rem;
    font-size: 0.8rem;
}

#add-wave-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

#close-waves-modal-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.delete-wave-btn {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
    border: none;
    border-radius: 5px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.delete-wave-btn:hover {
    filter: brightness(1.2);
}

.modal-btn.danger {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
}

.modal-btn.secondary {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    color: #d1d5db;
}

/* Ensure crisp canvas rendering */
#glCanvas {
    image-rendering: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
}

#boss-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    display: none;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

#uiCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none; /* Make sure it doesn't block mouse events for the game canvas */
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: unset;
}

/* Title Screen Styles */
#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #1f2937; /* Fallback color */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 300;
    overflow: hidden;
}

.title-screen-frame {
    position: relative;
    width: var(--title-frame-width, min(90vw, calc(90vh * (180 / 321))));
    height: var(--title-frame-height, auto);
    max-width: none;
    max-height: none;
    aspect-ratio: 180 / 321;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    gap: 1.5rem;
    overflow: hidden;
}

/* Pixel-perfect title background using pseudo-element */
.title-screen-frame::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(145deg, rgba(59, 130, 246, 0.1), rgba(16, 185, 129, 0.05));
    z-index: 0;
}

/* Hide chat, party, and room info when title screen is displayed (lobby UI only in lobby view) */
body:has(#title-screen[style*="display: flex"]) #chat-container,
body:has(#title-screen[style*="display: flex"]) #party-container,
body:has(#title-screen[style*="display: flex"]) #room-info-display {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

#title-screen::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1;
}

/* Ensure content is above overlay */
#title-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 1;
}

.title-screen-frame > * {
    position: relative;
    z-index: 1;
}

.title-content {
    text-align: center;
    color: white;
    margin-bottom: 3rem;
    position: relative;
}

.title-content h1 {
    font-size: 3.5rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.title-content p {
    font-size: 1.25rem;
    color: #9ca3af;
    margin: 1rem 0 0 0;
    font-weight: 400;
}

/* Epic Retro Arcade Style Title */
.psx-title {
    font-size: 5.5rem;
    font-weight: 900;
    margin: 0;
    font-family: 'Orbitron', 'Arial Black', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    position: relative;
    display: inline-block;
    background: linear-gradient(
        135deg,
        #ff0066 0%,
        #ff3399 20%,
        #ff66cc 40%,
        #ff99ff 50%,
        #ff66cc 60%,
        #ff3399 80%,
        #ff0066 100%
    );
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: arcadeShine 4s linear infinite;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
    transform: perspective(500px) rotateX(5deg);
    text-rendering: optimizeLegibility;
}

/* Shiny gradient animation */
@keyframes arcadeShine {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Shine sweep effect */
.psx-title::before {
    content: 'danmaku raiders';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.5) 48%,
        rgba(255, 255, 255, 0.8) 50%,
        rgba(255, 255, 255, 0.5) 52%,
        transparent 100%
    );
    background-size: 300% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shineSweep 3s ease-in-out infinite;
    pointer-events: none;
    z-index: 1;
}

/* Shine sweep animation */
@keyframes shineSweep {
    0% {
        background-position: -300% 0;
    }
    100% {
        background-position: 300% 0;
    }
}

/* Perfectly aligned shadow layer */
.psx-title::after {
    content: 'danmaku raiders';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    color: #000;
    z-index: -1;
    text-shadow: 
        4px 4px 0px rgba(0, 0, 0, 0.9),
        8px 8px 0px rgba(0, 0, 0, 0.7),
        12px 12px 0px rgba(0, 0, 0, 0.5),
        16px 16px 20px rgba(0, 0, 0, 0.8);
    -webkit-text-stroke: 2px rgba(0, 0, 0, 0.3);
    opacity: 0.8;
    transform: translateZ(0);
}

/* Tap to Start Animated Text */
.tap-to-start-text {
    position: absolute;
    left: 50%;
    bottom: 50px;
    transform: translateX(-50%);
    font-size: 2.5rem;
    font-weight: 700;
    font-family: 'Orbitron', 'Arial Black', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #ffffff;
    text-shadow: 
        0 0 10px rgba(255, 255, 255, 0.8),
        0 0 20px rgba(255, 255, 255, 0.6),
        0 0 30px rgba(255, 255, 255, 0.4),
        2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: tapToStartPulse 2s ease-in-out infinite;
    cursor: pointer;
    user-select: none;
    z-index: 10;
    pointer-events: auto;
    text-align: center;
    width: 100%;
}

@keyframes tapToStartPulse {
    0%, 100% {
        opacity: 0.6;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05);
    }
}

.title-buttons {
    display: none; /* Buttons moved to settings modal */
}

#stage-editor-btn {
    padding: 1rem 2.5rem;
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
    transform: translateY(0);
}

#stage-editor-btn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    transform: translateY(-4px);
    box-shadow: 0 12px 35px rgba(139, 92, 246, 0.6);
}

#stage-editor-btn:active {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
}

#stage-editor-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

#clear-data-btn {
    padding: 1rem 2.5rem;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 25px rgba(239, 68, 68, 0.4);
    transform: translateY(0);
}

#clear-data-btn:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-4px);
    box-shadow: 0 12px 35px rgba(239, 68, 68, 0.6);
}

#clear-data-btn:active {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(239, 68, 68, 0.4);
}

/* Switch Styles */
.switches-container {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
}

.switch-item {
    display: flex;
    align-items: center;
}

.switch-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    gap: 8px;
    min-width: 80px;
}

.switch-text {
    color: #d1d5db;
    font-weight: 500;
    font-size: 0.75rem;
    text-align: center;
    white-space: nowrap;
}

.switch-toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: all 0.3s ease;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch-input:checked + .switch-slider {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-color: rgba(59, 130, 246, 0.5);
}

.switch-input:checked + .switch-slider:before {
    transform: translateX(24px);
}

.switch-input:focus + .switch-slider {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.switch-input:hover + .switch-slider {
    background-color: rgba(255, 255, 255, 0.3);
}

.switch-input:checked:hover + .switch-slider {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
}

#spawner-add-enemy-btn {
    padding: 10px 16px;
    font-size: 0.875rem;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    :root {
        --quick-panel-slot: 48px; /* Button width - no gap */
    }
    #side-panel {
        width: 280px;
        right: -280px;
        left: auto;
    }
    .tab-content {
        max-height: calc(45vh - 60px);
        padding: 1rem;
    }
    .setting input[type="number"] {
        width: 50px;
        padding: 6px 10px;
        font-size: 0.9rem;
    }
    .setting input[type="range"] {
        height: 10px;
    }
    .setting input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
        margin-top: -5px;
    }
    .switch-toggle {
        width: 44px;
        height: 22px;
    }
    .switch-slider:before {
        height: 16px;
        width: 16px;
    }
    .switch-input:checked + .switch-slider:before {
        transform: translateX(22px);
    }
    /* Editor buttons bar responsive adjustments */
    #editor-buttons-bar,
    #stage-editor-buttons-bar {
        height: 32px; /* Slightly smaller on mobile */
    }
    
    #editor-buttons-bar button,
    #stage-editor-buttons-bar button {
        height: 32px;
        gap: 4px;
        padding: 0 6px;
    }
    
    .button-text {
        font-size: 0.6rem; /* Smaller text on mobile */
    }
    
    .button-emoji {
        font-size: 1rem; /* Slightly smaller emoji on mobile */
    }
}

/* Enemy Counter Overlay */
.enemy-counter-overlay {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    border: 2px solid #dc2626;
    border-radius: 12px;
    color: white;
    z-index: 250;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 4px 20px rgba(220, 38, 38, 0.4);
    padding: 12px 16px;
    min-width: 120px;
    text-align: center;
    display: none; /* Hidden by default, shown in stage editor */
}

.counter-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 4px;
}

.counter-icon {
    font-size: 16px;
}

.counter-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.counter-value {
    font-size: 24px;
    font-weight: 700;
    color: #fef3c7;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
/* Base styles in-game side panel only (do not group with #stage-editor-side-panel — that panel has its own block earlier with z-index 10050) */
#side-panel {
    position: fixed;
    top: 0;
    right: -320px;
    left: auto;
    width: 320px;
    height: 100vh;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    transition: right 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 850; /* Above keyboard/code editor, below modals */
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.3);
}

#side-panel.open {
    right: 0;
}

/* Ensure crisp canvas rendering */
#glCanvas {
    image-rendering: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
}

/* Title Screen Styles */
#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #1f2937; /* Fallback color */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 300;
    overflow: hidden;
}

.title-screen-frame {
    position: relative;
    width: var(--title-frame-width, min(90vw, calc(90vh * (180 / 321))));
    height: var(--title-frame-height, auto);
    max-width: none;
    max-height: none;
    aspect-ratio: 180 / 321;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    gap: 1.5rem;
    overflow: hidden;
}

/* Pixel-perfect title background using pseudo-element */
.title-screen-frame::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('sprites/title.jpg');
    background-size: cover; /* Maintain aspect ratio while covering the screen */
    background-position: center center;
    background-repeat: no-repeat;
    image-rendering: auto; /* Use smooth rendering for JPG */
    transform: translateZ(0); /* Force hardware acceleration for crisp rendering */
    will-change: transform; /* Optimize for rendering */
    backface-visibility: hidden; /* Prevent blurring */
    z-index: 0;
}

/* Hide chat, party, and room info when title screen is displayed (lobby UI only in lobby view) */
body:has(#title-screen[style*="display: flex"]) #chat-container,
body:has(#title-screen[style*="display: flex"]) #party-container,
body:has(#title-screen[style*="display: flex"]) #room-info-display {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Darken effect removed */
#title-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 1;
}

/* Ensure content is above overlay */
.title-screen-frame > * {
    position: relative;
    z-index: 1;
}

.title-content {
    text-align: center;
    color: white;
    margin-bottom: 3rem;
    position: relative;
}

.title-content h1 {
    font-size: 3.5rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.title-content p {
    font-size: 1.25rem;
    color: #9ca3af;
    margin: 1rem 0 0 0;
    font-weight: 400;
}

/* Epic Retro Arcade Style Title */
.psx-title {
    font-size: 5.5rem;
    font-weight: 900;
    margin: 0;
    font-family: 'Orbitron', 'Arial Black', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    position: relative;
    display: inline-block;
    background: linear-gradient(
        135deg,
        #ff0066 0%,
        #ff3399 20%,
        #ff66cc 40%,
        #ff99ff 50%,
        #ff66cc 60%,
        #ff3399 80%,
        #ff0066 100%
    );
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: arcadeShine 4s linear infinite;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
    transform: perspective(500px) rotateX(5deg);
    text-rendering: optimizeLegibility;
}

/* Shiny gradient animation */
@keyframes arcadeShine {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Shine sweep effect */
.psx-title::before {
    content: 'danmaku raiders';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.5) 48%,
        rgba(255, 255, 255, 0.8) 50%,
        rgba(255, 255, 255, 0.5) 52%,
        transparent 100%
    );
    background-size: 300% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shineSweep 3s ease-in-out infinite;
    pointer-events: none;
    z-index: 1;
}

/* Shine sweep animation */
@keyframes shineSweep {
    0% {
        background-position: -300% 0;
    }
    100% {
        background-position: 300% 0;
    }
}

/* Perfectly aligned shadow layer */
.psx-title::after {
    content: 'danmaku raiders';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    color: #000;
    z-index: -1;
    text-shadow: 
        4px 4px 0px rgba(0, 0, 0, 0.9),
        8px 8px 0px rgba(0, 0, 0, 0.7),
        12px 12px 0px rgba(0, 0, 0, 0.5),
        16px 16px 20px rgba(0, 0, 0, 0.8);
    -webkit-text-stroke: 2px rgba(0, 0, 0, 0.3);
    opacity: 0.8;
    transform: translateZ(0);
}

/* Tap to Start Animated Text */
.tap-to-start-text {
    position: absolute;
    left: 50%;
    bottom: 50px;
    transform: translateX(-50%);
    font-size: 2.5rem;
    font-weight: 700;
    font-family: 'Orbitron', 'Arial Black', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #ffffff;
    text-shadow: 
        0 0 10px rgba(255, 255, 255, 0.8),
        0 0 20px rgba(255, 255, 255, 0.6),
        0 0 30px rgba(255, 255, 255, 0.4),
        2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: tapToStartPulse 2s ease-in-out infinite;
    cursor: pointer;
    user-select: none;
    z-index: 10;
    pointer-events: auto;
    text-align: center;
    width: 100%;
}

@keyframes tapToStartPulse {
    0%, 100% {
        opacity: 0.6;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05);
    }
}

.title-buttons {
    display: none; /* Buttons moved to settings modal */
}

#stage-editor-btn {
    padding: 1rem 2.5rem;
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
    transform: translateY(0);
}

#stage-editor-btn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    transform: translateY(-4px);
    box-shadow: 0 12px 35px rgba(139, 92, 246, 0.6);
}

#stage-editor-btn:active {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
}

#stage-editor-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Switch Styles */
.switches-container {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
}

.switch-item {
    display: flex;
    align-items: center;
}

.switch-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    gap: 8px;
    min-width: 80px;
}

.switch-text {
    color: #d1d5db;
    font-weight: 500;
    font-size: 0.75rem;
    text-align: center;
    white-space: nowrap;
}

.switch-toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: all 0.3s ease;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch-input:checked + .switch-slider {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-color: rgba(59, 130, 246, 0.5);
}

.switch-input:checked + .switch-slider:before {
    transform: translateX(24px);
}

.switch-input:focus + .switch-slider {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.switch-input:hover + .switch-slider {
    background-color: rgba(255, 255, 255, 0.3);
}

.switch-input:checked:hover + .switch-slider {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
}

#spawner-add-enemy-btn {
    padding: 10px 16px;
    font-size: 0.875rem;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #side-panel {
        width: 280px;
        right: -280px;
        left: auto;
    }
    .tab-content {
        max-height: calc(45vh - 60px);
        padding: 1rem;
    }
    .setting input[type="number"] {
        width: 40px;
        padding: 6px 10px;
        font-size: 0.9rem;
    }
    .setting input[type="range"] {
        height: 10px;
    }
    .setting input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
        margin-top: -5px;
    }
    .switch-toggle {
        width: 44px;
        height: 22px;
    }
    .switch-slider:before {
        height: 16px;
        width: 16px;
    }
    .switch-input:checked + .switch-slider:before {
        transform: translateX(22px);
    }
    /* Editor buttons bar responsive adjustments */
    #editor-buttons-bar,
    #stage-editor-buttons-bar {
        height: 32px; /* Slightly smaller on mobile */
    }
    
    #editor-buttons-bar button,
    #stage-editor-buttons-bar button {
        height: 32px;
        gap: 4px;
        padding: 0 6px;
    }
    
    .button-text {
        font-size: 0.6rem; /* Smaller text on mobile */
    }
    
    .button-emoji {
        font-size: 1rem; /* Slightly smaller emoji on mobile */
    }
}

/* Enemy Counter Overlay */
.enemy-counter-overlay {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    border: 2px solid #dc2626;
    border-radius: 12px;
    color: white;
    z-index: 250;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 4px 20px rgba(220, 38, 38, 0.4);
    padding: 12px 16px;
    min-width: 120px;
    text-align: center;
    display: none; /* Hidden by default, shown in stage editor */
}

.counter-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 4px;
}

.counter-icon {
    font-size: 16px;
}

.counter-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.counter-value {
    font-size: 24px;
    font-weight: 700;
    color: #fef3c7;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}


/* Enemy Editor Mode - Hide Modal Background */
/* This rule applies only when in enemy editor mode (gameMode = false, stageEditorMode = false) */
body:not([data-game-mode="true"]):not([data-stage-editor-mode="true"]) #enemy-settings-modal-overlay {
    background-color: transparent !important;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 2rem;
    width: 500px;
    max-width: 95vw;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    color: white; /* Ensure text is white */
}

/* Game-style modal enhancements */
.game-style-modal {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    border: 2px solid rgba(139, 92, 246, 0.5);
    border-radius: 12px;
    box-shadow: 
        0 0 20px rgba(139, 92, 246, 0.3),
        0 0 40px rgba(0, 0, 0, 0.8),
        inset 0 0 20px rgba(139, 92, 246, 0.1);
    position: relative;
    overflow: hidden;
}

.game-style-modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(139, 92, 246, 0.8) 20%, 
        rgba(59, 130, 246, 0.8) 50%, 
        rgba(139, 92, 246, 0.8) 80%, 
        transparent 100%);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.game-modal-header {
    border-bottom: 2px solid rgba(139, 92, 246, 0.3);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    position: relative;
}

.game-modal-title {
    margin: 0;
    color: #fff;
    font-weight: 700;
    font-size: 1.5rem;
    text-shadow: 
        0 0 10px rgba(139, 92, 246, 0.5),
        0 2px 4px rgba(0, 0, 0, 0.8);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-family: 'Arial', sans-serif;
}

.game-modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.game-stat-box {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 8px;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.game-stat-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.game-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #60a5fa;
    text-shadow: 0 0 8px rgba(96, 165, 250, 0.5);
    font-family: 'Arial', sans-serif;
}

.game-info-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(139, 92, 246, 0.1);
    border-left: 3px solid rgba(139, 92, 246, 0.5);
    padding: 1rem;
    border-radius: 6px;
}

.game-icon {
    display: inline-block;
    margin-right: 0.5rem;
    font-size: 1.2em;
}

.game-invite-message {
    text-align: center;
    padding: 1.5rem;
    background: rgba(139, 92, 246, 0.15);
    border: 2px solid rgba(139, 92, 246, 0.3);
    border-radius: 8px;
}

.game-invite-text {
    margin: 0;
    font-size: 1.1rem;
    color: #fff;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.game-modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(139, 92, 246, 0.2);
}

.game-btn-primary {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    color: white;
    border: 1px solid rgba(139, 92, 246, 0.5);
    box-shadow: 
        0 4px 12px rgba(139, 92, 246, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all 0.2s;
}

.game-btn-primary:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    box-shadow: 
        0 6px 16px rgba(139, 92, 246, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.game-btn-primary:active {
    transform: translateY(0);
    box-shadow: 
        0 2px 8px rgba(139, 92, 246, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.game-btn-secondary {
    background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
    color: #d1d5db;
    border: 1px solid rgba(107, 114, 128, 0.5);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    font-weight: 600;
    transition: all 0.2s;
}

.game-btn-secondary:hover {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    box-shadow: 
        0 6px 16px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.game-btn-secondary:active {
    transform: translateY(0);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    color: white;
    font-weight: 600;
    font-size: 1.25rem;
    text-align: center;
}

.modal-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.5rem;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1.5rem;
}

.modal-buttons button {
    padding: 12px 24px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 100px;
    color: white; /* Ensure button text is white */
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%); /* Default background */
}

.modal-buttons button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

#add-enemy-type-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

#add-enemy-type-btn:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

.enemy-type-item, .saved-enemy-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    transition: all 0.2s ease;
}

.enemy-type-item:hover, .saved-enemy-item:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.load-stage-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.load-stage-item:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.delete-stage-btn {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
    border: none;
    border-radius: 5px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Server Stage Gallery Styles */
.server-stage-gallery-modal {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    border: 2px solid rgba(139, 92, 246, 0.5);
    box-shadow: 
        0 0 30px rgba(139, 92, 246, 0.4),
        0 0 60px rgba(0, 0, 0, 0.9),
        inset 0 0 30px rgba(139, 92, 246, 0.15);
    position: relative;
    overflow: hidden;
    max-width: 700px;
    width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.server-stage-gallery-modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(139, 92, 246, 0.8) 20%, 
        rgba(59, 130, 246, 0.8) 50%, 
        rgba(139, 92, 246, 0.8) 80%, 
        transparent 100%);
    animation: shimmer 2s infinite;
}

.gallery-header {
    text-align: center;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid rgba(139, 92, 246, 0.3);
    margin-bottom: 1.5rem;
}

.gallery-title {
    margin: 0 0 0.5rem 0;
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 50%, #8b5cf6 100%);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradient-shift 3s ease infinite;
    text-shadow: 0 0 20px rgba(139, 92, 246, 0.5);
}

.gallery-subtitle {
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.95rem;
}

@keyframes gradient-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.gallery-list {
    flex: 1;
    overflow-y: auto;
    max-height: 60vh;
    padding-right: 0.5rem;
    margin-bottom: 1.5rem;
}

.gallery-list::-webkit-scrollbar {
    width: 8px;
}

.gallery-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.gallery-list::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.5);
    border-radius: 4px;
}

.gallery-list::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.7);
}

.gallery-stage-card {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.9) 100%);
    border: 2px solid rgba(139, 92, 246, 0.3);
    border-radius: 12px;
    padding: 0.875rem 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    position: relative;
    overflow: hidden;
    animation: fadeInUp 0.4s ease forwards;
    opacity: 0;
    transform: translateY(20px);
    min-height: auto;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gallery-stage-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.2), transparent);
    transition: left 0.5s ease;
}

.gallery-stage-card:hover {
    border-color: rgba(139, 92, 246, 0.6);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.95) 100%);
    transform: translateY(-2px);
    box-shadow: 
        0 8px 24px rgba(139, 92, 246, 0.3),
        0 0 20px rgba(139, 92, 246, 0.2);
}

.gallery-stage-card:hover::before {
    left: 100%;
}

.gallery-card-content {
    flex: 1;
    min-width: 0;
}

.gallery-card-header {
    display: flex;
    align-items: center;
}

.gallery-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.gallery-stage-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    transition: all 0.3s ease;
    word-break: break-word;
}

.gallery-stage-card:hover .gallery-stage-name {
    transform: scale(1.02);
}

.gallery-uploader-bracket {
    color: rgba(255, 255, 255, 0.5);
    font-weight: 400;
}

.gallery-uploader-name {
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.gallery-stage-card:hover .gallery-uploader-name {
    text-shadow: 0 0 12px currentColor;
}

.gallery-card-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.gallery-updated {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    text-align: right;
}

.gallery-updated-text {
    font-style: italic;
    white-space: nowrap;
}

.gallery-load-btn {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    color: white;
    border: 2px solid rgba(139, 92, 246, 0.5);
    border-radius: 8px;
    padding: 0.525rem 1.05rem;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    box-shadow: 
        0 3px 9px rgba(139, 92, 246, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.gallery-load-btn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    border-color: rgba(139, 92, 246, 0.8);
    transform: translateY(-1px) scale(1.03);
    box-shadow: 
        0 4px 14px rgba(139, 92, 246, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.gallery-load-btn:active {
    transform: translateY(0) scale(1);
    box-shadow: 
        0 2px 6px rgba(139, 92, 246, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.gallery-load-icon {
    font-size: 1.1rem;
    transition: transform 0.3s ease;
}

.gallery-load-btn:hover .gallery-load-icon {
    transform: translateY(2px);
}

.gallery-buttons {
    border-top: 1px solid rgba(139, 92, 246, 0.2);
    padding-top: 1.5rem;
    margin-top: 1rem;
}

.delete-stage-btn:hover {
    filter: brightness(1.2);
}

/* Chat System Styles */
#chat-container {
    position: fixed;
    bottom: 4rem;
    left: 1rem;
    width: 300px;
    z-index: 1001;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.1s ease, visibility 0.1s ease;
}

/* Hide chat when title screen is visible - multiple selectors to catch all cases */
body.title-screen-visible #chat-container,
body:has(#title-screen[style*="flex"]) #chat-container,
body:has(#title-screen:not([style*="none"])) #chat-container {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transition: none !important;
}

/* Hide chat and lobby player names in editor modes (lobby UI must not show in editor) */
body[data-game-mode="editor"] #chat-container,
body[data-game-mode="stageEditor"] #chat-container,
body[data-game-mode="editor"] .lobby-player-names-overlay,
body[data-game-mode="stageEditor"] .lobby-player-names-overlay {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

#chat-messages {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 150px;
    overflow-y: hidden;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

#chat-messages li {
    padding: 0.25rem 0.5rem;
    color: white;
    font-size: 0.875rem;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

#chat-messages li.fade-out {
    opacity: 0;
}

#chat-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #4b5563;
    background-color: #1f2937;
    color: white;
    border-radius: 6px;
    outline: none;
}

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

/* Party System Styles */
#party-container {
    position: fixed;
    top: 10rem;
    left: 0.5rem;
    right: auto;
    width: auto;
    max-width: 180px;
    background: none;
    border-radius: 0;
    padding: 0;
    color: white;
    z-index: 999;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.1s ease, visibility 0.1s ease;
    overflow: hidden;
}

/* Show party container by default in game mode (lobby), hide in editors and title screen */
body[data-game-mode="game"] #party-container {
    display: block;
}

body[data-game-mode="editor"] #party-container,
body[data-game-mode="stageEditor"] #party-container,
body[data-game-mode="title"] #party-container,
body[data-game-mode="title"] #room-info-display {
    display: none !important;
}

/* Hide party container when title screen is visible (lobby UI only in actual lobby view, not on title) */
body.title-screen-visible #party-container,
body:has(#title-screen[style*="flex"]) #party-container,
body:has(#title-screen:not([style*="none"])) #party-container {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transition: none !important;
}

/* Force party visible only when in game mode AND in lobby (not on title screen) */
body[data-game-mode="game"][data-in-lobby="true"] #party-container,
body[data-game-mode="game"] #party-container.party-visible {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

#party-container h3 {
    margin: 0 0 0.5rem 0;
    font-size: 0.875rem;
    font-weight: bold;
    text-align: left;
    text-shadow: 1px 1px 2px black, -1px -1px 2px black, 1px -1px 2px black, -1px 1px 2px black;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#party-members {
    list-style: none;
    padding: 0;
    margin: 0;
}

#party-members li {
    font-size: 0.75rem;
    font-weight: bold;
    text-align: left;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 1px 1px 2px black, -1px -1px 2px black, 1px -1px 2px black, -1px 1px 2px black;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

#party-members li.party-member-local {
    color: #87CEEB;
}

#party-invite-modal-overlay.mmorpg-inventory-overlay {
    justify-content: center;
    align-items: center;
    z-index: 10004;
}

#party-invite-modal.party-invite-modal-panel {
    width: min(420px, 92vw);
    max-height: 85vh;
}

.party-invite-modal-section {
    margin-bottom: 0;
}

.party-invite-text {
    color: var(--psx-text, #d8d0c8);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.45;
    margin: 0.15rem 0 0;
    word-break: break-word;
    font-family: 'Courier New', 'Courier', monospace;
    text-shadow: 1px 1px 0 #101018;
}

.party-invite-modal-actions {
    margin-top: 0.75rem;
}

.party-invite-modal-actions .mmorpg-button {
    flex: 1 1 auto;
    min-width: 120px;
}

.party-invite-accept-btn {
    background: linear-gradient(180deg, #0faf72 0%, #059669 52%, #047857 100%) !important;
    border-color: #34d399 #064e3b #064e3b #34d399 !important;
    color: #ecfdf5 !important;
}

.party-invite-accept-btn:hover {
    background: linear-gradient(180deg, #16c784 0%, #0d9668 52%, #05825f 100%) !important;
    color: #ffffff !important;
}

#lobby-selection-modal-overlay.mmorpg-inventory-overlay {
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

#lobby-selection-modal.lobby-selection-modal-panel {
    width: min(480px, 92vw);
    max-height: 85vh;
}

.lobby-selection-modal-section {
    margin-bottom: 0;
}

.lobby-selection-modal-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: min(52vh, 420px);
    overflow-y: auto;
    padding-right: 0.25rem;
    scrollbar-width: thin;
    scrollbar-color: var(--psx-lite) var(--psx-deep);
}

.lobby-selection-location-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.lobby-selection-location-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.lobby-selection-location-title {
    margin: 0;
    flex: 1 1 auto;
}

.lobby-selection-new-btn {
    flex-shrink: 0;
    font-size: 0.72rem;
    padding: 0.35rem 0.55rem;
    white-space: nowrap;
}

.lobby-selection-room-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.lobby-selection-room-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0.65rem;
    background: var(--psx-deep);
    border: 2px solid;
    border-color: var(--psx-dark) var(--psx-lite) var(--psx-lite) var(--psx-dark);
    cursor: pointer;
    text-align: left;
    color: var(--psx-text);
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.35;
}

.lobby-selection-room-row:hover:not(.lobby-selection-room-row--full) {
    background: #242230;
    color: #f0ebe4;
}

.lobby-selection-room-row--current {
    border-color: #064e3b #34d399 #34d399 #064e3b;
    background: linear-gradient(180deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.1) 100%);
}

.lobby-selection-room-row--full {
    opacity: 0.65;
    cursor: not-allowed;
}

.lobby-selection-room-row--full.lobby-selection-room-row--current {
    border-color: #7f1d1d #f87171 #f87171 #7f1d1d;
}

.lobby-selection-room-name {
    font-weight: 700;
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
}

.lobby-selection-room-tag {
    color: #34d399;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.lobby-selection-room-tag--full {
    color: #f87171;
}

.lobby-selection-room-meta {
    color: var(--psx-hi);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.lobby-selection-empty {
    text-align: center;
    color: var(--psx-hi);
    margin: 1rem 0 0.25rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.lobby-selection-modal-actions {
    margin-top: 0.75rem;
}

.lobby-selection-modal-actions .mmorpg-button {
    flex: 1 1 auto;
    min-width: 120px;
}

/* Lobby: Map, Chat, Start Level, Items, Portal, Browse at bottom – clickable area matches visible background */
#map-button,
#lobby-chat-btn,
#lobby-start-level-btn,
#inventory-btn,
#game-mode-portal-btn,
#lobby-browse-levels-btn {
    top: auto !important;
    bottom: 1rem !important;
    width: 41.6px !important;
    height: 48px !important;
    background: transparent !important;
    box-shadow: none !important;
    position: fixed !important;
    border-radius: 8px !important;
}
#map-button::before,
#lobby-chat-btn::before,
#lobby-start-level-btn::before,
#inventory-btn::before,
#game-mode-portal-btn::before,
#lobby-browse-levels-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    opacity: 0.82;
    z-index: -1;
}
#map-button::before {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}
#lobby-chat-btn::before {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}
#lobby-start-level-btn::before {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}
#inventory-btn::before {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
}
#game-mode-portal-btn::before {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}
#lobby-browse-levels-btn::before {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
}
/* Map and Browse on left (Browse above Map); Chat next to Map; Items and Portal on right with 8px gap */
#map-button {
    left: 1rem !important;
    right: auto !important;
    color: #ffffff !important;
}
#lobby-browse-levels-btn {
    left: 1rem !important;
    right: auto !important;
    bottom: calc(1rem + 48px + 8px + 25px) !important;
    color: #ffffff !important;
}
#lobby-chat-btn {
    left: calc(1rem + 41.6px + 8px) !important;
    right: auto !important;
    color: #ffffff !important;
}
#lobby-start-level-btn {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 83.2px !important; /* 2x portal/chat button width (41.6 * 2) */
    color: #ffffff !important;
}
#inventory-btn {
    right: 1rem !important;
    color: #ffffff !important;
}
#game-mode-portal-btn {
    right: calc(1rem + 41.6px + 8px) !important;
    color: #ffffff !important;
}

/* Connection Status Indicator */
#connection-status {
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    z-index: 10001; /* Above bottom button panel (10000) */
    transition: background-color 0.3s ease, transform 0.2s;
    background-color: #ef4444 !important; /* Default to disconnected (red) */
    cursor: pointer;
}

#connection-status:hover {
    transform: scale(1.3);
}

#connection-status:active {
    transform: scale(1.1);
}

#connection-status.disconnected {
    background-color: #ef4444 !important; /* red */
}

#connection-status.connecting {
    background-color: #ef4444 !important; /* red (same as disconnected) */
}

#connection-status.connected {
    background-color: #22c55e !important; /* green */
}

/* Admin mode: blue when connected */
#connection-status.connected.admin-mode {
    background-color: #3b82f6 !important; /* blue */
}

/* Hide weapon buttons by default - only show in admin mode + enemy editor */
#save-weapon-btn,
#load-weapon-btn {
    display: none;
}

/* Fantasy RPG Inventory Styles */
@keyframes magical-glow {
    0%, 100% {
        box-shadow: 
            0 0 30px rgba(212, 175, 55, 0.4),
            0 0 60px rgba(184, 134, 11, 0.3),
            inset 0 0 40px rgba(139, 69, 19, 0.2),
            0 0 20px rgba(138, 43, 226, 0.2);
    }
    50% {
        box-shadow: 
            0 0 50px rgba(212, 175, 55, 0.6),
            0 0 100px rgba(184, 134, 11, 0.4),
            inset 0 0 60px rgba(139, 69, 19, 0.3),
            0 0 30px rgba(138, 43, 226, 0.3);
    }
}

@keyframes mystical-shine {
    0% {
        transform: translateX(-100%) translateY(-100%) rotate(45deg);
        opacity: 0;
    }
    50% {
        opacity: 0.3;
    }
    100% {
        transform: translateX(200%) translateY(200%) rotate(45deg);
        opacity: 0;
    }
}

@keyframes enchant-pulse {
    0%, 100% {
        filter: brightness(1) drop-shadow(0 0 8px rgba(212, 175, 55, 0.6));
    }
    50% {
        filter: brightness(1.15) drop-shadow(0 0 15px rgba(212, 175, 55, 0.9));
    }
}

/* --- Inventory UI: simple retro PSX-style (flat muddy palette, chunky bevels, mono) --- */
#inventory-modal-overlay.mmorpg-inventory-overlay {
    padding: 12vh 6vw;
    box-sizing: border-box;
    justify-content: stretch !important;
    align-items: stretch !important;
}

#inventory-modal.mmorpg-inventory-modal {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    min-height: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#inventory-modal .mmorpg-inventory-header {
    flex-shrink: 0;
}

/* Stats only: floating band fixed above the scrollable equipment + items; edge-to-edge with modal panel */
.inventory-modal-pinned-top {
    flex: 0 0 auto;
    position: relative;
    z-index: 5;
    margin: 0 -1.25rem 0.6rem;
    padding: 0.35rem 0 0.65rem;
    background: linear-gradient(
        180deg,
        rgba(26, 24, 34, 0.97) 0%,
        var(--psx-panel) 38%,
        var(--psx-panel) 100%
    );
    border: 2px solid;
    border-color: var(--psx-hi) var(--psx-dark) var(--psx-dark) var(--psx-hi);
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.45),
        inset 1px 1px 0 rgba(140, 130, 160, 0.1);
    box-sizing: border-box;
    overflow: visible;
}

/* Equipment + ITEMS: one shared scroll */
.inventory-modal-items-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--psx-lite) var(--psx-deep);
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding-right: 2px;
}

.inventory-modal-items-scroll::-webkit-scrollbar {
    width: 10px;
}

.inventory-modal-items-scroll::-webkit-scrollbar-track {
    background: var(--psx-deep);
    border-left: 1px solid var(--psx-dark);
}

.inventory-modal-items-scroll::-webkit-scrollbar-thumb {
    background: var(--psx-lite);
    border: 1px solid;
    border-color: var(--psx-hi) var(--psx-dark) var(--psx-dark) var(--psx-hi);
}

.inventory-modal-items-scroll::-webkit-scrollbar-thumb:hover {
    background: #686480;
}

.inventory-modal-items-scroll > .inventory-items-section {
    margin-bottom: 0;
}

.mmorpg-inventory-overlay {
    background: rgba(12, 10, 18, 0.92);
    position: relative;
}

/* Static light scanlines, no animation */
.mmorpg-inventory-overlay::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.02) 0px,
        transparent 1px,
        transparent 3px
    );
    opacity: 0.45;
    pointer-events: none;
    z-index: 1;
}

.mmorpg-inventory-modal {
    --psx-panel: #2c2a38;
    --psx-deep: #1a1822;
    --psx-lite: #5a5668;
    --psx-dark: #0e0c12;
    --psx-text: #d8d0c8;
    --psx-hi: #9890a8;
    background: var(--psx-panel);
    border: solid 2px;
    border-color: var(--psx-hi) var(--psx-dark) var(--psx-dark) var(--psx-hi);
    border-radius: 0;
    position: relative;
    padding: 1rem 1.25rem 1.25rem;
    width: 90vw;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    color: var(--psx-text);
    box-shadow:
        inset 1px 1px 0 rgba(140, 130, 160, 0.12),
        inset -1px -1px 0 rgba(0, 0, 0, 0.45),
        6px 6px 0 rgba(0, 0, 0, 0.55);
    scrollbar-width: thin;
    scrollbar-color: var(--psx-lite) var(--psx-deep);
    font-family: 'Courier New', 'Courier', monospace;
    font-size: 13px;
    z-index: 2;
    image-rendering: pixelated;
}

.mmorpg-inventory-modal::-webkit-scrollbar {
    width: 10px;
}

.mmorpg-inventory-modal::-webkit-scrollbar-track {
    background: var(--psx-deep);
    border-left: 1px solid var(--psx-dark);
}

.mmorpg-inventory-modal::-webkit-scrollbar-thumb {
    background: var(--psx-lite);
    border: 1px solid;
    border-color: var(--psx-hi) var(--psx-dark) var(--psx-dark) var(--psx-hi);
}

.mmorpg-inventory-modal::-webkit-scrollbar-thumb:hover {
    background: #686480;
}

.mmorpg-inventory-modal > * {
    position: relative;
    z-index: 1;
}

.mmorpg-inventory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--psx-dark);
    box-shadow: 0 1px 0 var(--psx-hi);
}

.mmorpg-inventory-title {
    margin: 0;
    color: #e8d868;
    font-weight: 700;
    font-size: 1.1rem;
    text-shadow: 1px 1px 0 #101018;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-family: 'Courier New', 'Courier', monospace;
}

.mmorpg-button {
    background: #3e3c48;
    border: 2px solid;
    border-color: #686580 #28262e #28262e #686580;
    border-radius: 0;
    color: var(--psx-text);
    padding: 6px 12px;
    cursor: pointer;
    font-family: 'Courier New', 'Courier', monospace;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.08), inset -1px -1px 0 rgba(0, 0, 0, 0.35);
    transition: none;
    text-shadow: 1px 1px 0 #101018;
}

.mmorpg-button:hover {
    background: #484658;
    color: #fff8e8;
    border-color: #686580 #28262e #28262e #686580;
    box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.12), inset -1px -1px 0 rgba(0, 0, 0, 0.3);
}

.mmorpg-button:active {
    background: #2e2c36;
    border-color: #28262e #686580 #686580 #28262e;
    box-shadow: inset 1px 1px 4px rgba(0, 0, 0, 0.5);
}

/* Room strip + stage info (compact modern chip) */
.room-info-display-bar {
    color: rgba(226, 232, 240, 0.92);
    font-size: 12px;
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    letter-spacing: 0.1px;
    line-height: 1.2;
    background: rgba(15, 23, 42, 0.62);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 12px;
    padding: 6px 10px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    text-shadow: none;
}

#room-info-times-btn {
    display: none;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    vertical-align: middle;
    min-width: 30px;
    min-height: 30px;
    padding: 0 8px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.12);
    box-shadow: none;
    color: rgba(226, 232, 240, 0.9);
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', system-ui, sans-serif;
}

#room-info-times-btn:hover {
    background: rgba(148, 163, 184, 0.18);
    border-color: rgba(148, 163, 184, 0.3);
}

#level-times-modal-content.level-times-modal-panel {
    max-width: min(560px, 92vw);
    max-height: 82vh;
}

#chat-player-modal-overlay.mmorpg-inventory-overlay {
    justify-content: center;
    align-items: center;
    z-index: 10003;
}

#chat-player-modal.player-profile-modal-panel {
    width: min(420px, 92vw);
    max-height: 85vh;
}

.player-profile-modal-section {
    margin-bottom: 0;
}

.player-profile-username-value {
    color: var(--psx-text, #d8d0c8);
    font-size: 1.05rem;
    font-weight: 700;
    word-break: break-word;
    font-family: 'Courier New', 'Courier', monospace;
    text-shadow: 1px 1px 0 #101018;
    padding: 0.15rem 0;
}

.player-profile-modal-actions {
    margin-top: 0.75rem;
}

.player-profile-modal-actions .mmorpg-button {
    flex: 1 1 auto;
    min-width: 120px;
}

.player-profile-invite-btn {
    background: linear-gradient(180deg, #0faf72 0%, #059669 52%, #047857 100%) !important;
    border-color: #34d399 #064e3b #064e3b #34d399 !important;
    color: #ecfdf5 !important;
}

.player-profile-invite-btn:hover {
    background: linear-gradient(180deg, #16c784 0%, #0d9668 52%, #05825f 100%) !important;
    color: #ffffff !important;
}

.level-times-modal-header {
    margin: 0 0 0.75rem 0;
    padding-bottom: 0.35rem;
    border-bottom: 2px solid var(--psx-dark, #0e0c12);
    box-shadow: 0 1px 0 var(--psx-hi, #9890a8);
}

.level-times-modal-title {
    margin: 0;
    font-size: 1rem;
    color: #e8d868;
    text-shadow: 1px 1px 0 #101018;
}

.level-times-modal-loot-panel {
    margin: 0 0 1rem 0;
    padding: 10px 12px;
    background: #1a1822;
    border: 2px solid;
    border-color: #0e0c12 #5a5668 #5a5668 #0e0c12;
    border-radius: 0;
    box-shadow:
        inset 1px 1px 0 rgba(110, 100, 128, 0.08),
        inset -1px -1px 0 rgba(0, 0, 0, 0.35);
}

.level-times-modal-loot-hint {
    margin: 0 0 0.65rem 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: #a8a0b8;
}

.level-times-modal-loot-list {
    font-size: 0.82rem;
    color: #d8d0c8;
    max-height: 32vh;
    overflow-y: auto;
}

.stage-info-loot-row {
    margin-bottom: 8px;
    padding: 8px;
    border: 2px solid;
    border-color: #28262e #4a4658 #4a4658 #28262e;
    background: #222028;
    color: #e8d868;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
}

.level-times-modal-leaderboard {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 2px solid #0e0c12;
    box-shadow: inset 0 1px 0 rgba(152, 144, 168, 0.15);
}

.level-times-modal-leaderboard h4 {
    margin: 0 0 0.5rem 0;
}

.level-times-modal-leaderboard-list {
    font-size: 0.85rem;
    color: #d8d0c8;
}

#level-times-modal-content table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Courier New', 'Courier', monospace;
}

#level-times-modal-content th,
#level-times-modal-content td {
    padding: 6px 8px 6px 0;
    border-bottom: 1px solid #28262e;
}

#level-times-modal-content th {
    color: #a8a0b8;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

#level-times-modal-content .stage-info-lb-rank {
    color: #e8d868;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
}

#level-times-modal-content .stage-info-lb-time {
    color: #fb923c;
    font-weight: 700;
}

.level-times-modal-actions {
    margin-top: 1rem;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.level-times-modal-start-btn {
    background: linear-gradient(180deg, #0faf72 0%, #059669 52%, #047857 100%) !important;
    border-color: #34d399 #064e3b #064e3b #34d399 !important;
    color: #ecfdf5 !important;
}

.level-times-modal-start-btn:hover {
    background: linear-gradient(180deg, #16c784 0%, #0d9668 52%, #05825f 100%) !important;
    color: #ffffff !important;
}

.mmorpg-inventory-section {
    background: var(--psx-deep);
    border: 2px solid;
    border-color: var(--psx-dark) var(--psx-lite) var(--psx-lite) var(--psx-dark);
    border-radius: 0;
    padding: 0.75rem 0.875rem;
    margin-bottom: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    box-shadow:
        inset 1px 1px 0 rgba(110, 100, 128, 0.08),
        inset -1px -1px 0 rgba(0, 0, 0, 0.35);
    position: relative;
    overflow: visible;
}

#inventory-stats-section {
    position: relative;
    z-index: 1;
    background: var(--psx-deep) !important;
    margin-bottom: 0.875rem;
    margin-left: -1.25rem;
    margin-right: -1.25rem;
    margin-top: 0;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    padding-top: 1rem;
    box-shadow:
        inset 1px 1px 0 rgba(110, 100, 128, 0.08),
        inset -1px -1px 0 rgba(0, 0, 0, 0.35);
    border: none;
    border-top: 2px solid var(--psx-lite);
    border-bottom: 2px solid var(--psx-lite);
}

/* Stats inside floating band: full width inside chrome, no horizontal inset */
.inventory-modal-pinned-top #inventory-stats-section {
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 0;
    margin-top: 0;
    padding-left: 0;
    padding-right: 0;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.mmorpg-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--psx-dark);
    box-shadow: 0 1px 0 var(--psx-hi);
    padding-bottom: 0.35rem;
    margin-bottom: 0.35rem;
}

.mmorpg-section-title {
    color: #c8c0b0;
    margin: 0;
    font-size: 0.75rem;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-family: 'Courier New', 'Courier', monospace;
}

.mmorpg-equipment-area {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    box-sizing: border-box;
    padding: 0.25rem 0;
}

.equipment-player-preview-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex: 0 0 auto;
}

.equipment-slots-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex: 0 0 auto;
}

.equipment-slots-column {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 0 0 auto;
}

.equipment-slots-column .equipment-slot-cell {
    width: 2.35rem;
    height: 2.35rem;
    flex-shrink: 0;
}

.equipment-player-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    /* Canvas stays 72×96; IK draw is scaled 2× inside the same buffer. */
    min-width: 72px;
    min-height: 96px;
    overflow: hidden;
    padding: 0.25rem;
    background: rgba(14, 12, 18, 0.55);
    border: 1px solid;
    border-color: var(--psx-hi) var(--psx-dark) var(--psx-dark) var(--psx-hi);
    box-shadow: inset 1px 1px 0 rgba(120, 110, 140, 0.08);
}

#equipment-player-preview-canvas {
    display: block;
    width: 72px;
    height: 96px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.equipment-player-preview-fallback {
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 72px;
    min-height: 80px;
    padding: 0.5rem;
    font-size: 0.65rem;
    line-height: 1.35;
    color: #6b6578;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.equipment-slot-cell {
    --slot-accent: #5c5a68;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    aspect-ratio: 1;
    width: 100%;
    min-height: 0;
    min-width: 0;
    padding: 0.12rem 0.1rem;
    border-radius: 0;
    border: 1px solid;
    border-color: #28262e #4a4658 #4a4658 #28262e;
    border-top-width: 2px;
    border-top-color: var(--slot-accent);
    background: #24222c;
    box-shadow:
        inset 1px 1px 0 rgba(120, 110, 140, 0.06),
        inset -1px -1px 0 rgba(0, 0, 0, 0.25);
    transition: none;
}

.equipment-slot-cell-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.06rem;
    flex: 1;
    min-height: 0;
    text-align: center;
}

.equipment-slot-cell:hover {
    background: #2a2834;
    border-color: #343240 #544e62 #544e62 #343240;
    border-top-color: var(--slot-accent);
}

.equipment-slot-cell.filled {
    background: #2a2838;
}

.equipment-slot-emoji {
    font-size: 0.62rem;
    line-height: 1;
    flex-shrink: 0;
}

.equipment-slot-text {
    font-size: 0.44rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--slot-accent);
    font-family: 'Courier New', 'Courier', monospace;
    text-shadow: 1px 1px 0 #101018;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    word-break: break-word;
    max-width: 100%;
}

.equipment-slot-text--empty {
    color: #6b6578;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.4rem;
}

/* Inventory modal — equipment slot tiles & label scale */
#equipment-area {
    --equipment-slot-text-scale: 1.6;
}

#equipment-area .equipment-slots-column .equipment-slot-cell,
#equipment-area .equipment-slots-row .equipment-slot-cell {
    width: calc(2.5rem * 1.15);
    height: 2.5rem;
    aspect-ratio: auto;
}

/* Icon in top region; label pinned to bottom of tile (matches smithing slot layout) */
#equipment-area .equipment-slot-cell-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    flex: 1;
    min-height: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    text-align: center;
}

#equipment-area .equipment-slot-emoji {
    font-size: calc(0.62rem * var(--equipment-slot-text-scale));
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

#equipment-area .equipment-slot-inner-empty {
    justify-content: center;
}

#equipment-area .equipment-slot-inner-empty .equipment-slot-emoji {
    flex: 0 0 auto;
}

#equipment-area .equipment-slot-text {
    font-size: calc(0.44rem * var(--equipment-slot-text-scale));
    flex-shrink: 0;
    margin-top: auto;
    width: 100%;
    padding-top: 2px;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

/* Empty slot: category icon at 30% opacity */
#equipment-area .equipment-slot-cell:not(.filled) .equipment-slot-emoji {
    opacity: 0.3;
}

#equipment-area .equipment-slot-cell.filled .equipment-slot-emoji {
    opacity: 1;
}

/* Smithing (blacksmith) — inventory-matching modal + armor list */
#smithing-modal.mmorpg-inventory-modal.smithing-modal-panel {
    max-width: min(520px, 94vw);
    max-height: 88vh;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
}

#smithing-modal .mmorpg-inventory-header {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}

#smithing-modal .smithing-armors-section {
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 0;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
}

#smithing-modal .smithing-armor-list {
    gap: 0;
}

#smithing-modal .smithing-armor-card {
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0.7rem;
    border-left: none;
    border-right: none;
    border-radius: 0;
}

#smithing-modal .smithing-armor-name-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    box-sizing: border-box;
}

#smithing-modal .smithing-armor-name-row .smithing-armor-name {
    padding-left: 0;
    padding-right: 0;
    flex: 1;
    min-width: 0;
}

button.smithing-set-rename-btn,
button.smithing-boss-delete-btn {
    flex-shrink: 0;
    margin: 0;
    padding: 0.2rem 0.45rem;
    font-size: 0.55rem;
    line-height: 1.2;
    letter-spacing: 0.04em;
    min-height: unset;
}

button.smithing-set-rename-btn:active,
button.smithing-boss-delete-btn:active {
    transform: scale(0.96);
}

.smithing-admin-hint {
    font-size: 0.5rem;
    font-weight: 400;
    color: #8a8478;
    letter-spacing: 0.03em;
    text-transform: none;
    font-family: 'Courier New', 'Courier', monospace;
    margin-left: auto;
    padding-left: 0.5rem;
    text-align: right;
    line-height: 1.2;
}

#smithing-modal .smithing-armor-slots {
    padding-left: 0;
    padding-right: 0;
}

.smithing-armor-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.smithing-armor-card {
    background: var(--psx-deep);
    border: 2px solid;
    border-color: var(--psx-dark) var(--psx-lite) var(--psx-lite) var(--psx-dark);
    border-radius: 0;
    padding: 0.65rem 0.7rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow:
        inset 1px 1px 0 rgba(110, 100, 128, 0.08),
        inset -1px -1px 0 rgba(0, 0, 0, 0.35);
}

.smithing-armor-name {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: #e8d868;
    text-shadow: 1px 1px 0 #101018;
    letter-spacing: 0.06em;
    font-family: 'Courier New', 'Courier', monospace;
}

.smithing-armor-name .smithing-armor-emoji {
    font-size: 0.95rem;
    line-height: 1;
    flex-shrink: 0;
}

.smithing-armor-slots {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 3px;
    width: 100%;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: stretch;
}

button.smithing-slot-btn.equipment-slot-cell {
    appearance: none;
    -webkit-appearance: none;
    margin: 0;
    cursor: pointer;
    font: inherit;
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    max-width: none;
    min-height: 3.75rem;
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
}

/* Weapon row: shorter tiles (60% of armor slot height), emoji + label inline */
button.smithing-slot-btn.smithing-slot-btn--weapon-row.equipment-slot-cell {
    min-height: 2.25rem;
    max-height: 2.25rem;
    height: 2.25rem;
    aspect-ratio: unset;
}

button.smithing-slot-btn.smithing-slot-btn--weapon-row .equipment-slot-cell-inner {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 0.35rem;
    padding: 0.12rem 0.4rem;
    text-align: left;
}

button.smithing-slot-btn.smithing-slot-btn--weapon-row .equipment-slot-emoji:not(.armor-sheet-icon-host) {
    flex: 0 0 auto;
    min-height: unset;
    width: auto;
    font-size: clamp(0.9rem, 2.8vw, 1.1rem);
    line-height: 1;
}

button.smithing-slot-btn.smithing-slot-btn--weapon-row .equipment-slot-emoji.armor-sheet-icon-host {
    flex: 0 0 auto;
    width: auto;
    min-height: unset;
    align-self: center;
}

button.smithing-slot-btn.smithing-slot-btn--weapon-row .equipment-slot-text {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    font-size: clamp(0.62rem, 2.1vw, 0.76rem);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#smithing-modal .smithing-armor-slots--weapons {
    margin-top: 0.25rem;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
    gap: 4px;
}

button.smithing-slot-btn.equipment-slot-cell:focus-visible {
    outline: 2px solid #e8d868;
    outline-offset: 2px;
}

button.smithing-slot-btn.equipment-slot-cell:active {
    background: #26242e;
    border-color: #28262e #686580 #686580 #28262e;
}

/* Icon area grows; label sits flush at bottom of tile */
button.smithing-slot-btn .equipment-slot-cell-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    flex: 1;
    min-height: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    text-align: center;
}

button.smithing-slot-btn .equipment-slot-emoji:not(.armor-sheet-icon-host) {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

button.smithing-slot-btn .equipment-slot-emoji.armor-sheet-icon-host {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Slot emoji fallback — inventory smithing size (sprites use armor-sheet host + larger canvas, not this font) */
button.smithing-slot-btn .equipment-slot-emoji {
    font-size: 1.24rem;
    line-height: 1;
}

/* Part name only — pinned to bottom */
button.smithing-slot-btn .equipment-slot-text,
button.smithing-slot-btn .equipment-slot-text--empty {
    flex-shrink: 0;
    margin-top: auto;
    width: 100%;
    padding-top: 2px;
    font-size: 0.9rem;
    line-height: 1.05;
    letter-spacing: 0.02em;
    font-weight: 700;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

button.smithing-slot-btn .equipment-slot-emoji.armor-sheet-icon-host,
.smithing-piece-icon-preview.armor-sheet-icon-host {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    line-height: 0;
}

button.smithing-slot-btn .equipment-slot-emoji.armor-sheet-icon-host {
    width: calc(1.35rem * 1.5);
    height: calc(1.35rem * 1.5);
    min-width: 0;
    flex-shrink: 0;
    overflow: hidden;
    box-sizing: border-box;
}

.smithing-piece-icon-preview.armor-sheet-icon-host {
    overflow: hidden;
    box-sizing: border-box;
}

.armor-sheet-icon-canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    flex-shrink: 0;
}

.armor-icon-frame-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 6px;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: #475569 rgba(15, 23, 42, 0.8);
}

.armor-icon-frame-grid::-webkit-scrollbar {
    height: 6px;
}

.armor-icon-frame-grid::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.8);
    border-radius: 3px;
}

.armor-icon-frame-grid::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 3px;
}

.armor-icon-frame-grid::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

button.armor-icon-frame-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    scroll-snap-align: start;
    overflow: hidden;
    width: 48px;
    height: 48px;
    padding: 2px;
    border: 2px solid #475569;
    border-radius: 8px;
    background: #020617;
    cursor: pointer;
    box-sizing: border-box;
}

button.armor-icon-frame-btn:hover {
    border-color: #64748b;
    background: #0f172a;
}

button.armor-icon-frame-btn.selected {
    border-color: #10b981;
    box-shadow: 0 0 0 1px #10b981;
}

button.armor-icon-frame-btn canvas {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

#smithing-piece-detail-modal.mmorpg-inventory-modal.smithing-piece-detail-panel {
    max-width: min(420px, 92vw);
    max-height: 85vh;
}

/* Piece detail body: no inner PSX panel frame */
.smithing-piece-detail-body {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.smithing-piece-detail-stats,
.smithing-piece-detail-requirements {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0;
    margin: 0 0 1rem 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.smithing-piece-detail-stat,
.smithing-piece-requirement-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.15rem 0;
    margin: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    font-size: 12px;
}

.smithing-piece-requirement-label {
    flex: 1;
    min-width: 0;
}

.equipment-item-name {
    flex: 1;
    color: var(--slot-accent);
    font-family: 'Courier New', 'Courier', monospace;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
}

.equipment-empty-label {
    flex: 1;
    color: var(--slot-accent);
    font-family: 'Courier New', 'Courier', monospace;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
}

.mmorpg-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

/* Inventory stats: PSX tiles, exactly 6 equal-width columns (tile size independent of total count). */
#inventory-stats-list.inventory-stats-tiles {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    padding: 0.2rem 0 0;
    box-sizing: border-box;
    justify-items: stretch;
    align-items: stretch;
    overflow: visible;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    min-height: 2.85rem;
    padding: 0.32rem 0.12rem;
    box-sizing: border-box;
    background: #23212c;
    border: 2px solid;
    border-color: #635e72 #17151c #17151c #635e72;
    border-radius: 0;
    box-shadow:
        inset 1px 1px 0 rgba(150, 140, 170, 0.07),
        inset -1px -1px 0 rgba(0, 0, 0, 0.35);
    font-family: 'Courier New', 'Courier', monospace;
    transition: none;
    cursor: pointer;
    overflow: visible;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile:focus {
    outline: 1px solid var(--psx-hi);
    outline-offset: 1px;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile:focus:not(:focus-visible) {
    outline: none;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile-flyout {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    padding: 3px 7px;
    font-size: 0.5rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.2;
    color: #e8e0d8;
    background: #1a1824;
    border: 2px solid;
    border-color: var(--psx-hi) var(--psx-dark) var(--psx-dark) var(--psx-hi);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
    max-width: min(200px, 42vw);
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 30;
    text-shadow: 1px 1px 0 #101018;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile--flyout-open .mmorpg-stat-tile-flyout {
    opacity: 1;
    visibility: visible;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile:hover {
    background: #2a2734;
    border-color: #6e6880 #101018 #101018 #6e6880;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile::after {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 0;
    border: 1px solid rgba(20, 18, 28, 0.45);
    pointer-events: none;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile-icon,
#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile-value {
    position: relative;
    z-index: 1;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile-icon {
    font-size: 0.896rem;
    line-height: 1;
    flex-shrink: 0;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stat-tile-value {
    font-size: 0.72rem;
    font-weight: 700;
    color: #e8d878;
    text-shadow: 1px 1px 0 #101018;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    line-height: 1.15;
}

#inventory-stats-list.inventory-stats-tiles .mmorpg-stats-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #6a6478;
    font-size: 0.75rem;
    font-family: 'Courier New', 'Courier', monospace;
    padding: 0.75rem 0.5rem;
    border: 2px dashed #3a3648;
    border-radius: 0;
    background: #16141c;
}

.mmorpg-inventory-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 100%;
    overflow: visible;
    padding-right: 4px;
}

.inventory-list-item {
    --slot-accent: #5c5a68;
    display: flex;
    align-items: center;
    gap: calc(0.65rem * 0.85);
    padding: calc(0.55rem * 0.85) calc(0.65rem * 0.85);
    min-height: calc(56px * 0.85);
    flex-shrink: 0;
    box-sizing: border-box;
    border: 2px solid;
    border-color: #28262e #4a4658 #4a4658 #28262e;
    border-left-width: 4px;
    border-left-color: var(--slot-accent);
    background: #222028;
    box-shadow:
        inset 1px 1px 0 rgba(140, 130, 160, 0.05),
        inset -1px -1px 0 rgba(0, 0, 0, 0.28);
    transition: none;
}

.inventory-list-item:hover {
    border-color: #383640 #686378 #686378 #383640;
    border-left-color: var(--slot-accent);
    background: #292630;
}

.inventory-list-item .equipment-item-name.inventory-item-title-line {
    font-size: calc(0.9rem * 0.85);
    line-height: 1.2;
}

.inventory-list-item .equipment-item-name {
    color: var(--slot-accent);
}

.inventory-item-stats-preview {
    font-size: calc(0.72rem * 0.85);
    color: #dce6f2 !important;
    font-style: normal !important;
    font-family: 'Courier New', 'Courier', monospace;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
}

.inventory-empty-message {
    text-align: center;
    padding: 1.5rem;
    color: #c4d0e4;
    font-style: normal;
    font-family: 'Courier New', 'Courier', monospace;
    border: 2px dashed #3a3648;
    background: #16141c;
}

/* Retro PSX slot styles (equipment grid placeholders) */
.mmorpg-slot {
    aspect-ratio: 1;
    background: #1c1a22;
    border: 2px solid;
    border-color: #28262e #4a4658 #4a4658 #28262e;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    min-height: 40px;
    transition: none;
    box-shadow:
        inset 1px 1px 0 rgba(120, 110, 140, 0.06),
        inset -1px -1px 0 rgba(0, 0, 0, 0.32);
    font-family: 'Courier New', 'Courier', monospace;
    font-size: 9px;
    overflow: hidden;
    image-rendering: pixelated;
}

.mmorpg-slot::before {
    content: '';
    position: absolute;
    inset: 0;
    background: transparent;
    pointer-events: none;
}

.mmorpg-slot:hover {
    border-color: #3a3744 #584e68 #584e68 #3a3744;
    background: #24222e;
}

.mmorpg-slot.filled {
    background: #282630;
    border-color: #2e2c36 #4e4a58 #4e4a58 #2e2c36;
}

.mmorpg-slot.filled:hover {
    border-color: #34323e #686378 #686378 #34323e;
}

.mmorpg-slot-text {
    color: #c8c0b0;
    text-align: center;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
    letter-spacing: 0.04em;
    z-index: 1;
    position: relative;
    font-family: 'Courier New', 'Courier', monospace;
}

.mmorpg-stat-item {
    background: #1c1a22;
    border: 2px solid;
    border-color: #28262e #4a4658 #4a4658 #28262e;
    border-radius: 0;
    padding: 0.45rem 0.65rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow:
        inset 1px 1px 0 rgba(120, 110, 140, 0.05),
        inset -1px -1px 0 rgba(0, 0, 0, 0.28);
    font-family: 'Courier New', 'Courier', monospace;
    font-size: 11px;
    transition: none;
}

.mmorpg-stat-item:hover {
    border-color: #343240 #544e62 #544e62 #343240;
    background: #222028;
    box-shadow:
        inset 1px 1px 0 rgba(120, 110, 140, 0.07),
        inset -1px -1px 0 rgba(0, 0, 0, 0.25);
}

.mmorpg-stat-label {
    color: #a8a0b8;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
    font-family: 'Courier New', 'Courier', monospace;
}

.mmorpg-stat-value {
    color: #e8e0d0;
    font-weight: 700;
    text-shadow: 1px 1px 0 #101018;
    font-family: 'Courier New', 'Courier', monospace;
}

/* Volume Control Styles */
/* Title Screen Editor Buttons - Above Settings */
#title-enemy-editor-btn,
#title-stage-editor-btn,
#title-portal-btn {
    position: fixed !important;
    right: 2rem !important;
    top: auto !important;
    left: auto !important;
    width: 57.6px;
    height: 64px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 301;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 2px 4px 4px 4px !important;
    gap: 2px !important;
    pointer-events: auto;
    backdrop-filter: blur(10px);
    transform: none !important;
    margin: 0 !important;
}

/* Campaign Levels Button - Separate to respect display: none */
#title-campaign-levels-btn {
    position: fixed !important;
    right: 2rem !important;
    top: auto !important;
    left: auto !important;
    width: 57.6px;
    height: 64px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 301;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 6px 4px 4px 4px !important;
    gap: 2px !important;
    pointer-events: auto;
    backdrop-filter: blur(10px);
    transform: none !important;
    margin: 0 !important;
}

#title-enemy-editor-btn {
    bottom: calc(2rem + 160px) !important;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

#title-portal-btn {
    bottom: -10px !important;
    right: calc(2rem + 57.6px + 0.5rem + 57.6px + 0.5rem) !important; /* Left of Create, which is left of Settings */
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

#title-stage-editor-btn {
    bottom: -10px !important;
    right: calc(2rem + 57.6px + 0.5rem) !important; /* Left of Settings */
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

#title-campaign-levels-btn {
    bottom: calc(2rem + 240px) !important;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

#title-enemy-editor-btn:disabled,
#title-stage-editor-btn:disabled,
#title-portal-btn:disabled,
#title-campaign-levels-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

#title-enemy-editor-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

#title-portal-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

#title-stage-editor-btn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
}

#title-campaign-levels-btn:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

#title-enemy-editor-btn:active,
#title-stage-editor-btn:active,
#title-portal-btn:active,
#title-campaign-levels-btn:active {
    transform: scale(0.95) !important;
}

#title-credits-btn {
    position: fixed !important;
    bottom: -10px !important;
    left: 2rem !important;
    top: auto !important;
    right: auto !important;
    width: 57.6px;
    height: 64px;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 301;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 2px 4px 4px 4px !important;
    gap: 2px !important;
    pointer-events: auto;
    backdrop-filter: blur(10px);
    transform: none !important;
    margin: 0 !important;
}

#title-credits-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

#title-credits-btn:hover {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.5);
}

#title-credits-btn:active {
    transform: scale(0.95) !important;
}

/* Credits modal: allow touch/click on links on Android (override body touch-action: none) */
#credits-modal-overlay,
#credits-modal {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(52, 152, 219, 0.2);
}
#credits-modal-overlay a[href^="http"],
#credits-modal a[href^="http"] {
    pointer-events: auto !important;
    touch-action: manipulation;
    cursor: pointer;
    padding: 6px 4px;
    margin: -6px -4px;
}

/* Settings Button on Title Screen - Separate from other buttons */
#title-settings-btn {
    position: fixed !important;
    bottom: -10px !important;
    right: 2rem !important;
    top: auto !important;
    left: auto !important;
    width: 57.6px;
    height: 64px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 301;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 2px 4px 4px 4px !important;
    gap: 2px !important;
    pointer-events: auto;
    backdrop-filter: blur(10px);
    transform: none !important;
    margin: 0 !important;
}

#title-settings-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

#title-settings-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1) rotate(90deg) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7);
}

#title-settings-btn:active {
    transform: scale(0.95) rotate(90deg) !important;
}

/* Game Settings Modal Styles */
#game-settings-modal .modal-section {
    margin-bottom: 1rem;
}

/* Volume: label + % on one row, full-width slider below */
#game-settings-modal .settings-volume-section {
    margin-bottom: 0.65rem;
}

#game-settings-modal .settings-volume-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#game-settings-modal .settings-volume-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    width: 100%;
    box-sizing: border-box;
    padding: 0.45rem 0.55rem 0.5rem;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

#game-settings-modal .settings-volume-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    min-width: 0;
}

#game-settings-modal .settings-volume-label {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: #cbd5e1;
    letter-spacing: 0.02em;
    line-height: 1.2;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

#game-settings-modal .settings-volume-slider {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: 6px;
    margin: 0;
    box-sizing: border-box;
}

#game-settings-modal .settings-volume-slider::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
}

#game-settings-modal .settings-volume-slider::-moz-range-track {
    height: 6px;
    border-radius: 3px;
}

#game-settings-modal .settings-volume-slider::-webkit-slider-thumb {
    width: 16px;
    height: 16px;
    margin-top: -5px;
    box-shadow: 0 1px 4px rgba(59, 130, 246, 0.45);
}

#game-settings-modal .settings-volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
}

#game-settings-modal .settings-volume-readout {
    flex-shrink: 0;
    margin: 0;
    padding: 0.2rem 0.45rem;
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #e2e8f0;
    text-align: right;
    line-height: 1.2;
    background: rgba(59, 130, 246, 0.18);
    border: 1px solid rgba(59, 130, 246, 0.28);
    border-radius: 5px;
    min-width: 2.75rem;
}

#game-settings-modal .settings-admin-section {
    margin-top: 1rem;
    margin-bottom: 0.65rem;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: 10px;
    padding: 0.85rem 0.9rem 0.95rem;
}

#game-settings-modal .settings-admin-heading {
    margin: 0 0 0.65rem 0;
    color: #fca5a5;
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
}

#game-settings-modal .settings-admin-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#game-settings-modal .settings-admin-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    min-height: 40px;
    box-sizing: border-box;
}

#game-settings-modal .settings-admin-row-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

#game-settings-modal .settings-admin-row-title {
    font-size: 0.8125rem;
    color: #d1d5db;
    font-weight: 600;
    letter-spacing: 0.02em;
}

#game-settings-modal .settings-admin-row-hint {
    font-size: 0.7rem;
    color: #9ca3af;
    line-height: 1.2;
}

#game-settings-modal .settings-admin-switch {
    margin: 0;
    flex-shrink: 0;
}

#game-settings-modal .volume-control {
    width: 100%;
}

#game-settings-modal .volume-slider-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

#game-settings-modal .volume-slider {
    flex: 1;
}

#game-settings-modal .volume-value {
    min-width: 50px;
    text-align: right;
}

.volume-control {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 250px;
    flex: 1;
}

.volume-control label {
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
}

.volume-slider-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.volume-slider {
    flex: 1;
    min-width: 0;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    transition: background 0.3s ease;
}

.volume-slider::-webkit-slider-runnable-track {
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
}

.volume-slider:hover::-webkit-slider-runnable-track {
    background: rgba(255, 255, 255, 0.3);
}

.volume-slider::-moz-range-track {
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
}

.volume-slider:hover {
    background: rgba(255, 255, 255, 0.3);
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    margin-top: -6px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.5);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: none;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.7);
}

.volume-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.5);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.volume-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.7);
}

.volume-value {
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    min-width: 50px;
    text-align: right;
    background: rgba(59, 130, 246, 0.2); 
    padding: 0.25rem 0.75rem; 
    border-radius: 8px; 
    border: 1px solid rgba(59, 130, 246, 0.3); 
}

/* Responsive sizing for arcade title */
@media (max-width: 768px) {
    .psx-title {
        font-size: 3rem;
        letter-spacing: 0.1em;
    }
    
    .psx-title::after {
        text-shadow: 
            3px 3px 0px rgba(0, 0, 0, 0.9),
            6px 6px 0px rgba(0, 0, 0, 0.7),
            9px 9px 0px rgba(0, 0, 0, 0.5),
            12px 12px 15px rgba(0, 0, 0, 0.8);
    }
    
    .tap-to-start-text {
        font-size: 1.8rem;
        letter-spacing: 0.1em;
    }
    
    .title-volume-controls {
        flex-direction: row;
        gap: 1rem;
        padding: 1rem 1.5rem;
        max-width: 90%;
    }
    
    .volume-control {
        min-width: 150px;
    }
}

@media (max-width: 480px) {
    .psx-title {
        font-size: 2rem;
        letter-spacing: 0.05em;
    }
    
    .psx-title::after {
        text-shadow: 
            2px 2px 0px rgba(0, 0, 0, 0.9),
            4px 4px 0px rgba(0, 0, 0, 0.7),
            6px 6px 0px rgba(0, 0, 0, 0.5),
            8px 8px 10px rgba(0, 0, 0, 0.8);
    }
    
    .tap-to-start-text {
        font-size: 1.4rem;
        letter-spacing: 0.05em;
    }
    
    .title-volume-controls {
        flex-direction: row;
        gap: 0.75rem;
        padding: 1rem;
        bottom: 1rem;
        max-width: 95%;
    }
    
    .volume-control {
        min-width: 120px;
    }
    
    .volume-control label {
        font-size: 0.8rem;
    }
}

/* Android Chat Modal Styles */
#android-chat-modal-overlay {
    backdrop-filter: blur(4px);
}

#android-chat-history {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
    min-height: 200px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 1rem;
    min-height: 0; /* Allow flex shrinking */
    box-sizing: border-box;
}


#android-chat-history::-webkit-scrollbar {
    width: 8px;
}

#android-chat-history::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

#android-chat-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

#android-chat-history::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

#android-chat-input:focus {
    border-color: rgba(139, 92, 246, 0.6);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

#android-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#android-chat-cancel-btn:hover {
    background: rgba(107, 114, 128, 1) !important;
}

#android-chat-cancel-btn:active {
    background: rgba(75, 85, 99, 0.8) !important;
}


/* Ensure modal appears above other elements on mobile */
@media (max-width: 768px) {
    #android-chat-modal-overlay {
        align-items: flex-start;
        padding-top: 1rem;
    }
    
    #android-chat-modal-overlay > div {
        border-radius: 0 0 16px 16px;
        max-width: 100%;
        width: 100%;
    }
    
    /* Adjust for keyboard on mobile */
    #android-chat-modal-content {
        max-height: 50vh;
    }
}

/* Undo overlay above slidable area: z-index 10013 > slide area 10012 so undo is always on top */
#keyboard-undo-overlay {
    z-index: 10013;
}

/* Hide save-to-stage button in game mode and stage editor mode */
body[data-game-mode="game"] #save-to-stage-btn,
body[data-game-mode="stageEditor"] #save-to-stage-btn {
    display: none !important;
}

/* Forum portal: level preview iframe in thread (Levels category) — full width, aspect 180×321 */
#forum-level-preview-container {
    width: 100%;
    box-sizing: border-box;
}
#forum-level-preview-wrapper,
#forum-level-preview-container > div {
    position: relative !important;
    margin-left: auto !important;
    margin-right: auto !important;
    background: rgba(0, 0, 0, 0.5) !important;
    border-radius: 8px !important;
    overflow: hidden !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-sizing: border-box !important;
    min-height: 280px;
    max-width: none !important;
}
#forum-level-preview-iframe,
#forum-level-preview-container > div > iframe {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    display: block !important;
    pointer-events: none !important;
}

/* Forum shared preview host (feed overlay): non-interactive so drag/scroll passes through to forum; keep inside viewport on Android */
#forum-shared-preview-host {
    pointer-events: none !important;
    max-height: calc(100vh - 24px) !important;
    max-width: calc(100vw - 24px) !important;
}
@supports (max-height: 100dvh) {
    #forum-shared-preview-host {
        max-height: calc(100dvh - 24px) !important;
    }
}

/* Forum modal: header and footer bars draw on top of the shared preview iframe (opaque so iframe doesn't show through) */
#forum-portal-modal-header {
    position: relative;
    z-index: 10004;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}
#forum-portal-modal-footer {
    position: relative;
    z-index: 10004;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}

/* Forum modal content: allow touch scroll on Android */
#forum-portal-modal-content {
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overflow-y: auto;
    overflow-x: hidden;
}
/* Allow vertical pan on overlay and content so Android can scroll the forum thread */
#forum-portal-modal-overlay,
#forum-portal-modal-overlay #forum-portal-modal-content {
    touch-action: pan-y;
}
#forum-portal-modal-overlay #forum-portal-modal-content {
    overflow-y: scroll;
}

/* Forum feed view: content area full width, no side gap */
#forum-portal-modal-content.forum-feed-view {
    padding-left: 0 !important;
    padding-right: 0 !important;
}
#forum-portal-modal-content.forum-feed-view > div {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Forum feed preview placeholder */
.forum-feed-preview-container {
    transition: min-height 0.25s ease;
}

/* Thread view: code preview collapsed by default; trigger expands to show placeholder */
.forum-code-preview-container.forum-code-preview-collapsed .forum-code-preview-placeholder {
    display: none !important;
}
.forum-code-preview-container.forum-code-preview-collapsed .forum-code-preview-trigger {
    display: flex !important;
}
.forum-code-preview-container:not(.forum-code-preview-collapsed) .forum-code-preview-trigger {
    display: none !important;
}
.forum-code-preview-container .forum-code-preview-placeholder {
    min-height: 120px;
}
.forum-code-preview-trigger:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: rgba(255, 255, 255, 0.8) !important;
}

.forum-feed-preview-placeholder:hover,
.forum-feed-code-preview-placeholder:hover,
.forum-code-preview-placeholder:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
    color: white !important;
    transform: translateY(-1px);
}
.forum-feed-preview-container #forum-level-preview-wrapper.forum-level-preview-wrapper-shared {
    width: 100% !important;
    height: 120px;
    min-height: 120px;
    margin: 0 auto !important;
    transition: height 0.25s ease, min-height 0.25s ease;
}
.forum-feed-preview-container #forum-level-preview-wrapper.forum-level-preview-wrapper-shared.forum-level-preview-expanded {
    height: auto;
    min-height: 0;
}
.forum-feed-preview-container #forum-level-preview-wrapper.forum-level-preview-wrapper-shared iframe {
    height: 120px;
    min-height: 120px;
    transition: height 0.25s ease, min-height 0.25s ease;
}
.forum-feed-preview-container #forum-level-preview-wrapper.forum-level-preview-wrapper-shared.forum-level-preview-expanded iframe {
    min-height: 0;
}


/* Hide whole editor UI when showing stage preview in forum (iframe with ?forumLevelPreview=1) */
body.forum-level-preview #stage-editor-buttons-bar,
body.forum-level-preview #stage-editor-menu-btn,
body.forum-level-preview #stage-editor-side-panel,
body.forum-level-preview #code-object-editor-panel,
body.forum-level-preview #code-object-editor-container,
body.forum-level-preview #editor-buttons-bar,
body.forum-level-preview #stage-children-labels-container,
body.forum-level-preview [id^="stage-editor-"],
body.forum-level-preview #test-stage-btn,
body.forum-level-preview .browse-levels-overlay {
    display: none !important;
}

/* Iframe preview (browse levels + forum level preview): hide quick test button and performance/side panel, show loading overlay until ready */
body.iframe-preview #test-stage-btn,
body.iframe-preview #side-panel,
body.iframe-preview #code-editor-test-btn,
body.iframe-preview #tick-time-display {
    display: none !important;
}
body.iframe-preview #iframe-preview-loading-overlay {
    display: flex !important;
}
body.iframe-preview #iframe-preview-loading-overlay.iframe-preview-loaded {
    display: none !important;
}

/* Browse levels bottom bar (inside iframe): prevent overflow / cut-off on small screens */
#browse-levels-overlay {
    box-sizing: border-box !important;
    max-width: 100% !important;
    width: 100% !important;
    min-width: 0;
    overflow: hidden;
}
#browse-levels-overlay .browse-levels-label-clickable {
    max-width: 100%;
}

/* Browse levels modal Play button (parent): above info bar; high z-index so it appears above iframe on Android */
#browse-levels-modal-play-btn {
    bottom: 52px !important;
    z-index: 10001 !important;
    pointer-events: auto !important;
}

@keyframes iframe-preview-spin {
    to { transform: rotate(360deg); }
}

/* Lobby room info bar: lobby/room name always orange; level = community fuschia or campaign light green */
#room-info-name.room-info-lobby-name,
#room-info-display #room-info-name {
    color: #ffa500 !important;
}
#room-info-level.room-info-community {
    color: #ff00ff !important;
}
#room-info-level.room-info-campaign {
    color: #90ee90 !important;
}
@keyframes room-info-level-pulsate {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.08); }
}
#room-info-level.room-info-level-pulsate {
    display: inline-block;
    animation: room-info-level-pulsate 0.75s ease-in-out infinite;
}

/* Stored Sprites Modal – layout works on all screen sizes and aspect ratios */
#stored-sprites-modal-overlay {
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
}
#stored-sprites-list {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: clamp(0.5rem, 2vw, 1rem);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-auto-flow: row;
    /* Row height = cell width (square cells); minimum so card chrome (padding + border + label) doesn’t overlap */
    grid-auto-rows: minmax(88px, auto);
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    align-content: start;
    align-items: stretch;
    justify-items: stretch;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    pointer-events: auto;
}
#stored-sprites-list .sprite-grid-card,
#stored-sprites-list .sprite-grid-folder {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 1;
    box-sizing: border-box;
    overflow: hidden;
    border-radius: 12px;
    padding: clamp(0.35rem, 1vw, 0.75rem);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
    touch-action: manipulation;
}
#stored-sprites-list .sprite-grid-folder {
    background: rgba(139, 92, 246, 0.15);
    border: 2px solid rgba(139, 92, 246, 0.4);
    font: inherit;
    color: inherit;
    text-align: left;
}
#stored-sprites-list .sprite-grid-card {
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.15);
}
#stored-sprites-list .sprite-grid-folder:active,
#stored-sprites-list .sprite-grid-card:active {
    transform: scale(0.97);
}
#stored-sprites-list .sprite-grid-folder .sprite-card-icon,
#stored-sprites-list .sprite-grid-card .sprite-card-preview {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    pointer-events: none;
}
#stored-sprites-list .sprite-grid-folder .sprite-card-icon {
    background: rgba(139, 92, 246, 0.2);
    font-size: clamp(1.5rem, 6vw, 2.5rem);
}
#stored-sprites-list .sprite-grid-card .sprite-card-preview {
    background: rgba(0, 0, 0, 0.3);
}
#stored-sprites-list .sprite-grid-card .sprite-card-preview img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}
#stored-sprites-list .sprite-card-name {
    font-size: clamp(0.55rem, 1.8vw, 0.7rem);
    line-height: 1.15;
    text-align: center;
    word-break: break-all;
    overflow-wrap: break-word;
    max-height: 2.2em;
    overflow: hidden;
    flex-shrink: 0;
    font-weight: 500;
    padding-top: 0.1rem;
    pointer-events: none;
}
#stored-sprites-list .sprite-grid-folder .sprite-card-name {
    color: rgba(255, 255, 255, 0.9);
}
#stored-sprites-list .sprite-grid-card .sprite-card-name {
    color: rgba(255, 255, 255, 0.7);
}
#stored-sprites-list .sprite-grid-empty-slot {
    min-height: 88px;
    pointer-events: none;
}

/* Pixel art editor modal — matches suggestions tutorial popup (virtualKeyboard showTutorialBox) */
.sprite-pixel-editor-overlay {
    position: fixed;
    inset: 0;
    z-index: 200050;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    pointer-events: auto;
    padding: 1rem;
    box-sizing: border-box;
    touch-action: auto;
}

.sprite-pixel-editor-overlay.open {
    display: flex;
}

/* While sprite browser is open on top, editor overlay must not steal clicks */
.sprite-pixel-editor-overlay.sprite-pixel-editor-browse-pass-through {
    pointer-events: none;
}

.sprite-pixel-editor-box {
    max-width: 520px;
    width: 100%;
    max-height: 92vh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: #1a1a1a;
    border: 1px solid rgba(0, 255, 0, 0.4);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    color: #e0e0e0;
    font-family: Arial, Helvetica, sans-serif;
    box-sizing: border-box;
    touch-action: manipulation;
    pointer-events: auto;
}

.sprite-pixel-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
}

.sprite-pixel-editor-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.sprite-pixel-editor-btn-tools {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(0, 255, 0, 0.35);
    border-radius: 6px;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 0.9rem;
    flex-shrink: 0;
    touch-action: manipulation;
}

.sprite-pixel-editor-btn-tools:hover {
    border-color: rgba(0, 255, 0, 0.5);
    background: rgba(0, 255, 0, 0.1);
}

.sprite-pixel-editor-btn-tools.active {
    background: rgba(0, 255, 0, 0.2);
    border-color: rgba(0, 255, 0, 0.55);
    color: #00ff00;
}

.sprite-pixel-editor-btn-close {
    padding: 8px 16px;
    background: rgba(0, 255, 0, 0.2);
    border: 1px solid rgba(0, 255, 0, 0.5);
    border-radius: 6px;
    color: #00ff00;
    cursor: pointer;
    font-size: 0.9rem;
    flex-shrink: 0;
    touch-action: manipulation;
}

.sprite-pixel-editor-btn-close:hover {
    background: rgba(0, 255, 0, 0.28);
}

.sprite-pixel-editor-tools-bar {
    width: 100%;
    flex-shrink: 0;
    margin-top: 2px;
}

.sprite-pixel-editor-tools-scroll {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0 4px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 255, 0, 0.35) rgba(255, 255, 255, 0.06);
}

.sprite-pixel-editor-tools-scroll::-webkit-scrollbar {
    height: 6px;
}

.sprite-pixel-editor-tools-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
}

.sprite-pixel-editor-tools-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 0, 0.3);
    border-radius: 3px;
}

.sprite-pixel-editor-tools {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    flex-shrink: 0;
}

.sprite-pixel-editor-brush-wrap {
    gap: 0;
    min-width: 0;
}

/* `hidden` must win over display:flex — otherwise paint + select shape rows both stay visible */
.sprite-pixel-editor-brush-wrap:not([hidden]) {
    display: flex;
    flex-direction: column;
}

.sprite-pixel-editor-brush-wrap[hidden] {
    display: none !important;
}

.sprite-pixel-editor-brush-shapes {
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sprite-pixel-editor-brush-shapes:not([hidden]) {
    display: flex;
}

.sprite-pixel-editor-brush-shapes[hidden] {
    display: none !important;
}

.sprite-pixel-editor-stamp-row {
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sprite-pixel-editor-stamp-row:not([hidden]) {
    display: flex;
}

.sprite-pixel-editor-stamp-row[hidden] {
    display: none !important;
}

.sprite-pixel-editor-stamp-slot {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 4px;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(0, 0, 0, 0.25);
    cursor: pointer;
    touch-action: manipulation;
    overflow: hidden;
}

.sprite-pixel-editor-stamp-slot:disabled {
    cursor: default;
}

.sprite-pixel-editor-stamp-slot.active {
    border-color: rgba(0, 255, 0, 0.65);
    box-shadow: 0 0 0 1px rgba(0, 255, 0, 0.35);
}

.sprite-pixel-editor-shape-slot {
    color: #e0e0e0;
    font-size: 1.05rem;
    line-height: 1;
}

.sprite-pixel-editor-shape-slot-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
}

.sprite-pixel-editor-stamp-thumb {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    display: block;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    box-sizing: border-box;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.35);
    box-shadow: none !important;
    transform: none !important;
    -webkit-transform: none !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
}

.sprite-pixel-editor-tool-btn {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.sprite-pixel-editor-tool-btn:hover {
    border-color: rgba(0, 255, 0, 0.35);
}

.sprite-pixel-editor-tool-btn.active {
    background: rgba(0, 255, 0, 0.2);
    border-color: rgba(0, 255, 0, 0.55);
    color: #00ff00;
}

.sprite-pixel-editor-shape-btn {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    white-space: nowrap;
}

.sprite-pixel-editor-shape-btn:hover {
    border-color: rgba(0, 255, 0, 0.35);
}

.sprite-pixel-editor-shape-btn.active {
    background: rgba(0, 255, 0, 0.2);
    border-color: rgba(0, 255, 0, 0.55);
    color: #00ff00;
}

.sprite-pixel-editor-select-copy-btn:disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.sprite-pixel-editor-btn-danger {
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.45);
    border-radius: 6px;
    color: #fca5a5;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.sprite-pixel-editor-btn-primary {
    padding: 8px 12px;
    background: rgba(0, 255, 0, 0.2);
    border: 1px solid rgba(0, 255, 0, 0.5);
    border-radius: 6px;
    color: #00ff00;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.sprite-pixel-editor-image-tools-panel {
    position: relative;
    isolation: isolate;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    flex-shrink: 0;
    padding: 10px 12px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: transparent;
}

.sprite-pixel-editor-image-tools-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    border-radius: inherit;
    background: rgba(69, 10, 10, 0.55);
    pointer-events: none;
}

.sprite-pixel-editor-image-tools-panel > * {
    position: relative;
    z-index: 1;
}

.sprite-pixel-editor-image-tools-panel[hidden] {
    display: none !important;
}

.sprite-pixel-editor-image-tools-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}

.sprite-pixel-editor-image-tools-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #e0e0e0;
    letter-spacing: 0.03em;
}

.sprite-pixel-editor-image-tools-close {
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: #e0e0e0;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.sprite-pixel-editor-image-tools-close:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.35);
    color: #fff;
}

.sprite-pixel-editor-filters-bar {
    display: flex;
    flex-direction: column;
    width: 100%;
    flex-shrink: 0;
    margin-bottom: 0;
    box-sizing: border-box;
}

.sprite-pixel-editor-filter-selection-badge {
    text-align: center;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fb923c;
    padding: 5px 10px;
    margin-bottom: 6px;
    border: 1px solid #ea580c;
    border-radius: 6px;
    background: rgba(234, 88, 12, 0.12);
}

.sprite-pixel-editor-filter-selection-badge[hidden] {
    display: none !important;
}

.sprite-pixel-editor-filters-bar.sprite-pixel-editor-filters-selection-scope {
    outline: 2px solid #ea580c;
    outline-offset: 2px;
    border-radius: 10px;
    padding: 6px 6px 2px;
}

.sprite-pixel-editor-filters-scroll {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 255, 0, 0.35) rgba(255, 255, 255, 0.06);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sprite-pixel-editor-filters-scroll::-webkit-scrollbar {
    height: 6px;
}

.sprite-pixel-editor-filters-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
}

.sprite-pixel-editor-filters-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 0, 0.3);
    border-radius: 3px;
}

.sprite-pixel-editor-filter-name-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    white-space: nowrap;
}

.sprite-pixel-editor-filter-name-btn:hover {
    border-color: rgba(0, 255, 0, 0.35);
}

.sprite-pixel-editor-filter-name-btn.active {
    background: rgba(0, 255, 0, 0.2);
    border-color: rgba(0, 255, 0, 0.55);
    color: #00ff00;
}

.sprite-pixel-editor-filter-panel {
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sprite-pixel-editor-filter-panel[hidden] {
    display: none !important;
}

.sprite-pixel-editor-filter-sliders {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sprite-pixel-editor-filter-sliders[hidden] {
    display: none !important;
}

.sprite-pixel-editor-filter-hint {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.45);
    line-height: 1.35;
    margin: 0 0 4px;
}

.sprite-pixel-editor-filter-label {
    font-size: 0.7rem;
    color: #c0c0c0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.sprite-pixel-editor-filter-range {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.12);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.sprite-pixel-editor-filter-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #00ff00;
    border: 1px solid rgba(0, 200, 0, 0.8);
    cursor: pointer;
}

.sprite-pixel-editor-filter-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #00ff00;
    border: 1px solid rgba(0, 200, 0, 0.8);
    cursor: pointer;
}

.sprite-pixel-editor-filters-bar > .sprite-pixel-editor-filter-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sprite-pixel-editor-filter-apply {
    padding: 8px 16px;
    background: rgba(0, 255, 0, 0.15);
    border: 1px solid rgba(0, 255, 0, 0.45);
    border-radius: 6px;
    color: #86efac;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.sprite-pixel-editor-filter-apply:hover {
    background: rgba(0, 255, 0, 0.22);
}

.sprite-pixel-editor-filter-cancel {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #cfcfcf;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.sprite-pixel-editor-filter-cancel:hover {
    border-color: rgba(255, 255, 255, 0.35);
    color: #fff;
}

.sprite-pixel-editor-filter-actions .sprite-pixel-editor-filter-panel-action {
    padding: 8px 14px;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 6px;
    touch-action: manipulation;
}

.sprite-pixel-editor-filter-swatch {
    display: inline-block;
    width: 100%;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-sizing: border-box;
    background: hsl(0, 100%, 50%);
}

.sprite-pixel-editor-stretch-axis {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-bottom: 4px;
}

.sprite-pixel-editor-filter-inline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    color: #d4d4d4;
    cursor: pointer;
}

.sprite-pixel-editor-filter-inline input {
    accent-color: #22c55e;
}

.sprite-pixel-editor-filter-num {
    width: 3.5rem;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 0.75rem;
}

.sprite-pixel-editor-filter-select {
    flex: 1;
    min-width: 0;
    max-width: 12rem;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 0.75rem;
}

.sprite-pixel-editor-canvas-outer {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    min-height: 160px;
}

.sprite-pixel-editor-canvas-frame {
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.35);
    background: #000000;
    display: flex;
    flex-direction: column;
    min-height: 140px;
}

/* Checkerboard only behind the image (canvas) area; frame stays solid black outside it */
.sprite-pixel-editor-canvas-sheet {
    position: relative;
    display: inline-block;
    vertical-align: top;
    line-height: 0;
    box-sizing: border-box;
    background-color: #0a0a0a;
    background-image:
        linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
        linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.55),
        0 0 0 2px rgba(0, 0, 0, 0.9),
        inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.sprite-pixel-editor-viewport {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 120px;
    touch-action: none;
}

.sprite-pixel-editor-viewport-pan {
    position: relative;
    display: inline-block;
    transform-origin: 0 0;
    will-change: transform;
}

.sprite-pixel-editor-canvas-frame.sprite-pixel-editor-space-pan .sprite-pixel-editor-canvas-sheet canvas#sprite-pixel-editor-canvas,
.sprite-pixel-editor-canvas-frame.sprite-pixel-editor-tool-none .sprite-pixel-editor-canvas-sheet canvas#sprite-pixel-editor-canvas {
    cursor: grab !important;
}

.sprite-pixel-editor-canvas-frame.sprite-pixel-editor-viewport-grabbing .sprite-pixel-editor-canvas-sheet canvas#sprite-pixel-editor-canvas {
    cursor: grabbing !important;
}

.sprite-pixel-editor-canvas-hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 25;
}

.sprite-pixel-editor-canvas-hud-left,
.sprite-pixel-editor-canvas-hud-right,
.sprite-pixel-editor-canvas-hud-center {
    position: absolute;
    top: 6px;
    display: flex;
    gap: 4px;
    pointer-events: none;
}

.sprite-pixel-editor-canvas-hud-left {
    left: 6px;
    pointer-events: auto;
}

.sprite-pixel-editor-canvas-hud-right {
    right: 6px;
    pointer-events: auto;
}

.sprite-pixel-editor-canvas-hud-center {
    left: 50%;
    transform: translateX(-50%);
    justify-content: center;
    max-width: calc(100% - 200px);
}

.sprite-pixel-editor-canvas-dim-label {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(12, 12, 12, 0.92);
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.8rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, monospace;
    line-height: 1.2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
}

.sprite-pixel-editor-hud-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 0 8px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(20, 20, 20, 0.85);
    color: #f3f3f3;
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.sprite-pixel-editor-hud-btn:hover:not(:disabled) {
    background: rgba(45, 45, 45, 0.95);
    border-color: rgba(255, 255, 255, 0.35);
}

.sprite-pixel-editor-hud-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Reset global `canvas {}` rules (absolute + translateZ) so hit-testing and layout match the editor UI */
.sprite-pixel-editor-canvas-sheet canvas#sprite-pixel-editor-canvas,
.sprite-pixel-editor-canvas-frame canvas#sprite-pixel-editor-canvas,
#sprite-pixel-editor-canvas {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    -webkit-transform: none !important;
    will-change: auto !important;
    backface-visibility: visible !important;
    -webkit-backface-visibility: visible !important;
    pointer-events: auto !important;
    cursor: crosshair !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

.sprite-pixel-editor-canvas-sheet canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1;
    height: auto;
    box-sizing: border-box;
    touch-action: none;
}

.sprite-pixel-editor-selection {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: none;
    z-index: 10;
    box-sizing: border-box;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.sprite-pixel-editor-footer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

.sprite-pixel-editor-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #cfcfcf;
}

.sprite-pixel-editor-colors-header,
.sprite-pixel-editor-brush-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.sprite-pixel-editor-hex {
    font-size: 0.7rem;
    font-family: ui-monospace, monospace;
    color: rgba(255, 255, 255, 0.45);
}

.sprite-pixel-editor-colors-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sprite-pixel-editor-color-wrap {
    position: relative;
    flex-shrink: 0;
}

.sprite-pixel-editor-color-input,
.sprite-pixel-editor-color-swatch {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
}

.sprite-pixel-editor-color-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sprite-pixel-editor-color-popover {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    z-index: 50;
    width: 220px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    color: #111;
}

.sprite-pixel-editor-color-popover[hidden] {
    display: none !important;
}

.sprite-pixel-editor-color-sv {
    position: relative;
    width: 100%;
    height: 120px;
    border-radius: 4px;
    overflow: hidden;
    cursor: crosshair;
    touch-action: none;
}

.sprite-pixel-editor-color-sv-cursor {
    position: absolute;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.sprite-pixel-editor-color-sliders {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.sprite-pixel-editor-color-preview {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.sprite-pixel-editor-color-hue {
    flex: 1;
    height: 12px;
    margin: 0;
    padding: 0;
    border-radius: 6px;
    background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.sprite-pixel-editor-color-hue::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.25);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    cursor: pointer;
}

.sprite-pixel-editor-color-hue::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.25);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    cursor: pointer;
}

.sprite-pixel-editor-color-hue::-webkit-slider-runnable-track {
    height: 12px;
    border-radius: 6px;
    background: transparent;
}

.sprite-pixel-editor-color-hue::-moz-range-track {
    height: 12px;
    border-radius: 6px;
    background: transparent;
}

.sprite-pixel-editor-color-inputs {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-top: 10px;
}

.sprite-pixel-editor-color-input-row {
    display: flex;
    flex: 1;
    gap: 6px;
}

.sprite-pixel-editor-color-input-row[hidden] {
    display: none;
}

.sprite-pixel-editor-color-field {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
}

.sprite-pixel-editor-color-field input {
    width: 100%;
    box-sizing: border-box;
    padding: 4px 2px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 4px;
    background: #fff;
    color: #111;
    font-size: 0.75rem;
    font-family: ui-monospace, monospace;
    text-align: center;
    -moz-appearance: textfield;
}

.sprite-pixel-editor-color-field input::-webkit-outer-spin-button,
.sprite-pixel-editor-color-field input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.sprite-pixel-editor-color-field span {
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.55);
    text-transform: uppercase;
}

.sprite-pixel-editor-color-mode-toggle {
    width: 24px;
    height: 24px;
    margin-top: 2px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    background: #f3f4f6;
    color: rgba(0, 0, 0, 0.65);
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
}

.sprite-pixel-editor-color-mode-toggle:hover {
    background: #e5e7eb;
}

.sprite-pixel-editor-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sprite-pixel-editor-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    cursor: pointer;
    padding: 0;
    touch-action: manipulation;
}

.sprite-pixel-editor-brush-val {
    font-size: 0.8rem;
    font-weight: 700;
    color: #00ff00;
}

.sprite-pixel-editor-range {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.12);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.sprite-pixel-editor-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #00ff00;
    border: 1px solid rgba(0, 200, 0, 0.8);
    cursor: pointer;
}

.sprite-pixel-editor-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #00ff00;
    border: 1px solid rgba(0, 200, 0, 0.8);
    cursor: pointer;
}

/* JRPG NPC dialogue (lobby mayor) */
.jrpg-dialogue-overlay {
    padding: 0 1rem 1.5rem;
    box-sizing: border-box;
}
.jrpg-dialogue-box {
    width: 100%;
    max-width: 520px;
    min-height: 100px;
    cursor: pointer;
    touch-action: manipulation;
    background: linear-gradient(180deg, #2d2416 0%, #1a1510 100%);
    border: 3px solid #8b6914;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px #c9a227, 0 4px 12px rgba(0, 0, 0, 0.5);
    padding: 12px 16px 14px;
    font-family: 'VT323', 'Press Start 2P', monospace;
    margin-bottom: env(safe-area-inset-bottom, 0);
}
.jrpg-dialogue-name {
    display: inline-block;
    background: #8b6914;
    color: #f5e6c8;
    font-size: 0.9rem;
    padding: 2px 10px 4px;
    margin-bottom: 8px;
    border-radius: 2px;
}
.jrpg-dialogue-text {
    color: #f5e6c8;
    font-size: 1.15rem;
    line-height: 1.45;
    min-height: 3.5rem;
    white-space: pre-wrap;
}
.jrpg-dialogue-text.npc-dialogue-text--acquired {
    font-weight: bold;
}
.npc-acquired-label {
    color: #ffffff;
    -webkit-text-stroke: 1px #000000;
    paint-order: stroke fill;
    text-shadow:
        1px 1px 0 #000,
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        0 1px 0 #000,
        0 -1px 0 #000,
        1px 0 0 #000,
        -1px 0 0 #000;
}
.npc-acquired-item {
    color: #f97316;
    -webkit-text-stroke: 1px #000000;
    paint-order: stroke fill;
    text-shadow:
        1px 1px 0 #000,
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        0 1px 0 #000,
        0 -1px 0 #000,
        1px 0 0 #000,
        -1px 0 0 #000;
}
.jrpg-dialogue-hint {
    color: #c4b896;
    font-size: 0.85rem;
}
.jrpg-dialogue-cancel {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid #8b6914;
    color: #e8dcc8;
    font-family: inherit;
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
}

/* Player animation editor — vertical layout like sprite pixel editor */
.player-anim-editor-overlay {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    padding: 1rem;
    box-sizing: border-box;
    touch-action: auto;
}

.player-anim-editor-overlay.open {
    display: flex;
}

.player-anim-editor-box {
    max-width: 520px;
    width: 100%;
    max-height: 92vh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: #1a1a1a;
    border: 1px solid rgba(0, 255, 0, 0.4);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    color: #e0e0e0;
    font-family: Arial, Helvetica, sans-serif;
    box-sizing: border-box;
    touch-action: manipulation;
}

.player-anim-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
}

.player-anim-editor-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #e0e0e0;
}

.player-anim-editor-btn-close {
    padding: 8px 16px;
    background: rgba(0, 255, 0, 0.2);
    border: 1px solid rgba(0, 255, 0, 0.5);
    border-radius: 6px;
    color: #00ff00;
    cursor: pointer;
    font-size: 0.9rem;
    flex-shrink: 0;
    touch-action: manipulation;
}

.player-anim-editor-btn-close:hover {
    background: rgba(0, 255, 0, 0.28);
}

.player-anim-editor-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    flex-shrink: 0;
}

.player-anim-editor-btn-toggle {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(0, 255, 0, 0.35);
    border-radius: 6px;
    color: #9ca3af;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.player-anim-editor-btn-toggle:hover {
    border-color: rgba(0, 255, 0, 0.5);
    background: rgba(0, 255, 0, 0.08);
}

.player-anim-editor-btn-toggle.active {
    background: rgba(0, 255, 0, 0.2);
    border-color: rgba(0, 255, 0, 0.55);
    color: #00ff00;
}

.player-anim-editor-keyframes {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.player-anim-kf-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.player-anim-editor-btn-kf {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(0, 255, 0, 0.35);
    border-radius: 6px;
    color: #d1d5db;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.player-anim-editor-btn-kf:hover:not(:disabled) {
    border-color: rgba(0, 255, 0, 0.5);
    background: rgba(0, 255, 0, 0.08);
}

.player-anim-editor-btn-kf:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.player-anim-kf-duration-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    font-size: 0.75rem;
    color: #9ca3af;
}

.player-anim-kf-duration-label input {
    width: 3.5rem;
    padding: 6px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.35);
    color: #e5e7eb;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.player-anim-kf-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 36px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

.player-anim-kf-list:empty::before {
    content: 'No keyframes — pose and tap + Keyframe';
    font-size: 0.72rem;
    color: #6b7280;
    line-height: 1.4;
}

.player-anim-kf-chip {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
    color: #d1d5db;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.player-anim-kf-chip:hover {
    border-color: rgba(0, 255, 0, 0.45);
}

.player-anim-kf-chip.selected {
    background: rgba(0, 255, 0, 0.18);
    border-color: rgba(0, 255, 0, 0.55);
    color: #00ff00;
}

.player-anim-editor-hint {
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.4;
    color: #9ca3af;
    flex-shrink: 0;
}

.player-anim-editor-canvas-outer {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    min-height: 120px;
    width: 100%;
    box-sizing: border-box;
}

.player-anim-editor-canvas-frame {
    position: relative;
    width: 100%;
    max-width: 360px;
    margin-left: auto;
    margin-right: auto;
    background: #0a0a0a;
    border-radius: 4px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.player-anim-editor-canvas-frame canvas#player-anim-editor-canvas {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    -webkit-transform: none !important;
    display: block;
    width: 100%;
    max-width: 360px;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
    touch-action: none;
    box-sizing: border-box;
}

.player-anim-editor-canvas-hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

.player-anim-editor-canvas-hud-right {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: auto;
}

.player-anim-editor-hud-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 0 8px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(20, 20, 20, 0.85);
    color: #f3f3f3;
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.player-anim-editor-hud-btn:hover:not(:disabled) {
    background: rgba(45, 45, 45, 0.95);
    border-color: rgba(255, 255, 255, 0.35);
}

.player-anim-editor-hud-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.player-anim-editor-zoom-label {
    display: inline-block;
    min-width: 2.5rem;
    padding: 6px 8px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.88);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(12, 12, 12, 0.92);
}

.player-anim-editor-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
    width: 100%;
}

.player-anim-editor-readout {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: ui-monospace, monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 28vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.player-anim-editor-btn-primary {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 255, 0, 0.2);
    border: 1px solid rgba(0, 255, 0, 0.5);
    border-radius: 6px;
    color: #00ff00;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.player-anim-editor-btn-primary:hover {
    background: rgba(0, 255, 0, 0.28);
}
