:root {
    --bg: #12121f;
    --card: #ffffff;
    --ink: #1d2430;
    --muted: #6b7280;
    --line: #e3e6ea;
    --accent: #4a9eff;
    --accent-soft: #eaf4ff;
    --shell: #16162a;
    --shell-2: #12121f;
    --shell-line: #2a2a4a;
    --shell-ink: #e0e0e0;
    --shell-muted: #8a8aaa;
    --shell-hover: #2a2a4a;
    --warning: #f5c542;
    --radius: 10px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
    margin: 0;
    height: 100%;
    background: #1a1a2e;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
        "PingFang SC", "Hiragino Sans GB", sans-serif;
    line-height: 1.5;
    overflow: hidden;
}

/* ---- fullscreen shell ---- */
#app {
    display: flex;
    width: 100vw;
    height: 100vh;
    min-width: 0;
}
#preview-panel {
    flex: 0 0 clamp(360px, 38vw, 560px);
    min-width: 0;
    background: var(--shell);
    color: var(--shell-ink);
    border-right: 1px solid var(--shell-line);
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 0;
    overflow: hidden;
}
#control-panel {
    flex: 1;
    min-width: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--shell-2);
}
.brand-block {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--shell-line);
    flex: none;
}
.brand-mark {
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    background: #1e3a5f;
    color: #fff;
    font-weight: 760;
    letter-spacing: .03em;
}
.panel-kicker {
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--shell-muted);
}
.panel-title {
    margin-top: 2px;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.35;
}

/* ---- top bar ---- */
#topbar {
    flex: none;
    z-index: 10;
    background: var(--shell);
    border-bottom: 1px solid var(--shell-line);
}
#topbar-inner {
    max-width: none;
    margin: 0;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.topbar-titles h1 { margin: 0; font-size: 18px; font-weight: 650; }
.topbar-titles h1 { color: var(--shell-ink); }
.topbar-titles p { margin: 2px 0 0; font-size: 13px; color: var(--shell-muted); }
#topbar-preview:empty { display: none; }
#topbar-preview {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 16px 16px;
}
#topbar-preview .style-preview {
    position: static;
    background: transparent;
    padding: 0;
    margin: 0;
    color: var(--ink);
}
#topbar-preview .style-preview-label {
    margin-bottom: 10px;
}
#topbar-preview .style-preview-card {
    box-shadow: none;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 18px;
    min-height: 260px;
    background: #ffffff;
}
#topbar-preview .spl-title {
    color: var(--shell-ink);
}
#topbar-preview .spl-note {
    color: var(--shell-muted);
}
#topbar-preview .sp-title,
#topbar-preview .sp-body-wrap {
    white-space: normal;
}
#topbar-preview .sp-chip {
    align-self: stretch;
    justify-content: flex-start;
}
#topbar-preview .sp-icon-mark {
    width: 34px;
    height: 34px;
}
#topbar-preview .sp-icon-mark svg {
    width: 30px;
    height: 30px;
    max-width: 30px;
    max-height: 30px;
}

