:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f1f2f7;
    --border: #e3e5ee;
    --border-strong: #c8ccd9;
    --text: #1a1d29;
    --text-muted: #5a6172;
    --text-soft: #828a9c;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #eef2ff;
    --danger: #dc2626;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.08);
    --transition: 160ms ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1018;
        --surface: #181b25;
        --surface-2: #20242f;
        --border: #2a2f3d;
        --border-strong: #3a4150;
        --text: #e6e8ef;
        --text-muted: #a4abbc;
        --text-soft: #6c7488;
        --accent: #818cf8;
        --accent-hover: #a5b4fc;
        --accent-soft: #1e1f3a;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
        --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
    max-width: 1080px;
    margin: 0 auto;
    padding: 32px 20px 80px;
}

.app-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 28px;
    gap: 16px;
    flex-wrap: wrap;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 18px;
    color: var(--text);
    text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--text); }

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

.subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

@media (max-width: 820px) {
    .layout { grid-template-columns: 1fr; }
    .app { padding: 20px 14px 60px; }
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

.card + .card { margin-top: 16px; }

.card h2 {
    margin: 0 0 14px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card h2 .badge {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: 999px;
}

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

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

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 480px) {
    .field-row { grid-template-columns: 1fr; }
}

input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

textarea {
    resize: vertical;
    min-height: 88px;
    line-height: 1.5;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%235a6172' d='M6 8L0 0h12z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 10px;
    padding-right: 32px;
}

.range-row {
    display: grid;
    grid-template-columns: 1fr 56px;
    gap: 10px;
    align-items: center;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--surface-2);
    border-radius: 999px;
    outline: none;
    border: none;
    padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--surface);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--surface);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 4px; }

.color-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.type-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    padding: 4px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    overflow-x: auto;
    scrollbar-width: none;
}
.type-tabs::-webkit-scrollbar { display: none; }

.type-tab {
    flex: 1;
    min-width: 56px;
    padding: 7px 10px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    border-radius: 5px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.type-tab:hover { color: var(--text); }
.type-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
    -webkit-user-select: none;
    user-select: none;
}
.btn:hover { background: var(--surface); border-color: var(--text-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.preview {
    position: sticky;
    top: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.preview-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.preview-frame {
    background:
        linear-gradient(45deg, var(--surface-2) 25%, transparent 25%),
        linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--surface-2) 75%),
        linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%);
    background-size: 14px 14px;
    background-position: 0 0, 0 7px, 7px -7px, -7px 0;
    border-radius: var(--radius-sm);
    padding: 16px;
    line-height: 0;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-frame img,
.preview-frame svg {
    max-width: 100%;
    height: auto;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    border-radius: 2px;
}

.preview-meta {
    width: 100%;
    font-size: 12px;
    color: var(--text-soft);
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.api-url-bar {
    width: 100%;
    display: flex;
    align-items: stretch;
    gap: 6px;
}
.api-url-bar input {
    flex: 1;
    min-width: 0;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 11.5px;
    color: var(--text-muted);
    background: var(--surface-2);
    border-color: var(--border);
    padding: 7px 10px;
    cursor: text;
    text-overflow: ellipsis;
}
.api-url-bar input::placeholder { color: var(--text-soft); }
.api-url-bar input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    color: var(--text);
}
.api-url-bar .btn { padding: 7px 12px; font-size: 12.5px; flex-shrink: 0; }

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--text);
    color: var(--surface);
    padding: 9px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity 200ms, transform 200ms;
    pointer-events: none;
    z-index: 50;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.error-bar {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--danger);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 12px;
    display: none;
}
@media (prefers-color-scheme: dark) {
    .error-bar { background: #2a1212; border-color: #4a1f1f; }
}
.error-bar.show { display: block; }

.help {
    font-size: 12px;
    color: var(--text-soft);
    margin-top: 4px;
    line-height: 1.4;
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-soft);
    text-transform: uppercase;
    margin: 0 0 10px;
}
