:root {
    --bg: #020305;
    --text: #e6edf3;
    --muted: rgba(230, 237, 243, 0.62);
    --dim: rgba(230, 237, 243, 0.34);
    --faint: rgba(230, 237, 243, 0.12);
    --accent: 94, 234, 212;            /* RGB 分量，随场景切换 */
    --serif-zh: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', SimSun, serif;
    --mono: 'JetBrains Mono', 'Courier New', monospace;
    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    -webkit-font-smoothing: antialiased;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

#stage {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

.hud > * { pointer-events: auto; }
.hud > .brand, .hud > .card, .hud > .intro, .hud > .stats { pointer-events: none; }
.intro .intro-start { pointer-events: auto; }

body.hud-hidden .hud { opacity: 0; }
body.hud-hidden .hud > * { pointer-events: none; }

/* ---------- 品牌 ---------- */
.brand {
    position: absolute;
    top: 32px;
    left: 40px;
}

.brand-title {
    font-family: var(--serif-zh);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.32em;
}

.brand-sub {
    margin-top: 8px;
    font-size: 10px;
    letter-spacing: 0.38em;
    color: var(--dim);
    text-transform: uppercase;
}

.brand-sub::before {
    content: '';
    display: inline-block;
    width: 22px;
    height: 1px;
    margin-right: 10px;
    vertical-align: middle;
    background: rgb(var(--accent));
    opacity: 0.8;
    transition: background 1.2s ease;
}

/* ---------- 序幕 ---------- */
.intro {
    position: absolute;
    left: 40px;
    bottom: 150px;
    max-width: 460px;
    transition: opacity 0.8s var(--ease), transform 0.8s var(--ease);
}

.intro h1 {
    font-family: var(--serif-zh);
    font-size: 44px;
    font-weight: 600;
    letter-spacing: 0.2em;
    line-height: 1.2;
}

.intro p {
    margin-top: 18px;
    font-family: var(--serif-zh);
    font-size: 15px;
    line-height: 2;
    color: var(--muted);
}

.intro-start {
    margin-top: 28px;
    padding: 10px 22px;
    border: 1px solid rgba(var(--accent), 0.5);
    border-radius: 2px;
    font-size: 11px;
    letter-spacing: 0.32em;
    color: rgb(var(--accent));
    transition: background 0.3s ease, border-color 0.3s ease;
}

.intro-start:hover:not(:disabled) {
    background: rgba(var(--accent), 0.1);
    border-color: rgb(var(--accent));
}

button:disabled {
    cursor: default;
    opacity: 0.45;
}

.intro-status {
    margin-top: 14px;
    min-height: 2.8em;
    max-width: 360px;
    font-family: var(--serif-zh);
    font-size: 12px;
    line-height: 1.8;
    color: var(--muted);
}

.intro.is-hidden {
    opacity: 0;
    transform: translateY(12px);
    visibility: hidden;
    transition: opacity 0.6s var(--ease), transform 0.6s var(--ease), visibility 0s 0.6s;
}

/* ---------- 信息卡 ---------- */
.card {
    position: absolute;
    left: 40px;
    bottom: 112px;
    width: min(440px, calc(100vw - 80px));
}

/* 柔和的暗色衬底：保证文字在粒子上可读（不使用 backdrop-filter） */
.card::before {
    content: '';
    position: absolute;
    inset: -60px -90px -50px -60px;
    background: radial-gradient(ellipse at 30% 60%, rgba(2, 3, 5, 0.72) 0%, rgba(2, 3, 5, 0.4) 45%, rgba(2, 3, 5, 0) 72%);
    z-index: -1;
    pointer-events: none;
}

.card > * {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}

.card.is-in > * { opacity: 1; transform: none; }
.card.is-in > :nth-child(2) { transition-delay: 0.08s; }
.card.is-in > :nth-child(3) { transition-delay: 0.16s; }
.card.is-in > :nth-child(4) { transition-delay: 0.24s; }
.card.is-in > :nth-child(5) { transition-delay: 0.32s; }

.card-index {
    font-size: 10px;
    letter-spacing: 0.32em;
    color: var(--dim);
}

.card-index b {
    font-weight: 600;
    color: rgb(var(--accent));
    transition: color 1.2s ease;
}

.card-title {
    margin-top: 10px;
    display: flex;
    align-items: baseline;
    gap: 14px;
    flex-wrap: wrap;
}

.card-zh {
    font-family: var(--serif-zh);
    font-size: 32px;
    font-weight: 600;
    letter-spacing: 0.12em;
}

.card-en {
    font-size: 10px;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--dim);
}

.card-tex {
    margin-top: 14px;
    min-height: 28px;
    font-size: 16px;
    color: rgba(var(--accent), 1);
    transition: color 1.2s ease;
}

.card-tex mjx-container { margin: 0 !important; text-align: left !important; }

