* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0c0c0f;
    --panel: #121217;
    --panel2: #15151b;
    --edit: #0f0f14;
    --line: #242430;
    --line2: #31313d;
    --fg: #d9d5cb;
    --dim: #8a8792;
    --faint: #5b5864;
    --accent: #f0a43c;
    --accent-dim: rgba(240, 164, 60, .13);
    --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
    --px: 'Silkscreen', var(--mono);
    --gutter: 46px;
    --lh: 20px;
}

html,
body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--fg);
    font: 400 13px var(--mono);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
}

textarea {
    user-select: text;
    -webkit-user-select: text;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

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

svg {
    display: block;
}

/* ── top bar ─────────────────────────────── */
.topbar {
    height: 54px;
    flex: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    margin-right: auto;
    min-width: 0;
}

.logo {
    flex: none;
}

.bt .title {
    font: 700 13px var(--px);
    letter-spacing: 1px;
}

.bt .title span {
    color: var(--accent);
}

.bt .tag {
    font: 400 10px var(--mono);
    color: var(--faint);
    margin-top: 1px;
    white-space: nowrap;
}

.tb-actions {
    display: flex;
    align-items: center;
    gap: 7px;
}

.vsep {
    width: 1px;
    height: 18px;
    background: var(--line);
    margin: 0 3px;
}

.btn {
    height: 32px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    font: 600 10.5px var(--mono);
    letter-spacing: .5px;
    color: var(--dim);
    transition: background .12s, color .12s, border-color .12s;
}

.btn:hover {
    color: var(--fg);
    border-color: var(--line2);
    background: rgba(255, 255, 255, .035);
}

.btn.icon {
    width: 32px;
    padding: 0;
    justify-content: center;
}

.btn.sm {
    height: 26px;
    width: 26px;
}

.btn.tog.on {
    color: var(--accent);
    border-color: rgba(240, 164, 60, .45);
    background: var(--accent-dim);
}

.btn.primary {
    background: var(--accent);
    border-color: transparent;
    color: #241703;
    font-weight: 700;
}

.btn.primary:hover {
    filter: brightness(1.08);
    background: var(--accent);
}

.btn:disabled {
    opacity: .32;
    pointer-events: none;
}

.menu-wrap {
    position: relative;
}

/* ── main ─────────────────────────────────── */
main {
    flex: 1;
    display: flex;
    min-height: 0;
}

.toolrail {
    width: 54px;
    flex: none;
    background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 0 12px;
}

.tool {
    width: 40px;
    height: 40px;
    border-radius: 9px;
    color: var(--dim);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: color .12s, background .12s;
}

.tool:hover {
    color: var(--fg);
    background: rgba(255, 255, 255, .045);
}

.tool.on {
    color: var(--accent);
    background: var(--accent-dim);
    box-shadow: inset 0 0 0 1px rgba(240, 164, 60, .42);
}

.tool::after {
    content: attr(data-tip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    pointer-events: none;
    background: #050508;
    border: 1px solid var(--line2);
    border-radius: 6px;
    padding: 4px 8px;
    font: 500 10px var(--mono);
    color: var(--fg);
    opacity: 0;
    transition: opacity .12s;
    z-index: 40;
}

.tool:hover::after {
    opacity: 1;
}

.rsep {
    width: 20px;
    height: 1px;
    background: var(--line);
    margin: 4px 0;
}

.rail-spacer {
    flex: 1;
}

.chip {
    width: 40px;
    height: 40px;
    border-radius: 9px;
    position: relative;
    border: 1px solid var(--line2);
    overflow: hidden;
    background: repeating-conic-gradient(#2c2c35 0% 25%, #232329 0% 50%) 0 0/8px 8px;
}

.chip .fill {
    position: absolute;
    inset: 3px;
    border-radius: 6px;
}

.chip .fill.clear {
    background: repeating-conic-gradient(#33333d 0% 25%, #26262e 0% 50%) 0 0/7px 7px;
}

.chip .k {
    position: absolute;
    right: 3px;
    bottom: 1px;
    font: 700 10px var(--px);
    text-shadow: 0 1px 2px rgba(0, 0, 0, .7);
}

/* ── stage ────────────────────────────────── */
.stage {
    position: relative;
    flex: 1;
    min-width: 0;
    background: var(--bg);
    overflow: hidden;
    touch-action: none;
}

#phaserHost {
    position: absolute;
    inset: 0;
}

#phaserHost canvas {
    cursor: crosshair;
}

#artboard {
    position: absolute;
    display: none;
    pointer-events: none;
    background: repeating-conic-gradient(#1d1d24 0% 25%, #15151b 0% 50%);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .05), 0 18px 50px rgba(0, 0, 0, .5);
}

.preview1x {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 7px;
    background: rgba(12, 12, 15, .88);
    border: 1px solid var(--line);
    border-radius: 9px;
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.preview1x canvas {
    image-rendering: pixelated;
    display: block;
    background: repeating-conic-gradient(#26262e 0% 25%, #1b1b21 0% 50%) 0 0/6px 6px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .09);
}

.preview1x .cap {
    font: 400 8px var(--px);
    color: var(--faint);
    letter-spacing: 1px;
}

.statusbar {
    position: absolute;
    left: 12px;
    bottom: 12px;
    max-width: calc(100% - 190px);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 6px 13px;
    background: rgba(12, 12, 15, .88);
    border: 1px solid var(--line);
    border-radius: 9px;
    backdrop-filter: blur(8px);
}

.statusbar .pos {
    font: 400 10px var(--px);
    color: var(--accent);
    letter-spacing: 1px;
}

.keychip {
    display: none;
    align-items: center;
    gap: 7px;
    font: 500 10.5px var(--mono);
    color: var(--dim);
}

.keychip i {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 3px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
    background: repeating-conic-gradient(#33333d 0% 25%, #26262e 0% 50%) 0 0/5px 5px;
}

.keychip em {
    font-style: normal;
    color: var(--faint);
}

.selchip {
    display: none;
    font: 400 10px var(--px);
    color: var(--accent);
    letter-spacing: 1px;
    white-space: nowrap;
}

.statusbar .hint {
    font: 400 10px var(--mono);
    color: var(--faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.zoomer {
    position: absolute;
    right: 12px;
    bottom: 12px;
    display: flex;
    align-items: center;
    gap: 2px;
    background: rgba(12, 12, 15, .88);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 3px;
    backdrop-filter: blur(8px);
}

.zbtn {
    width: 28px;
    height: 26px;
    border-radius: 6px;
    color: var(--dim);
    display: flex;
    align-items: center;
    justify-content: center;
}

.zbtn:hover {
    color: var(--fg);
    background: rgba(255, 255, 255, .05);
}

.zval {
    width: 44px;
    text-align: center;
    font: 400 10px var(--px);
    color: var(--accent);
}

.empty {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 18px;
    pointer-events: none;
    text-align: left;
}

.empty .e-ic {
    color: var(--faint);
}

.empty b {
    display: block;
    font: 700 12px var(--px);
    letter-spacing: 2px;
    color: var(--dim);
    margin-bottom: 6px;
}

.empty span {
    font: 400 11.5px var(--mono);
    color: var(--faint);
    max-width: 340px;
    line-height: 1.7;
    display: block;
}

/* ── reference panel ────────────────────────── */
.refpanel {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 5;
    width: 254px;
    max-width: calc(100% - 24px);
    background: rgba(12, 12, 15, .88);
    border: 1px solid var(--line);
    border-radius: 9px;
    backdrop-filter: blur(8px);
    padding: 10px 11px 11px;
    display: none;
    touch-action: auto;
}

.refpanel.open {
    display: block;
    animation: panelIn .16s ease-out;
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.rp-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 9px;
}

.rp-count {
    font: 400 10px var(--mono);
    color: var(--faint);
}

.rbtn {
    height: 26px;
    min-width: 26px;
    padding: 0 7px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--dim);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font: 600 9.5px var(--mono);
    letter-spacing: .4px;
    transition: color .12s, border-color .12s, background .12s;
}

.rbtn:hover {
    color: var(--fg);
    border-color: var(--line2);
    background: rgba(255, 255, 255, .04);
}

.rbtn:disabled {
    opacity: .3;
    pointer-events: none;
}

.rbtn.on {
    color: var(--accent);
    border-color: rgba(240, 164, 60, .45);
    background: var(--accent-dim);
}

.rbtn.ic {
    width: 26px;
    padding: 0;
}

.rbtn.ic svg {
    width: 13px;
    height: 13px;
}

.rbtn.wide {
    height: 27px;
}

.rbtn.wide span {
    display: inline-flex;
}

.rbtn.wide svg {
    width: 13px;
    height: 13px;
}

.rbtn.acc {
    color: var(--accent);
    border-color: rgba(240, 164, 60, .5);
}

.rbtn.acc:hover {
    background: var(--accent-dim);
}

.rp-empty {
    text-align: center;
    padding: 13px 8px 12px;
    border: 1px dashed var(--line2);
    border-radius: 8px;
}

.rp-empty .rp-eic {
    color: var(--faint);
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}

.rp-empty .rp-eic svg {
    width: 22px;
    height: 22px;
}

.rp-empty b {
    display: block;
    font: 700 9px var(--px);
    letter-spacing: 1.5px;
    color: var(--dim);
    margin-bottom: 7px;
}

.rp-empty>span {
    display: block;
    font: 400 10.5px var(--mono);
    color: var(--faint);
    line-height: 1.65;
    max-width: 204px;
    margin: 0 auto 11px;
}

.rp-empty .rp-dropnote {
    margin: 9px auto 0;
    font-size: 9.5px;
    opacity: .85;
}

.rp-actions {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.rp-full .thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 96px;
    overflow-y: auto;
    padding: 2px;
    margin-bottom: 9px;
    scrollbar-color: #2b2b35 transparent;
    scrollbar-width: thin;
}

.thumb {
    width: 42px;
    height: 42px;
    border-radius: 7px;
    position: relative;
    flex: none;
    border: 1px solid var(--line2);
    display: flex;
    align-items: center;
    justify-content: center;
    background: repeating-conic-gradient(#26262e 0% 25%, #1d1d24 0% 50%) 0 0/8px 8px;
    transition: border-color .12s, box-shadow .12s;
}

.thumb:hover {
    border-color: rgba(255, 255, 255, .3);
}

.thumb.sel {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(240, 164, 60, .3);
}

.thumb canvas {
    image-rendering: pixelated;
    max-width: 34px;
    max-height: 34px;
}

.thumb .tx {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #26262e;
    border: 1px solid var(--line2);
    color: var(--dim);
    font: 700 10px/13px var(--mono);
    text-align: center;
    display: none;
}

.thumb:hover .tx {
    display: block;
}

.thumb .tx:hover {
    color: #ff8f8f;
    border-color: #a05555;
}

.rp-row {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 8px;
}

.rp-num {
    font: 400 10px var(--px);
    color: var(--dim);
    letter-spacing: 1px;
    min-width: 42px;
    text-align: center;
}

.rp-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 7px;
}

.rp-slider label {
    font: 400 8px var(--px);
    color: var(--faint);
    letter-spacing: 1px;
    width: 46px;
    text-transform: uppercase;
}

.rp-slider b {
    font: 500 10px var(--mono);
    color: var(--accent);
    min-width: 42px;
    text-align: right;
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 3px;
    border-radius: 2px;
    background: #2b2b35;
    outline: none;
    cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 11px;
    height: 11px;
    border-radius: 3px;
    background: var(--accent);
    border: 0;
}

input[type=range]::-moz-range-thumb {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    background: var(--accent);
    border: 0;
}

input[type=range]::-moz-range-track {
    background: #2b2b35;
    height: 3px;
    border-radius: 2px;
}

#refNew {
    width: 100%;
    height: 30px;
    margin-top: 1px;
}

.rp-hint {
    font: 400 9.5px var(--mono);
    color: var(--faint);
    line-height: 1.7;
    margin-top: 2px;
}

.rp-hint b {
    color: var(--dim);
    font-weight: 600;
}

.dropveil {
    position: absolute;
    inset: 10px;
    z-index: 6;
    display: none;
    pointer-events: none;
    border: 2px dashed rgba(240, 164, 60, .5);
    border-radius: 12px;
    background: rgba(240, 164, 60, .05);
    align-items: center;
    justify-content: center;
}

.dropveil span {
    font: 700 10px var(--px);
    color: var(--accent);
    letter-spacing: 2px;
    background: rgba(12, 12, 15, .88);
    padding: 9px 15px;
    border-radius: 8px;
}

/* ── side column ───────────────────────────── */
.side {
    width: clamp(340px, 36vw, 560px);
    flex: none;
    background: var(--panel);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-head {
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
    padding: 5px 12px;
    border-bottom: 1px solid var(--line);
}

.panel-title {
    font: 400 9px var(--px);
    color: var(--dim);
    letter-spacing: 2.5px;
}

.ph-desc,
.ph-count {
    font: 400 10px var(--mono);
    color: var(--faint);
}

.spacer {
    flex: 1;
}

.step {
    display: flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
}

.step .sl {
    font: 400 8px var(--px);
    color: var(--faint);
    padding: 0 5px 0 7px;
    letter-spacing: 1px;
}

.step button {
    width: 22px;
    height: 24px;
    color: var(--dim);
    font-size: 13px;
    line-height: 1;
}

.step button:hover {
    color: var(--accent);
    background: rgba(255, 255, 255, .04);
}

.step b {
    min-width: 26px;
    text-align: center;
    font: 500 11px var(--mono);
    color: var(--fg);
}

.linkbtn {
    font: 500 10.5px var(--mono);
    color: var(--faint);
    text-decoration: underline dotted;
}

.linkbtn:hover {
    color: var(--fg);
}

/* editor */
.editor {
    position: relative;
    flex: 1;
    min-height: 0;
    background: var(--edit);
    overflow: hidden;
}

#gutter {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--gutter);
    z-index: 1;
    background: #121218;
    border-right: 1px solid var(--line);
    overflow: hidden;
    padding-top: 12px;
}

#gutter .ln {
    height: var(--lh);
    line-height: var(--lh);
    text-align: right;
    padding-right: 10px;
    font: 400 10px var(--mono);
    color: #494652;
}

#gutter .ln.on {
    color: var(--accent);
}

#editScroll {
    position: absolute;
    left: var(--gutter);
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
}

#surface {
    position: absolute;
    left: 0;
    top: 0;
    will-change: transform;
}

#hl,
#code {
    font: 500 13px/20px var(--mono);
    white-space: pre;
    tab-size: 2;
    letter-spacing: 0;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0;
    padding: 12px 16px 80px 14px;
}

