/* Base & theme */

:root {
    color-scheme: dark;
    --bg: #0c1118;
    --panel: #131c26;
    --panel-elevated: #192431;
    --edge: #2a3b4b;
    --edge-soft: #20303e;
    --text: #e5eef3;
    --sub: #93a7b9;
    --muted: #64798c;
    --accent: #65e9cb;
    --accent-text: #072820;
    --warning: #f4bd7a;
    --display-tile: 16px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    min-height: 530px;
}

body {
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

button, input, select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    opacity: .37;
    cursor: not-allowed;
}

button:focus-visible, input:focus-visible, select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input[type=number]::-webkit-inner-spin-button {
    opacity: .65;
}

/* Top bar */

.topbar {
    flex: none;
    min-height: 73px;
    padding: 13px 21px;
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    background: #0f1720;
    border-bottom: 1px solid var(--edge-soft);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-icon {
    width: 37px;
    height: 37px;
    border: 1px solid #4aa997;
    border-radius: 10px;
    background: rgba(101,233,203,.08);
    display: grid;
    grid-template-columns: repeat(2,9px);
    grid-template-rows: repeat(2,9px);
    justify-content: center;
    align-content: center;
    gap: 3px;
    box-shadow: inset 0 0 22px rgba(101,233,203,.08);
}

.brand-icon i {
    display: block;
    background: var(--accent);
    opacity: .9;
}

.brand-icon i:nth-child(2) {
    opacity: .23;
}

.brand-icon i:nth-child(3) {
    opacity: .55;
}

.brand h1 {
    font-size: 16px;
    letter-spacing: .02em;
    margin: 0;
    font-weight: 750;
}

.brand h1 span {
    font-weight: 450;
    color: var(--sub);
}

.brand .subtitle {
    font-size: 11px;
    color: var(--muted);
    margin-top: 3px;
}

.top-actions, .right-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.chip {
    color: var(--accent);
    font-size: 11px;
    border: 1px solid #2c5e56;
    background: #112721;
    padding: 6px 8px;
    border-radius: 20px;
    font-variant-numeric: tabular-nums;
}

.btn {
    border: 1px solid #314354;
    background: #1b2935;
    color: var(--text);
    padding: 9px 13px;
    border-radius: 8px;
    white-space: nowrap;
    font-weight: 650;
    font-size: 12px;
    transition: background .15s, border-color .15s;
}

.btn:hover:not(:disabled) {
    background: #263949;
    border-color: #577085;
}

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

.btn.primary:hover:not(:disabled) {
    background: #a1ffdf;
}

.btn.ghost {
    background: transparent;
    border-color: var(--edge);
    color: var(--sub);
}

.btn.ghost:hover:not(:disabled) {
    color: var(--text);
}

.btn.small {
    padding: 7px 10px;
}

.brand-copy {
    min-width: 0;
}

.brand-stats {
    display: flex;
    gap: 7px;
    align-items: center;
    flex-wrap: wrap;
    flex: none;
    margin-right: 6px;
}

.brand-stats .chip {
    padding: 3px 8px;
}

.top-actions {
    margin-left: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
}

/* Shared section headings */

.section-label {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .095em;
    color: var(--muted);
    text-transform: uppercase;
}

/* Sidebar & atlas filters */

.sidebar {
    min-height: 0;
    min-width: 0;
    border-right: 1px solid var(--edge);
    background: var(--panel);
    display: flex;
    flex-direction: column;
}

.sidebar-heading {
    padding: 0;
    display: grid;
    grid-template-rows: var(--map-header-height, 60px) var(--map-tools-height, 62px);
    border-bottom: 1px solid var(--edge-soft);
}

.eyebrow {
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .14em;
    color: var(--muted);
    font-weight: 800;
}

.atlas-heading-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 0;
    padding: 0 18px;
    border-bottom: 1px solid var(--edge);
}

.atlas-heading-row .tile-count {
    font-size: 11px;
    font-weight: 700;
    color: var(--sub);
    font-variant-numeric: tabular-nums;
}

