:root {
    --bg: #0e0f13;
    --panel: #151821;
    --text: #e6e7eb;
    --muted: #9aa0aa;
    --accent: #64b5f6;
    --border: #232734;
    --hud-text-color: #fff;
    --screen-flash-color: #ff4040;
    --screen-flash-opacity: 0.85;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    color: var(--text);
    background: radial-gradient(1200px 600px at 50% -200px, #182036 0%, var(--bg) 60%);
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px clamp(16px, 4vw, 32px);
    border-bottom: 1px solid var(--border);
    background: rgba(15, 19, 32, 0.82);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

header h1 {
    margin: 0;
    font-size: clamp(1.35rem, 2vw + 1rem, 1.9rem);
    letter-spacing: 0.4px;
}

header input {
    flex: 1 1 220px;
    max-width: 360px;
    padding: 8px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
}

main {
    flex: 1;
    width: min(1100px, 100%);
    margin: 0 auto;
    padding: clamp(16px, 4vw, 32px);
    display: grid;
    gap: 24px;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: clamp(6px, 2vw, 10px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    background: rgba(10, 13, 22, 0.8);
    width: 100%;
    max-width: 720px;
    margin: clamp(6px, 2vw, 14px) auto;
}

body.game-mode .tabs {
    margin-bottom: 0;
}

.tabs-title {
    flex: 1 1 100%;
    margin: 0;
    text-align: center;
    font-size: clamp(0.75rem, 2vw, 0.9rem);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.65);
}

.tabs-links {
    flex: 1 1 auto;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.tab-button {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(26, 32, 48, 0.9);
    color: #f2f5ff;
    cursor: pointer;
    font-weight: 600;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
    font-size: 0.95rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.tab-action-button {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(30, 35, 55, 0.88);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.tab-button:hover,
.tab-button.active,
.tab-action-button:hover {
    background: rgba(100, 181, 246, 0.2);
    border-color: rgba(100, 181, 246, 0.45);
    color: #fff;
}

@media (max-width: 640px) {
    .tabs {
        gap: 6px;
        padding: 6px;
        border-radius: 12px;
        margin: 6px auto 10px;
    }

    .tabs-title {
        font-size: 0.75rem;
    }

    .tabs-links {
        gap: 6px;
        justify-content: center;
    }

    .tab-button {
        min-height: 32px;
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .tab-action-button {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    body.game-mode #game-container {
        justify-content: flex-start;
        padding-top: 4px;
        padding-bottom: 10px;
        gap: 8px;
        margin-top: 0;
    }

    body.game-mode .game-screen {
        margin-top: 8px;
    }
}

.tab-button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tab-content {
    display: none;
    padding: clamp(16px, 3vw, 28px);
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(10, 13, 22, 0.88);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
}

.tab-content.active {
    display: block;
}

body.editor-mode main {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    gap: 0;
    display: flex;
    flex-direction: column;
}

body.editor-mode #tab-editor.tab-content {
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: rgba(10, 13, 22, 0.9);
    padding: 0;
}

body.editor-mode #tab-editor.tab-content.active {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

body.editor-mode #tab-editor .editor-layout {
    flex: 1;
    min-height: 0;
    padding: clamp(16px, 4vw, 32px);
    overflow: auto;
}

body.game-mode {
    overflow: hidden;
}

body.game-mode .app {
    height: 100vh;
}

body.game-mode header {
    display: none;
}

body.game-mode main {
    flex: 1;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    gap: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

body.game-mode .tab-action-button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

body.game-mode #tab-game.tab-content {
    flex: 1;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: #000;
    min-height: 0;
}

body.game-mode #tab-game.tab-content.active {
    display: flex;
}

body.game-mode #game-container {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0 clamp(12px, 3vw, 32px) clamp(12px, 3vw, 32px);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
}

body.game-mode #tab-game .game-controls {
    position: absolute;
    bottom: clamp(12px, 4vw, 28px);
    right: clamp(12px, 4vw, 32px);
    padding: 6px 8px;
    background: rgba(10, 13, 22, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    z-index: 3;
}

body.game-mode #tab-game .game-controls button {
    font-size: 0.75rem;
    padding: 6px 10px;
}

.game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    text-align: center;
}