.lang-select {
    position: relative;
    flex: none;
}
.lang-select-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    height: 38px;
    min-width: 118px;
    padding: 0 12px;
    border-radius: 4px;
    border: 1px solid #3a3a5a;
    background: #1e1e3a;
    color: #c0c0d8;
    font-size: 14px;
    cursor: pointer;
}
.lang-select-btn:hover { color: #ffffff; background: var(--shell-hover); border-color: #5a5a7a; }
.lang-caret { font-size: 10px; color: #8a8aa8; }
.lang-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    margin: 0;
    padding: 4px;
    list-style: none;
    min-width: 110px;
    background: #1e1e3a;
    border: 1px solid #3a3a5a;
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    z-index: 60;
}
.lang-menu li {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    color: #c0c0d8;
    cursor: pointer;
}
.lang-menu li:hover,
.lang-menu li:focus { background: var(--shell-hover); color: #ffffff; }
.lang-menu li.selected { color: #ffffff; font-weight: 650; }

/* ---- form ---- */
#form {
    flex: 1;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 24px 32px;
    overflow-y: auto;
}
#sections {
    max-width: 1220px;
    margin: 0 auto;
}
#loading, #error { padding: 40px 0; text-align: center; color: var(--shell-muted); }
#error { color: #b42318; }

.section {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 16px;
}
.section-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.section-num {
    flex: none;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: #1e4fa3;
    font-size: 12px; font-weight: 700;
    display: grid; place-items: center;
}
.section-title { font-size: 15px; font-weight: 620; }
.section-note { font-size: 12.5px; color: var(--muted); }

/* ---- generic controls ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 13.5px;
    line-height: 1.35;
    cursor: pointer;
    transition: all .12s ease;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.chip:hover { border-color: var(--accent); }
.chip.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}
.chip-text { min-width: 0; }
.chip-copy { min-width: 0; }
.chip-with-preview {
    width: 230px;
    padding: 9px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
    text-align: left;
}
.chip-with-preview .chip-text {
    display: block;
    font-size: 12.8px;
}
.chip-with-preview .rec-badge {
    display: inline-block;
    margin: 4px 0 0;
}
.chip-preview-visual_style {
    width: 320px;
}
.option-preview {
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 1px solid var(--line);
    border-radius: 7px;
    overflow: hidden;
    background: #fff;
}
.option-preview svg {
    display: block;
    width: 100%;
    height: 100%;
}
.option-preview img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.option-preview-icons { aspect-ratio: 16 / 7; }
.real-icon-preview {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    background: #fff;
    color: #2563eb;
}
.real-icon-sample {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.real-icon-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: currentColor;
}
.real-icon-mark svg {
    display: block;
    width: 34px;
    height: 34px;
    max-width: 34px;
    max-height: 34px;
    overflow: visible;
}
.real-icon-preview-chunk-filled .real-icon-mark svg {
    shape-rendering: crispEdges;
}
.real-icon-label {
    max-width: 100%;
    color: #64748b;
    font-size: 9px;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text-input, .num-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
}
.text-input:focus, .num-input:focus { outline: none; border-color: var(--accent); }
.num-input { width: 140px; }

/* ---- color candidates ---- */
.color-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.color-card {
    border: 2px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    min-width: 150px;
    transition: border-color .12s ease;
}
.color-card:hover { border-color: var(--accent); }
.color-card.selected { border-color: var(--accent); }
.swatches { display: flex; gap: 6px; margin-bottom: 8px; }
.swatch {
    width: 34px; height: 34px;
    border-radius: 7px;
    border: 1px solid rgba(0,0,0,.06);
}
.color-name { font-size: 13.5px; font-weight: 600; }
.color-hex { font-size: 11.5px; color: var(--muted); font-family: ui-monospace, monospace; }
.color-note { font-size: 12px; color: var(--muted); margin-top: 4px; }

.hex-override { margin-top: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hex-override label { font-size: 12.5px; color: var(--muted); }
.hex-override input {
    width: 96px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 8px;
    font-family: ui-monospace, monospace;
    font-size: 12.5px;
}

/* ---- typography candidates ---- */
.font-grid { display: flex; flex-direction: column; gap: 10px; }
.font-card {
    border: 2px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color .12s ease;
}
.font-card:hover { border-color: var(--accent); }
.font-card.selected { border-color: var(--accent); }
.font-card-head {
    display: flex; align-items: baseline; gap: 10px;
    margin-bottom: 8px;
}
.font-card-name { font-size: 13.5px; font-weight: 600; }
.font-card-meta { font-size: 11.5px; color: var(--muted); }
.image-strategy-previews {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    margin: 8px 0 10px;
}
.image-strategy-preview {
    position: relative;
    aspect-ratio: 16 / 9;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}
.image-strategy-preview img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.image-strategy-preview-label {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.74);
    color: #fff;
    font-size: 10.5px;
    line-height: 1.4;
}
.image-strategy-preview-card {
    flex-direction: column;
    align-items: stretch;
}
.image-strategy-preview-visual {
    width: 100%;
}
.image-strategy-preview-visual .image-strategy-previews {
    grid-template-columns: 1fr;
    margin: 0 0 12px;
}
.image-strategy-preview-visual .image-strategy-preview {
    min-height: 150px;
}
.image-strategy-preview-empty {
    padding: 14px 0 4px;
}
.image-strategy-manual-card {
    background: var(--card);
}
.image-strategy-manual-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin: 10px 0;
}
.image-strategy-select-wrap {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.image-strategy-select-label {
    font-size: 11.5px;
    color: var(--muted);
}
.image-strategy-select {
    width: 100%;
    min-height: 34px;
    padding: 6px 8px;
}
.image-strategy-manual-preview-host > .image-strategy-previews {
    margin-bottom: 0;
}
.font-sample-heading { font-size: 24px; font-weight: 700; line-height: 1.3; }
.font-sample-body { font-size: 14px; color: #333; margin-top: 4px; }
.custom-typography-input { margin-top: 8px; min-height: 58px; resize: vertical; }
.custom-color-input { margin-top: 8px; min-height: 58px; resize: vertical; }
.image-strategy-custom-input { margin-top: 8px; min-height: 72px; resize: vertical; }
.image-usage-notes-input { min-height: 64px; resize: vertical; }
.font-size-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.font-size-input { width: 96px; }
.font-size-unit {
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
}
.body-size-relation { margin-bottom: 6px; }
.body-size-pt { margin-top: 6px; }
.body-size-hint { margin-top: 3px; }

.subfield { margin-top: 14px; }
.subfield-label { font-size: 12.5px; color: var(--muted); margin-bottom: 7px; }

/* ---- toggles ---- */
.toggle-row { display: flex; align-items: center; gap: 12px; }
.toggle-desc { font-size: 12.5px; color: var(--muted); }

/* ---- action bar ---- */
#actionbar {
    flex: none;
    background: var(--shell);
    border-top: 1px solid var(--shell-line);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
}
#confirm-status {
    min-height: 20px;
    font-size: 13px;
    color: var(--shell-muted);
}
#confirm-status.done { color: #067647; font-weight: 600; }
#btn-confirm {
    border: none;
    background: var(--warning);
    color: #1a1a2e;
    font-size: 14.5px;
    font-weight: 600;
    min-width: 132px;
    padding: 10px 26px;
    border-radius: 9px;
    cursor: pointer;
}
#btn-confirm:hover { background: #e5b532; }
#btn-confirm:disabled { background: #6d6450; color: #b8b0a0; cursor: default; }

