:root {
    --bg: #10131a;
    --bg-soft: #171b25;
    --panel: #1d2230;
    --panel-2: #232937;
    --line: #2e3648;
    --text: #e8ecf5;
    --muted: #93a0b8;
    --accent: #f88017;
    --accent-2: #ffa04d;
    --danger: #e2504a;
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

h1, h2, h3 { margin: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 18px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--line);
    flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 16px; letter-spacing: .3px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.brand-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, var(--accent-2), var(--accent));
    box-shadow: 0 0 0 3px rgba(248, 128, 23, .18);
}

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

.btn {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
    transition: background .15s, border-color .15s, transform .05s;
}

.btn:hover { background: #2b3243; border-color: #3b445a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
    border-color: #d96f0f;
    color: #1a1206;
    font-weight: 600;
}

.btn-primary:hover { filter: brightness(1.06); background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: #6b2f2c; color: #ffb3af; background: #2a1c1c; }
.btn-block { width: 100%; }

.layout {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
}

.sidebar {
    width: 320px;
    flex: 0 0 320px;
    background: var(--bg-soft);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
}

.panel h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--muted);
    margin-bottom: 10px;
}

label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}

label.full { display: block; }

input[type="number"],
input[type="text"],
select {
    width: 100%;
    margin-top: 4px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    padding: 7px 8px;
    font-size: 13px;
    outline: none;
}

input:focus, select:focus { border-color: var(--accent); }
input[readonly] { color: var(--muted); }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 10px;
}

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }

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

.tool {
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 6px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.tool:hover { border-color: #3b445a; }
.tool.active { border-color: var(--accent); background: rgba(248, 128, 23, .14); }
.tool span { margin-right: auto; }
.tool i { width: 14px; text-align: center; font-size: 13px; color: var(--text); }
.tool.active i { color: var(--accent); }
.btn i { margin-right: 6px; font-size: 13px; }
.btn-icon { padding: 8px 11px; }
.btn-icon i { margin-right: 0; font-size: 15px; }
.btn-group .btn i { margin-right: 4px; }

.selection-box { margin-top: 12px; display: grid; gap: 8px; min-width: 0; }
.selection-box .btn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selection-info { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.selection-hint { margin: 0; font-size: 11px; line-height: 1.6; color: var(--muted); overflow-wrap: anywhere; }
.selection-hint kbd { font-size: 10px; }

kbd {
    background: #0d1017;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 0 4px;
    font-size: 10px;
    color: var(--muted);
}

.swatches {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.swatch {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    border: 2px solid transparent;
    outline: 1px solid var(--line);
    cursor: pointer;
}

.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.swatch span {
    position: absolute;
    bottom: 1px;
    right: 3px;
    font-size: 9px;
    color: rgba(255, 255, 255, .85);
    text-shadow: 0 0 3px #000;
}

.palette-actions { display: grid; grid-template-columns: 44px 1fr; gap: 8px; align-items: center; }
.palette-actions .btn { grid-column: 2; }

input[type="color"] {
    width: 44px;
    height: 34px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    cursor: pointer;
    grid-row: 1 / span 3;
}

.stats { display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.stat-row { display: flex; align-items: center; gap: 8px; }
.stat-dot { width: 14px; height: 14px; border-radius: 50%; outline: 1px solid var(--line); flex: 0 0 auto; }
.stat-row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.stat-total { border-top: 1px solid var(--line); padding-top: 6px; color: var(--muted); }

.workspace { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }

.canvas-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 14px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.canvas-toolbar label { margin: 0; display: flex; align-items: center; gap: 8px; }
.zoom input[type="range"] { width: 160px; }
.rotate input[type="range"] { width: 120px; }
#zoomValue, #rotationValue { min-width: 34px; font-variant-numeric: tabular-nums; }
.btn-group { display: flex; gap: 4px; }
.btn-group .btn { padding: 6px 10px; }
.check input { accent-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; margin-left: auto; font-variant-numeric: tabular-nums; }

.canvas-wrap {
    flex: 1 1 auto;
    overflow: auto;
    padding: 24px;
    background:
        linear-gradient(45deg, #0d1017 25%, transparent 25%) -10px 0/20px 20px,
        linear-gradient(-45deg, #0d1017 25%, transparent 25%) -10px 0/20px 20px,
        linear-gradient(45deg, transparent 75%, #0d1017 75%) 0 0/20px 20px,
        linear-gradient(-45deg, transparent 75%, #0d1017 75%) 0 0/20px 20px,
        #12151d;
}

#canvas {
    background: #ffffff;
    border-radius: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    cursor: crosshair;
    display: block;
    touch-action: none;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(6, 8, 12, .72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 50;
}

.modal[hidden] { display: none; }

.modal-box {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    width: min(560px, 100%);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-wide { width: min(1000px, 100%); }

.modal-box header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.modal-box h3 { font-size: 15px; }

.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.modal-body { padding: 14px 16px; overflow: auto; }
.code-actions { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }

.code {
    background: #0b0e14;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    font-family: "JetBrains Mono", Consolas, "Courier New", monospace;
    font-size: 12px;
    line-height: 1.45;
    color: #cfd8e8;
    max-height: 62vh;
    overflow: auto;
    white-space: pre;
    margin: 0;
}

.design-list { display: flex; flex-direction: column; gap: 8px; }

.design-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
}

.design-item .meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.design-item .meta strong { font-size: 13px; }
.design-item .meta small { color: var(--muted); font-size: 11px; }
.design-item .spacer { margin-left: auto; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 10px;
    z-index: 80;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .5);
    max-width: 70vw;
}

.toast[hidden] { display: none; }
.toast.error { border-left-color: var(--danger); }

.lang-select {
    width: auto;
    margin-top: 0;
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: pointer;
}