.game-screen {
    position: relative;
    display: inline-block;
    line-height: 0;
}

.game-screen canvas {
    display: block;
}

.combat-indicator {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 4px 10px;
    border-radius: 6px;
    font-family: monospace;
    font-size: clamp(18px, 4vw, 24px);
    color: #ffffff;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease-in-out;
    will-change: opacity;
    z-index: 4;
}

.combat-indicator.visible {
    opacity: 1;
}

.screen-flash {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: var(--screen-flash-color);
    mix-blend-mode: screen;
    opacity: 0;
    transition: opacity 150ms ease-out;
    z-index: 3;
}

.screen-flash.visible {
    opacity: var(--screen-flash-opacity);
}

#game-canvas {
    width: clamp(128px, 45vw, 384px);
    max-width: 100%;
    height: auto;
    margin-top: 1em;
}

#editor-canvas {
    width: clamp(220px, 90vw, 820px);
    max-width: 100%;
    height: auto;
    flex: 0 1 auto;
}

.editor-map-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    padding: 24px;
    margin: 0 auto;
    width: 100%;
    max-width: 900px;
}

.editor-map-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 1.05rem;
    color: var(--text);
}

.editor-map-position {
    font-size: 0.9rem;
    color: var(--muted);
}

.editor-map-wrapper canvas {
    display: block;
    width: 100%;
}

.map-nav-button {
    --map-nav-arrow-color: rgba(255, 255, 255, 0.85);
    position: absolute;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(10, 15, 25, 0.85);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
    z-index: 3;
}

.map-nav-button:hover:not(:disabled),
.map-nav-button:focus-visible:not(:disabled) {
    border-color: rgba(96, 165, 250, 0.9);
    background: rgba(96, 165, 250, 0.35);
    outline: none;
}

.map-nav-button:disabled {
    opacity: 0.35;
    cursor: default;
    --map-nav-arrow-color: rgba(255, 255, 255, 0.35);
}

.map-nav-button::after {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-style: solid;
}

.map-nav-button--up {
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
}

.map-nav-button--up::after {
    border-width: 0 6px 8px 6px;
    border-color: transparent transparent var(--map-nav-arrow-color) transparent;
}

.map-nav-button--down {
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
}

.map-nav-button--down::after {
    border-width: 8px 6px 0 6px;
    border-color: var(--map-nav-arrow-color) transparent transparent transparent;
}

.map-nav-button--left {
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
}

.map-nav-button--left::after {
    border-width: 6px 8px 6px 0;
    border-color: transparent var(--map-nav-arrow-color) transparent transparent;
}

.map-nav-button--right {
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
}

.map-nav-button--right::after {
    border-width: 6px 0 6px 8px;
    border-color: transparent transparent transparent var(--map-nav-arrow-color);
}

.editor-mobile-nav {
    display: none;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
    flex-wrap: wrap;
}

.editor-mobile-nav-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(15, 23, 42, 0.8);
    color: #fff;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.editor-mobile-nav-button.active {
    border-color: rgba(96, 165, 250, 0.9);
    background: rgba(96, 165, 250, 0.25);
    transform: translateY(-1px);
}

.editor-mobile-nav-button:focus-visible {
    outline: 2px solid rgba(147, 197, 253, 0.8);
    outline-offset: 2px;
}

#tile-canvas {
    width: clamp(128px, 45vw, 384px);
    max-width: 100%;
    height: auto;
}

#selected-tile-preview {
    width: clamp(64px, 24vw, 128px);
    max-width: 100%;
    height: auto;
}

.game-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
    color: var(--muted);
    font-size: 0.9rem;
}

.game-controls button {
    flex: 0 0 auto;
}

.touch-controls-toggle {
    display: none;
    margin-top: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.02);
    color: #fff;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 600;
    cursor: pointer;
}

.touch-controls-toggle[aria-expanded="true"] {
    border-color: #64b5f6;
}

.game-touch-pad {
    display: none;
    z-index: 2;
    gap: 6px;
    align-items: center;
}

