:root {
    --bg: #f3f1e8;
    --panel: #fffdf7;
    --line: #d6cfbe;
    --ink: #1d2a2f;
    --muted: #627277;
    --accent: #0f766e;
    --accent-strong: #0b5f59;
    --warn: #8f3d1c;
    --ok: #136f3c;
    --shadow: 0 18px 40px rgba(24, 36, 30, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top right, rgba(15, 118, 110, 0.12), transparent 26%),
        linear-gradient(180deg, #f8f5ec 0%, #efe9dc 100%);
}

button,
input,
select {
    font: inherit;
}

button {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    padding: 0.62rem 0.9rem;
    cursor: pointer;
    transition: background 120ms ease, transform 120ms ease;
}

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

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

select {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 0.62rem 0.78rem;
    color: var(--ink);
}

input[type="range"] {
    width: 100%;
}

code {
    padding: 0.1rem 0.35rem;
    border-radius: 6px;
    background: rgba(15, 118, 110, 0.08);
}

.ghost-button {
    background: transparent;
    color: var(--accent);
}

.page-shell {
    max-width: 1820px;
    height: 100vh;
    margin: 0 auto;
    padding: 0.35rem 0.5rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.hero {
    display: block;
    margin-bottom: 0;
}

.eyebrow,
.status-label,
.field-label,
.summary-title,
.small-note {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.status-banner {
    padding: 0.42rem 0.7rem;
    border-radius: 12px;
    border: 1px solid transparent;
    line-height: 1.3;
    font-size: 0.8rem;
}

.status-ok {
    background: rgba(19, 111, 60, 0.08);
    color: var(--ok);
    border-color: rgba(19, 111, 60, 0.18);
}

.status-warn {
    background: rgba(143, 61, 28, 0.08);
    color: var(--warn);
    border-color: rgba(143, 61, 28, 0.18);
}

.workspace {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) 290px;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "left chart params";
    gap: 0.7rem;
}

.site-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 1.45rem;
    color: var(--muted);
    font-size: 0.76rem;
}

.site-footer strong {
    color: var(--accent-strong);
    font-variant-numeric: tabular-nums;
}

.panel {
    border: 1px solid rgba(19, 33, 41, 0.08);
    border-radius: 22px;
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 0.72rem;
    overflow: hidden;
}

.left-column {
    grid-area: left;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 0.7rem;
}

.control-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
}

.promo-panel {
    flex: 0 0 auto;
    margin-top: auto;
    padding: 0.5rem;
}

.promo-trigger-btn {
    width: 100%;
}

.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(29, 42, 47, 0.46);
}

.dialog-backdrop[hidden] {
    display: none !important;
}

.dialog-card {
    width: min(460px, 100%);
    border: 1px solid rgba(19, 33, 41, 0.1);
    border-radius: 22px;
    background: var(--panel);
    box-shadow: 0 24px 60px rgba(24, 36, 30, 0.18);
    padding: 0.9rem;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    margin-bottom: 0.7rem;
}

.dialog-header h3 {
    margin: 0;
    font-size: 1rem;
}

.dialog-close-btn {
    padding: 0.42rem 0.7rem;
}

.dialog-copy {
    margin-bottom: 0.7rem;
    color: var(--accent-strong);
    font-weight: 600;
    line-height: 1.45;
}

.dialog-image {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 16px;
}

.chart-panel {
    grid-area: chart;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.parameter-panel {
    grid-area: params;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-title-row,
.button-row,
.button-stack {
    display: flex;
    gap: 0.7rem;
}

.panel-title-row {
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.55rem;
}

.panel-title-row h2 {
    margin: 0;
    font-size: 0.98rem;
}

.drop-zone {
    margin-bottom: 0.75rem;
    padding: 0.9rem 0.8rem;
    border: 1.5px dashed rgba(15, 118, 110, 0.35);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(15, 118, 110, 0.05), rgba(15, 118, 110, 0.02));
    text-align: center;
    cursor: pointer;
    transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.drop-zone:hover,
.drop-zone.drag-over {
    transform: translateY(-1px);
    border-color: rgba(15, 118, 110, 0.7);
    background: linear-gradient(180deg, rgba(15, 118, 110, 0.09), rgba(15, 118, 110, 0.04));
}

.drop-title {
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.drop-subtitle {
    color: var(--muted);
    font-size: 0.95rem;
}

.example-list,
.parameter-list {
    display: grid;
    gap: 0.55rem;
}

.summary-box {
    margin-top: 0.2rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--line);
}

.summary-list {
    margin: 0.55rem 0 0;
    display: grid;
    gap: 0.45rem;
}

.summary-list div {
    display: grid;
    grid-template-columns: 74px 1fr;
    gap: 0.5rem;
}

.summary-list dt {
    color: var(--muted);
}

.summary-list dd,
.summary-list dt {
    margin: 0;
}

.toolbar-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.6rem;
    margin-bottom: 0.42rem;
}

.chart-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.42rem;
    margin-bottom: 0.5rem;
}

.chart-action-btn {
    padding: 0.42rem 0.68rem;
    line-height: 1.05;
}

.engineer-option-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 0.45rem;
    padding: 0.18rem 0.1rem 0;
}

.engineer-option {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--muted);
    font-size: 0.82rem;
    cursor: pointer;
    user-select: none;
}

.engineer-option input {
    margin: 0;
}

.chart-shell {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: linear-gradient(180deg, #fbfaf5 0%, #f4efe2 100%);
    padding: 0.18rem;
}

#chartCanvas {
    width: 100%;
    height: 100%;
    min-height: 420px;
    display: block;
    cursor: grab;
}

