:root {
    --bg: #0b0f17;
    --bg-elevated: #121826;
    --bg-panel: #161d2b;
    --border: #253147;
    --border-soft: #1c2534;
    --text: #e6ecf7;
    --text-muted: #8b9ab3;
    --accent: #7c8cff;
    --accent-strong: #5d6ef0;
    --danger: #f87171;
    --ok: #34d399;
    --radius: 10px;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1 {
    font-size: 22px;
    letter-spacing: 0.01em;
    margin: 0 0 16px;
}

h2 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 0 0 12px;
}

code {
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 12px;
    background: #0e1420;
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    padding: 1px 5px;
}

.muted {
    color: var(--text-muted);
}

.small {
    font-size: 12px;
}

.pad {
    padding: 12px;
}

.ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- shell ---------- */

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

.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 22px;
    background: rgba(11, 15, 23, 0.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-soft);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.brand:hover {
    text-decoration: none;
    color: #fff;
}

.brand-mark,
.folder-glyph {
    display: inline-grid;
    grid-template-columns: repeat(2, 7px);
    grid-template-rows: repeat(2, 7px);
    gap: 2px;
}

.brand-mark i,
.folder-glyph i {
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 1px;
}

.brand-mark i:nth-child(1),
.folder-glyph i:nth-child(1) { background: #7c8cff; }

.brand-mark i:nth-child(2),
.folder-glyph i:nth-child(2) { background: #f472b6; }

.brand-mark i:nth-child(3),
.folder-glyph i:nth-child(3) { background: #34d399; }

.brand-mark i:nth-child(4),
.folder-glyph i:nth-child(4) { background: #fbbf24; }

.nav {
    display: flex;
    gap: 6px;
}

.nav a {
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 500;
}

.nav a:hover {
    background: var(--bg-panel);
    color: var(--text);
    text-decoration: none;
}

.nav a.active {
    background: var(--bg-panel);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--border);
}

.header-meta {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.pill {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    background: var(--bg-panel);
    border: 1px solid var(--border-soft);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 3px 9px;
    white-space: nowrap;
}

.pill.warn {
    color: #fbbf24;
    border-color: #4b3a12;
}

.root-label {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: rtl;
    text-align: left;
}

.library-select {
    max-width: 220px;
    font-size: 12px;
    padding: 4px 8px;
}

.header-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 22px 0;
}

.header-banner .banner {
    flex: 1;
}

.library-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.library-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---------- galleries page ---------- */

.gallery-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.gallery-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(0, 1.6fr) auto;
    align-items: center;
    column-gap: 12px;
    row-gap: 4px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-soft);
}

.gallery-row:last-child {
    border-bottom: none;
}

.gallery-row-head {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.gallery-name,
.gallery-path {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.gallery-name .text {
    width: 100%;
    min-width: 0;
    font-family: inherit;
}

.trash-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gallery-path code {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gallery-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.gallery-key-row {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 2px;
}

.gallery-key-row .api-key {
    flex: 1 1 320px;
}

.gallery-usage-row {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding-left: 2px;
}

.usage-key-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 1px 4px 1px 8px;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    background: rgba(124, 140, 255, 0.08);
}

.usage-key-chip .link {
    font-size: 10.5px;
}

.gallery-create {
    margin-top: 12px;
}

.gallery-hint {
    margin-top: 8px;
}

/* ---------- API usage page ---------- */

.stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.usage-note {
    margin-bottom: 10px;
}

.usage-keys {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.usage-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.usage-row {
    display: grid;
    grid-template-columns: minmax(0, 2fr) 150px minmax(0, 1.2fr);
    align-items: center;
    column-gap: 12px;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-soft);
}

.usage-row:last-child {
    border-bottom: none;
}

.usage-row-head {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.usage-image {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}

.usage-image code {
    max-width: 100%;
}

.library-row .text {
    min-width: 180px;
}

.library-row .library-name {
    flex: 0 1 180px;
    min-width: 120px;
    font-family: inherit;
}

.library-row .btn {
    flex: none;
}

.library-meta {
    margin-top: -6px;
    padding-left: 2px;
}

.api-key-row {
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    padding-left: 2px;
}

.ai-endpoint {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-panel);
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 12px;
}

.ai-endpoint .text {
    min-width: 200px;
}

.api-key {
    flex: 1 1 320px;
    max-width: 460px;
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 12px;
}

.shared-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 10px;
    line-height: 16px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    vertical-align: middle;
}

.code-block {
    margin: 8px 0;
    padding: 12px;
    overflow-x: auto;
    background: #0d1320;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    color: var(--text);
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
}

.app-main {
    flex: 1;
    padding: 22px;
}

/* ---------- library layout ---------- */

.library {
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.sidebar {
    position: sticky;
    top: 78px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 16px;
    max-height: calc(100vh - 100px);
    overflow: auto;
}

.side-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
}

.link {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
}

.search {
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #0d1320;
    color: var(--text);
    font-size: 13px;
}

.search:focus {
    outline: 2px solid rgba(124, 140, 255, 0.35);
    border-color: var(--accent);
}

.tag-filters {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-height: 320px;
    overflow: auto;
}

.tag-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
}

.tag-filter:hover {
    background: var(--bg-panel);
}

.tag-filter.active {
    background: rgba(124, 140, 255, 0.14);
    border-color: rgba(124, 140, 255, 0.5);
}

.tag-filter .name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag-filter .count {
    font-size: 11px;
    color: var(--text-muted);
    background: #0d1320;
    border-radius: 999px;
    padding: 1px 7px;
    min-width: 22px;
    text-align: center;
}

.tag-dot {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    background: var(--tag-color, var(--accent));
    flex: none;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
}

.segmented button {
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 5px 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.segmented button.active {
    background: var(--accent-strong);
    color: #fff;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.check input {
    accent-color: var(--accent);
}

.stats {
    border-top: 1px solid var(--border-soft);
    padding-top: 12px;
    font-size: 12px;
    color: var(--text-muted);
    gap: 4px;
}

.stats strong {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ---------- content ---------- */

.content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
    position: relative;
}

/* ---------- drag-and-drop upload ---------- */

.drop-overlay {
    position: absolute;
    inset: -8px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    border: 2px dashed var(--accent);
    border-radius: calc(var(--radius) + 4px);
    background: rgba(12, 17, 27, 0.82);
    pointer-events: none;
    z-index: 20;
}

.content.accepts-drop .drop-overlay {
    display: flex;
}

.drop-overlay-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
    padding: 18px 26px;
    border-radius: var(--radius);
    background: var(--bg-elevated);
    border: 1px solid var(--accent);
}

.drop-overlay-card strong {
    font-size: 16px;
    color: var(--accent);
}

.drop-overlay-card span {
    color: var(--text-muted);
    font-size: 13px;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

.crumb {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 3px 6px;
    border-radius: 6px;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crumb:hover {
    color: var(--text);
    background: var(--bg-panel);
}

.crumb:last-of-type {
    color: var(--text);
    font-weight: 600;
}

.crumb-sep {
    color: #3a4560;
    font-size: 11px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.select {
    background: #0d1320;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 9px;
    font-size: 13px;
    cursor: pointer;
}

.select:focus {
    outline: 2px solid rgba(124, 140, 255, 0.35);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--bg-panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 13px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    background: #1b2434;
    border-color: #33425c;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn.primary {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: #fff;
}

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

.btn.danger {
    background: #7f1d1d;
    border-color: #991b1b;
    color: #fee2e2;
}

.btn.ghost {
    background: transparent;
}

.btn.small {
    padding: 4px 9px;
    font-size: 12px;
}

.btn.glyph {
    min-width: 30px;
    padding: 4px 6px;
    font-size: 15px;
    line-height: 1;
    font-variant-emoji: text;
}

.btn.icon {
    padding: 7px 10px;
    font-size: 14px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
}

.icon-btn:hover {
    background: var(--bg-panel);
    color: var(--text);
}

.banner {
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    border: 1px solid transparent;
}

.banner.error {
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.4);
    color: #fca5a5;
}

.banner.ok {
    background: rgba(52, 211, 153, 0.1);
    border-color: rgba(52, 211, 153, 0.35);
    color: #6ee7b7;
}

.banner.warn {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.38);
    color: #fcd34d;
}

.sync-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.bulk-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    background: rgba(124, 140, 255, 0.1);
    border: 1px solid rgba(124, 140, 255, 0.35);
    border-radius: 9px;
    padding: 9px 12px;
    font-size: 13px;
}

.bulk-new {
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 6px 9px;
    font-size: 12px;
    width: 160px;
}

.section-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-top: 4px;
}

