:root {
    --bg: #f4f7fc;
    --surface: #ffffff;
    --surface-soft: #f8faff;
    --surface-2: #eef3fb;
    --line: #d6ddeb;
    --line-strong: #b8c5dd;
    --text: #162033;
    --muted: #657089;
    --primary: #2859ff;
    --primary-strong: #1f46cc;
    --danger: #d03f34;
    --success: #16784d;
    --shadow: 0 14px 34px rgba(34, 52, 90, 0.08);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 10px;
}

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

* {
    min-width: 0;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
    overflow-x: hidden;
}

img,
svg,
video,
canvas {
    max-width: 100%;
}

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

button {
    cursor: pointer;
}

.app-shell {
    width: min(100%, 460px);
    margin: 0 auto;
    padding: 12px 14px 20px;
    margin-bottom: 30px;
}

@supports (padding: max(0px)) {
    .app-shell {
        padding-right: max(14px, env(safe-area-inset-right));
        padding-left: max(14px, env(safe-area-inset-left));
        padding-top: max(12px, env(safe-area-inset-top));
    }
}

.topbar {
    display: grid;
    gap: 12px;
    margin-bottom: 14px;
    justify-items: center;
}

.topbar-brand {
    text-align: center;
}

.topbar-brand h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.2;
    font-weight: 800;
}

.topbar-brand p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.topbar-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.top-chip {
    height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
}

.top-chip-live {
    color: #2051df;
    border-color: #c6d7ff;
    background: #ecf2ff;
}

.top-chip-action {
    border: 0;
}

.top-chip-link {
    text-decoration: none;
}

.workspace {
    width: 100%;
}

.generator,
.creator-pane,
.result-pane {
    display: grid;
    gap: 14px;
}

.surface,
.result-section {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.surface,
.result-section {
    padding: 14px;
}

.section-title {
    margin: 0;
    font-size: 15px;
    line-height: 1.3;
    font-weight: 800;
}

.mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px;
    border-radius: 12px;
    background: var(--surface-2);
}

.mode-tab {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-size: 15px;
    font-weight: 700;
}

.mode-tab.is-active {
    border-color: #b8cbff;
    background: #ffffff;
    color: var(--primary);
}

.textarea-shell {
    position: relative;
    margin-top: 10px;
}

.textarea-shell textarea {
    width: 100%;
    min-height: 156px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 12px 12px 34px;
    color: var(--text);
    background: #ffffff;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
}

.textarea-shell textarea::placeholder,
.auth-field input::placeholder {
    color: #8f99ac;
}

.prompt-counter {
    position: absolute;
    right: 10px;
    bottom: 10px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1;
}

.sample-row {
    margin-top: 12px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 126px;
    gap: 10px;
    align-items: end;
}

.sample-label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--muted);
}

.select-shell {
    position: relative;
}

.select-shell select {
    width: 100%;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 34px 0 10px;
    background: #ffffff;
    color: var(--text);
    appearance: none;
    outline: none;
}

.select-shell::after {
    content: "";
    position: absolute;
    right: 12px;
    top: 50%;
    width: 8px;
    height: 8px;
    border-right: 2px solid #66718a;
    border-bottom: 2px solid #66718a;
    transform: translateY(-60%) rotate(45deg);
    pointer-events: none;
}

.qr-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-soft);
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    padding: 8px;
}

.qr-card img {
    width: 52px;
    height: 52px;
    border-radius: 6px;
    object-fit: cover;
}

.qr-card span {
    font-size: 11px;
    line-height: 1.4;
    color: var(--muted);
    font-weight: 700;
}

.upload-panel {
    display: grid;
    gap: 10px;
}

.upload-drop {
    position: relative;
    border: 1px dashed #aac0ed;
    border-radius: var(--radius-md);
    min-height: 92px;
    padding: 12px;
    display: grid;
    align-items: center;
    background: #f4f8ff;
}

.upload-drop input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.upload-copy strong {
    display: block;
    font-size: 15px;
}

.upload-copy small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.upload-preview {
    margin-top: 10px;
    width: 100%;
    max-height: 180px;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid var(--line);
}

.upload-clear {
    height: 36px;
    border: 1px solid #f2c4c0;
    border-radius: 10px;
    background: #fff5f4;
    color: #bb3329;
    font-size: 13px;
    font-weight: 700;
}

.size-list {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
}

.size-option {
    flex: 0 0 80px;
    width: 80px;
    height: 74px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #ffffff;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.size-option.is-active {
    border-color: #8caeff;
    background: #edf3ff;
    color: #1c4fdf;
}

