/* Entrance: dark room, small monitor, boot log, then the camera moves in.
   html[data-entrance] is set before first paint and removed when it ends. */

#entrance-veil {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(ellipse at 50% 62%, rgba(4, 8, 6, 0.78) 0%, rgba(4, 8, 6, 0.9) 50%, #040806 82%);
}
html[data-entrance] #entrance-veil {
    opacity: var(--entrance-dark, 1);
}
html[data-entrance] #monitor-rig {
    pointer-events: none;
}

#boot-log {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 300;
    margin: 0;
    padding: clamp(14px, 5%, 44px);
    overflow: hidden;
    font: inherit;
    font-size: clamp(11px, 1.9cqw, 17px);
    line-height: 1.7;
    white-space: pre-wrap;
    color: #8fe3a5;
    text-shadow: 0 0 8px rgba(143, 227, 165, 0.45);
    background: #0c0d0f;
}
#boot-log::after {
    content: '\2588';
    animation: boot-cursor 0.7s steps(1) infinite;
}
@keyframes boot-cursor {
    50% {
        opacity: 0;
    }
}
html[data-entrance='dark'] #boot-log,
html[data-entrance='boot'] #boot-log {
    display: block;
}
html[data-entrance='dark'] #terminal-container,
html[data-entrance='boot'] #terminal-container,
html[data-entrance='dark'] #starfield,
html[data-entrance='boot'] #starfield {
    visibility: hidden;
}
html[data-entrance='dark'] #monitor-glass,
html[data-entrance='boot'] #monitor-glass {
    background: #0c0d0f;
}
html[data-entrance='dolly'] #terminal-container {
    animation: screen-settle 420ms ease-out;
}
@keyframes screen-settle {
    from {
        opacity: 0;
    }
}

/* The wide shot. JS takes over these transforms once the camera starts moving. */
@media (min-width: 1000px) and (min-height: 600px) {
    html[data-entrance]:not([data-room3d]) body:not([data-display-mode='web1']) #monitor-rig {
        transform: scale(0.56);
        transform-origin: 50% calc(100% + var(--monitor-stand-height, 0px));
    }
    html[data-entrance]:not([data-room3d]) .room-backdrop {
        transform: scale(0.93);
    }
    html[data-entrance]:not([data-room3d]) .room-foreground {
        transform: scale(0.88);
        transform-origin: 50% 100%;
    }
}

@media print {
    #entrance-veil,
    #boot-log {
        display: none !important;
    }
}

/* ---- the room, alive. Everything is gated on body[data-room-live], which
   room-life.js sets; without scripts or with reduced motion the room is still. */

.lamp-light {
    position: absolute;
    left: -28%;
    top: 27%;
    width: 150%;
    height: 80%;
    clip-path: polygon(22% 0, 44% 0, 100% 100%, 0 100%);
    background: linear-gradient(rgba(134, 180, 147, 0.2), rgba(134, 180, 147, 0.02));
    opacity: 0;
    transition: opacity 0.5s;
    pointer-events: none;
}
body[data-room-live][data-lamp='on'] .lamp-light {
    opacity: 1;
}
body[data-lamp='off'] .lamp-shade::after {
    border-color: var(--scene-line);
    background: var(--scene-line);
}
html[data-entrance='dark'] .lamp-light,
html[data-entrance='boot'] .lamp-light {
    opacity: 0 !important;
}

.room-skyline b {
    position: absolute;
    width: 3px;
    height: 4px;
    background: var(--scene-accent);
    opacity: 0;
    transition: opacity 1.8s;
}
.room-skyline b.is-lit {
    opacity: 0.9;
}

body[data-room-live] .rack-meter i,
body[data-room-live] .rack-meter i:nth-child(n) {
    height: 100%;
    transform-origin: bottom;
    transform: scaleY(var(--level, 0.4));
    transition: transform 0.24s linear;
}

body[data-room-live]:not([data-room-still]) .room-curtain {
    animation: curtain-sway 7s ease-in-out infinite alternate;
}
@keyframes curtain-sway {
    to {
        transform: skewX(-4.4deg);
    }
}

body[data-room-live]:not([data-room-still]) .room-neon::after {
    animation: neon-cursor 1.1s steps(1) infinite;
}
@keyframes neon-cursor {
    50% {
        opacity: 0.15;
    }
}
.room-neon.is-jolted {
    animation: neon-jolt 420ms steps(1);
}
@keyframes neon-jolt {
    0%,
    40% {
        opacity: 0.25;
    }
    20%,
    60% {
        opacity: 1;
    }
    80% {
        opacity: 0.5;
    }
}

.rack-drives i.is-busy::after {
    animation: drive-busy 100ms steps(1) 5;
}
@keyframes drive-busy {
    50% {
        background: #e9fff0;
        box-shadow: 0 0 6px #b8ffd0;
    }
}