#hl .p {
    color: #6f6c7a;
}

#hl .dot {
    color: #4c4956;
}

#hl .k {
    font-weight: 700;
}

#hl .pk {
    font-weight: 700;
}

#hl .uk {
    color: #a06455;
    text-decoration: underline dotted;
}

#hl .cm {
    color: #575465;
    font-style: italic;
}

#hl .pill {
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

#codeCursor {
    position: absolute;
    display: none;
    pointer-events: none;
    border-radius: 3px;
    background: rgba(240, 164, 60, .20);
    box-shadow: inset 0 0 0 1px rgba(240, 164, 60, .85);
}

#codeCursor.pulse {
    animation: curPulse .5s ease-out;
}

@keyframes curPulse {
    0% {
        background: rgba(240, 164, 60, .6);
        box-shadow: inset 0 0 0 2px rgba(240, 164, 60, 1);
    }

    100% {
        background: rgba(240, 164, 60, .20);
        box-shadow: inset 0 0 0 1px rgba(240, 164, 60, .85);
    }
}

#code {
    position: absolute;
    left: var(--gutter);
    top: 0;
    right: 0;
    bottom: 0;
    width: calc(100% - var(--gutter));
    z-index: 2;
    background: transparent;
    border: 0;
    outline: 0;
    resize: none;
    overflow: auto;
    color: transparent;
    caret-color: var(--accent);
    scrollbar-color: #2b2b35 transparent;
    scrollbar-width: thin;
}

