:root {
    --page-bg: #fbfbf6;
    --surface: #fffefb;
    --ink: #171714;
    --muted: #666660;
    --soft: #d9d8d0;
    --soft-strong: #b8b7ad;
    --danger: #b42318;
    --success: #247a42;
    --shadow: 0 18px 45px rgba(23, 23, 20, 0.06);
}

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

* {
    max-width: 100%;
    min-width: 0;
}

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

html {
    width: 100%;
    max-width: 100vw;
    min-height: 100%;
    background: var(--page-bg);
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

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

button,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.page-shell {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    margin: 0 auto;
    padding: 32px 14px 54px;
    overflow-x: hidden;
}

@supports (padding: max(0px)) {
    .page-shell {
        padding-top: calc(32px + env(safe-area-inset-top));
        padding-right: max(14px, env(safe-area-inset-right));
        padding-bottom: calc(54px + env(safe-area-inset-bottom));
        padding-left: max(14px, env(safe-area-inset-left));
    }
}

.app-header {
    text-align: center;
    margin-bottom: 26px;
}

.app-header h1 {
    margin: 0;
    font-size: 32px;
    line-height: 1.18;
    font-weight: 800;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.app-header p {
    margin: 16px 0 0;
    font-size: 17px;
    line-height: 1.45;
    color: #33332f;
}

.result-panel {
    width: 100%;
    min-height: 0;
    margin-top: -6px;
    border: 1px solid var(--soft);
    border-radius: 16px;
    background: rgba(255, 254, 251, 0.72);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
    overflow: hidden;
}

.result-grid {
    display: grid;
    gap: 12px;
    padding: 12px;
}

.empty-record {
    margin: 0;
    padding: 8px 4px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
}

.task-card {
    width: 100%;
    border: 1px solid var(--soft);
    border-radius: 14px;
    background: var(--surface);
    padding: 14px;
}

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

.task-title {
    flex: 1 1 0;
    display: grid;
    gap: 4px;
    min-width: 0;
}

.task-title strong {
    font-size: 16px;
    line-height: 1.25;
}

.task-title span {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.3;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.status-badge {
    flex: 0 0 auto;
    min-width: 58px;
    height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    color: #5f5740;
    background: #f1ecdc;
    font-size: 13px;
    font-weight: 750;
}

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

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

.status-badge.is-processing,
.status-badge.is-in_progress {
    color: #245a8d;
    background: #e9f3ff;
}

.task-prompt {
    margin: 12px 0 0;
    color: #2e2e2a;
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.task-progress {
    height: 8px;
    margin-top: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: #edebe2;
}

.task-progress span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: var(--ink);
    transition: width 240ms ease;
}

.task-message {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
    overflow-wrap: anywhere;
    word-break: break-word;
}

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

.task-images {
    display: grid;
    gap: 12px;
    margin-top: 12px;
}

.task-image {
    margin: 0;
}

.task-image img {
    display: block;
    width: 100%;
    max-height: 520px;
    object-fit: contain;
    border-radius: 12px;
    background: #f3f2eb;
}

.task-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.task-actions a {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    height: 40px;
    padding: 0 8px;
    border: 1px solid var(--soft);
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    background: var(--surface);
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.result-item {
    margin: 0;
}

.result-item img {
    display: block;
    width: 100%;
    max-height: 520px;
    object-fit: contain;
    border-radius: 12px;
    background: #f3f2eb;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.result-actions a {
    flex: 1 1 120px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--soft);
    border-radius: 10px;
    color: var(--ink);
    text-decoration: none;
    font-size: 15px;
    font-weight: 650;
    background: var(--surface);
}

.generator {
    display: grid;
    gap: 20px;
    width: 100%;
}

.mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.mode-tab {
    min-height: 56px;
    height: auto;
    border: 1px solid var(--soft);
    border-radius: 12px;
    background: var(--surface);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 8px;
    font-size: 17px;
    line-height: 1.15;
    font-weight: 750;
    min-width: 0;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.mode-tab span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mode-tab svg,
.generate-btn svg,
.upload-symbol svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.1;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mode-tab.is-active {
    background: var(--ink);
    border-color: var(--ink);
    color: #fffef8;
    box-shadow: var(--shadow);
}

.mode-tab:active,
.generate-btn:active,
.size-option:active {
    transform: scale(0.985);
}

.upload-panel,
.prompt-panel {
    width: 100%;
    border: 1px solid var(--soft);
    border-radius: 16px;
    background: rgba(255, 254, 251, 0.78);
    padding: 16px;
}

.upload-drop {
    position: relative;
    min-height: 116px;
    border: 1px dashed var(--soft-strong);
    border-radius: 14px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 16px;
    overflow: hidden;
}

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

.upload-symbol {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f1f0e8;
    color: var(--ink);
    flex: 0 0 auto;
}

.upload-copy {
    display: grid;
    gap: 5px;
    min-width: 0;
}

.upload-copy strong {
    font-size: 17px;
    overflow-wrap: anywhere;
}

.upload-copy small {
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.upload-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: var(--surface);
}

.upload-clear {
    height: 40px;
    margin-top: 12px;
    border: 1px solid var(--soft);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font-size: 14px;
    font-weight: 650;
}

.textarea-shell {
    position: relative;
}

.textarea-shell textarea {
    display: block;
    width: 100%;
    min-height: 168px;
    padding: 20px 16px 42px;
    border: 1px solid var(--soft);
    border-radius: 14px;
    color: var(--ink);
    background: var(--surface);
    font-size: 19px;
    line-height: 1.45;
    resize: vertical;
    outline: none;
    overflow-wrap: break-word;
}

.textarea-shell textarea::placeholder {
    color: #30302c;
}

.textarea-shell textarea:focus,
.select-shell select:focus,
.size-option:focus-visible,
.mode-tab:focus-visible,
.generate-btn:focus-visible,
.upload-clear:focus-visible {
    border-color: var(--ink);
    outline: 2px solid rgba(23, 23, 20, 0.14);
    outline-offset: 2px;
}

.prompt-counter {
    position: absolute;
    right: 16px;
    bottom: 13px;
    color: #77766e;
    font-size: 16px;
    line-height: 1;
    pointer-events: none;
}

.sample-label {
    display: block;
    margin: 0 0 10px;
    font-size: 17px;
    font-weight: 700;
}

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

.sample-control {
    min-width: 0;
    width: 100%;
}

.select-shell {
    position: relative;
    width: 100%;
    min-width: 0;
}

.select-shell select {
    width: 100%;
    height: 48px;
    appearance: none;
    border: 1px solid var(--soft);
    border-radius: 9px;
    background: var(--surface);
    color: #8a8982;
    padding: 0 44px 0 16px;
    font-size: 16px;
    outline: none;
    min-width: 0;
    text-overflow: ellipsis;
}

.select-arrow {
    position: absolute;
    top: 50%;
    right: 18px;
    width: 13px;
    height: 13px;
    border-right: 2px solid #8a8982;
    border-bottom: 2px solid #8a8982;
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

.qr-card {
    width: 100%;
    min-height: 62px;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 7px;
    padding: 6px;
    border: 1px solid var(--soft);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    user-select: none;
}

.qr-card img {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    background: #f3f2eb;
}

.qr-card span {
    font-size: 12px;
    line-height: 1.3;
    font-weight: 700;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.size-section h2 {
    margin: 14px 0 14px;
    font-size: 21px;
    line-height: 1.2;
}

.size-section {
    width: 100%;
    overflow: hidden;
}

.size-list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 2px 2px 8px;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    max-width: 100%;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.size-list::-webkit-scrollbar {
    display: none;
}

.size-option {
    width: 86px;
    height: 96px;
    flex: 0 0 86px;
    border: 1px solid var(--soft);
    border-radius: 13px;
    background: var(--surface);
    color: var(--ink);
    display: grid;
    grid-template-rows: 36px 1fr;
    align-items: center;
    justify-items: center;
    padding: 16px 8px 12px;
    scroll-snap-align: start;
}

.size-option.is-active {
    border: 2px solid var(--ink);
    padding: 15px 7px 11px;
}

.size-shape {
    display: block;
    border: 3px solid currentColor;
    border-radius: 6px;
    opacity: 0.92;
}

.size-option:not(.is-active) .size-shape {
    color: #a9a9a2;
}

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

.shape-wide {
    width: 38px;
    height: 22px;
}

.shape-tall {
    width: 24px;
    height: 36px;
}

.size-label {
    align-self: end;
    font-size: 16px;
    font-weight: 750;
    white-space: nowrap;
}

.generate-btn {
    width: 100%;
    min-height: 64px;
    height: auto;
    border: 0;
    border-radius: 12px;
    background: var(--ink);
    color: #fffef8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 10px;
    font-size: 21px;
    line-height: 1.2;
    font-weight: 800;
    box-shadow: var(--shadow);
}

.generate-btn[disabled] {
    cursor: wait;
    opacity: 0.72;
}

.generate-btn.is-submitting {
    opacity: 0.86;
}

.status-message {
    min-height: 22px;
    margin: -8px 0 0;
    font-size: 15px;
    line-height: 1.45;
    color: var(--muted);
    text-align: center;
}

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

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

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

[hidden] {
    display: none !important;
}

@media (max-width: 430px) {
    .page-shell {
        padding-right: 12px;
        padding-left: 12px;
    }

    .app-header {
        margin-bottom: 24px;
    }

    .app-header h1 {
        font-size: 30px;
    }

    .app-header p {
        font-size: 16px;
    }

    .prompt-panel,
    .upload-panel {
        padding: 14px;
    }

    .textarea-shell textarea {
        min-height: 156px;
        font-size: 18px;
    }

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

    .size-option {
        width: 82px;
        flex-basis: 82px;
    }
}

@media (max-width: 390px) {
    .app-header h1 {
        font-size: 28px;
    }

    .app-header p {
        font-size: 15px;
    }

    .mode-tab {
        gap: 6px;
        font-size: 15px;
        padding-right: 6px;
        padding-left: 6px;
    }

    .mode-tab svg,
    .generate-btn svg,
    .upload-symbol svg {
        width: 22px;
        height: 22px;
    }

    .textarea-shell textarea {
        padding-right: 14px;
        padding-left: 14px;
    }

    .sample-label {
        font-size: 16px;
    }

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

    .qr-card {
        width: 100%;
        grid-template-columns: 44px minmax(0, 1fr);
        min-height: 58px;
        padding: 6px;
        gap: 6px;
    }

    .qr-card img {
        width: 44px;
        height: 44px;
    }

    .qr-card span {
        font-size: 11px;
        line-height: 1.25;
    }
}

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

    .qr-card {
        width: 100%;
        grid-template-columns: 48px minmax(0, 1fr);
    }

    .task-actions a,
    .result-actions a {
        flex-basis: 100%;
    }
}

@media (max-width: 330px) {
    .page-shell {
        padding-right: 10px;
        padding-left: 10px;
    }

    .app-header h1 {
        font-size: 26px;
    }

    .mode-tabs {
        gap: 8px;
    }

    .mode-tab {
        min-height: 52px;
        font-size: 14px;
    }

    .textarea-shell textarea {
        font-size: 17px;
    }

    .generate-btn {
        font-size: 20px;
    }

    .size-option {
        width: 78px;
        flex-basis: 78px;
    }
}