.power-led.is-beating {
    animation: led-beat 700ms ease-out;
}
@keyframes led-beat {
    0% {
        background: #e9fff0;
        box-shadow: 0 0 10px 2px #b8ffd0;
    }
}

.room-speaker.is-thumping i {
    animation: cone-thump 360ms ease-out;
}
@keyframes cone-thump {
    25% {
        transform: scale(1.09);
    }
}

/* ---- section changes run as a command ---- */

.command-line {
    margin: 0 0 14px;
    color: var(--terminal-fg);
    white-space: nowrap;
    overflow: hidden;
}
.command-prompt {
    color: var(--terminal-dim);
}
.command-cursor {
    margin-left: 1px;
    opacity: 0;
}
.command-line.is-typing .command-cursor {
    opacity: 1;
}
.section-content > .is-pending {
    visibility: hidden;
}
body[data-display-mode='web1'] .command-line {
    display: none;
}
@media print {
    .command-line {
        display: none;
    }
    .section-content > .is-pending {
        visibility: visible;
    }
}

/* ---- the 3D room (room3d.js). html[data-room3d] is set before first paint
   ('loading'), becomes 'on' when the scene is ready and is removed when 3D is
   unavailable, which brings the CSS room back. ---- */

#room3d {
    display: none;
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.7s;
    image-rendering: pixelated;
}
html[data-room3d] body:not([data-display-mode='web1']) {
    background: #020306;
}
/* The sky seen through the room's window: the room canvas is transparent there. */
html[data-room3d='on'] body:not([data-display-mode='web1']) {
    background: var(--room-sky, #020306) fixed;
}
html body #starfield.in-sky {
    position: fixed;
    inset: 0;
    z-index: -2;
    width: 100%;
    height: 100%;
    opacity: 1;
    filter: none;
    visibility: visible;
    image-rendering: pixelated;
}
html[data-room3d] #room-scene {
    visibility: hidden;
}
html[data-room3d='on'][data-entrance] #room3d,
html[data-room3d='on'][data-room-look] #room3d {
    display: block;
    opacity: 1;
}
html[data-room-look] #monitor-shell {
    pointer-events: none;
}
html[data-room-look],
html[data-room-look] body {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
#room-hint {
    position: fixed;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 5;
    transform: translateX(-50%);
    padding: 6px 12px;
    border: 1px solid rgba(120, 255, 170, 0.25);
    background: rgba(4, 8, 10, 0.72);
    color: rgba(150, 255, 190, 0.85);
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s, visibility 0.4s;
}
html[data-room-look] #room-hint {
    opacity: 1;
    visibility: visible;
}
#room-hint .hint-touch,
#room-hint .hint-focus,
html[data-room-focus] #room-hint .hint-room,
html[data-room-look='drag'] #room-hint {
    display: none;
}
html[data-room-focus] #room-hint .hint-focus.hint-mouse {
    display: inline;
}
@media (pointer: coarse) {
    #room-hint .hint-room.hint-touch,
    html[data-room-focus] #room-hint .hint-focus.hint-touch {
        display: inline;
    }
    html[data-room-focus] #room-hint .hint-room,
    html[data-room-focus] #room-hint .hint-focus.hint-mouse,
    html #room-hint .hint-mouse {
        display: none;
    }
}
@media (max-width: 700px) {
    #room-hint {
        box-sizing: border-box;
        width: max-content;
        max-width: calc(100vw - 24px);
        white-space: normal;
        text-align: center;
    }
}
/* DOM that belongs to a close-up in the 3D room; room3d.js places it. */
#room-focus {
    position: fixed;
    inset: 0;
    z-index: 5;
    overflow: hidden;
    pointer-events: none;
}
.focus-lcd {
    display: none;
    position: absolute;
    left: 0;
    top: 0;
    box-sizing: border-box;
    padding: 12px;
    transform-origin: 0 0;
    background: #0b1a22;
    color: #a8ecff;
    font-size: 14px;
    line-height: 1.4;
    will-change: transform;
}
#focus-back {
    position: absolute;
    left: max(18px, env(safe-area-inset-left));
    top: max(18px, env(safe-area-inset-top));
    padding: 6px 12px;
    border: 1px solid rgba(120, 255, 170, 0.25);
    background: rgba(4, 8, 10, 0.72);
    color: rgba(150, 255, 190, 0.85);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s, visibility 0.4s;
}
html[data-room-focus] #focus-back {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
#focus-back:hover,
#focus-back:focus-visible {
    color: #fff;
    border-color: rgba(120, 255, 170, 0.6);
}
#focus-book-label {
    display: none;
    position: absolute;
    transform: translate(-50%, calc(-100% - 14px));
    padding: 3px 8px;
    border: 1px solid rgba(120, 255, 170, 0.4);
    background: rgba(4, 8, 10, 0.85);
    color: rgba(170, 255, 200, 0.95);
    font-size: 12px;
    white-space: nowrap;
}
#focus-books {
    display: flex;
    position: absolute;
    left: 50%;
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 44px);
    gap: 6px 16px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100vw - 32px);
    transform: translateX(-50%);
    padding: 8px 14px;
    border: 1px solid rgba(120, 255, 170, 0.25);
    background: rgba(4, 8, 10, 0.72);
    font-size: 13px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s, visibility 0.4s;
}
html[data-room-focus='books'] #focus-books {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0.5s;
}
#focus-drink {
    position: absolute;
    left: 50%;
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 44px);
    box-sizing: border-box;
    width: max-content;
    max-width: calc(100vw - 32px);
    margin: 0;
    transform: translateX(-50%);
    padding: 8px 14px;
    border: 1px solid rgba(120, 255, 170, 0.25);
    background: rgba(4, 8, 10, 0.72);
    color: rgba(150, 255, 190, 0.9);
    font-size: 14px;
    line-height: 1.6;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s, visibility 0.4s;
}
/* The second half is said under the breath. */
#focus-drink small {
    font-size: 10px;
    opacity: 0.6;
}
html[data-room-focus='drink'] #focus-drink {
    opacity: 1;
    visibility: visible;
    transition-delay: 0.6s;
}
/* One language at a time, each fading in and out in the same place. */
#focus-drink {
    display: grid;
}
#focus-drink > span {
    grid-area: 1 / 1;
    opacity: 0;
}
html[data-room-focus='drink'] #focus-drink > span {
    animation: drink-line 8s 0.6s infinite both;
}
html[data-room-focus='drink'] #focus-drink > span:nth-child(2) {
    animation-delay: 3.27s;
}
html[data-room-focus='drink'] #focus-drink > span:nth-child(3) {
    animation-delay: 5.93s;
}
@keyframes drink-line {
    0%,
    33.3%,
    100% {
        opacity: 0;
    }
    6%,
    27% {
        opacity: 1;
    }
}
@media (prefers-reduced-motion: reduce) {
    #focus-drink > span {
        grid-area: auto;
        opacity: 1;
        animation: none !important;
    }
}
#focus-books a {
    color: rgba(150, 255, 190, 0.9);
    text-decoration: none;
    cursor: pointer;
}
#focus-books a:hover,
#focus-books a:focus-visible {
    color: #fff;
    text-decoration: underline;
}
html[data-room3d][data-entrance] #monitor-shell,
html[data-room-look] #monitor-shell {
    will-change: transform;
}
/* Walking in: the screen is off, and the DOM would show through the door. */
html[data-entrance-walk] #monitor-shell {
    visibility: hidden;
}
/* While the room loads on a first visit the screen stays dark. */
html[data-room3d='loading'][data-entrance] #monitor-shell {
    visibility: hidden;
}