#code::selection {
    background: rgba(240, 164, 60, .28);
}

#code::-webkit-scrollbar {
    width: 11px;
    height: 11px;
}

#code::-webkit-scrollbar-thumb {
    background: #2b2b35;
    border-radius: 5px;
    border: 3px solid var(--edit);
}

#code::-webkit-scrollbar-corner {
    background: transparent;
}

/* palette */
.palette-panel {
    border-top: 1px solid var(--line);
    background: var(--panel2);
    padding: 10px 12px 12px;
}

.palette-head {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 10px;
}

.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    max-height: 148px;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-color: #2b2b35 transparent;
    scrollbar-width: thin;
}

.swatch {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    position: relative;
    flex: none;
    border: 1px solid rgba(255, 255, 255, .12);
    overflow: hidden;
    background: repeating-conic-gradient(#2c2c35 0% 25%, #232329 0% 50%) 0 0/8px 8px;
    transition: transform .12s, border-color .12s, box-shadow .12s;
}

.swatch:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, .3);
}

.swatch.sel {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(240, 164, 60, .35);
}

.swatch .fill {
    position: absolute;
    inset: 3px;
    border-radius: 6px;
}

.swatch .fill.clear {
    background: repeating-conic-gradient(#33333d 0% 25%, #26262e 0% 50%) 0 0/7px 7px;
}

.swatch .k {
    position: absolute;
    right: 4px;
    bottom: 2px;
    font: 700 10px var(--px);
    text-shadow: 0 1px 2px rgba(0, 0, 0, .75);
}

/* toast + menu */
#toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    z-index: 99;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 15px;
    background: rgba(17, 17, 23, .95);
    border: 1px solid var(--line2);
    border-left: 3px solid var(--accent);
    border-radius: 9px;
    font: 500 12px var(--mono);
    color: var(--fg);
    opacity: 0;
    transform: translate(-50%, 14px);
    transition: opacity .22s, transform .22s;
}

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

#toast .ti {
    color: var(--accent);
}

.menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 50;
    display: none;
    min-width: 170px;
    background: #17171e;
    border: 1px solid var(--line2);
    border-radius: 9px;
    padding: 4px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, .55);
}

.menu.open {
    display: block;
}

.menu button {
    display: flex;
    width: 100%;
    justify-content: space-between;
    gap: 18px;
    padding: 7px 10px;
    font: 500 11px var(--mono);
    color: var(--dim);
    border-radius: 6px;
}

.menu button:hover {
    background: rgba(255, 255, 255, .05);
    color: var(--fg);
}

.menu button .dim2 {
    color: var(--faint);
}

@media (max-width:940px) {
    main {
        flex-direction: column;
    }

    .toolrail {
        flex-direction: row;
        width: 100%;
        height: 50px;
        padding: 0 10px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .tool::after {
        display: none;
    }

    .rsep {
        width: 1px;
        height: 20px;
        margin: 0 4px;
    }

    .side {
        width: 100%;
        flex: 1;
        border-left: 0;
        border-top: 1px solid var(--line);
    }

    .stage {
        flex: none;
        height: 46vh;
    }

    .bt .tag {
        display: none;
    }

    .statusbar .hint {
        display: none;
    }
}