.section-head h2 {
    margin: 0;
    color: var(--text);
    font-size: 13px;
    letter-spacing: 0.09em;
}

.section-head .muted {
    font-size: 12px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 14px;
}

/* ---------- cards ---------- */

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    overflow: visible;
    transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

.card:hover {
    border-color: #37476a;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
    z-index: 2;
}

.card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset;
}

/* ---------- dragging items between folders ---------- */

.card[draggable="true"] {
    cursor: grab;
}

.card.dragging {
    opacity: 0.4;
}

.card.drop-target,
.crumb.drop-target {
    border-color: var(--accent);
    outline: 2px dashed var(--accent);
    outline-offset: 2px;
    background: rgba(124, 140, 255, 0.14);
}

.crumb.drop-target {
    color: var(--accent);
}

.card-thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-bottom: 1px solid var(--border-soft);
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    overflow: hidden;
    background-color: #0d1320;
    background-image:
        linear-gradient(45deg, #131b29 25%, transparent 25%),
        linear-gradient(-45deg, #131b29 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #131b29 75%),
        linear-gradient(-45deg, transparent 75%, #131b29 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.card-thumb img {
    width: 100%;
    height: 100%;
    padding: 10px;
    image-rendering: pixelated;
    object-fit: contain;
    transition: transform 0.15s ease;
}

.card:hover .card-thumb img {
    transform: scale(1.03);
}

.folder-glyph {
    grid-template-columns: repeat(2, 16px);
    grid-template-rows: repeat(2, 16px);
    gap: 4px;
    opacity: 0.85;
}

.folder-glyph i {
    width: 16px;
    height: 16px;
    border-radius: 2px;
}

.thumb-badge {
    position: absolute;
    left: 8px;
    bottom: 8px;
    font-size: 10px;
    color: var(--text);
    background: rgba(6, 9, 15, 0.78);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    padding: 2px 8px;
    backdrop-filter: blur(4px);
}

.card-body {
    padding: 9px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.card-title:hover {
    color: var(--accent);
}

.card-sub {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 18px;
}

.card-variants {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.variant-select {
    flex: 1;
    min-width: 0;
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 11px;
    padding: 3px 5px;
    cursor: pointer;
}

.sync-badge {
    flex: none;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fcd34d;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.4);
    border-radius: 999px;
    padding: 1px 6px;
}

/* ---------- API usage on a card ---------- */

.card-usage {
    position: relative;
    display: flex;
}

.usage-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 600;
    color: var(--ok);
    background: rgba(52, 211, 153, 0.12);
    border: 1px solid rgba(52, 211, 153, 0.4);
    border-radius: 999px;
    padding: 1px 8px;
    cursor: default;
    outline: none;
}

.usage-chip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.usage-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ok);
}