@media (min-width: 1000px) and (min-height: 600px) {
    html[data-room3d='on'] body:not([data-display-mode='web1']) #room3d {
        display: block;
        opacity: 1;
    }
    /* The model supplies the case, stand and controls; the DOM keeps the screen. */
    html[data-room3d] body:not([data-display-mode='web1']) #monitor-shell {
        background: transparent;
        border-color: transparent;
        box-shadow: none;
    }
    html[data-room3d] body:not([data-display-mode='web1']) #monitor-shell::before,
    html[data-room3d] body:not([data-display-mode='web1']) #monitor-shell::after,
    html[data-room3d] body:not([data-display-mode='web1']) .monitor-face,
    html[data-room3d] body:not([data-display-mode='web1']) .monitor-chin > *,
    html[data-room3d] body:not([data-display-mode='web1']) .monitor-depth {
        visibility: hidden;
    }
    html[data-room3d] #monitor-glass {
        box-shadow: none;
    }
    html[data-room3d='on'] body:not([data-display-mode='web1']) {
        cursor: zoom-out;
    }
    html[data-room3d='on'] #monitor-shell {
        cursor: auto;
    }
    /* The room view: move to look around, a hand over what can be pressed. */
    html[data-room3d='on'][data-room-look] body:not([data-display-mode='web1']) {
        cursor: move;
    }
    html[data-room3d='on'][data-room-look][data-room-focus] body:not([data-display-mode='web1']) {
        cursor: default;
    }
    html[data-room3d='on'][data-room-look][data-room-hover] body:not([data-display-mode='web1']) {
        cursor: pointer;
    }
    html[data-room3d='on'][data-room-look='drag'] body:not([data-display-mode='web1']) {
        cursor: grabbing;
    }
    /* Reading size: leave the room some width beside the monitor. */
    body:not([data-display-mode='web1']) #monitor-rig {
        max-width: 66vw;
    }
}
@media not all and (min-width: 1000px) and (min-height: 600px) {
    /* On a phone the monitor in the room is the page itself. */
    html[data-room3d='on'][data-entrance] #monitor-shell,
    html[data-room-look] #monitor-shell {
        border-color: transparent;
        background: transparent;
    }
}
@media print {
    #room3d,
    #room-focus,
    #room-hint {
        display: none !important;
    }
}