.game-touch-pad .pad-button {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    padding: 0;
    touch-action: manipulation;
}

.game-touch-pad .pad-button:active {
    transform: translateY(1px);
}

.game-touch-pad .pad-middle-row {
    display: flex;
    gap: 6px;
}

.game-touch-pad .pad-center {
    opacity: 0;
}

.game-touch-pad .pad-up::before {
    content: '▲';
}

.game-touch-pad .pad-down::before {
    content: '▼';
}

.game-touch-pad .pad-left::before {
    content: '◀';
}

.game-touch-pad .pad-right::before {
    content: '▶';
}

.game-touch-pad .touch-controls-hide {
    display: none;
}

@media (max-width: 720px) {
    .touch-controls-toggle {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    body.touch-controls-visible .touch-controls-toggle {
        display: none;
    }

    body.touch-controls-visible .game-touch-pad {
        display: grid;
        position: absolute;
        bottom: clamp(72px, 18vw, 128px);
        left: 50%;
        transform: translateX(-50%);
        justify-items: center;
    }

    body.touch-controls-visible .game-touch-pad .touch-controls-hide {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 4px 10px;
        border-radius: 999px;
        border: 1px solid rgba(255, 255, 255, 0.3);
        background: rgba(255, 255, 255, 0.05);
        font-size: 0.65rem;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        margin-bottom: 4px;
        color: #fff;
    }

    body.game-mode.touch-controls-visible #game-container {
        padding-bottom: clamp(110px, 24vw, 160px);
    }
}


.editor-layout {
    display: grid;
    gap: 24px;
    grid-template-columns: minmax(0, 360px) minmax(0, 1fr) minmax(0, 360px);
    grid-template-areas: "left center right";
    align-items: start;
}

.editor-left,
.editor-right,
.editor-center {
    display: grid;
    gap: 24px;
    align-content: start;
    width: 100%;
    min-width: 0;
}

.editor-left {
    grid-area: left;
    max-width: 360px;
    justify-self: start;
}

.editor-center {
    grid-area: center;
    align-content: start;
    justify-items: center;
    justify-self: center;
}

.editor-right {
    grid-area: right;
    max-width: 360px;
    justify-self: end;
}

.editor-section--map {
    width: 100%;
    max-width: 768px;
    justify-items: center;
}

.editor-section--map canvas {
    margin: 0 auto;
}

.editor-section {
    display: grid;
    gap: 16px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(15, 18, 29, 0.85);
}

.editor-section h3 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: 0.3px;
}

.editor-section canvas {
    justify-self: center;
}

.editor-section details {
    display: grid;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(8, 10, 16, 0.9);
}

.editor-section details + details {
    margin-top: 12px;
}

.editor-section summary {
    cursor: pointer;
    font-weight: 600;
    margin: -12px -14px 0;
    padding: 12px 14px;
    border-radius: 8px;
}

.editor-section details[open] summary {
    margin-bottom: 12px;
    background: rgba(21, 24, 33, 0.9);
}


.tile-editor {
    display: grid;
    gap: 16px;
}

.tile-editor-top {
    display: grid;
    justify-items: center;
}

.tile-editor-info {
    display: grid;
    gap: 12px;
}

.tile-name-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.tile-name-line .label {
    color: var(--muted);
}

.tile-editor-info .checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
}

.control-group {
    display: grid;
    gap: 6px;
}

.control-group label {
    font-size: 0.85rem;
    color: var(--muted);
}

.control-group input[type="text"],
.control-group input[type="color"],
.control-group select,
.control-group textarea {
    width: 100%;
}

canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    max-width: 100%;
    height: auto;
}

input,
select,
textarea,
button {
    font: inherit;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #0f1422;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.15);
}

button {
    cursor: pointer;
}

button:hover {
    border-color: #2d3242;
}

textarea {
    width: 100%;
    min-height: 160px;
    resize: vertical;
}