.card-def {
    margin-top: 14px;
    font-family: var(--serif-zh);
    font-size: 14px;
    line-height: 1.95;
    color: var(--muted);
}

.card-poetic {
    margin-top: 12px;
    padding-left: 14px;
    border-left: 1px solid rgba(var(--accent), 0.45);
    font-family: var(--serif-zh);
    font-size: 12.5px;
    line-height: 1.9;
    color: var(--dim);
    transition: border-color 1.2s ease;
}

/* ---------- 扰动面板 ---------- */
.panel {
    position: absolute;
    right: 0;
    top: 50%;
    width: 300px;
    transform: translate(0, -50%);
    transition: transform 0.6s var(--ease), opacity 0.6s var(--ease);
}

.panel.is-collapsed { transform: translate(calc(100% - 34px), -50%); }
.panel.is-empty { opacity: 0; pointer-events: none; transform: translate(40px, -50%); }

.panel-inner {
    display: flex;
    align-items: stretch;
}

.panel-tab {
    flex: 0 0 34px;
    padding: 16px 0;
    writing-mode: vertical-rl;
    font-size: 10px;
    letter-spacing: 0.4em;
    color: var(--dim);
    border: 1px solid var(--faint);
    border-right: none;
    background: rgba(4, 6, 10, 0.72);
    transition: color 0.3s ease;
}

.panel-tab:hover { color: var(--text); }

.panel-body {
    flex: 1;
    min-width: 0;
    padding: 20px 22px 18px;
    background: rgba(4, 6, 10, 0.78);
    border: 1px solid var(--faint);
    border-right: none;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10px;
    letter-spacing: 0.3em;
    color: var(--dim);
}

.panel-reset {
    font-size: 10px;
    letter-spacing: 0.12em;
    color: rgb(var(--accent));
    opacity: 0.85;
}

.panel-reset:hover { opacity: 1; text-decoration: underline; }

.ctl { margin-top: 20px; }

.ctl-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.ctl-label {
    font-family: 'Times New Roman', var(--serif-zh), serif;
    font-style: italic;
    font-size: 17px;
}

.ctl-label sub { font-size: 11px; font-style: normal; }

.ctl-value {
    font-size: 11px;
    color: var(--muted);
}

.ctl-value.is-real { color: rgb(var(--accent)); }

.ctl-track { position: relative; margin-top: 10px; }

.ctl-track input {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 18px;
    background: transparent;
    cursor: pointer;
}

.ctl-track input::-webkit-slider-runnable-track {
    height: 1px;
    background: rgba(230, 237, 243, 0.22);
}

.ctl-track input::-moz-range-track {
    height: 1px;
    background: rgba(230, 237, 243, 0.22);
}

.ctl-track input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 11px;
    height: 11px;
    margin-top: -5px;
    border-radius: 50%;
    background: rgb(var(--accent));
    box-shadow: 0 0 10px rgba(var(--accent), 0.8);
}

.ctl-track input::-moz-range-thumb {
    width: 11px;
    height: 11px;
    border: none;
    border-radius: 50%;
    background: rgb(var(--accent));
    box-shadow: 0 0 10px rgba(var(--accent), 0.8);
}

/* 真实值刻度 */
.ctl-real {
    position: absolute;
    top: 13px;
    width: 1px;
    height: 7px;
    background: rgba(var(--accent), 0.7);
    pointer-events: none;
}

.ctl-real::after {
    content: attr(data-label);
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8.5px;
    letter-spacing: 0.1em;
    color: var(--dim);
    white-space: nowrap;
}

.ctl-note {
    margin-top: 14px;
    font-size: 10.5px;
    line-height: 1.7;
    color: var(--dim);
}

.readout {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--faint);
}

.readout:empty { display: none; }

.readout-title {
    font-size: 10px;
    letter-spacing: 0.24em;
    color: var(--dim);
}

.readout-big {
    margin-top: 8px;
    font-size: 20px;
    letter-spacing: 0.04em;
    color: var(--text);
}

.readout-big small { font-size: 11px; color: var(--muted); }

.readout-line {
    margin-top: 6px;
    font-size: 10.5px;
    line-height: 1.7;
    color: var(--muted);
}

.readout canvas {
    display: block;
    width: 100%;
    height: 112px;
    margin-top: 10px;
}

.readout-legend {
    display: flex;
    gap: 14px;
    margin-top: 6px;
    font-size: 9.5px;
    color: var(--dim);
}

.readout-legend { flex-wrap: wrap; row-gap: 2px; }
.readout-legend span { white-space: nowrap; }
.readout-legend .readout-axis { flex-basis: 100%; }

.readout-legend i {
    display: inline-block;
    width: 10px;
    height: 2px;
    margin-right: 5px;
    vertical-align: middle;
}