.size-shape {
    border: 2px solid currentColor;
    border-radius: 4px;
    opacity: 0.85;
}

.shape-square {
    width: 22px;
    height: 22px;
}

.shape-wide {
    width: 28px;
    height: 18px;
}

.shape-tall {
    width: 17px;
    height: 26px;
}

.submit-wrap {
    display: grid;
    gap: 8px;
}

.generate-btn {
    height: 50px;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(120deg, #2c58ff, #3970ff);
    color: #ffffff;
    font-size: 16px;
    font-weight: 800;
}

.generate-btn:disabled {
    opacity: 0.56;
    cursor: not-allowed;
}

.status-message {
    margin: 0;
    min-height: 18px;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.35;
}

.status-message.is-success {
    color: var(--success);
}

.status-message.is-error {
    color: var(--danger);
}

.result-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.result-head h2 {
    margin: 0;
    font-size: 15px;
}

.head-count {
    min-width: 26px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 7px;
}

.task-list {
    display: grid;
    gap: 10px;
}

.task-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
    padding: 10px;
}

.task-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.task-title {
    display: grid;
    gap: 4px;
}

.task-title strong {
    font-size: 14px;
}

.task-title span {
    font-size: 12px;
    color: var(--muted);
}

.status-badge {
    flex: 0 0 auto;
    min-width: 58px;
    height: 24px;
    border-radius: 999px;
    background: #e7eefb;
    color: #315ea7;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
}

.status-badge.is-completed {
    background: #e6f7ee;
    color: var(--success);
}

.status-badge.is-failed {
    background: #fff0ef;
    color: var(--danger);
}

.task-prompt {
    margin: 10px 0 0;
    font-size: 13px;
    line-height: 1.45;
}

.task-progress {
    margin-top: 10px;
    height: 6px;
    background: #dfe7f6;
    border-radius: 999px;
    overflow: hidden;
}

.task-progress span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #3a68ff, #6990ff);
}

.task-message {
    margin: 10px 0 0;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.45;
}

.task-message.is-error {
    color: var(--danger);
}

.task-message.is-success {
    color: var(--success);
}

.gallery-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.gallery-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #ffffff;
}

.gallery-thumb {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    display: block;
    background: #e9effb;
}

.gallery-info {
    padding: 9px;
    display: grid;
    gap: 7px;
}

.gallery-info p {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
}

.task-actions {
    display: flex;
    gap: 8px;
}

.task-actions button,
.task-actions a {
    flex: 1 1 0;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface-soft);
    color: #2b3956;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.task-actions .btn-primary {
    border-color: #95b0f7;
    background: #eaf0ff;
    color: #254fd0;
}

.empty-record {
    margin: 0;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-md);
    padding: 14px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.site-footer {
    margin: 16px 0 0;
    font-size: 12px;
    line-height: 1.4;
    color: #8a95aa;
    text-align: center;
}

.image-modal[hidden] {
    display: none;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 12px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(4, 10, 24, 0.72);
}

.modal-dialog {
    position: relative;
    width: min(100%, 900px);
    max-height: calc(100vh - 24px);
    overflow: auto;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: #0e1423;
    color: #dbe5ff;
    padding: 16px;
    z-index: 1;
}

.modal-close {
    position: absolute;
    right: 10px;
    top: 10px;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-size: 24px;
    line-height: 1;
}

#imageModalImg {
    width: 100%;
    max-height: 72vh;
    object-fit: contain;
    display: block;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
}

#imageModalPrompt {
    margin: 10px 0 0;
    font-size: 13px;
    line-height: 1.45;
    color: #b5c1df;
}

#imageModalDownload {
    margin-top: 12px;
    width: 100%;
    height: 40px;
    border-radius: 10px;
    background: #2d67ff;
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(8, 14, 28, 0.72);
    display: grid;
    place-items: center;
    padding: 16px;
}

.auth-gate[hidden] {
    display: none;
}

.auth-card {
    width: min(100%, 420px);
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 20px;
    display: grid;
    gap: 16px;
}

.auth-copy h2 {
    margin: 0;
    font-size: 22px;
    line-height: 1.25;
}

.auth-copy p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.auth-form {
    display: grid;
    gap: 12px;
}

.auth-field {
    display: grid;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
}

.auth-field input {
    width: 100%;
    height: 46px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 12px;
    background: #fff;
    color: var(--text);
}

