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

/* ── Tokens ── */
:root {
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #e8e8e8;
    --border-focus: #1a1a1a;
    --text-primary: #111111;
    --text-secondary: #6b6b6b;
    --text-tertiary: #a0a0a0;
    --accent: #111111;
    --accent-hover: #2a2a2a;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
    --transition: 150ms ease;
}

/* ── Base ── */
html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Top bar ── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--accent);
    color: white;
    font-weight: 600;
    font-size: 14px;
    border-radius: 7px;
    letter-spacing: -0.02em;
}

.brand-name {
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.04em;
    color: var(--text-primary);
}

.topbar-meta {
    font-size: 13px;
    color: var(--text-tertiary);
}

/* ── Layout ── */
.layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    min-height: calc(100vh - 56px);
}

/* ── Sidebar (form) ── */
.sidebar {
    padding: 32px 28px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.sidebar-header {
    margin-bottom: 28px;
}

.sidebar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}

.sidebar-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ── Form ── */
.field {
    margin-bottom: 20px;
}

.field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.field input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.06);
}

.field input::placeholder {
    color: var(--text-tertiary);
}

/* ── Button ── */
.btn-primary {
    width: 100%;
    padding: 12px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: background var(--transition), transform 80ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 28px;
}

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

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
}

/* ── Preview panel ── */
.preview-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.preview-chrome {
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.preview-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.preview-canvas {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 32px;
}

.preview-container {
    width: 100%;
    max-width: 640px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 32px;
    box-shadow: var(--shadow-md);
    min-height: 300px;
}

#previewFrame {
    width: 100%;
    border: none;
    min-height: 260px;
    background: transparent;
}

.preview-hint {
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-tertiary);
    text-align: center;
}

/* ── Spinner ── */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.12);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}

.spinner--light {
    border-color: rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
}

/* ── Preview states ── */
.preview-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 260px;
    color: var(--text-secondary);
    font-size: 13px;
}

.preview-error {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    color: #d93025;
    font-size: 13px;
    text-align: center;
}

.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* ── Toast ── */
.success-message {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
    animation: toastIn 0.3s ease;
    z-index: 1000;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ── Responsive ── */
@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .preview-canvas {
        padding: 32px 20px;
    }

    .topbar {
        padding: 0 20px;
    }
}

@media (max-width: 480px) {
    .topbar-meta {
        display: none;
    }

    .sidebar {
        padding: 24px 20px;
    }

    .preview-container {
        padding: 20px;
    }
}