/* ---------- 数量级天梯 ---------- */
.ladder {
    position: absolute;
    left: 40px;
    right: 40px;
    bottom: 30px;
    height: 54px;
}

.ladder-axis {
    position: absolute;
    left: 0;
    right: 0;
    top: 30px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(230, 237, 243, 0.22) 6%, rgba(230, 237, 243, 0.22) 94%, transparent);
}

.ladder-tick {
    position: absolute;
    top: -3px;
    width: 1px;
    height: 7px;
    background: rgba(230, 237, 243, 0.2);
}

.ladder-tick span {
    position: absolute;
    top: 11px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8.5px;
    color: var(--dim);
    white-space: nowrap;
}

.ladder-tick span sup { font-size: 7px; }

.ladder-dot {
    position: absolute;
    top: -22px;              /* 圆点中心对齐轴线 */
    width: 26px;
    height: 32px;
    margin-left: -13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    font-family: 'Times New Roman', var(--serif-zh), serif;
    font-style: italic;
    font-size: 13px;
    color: var(--muted);
    transition: color 0.3s ease;
}

.ladder-dot sub { font-size: 8.5px; font-style: normal; }

.ladder-dot::after {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
}

.ladder-dot:hover { color: var(--text); }
.ladder-dot.is-active { color: rgb(var(--accent)); }

.ladder-dot.is-pending {
    color: rgba(230, 237, 243, 0.2);
    cursor: default;
}

.ladder-dot.is-pending::after { box-shadow: none; }

.ladder-cursor {
    position: absolute;
    top: -22px;
    width: 1px;
    height: 30px;
    margin-left: -0.5px;
    background: linear-gradient(180deg, rgba(var(--accent), 0), rgba(var(--accent), 0.9));
    transition: left 1.4s var(--ease), opacity 0.6s ease;
    pointer-events: none;
}

.ladder-caption {
    position: absolute;
    right: 0;
    top: 0;
    font-size: 8.5px;
    letter-spacing: 0.2em;
    color: var(--dim);
}

/* ---------- 导航 ---------- */
.nav {
    position: absolute;
    right: 40px;
    bottom: 104px;
    display: flex;
    gap: 6px;
}

.nav-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--faint);
    border-radius: 50%;
    font-size: 16px;
    line-height: 1;
    color: var(--muted);
    transition: color 0.3s ease, border-color 0.3s ease;
}

.nav-btn:hover { color: var(--text); border-color: rgba(230, 237, 243, 0.35); }

.nav-btn[aria-pressed="true"] {
    color: rgb(var(--accent));
    border-color: rgba(var(--accent), 0.6);
}

.nav-quality { font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em; }

.hint {
    position: absolute;
    right: 40px;
    top: 36px;
    font-size: 9.5px;
    letter-spacing: 0.18em;
    color: var(--dim);
}

.hint kbd {
    display: inline-block;
    min-width: 17px;
    padding: 1px 4px;
    margin-right: 4px;
    border: 1px solid rgba(230, 237, 243, 0.16);
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 8.5px;
    text-align: center;
    color: var(--muted);
}

.hint span + span { margin-left: 14px; }

.stats {
    position: absolute;
    right: 40px;
    top: 64px;
    font-size: 10px;
    line-height: 1.8;
    letter-spacing: 0.18em;
    color: var(--dim);
    text-align: right;
}

/* ---------- 降级 ---------- */
.fallback {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    font-family: var(--serif-zh);
    color: var(--muted);
    text-align: center;
    padding: 24px;
}

.fallback small {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--dim);
}

body.no-webgl .fallback { display: flex; }
body.no-webgl #stage, body.no-webgl .hud { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
    .hint { display: none; }
    .panel { top: auto; bottom: 168px; transform: none; width: 280px; }
    .panel.is-collapsed { transform: translateX(calc(100% - 34px)); }
    .panel.is-empty { transform: translateX(40px); }
}

@media (max-width: 640px) {
    .brand { top: 20px; left: 20px; }
    .brand-title { font-size: 16px; }
    .intro { left: 20px; right: 20px; bottom: 130px; }
    .intro h1 { font-size: 32px; }
    .card { left: 20px; bottom: 96px; width: calc(100vw - 40px); }
    .card-zh { font-size: 24px; }
    .card-def { font-size: 13px; line-height: 1.8; }
    .card-poetic { display: none; }
    .ladder { left: 20px; right: 20px; bottom: 18px; }
    .ladder-tick span { display: none; }
    .ladder-caption { display: none; }
    .nav { right: 20px; top: 18px; bottom: auto; }
    .nav-btn { width: 30px; height: 30px; font-size: 14px; }
    .nav-quality { font-size: 9px; }
    .panel { bottom: auto; top: 64px; width: min(300px, calc(100vw - 16px)); }
    .panel-body { padding: 16px 16px 14px; }
    .stats { right: 20px; top: 56px; }
}
