:root {
    --accent: #4cc2ff;
    --accent-hover: #6fd0ff;
    --accent-active: #1a9fe0;
    --accent-soft: rgba(76, 194, 255, 0.16);
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --text-tertiary: #808080;
    --fill-card: rgba(32, 32, 32, 0.82);
    --fill-media: rgba(28, 28, 28, 0.72);
    --stroke-rest: rgba(255, 255, 255, 0.08);
    --stroke-hover: rgba(255, 255, 255, 0.16);
    --shadow-elevation: 0 8px 16px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.05);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --fps-good: #6ccb5f;
    --fps-mid: #fbbc04;
    --fps-bad: #f14c4c;

    --font-ui: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-mono: "Cascadia Mono", "Consolas", monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: var(--font-ui);
    color: var(--text-primary);
}

canvas#gl-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    display: block;
    background: radial-gradient(ellipse at center, #0d1420 0%, #000 100%);
}

/* ---------- 顶部 HUD ---------- */
.hud-top {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 20;
}

.hud-title {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--fill-card);
    -webkit-backdrop-filter: blur(30px) saturate(140%);
    backdrop-filter: blur(30px) saturate(140%);
    border: 1px solid var(--stroke-rest);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-elevation);
}

.hud-title-main {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.hud-title-sub {
    margin-top: 2px;
    font-size: 11px;
    color: var(--text-tertiary);
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- FPS 卡片 ---------- */
.fps-card {
    padding: 10px 14px;
    background: var(--accent-soft);
    -webkit-backdrop-filter: blur(30px) saturate(140%);
    backdrop-filter: blur(30px) saturate(140%);
    border: 1px solid rgba(76, 194, 255, 0.35);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-elevation);
    text-align: right;
    min-width: 150px;
    transition: border-color 0.2s ease;
}

.fps-card .fps-value {
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 4px;
    font-family: var(--font-mono);
}

.fps-card .fps-value span {
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.fps-card .fps-unit {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-ui);
}

.fps-meta {
    margin-top: 2px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.fps-res {
    margin-top: 2px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}

/* ---------- 压力模式 ---------- */
.mode-bar {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--fill-card);
    -webkit-backdrop-filter: blur(30px) saturate(140%);
    backdrop-filter: blur(30px) saturate(140%);
    border: 1px solid var(--stroke-rest);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-elevation);
    z-index: 20;
}

.mode-btn {
    appearance: none;
    border: none;
    cursor: pointer;
    padding: 8px 24px;
    border-radius: var(--radius-md);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    transition: background 0.15s ease, color 0.15s ease;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent);
    color: #0b0b0b;
    font-weight: 600;
}

.mode-btn.active:hover {
    background: var(--accent-hover);
}

/* ---------- 底部控制 ---------- */
.ctl-bar {
    position: fixed;
    right: 16px;
    bottom: 18px;
    display: flex;
    gap: 8px;
    z-index: 20;
}

.ctl-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--stroke-rest);
    border-radius: var(--radius-md);
    background: var(--fill-card);
    -webkit-backdrop-filter: blur(30px) saturate(140%);
    backdrop-filter: blur(30px) saturate(140%);
    color: var(--text-primary);
    box-shadow: var(--shadow-elevation);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.ctl-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--stroke-hover);
    transform: translateY(-1px);
}

.ctl-btn:active {
    transform: translateY(0) scale(0.96);
}

.ctl-btn.accent {
    background: var(--accent);
    border-color: transparent;
    color: #0b0b0b;
}

.ctl-btn.accent:hover {
    background: var(--accent-hover);
}

.glyph {
    font-family: "Segoe Fluent Icons", "Segoe MDL2 Assets", system-ui;
    font-size: 16px;
    line-height: 1;
}

/* ---------- Fluent 设置悬窗 ---------- */
.flyout[hidden],
.flyout-mask[hidden] {
    display: none !important;
}

.flyout-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 30;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.flyout {
    position: fixed;
    right: 12px;
    bottom: 72px;
    width: 340px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    background: var(--fill-media);
    -webkit-backdrop-filter: blur(50px) saturate(180%);
    backdrop-filter: blur(50px) saturate(180%);
    border: 1px solid var(--stroke-rest);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
    z-index: 40;
    overflow: hidden;
    animation: flyoutIn 0.18s cubic-bezier(0.3, 0.9, 0.4, 1);
    transform-origin: bottom right;
}

@keyframes flyoutIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.flyout-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px 8px;
}

.flyout-title {
    font-size: 16px;
    font-weight: 600;
}

.icon-btn {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.flyout-body {
    padding: 4px 16px 12px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.setting-row {
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
}

.setting-desc {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    color: var(--text-tertiary);
    line-height: 1.4;
}

.setting-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.setting-value {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    align-self: flex-end;
    font-variant-numeric: tabular-nums;
}

/* ---------- 滑杆 ---------- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 20px;
    background: transparent;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(
        to right,
        var(--accent) 0%,
        var(--accent) var(--range-fill, 50%),
        rgba(255, 255, 255, 0.15) var(--range-fill, 50%)
    );
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    margin-top: -7px;
    transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type="range"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---------- Fluent 开关 ---------- */
.switch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    flex-shrink: 0;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.switch-track {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.28);
    transition: background 0.15s ease;
}

.switch-track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s cubic-bezier(0.3, 0.9, 0.4, 1);
}

.switch input:checked + .switch-track {
    background: var(--accent);
}

.switch input:checked + .switch-track::after {
    transform: translateX(20px);
}

.switch input:focus-visible + .switch-track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- 设置底部按钮 ---------- */
.flyout-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.btn {
    padding: 8px 18px;
    border: 1px solid var(--stroke-rest);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--stroke-hover);
}

.btn.accent {
    background: var(--accent);
    border-color: transparent;
    color: #0b0b0b;
    font-weight: 600;
}

.btn.accent:hover {
    background: var(--accent-hover);
}

/* ---------- 错误提示 ---------- */
.gl-error {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 420px;
    padding: 18px 22px;
    background: var(--fill-card);
    -webkit-backdrop-filter: blur(30px) saturate(140%);
    backdrop-filter: blur(30px) saturate(140%);
    border: 1px solid var(--stroke-rest);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-elevation);
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.6;
    text-align: center;
    z-index: 50;
}

@media (prefers-reduced-motion: reduce) {
    .flyout,
    .flyout-mask {
        animation: none;
    }
}