:root {
    --bg: #fafafa;
    --fg: #171717;
    --muted: #666666;
    --muted-2: #999999;
    --border: #eaeaea;
    --border-hover: #d4d4d4;
    --surface: #ffffff;
    --accent: #000000;
    --accent-fg: #ffffff;
    --danger: #e5484d;
    --danger-bg: #fff0f0;
    --radius: 8px;
    --toolbar-h: 56px;
    --panel-w: 320px;
    --artboard-w: 867px;
    --font: "Geist Sans", "GeistSans", ui-sans-serif, system-ui, sans-serif;
    --font-mono: "Geist Mono", "GeistMono", ui-monospace, monospace;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-panel: -4px 0 24px rgba(0, 0, 0, 0.06);
}

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

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--fg);
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ——— Toolbar ——— */
.toolbar {
    height: var(--toolbar-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 20;
}

.toolbar__brand {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--fg);
    text-decoration: none;
}

.toolbar__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

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

/* ——— Project switcher ——— */
.project-switcher {
    position: relative;
}

.project-switcher__trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--fg);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    max-width: 220px;
}

.project-switcher__trigger:hover {
    border-color: var(--border-hover);
    background: var(--bg);
}

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

.project-switcher__menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    z-index: 40;
    overflow: hidden;
}

.project-switcher__list {
    max-height: 220px;
    overflow-y: auto;
    padding: 6px;
}

.project-switcher__item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--fg);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.project-switcher__item:hover {
    background: var(--bg);
}

.project-switcher__item.is-active {
    background: var(--fg);
    color: var(--accent-fg);
}

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

.project-switcher__actions {
    border-top: 1px solid var(--border);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.project-switcher__action {
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--fg);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}

.project-switcher__action:hover {
    background: var(--bg);
}

.project-switcher__action--danger {
    color: var(--danger);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
    white-space: nowrap;
    background: transparent;
}

.btn--ghost {
    border-color: var(--border);
    background: var(--surface);
    color: var(--fg);
}

.btn--ghost:hover {
    border-color: var(--border-hover);
    background: var(--bg);
}

.btn--primary {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: var(--accent);
}

.btn--primary:hover {
    background: #333;
    border-color: #333;
}

.btn--saved {
    border-color: #18a957 !important;
    color: #18a957 !important;
}

.btn--danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: transparent;
}

.btn--danger:hover {
    background: #ffe0e0;
}

.btn--block {
    width: 100%;
    justify-content: center;
}

/* ——— Workspace ——— */
.workspace {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.canvas-wrap {
    flex: 1;
    overflow: auto;
    background:
        linear-gradient(90deg, var(--border) 1px, transparent 1px),
        linear-gradient(var(--border) 1px, transparent 1px);
    background-size: 24px 24px;
    background-color: var(--bg);
}

.stage {
    position: relative;
    width: 100%;
    min-height: calc(100vh - var(--toolbar-h));
    display: flex;
    justify-content: center;
    padding: 0 16px 48px;
    box-sizing: border-box;
}

.artboard-slot {
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}

.artboard-scale {
    position: relative;
    width: var(--artboard-w);
    transform-origin: top left;
    will-change: transform;
}

.canvas {
    position: relative;
    width: var(--artboard-w);
    min-height: calc(100vh - var(--toolbar-h) - 72px);
    height: 1400px;
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--border), 0 8px 30px rgba(0, 0, 0, 0.04);
}

/* Artboard guides — left & right edges of the 867px frame */
.frame-guides {
    position: absolute;
    inset: 0;
    width: var(--artboard-w);
    pointer-events: none;
    z-index: 1;
}

.frame-guides__line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 0;
    border-left: 1.5px dashed #c4c4c4;
}

.frame-guides__line--left {
    left: 0;
}

.frame-guides__line--right {
    left: 100%;
}

/* ——— Elements ——— */
.el {
    position: absolute;
    z-index: 2;
    cursor: grab;
    user-select: none;
    outline: 1.5px solid transparent;
    outline-offset: 2px;
    transition: outline-color 0.1s ease;
    transform-origin: center center;
}

.el:hover {
    outline-color: rgba(0, 0, 0, 0.12);
}

.el.is-selected {
    outline-color: var(--accent);
    cursor: grabbing;
}

.el.is-dragging {
    opacity: 0.92;
    z-index: 20;
}

.el--text {
    display: block;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.35;
    min-width: 40px;
    min-height: 24px;
}

.el--text a {
    color: inherit;
    text-decoration: underline;
    pointer-events: none;
}

.el--image {
    display: block;
}

.el--image img {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
    -webkit-user-drag: none;
}

