:root {
    --bg: #efe8de;
    --panel: rgba(255, 251, 246, 0.94);
    --panel-strong: #fffaf3;
    --ink: #1d3040;
    --muted: #6b7681;
    --line: #d8ccbd;
    --accent: #0f446c;
    --accent-dark: #0a314d;
    --warm: #9b6a43;
    --warm-dark: #7d512f;
    --ok: #1f7a52;
    --error: #a23c32;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Microsoft YaHei", Arial, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(155, 106, 67, 0.18), transparent 28%),
        radial-gradient(circle at right center, rgba(15, 68, 108, 0.16), transparent 30%),
        linear-gradient(180deg, #f6f1ea 0%, #ece1d3 100%);
}

.page {
    min-height: 100vh;
    padding: 18px;
}

.hero,
.shell {
    width: min(1180px, 100%);
    margin: 0 auto;
}

.hero {
    margin-bottom: 10px;
}

.hero-copy,
.form-card {
    background: var(--panel);
    border: 1px solid rgba(216, 204, 189, 0.9);
    border-radius: 24px;
    box-shadow: 0 18px 40px rgba(29, 48, 64, 0.08);
}

.hero-copy {
    padding: 24px 24px;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--warm);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 12px;
    font-weight: 700;
}

h1 {
    margin: 0 0 14px;
    font-size: clamp(30px, 4vw, 46px);
    line-height: 1.15;
}

.hero-text {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
    max-width: 48em;
}

.hero-actions {
    display: flex;
    gap: 12px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.hero-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 148px;
    padding: 12px 16px;
    border-radius: 999px;
    text-decoration: none;
    color: white;
    background: var(--accent);
    font-weight: 700;
}

.form-card {
    padding: 16px;
}

.section-head {
    margin-bottom: 8px;
}

.section-head h2 {
    margin: 0 0 6px;
    font-size: 22px;
}

.section-head p {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
}

.top-gap {
    margin-top: 12px;
}

.selection-layout {
    display: grid;
    grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.1fr);
    gap: 12px;
    align-items: start;
}

.base-options {
    display: grid;
    gap: 10px;
}

.base-card {
    cursor: pointer;
}

.base-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.base-card-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, #fffdf9 0%, #f6eee5 100%);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    min-height: 76px;
}

.base-card-body strong {
    font-size: 19px;
    color: var(--ink);
}

.base-card input:checked + .base-card-body {
    border-color: rgba(15, 68, 108, 0.55);
    box-shadow: 0 14px 28px rgba(15, 68, 108, 0.12);
    transform: translateY(-1px);
    background: linear-gradient(180deg, #f8fcff 0%, #edf5fb 100%);
}

.preview-panel {
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 12px;
}

.preview-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 10px;
}

.preview-head h3 {
    margin: 0 0 6px;
    font-size: 20px;
}

.preview-head p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.preview-badge {
    padding: 8px 12px;
    border-radius: 999px;
    background: #efe4d6;
    color: var(--warm);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.preview-empty {
    min-height: 128px;
    display: grid;
    place-items: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 18px;
    padding: 14px;
    text-align: center;
    line-height: 1.7;
    background: rgba(255, 255, 255, 0.52);
}

.hidden {
    display: none !important;
}

.preview-content {
    display: grid;
    gap: 10px;
}

.preview-detail-container {
    min-width: 0;
}

.preview-panel.has-selection .preview-head {
    display: none;
}

.chart-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: white;
    overflow: hidden;
}

.chart-card-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: baseline;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: #fbf6ef;
}

.chart-card-head h4 {
    margin: 0;
    font-size: 17px;
}

.chart-card-head span {
    color: var(--muted);
    font-size: 13px;
}

.chart-wrap {
    height: 250px;
    padding: 8px 10px 10px;
}

.total-analysis {
    padding: 12px;
    display: grid;
    gap: 10px;
}

