/* ─── 变量 ──────────────────────────────────────── */
:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-soft: #f5f6f8;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.12);
    --text: #111111;
    --text-soft: #5f5f5f;
    --text-muted: #878787;
    --primary: #111111;
    --primary-hover: #222222;
    --primary-fg: #ffffff;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 16px 36px rgba(0, 0, 0, 0.12);
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --shell: min(1200px, calc(100vw - 40px));
    --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: linear-gradient(180deg, #fffef9 0%, #ffffff 22%, #f7f8fa 100%);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
img { display: block; max-width: 100%; }
button, input, textarea, a { font: inherit; }
button { border: 0; cursor: pointer; background: transparent; }
a { color: inherit; text-decoration: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
    outline: 3px solid rgba(51, 51, 51, 0.15);
    outline-offset: 2px;
}

.shell {
    width: var(--shell);
    margin: 0 auto;
}

/* ─── Topbar ────────────────────────────────────── */
.studio-topbar {
    position: relative;
    z-index: 30;
    background: transparent;
}

.studio-topbar__inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    height: 64px;
}

.studio-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
}

.studio-brand__logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
}

.studio-topbar__actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-link,
.inline-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 16px;
    border-radius: 999px;
    border: none;
    font-weight: 600;
    font-size: 0.875rem;
    background: var(--primary);
    color: var(--primary-fg);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.topbar-link:hover,
.inline-button:hover {
    background: var(--primary-hover);
    color: var(--primary-fg);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.topbar-link--outline {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.topbar-link--outline:hover {
    background: var(--surface-soft);
    color: var(--text);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

/* ─── Key Panel ──────────────────────────────────── */
.key-panel {
    background: transparent;
    padding: 10px 0 20px;
}

.key-panel__inner {
    display: grid;
    gap: 14px;
}

.key-panel__promo {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #f3d3a1;
    border-left: 4px solid #f59e0b;
    box-shadow: var(--shadow-sm);
}

.key-panel__promo-badge {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    background: #fff2d6;
    color: #7c4a03;
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.key-panel__promo-text {
    flex: 1;
    min-width: 220px;
    color: var(--text-soft);
    font-size: 0.9rem;
}

.key-panel__promo-links {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.key-panel__promo-links a {
    color: var(--text);
    font-weight: 700;
    text-decoration: underline;
}

.key-field {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    min-width: 0;
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow-sm);
}

.key-field__meta {
    display: grid;
    gap: 6px;
}

.key-field__hint {
    font-size: 0.84rem;
    color: var(--text-soft);
    line-height: 1.6;
}

.key-field__controls {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.key-panel__label {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0;
}

.key-field input {
    flex: 1;
    min-width: 0;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

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

.key-field input:focus-visible {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(51, 51, 51, 0.1);
}

.inline-button--soft {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}

.inline-button--soft:hover {
    background: var(--surface-soft);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* ─── Import Banner ──────────────────────────────── */
.import-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
}

.import-banner__content {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 14px;
}

.import-banner h2 {
    font-size: 0.95rem;
    font-weight: 700;
}

.import-banner p {
    font-size: 0.88rem;
    color: var(--text-soft);
}

.import-banner__actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ─── Main layout ────────────────────────────────── */
.studio-main {
    padding: 24px 0 80px;
}

.studio-container {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    min-height: 80vh;
}

.studio-left {
    flex: 1;
    min-width: 0;
    border-right: 1px solid var(--border);
    background: var(--surface-soft);
    padding: 28px;
    overflow-y: auto;
}

.studio-right {
    flex: 1;
    min-width: 0;
    background: var(--surface);
    padding: 28px;
    overflow-y: auto;
}

/* ─── Section labels ─────────────────────────────── */
.section-label {
    display: block;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 10px;
}

/* ─── Scene Tabs ─────────────────────────────────── */
.compose-zone {
    margin-bottom: 20px;
}

.scene-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 0;
    border: 1px solid rgba(17, 17, 17, 0.08);
    border-bottom: 1px solid rgba(17, 17, 17, 0.04);
    background: var(--surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 12px 14px 0 14px;
}

.scene-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: transparent;
    color: var(--text-soft);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: -1px;
}

.scene-tab:hover {
    color: var(--text);
    background: rgba(17, 17, 17, 0.03);
}

.scene-tab.is-active {
    background: rgba(255, 255, 255, 0.7);
    color: var(--primary);
    border-color: rgba(17, 17, 17, 0.08) rgba(17, 17, 17, 0.08) rgba(255, 255, 255, 0.7);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.02);
}

.scene-tab__icon {
    font-size: 1em;
}

/* ─── Compose Box ────────────────────────────────── */
.compose-box {
    background: var(--surface);
    border: 1px solid rgba(17, 17, 17, 0.08);
    border-top: none;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.compose-textarea {
    display: block;
    width: 100%;
    min-height: 120px;
    padding: 16px;
    border: none;
    border-bottom: 1px solid var(--border);
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.6;
    font-family: var(--font);
    transition: border-color 0.15s;
}

.compose-textarea:focus {
    border-bottom-color: var(--primary);
}

.compose-textarea::placeholder {
    color: var(--text-muted);
}

/* ─── Toolbar (params + actions) ─────────────────── */
.compose-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    flex-wrap: wrap;
}

.compose-params {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.param-group {
    display: flex;
    gap: 2px;
}

.param-btn {
    min-height: 30px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-soft);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.14s, color 0.14s, border-color 0.14s;
}

.param-btn:hover {
    background: var(--surface-soft);
    border-color: var(--border);
    color: var(--text);
}

.param-btn.is-active {
    background: var(--primary);
    color: var(--primary-fg);
    border-color: var(--primary);
}

.param-btn:disabled,
.param-btn.is-disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.param-divider {
    width: 1px;
    height: 18px;
    background: var(--border-strong);
    margin: 0 6px;
    flex-shrink: 0;
}

.param-size-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-left: 4px;
    white-space: nowrap;
    font-family: 'Courier New', monospace;
}

.compose-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Buttons */
.compose-btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-soft);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.compose-btn-secondary:hover {
    background: var(--surface-soft);
    color: var(--text);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.compose-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    min-width: 88px;
    padding: 0 22px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--primary);
    color: var(--primary-fg);
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.compose-btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.compose-btn-primary:active {
    transform: translateY(0);
}

.compose-btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.8;
}

/* ─── Smart Fill Panel ───────────────────────────── */
.smart-fill-panel {
    margin-top: 16px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.smart-fill-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}

.sf-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 14px;
}