.tile-preset-summary {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.objects-panel {
    display: grid;
    gap: 12px;
}

.object-types {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    max-height: min(40vh, 260px);
    overflow-y: auto;
    padding-right: 4px;
}

.object-type-card {
    display: grid;
    grid-template-columns: 48px 1fr;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.object-type-card:hover {
    border-color: rgba(100, 181, 246, 0.6);
    transform: translateY(-1px);
}

.object-types::-webkit-scrollbar {
    width: 6px;
}

.object-types::-webkit-scrollbar-thumb {
    background: #232734;
    border-radius: 999px;
}

.object-type-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.15);
}

.object-type-card.placed .object-type-info {
    color: #8be9a5;
}

.object-type-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
}

.object-type-name {
    font-weight: 600;
    color: var(--text);
}

.object-type-info {
    font-size: 0.75rem;
    color: var(--muted);
}

.objects-list {
    display: grid;
    gap: 8px;
}

.object-card {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 12px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: rgba(18, 22, 34, 0.6);
}

.object-preview,
.object-type-preview {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    max-width: 48px;
    max-height: 48px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(15, 19, 32, 0.65);
    image-rendering: pixelated;
    flex-shrink: 0;
    justify-self: center;
}

.object-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.object-card .object-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.object-name {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.object-card .object-remove {
    align-self: flex-end;
    margin-top: 4px;
}

.object-position {
    font-size: 0.8rem;
    color: var(--muted);
}

.object-card .object-config {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 8px;
    border-radius: 6px;
    background: rgba(33, 47, 68, 0.4);
}

.object-config-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.75rem;
    color: #cfd8dc;
}

.object-config-select {
    width: 100%;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid #334155;
    background: #172030;
    color: #e8f1ff;
}

.object-config-textarea {
    width: 100%;
    min-height: 84px;
    padding: 6px;
    border-radius: 4px;
    border: 1px solid #334155;
    background: #0f172a;
    color: #e8f1ff;
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
}

.object-config-hint {
    font-size: 0.7rem;
    color: var(--muted);
    text-align: right;
}

.object-status {
    font-size: 0.75rem;
    color: #eceff1;
}

.object-status.is-on {
    color: #8be9a5;
}

.npc-conditional-group {
    display: grid;
    gap: 6px;
    margin: 8px 0;
}
.npc-conditional-section {
    display: grid;
    gap: 8px;
}
.npc-conditional-section[hidden] {
    display: none;
}
.npc-conditional-toggle {
    margin: 8px 0;
}
.npc-conditional-toggle button {
    width: 100%;
    padding: 8px 10px;
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: rgba(15, 18, 29, 0.5);
    color: var(--muted);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.npc-conditional-toggle button[aria-expanded="true"] {
    border-style: solid;
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(100, 181, 246, 0.08);
}
.npc-conditional-toggle button:hover,
.npc-conditional-toggle button:focus-visible {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(100, 181, 246, 0.08);
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.npc-reward-group {
    display: grid;
    gap: 6px;
    margin: 8px 0;
}
.npc-reward-group select {
    width: 100%;
}

.npc-conditional-group select,
.npc-conditional-group textarea {
    width: 100%;
}

.npc-extra {
    font-size: 0.75rem;
    color: var(--muted);
}


.project-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.project-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 220px;
    min-width: 200px;
}

.project-field span {
    font-size: 0.85rem;
    color: var(--muted);
}

.project-field input {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    font-size: 0.95rem;
}

.project-actions button {
    flex: 1 1 160px;
}

.project-actions button {
    flex-basis: 100%;
}

.project-share-hint {
    flex: 1 1 100%;
    font-size: 0.9rem;
    color: var(--muted);
    margin: 4px 0;
}

.enemies-panel {
    display: grid;
    gap: 12px;
}

.enemy-types {
    display: grid;
    gap: 8px;
    max-height: min(40vh, 260px);
    overflow-y: auto;
    padding-right: 4px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.enemy-types::-webkit-scrollbar {
    width: 6px;
}

.enemy-types::-webkit-scrollbar-thumb {
    background: #232734;
    border-radius: 999px;
}

.enemy-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.enemy-card.boss {
    border-color: rgba(255, 193, 7, 0.55);
    background: linear-gradient(135deg, rgba(43, 32, 12, 0.6), rgba(24, 18, 10, 0.6));
}

.enemy-card:hover {
    border-color: rgba(100, 181, 246, 0.6);
    transform: translateY(-1px);
}

.enemy-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.15);
}