.filter-row {
    display: grid;
    grid-template-columns: minmax(0,1fr) minmax(0,1fr) 30px;
    align-items: center;
    gap: 7px;
    min-height: 0;
    margin: 0;
    padding: 0 18px;
}

.filter-row select {
    min-width: 0;
    width: 100%;
    background: #1b2935;
    color: var(--text);
    border: 1px solid #344758;
    padding: 9px 6px;
    font-size: 11px;
    border-radius: 8px;
}

.palette-view-toggle {
    width: 30px;
    height: 34px;
    display: grid;
    place-items: center;
    background: #1b2935;
    color: var(--sub);
    border: 1px solid #344758;
    border-radius: 8px;
    cursor: pointer;
    font-size: 17px;
    line-height: 1;
}

.palette-view-toggle:hover,.palette-view-toggle[aria-pressed="true"] {
    background: #24453e;
    color: #bffbe8;
    border-color: #448c7c;
}

/* Tile palette */

.tile-list {
    min-height: 0;
    flex: 1;
    overflow: auto;
    padding: 9px 18px;
    overscroll-behavior: contain;
    scrollbar-color: #41576a #13202b;
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 6px;
    align-content: start;
}

.tile-entry {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 9px;
    display: flex;
    align-items: center;
    color: var(--text);
    text-align: left;
    position: relative;
    min-width: 0;
    min-height: 62px;
    padding: 7px 6px;
    gap: 6px;
    border-color: var(--edge-soft);
    background: #17232e;
}

.tile-entry:hover {
    background: #20303d;
}

.tile-entry.selected {
    background: #16352f;
    border-color: #448c7c;
}

.tile-entry .sprite-frame {
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    background: #0a1117;
    border: 1px solid #2c3a46;
    border-radius: 6px;
    height: 34px;
}

.sprite {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}

.tile-entry .sprite {
    width: 32px;
    height: 32px;
}

