/* huanfly-os is always mounted on the physical monitor, with a WebGL-free fallback. */
.monitor-focus { position: fixed; inset: 0; display: none; pointer-events: none; }
/* Bleed only the dark backing beneath the opaque WebGL rim. The HTML viewport
   and its hit area stay unchanged; coincident CSS/WebGL antialiasing cannot
   reveal the paper background through a hairline at the aperture edge. */
.monitor-focus.is-spatial { position: absolute; inset: auto; display: block; backface-visibility: hidden; background: var(--st-screen); box-shadow: 0 0 0 3px var(--st-screen); }
.mf-screen { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; background: #0b1916; color: #edf9f3; font-family: var(--font-ui); -webkit-font-smoothing: antialiased; touch-action: auto; }
/* A restrained luminous edge, not a milky reflection/filter over photos or text.
   It stays inside the same depth-occluded plane and never intercepts input. */
.mf-screen::after { content: ''; position: absolute; inset: 0; z-index: 4; pointer-events: none; box-shadow: inset 0 0 0 1px #b6fff23d, inset 0 0 14px #79e9d112; }
.mf-exit { position: fixed; z-index: 7; right: 30px; top: 20px; display: flex; align-items: center; gap: 8px; min-height: 37px; padding: 0 14px; background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-line); border-radius: 15px; font-size: 12px !important; }
.mf-exit kbd { font: 10px var(--font-ui); opacity: .6; }
.studio.is-at-monitor .lab-header-tools { margin-right: 130px; }
.studio.is-computer-fallback .monitor-focus { display: block; z-index: 6; inset: 80px max(20px, calc((100vw - 1180px) / 2)) 95px; pointer-events: auto; }
.studio.is-computer-fallback .lab-loader { display: none; }

/* ---------- OS 骨架 ---------- */
.os {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(ellipse at 18% 8%, #4fc4cf38, transparent 58%),
        radial-gradient(ellipse at 82% 92%, #7cc95f24, transparent 55%),
        linear-gradient(145deg, #102c27, #081612 70%);
}

.os-topbar {
    flex: 0 0 auto;
    height: 48px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    font-size: 0.82rem;
    color: rgba(230, 240, 232, 0.78);
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.os-topbar .os-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    color: #fffdf5;
    letter-spacing: 0.02em;
}

.os-topbar .os-brand img {
    width: 20px;
    height: 20px;
    border-radius: 46% 54% 52% 48% / 54% 46% 54% 46%;
    border: 1.5px solid rgba(255, 253, 245, 0.7);
}

.os-topbar .os-title {
    flex: 1;
    text-align: center;
    font-weight: 700;
    color: rgba(230, 240, 232, 0.9);
}

.os-topbar .os-status {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.os-topbar .os-status i {
    opacity: 0.8;
}

.os-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 36px;
    height: 34px;
    padding: 0 10px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(230, 240, 232, 0.85);
    background: rgba(255, 255, 255, 0.06);
    border: 1.5px solid rgba(255, 255, 255, 0.14);
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.os-btn:hover {
    background: rgba(124, 201, 95, 0.22);
    border-color: rgba(124, 201, 95, 0.5);
    color: #fffdf5;
}

.os-btn.primary {
    background: var(--primary-color);
    border-color: transparent;
    color: #10140e;
}

.os-btn.primary:hover {
    background: var(--primary-hover);
}

.os-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.os-btn[hidden] {
    display: none;
}

.os-body {
    flex: 1;
    position: relative;
    min-height: 0;
}

.os-app {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    min-height: 0;
}

.os-app.active {
    display: flex;
    animation: os-app-in 0.35s ease both;
}

@keyframes os-app-in {
    from { opacity: 0; transform: translateY(10px) scale(0.985); }
}

/* ---------- 桌面 ---------- */
.os-desktop {
    align-items: center;
    justify-content: center;
    gap: clamp(20px, 4vmin, 42px);
    text-align: center;
    padding: 24px;
    overflow: auto;
}

.os-desktop::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 26%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 220' preserveAspectRatio='none'%3E%3Cpath fill='%237cc95f' fill-opacity='0.10' d='M0 118C200 70 420 140 640 104 880 66 1140 132 1440 88v132H0z'/%3E%3Cpath fill='%236fd8e2' fill-opacity='0.10' d='M0 158c240-40 520 24 780-10 240-30 460 28 660-10v82H0z'/%3E%3C/svg%3E") no-repeat bottom / 100% 100%;
    pointer-events: none;
}

.os-clock {
    position: relative;
    line-height: 1;
}

.os-clock .time {
    font-size: clamp(2.4rem, 8vmin, 5.2rem);
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.04em;
    color: #f2f8f1;
    text-shadow: 0 6px 30px rgba(111, 216, 226, 0.25);
}

.os-clock .date {
    margin-top: 0.6vmin;
    font-size: clamp(0.8rem, 2vmin, 1.05rem);
    color: rgba(230, 240, 232, 0.65);
}

.os-clock .greet {
    margin-top: 18px;
    font-size: clamp(0.8rem, 2.1vmin, 1.1rem);
    color: rgba(230, 240, 232, 0.8);
    font-style: normal;
}

.os-dock {
    position: relative;
    display: flex;
    gap: clamp(10px, 2.4vmin, 26px);
    padding: clamp(8px, 1.6vmin, 16px) clamp(12px, 2.4vmin, 24px);
    background: rgba(255, 255, 255, 0.06);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-radius: 22px;
    backdrop-filter: blur(6px);
}

.os-dock-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: clamp(84px, 14vmin, 140px);
    padding: 0;
    background: none;
    border: none;
    color: rgba(230, 240, 232, 0.9);
    font-family: inherit;
    font-size: clamp(0.7rem, 1.7vmin, 0.9rem);
    font-weight: 700;
    cursor: pointer;
}

.os-dock-item .icon {
    width: clamp(46px, 8.6vmin, 80px);
    height: clamp(46px, 8.6vmin, 80px);
    display: grid;
    place-items: center;
    font-size: clamp(1.3rem, 3.8vmin, 2.2rem);
    color: #10140e;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 22px;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.3), 0 6px 18px rgba(0, 0, 0, 0.22);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.os-dock-item:hover .icon,
.os-dock-item:focus-visible .icon {
    transform: translateY(-5px) scale(1.03);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
}

.os-dock-item.terminal .icon { background: linear-gradient(145deg, #8fd873, #5da844); }
.os-dock-item.album .icon { background: linear-gradient(145deg, #7ee3ec, #4fc4cf); }
.os-dock-item.robot .icon { background: linear-gradient(145deg, #c9b4f4, #9b7ede); }

.os-dock-item .badge {
    position: absolute;
}

/* ---------- 通用 App 头部 ---------- */
.app-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    flex-wrap: wrap;
    font-size: 0.86rem;
    color: rgba(230, 240, 232, 0.8);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(0, 0, 0, 0.18);
}

.app-head .app-name {
    font-weight: 800;
    color: #fffdf5;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.app-head .grow {
    flex: 1;
}

.app-head .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #6d7a6e;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.app-head .dot.guest { background: #f2c46e; }

.app-body {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* ---------- 终端 ---------- */
.term-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    background: #13231d;
    text-align: center;
    color: #dcead0;
}
.term-loading[hidden], .term-loading button[hidden] { display: none; }
.term-loading small { color: #afc3b5; line-height: 1.6; }

.term-body {
    position: absolute;
    inset: 0;
    padding: 8px 4px 6px 10px;
    background: #0b1210;
}

.term-body .xterm {
    height: 100%;
}

.term-body .xterm .xterm-viewport {
    background-color: transparent !important;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 201, 95, 0.35) transparent;
}

.term-body .xterm .xterm-viewport::-webkit-scrollbar {
    width: 8px;
}

.term-body .xterm .xterm-viewport::-webkit-scrollbar-thumb {
    background: rgba(124, 201, 95, 0.35);
    border: none;
    border-radius: 6px;
}

/* ---------- 相册 ---------- */
.album-tabs {
    display: inline-flex;
    gap: 6px;
}

.album-grid {
    position: absolute;
    inset: 0;
    overflow: auto;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(clamp(120px, 20vmin, 220px), 1fr));
    gap: 12px;
    align-content: start;
    scrollbar-width: thin;
}

/* A handful of photos should read as a few large prints, not a sparse thumbnail sheet. */
.album-grid[data-density="sparse"] {
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 45%), 1fr));
    gap: 16px;
    padding: 18px;
}

.album-item {
    position: relative;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    padding: 0;
    background: rgba(255, 255, 255, 0.04);
    border: 2px solid rgba(255, 253, 245, 0.16);
    border-radius: var(--wobble-sm);
    cursor: pointer;
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.album-item:nth-child(odd) { transform: rotate(-0.8deg); }
.album-item:nth-child(even) { transform: rotate(0.8deg); }

.album-item:hover,
.album-item:focus-visible {
    transform: translateY(-4px) rotate(0deg);
    border-color: rgba(111, 216, 226, 0.8);
    box-shadow: 4px 6px 0 rgba(0, 0, 0, 0.35);
}

.album-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}

.album-item:hover img {
    transform: scale(1.05);
}

.album-item figcaption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 5px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    color: #fffdf5;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    text-align: left;
}

.album-empty {
    grid-column: 1 / -1;
    padding: 4vmin 1rem;
    text-align: center;
    color: rgba(230, 240, 232, 0.55);
}

.album-viewer {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: none;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #080f0d;
}

.album-viewer.open {
    display: flex;
}

.album-viewer .viewer-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
}

.album-viewer .viewer-index {
    min-width: 0;
    color: #b2c8be;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.viewer-close { flex-shrink: 0; background: #24382d; }

.album-viewer .viewer-stage {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: center;
    padding: 4px 64px;
    position: relative;
}

/* Both dimensions belong to the bounded grid cell, never to the image's
   intrinsic size. Contain preserves every edge, including tall panoramas. */
.album-viewer img {
    display: block;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    object-fit: contain;
}

.album-viewer .viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    font-size: 1.1rem;
    color: #fffdf5;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 253, 245, 0.35);
    border-radius: 46% 54% 52% 48% / 54% 46% 54% 46%;
    cursor: pointer;
    transition: background 0.2s ease;
}

.album-viewer .viewer-nav:hover {
    background: rgba(93, 168, 68, 0.6);
}

.album-viewer .viewer-nav.prev { left: 14px; }
.album-viewer .viewer-nav.next { right: 14px; }

.album-viewer .viewer-caption {
    flex: 0 0 auto;
    min-width: 0;
    padding: 6px 16px 10px;
    text-align: center;
    font-size: 0.92rem;
    line-height: 1.4;
    color: rgba(230, 240, 232, 0.85);
}

.album-viewer .viewer-caption span {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.album-viewer .viewer-caption span:empty { display: none; }

.album-viewer .viewer-caption small {
    display: block;
    margin-top: 2px;
    font-size: 0.75rem;
    color: rgba(230, 240, 232, 0.45);
}

/* ---------- Robot：静态研究占位 ---------- */
.robot-status { margin-left: auto; color: #c2ace8; }
.robot-placeholder { display: flex; overflow: auto; padding: 24px; }
.robot-placeholder-content { margin: auto; max-width: 360px; text-align: center; }
.robot-placeholder-content > i {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    border-radius: 20px;
    background: rgba(179, 154, 236, 0.12);
    color: #c2ace8;
    font-size: 28px;
}
.robot-placeholder h2 { margin: 0 0 10px; color: #e6f0e8; font-size: 22px; font-weight: 500; }
.robot-placeholder p { margin: 0; color: #afc3b5; font-size: 14px; line-height: 1.8; }

/* ---------- 应用细节 ---------- */
.os-desktop-label { margin: 0; color: #a8c1ad; font: 10px ui-monospace, monospace; letter-spacing: 0.24em; }
.os-dock-item small { color: #b2c5b8; font-size: 11px; font-weight: 400; margin-top: 2px; }
.os-session { font-size: 10px; letter-spacing: 0.06em; opacity: 0.65; }
.os-topbar .os-status .os-btn { border: none; background: transparent; }
.os-app[data-app="album"] .app-body { overflow: hidden; }

@media (max-width: 600px) {
    .mf-exit { top: max(12px, env(safe-area-inset-top)); right: 12px; padding: 8px 12px; font-size: 12px; }
    .mf-exit kbd { display: none; }
    .os-topbar { height: 46px; padding: 0 12px; gap: 8px; font-size: 12px; }
    .os-topbar .os-session { display: none; }
    .os-topbar .os-status { gap: 6px; }
    .os-desktop { padding: 20px 10px; gap: 36px; }
    .os-clock .time { font-size: 64px; }
    .os-clock .date { margin-top: 12px; font-size: 12px; }
    .os-clock .greet { font-size: 13px; }
    .os-dock { gap: 6px; padding: 16px 8px; border-radius: 18px; }
    .os-dock-item { width: clamp(72px, 22vw, 86px); font-size: 13px; }
    .os-dock-item .icon { width: 54px; height: 54px; border-radius: 16px; font-size: 22px; margin-bottom: 4px; }
    .os-dock-item small { font-size: 9px; }
    .os-btn { min-height: 40px; }
    .app-head { padding: 10px 12px; gap: 8px; font-size: 12px; }
    .app-head .app-name { gap: 6px; }
    .album-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 10px; }
    .album-viewer .viewer-stage { padding: 2px 52px; }
    .album-viewer .viewer-toolbar { padding: 4px 10px; }
    .album-viewer .viewer-nav.prev { left: 5px; }
    .album-viewer .viewer-nav.next { right: 5px; }
    .album-viewer .viewer-caption { padding: 4px 10px 6px; font-size: 12px; }
    .album-viewer .viewer-caption small { display: none; }
}

@media (max-height: 600px) and (min-width: 601px) {
    .mf-exit { right: 8px; top: 8px; font-size: 0; padding: 12px; }
    .mf-exit i { font-size: 14px; }
    .mf-exit kbd { display: none; }
    .os-desktop { gap: 14px; }
    .os-desktop-label { display: none; }
    .os-clock .time { font-size: 42px; }
    .os-clock .greet { margin-top: 8px; }
    .os-dock { padding: 8px 16px; }
    .os-dock-item .icon { width: 42px; height: 42px; border-radius: 12px; font-size: 20px; }
    .os-dock-item small { display: none; }
    .album-viewer .viewer-toolbar { padding: 4px 10px; }
    .album-viewer .viewer-caption { padding: 4px 10px 6px; font-size: 12px; }
    .album-viewer .viewer-caption small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .studio *, .studio *::before, .studio *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Layout is sized to the monitor, independent of its projected size on the page. */
.is-spatial .os-topbar { height: 38px; font-size: 12px; }
.is-spatial .os-desktop { gap: 24px; padding: 20px; }
.is-spatial .os-clock .time { font-size: 78px; }
.is-spatial .os-clock .date { font-size: 14px; margin-top: 10px; }
.is-spatial .os-clock .greet { font-size: 15px; margin-top: 14px; }
.is-spatial .os-dock { padding: 12px 20px; gap: 22px; }
.is-spatial .os-dock-item { width: 110px; font-size: 14px !important; }
.is-spatial .os-dock-item .icon { width: 56px; height: 56px; font-size: 25px; }
.is-spatial .app-body { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.is-spatial .os-app[data-app="album"] .app-body { overflow: hidden; }
.is-spatial .os-app.active { animation: none; }
@media (max-width: 700px) {
    .studio.is-at-monitor .lab-header-tools { margin-right: 100px; }
    .studio.is-at-monitor .lab-breeze, .studio.is-at-monitor #lab-theme { display: none; }
    .mf-exit { right: 16px; top: 17px; min-height: 32px; }
    .mf-exit kbd { display: none; }
    .is-spatial .os-topbar { height: 32px; }
    .is-spatial .os-desktop { padding: 12px; gap: 12px; flex-direction: row; }
    .is-spatial .os-desktop-label, .is-spatial .os-clock .greet, .is-spatial .os-session, .is-spatial .os-dock-item small { display: none; }
    .is-spatial .os-clock { flex: 0 0 120px; }
    .is-spatial .os-clock .time { font-size: 42px; }
    .is-spatial .os-clock .date { margin-top: 8px; font-size: 12px; line-height: 1.5; }
    .is-spatial .os-dock { padding: 10px; gap: 10px; }
    .is-spatial .os-dock-item { width: 62px; }
    .is-spatial .os-dock-item .icon { width: 48px; height: 48px; font-size: 23px; }
    .is-spatial .app-head { padding: 4px 10px; min-height: 36px; }
    .is-spatial .album-viewer .viewer-toolbar { padding: 4px 10px; }
    .is-spatial .album-viewer .viewer-stage { padding: 2px 52px; }
    .is-spatial .album-viewer .viewer-nav.prev { left: 5px; }
    .is-spatial .album-viewer .viewer-nav.next { right: 5px; }
    .is-spatial .album-viewer .viewer-caption { padding: 4px 10px 6px; font-size: 12px; }
    .is-spatial .album-viewer .viewer-caption small { display: none; }
    .is-spatial .robot-placeholder { padding: 8px 12px; }
    .is-spatial .robot-placeholder-content > i { width: 36px; height: 36px; margin-bottom: 8px; font-size: 22px; border-radius: 12px; }
    .is-spatial .robot-placeholder h2 { margin-bottom: 6px; font-size: 18px; }
    .is-spatial .robot-placeholder p { font-size: 12px; line-height: 1.6; }
}