.enemy-preview {
    width: 48px;
    height: 48px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(15, 18, 29, 0.6);
    flex-shrink: 0;
}

.enemy-meta {
    display: grid;
    gap: 4px;
    flex: 1;
}

.enemy-boss-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #1f1302;
    background: linear-gradient(135deg, #fbc02d, #ffeb3b);
    border-radius: 12px;
    width: fit-content;
}

.enemy-name {
    font-size: 0.9rem;
    font-weight: 600;
}

.enemy-damage {
    font-size: 0.8rem;
    color: var(--accent);
}

.enemies-list {
    display: grid;
    gap: 6px;
}

.enemy-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(18, 22, 34, 0.6);
    font-size: 0.8rem;
}

.enemy-item > span {
    flex: 1 1 auto;
    text-align: left;
    line-height: 1.3;
}

.enemy-variable-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--muted);
}

.enemy-variable-select {
    min-width: 120px;
    padding: 3px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: rgba(15, 18, 29, 0.85);
    color: var(--text);
    font-size: 0.75rem;
}

.enemy-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
}

.enemy-controls .enemy-variable-wrapper {
    flex: 1;
}

.enemy-remove {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: rgba(15, 18, 29, 0.9);
    color: var(--text);
    cursor: pointer;
}

.tile-list,
.npcs-list {
    display: grid;
    gap: 8px;
    max-height: min(40vh, 260px);
    overflow-y: auto;
    padding-right: 4px;
}

.npcs-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tile-group {
    display: grid;
    gap: 6px;
}

.tile-group + .tile-group {
    margin-top: 12px;
}

.tile-group-title {
    margin: 4px 0 0;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.tile-group:first-child .tile-group-title {
    margin-top: 0;
}

.tile-list::-webkit-scrollbar,
.npcs-list::-webkit-scrollbar {
    width: 6px;
}

.tile-list::-webkit-scrollbar-thumb,
.npcs-list::-webkit-scrollbar-thumb {
    background: #232734;
    border-radius: 999px;
}

.tile-card {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    width: 80px;
    aspect-ratio: 1 / 1;
    appearance: none;
    -webkit-appearance: none;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
    min-height: 72px;
}

.tile-card:hover {
    border-color: rgba(100, 181, 246, 0.6);
    transform: translateY(-1px);
}

.tile-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.npc-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
}


.tile-card.selected {
    border-color: var(--accent);
    background: rgba(100, 181, 246, 0.08);
    box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.15);
}
.tile-card canvas {
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 64px;
    height: 64px;
}

.npc-card .meta {
    flex: 1;
    display: grid;
    gap: 4px;
}
.tile-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}


.npc-card .row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--muted);
}

.npc-card label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.npc-card.selected {
    border-color: var(--accent);
    background: rgba(100, 181, 246, 0.1);
    box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.15);
}

.npc-card .npc-preview {
    width: 48px;
    height: 48px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--panel);
    display: block;
    image-rendering: pixelated;
    flex-shrink: 0;
}

.world-panel {
    padding: 4px 0;
}

.world-grid {
    --world-cols: 3;
    display: grid;
    grid-template-columns: repeat(var(--world-cols), minmax(0, 1fr));
    gap: 6px;
}

.world-cell {
    outline: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel);
    color: var(--muted);
    font-weight: 600;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.world-cell:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.world-cell.active {
    border-color: var(--accent);
    background: rgba(100, 181, 246, 0.12);
    color: var(--text);
    box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.18);
}

.world-cell-label {
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.world-cell-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
}

.world-cell-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(100, 181, 246, 0.18);
    color: var(--text);
}

.world-cell .badge-start {
    background: rgba(255, 193, 7, 0.25);
    color: #ffecb3;
}

.npc-card .npc-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.npc-card .npc-position,
.npc-card .npc-dialog {
    font-size: 0.75rem;
    color: var(--muted);
}

.npc-card .npc-dialog {
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}

.npc-variant-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-start;
    margin-bottom: 8px;
}