#chartCanvas.is-panning {
    cursor: grabbing;
}

.chart-tooltip {
    position: absolute;
    min-width: 170px;
    max-width: min(320px, calc(100% - 1rem));
    padding: 0.55rem 0.7rem;
    border: 1px solid rgba(15, 118, 110, 0.24);
    border-radius: 12px;
    background: rgba(255, 253, 247, 0.96);
    box-shadow: 0 12px 28px rgba(24, 36, 30, 0.12);
    color: var(--ink);
    font-size: 0.82rem;
    line-height: 1.35;
    pointer-events: none;
    z-index: 2;
}

.chart-tooltip strong {
    display: block;
    margin-bottom: 0.22rem;
    color: var(--accent-strong);
}

.slider-row {
    margin-top: 0.45rem;
}

.slider-label {
    margin-top: 0.35rem;
    color: var(--muted);
}

.metric-strip {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.45rem;
}

.metric-pill {
    padding: 0.32rem 0.58rem;
    border-radius: 999px;
    background: rgba(15, 118, 110, 0.1);
    color: var(--accent-strong);
    font-size: 0.78rem;
}

.port-builder {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 0.55rem;
    align-items: end;
    margin-bottom: 0.45rem;
}

.port-builder label {
    display: grid;
    gap: 0.3rem;
}

.port-builder input[type="number"] {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 0.58rem 0.7rem;
    color: var(--ink);
}

.parameter-hint {
    margin-bottom: 0.5rem;
    line-height: 1.45;
}

.parameter-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    border: 1px solid rgba(214, 207, 190, 0.95);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.5);
    padding: 0.45rem;
    padding-right: 0.15rem;
    margin-top: 0.15rem;
}

.parameter-tree,
.parameter-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.parameter-tree {
    display: grid;
    gap: 0.3rem;
    align-content: start;
}

.parameter-branch {
    position: relative;
}

.parameter-branch-details {
    border: 1px solid rgba(214, 207, 190, 0.92);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    overflow: hidden;
}

.parameter-root {
    list-style: none;
}

.parameter-branch-summary {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.4rem;
    padding: 0.38rem 0.55rem;
    background: rgba(15, 118, 110, 0.06);
    cursor: pointer;
    font-weight: 600;
    line-height: 1.2;
}

.parameter-branch-summary::-webkit-details-marker {
    display: none;
}

.parameter-branch-summary::before {
    content: "";
    width: 0.45rem;
    height: 0.45rem;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform 140ms ease;
    margin-right: 0.05rem;
}

.parameter-branch-details[open] > .parameter-branch-summary::before {
    transform: rotate(45deg);
}

.parameter-branch-summary input {
    margin-left: 0.05rem;
}

.parameter-branch-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.parameter-branch-meta {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 500;
}

.parameter-children {
    display: grid;
    gap: 0.14rem;
    padding: 0.16rem 0.28rem 0.25rem 1.05rem;
    position: relative;
}

.parameter-children::before {
    content: "";
    position: absolute;
    left: 0.76rem;
    top: 0;
    bottom: 0.2rem;
    border-left: 1px solid rgba(214, 207, 190, 0.95);
}

.parameter-leaf {
    position: relative;
}

.parameter-leaf::before {
    content: "";
    position: absolute;
    left: -0.28rem;
    top: 50%;
    width: 0.28rem;
    border-top: 1px solid rgba(214, 207, 190, 0.95);
}

.parameter-item {
    display: flex;
    align-items: center;
    gap: 0.38rem;
    padding: 0.18rem 0.38rem;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    min-width: 0;
    line-height: 1.15;
}

.parameter-item > span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.parameter-tree-toggle {
    grid-template-columns: auto minmax(0, 1fr);
    margin-bottom: 0;
    padding: 0.18rem 0.38rem;
    border-radius: 8px;
    background: transparent;
}

.parameter-tree-toggle:hover {
    background: rgba(15, 118, 110, 0.05);
}

.parameter-tree-toggle::before {
    content: none;
}

.button-stack {
    flex-direction: column;
    margin-top: 0.5rem;
    flex: 0 0 auto;
}

.text-box {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    padding: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.empty-note {
    color: var(--muted);
}

@media (max-width: 1280px) {
    html,
    body {
        overflow: auto;
    }

    .page-shell {
        height: auto;
        min-height: 100vh;
    }

    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        grid-template-areas: none;
    }

    .control-panel,
    .left-column,
    .chart-panel,
    .parameter-panel {
        grid-area: auto;
    }

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

    .chart-action-row {
        gap: 0.36rem;
    }

    .engineer-option-row {
        gap: 0.6rem;
    }

    .parameter-list {
        max-height: 320px;
    }

    .hero {
        flex-direction: column;
    }
}

@media (max-height: 900px) {
    .drop-zone {
        padding: 0.9rem 0.8rem;
    }

    #chartCanvas {
        min-height: 340px;
    }
}

@media (max-width: 760px) {
    .page-shell {
        padding: 0.8rem;
    }

    .toolbar-grid {
        grid-template-columns: 1fr;
    }

    .chart-action-row {
        justify-content: flex-start;
    }

    .engineer-option-row {
        flex-direction: column;
        gap: 0.35rem;
    }

    .panel-title-row {
        flex-direction: column;
        align-items: stretch;
    }

    .parameter-list {
        grid-template-columns: 1fr;
    }

    .parameter-children,
    .port-builder {
        grid-template-columns: 1fr;
    }

    .metric-strip {
        justify-content: flex-start;
    }
}