.core-metrics {
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.metric-chip {
    border-radius: 12px;
    background: #f7f3ed;
    padding: 12px;
}

.metric-chip strong {
    display: block;
    margin-bottom: 6px;
    color: var(--ink);
}

.metric-chip span {
    color: var(--muted);
    font-size: 13px;
}

.ratio-bar {
    display: flex;
    height: 22px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8ecef;
}

.ratio-segment {
    height: 100%;
}

.ratio-segment.acid {
    background: #ff6b6b;
}

.ratio-segment.ester {
    background: #4ecdc4;
}

.ratio-segment.alcohol {
    background: #ffd166;
}

.ratio-segment.aldehyde {
    background: #06d6a0;
}

.ratio-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.ratio-item {
    border-radius: 12px;
    background: #f7f3ed;
    padding: 10px;
}

.ratio-item strong {
    display: block;
    margin-bottom: 6px;
}

.ratio-item span {
    display: block;
    color: var(--muted);
    line-height: 1.6;
    font-size: 13px;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

label,
.color-field,
.packaging-field {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

input:required:invalid {
    border-color: rgba(162, 60, 50, 0.45);
}

label.full {
    grid-column: 1 / -1;
}

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

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    background: white;
    color: var(--ink);
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.input-with-unit {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.input-unit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 54px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f7f1e9;
    color: var(--warm);
    font-weight: 700;
}

.color-field,
.packaging-field {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 10px;
    background: white;
}

.color-field legend,
.packaging-field legend {
    padding: 0 6px;
    color: var(--muted);
}

.field-note {
    margin: 0 0 2px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.packaging-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.packaging-more-note {
    margin: 2px 0 0;
    color: var(--muted);
    line-height: 1.7;
}

.packaging-card {
    justify-items: center;
    cursor: pointer;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 8px 8px;
    background: linear-gradient(180deg, #fffdfa 0%, #f5ece1 100%);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.packaging-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.packaging-visual {
    width: 100%;
    height: 168px;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    border: 2px solid transparent;
    background: linear-gradient(180deg, #fcf8f2 0%, #f3eadf 100%);
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.packaging-visual img {
    position: absolute;
    inset: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    max-width: calc(100% - 20px);
    max-height: calc(100% - 20px);
    object-fit: contain;
    object-position: center;
    display: block;
    background: #fff8ef;
    box-sizing: border-box;
    transform: none;
}

.packaging-name {
    color: var(--ink);
    font-size: 13px;
    font-weight: 700;
}

.packaging-card input:checked + .packaging-visual {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(15, 68, 108, 0.12);
}

.packaging-card input:checked ~ .packaging-name {
    color: var(--accent);
}

.packaging-card:has(input:checked) {
    border-color: rgba(15, 68, 108, 0.4);
    box-shadow: 0 14px 28px rgba(15, 68, 108, 0.08);
    transform: translateY(-1px);
}

.case-showcase {
    display: grid;
    gap: 8px;
}

.case-gallery {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.case-card {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 16px;
    overflow: hidden;
    background: white;
    box-shadow: 0 10px 24px rgba(29, 48, 64, 0.07);
}

.case-card img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: linear-gradient(180deg, #f7ede1 0%, #efe3d3 100%);
}

.case-card figcaption {
    padding: 10px 12px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.color-swatch {
    display: grid;
    gap: 8px;
    justify-items: center;
    cursor: pointer;
}

.color-swatch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.swatch-chip {
    width: 100%;
    height: 42px;
    border-radius: 14px;
    background: var(--swatch);
    border: 2px solid transparent;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.swatch-name {
    color: var(--ink);
    font-size: 13px;
}

.color-swatch input:checked + .swatch-chip {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(15, 68, 108, 0.14);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 16px;
    flex-wrap: wrap;
}

button {
    border: none;
    border-radius: 14px;
    background: var(--accent);
    color: white;
    padding: 12px 18px;
    cursor: pointer;
    font-weight: 700;
}

button:hover {
    background: var(--accent-dark);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.status {
    min-height: 24px;
    color: var(--muted);
}

.status.ok {
    color: var(--ok);
}

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

.preview-panel .product-detail .card:first-child {
    margin-bottom: 14px;
}

.preview-panel .product-detail .card:last-child {
    margin-bottom: 0;
}

.preview-panel .welcome-message {
    padding: 32px 18px;
}

@media (max-width: 980px) {
    .selection-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .field-grid,
    .color-grid,
    .ratio-grid,
    .core-metrics {
        grid-template-columns: 1fr;
    }

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

    .page {
        padding: 14px;
    }

    .hero-copy,
    .form-card {
        padding-left: 16px;
        padding-right: 16px;
    }

    .preview-head {
        flex-direction: column;
    }

    .preview-panel {
        padding: 10px;
    }
}

@media (max-width: 620px) {
    .case-gallery,
    .packaging-grid {
        grid-template-columns: 1fr;
    }

    .packaging-visual {
        height: 188px;
    }
}

/* ========== H5 手机端专项优化 ========== */

/* iOS 防止输入框触发缩放（< 16px 会触发） */
@media (max-width: 768px) {
    input[type="text"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* 触摸反馈：消除 300ms 延迟和蓝色闪烁 */
.packaging-card,
.base-card,
.color-swatch,
.btn,
button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* 按下反馈 */
.packaging-card:active,
.base-card:active,
.color-swatch:active {
    opacity: 0.82;
    transform: scale(0.97);
}

/* 底部 safe-area（iPhone X+ 刘海屏） */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .page {
            padding-bottom: calc(18px + env(safe-area-inset-bottom));
        }
    }
}

/* 手机端最小触摸目标高度 */
@media (max-width: 768px) {
    .base-card-body {
        min-height: 64px;
    }

    .packaging-card {
        min-height: 44px;
    }

    /* 包装图片在手机上稍微大一些 */
    .packaging-visual {
        height: 140px;
    }

    /* 表单标签行高加大，更易点击 */
    .form-card label {
        line-height: 1.8;
    }

    /* 提交按钮全宽，更易点击 */
    #submitBtn {
        width: 100%;
        min-height: 52px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    /* 超小屏：hero 精简 */
    .hero-copy {
        padding: 16px;
    }

    h1 {
        font-size: 24px;
    }

    .hero-text {
        font-size: 14px;
    }

    /* 案例画廊单列，图片稍微矮一些 */
    .case-gallery {
        grid-template-columns: 1fr;
    }

    .case-card img {
        aspect-ratio: 4 / 3;
    }

    /* 包装选择 2 列保持，增大视觉区域 */
    .packaging-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .packaging-visual {
        height: 120px;
    }

    /* 颜色选择格子 3 列 */
    .color-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    /* 表单区域内边距收紧 */
    .form-card {
        padding: 12px;
    }

    .section-head h2 {
        font-size: 18px;
    }
}