.npc-variant-buttons {
    display: inline-flex;
    gap: 6px;
}

.npc-variant-button {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.npc-variant-button:hover,
.npc-variant-button:focus-visible {
    border-color: var(--accent);
    transform: translateY(-1px);
    outline: none;
}

.npc-variant-button.active {
    border-color: var(--accent);
    background: rgba(100, 181, 246, 0.12);
    box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.18);
}

.npc-editor {
    display: grid;
    gap: 8px;
}

.npc-editor[hidden] {
    display: none !important;
}

.npc-editor label {
    font-size: 0.85rem;
    color: var(--muted);
}

.npc-editor textarea {
    min-height: 140px;
}

.npc-editor button {
    justify-self: flex-start;
}

.json-editor {
    display: grid;
    gap: 8px;
}

.json-editor textarea {
    min-height: 160px;
    font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.app-footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    padding: 12px 16px;
    text-align: center;
}

@media (min-width: 1800px) {
    .editor-layout {
        zoom: 1.3;
    }
}

@media (min-width: 2000px) {
    .editor-layout {
        zoom: 1.4;
    }
}

@media (min-width: 2500px) {
    .editor-layout {
        zoom: 1.6;
    }
}

@media (max-width: 1200px) {
    .editor-layout {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas:
            "center center"
            "left right";
    }

    .editor-left,
    .editor-right {
        justify-self: stretch;
        max-width: none;
    }

    .editor-center {
        justify-self: stretch;
    }
}

@media (max-width: 960px) {
    main {
        padding: clamp(16px, 5vw, 24px);
    }

    .editor-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "center"
            "left"
            "right";
    }

    .editor-left,
    .editor-right {
        max-width: none;
    }

    .editor-left,
    .editor-right,
    .editor-center {
        justify-self: stretch;
    }
}

@media (max-width: 920px) {
    .editor-mobile-nav {
        display: flex;
    }

    .editor-section[data-mobile-panel] {
        display: none;
    }

    .editor-section[data-mobile-panel].is-mobile-active {
        display: block;
    }

    .editor-left,
    .editor-right {
        width: 100%;
    }
}

@media (max-width: 700px) {
    header {
        justify-content: flex-start;
    }

    header input {
        max-width: 100%;
    }

    .tab-button {
        flex: 0 0 auto;
    }

    .game-controls {
        flex-direction: column;
    }

    .object-card {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .object-preview {
        justify-self: center;
    }

    .object-card .object-header {
        flex-direction: column;
        align-items: center;
        gap: 4px;
    }
}

@media (max-width: 560px) {
    header {
        padding: 14px 16px;
    }

    header h1 {
        font-size: 1.35rem;
    }

    main {
        padding: 16px 14px 28px;
    }

    .tabs {
        gap: 6px;
    }

    .tab-button {
        flex: 0 0 auto;
        min-width: auto;
    }

    .npc-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .npc-card .npc-preview {
        margin-bottom: 4px;
    }

    .project-actions button {
        flex: 1 1 100%;
    }

    .tile-editor-controls {
        grid-template-columns: 1fr;
    }

    .tile-editor-controls .control-group:last-child {
        flex-direction: column;
    }
}

.game-minimap {
    top: clamp(12px, 3vw, 28px);
    right: clamp(12px, 4vw, 32px);
    width: 72px;
    height: 72px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 6px;
    border-radius: 10px;
    background: rgba(10, 13, 22, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    z-index: 3;
}

.game-minimap-cell {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.35);
}

.game-minimap-cell-active {
    background: rgba(100, 181, 246, 0.9);
    border-color: rgba(100, 181, 246, 0.9);
    box-shadow: 0 0 6px rgba(100, 181, 246, 0.65),
        inset 0 0 4px rgba(255, 255, 255, 0.4);
}

.world-cell:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (max-width: 960px) {
    .editor-left .editor-section canvas {
        width: clamp(200px, 80vw, 320px);
    }
}

.tile-group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, max-content));
    gap: 8px;
    justify-content: flex-start;
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, max-content));
    gap: 2px;
    justify-content: flex-start;
}