.sf-label:last-of-type { margin-bottom: 0; }

.sf-label input,
.sf-label textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.5;
    font-family: var(--font);
    resize: vertical;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.sf-label input:focus-visible,
.sf-label textarea:focus-visible {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(51, 51, 51, 0.1);
    background: var(--surface);
}

.sf-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.sf-close-btn {
    min-height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.14s;
}

.sf-close-btn:hover { color: var(--text-soft); }

/* ─── Inspo Zone ─────────────────────────────────── */
.inspo-zone {
    margin-top: 24px;
}

.inspo-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 14px;
}

.inspo-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

.inspo-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.inspo-grid {
    column-count: 4;
    column-gap: 12px;
}

.inspo-card {
    position: relative;
    display: inline-block;
    width: 100%;
    min-height: 112px;
    margin-bottom: 12px;
    break-inside: avoid;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    background: #ffffff;
    border: 1px solid rgba(17, 17, 17, 0.06);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.03);
    transition: all 0.25s ease;
}

.inspo-card::before {
    content: "";
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    background: linear-gradient(90deg, #f2f3f5 25%, #e9ecef 50%, #f2f3f5 75%);
    background-size: 200% 100%;
    transition: opacity 0.18s ease;
}

.inspo-card.is-image-loading {
    aspect-ratio: 1 / 1;
}

.inspo-card.is-image-loading::before {
    opacity: 1;
    animation: shimmer 1.4s infinite ease-in-out;
}

.inspo-card:hover {
    border-color: rgba(17, 17, 17, 0.15);
    transform: translateY(-3px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08);
}

.inspo-card img {
    width: 100%;
    height: auto;
    min-height: 112px;
    object-fit: cover;
    display: block;
    opacity: 1;
    transition: transform 0.3s ease, opacity 0.18s ease;
}

.inspo-card.is-image-loading img {
    opacity: 0;
}

.inspo-card:hover img {
    transform: scale(1.04);
}

.inspo-card__overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 55%);
    opacity: 0;
    transition: opacity 0.22s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 12px;
    gap: 4px;
}

