/*  Theme  */
:root {
    --bg: #0e0e16;
    --bg-2: #14141f;
    --panel: #17172340;
    --panel-solid: #181826;
    --panel-2: #1d1d2c;
    --border: #2a2a3d;
    --border-soft: #22223480;
    --text: #e7e7f2;
    --text-dim: #a2a2bd;
    --text-faint: #6d6d88;
    --accent: #7c5cff;
    --accent-2: #9d83ff;
    --accent-soft: #7c5cff22;
    --danger: #ff5c7a;
    --good: #38d39f;
    --warn: #ffb454;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 10px 30px -12px #000a, 0 2px 8px -4px #0006;
    --r-sm: 7px;
    --ui:
        -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
        system-ui, sans-serif;
    --mono:
        ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Consolas,
        Menlo, monospace;
    font-synthesis: none;
}

* {
    box-sizing: border-box;
}
html,
body {
    height: 100%;
}
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--ui);
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow: hidden;
}
.mono {
    font-family: var(--mono);
}

/*  Layout  */
#app {
    display: grid;
    grid-template-rows: 50px 1fr 26px;
    height: 100vh;
}
.workspace {
    display: grid;
    grid-template-columns: 60px 1fr 280px;
    min-height: 0;
}

/*  Top bar  */
.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 14px;
    background: #161623;
    border-bottom: 1px solid var(--border);
    z-index: 30;
}
.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    letter-spacing: 0.2px;
}
.app-name {
    font-size: 14px;
}
.topbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}
.topbar-group.right {
    margin-left: auto;
}
.divider {
    width: 1px;
    height: 22px;
    background: var(--border);
    margin: 0 4px;
}
.divider.v {
    width: auto;
    height: 18px;
}

/*  Buttons  */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition:
        background 0.12s,
        border-color 0.12s,
        transform 0.05s,
        color 0.12s;
    user-select: none;
    white-space: nowrap;
}
.btn:hover {
    background: #25253a;
    border-color: #34344c;
}
.btn:active {
    transform: translateY(1px);
}
.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.btn.primary {
    background: var(--accent);
    border-color: #6a4cf0;
    color: #fff;
    box-shadow: 0 4px 14px -4px var(--accent-soft);
}
.btn.primary:hover {
    background: #8a6bff;
}
.btn.icon {
    padding: 0;
    width: 32px;
    justify-content: center;
}
.btn.icon.wide {
    width: auto;
    padding: 0 10px;
}
.ic {
    width: 17px;
    height: 17px;
}

/*  Menus  */
.menu {
    position: relative;
}
.menu-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 190px;
    background: var(--panel-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px;
    z-index: 60;
    animation: pop 0.12s ease;
}
.menu.open .menu-dropdown {
    display: block;
}
.menu-dropdown button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    color: var(--text);
    border: 0;
    border-radius: 6px;
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.menu-dropdown button:hover {
    background: var(--accent-soft);
    color: #fff;
}
.menu-dropdown button .k {
    color: var(--text-faint);
    font-size: 11px;
}
.menu-dropdown hr {
    border: 0;
    border-top: 1px solid var(--border-soft);
    margin: 5px 4px;
}
@keyframes pop {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/*  Tools (left bar)  */
.leftbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 8px;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
}
.tool {
    position: relative;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition:
        background 0.12s,
        color 0.12s,
        border-color 0.12s;
}
.tool:hover {
    background: #20202f;
    color: var(--text);
}
.tool.active {
    background: var(--accent-soft);
    color: #fff;
    border-color: #6a4cf055;
    box-shadow: inset 0 0 0 1px #6a4cf033;
}
.tool svg {
    width: 20px;
    height: 20px;
}
.tool .tip {
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: #000d;
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.1s;
    z-index: 50;
}
.tool .tip kbd {
    background: #ffffff22;
    border-radius: 3px;
    padding: 0 4px;
    margin-left: 4px;
    font-size: 10px;
}
.tool:hover .tip {
    opacity: 1;
}
.tool-sep {
    width: 26px;
    height: 1px;
    background: var(--border);
    margin: 6px 0;
}

/*  Stage  */
.stage {
    position: relative;
    min-width: 0;
    background: #0a0a13;
    overflow: hidden;
}
.stage-scroll {
    position: absolute;
    inset: 0;
    overflow: auto;
}
.stage-inner {
    min-width: 100%;
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 40px;
    box-sizing: border-box;
}
.canvas-frame {
    position: relative;
    background: repeating-conic-gradient(#15151f 0% 25%, #101019 0% 50%) 0 0 /
        16px 16px;
    border-radius: 4px;
    box-shadow:
        0 0 0 1px var(--border),
        0 24px 60px -20px #000c;
    line-height: 0;
}
#art-canvas {
    display: block;
}
.caret {
    position: absolute;
    display: none;
    width: 1px;
    background: var(--accent-2);
    pointer-events: none;
    z-index: 5;
    box-shadow: 0 0 6px var(--accent);
    animation: blink 1s steps(1) infinite;
}
@keyframes blink {
    50% {
        opacity: 0;
    }
}