/* ---- custom input ---- */
.custom-input { margin-top: 8px; }

/* ---- recommended chip + group labels ---- */
.chip.recommended {
    border-color: var(--line);
    box-shadow: none;
}
.rec-badge {
    margin-left: 6px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--muted);
}
.chip.selected .rec-badge { color: var(--accent); }
.group-label {
    font-size: 11.5px;
    color: var(--muted);
    margin: 10px 0 5px;
    letter-spacing: .02em;
}
.chips + .group-label { margin-top: 12px; }

/* ---- palette swatches with role labels ---- */
.swatches { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.swatch-col { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.swatch-role { font-size: 10px; color: var(--muted); }

/* ---- custom HEX grid ---- */
.hex-override { margin-top: 14px; }
.hex-row { display: flex; gap: 10px; flex-wrap: wrap; }
.hex-cell { display: flex; flex-direction: column; gap: 4px; }
.hex-cell-label { font-size: 11px; color: var(--muted); }
.hex-input-line { display: flex; align-items: center; gap: 6px; }
.role-size-line { display: flex; align-items: center; gap: 6px; }
.role-size-pt { min-height: 15px; font-size: 11px; color: var(--muted); }
.hex-cell input {
    width: 92px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 8px;
    font-family: ui-monospace, monospace;
    font-size: 12.5px;
}
/* Live preview of the value typed into the HEX box. */
.hex-swatch {
    flex: none;
    width: 20px; height: 20px;
    border-radius: 5px;
    border: 1px solid var(--line);
}
.hex-swatch.hex-swatch-empty {
    /* Subtle checker so an empty / invalid value reads as "no color" */
    background:
        linear-gradient(45deg, var(--line) 25%, transparent 25%, transparent 75%, var(--line) 75%) 0 0 / 10px 10px,
        var(--card);
}

/* ---- typography CJK / Latin previews ---- */
.font-sample-line { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.font-sample-heading-box .fs-cjk { font-size: 24px; font-weight: 700; }
.font-sample-heading-box .fs-latin { font-size: 22px; font-weight: 700; }
.font-sample-body-box { margin-top: 6px; }
.font-sample-body-box .fs-cjk,
.font-sample-body-box .fs-latin { font-size: 14px; color: #333; }
.font-card-meta { display: block; margin-top: 4px; }

/* ---- confirmed overlay ---- */
#confirmed-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 18, 29, 0.86);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.cf-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 36px 44px;
    text-align: center;
    max-width: 420px;
}
.cf-title { font-size: 22px; font-weight: 700; color: #067647; }
.cf-hint { font-size: 14px; color: var(--muted); margin-top: 10px; line-height: 1.6; }

/* Combined color + typography "overall impression" preview — sticky strip
   that rides along the color / icon / typography picking sections. */
.style-preview {
    position: sticky;
    z-index: 5;
    background: var(--shell-2);
    padding: 8px 0;
    margin-bottom: 16px;
}
.style-preview-label {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 6px;
}
.spl-title { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.spl-note { font-size: 11.5px; color: var(--muted); }
.style-preview-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 16px;
    overflow: hidden;
}
.sp-textcol { flex: 1; min-width: 0; }
.sp-title {
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sp-title-lat { margin-left: 10px; opacity: 0.92; }
.sp-body { display: flex; align-items: stretch; gap: 10px; margin-top: 6px; }
.sp-accent-bar { flex: 0 0 4px; border-radius: 2px; }
.sp-body-wrap {
    flex: 1;
    min-width: 0;
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sp-body-lat { margin-left: 10px; opacity: 0.92; }
.sp-content {
    display: grid;
    gap: 10px;
}
.sp-content-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, 0.07);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.68);
}
.sp-content-icon {
    flex: none;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    color: currentColor;
}
.sp-content-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.sp-content-copy b {
    font-size: 13px;
    line-height: 1.3;
}
.sp-content-copy small {
    color: #64748b;
    font-size: 11.5px;
    line-height: 1.45;
}
.sp-chip {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}
.sp-chip-dot { width: 12px; height: 12px; border-radius: 50%; }
.sp-chip-label { font-size: 12.5px; }
.sp-icon-mark {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    color: currentColor;
}
.sp-icon-mark svg {
    display: block;
    width: 22px;
    height: 22px;
    max-width: 22px;
    max-height: 22px;
    overflow: visible;
}
.sp-icon-emoji {
    font-size: 20px;
    line-height: 1;
}
.sp-icon-none {
    color: #64748b;
    font-size: 11px;
    white-space: nowrap;
}
.sp-icon-none-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    opacity: .55;
}
.direction-preview-card {
    gap: 14px;
}
.direction-preview-visual {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
}
.direction-preview-visual svg,
.direction-preview-visual img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}
.direction-preview-title {
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
}
.direction-preview-desc {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.55;
}

@media (max-width: 1040px) {
    body {
        height: auto;
        overflow: auto;
        background: var(--shell-2);
    }
    #app {
        display: block;
        width: auto;
        height: auto;
        min-height: 100vh;
    }
    #preview-panel {
        width: auto;
        border: 0;
        border-bottom: 1px solid var(--shell-line);
        overflow: visible;
        padding: 0;
    }
    #control-panel {
        height: auto;
        min-height: 0;
    }
    #form {
        overflow: visible;
        padding: 20px;
    }
    #actionbar {
        position: sticky;
        bottom: 0;
        padding: 14px 20px;
    }
    .chip-with-preview {
        width: min(100%, 230px);
    }
    .chip-preview-visual_style {
        width: min(100%, 320px);
    }
    .style-preview-card {
        flex-wrap: wrap;
    }
}
