:root {
    color-scheme: dark;
    --bg: #0f172a;
    --panel: #1e293b;
    --panel-border: #334155;
    --sunken: #172033;
    --border-strong: #475569;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --faint: #64748b;
    --line: #334155;
    --accent: #38bdf8;
    --accent-soft: rgba(56, 189, 248, 0.12);
    --accent-dark: #7dd3fc;
    --error: #f87171;
    --warn: #fbbf24;
    --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
}

#app { position: fixed; inset: 0; background: var(--bg); overflow: hidden; }

#stage {
    position: absolute;
    left: 0;
    top: 0;
    width: 1920px;
    height: 1080px;
    padding: 32px;
    transform-origin: 0 0;
    display: flex;
    flex-direction: column;
    gap: 32px;
    background: var(--bg);
}

.topbar {
    height: 88px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand { display: flex; align-items: baseline; gap: 28px; }
.brand h1 { margin: 0; font-size: 44px; font-weight: 700; letter-spacing: 1px; color: var(--text); }
.subtitle {
    margin: 0;
    padding-left: 28px;
    border-left: 3px solid var(--accent);
    font-size: 24px;
    color: var(--muted);
}
.config-warning {
    padding: 10px 24px;
    font-size: 22px;
    color: var(--warn);
    border: 2px solid rgba(251, 191, 36, 0.45);
    border-radius: 12px;
    background: rgba(251, 191, 36, 0.1);
}

.columns {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 360px 1fr 520px;
    gap: 32px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}
.panel-title { margin: 0; font-size: 28px; font-weight: 600; color: var(--text); }

/* 左栏 */
.col-left { padding: 28px; display: flex; flex-direction: column; gap: 24px; min-height: 0; }
.sample-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 16px; }
.sample {
    min-height: 0;
    min-width: 0;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font: inherit;
    font-size: 22px;
    color: var(--text);
    background: var(--sunken);
    border: 2px solid var(--panel-border);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.sample img { flex: 1; min-height: 0; width: 100%; object-fit: cover; border-radius: 8px; display: block; }
.sample span { flex: none; line-height: 1.2; }
.sample:hover { border-color: var(--border-strong); }
.sample.is-selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.upload-zone {
    flex: none;
    height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 16px;
    text-align: center;
    border: 2px dashed var(--border-strong);
    border-radius: 12px;
    color: var(--muted);
    background: var(--sunken);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.upload-zone:hover,
.upload-zone.is-dragover { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.upload-icon { font-size: 40px; line-height: 1; color: var(--accent); }
.upload-text { max-width: 8.2em; font-size: 22px; line-height: 1.3; }

/* 中栏 */
.col-mid { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 32px; }
.preview { flex: 1; min-height: 0; position: relative; padding: 20px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#preview-img { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; display: block; border-radius: 8px; }
.preview-empty { font-size: 32px; color: var(--faint); }

.flow { flex: none; margin: 0; padding: 24px 12px; list-style: none; display: flex; }
.flow-step { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 0 6px; text-align: center; }
.flow-step::before {
    content: "";
    position: absolute;
    top: 29px;
    left: calc(-50% + 36px);
    width: calc(100% - 72px);
    height: 3px;
    background: var(--panel-border);
    border-radius: 2px;
}
.flow-step:first-child::before { display: none; }
.flow-step[data-status="done"]::before { background: var(--accent); }
.flow-step[data-status="active"]::before { background: linear-gradient(90deg, var(--accent), var(--panel-border)); }
.flow-dot {
    position: relative;
    z-index: 1;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 600;
    border: 2px solid var(--border-strong);
    color: var(--faint);
    background: var(--panel);
}
.flow-label { text-wrap: balance; font-size: 22px; line-height: 1.3; color: var(--faint); min-height: 58px; }
.flow-step[data-status="active"] .flow-dot {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
    animation: breathe 1.4s ease-in-out infinite;
}
.flow-step[data-status="active"] .flow-label { color: var(--accent-dark); }
.flow-step[data-status="done"] .flow-dot { color: var(--bg); border-color: var(--accent); background: var(--accent); }
.flow-step[data-status="done"] .flow-dot .num { display: none; }
.flow-step[data-status="done"] .flow-dot::after { content: "✓"; }
.flow-step[data-status="done"] .flow-label { color: var(--text); }
@keyframes breathe {
    0%, 100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.3); }
    50% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
}

/* 右栏 */
.col-right { padding: 28px 32px; display: flex; flex-direction: column; gap: 20px; min-height: 0; overflow: hidden; }
.col-right .panel-title { font-size: 24px; color: var(--muted); font-weight: 500; }
.valve-name { font-size: 64px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; color: var(--accent-dark); }
.result-message { text-wrap: balance; margin: 0; font-size: 32px; line-height: 1.5; color: var(--muted); }
#app[data-state="error"] .result-message { color: var(--error); }
#app[data-state="not_found"] .result-message { color: var(--warn); }
#app[data-state="loading"] .result-message { color: var(--accent); }
.result-rows { display: flex; flex-direction: column; gap: 6px; }
.result-row { display: flex; flex-direction: column; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.result-label { font-size: 24px; color: var(--muted); }
.result-value { font-size: 40px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; min-height: 48px; color: var(--text); }
.result-row.is-skeleton .result-value {
    width: 60%;
    border-radius: 8px;
    background: #334155;
    color: transparent;
    animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }
.result-elapsed { margin-top: auto; font-size: 28px; color: var(--muted); }
.retry-btn {
    align-self: flex-start;
    padding: 14px 48px;
    font: inherit;
    font-size: 28px;
    font-weight: 600;
    color: var(--bg);
    background: var(--accent);
    border: 0;
    border-radius: 12px;
    cursor: pointer;
}
.retry-btn:hover { background: var(--accent-dark); }