.inspo-card:hover .inspo-card__overlay {
    opacity: 1;
}

.inspo-card__label {
    font-size: 0.72rem;
    font-weight: 700;
    color: rgba(255,255,255,0.75);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.inspo-card__title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
}

.inspo-card__use-btn {
    margin-top: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    width: fit-content;
}

.inspo-empty {
    grid-column: 1 / -1;
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.inspo-skeleton {
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--surface-soft) 25%, #eef0f2 50%, var(--surface-soft) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite ease-in-out;
    border: 1px solid var(--border);
}

/* ─── Result Zone ────────────────────────────────── */
.result-zone {
    margin-top: 0;
}

.loading-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 60px 20px;
    text-align: center;
    background: var(--surface-soft);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.loading-box p {
    color: var(--text-soft);
    font-size: 0.95rem;
    font-weight: 500;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
}

.result-empty {
    padding: 80px 24px;
    text-align: center;
    color: var(--text-muted);
}

.result-empty__icon {
    font-size: 3.5rem;
    margin: 0 0 16px;
    opacity: 0.25;
}

.result-empty p:last-child {
    font-size: 0.9rem;
    line-height: 1.6;
}

.result-grid {
    display: grid;
    gap: 20px;
}

.result-card {
    background: #ffffff;
    border: 1px solid rgba(17, 17, 17, 0.08);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.result-card__media {
    background: #fafafa;
    border-bottom: 1px solid rgba(17, 17, 17, 0.06);
}

.result-card__media img {
    width: 100%;
    height: auto;
    max-height: 680px;
    object-fit: contain;
    display: block;
}

.result-card__body {
    padding: 20px;
}

.result-card__meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.result-card__title {
    font-size: 0.95rem;
    font-weight: 700;
}

.result-card__badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-soft);
}

.result-card__prompt {
    margin: 0 0 16px;
    padding: 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-soft);
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font);
}

.result-card__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ─── Toast ──────────────────────────────────────── */
.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 50;
    max-width: min(380px, calc(100vw - 40px));
    padding: 12px 18px;
    border-radius: var(--radius-md);
    background: rgba(17, 17, 17, 0.94);
    color: rgba(255, 255, 255, 0.95);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.toast.is-error {
    background: rgba(180, 28, 28, 0.96);
}

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

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Responsive ─────────────────────────────────── */
@media (max-width: 860px) {
    :root { --shell: calc(100vw - 24px); }

    .studio-topbar {
        position: static;
    }

    .studio-topbar__inner {
        height: auto;
        padding: 12px 0;
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .studio-topbar__actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .key-field {
        grid-template-columns: 1fr;
    }

    .key-field__controls {
        flex-wrap: wrap;
    }

    .key-field__controls .inline-button {
        min-width: 88px;
    }

    .studio-container {
        flex-direction: column;
        overflow: visible;
        min-height: 0;
    }

    .studio-left,
    .studio-right {
        flex: none;
        overflow: visible;
    }

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

    .inspo-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .smart-fill-grid {
        grid-template-columns: 1fr;
    }

    .compose-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .compose-actions {
        justify-content: flex-end;
    }

    .scene-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }
    .scene-tabs::-webkit-scrollbar { display: none; }

    .scene-tab { white-space: nowrap; }
}

@media (max-width: 480px) {
    .studio-left, .studio-right { padding: 18px; }
    .inspo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    .topbar-link,
    .inline-button {
        width: 100%;
    }

    .key-panel__promo {
        padding: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 1ms !important;
        animation-duration: 1ms !important;
    }
}