.tile-info {
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.tile-name {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 640;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.tile-type {
    margin-top: 4px;
    font-size: 9px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-search {
    padding: 30px 20px;
    text-align: center;
    font-size: 12px;
    color: var(--sub);
    line-height: 1.7;
}

.selection-preview .sprite {
    width: 40px;
    height: 40px;
}

.tile-entry .tile-name-text {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tile-list .empty-search {
    grid-column: 1/-1;
}

.selected-graphic .sprite {
    width: 36px;
    height: 36px;
}

.tile-list.images-only {
    grid-template-columns: repeat(auto-fill,minmax(46px,1fr));
    gap: 7px;
}

.tile-list.images-only .tile-entry {
    min-height: 48px;
    height: 48px;
    padding: 4px;
    justify-content: center;
}

.tile-list.images-only .sprite-frame {
    flex: 0 0 34px;
    height: 34px;
}

.tile-list.images-only .tile-info {
    display: none;
}

/* Selected tile */

.selected-panel {
    flex: none;
    border-top: 1px solid var(--edge);
    padding: 13px 18px 16px;
    background: #17232e;
}

.selection-preview {
    border: 1px solid #456171;
    background: #101c26;
    display: grid;
    place-items: center;
    width: 55px;
    height: 55px;
    border-radius: 8px;
    flex: none;
}

.selected-name {
    font-size: 13px;
    font-weight: 750;
    margin-bottom: 5px;
    line-height: 1.2;
}

.selected-detail {
    font-size: 11px;
    color: var(--sub);
}

.selected-tile-row {
    display: flex;
    align-items: flex-start;
    margin-top: 12px;
    min-width: 0;
    position: relative;
    gap: 9px;
}

.selected-graphics {
    display: flex;
    align-items: flex-start;
    flex: none;
    gap: 6px;
}

.selected-graphic {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    min-width: 0;
}

.selected-graphic .selection-preview {
    flex: none;
    width: 42px;
    height: 42px;
}

.selected-graphic > span {
    font-size: 10px;
    color: var(--sub);
}

.selected-metadata {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding-top: 4px;
}

.selected-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
    width: 100%;
}

.selected-title-row .selected-name {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-tile-id {
    flex: none;
    font-size: 10px;
    color: var(--sub);
    font-weight: 600;
}

.selection-box {
    position: absolute;
    pointer-events: none;
    display: none;
    box-sizing: border-box;
    border: 2px dashed #9df9da;
    background: rgba(101,233,203,.16);
    box-shadow: 0 0 0 1px #09241e,inset 0 0 18px #65e9cb20;
    z-index: 4;
}

/* Workspace & map header */

.workspace {
    display: grid;
    grid-template-columns: 335px minmax(0,1fr);
    min-height: 0;
    flex: 1;
}

.editor {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.controlbar {
    flex: none;
    padding: 12px 16px;
    border-bottom: 1px solid var(--edge);
    background: #131e29;
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: space-between;
    flex-wrap: wrap;
}


.number {
    width: 67px;
    border: 1px solid #344758;
    border-radius: 7px;
    background: #0d1822;
    color: #e8f6fc;
    padding: 7px 9px;
    font: 12px ui-monospace,SFMono-Regular,Consolas,monospace;
}

.map-name {
    width: clamp(120px, 19vw, 250px);
    min-width: 100px;
}

.controlbar .map-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
    flex-wrap: wrap;
    margin-left: auto;
}

/* Drawing toolbar */

.split {
    width: 1px;
    height: 28px;
    background: #2a3b4b;
    margin: 0 3px;
}

.toolbar {
    flex: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 16px;
    background: #111a24;
    border-bottom: 1px solid var(--edge-soft);
}

.tool-group {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    background: #0b151e;
    border: 1px solid var(--edge);
    border-radius: 9px;
    padding: 4px;
}

.tool-button {
    background: transparent;
    color: var(--sub);
    border: 1px solid transparent;
    border-radius: 6px;
    min-width: 0;
    white-space: nowrap;
    padding: 7px 9px;
    font-size: 12px;
    font-weight: 700;
}

.tool-button:hover {
    color: var(--text);
    background: #1b2935;
}

.tool-button.active {
    background: #2b5b51;
    color: #c2ffec;
    border-color: #3c7d6d;
}

.zoom-label {
    color: var(--sub);
    font-size: 12px;
    margin-left: 3px;
}

.zoom-select {
    background: #1b2935;
    border: 1px solid #344758;
    color: var(--text);
    border-radius: 7px;
    padding: 7px 7px;
    font-size: 12px;
}

.toggle {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 12px;
    color: var(--sub);
    cursor: pointer;
    white-space: nowrap;
}

.toggle input {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
}

.tool-button:disabled {
    opacity: .37;
    cursor: not-allowed;
}

/* Map canvas & overlays */

.map-scroller {
    flex: 1;
    min-height: 0;
    overflow: auto;
    position: relative;
    background-color: #0b131b;
    background-image: radial-gradient(#253340 0.7px,transparent 0.7px);
    background-size: 14px 14px;
    scrollbar-color: #41576a #15232f;
    scrollbar-width: thin;
}

.map-pad {
    min-height: 100%;
    min-width: 100%;
    padding: 10px 16px;
    width: max-content;
    position: relative;
}

.map-frame {
    width: max-content;
    position: relative;
    border: 1px solid #5a7180;
    box-shadow: 0 0 0 5px rgba(7,15,23,.45),0 8px 40px rgba(0,0,0,.5);
}

#mapCanvas {
    display: block;
    image-rendering: pixelated;
    touch-action: none;
    cursor: crosshair;
}

.map-grid {
    pointer-events: none;
    position: absolute;
    inset: 0;
    opacity: 1;
    background-image: linear-gradient(to right,rgba(191,219,225,.2) 1px,transparent 1px),linear-gradient(to bottom,rgba(191,219,225,.2) 1px,transparent 1px);
    background-size: var(--display-tile) var(--display-tile);
}

.map-frame.no-grid .map-grid {
    display: none;
}

.hover-cell {
    position: absolute;
    pointer-events: none;
    border: 2px solid var(--accent);
    box-shadow: 0 0 0 1px #0c1819, inset 0 0 0 1px #0c1819,0 0 13px #65e9cb44;
    display: none;
}

.paste-box {
    position: absolute;
    pointer-events: none;
    display: none;
    box-sizing: border-box;
    border: 2px solid #ffc976;
    background: rgba(255,201,118,.14);
    z-index: 5;
}

#mapFrame.paste-mode #mapCanvas {
    cursor: copy;
}

#mapFrame.select-mode #mapCanvas {
    cursor: crosshair;
}

/* Status bar */

.statusbar {
    min-height: 37px;
    flex: none;
    padding: 8px 16px;
    background: #0f1720;
    border-top: 1px solid var(--edge);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px;
    color: var(--sub);
    font-size: 11px;
}

.status-left, .status-right {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.status-coords {
    display: inline-block;
    width: 126px;
    flex: none;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.status-light {
    width: 6px;
    height: 6px;
    display: inline-block;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 5px;
    box-shadow: 0 0 7px #65e9cb90;
}

/* Dialogs */

.map-dialog {
    width: min(440px,calc(100vw - 32px));
    max-height: 85vh;
    overflow: auto;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--edge);
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 24px 80px #000a;
}

.map-dialog::backdrop {
    background: rgba(3,9,14,.78);
}

.map-dialog h2 {
    margin: 7px 0;
    font-size: 20px;
}

.map-dialog p {
    font-size: 12px;
    color: var(--sub);
    line-height: 1.6;
    margin: 0 0 18px;
}

.dialog-label {
    display: block;
    font-size: 11px;
    color: var(--sub);
    font-weight: 700;
    margin: 12px 0 6px;
}

.dialog-select {
    display: block;
    width: 100%;
    min-width: 0;
    padding: 11px;
    background: #0e1822;
    color: var(--text);
    border: 1px solid #344758;
    border-radius: 8px;
    font-size: 13px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    margin-top: 22px;
}

/* Notifications */

.toast {
    position: fixed;
    bottom: 55px;
    right: 20px;
    background: #224b42;
    border: 1px solid #4e9e89;
    color: #d8ffef;
    padding: 11px 15px;
    border-radius: 9px;
    font-size: 12px;
    box-shadow: 0 10px 35px #0009;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .2s,transform .2s;
    pointer-events: none;
    z-index: 8;
    max-width: 330px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    background: #512c30;
    border-color: #ad585e;
    color: #ffe2dd;
}

.dirty-indicator {
    color: #f3bd75;
    font-weight: 750;
    font-size: 11px;
    letter-spacing: .025em;
}

.dirty-indicator[hidden] {
    display: none;
}

/* Responsive layout */

@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 290px minmax(0,1fr);
    }

    .topbar {
        padding: 10px 13px;
    }

    .controlbar {
        gap: 9px;
    }

    .toolbar {
        padding: 8px 11px;
    }
}

@media (max-width: 1000px) {
    .top-actions {
        flex-wrap: wrap;
    }

    .brand {
        align-items: flex-start;
    }
}

@media (max-width: 780px) {
    body {
        overflow: auto;
    }

    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: 285px minmax(380px,1fr);
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--edge);
    }

    .sidebar-heading {
        padding: 0;
    }

    .sidebar-heading .filter-row {
        padding: 0 12px;
    }

    .atlas-heading-row {
        padding: 0 12px;
    }

    .tile-list {
        padding: 5px 12px;
    }

    .selected-panel {
        display: none;
    }

    .editor {
        min-height: 380px;
    }

    .topbar {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .brand .subtitle {
        display: none;
    }

    .brand-stats {
        display: flex;
    }

    .top-actions {
        margin-left: 0;
    }

    .map-pad {
        padding: 8px 11px;
    }
}