.auth-submit {
    margin-top: 4px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

[hidden] {
    display: none !important;
}

textarea:focus,
select:focus,
button:focus-visible,
a:focus-visible,
input:focus {
    outline: 2px solid rgba(56, 108, 248, 0.45);
    outline-offset: 1px;
}

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

@media (min-width: 1024px) {
    :root {
        --bg: #0b1220;
        --surface: #101a2e;
        --surface-soft: #15233d;
        --surface-2: #1a2946;
        --line: #23365a;
        --line-strong: #365183;
        --text: #eaf0ff;
        --muted: #98a8cb;
        --primary: #4a78ff;
        --primary-strong: #7aa0ff;
        --shadow: 0 14px 34px rgba(2, 5, 12, 0.42);
    }

    .app-shell {
        width: min(100%, 1460px);
        padding: 18px 22px 24px;
    }

    .topbar {
        justify-items: center;
        margin-bottom: 16px;
    }

    .topbar-brand h1 {
        font-size: 30px;
    }

    .topbar-brand p {
        font-size: 13px;
        margin-top: 7px;
    }

    .top-chip {
        height: 32px;
        background: #14223b;
        border-color: #28406e;
    }

    .top-chip-live {
        background: #1a2f57;
        color: #cfe0ff;
    }

    .top-chip-action {
        background: #24437c;
        color: #e6eeff;
    }

    .top-chip-link {
        background: #1d345f;
        color: #dce8ff;
        border-color: #35558f;
    }

    .generator {
        grid-template-columns: minmax(360px, 410px) minmax(0, 1fr);
        align-items: start;
    }

    .creator-pane {
        position: sticky;
        top: 18px;
        max-height: calc(100vh - 38px);
        overflow: auto;
        padding-right: 3px;
    }

    .creator-pane::-webkit-scrollbar,
    .task-list::-webkit-scrollbar {
        width: 8px;
    }

    .creator-pane::-webkit-scrollbar-thumb,
    .task-list::-webkit-scrollbar-thumb {
        border-radius: 999px;
        background: #2b416e;
    }

    .section-title {
        font-size: 14px;
        color: #dbe5ff;
    }

    .textarea-shell textarea,
    .select-shell select,
    .auth-field input {
        background: #0f1b31;
        border-color: #2a416e;
        color: #e8f0ff;
    }

    .sample-row {
        grid-template-columns: minmax(0, 1fr) 140px;
    }

    .select-shell::after {
        border-color: #8ea7d9;
    }

    .qr-card,
    .upload-drop,
    .task-card,
    .gallery-card,
    .empty-record,
    .auth-card {
        background: #0f1b31;
        border-color: #2a416e;
    }

    .upload-drop {
        border-style: dashed;
        border-color: #3c5a94;
    }

    .upload-preview {
        border-color: #2b416f;
    }

    .upload-clear {
        background: #27191d;
        border-color: #663136;
        color: #ffb5af;
    }

    .size-option {
        background: #0f1b31;
        border-color: #2a416e;
        color: #a1b3d8;
    }

    .size-option.is-active {
        background: #173266;
        border-color: #4e74bd;
        color: #e5eeff;
    }

    .submit-wrap {
        position: sticky;
        bottom: 0;
        padding-top: 8px;
        background: linear-gradient(180deg, rgba(11, 18, 32, 0) 0%, rgba(11, 18, 32, 0.92) 25%, rgba(11, 18, 32, 1) 100%);
    }

    .generate-btn {
        height: 52px;
        background: linear-gradient(120deg, #3a66ff, #5b84ff);
    }

    .result-head h2,
    .task-title strong {
        color: #e8f0ff;
    }

    .head-count {
        background: #14233f;
        border-color: #2b416f;
    }

    .task-list {
        max-height: 45vh;
        overflow: auto;
        padding-right: 2px;
    }

    .task-title span,
    .task-prompt,
    .task-message,
    .gallery-info p,
    .auth-copy p,
    .auth-field {
        color: #9db0d6;
    }

    .task-progress {
        background: #253a63;
    }

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

    .task-actions button,
    .task-actions a {
        background: #152747;
        border-color: #304c81;
        color: #dce8ff;
    }

    .task-actions .btn-primary {
        background: #2a4e9f;
        border-color: #426bc5;
        color: #eaf0ff;
    }

    .site-footer {
        margin-top: 18px;
        color: #7f92bc;
    }
}

@media (min-width: 1440px) {
    .gallery-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
