:root {
    --bg: #030305;
    --card: rgba(255, 255, 255, 0.04);
    --line: rgba(255, 255, 255, 0.09);
    --text: #e8e6f2;
    --muted: #94a3b8;
    --a1: #9333ea;
    --a2: #c084fc;
    --ok: #4ade80;
    --bad: #f87171;
    --field: rgba(0, 0, 0, 0.5);
    --sans: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, monospace;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 12px; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg) radial-gradient(circle at 50% 0%, rgba(168, 85, 247, 0.12) 0%, transparent 55%) no-repeat;
    color: var(--text);
    font: 500 14px/1.5 var(--sans);
    -webkit-tap-highlight-color: transparent;
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--a2); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { max-width: 1120px; margin: 0 auto; padding: 0 16px 48px; }

/* Header */
.top { display: flex; align-items: center; gap: 12px; padding: 16px 0 8px; }
.logo {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
    background: linear-gradient(135deg, var(--a1), var(--a2)); color: #fff;
    box-shadow: 0 6px 20px rgba(147, 51, 234, 0.35);
}
.top h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; color: #fff; }
.top p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* Layout */
.layout { display: grid; gap: 14px; }
@media (min-width: 900px) {
    .layout { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; gap: 20px; }
    .stage { position: sticky; top: 16px; }
    #cv { max-height: 68vh; }
}

/* Preview */
.stage {
    background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px;
}
.stage-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.badge {
    font: 700 11px var(--mono); color: var(--a2); background: rgba(168, 85, 247, 0.12);
    border: 1px solid rgba(168, 85, 247, 0.3); border-radius: 999px; padding: 4px 10px; white-space: nowrap;
}
.canvas-wrap {
    display: grid; place-items: center; border-radius: 12px; padding: 8px;
    background: repeating-conic-gradient(rgba(255, 255, 255, 0.035) 0% 25%, transparent 0% 50%) 50% / 18px 18px;
}
#cv {
    display: block; max-width: 100%; max-height: 38vh; width: auto; height: auto; border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: grab;
}
#cv.drag { cursor: grabbing; }
.hint { margin: 8px 2px 0; font-size: 11.5px; color: var(--muted); text-align: center; }
@media (max-width: 899px) {
    .stage {
        position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; border-radius: 0 0 18px 18px;
        background: rgba(10, 10, 14, 0.92); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
        margin: 0 -16px; padding: 10px 16px 8px; border-top: 0;
    }
    .hint { display: none; }
}

/* Segmented / chips */
.seg { display: inline-flex; gap: 4px; background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 3px; flex-wrap: wrap; }
.seg button {
    border: 0; background: transparent; color: var(--muted); font-weight: 700; font-size: 12.5px;
    padding: 7px 12px; border-radius: 9px;
}
.seg button.on { background: linear-gradient(135deg, var(--a1), var(--a2)); color: #fff; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
    border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px;
    font-weight: 700; font-size: 12.5px; color: var(--text);
}
.chip.on { border-color: var(--a2); background: rgba(168, 85, 247, 0.18); color: #fff; }

/* Panel */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
    flex: 1 0 auto; border: 1px solid var(--line); background: transparent; color: var(--muted);
    border-radius: 11px; padding: 9px 14px; font-weight: 700; font-size: 13px;
}
.tab[aria-selected="true"] { color: #fff; border-color: rgba(192, 132, 252, 0.6); background: rgba(168, 85, 247, 0.16); }
.pane { display: flex; flex-direction: column; gap: 14px; padding: 4px 2px 6px; }
.lbl { font-size: 12px; color: var(--muted); font-weight: 700; margin: 0 0 6px; display: block; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

textarea, input[type="text"] {
    width: 100%; background: var(--field); border: 1px solid var(--line); border-radius: 10px;
    padding: 11px 12px; font-weight: 700; resize: vertical; outline: none;
}
textarea:focus, input[type="text"]:focus { border-color: var(--a2); }
input[type="color"] {
    width: 100%; height: 42px; padding: 3px; background: var(--field); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
input[type="file"] { display: none; }

/* Sliders */
.srow { display: flex; flex-direction: column; gap: 4px; }
.shead { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-weight: 700; }
.shead b { font-family: var(--mono); color: var(--a2); font-weight: 700; }
.sctl { display: flex; align-items: center; gap: 10px; }
.step {
    width: 36px; height: 36px; flex: none; border-radius: 50%; border: 1px solid var(--line);
    background: rgba(168, 85, 247, 0.14); color: #fff; font-size: 18px; font-weight: 800; line-height: 1;
    user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.step:active { background: rgba(168, 85, 247, 0.35); }
input[type="range"] { flex: 1; min-width: 0; accent-color: var(--a1); height: 28px; }

/* Buttons */
.btn {
    border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 12px;
    padding: 12px 14px; font-weight: 800; font-size: 13.5px; text-align: center; display: block; width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn.main { background: linear-gradient(135deg, var(--a1), var(--a2)); border: 0; color: #fff; padding: 15px; font-size: 15px; box-shadow: 0 8px 24px rgba(147, 51, 234, 0.3); }
.btn.danger { color: var(--bad); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.07); }
.btn.sm { padding: 9px 12px; font-size: 12.5px; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-grid button {
    width: 46px; height: 46px; font-size: 24px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}
.emoji-grid button:active { transform: scale(1.12); }
.box { border: 1px solid rgba(168, 85, 247, 0.3); background: rgba(168, 85, 247, 0.06); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.note { margin: 0; font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 13px; }
.check input { width: 20px; height: 20px; accent-color: var(--a1); }

/* Export */
.export { margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.export-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Toast */
.toast {
    position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px);
    background: #0d0c14; border: 1px solid var(--a2); border-radius: 12px; padding: 10px 18px; font-weight: 700; font-size: 13px;
    opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 50; max-width: 90vw; text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--bad); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } .btn:active, .emoji-grid button:active { transform: none; } }