.floating-controls {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    background: #0c0c16cc;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px 8px;
    box-shadow: var(--shadow);
    z-index: 20;
}
.zoom-label {
    min-width: 44px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
    font-size: 12px;
}
.toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--text-dim);
    font-size: 12px;
}
.toggle input {
    accent-color: var(--accent);
}

/*  Right bar / inspector  */
.rightbar {
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
    border-left: 1px solid var(--border);
    min-height: 0;
    overflow-y: auto;
}
.panel {
    padding: 14px;
    border-bottom: 1px solid var(--border);
}
.panel.grow {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.panel h3 {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

/* fg/bg */
.fg-bg {
    position: relative;
    width: 46px;
    height: 30px;
}
.fgbg {
    position: absolute;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    border: 2px solid var(--panel-solid);
    padding: 0;
    box-shadow: 0 0 0 1px var(--border);
    cursor: pointer;
}
.color-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
    border: 0;
    padding: 0;
}
.fgbg#fg-swatch {
    left: 0;
    top: 0;
    z-index: 2;
}
.fgbg#bg-swatch {
    right: 0;
    bottom: 0;
}
.fgbg.active-ring {
    box-shadow: 0 0 0 2px var(--accent);
}

.swatches {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    margin-top: 10px;
}
.swatch {
    aspect-ratio: 1;
    border-radius: 5px;
    cursor: pointer;
    border: 1px solid #ffffff14;
    position: relative;
}
.swatch:hover {
    transform: scale(1.12);
    z-index: 2;
}
.swatch.sel {
    box-shadow:
        0 0 0 2px var(--accent),
        0 0 0 4px #00000055;
}
.swatches.mini {
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
}
.swatches.mini .swatch {
    border-radius: 4px;
}

.checkrow,
.recent {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}
.checkrow {
    cursor: pointer;
    color: var(--text-dim);
}
.checkrow input {
    accent-color: var(--accent);
}
.recent {
    align-items: center;
}
.recent-label {
    color: var(--text-faint);
    font-size: 11px;
}
.recent .swatches.mini {
    flex: 1;
    margin-top: 0;
}

/* char palette */
.char-input {
    width: 38px;
    height: 30px;
    text-align: center;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    font: 16px/1 var(--mono);
}
.char-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}
.char-tab {
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid transparent;
}
.char-tab:hover {
    background: var(--panel-2);
    color: var(--text);
}
.char-tab.active {
    background: var(--accent-soft);
    color: #fff;
    border-color: #6a4cf055;
}

.char-grid {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    padding-right: 2px;
    font-family: var(--mono);
}
.char-cell {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    background: #12121c;
    border: 1px solid #ffffff08;
    border-radius: 5px;
    font-size: 15px;
    color: var(--text);
    cursor: pointer;
    transition:
        background 0.1s,
        transform 0.05s;
}
.char-cell:hover {
    background: #1d1d2c;
    transform: scale(1.06);
}
.char-cell.sel {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 0 1px var(--accent);
}

/* scrollbars */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #2c2c40;
    border-radius: 8px;
    border: 2px solid var(--bg-2);
}
::-webkit-scrollbar-thumb:hover {
    background: #3a3a55;
}

/*  Status bar  */
.statusbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}
.statusbar .sep {
    color: var(--text-faint);
}
.statusbar .spacer {
    flex: 1;
}
#status-hint {
    color: var(--text-faint);
}

/*  Toast  */
.toast-stack {
    position: fixed;
    bottom: 50px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}
.toast {
    background: var(--panel-solid);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
    animation: slidein 0.18s ease;
    max-width: 320px;
}
.toast.good {
    border-left-color: var(--good);
}
.toast.warn {
    border-left-color: var(--warn);
}
.toast.error {
    border-left-color: var(--danger);
}
@keyframes slidein {
    from {
        transform: translateX(20px);
        opacity: 0;
    }
}

/*  Modal  */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: #05050aaa;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: grid;
    place-items: center;
    z-index: 200;
    animation: fade 0.12s ease;
}
.modal {
    width: min(420px, 92vw);
    background: var(--panel-solid);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 20px;
}
.modal h2 {
    margin: 0 0 4px;
    font-size: 16px;
}
.modal p {
    margin: 0 0 16px;
    color: var(--text-dim);
    font-size: 12.5px;
}
.modal .row {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
}
.modal .field {
    flex: 1;
}
.modal label {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.modal input[type="number"] {
    width: 100%;
    height: 34px;
    padding: 0 10px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
.modal .actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
@keyframes fade {
    from {
        opacity: 0;
    }
}

/* responsive-ish */
@media (max-width: 880px) {
    .workspace {
        grid-template-columns: 52px 1fr 240px;
    }
}
@media (max-width: 680px) {
    .workspace {
        grid-template-columns: 52px 1fr;
    }
    .rightbar {
        display: none;
    }
}