.el--rect {
    box-sizing: border-box;
}

/* ——— Side panel ——— */
.panel {
    position: fixed;
    top: var(--toolbar-h);
    right: 0;
    bottom: 0;
    width: var(--panel-w);
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-panel);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 30;
}

.workspace.panel-open .panel {
    transform: translateX(0);
}

.panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel__title {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.panel__close {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.panel__close:hover {
    background: var(--bg);
    color: var(--fg);
}

.panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.panel__footer {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.panel__z {
    display: flex;
    gap: 8px;
}

.panel__z .btn {
    flex: 1;
    padding: 0 8px;
    font-size: 12px;
}

.multi-hint {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
    padding: 8px 0;
}

/* ——— Form controls ——— */
.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field__label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.field__value {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
}

.field__hint {
    font-size: 11px;
    color: var(--muted-2);
    margin-top: 2px;
}

.field input[type="text"],
.field input[type="url"],
.field textarea,
.field select {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    font-size: 13px;
    outline: none;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.field textarea {
    height: auto;
    min-height: 72px;
    padding: 8px 10px;
    resize: vertical;
    line-height: 1.4;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: var(--fg);
    box-shadow: 0 0 0 1px var(--fg);
}

.field select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' viewBox='0 0 12 12'%3E%3Cpath stroke='%23666' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M3 4.5 6 7.5l3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.field input[type="color"] {
    width: 100%;
    height: 36px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
}

.field input[type="range"] {
    width: 100%;
    height: 4px;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.field input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--fg);
    cursor: pointer;
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--border);
}

.field input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--fg);
    cursor: pointer;
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--border);
}

.field__row {
    display: flex;
    gap: 8px;
}

.field__row .field {
    flex: 1;
}

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

.align-btn {
    flex: 1;
    height: 36px;
    display: grid;
    place-items: center;
    border: none;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.align-btn + .align-btn {
    border-left: 1px solid var(--border);
}

.align-btn:hover {
    background: var(--bg);
    color: var(--fg);
}

.align-btn.is-active {
    background: var(--fg);
    color: var(--accent-fg);
}

/* ——— Color picker ——— */
.color-field {
    position: relative;
}

.color-trigger {
    width: 100%;
    height: 36px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.12s ease;
}

.color-trigger:hover {
    border-color: var(--border-hover);
}

.color-trigger__swatch {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    flex-shrink: 0;
}

.color-trigger__hex {
    flex: 1;
    text-align: left;
    font-size: 13px;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.color-trigger__chevron {
    color: var(--muted-2);
    flex-shrink: 0;
}

.color-popover {
    z-index: 80;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

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

.color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    padding: 0;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.color-swatch:hover {
    transform: scale(1.08);
}

.color-swatch.is-active {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--fg);
}

.color-swatch--transparent {
    background:
        linear-gradient(45deg, #ddd 25%, transparent 25%),
        linear-gradient(-45deg, #ddd 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ddd 75%),
        linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0;
    background-color: #fff;
}

.color-hex-row {
    display: flex;
    align-items: center;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg);
}

.color-hex-prefix {
    padding: 0 0 0 10px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--muted);
}

.color-hex-input {
    flex: 1;
    height: 100%;
    border: none;
    background: transparent;
    padding: 0 10px 0 2px;
    font-family: var(--font-mono);
    font-size: 13px;
    outline: none;
    text-transform: uppercase;
}

.btn-upload {
    width: 100%;
    height: 36px;
    justify-content: center;
}

.empty-hint__text {
    font-size: 14px;
    color: var(--muted-2);
    text-align: center;
    max-width: 320px;
    line-height: 1.5;
    margin: 160px auto 0;
}

.empty-hint {
    position: absolute;
    inset: 0;
    display: block;
    pointer-events: none;
    z-index: 0;
}

.empty-hint__text code {
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
}

.canvas:has(.el) .empty-hint {
    display: none;
}

/* Hover animation preview in editor */
.el--image[data-hover="zoom"] img {
    transition: transform 0.35s ease;
}

.el--image[data-hover="zoom"]:hover img {
    transform: scale(1.05);
}

.el--image[data-hover="fade"] img {
    transition: opacity 0.35s ease;
}

.el--image[data-hover="fade"]:hover img {
    opacity: 0.75;
}

.el--image[data-hover="lift"] {
    transition: transform 0.35s ease;
}

.el--image[data-hover="lift"]:hover {
    transform: translateY(-4px) rotate(var(--rot, 0deg));
}

@media (max-width: 560px) {
    .btn {
        font-size: 12px;
        padding: 0 8px;
    }
}