.usage-pop {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 8;
    min-width: 220px;
    padding: 8px 9px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    cursor: default;
}

.card-usage:hover .usage-pop,
.card-usage:focus-within .usage-pop {
    display: block;
}

.usage-pop-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    padding-bottom: 5px;
    margin-bottom: 5px;
    border-bottom: 1px solid var(--border-soft);
}

.usage-pop-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    padding: 2px 0;
}

.usage-pop-row code {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.usage-clear {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: 5px;
    font-size: 10px;
    padding: 1px 6px;
    cursor: pointer;
}

.usage-clear:hover {
    color: #fff;
    border-color: var(--danger);
    background: rgba(248, 113, 113, 0.18);
}

.card-check {
    position: absolute;
    top: 7px;
    left: 7px;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: rgba(6, 9, 15, 0.7);
    border: 1px solid var(--border-soft);
    opacity: 0.5;
    transition: opacity 0.12s ease;
    cursor: pointer;
}

.card:hover .card-check,
.card.selected .card-check {
    opacity: 1;
}

.card-check input {
    accent-color: var(--accent);
    width: 13px;
    height: 13px;
    cursor: pointer;
}

.card-tag-btn {
    position: absolute;
    top: 7px;
    right: 7px;
    z-index: 3;
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: rgba(6, 9, 15, 0.7);
    border: 1px solid var(--border-soft);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.12s ease;
}

.card:hover .card-tag-btn,
.card-tag-btn.active {
    opacity: 1;
}

.card-tag-btn:hover,
.card-tag-btn.active {
    color: #fff;
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

/* ---------- tag chips ---------- */

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    line-height: 1.5;
    padding: 1px 7px 1px 5px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--tag-color, #7c8cff) 20%, transparent);
    border: 1px solid color-mix(in srgb, var(--tag-color, #7c8cff) 55%, transparent);
    color: color-mix(in srgb, var(--tag-color, #7c8cff) 70%, #ffffff);
    max-width: 130px;
}

.tag-chip .tag-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag-chip.inherited {
    opacity: 0.68;
    border-style: dashed;
}

.tag-chip .tag-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.tag-more {
    font-size: 10.5px;
    color: var(--text-muted);
    background: var(--bg-panel);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    padding: 1px 7px;
}

/* ---------- tag editor popover ---------- */

.tag-editor {
    position: absolute;
    z-index: 20;
    top: calc(100% - 6px);
    left: 0;
    right: 0;
    background: #0f1622;
    border: 1px solid var(--border);
    border-radius: 9px;
    box-shadow: var(--shadow);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tag-editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.tag-editor-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 190px;
    overflow: auto;
}

.tag-option {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 3px 4px;
    border-radius: 6px;
    cursor: pointer;
}

.tag-option:hover {
    background: var(--bg-panel);
}

.tag-option input {
    accent-color: var(--accent);
    margin: 0;
}

.tag-editor-new {
    display: flex;
    gap: 6px;
}

.tag-editor-new input {
    flex: 1;
    min-width: 0;
    background: #0b111c;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    padding: 5px 7px;
    font-size: 12px;
}

.tag-editor-error {
    font-size: 11px;
    color: #fca5a5;
}

/* ---------- lightbox ---------- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(3, 6, 11, 0.82);
    display: grid;
    place-items: center;
    padding: 26px;
    backdrop-filter: blur(3px);
}

.lightbox-inner {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 18px;
    max-width: min(94vw, 1100px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lightbox-inner.dialog {
    width: min(94vw, 420px);
}

.lightbox-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.lightbox-title {
    font-size: 16px;
    font-weight: 600;
}

.lightbox-image {
    flex: 1;
    min-height: 120px;
    display: grid;
    place-items: center;
    overflow: auto;
    background-color: #0d1320;
    background-image:
        linear-gradient(45deg, #131b29 25%, transparent 25%),
        linear-gradient(-45deg, #131b29 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #131b29 75%),
        linear-gradient(-45deg, transparent 75%, #131b29 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    border-radius: 10px;
    padding: 14px;
}

.lightbox-image img {
    max-width: 100%;
    max-height: 62vh;
    width: auto;
    min-width: min(100%, 256px);
    image-rendering: pixelated;
}

.lightbox-tags {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* ---------- panels, forms ---------- */

.panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    max-width: 880px;
}

.panel h2 {
    color: var(--text);
    font-size: 13px;
}

.panel p {
    margin: 0 0 14px;
}

.field-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
}

.text {
    flex: 1;
    min-width: 260px;
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 10px;
    font-size: 13px;
    font-family: "Cascadia Code", Consolas, monospace;
}

.text:focus {
    outline: 2px solid rgba(124, 140, 255, 0.35);
    border-color: var(--accent);
}

input[type="number"] {
    width: 100px;
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 7px 9px;
    font-size: 13px;
}

.color {
    width: 42px;
    height: 34px;
    padding: 2px;
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

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

.tag-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tag-row {
    display: grid;
    grid-template-columns: 48px minmax(140px, 1fr) 190px 190px;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-soft);
}

.tag-row:last-child {
    border-bottom: none;
}

.tag-row-head {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.tag-row .text {
    min-width: 0;
    font-family: inherit;
}

.confirm {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* ---------- empty states ---------- */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state h1,
.empty-state h2 {
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    font-size: 22px;
    margin: 0;
}

.empty-inline {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    padding: 60px 20px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
}

.empty-inline h2 {
    margin: 0;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    font-size: 16px;
}

/* ---------- modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(3, 6, 11, 0.78);
    display: grid;
    place-items: center;
    padding: 24px;
}

.modal {
    width: min(720px, 96vw);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 18px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-head h2 {
    margin: 0;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    font-size: 16px;
}

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-top: 1px solid var(--border-soft);
    padding-top: 12px;
}

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

/* ---------- paste placement ---------- */

.paste-modal {
    width: min(560px, 96vw);
}

.extract-modal {
    width: min(480px, 96vw);
}

.smooth-modal {
    width: min(440px, 96vw);
}

.smooth-slider {
    width: 100%;
    height: 26px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.segmented.three {
    grid-template-columns: repeat(3, 1fr);
}

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

.paste-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.paste-align {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* The editor sidebar is narrow, so alignment groups stack instead of sitting side by side. */
.resize-align {
    grid-template-columns: 1fr;
    gap: 8px;
}

.paste-align-group {
    margin: 0;
    padding: 8px 10px 10px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.paste-align-group legend {
    padding: 0 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.paste-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px;
    background: #0d1320;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
}

.paste-preview canvas {
    max-width: 100%;
    max-height: 260px;
    image-rendering: pixelated;
    background-color: #131a28;
    background-image:
        linear-gradient(45deg, rgba(255, 255, 255, 0.06) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(255, 255, 255, 0.06) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.06) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.06) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.picker-path {
    display: flex;
    gap: 8px;
}

.picker-path input {
    flex: 1;
    min-width: 0;
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 10px;
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 12.5px;
}

.picker-roots {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.chip {
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    padding: 3px 10px;
    font-size: 11.5px;
    cursor: pointer;
}

.chip:hover {
    color: var(--text);
    border-color: #37476a;
}

.picker-list {
    flex: 1;
    min-height: 220px;
    max-height: 44vh;
    overflow: auto;
    border: 1px solid var(--border-soft);
    border-radius: 9px;
    background: #0b111c;
    padding: 5px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.picker-row {
    display: flex;
    align-items: center;
    gap: 9px;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--text);
    padding: 7px 9px;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
}

.picker-row:hover {
    background: var(--bg-panel);
}

.picker-icon {
    color: var(--text-muted);
    font-size: 11px;
    width: 12px;
}

.picker-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- pixel editor ---------- */

.card-actions {
    padding: 0 10px 10px;
    margin-top: -2px;
}

.card-actions.row {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

.card-actions.row .card-new {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
}

.card-delete {
    flex: 0 0 auto;
    padding: 5px 9px;
    font-size: 11.5px;
    font-weight: 600;
    color: #fca5a5;
    background: #170f11;
    border: 1px dashed #7f1d1d;
    border-radius: 7px;
    cursor: pointer;
    transition: color 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.card-delete:hover {
    color: #fff;
    border-color: #b91c1c;
    background: #7f1d1d;
}

.card-delete.danger {
    color: #fee2e2;
    border-style: solid;
}

.card-new {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 5px 8px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-muted);
    background: #0f1622;
    border: 1px dashed var(--border);
    border-radius: 7px;
    cursor: pointer;
    transition: color 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.card-new:hover {
    color: #fff;
    border-color: var(--accent);
    background: rgba(124, 140, 255, 0.12);
}

.editor-layout {
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
    min-height: calc(100vh - 140px);
}

.editor-sidebar {
    position: sticky;
    top: 78px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 16px;
    max-height: calc(100vh - 100px);
    overflow: auto;
}

/* ---------- editor sidebar collapsible sections ---------- */

.editor-sidebar .side-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: -2px;
}

.editor-sidebar .side-actions .link {
    font-size: 11px;
    letter-spacing: 0.03em;
    transition: color 0.14s ease, opacity 0.14s ease;
}

.editor-sidebar .side-actions .link:hover:not(:disabled) {
    text-decoration: underline;
}

.editor-sidebar .side-actions .link:disabled {
    color: var(--text-muted);
    opacity: 0.5;
    cursor: default;
}

.editor-sidebar .side-block.collapsible {
    gap: 8px;
    padding: 0 10px 10px;
    border: 1px solid var(--border-soft);
    border-radius: calc(var(--radius) - 2px);
    background: rgba(255, 255, 255, 0.018);
}

.editor-sidebar .side-block.collapsible.collapsed {
    padding-bottom: 0;
}

.editor-sidebar .side-block.collapsible.collapsed > :not(.side-head) {
    display: none;
}

.editor-sidebar .side-block.collapsible > .side-head {
    gap: 8px;
    margin: 0 -10px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.035);
    border-bottom: 1px solid var(--border-soft);
    border-radius: calc(var(--radius) - 3px) calc(var(--radius) - 3px) 0 0;
}

.editor-sidebar .side-block.collapsible.collapsed > .side-head {
    border-bottom-color: transparent;
    border-radius: calc(var(--radius) - 3px);
}

.editor-sidebar .side-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    padding: 2px 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    text-align: left;
    cursor: pointer;
}

.editor-sidebar .side-toggle:focus-visible {
    outline: 2px solid rgba(124, 140, 255, 0.55);
    outline-offset: 2px;
    border-radius: 4px;
}

.editor-sidebar .side-toggle:hover .side-title,
.editor-sidebar .side-toggle:focus-visible .side-title {
    color: var(--accent);
}

.editor-sidebar .side-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text);
    transition: color 0.14s ease;
}

.editor-sidebar .side-block.collapsible.collapsed .side-title {
    color: var(--text-muted);
}

.editor-sidebar .side-chevron {
    flex: none;
    width: 0;
    height: 0;
    border-left: 5px solid currentColor;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transform: rotate(90deg);
    transition: transform 0.16s ease;
    opacity: 0.85;
}

.editor-sidebar .side-block.collapsed .side-chevron {
    transform: rotate(0deg);
}

.editor-main {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    min-height: 0;
}

.editor-tabs {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 0 2px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.editor-tab {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
    max-width: 220px;
    padding: 3px 3px 3px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    color: var(--text-muted);
}

.editor-tab.active {
    background: rgba(124, 140, 255, 0.14);
    border-color: var(--accent);
    color: var(--text);
}

.editor-tab-label {
    max-width: 170px;
    padding: 3px 0;
    overflow: hidden;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    font-size: 12.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.editor-tab-close {
    padding: 1px 6px;
    background: none;
    border: none;
    border-radius: 5px;
    color: inherit;
    font-size: 14px;
    line-height: 1.1;
    opacity: 0.65;
    cursor: pointer;
}

.editor-tab-close:hover {
    background: rgba(255, 255, 255, 0.12);
    opacity: 1;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}

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

.selection-size-group input {
    width: 60px;
}

.toolbar-group.push-right {
    margin-left: auto;
}

.name-group {
    flex: 1 1 460px;
    flex-wrap: wrap;
}

.name-group .field.inline {
    flex: 1 1 180px;
    width: auto;
}

.name-group .variant-field {
    flex: 0 0 auto;
}

.field.inline {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.field.inline .text {
    min-width: 0;
    padding: 5px 9px;
    font-size: 12.5px;
}

.variant-field {
    flex: none;
}

.select.compact {
    padding: 4px 7px;
    font-size: 11.5px;
    min-width: 0;
}

.res-fields {
    display: flex;
    gap: 10px;
}

.res-fields input[type="number"] {
    width: 100%;
}

.preset-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.btn.full {
    width: 100%;
}

.color-input {
    width: 40px;
    height: 34px;
    padding: 2px;
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.color-picker {
    display: flex;
    align-items: center;
    gap: 6px;
}

.color-preview {
    width: 26px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background-image:
        linear-gradient(var(--preview), var(--preview)),
        conic-gradient(#3a4152 25%, #222a39 0 50%, #3a4152 0 75%, #222a39 0);
    background-size: 100% 100%, 8px 8px;
    background-position: 0 0, 0 0;
}

.alpha-row {
    display: flex;
    align-items: center;
    gap: 5px;
}

.alpha-slider {
    width: 84px;
    height: 34px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.alpha-value {
    min-width: 34px;
    text-align: right;
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.swatches {
    display: grid;
    grid-template-columns: repeat(8, 18px);
    gap: 3px;
}

.palette-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.palette-mode {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.palette-badge {
    font-size: 10.5px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(124, 140, 255, 0.18);
    border: 1px solid rgba(124, 140, 255, 0.45);
    color: var(--text);
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-preview {
    max-height: 120px;
    overflow: auto;
    padding: 6px;
}

.swatch.static {
    cursor: default;
}

.convert-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.convert-row > * {
    min-width: 0;
}

.convert-row .select {
    width: 100%;
}

.palette-dialog {
    width: min(460px, 96vw);
}

.palette-mode .btn {
    padding: 2px 6px;
    font-size: 10.5px;
}

.color-suggestions {
    display: flex;
    align-items: center;
    gap: 5px;
}

.suggestion-swatches {
    display: flex;
    gap: 3px;
}

.swatch.suggestion {
    border-style: dashed;
}

.swatch {
    width: 18px;
    height: 18px;
    padding: 0;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: var(--swatch);
    cursor: pointer;
}

.swatch.active {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.zoom-label {
    min-width: 46px;
    text-align: center;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.pixel-canvas-host {
    position: relative;
    flex: 1;
    min-height: 480px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #080b11;
    overflow: hidden;
    touch-action: none;
}

.pixel-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.editor-hint {
    text-align: center;
}

.editor-hint.paste-active {
    color: #7ee787;
}

.editor-file-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 45vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
}

.editor-file-list > * {
    flex: 0 0 auto;
}

.editor-crumbs {
    flex-wrap: wrap;
    margin: 0;
}

.editor-crumbs .crumb {
    font-size: 11px;
}

.editor-folder-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.editor-folder {
    padding-top: 4px;
    padding-bottom: 4px;
    font-weight: 500;
}

.editor-folder .folder-glyph {
    grid-template-columns: repeat(2, 8px);
    grid-template-rows: repeat(2, 8px);
    gap: 2px;
    flex: none;
    width: 18px;
    height: 18px;
}

.editor-folder .folder-glyph i {
    width: 8px;
    height: 8px;
    border-radius: 1px;
}

.editor-file {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 5px 7px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    text-align: left;
    min-width: 0;
    cursor: pointer;
}

.editor-file-row {
    display: flex;
    align-items: stretch;
    gap: 4px;
}

.editor-file-row .editor-file {
    flex: 1;
    min-width: 0;
}

.layer-add {
    flex: none;
    width: 26px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #0f1622;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: color 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.layer-add:hover:not(:disabled) {
    color: #fff;
    border-color: var(--accent);
    background: rgba(124, 140, 255, 0.12);
}

.layer-add:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.editor-file-badge {
    flex: none;
    align-self: center;
    padding: 0 4px;
    border: 1px solid rgba(255, 209, 102, 0.55);
    border-radius: 5px;
    color: #ffd166;
    font-size: 9px;
    letter-spacing: 0.06em;
    line-height: 16px;
}

.layer-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.layer-row {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px 4px;
    border: 1px solid transparent;
    border-radius: 7px;
}

.layer-row.active {
    border-color: var(--accent-strong);
    background: rgba(93, 110, 240, 0.18);
}

.layer-toggle,
.layer-mini {
    flex: none;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
}

.layer-toggle:hover,
.layer-mini:hover:not(:disabled) {
    background: var(--bg-panel);
    color: #fff;
}

.layer-mini:disabled {
    opacity: 0.3;
    cursor: default;
}

.layer-mini.active {
    background: rgba(93, 110, 240, 0.28);
    color: #fff;
}

.layer-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
}

.layer-name:hover {
    color: var(--accent);
}

.layer-ref {
    flex: none;
    align-self: center;
    padding: 0 5px;
    border: 1px solid rgba(255, 209, 102, 0.55);
    border-radius: 5px;
    color: #ffd166;
    font-size: 9px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.layer-file {
    flex: none;
    align-self: center;
    padding: 0 5px;
    border: 1px solid rgba(126, 231, 135, 0.55);
    border-radius: 5px;
    color: #7ee787;
    font-size: 9px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.layer-offset {
    flex: none;
    color: var(--text-muted);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}

.layer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Layer × draw-order-tag grid: a ticked cell draws that layer behind the tag's layers. */
.behind-matrix-wrap {
    overflow-x: auto;
    padding: 2px 0 4px;
}

.behind-matrix {
    border-collapse: collapse;
    font-size: 10px;
}

.behind-matrix th,
.behind-matrix td {
    padding: 1px 2px;
    text-align: center;
}

.behind-matrix thead th {
    font-weight: 500;
    color: var(--text-muted);
}

.behind-matrix th.behind-col {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
    max-height: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.behind-matrix th.behind-corner {
    width: 1px;
}

.behind-matrix th.behind-row-name {
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    font-weight: 400;
    color: var(--text);
}

.behind-matrix tbody tr.active th.behind-row-name {
    color: var(--accent);
}

.behind-matrix input[type="checkbox"] {
    width: 13px;
    height: 13px;
    margin: 0;
    accent-color: var(--accent-strong);
    cursor: pointer;
}

.curve-edge {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border-soft);
}

.curve-edge input[type="file"] {
    max-width: 100%;
    font-size: 12px;
    color: var(--text-muted);
}

.curve-edge input[type="file"]::file-selector-button {
    margin-right: 8px;
    padding: 5px 10px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.curve-edge input[type="file"]::file-selector-button:hover {
    background: #1b2434;
    border-color: #33425c;
}

/* A thin strip is only a few pixels tall, so it is shown scaled up but never squashed. */
.curve-edge-thumb {
    align-self: flex-start;
    height: 32px;
    max-width: 100%;
    background: #0d1320;
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    object-fit: contain;
    image-rendering: pixelated;
}

.region-layer {
    border: 1px dashed rgba(124, 140, 255, 0.4);
    margin-bottom: 2px;
}

.region-layer-name {
    cursor: default;
    font-style: italic;
    color: var(--text-muted);
}

.region-layer-name:hover {
    color: var(--text-muted);
}

.muted-layer .region-layer-name {
    opacity: 0.55;
    text-decoration: line-through;
}

.region-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.region-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 4px;
    border: 1px solid transparent;
    border-radius: 7px;
}

.region-row.active {
    border-color: #ffd166;
    background: rgba(255, 209, 102, 0.14);
}

.region-name {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
}

.region-name:hover {
    color: #ffd166;
}

.region-swatch {
    flex: none;
    width: 9px;
    height: 9px;
    border-radius: 2px;
    border: 1px solid rgba(255, 209, 102, 0.9);
    background: rgba(255, 209, 102, 0.25);
}

.region-swatch.mask {
    border-style: dashed;
    border-color: #ffb703;
    background: rgba(255, 183, 3, 0.3);
}

.region-mask-badge {
    flex: none;
    padding: 0 4px;
    border: 1px solid rgba(255, 183, 3, 0.65);
    border-radius: 4px;
    color: #ffb703;
    font-size: 8.5px;
    letter-spacing: 0.05em;
    line-height: 13px;
    text-transform: uppercase;
}

.region-size {
    flex: none;
    font-size: 10.5px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.region-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border-soft);
}

.region-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.region-editor .text {
    min-width: 0;
    width: 100%;
    padding: 6px 8px;
    font-size: 12px;
}

.region-fields input[type="number"] {
    width: 100%;
}

.side-subhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 10.5px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.region-attributes {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.attribute-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px;
}

.attribute-row .text {
    min-width: 0;
    width: 100%;
    padding: 4px 6px;
    font-size: 11.5px;
}

.region-mask-badge.focus {
    border-color: rgba(126, 231, 135, 0.8);
    color: #7ee787;
}

.region-mask-badge.attr {
    border-color: rgba(126, 231, 135, 0.55);
    color: #9be9a8;
}

.atlas-merge {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
}

.atlas-picked {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.atlas-picked-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.atlas-picked-chips .chip {
    padding: 1px 6px;
    border: 1px solid rgba(126, 231, 135, 0.55);
    border-radius: 999px;
    background: rgba(126, 231, 135, 0.12);
    color: #9be9a8;
    font-family: inherit;
    font-size: 10.5px;
    line-height: 15px;
    cursor: pointer;
}

.atlas-picked-chips .chip:hover {
    background: rgba(126, 231, 135, 0.22);
}

.editor-file:hover {
    background: var(--bg-panel);
    text-decoration: none;
}

.editor-file:disabled {
    opacity: 0.5;
    cursor: wait;
}

.editor-file.current {
    border-color: var(--accent);
    background: rgba(124, 140, 255, 0.1);
}

.editor-file.selected {
    border-color: var(--accent-strong);
    background: rgba(93, 110, 240, 0.22);
}

.editor-file-size {
    margin-left: auto;
    flex: none;
    font-size: 10.5px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.editor-file img {
    width: 30px;
    height: 30px;
    object-fit: contain;
    image-rendering: pixelated;
    background: #0d1320;
    border-radius: 4px;
    flex: none;
}

.resize-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.resize-source {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    font-size: 12px;
}

.resize-message {
    font-size: 12px;
    padding: 6px 8px;
    border-radius: 7px;
    border: 1px solid transparent;
}

.resize-message.ok {
    background: rgba(52, 211, 153, 0.1);
    border-color: rgba(52, 211, 153, 0.35);
    color: #6ee7b7;
}

.resize-message.error {
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.4);
    color: #fca5a5;
}

.resize-message.warn {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.4);
    color: #fcd34d;
}

/* ---------- responsive ---------- */

@media (max-width: 1000px) {
    .library {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        max-height: none;
    }

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

    .editor-sidebar {
        position: static;
        max-height: none;
    }

    .root-label {
        display: none;
    }

    .library-select {
        max-width: 140px;
    }
}

@media (max-width: 720px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    }

    .tag-row {
        grid-template-columns: 44px 1fr 130px;
    }

    .tag-row .confirm,
    .tag-row > .btn {
        grid-column: span 3;
        justify-self: end;
    }

    .usage-row {
        grid-template-columns: minmax(0, 1fr) 110px;
    }

    .usage-row > :last-child {
        display: none;
    }
}

/* ---- AI edit panel ---- */

.side-block .text {
    min-width: 0;
    width: 100%;
}

.textarea {
    resize: vertical;
    line-height: 1.45;
    min-height: 56px;
}

.workflow-textarea {
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 12px;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
}

.ai-block .resize-message {
    margin-top: 2px;
}

.ai-preview {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-panel);
}

.ai-preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ai-preview-image {
    display: grid;
    place-items: center;
    padding: 6px;
    border-radius: 8px;
    background:
        repeating-conic-gradient(#151b27 0% 25%, #1d2636 0% 50%) 50% / 16px 16px;
    max-height: 260px;
    overflow: hidden;
}

.ai-preview-image img {
    max-width: 100%;
    max-height: 248px;
    image-rendering: pixelated;
    display: block;
}

.panel h3 {
    margin: 14px 0 4px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.panel code {
    background: #0d1320;
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    padding: 1px 4px;
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 12px;
}

.preview-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 240px;
    padding: 16px;
    background: #0d1320;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
}

.preview-image {
    max-width: 100%;
    max-height: 512px;
    image-rendering: pixelated;
    display: block;
}

/* Game files page */
.files-upload {
    align-items: center;
}

.files-upload input[type="file"] {
    max-width: 320px;
    font-family: inherit;
    font-size: 12px;
    color: var(--text-muted);
}

.files-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 12px 0 8px;
    font-size: 12px;
}

.files-breadcrumbs .link {
    font-family: inherit;
}

.files-clone {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-elevated);
}

.files-clone code {
    flex: 1 1 320px;
    overflow-x: auto;
    white-space: nowrap;
    font-family: inherit;
    font-size: 12px;
}

.files-history {
    margin-top: 16px;
}

.files-history h3 {
    margin: 0;
    font-size: 13px;
}

/* Palette generation: lockable swatches and the palette studio page. */
.swatch-cell {
    position: relative;
    display: block;
    width: 18px;
    height: 18px;
}

.swatch-cell .swatch {
    display: block;
    width: 100%;
    height: 100%;
}

.swatch-lock {
    position: absolute;
    right: -5px;
    bottom: -5px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    font-size: 8px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.swatch-cell:hover .swatch-lock,
.swatch-cell.locked .swatch-lock {
    opacity: 1;
}

.swatch-cell.locked .swatch {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.palette-generate {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.palette-generate > * {
    min-width: 0;
}

.palette-generate .select {
    width: 100%;
}

.palette-studio {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin: 14px 0;
}

.studio-chip {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.studio-swatch {
    width: 92px;
    height: 92px;
    padding: 0;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: var(--swatch);
    cursor: pointer;
}

.studio-chip.locked .studio-swatch {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.studio-lock {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: rgba(11, 15, 23, 0.72);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
}

.studio-hex {
    text-align: center;
    font-size: 11px;
    font-family: "Cascadia Code", Consolas, monospace;
    color: var(--text-muted);
}

.saved-palette {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid var(--border-soft);
}

.saved-palette:first-of-type {
    border-top: none;
}

.saved-palette-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.palette-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.palette-slider {
    flex: 1 1 170px;
    min-width: 0;
}

.palette-slider input[type="range"] {
    width: 100%;
}

/* ---- accounts and collaboration ---- */

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.user-name {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.pill.subtle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.login-page {
    display: flex;
    justify-content: center;
    padding: 64px 16px;
}

.login-card {
    width: min(520px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-providers {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-provider {
    justify-content: center;
    text-align: center;
}

.login-hint {
    background: #0d1320;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 12px;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table th,
.table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
}

.invite-link {
    width: 100%;
    min-width: 320px;
    font-size: 11px;
}
