/* 银河系动态运转模拟 — UI 样式
   配色锁定: 深空黑背景 + 唯一强调色(太阳系亮蓝)
   禁纯黑 #000000 / 禁纯白 #ffffff */

:root {
    --bg:          #08090c;
    --bg-panel:    rgba(14, 16, 21, 0.82);
    --bg-panel-2:  rgba(20, 23, 29, 0.9);
    --border:      rgba(255, 255, 255, 0.09);
    --border-str:  rgba(255, 255, 255, 0.16);

    --text:        #e8e9ec;
    --text-dim:    #8a8f98;
    --text-faint:  #5d626b;

    --accent:      #5fd0ff;
    --accent-dim:  rgba(95, 208, 255, 0.16);
    --accent-line: rgba(95, 208, 255, 0.4);

    --warm:        #ffd2a1;

    --radius:      10px;
    --radius-sm:   6px;

    --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
            -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
            "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

#scene {
    position: fixed;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: grab;
}
#scene:active { cursor: grabbing; }

/* ---------------------------------------------------------- 载入态 */

#boot {
    position: fixed;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 14px;
    justify-items: center;
    background: var(--bg);
    z-index: 50;
    transition: opacity 0.6s ease;
}
#boot.hidden { opacity: 0; pointer-events: none; }

.boot-ring {
    width: 42px; height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.boot-text {
    font-size: 13px;
    color: var(--text-dim);
    letter-spacing: 0.04em;
}
#boot-error { color: #ff8080; font-size: 13px; max-width: 80vw; text-align: center; }

/* ---------------------------------------------------------- 标题 */

#title {
    position: fixed;
    top: 26px;
    left: 30px;
    z-index: 10;
    pointer-events: none;
}
#title h1 {
    margin: 0;
    font-size: 19px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text);
}
#title p {
    margin: 5px 0 0;
    font-size: 12px;
    color: var(--text-faint);
    font-family: var(--mono);
    letter-spacing: 0.03em;
}
#title .title-note {
    margin-top: 3px;
    font-size: 11px;
    color: rgba(95, 208, 255, 0.62);
}

/* ---------------------------------------------------------- 右侧信息面板 */

#info-panel {
    position: fixed;
    top: 24px;
    right: 24px;
    width: 286px;
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    z-index: 20;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s ease;
}
#info-panel.collapsed {
    transform: translateX(calc(100% + 30px));
    opacity: 0;
    pointer-events: none;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 15px;
    border-bottom: 1px solid var(--border);
}
.panel-head span {
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-dim);
    font-family: var(--mono);
}

.panel-body { padding: 4px 0 8px; }

.sec {
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.sec:last-child { border-bottom: none; }

.sec-title {
    font-size: 10.5px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
    font-family: var(--mono);
    margin-bottom: 9px;
}

.row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    padding: 3px 0;
    font-size: 12.5px;
}
.row .k { color: var(--text-dim); white-space: nowrap; }
.row .v {
    font-family: var(--mono);
    color: var(--text);
    text-align: right;
    font-size: 12px;
}
.row .v.accent { color: var(--accent); }
.row .v.warm { color: var(--warm); }

/* 视角 / 跟随按钮 */

.btn-row { display: flex; gap: 6px; margin-top: 4px; }

.btn {
    flex: 1;
    padding: 7px 6px;
    font-size: 12px;
    font-family: var(--font);
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.075); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn.active {
    background: var(--accent-dim);
    border-color: var(--accent-line);
    color: var(--accent);
}
.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* 图例 */

.legend { display: flex; flex-direction: column; gap: 6px; }
.legend-item {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 12px;
    color: var(--text-dim);
}
.legend-swatch {
    width: 16px; height: 3px;
    border-radius: 2px;
    flex-shrink: 0;
}
.legend-item .mono {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-faint);
}

/* ---------------------------------------------------------- 地球生物史卡片 */

.life-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    background: rgba(95, 208, 255, 0.05);
    border: 1px solid var(--accent-line);
    border-radius: var(--radius-sm);
}

.life-card.flash { animation: lifeFlash 0.75s ease-out; }
@keyframes lifeFlash {
    0%   { background: rgba(95, 208, 255, 0.26); transform: scale(1.03); }
    100% { background: rgba(95, 208, 255, 0.05);  transform: scale(1); }
}

.life-emoji {
    font-size: 30px;
    line-height: 1;
    flex-shrink: 0;
    width: 40px;
    text-align: center;
    filter: drop-shadow(0 0 8px rgba(95, 208, 255, 0.35));
}

.life-main { min-width: 0; flex: 1; }

.life-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
}
.life-latin {
    font-size: 10.5px;
    font-style: italic;
    color: var(--accent);
    font-family: var(--mono);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.life-era {
    font-size: 10.5px;
    color: var(--text-faint);
    font-family: var(--mono);
    margin-top: 2px;
}

.life-note {
    margin-top: 8px;
    font-size: 11.5px;
    line-height: 1.55;
    color: var(--text-dim);
}

.life-bar {
    margin-top: 9px;
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
}
.life-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--warm));
    border-radius: 2px;
    transition: width 0.12s linear;
}

.life-timeline {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 10.5px;
    color: var(--text-faint);
}

/* ---------------------------------------------------------- 底部控制条 */

#controls {
    position: fixed;
    bottom: 26px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 9px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

#scale-options { display: flex; gap: 5px; }

.scale-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 13px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
    font-family: var(--font);
}
.scale-btn:hover { background: rgba(255, 255, 255, 0.075); }
.scale-btn:active { transform: translateY(1px); }
.scale-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent-line);
}
.scale-main {
    font-size: 12.5px;
    color: var(--text-dim);
    white-space: nowrap;
}
.scale-btn.active .scale-main { color: var(--accent); }
.scale-sub {
    font-size: 10px;
    color: var(--text-faint);
    font-family: var(--mono);
}
.scale-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ctrl-sep {
    width: 1px;
    height: 30px;
    background: var(--border);
}

.icon-btn {
    width: 34px; height: 34px;
    display: grid;
    place-items: center;
    font-size: 14px;
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.075); color: var(--text); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent-line);
    color: var(--accent);
}
.icon-btn.paused { color: var(--accent); border-color: var(--accent-line); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 面板开合按钮 */
#panel-toggle {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 21;
    width: 34px; height: 34px;
    display: grid;
    place-items: center;
    color: var(--text-dim);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, color 0.18s ease;
}
#info-panel.collapsed ~ #panel-toggle {
    opacity: 1;
    pointer-events: auto;
}
#panel-toggle:hover { color: var(--accent); }

/* ---------------------------------------------------------- 提示 */

#hint {
    position: fixed;
    bottom: 92px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    font-size: 11.5px;
    color: var(--text-faint);
    font-family: var(--mono);
    letter-spacing: 0.04em;
    pointer-events: none;
    text-align: center;
    transition: opacity 0.6s ease;
}
#hint.fade { opacity: 0; }

/* ---------------------------------------------------------- 移动端 */

@media (max-width: 820px) {
    #title { top: 16px; left: 18px; }
    #title h1 { font-size: 16px; }
    #title p { font-size: 11px; }

    /* 移动端: 面板贴底, 折叠时向下移出屏幕。
       ⚠️ transform 的基线值必须一致 —— 桌面端用 translateX,
          移动端用 translateY。如果基线是 none, 折叠/展开时
          浏览器会从 none 插值到 translateY(...), 面板会横向抖一下。 */
    #info-panel {
        top: auto;
        bottom: 92px;
        right: 12px;
        left: 12px;
        width: auto;
        max-height: 46dvh;
        transform: translateY(0);
    }
    #info-panel.collapsed {
        transform: translateY(calc(100% + 100px));
    }
    #panel-toggle { top: 16px; right: 16px; }

    #controls {
        bottom: 16px;
        left: 12px;
        right: 12px;
        transform: none;
        flex-wrap: wrap;
        justify-content: center;
        gap: 9px;
    }
    .scale-btn { padding: 5px 9px; }
    .scale-main { font-size: 11.5px; }

    #hint { bottom: auto; top: 68px; font-size: 10.5px; }
}

/* ---------------------------------------------------------- 降级 */

@media (prefers-reduced-motion: reduce) {
    .boot-ring { animation: none; }
    * { transition-duration: 0.01ms !important; }
}

@media (prefers-reduced-transparency: reduce) {
    #info-panel, #controls, #panel-toggle {
        background: rgba(12, 14, 18, 0.96);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}
