:root {
    --animated-background-colour: #0222b9;
    --active-poem-font-size: 16px;
    --active-poem-line-height: 21.6px;
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #ffffff;
}

canvas {
    display: block;
}

.poem-layer {
    position: fixed;
    z-index: 10;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 48px;
    pointer-events: none;
}

.electronics-layer {
    --components-background-colour: var(--animated-background-colour);
    --electronics-neon-secondary: rgba(199, 179, 215, 0.42);
    --electronics-glow-small: 4px;
    --electronics-glow-medium: 10px;
    --electronics-glow-large: 16px;
    position: fixed;
    z-index: 8;
    inset: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1200ms ease;
}

body:not(.is-idle) .electronics-layer {
    opacity: 1;
}

.electronic-component {
    position: absolute;
    width: var(--component-size);
    height: var(--component-size);
    background: var(--components-background-colour);
    -webkit-mask: var(--component-mask) center / contain no-repeat;
    mask: var(--component-mask) center / contain no-repeat;
    opacity: 0.72;
    will-change: transform, opacity, filter;
    animation:
        electronic-component-float var(--float-duration) ease-in-out infinite alternate,
        electronic-component-pulse var(--pulse-duration) ease-in-out infinite;
    animation-delay: var(--float-delay), var(--pulse-delay);
}

.electronics-layer--neon .electronic-component {
    opacity: 0.94;
    filter:
        drop-shadow(0 0 var(--electronics-glow-small) var(--components-background-colour))
        drop-shadow(0 0 var(--electronics-glow-medium) var(--components-background-colour))
        drop-shadow(0 0 var(--electronics-glow-large) var(--electronics-neon-secondary));
}

.electronic-component[data-component="transistor"] {
    --component-mask: url('/assets/v2/electric-components/TRANSISTOR.svg');
}

.electronic-component[data-component="switch"] {
    --component-mask: url('/assets/v2/electric-components/SWITCH.svg');
}

.electronic-component[data-component="dc-voltage"] {
    --component-mask: url('/assets/v2/electric-components/DC_VOLTAGE.svg');
}

.electronic-component[data-component="diode"] {
    --component-mask: url('/assets/v2/electric-components/DIODE.svg');
}

.electronic-component[data-component="inductor"] {
    --component-mask: url('/assets/v2/electric-components/INDUCTOR.svg');
}

.electronic-component[data-component="resistor"] {
    --component-mask: url('/assets/v2/electric-components/RESISTOR.svg');
}

.electronic-component[data-component="ac-voltage"] {
    --component-mask: url('/assets/v2/electric-components/AC_VOLTAGE.svg');
}

@keyframes electronic-component-float {
    0% {
        transform: translate3d(0, 0, 0) rotate(var(--rotation-start));
    }
    48% {
        transform: translate3d(var(--float-x), var(--float-y), 0) rotate(var(--rotation-mid));
    }
    100% {
        transform: translate3d(var(--float-x-end), var(--float-y-end), 0) rotate(var(--rotation-end));
    }
}

@keyframes electronic-component-pulse {
    0%, 100% { opacity: 0.72; }
    50% { opacity: 1; }
}

.poem {
    --poem-neon-primary: rgba(124, 87, 164, 0.9);
    --poem-neon-secondary: rgba(244, 154, 193, 0.55);
    --poem-glow-small: 5px;
    --poem-glow-medium: 13px;
    --poem-glow-large: 27px;
    width: max-content;
    max-width: 100%;
    margin: 0;
    overflow: hidden;
    color: #111827;
    font-family: "JetBrains Mono", monospace;
    font-size: 16px;
    font-weight: 400;
    line-height: var(--active-poem-line-height);
    tab-size: 4;
    white-space: pre;
    contain: layout paint style;
    transform: translateZ(0);
}

.poem--neon {
    color: rgba(255, 255, 255, 0.98);
    -webkit-text-stroke: 0.25px rgba(17, 24, 39, 0.7);
    text-shadow:
        0 0 1px rgba(17, 24, 39, 0.9),
        0 0 var(--poem-glow-small) var(--poem-neon-primary),
        0 0 var(--poem-glow-medium) var(--poem-neon-primary),
        0 0 var(--poem-glow-large) var(--poem-neon-secondary);
}

.poem-cursor {
    display: inline-block;
    animation: poem-cursor-blink 900ms steps(1, end) infinite;
}

.installation-logo {
    position: fixed;
    z-index: 12;
    left: 15px;
    bottom: 15px;
    height: 75px;
    opacity: 0;
    pointer-events: none;
    transform-origin: left bottom;
    will-change: opacity, transform;
}

.installation-logo__mark {
    display: block;
    width: 170.4px;
    height: 75px;
    background: var(--animated-background-colour);
    -webkit-mask: url('/assets/v2/logo-meltdown.svg') center / contain no-repeat;
    mask: url('/assets/v2/logo-meltdown.svg') center / contain no-repeat;
    transform-origin: left bottom;
    will-change: transform;
}

body.is-idle .controls,
body.is-idle .installation-logo {
    display: none;
}

body.is-idle .poem {
    width: auto;
    height: auto !important;
    color: #ffffff;
    -webkit-text-stroke: 0;
    text-shadow: none;
}

body.is-idle #poem-text {
    display: none;
}

body.is-idle .poem-cursor {
    color: #ffffff;
    font-size: 3rem;
    line-height: 1;
    transform-origin: left top;
}

@keyframes poem-cursor-blink {
    50% {
        opacity: 0;
    }
}

button,
input,
select {
    font: inherit;
}

.controls {
    --machine-green: #a5ff8a;
    --machine-pink: #ff57bb;
    position: fixed;
    z-index: 50;
    top: 14px;
    right: 14px;
    width: min(410px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
    overflow-y: auto;
    border: 1px solid var(--machine-green);
    border-radius: 0;
    color: var(--machine-green);
    background:
        linear-gradient(115deg, rgba(255, 87, 187, 0.08), transparent 31%),
        #030807;
    box-shadow:
        -5px 0 0 rgba(255, 87, 187, 0.68),
        5px 5px 0 rgba(0, 238, 255, 0.28),
        0 22px 70px rgba(0, 0, 0, 0.48),
        inset 0 0 28px rgba(165, 255, 138, 0.06);
    isolation: isolate;
    overscroll-behavior: contain;
    animation: machine-panel-enter 180ms steps(3, end);
    scrollbar-color: var(--machine-green) #07100d;
}

.controls[hidden] {
    display: none;
}

.controls::before {
    position: absolute;
    z-index: 4;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0,
        transparent 3px,
        rgba(165, 255, 138, 0.035) 4px
    );
    content: '';
    pointer-events: none;
}

.controls__header {
    position: sticky;
    z-index: 1;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 15px 17px;
    border-bottom: 1px dashed rgba(165, 255, 138, 0.5);
    background: rgba(2, 12, 8, 0.96);
}

.controls__header h1 {
    margin: 0;
    font-family: "JetBrains Mono", monospace;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.14em;
    text-shadow: 2px 0 var(--machine-pink), -1px 0 #00eeff;
    animation: machine-title-glitch 2.8s steps(1, end) infinite;
}

.phase {
    margin: 4px 0 0;
    color: rgba(165, 255, 138, 0.62);
    font-family: "JetBrains Mono", monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
}

.live-status {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.icon-button {
    width: 34px;
    height: 34px;
    border: 1px solid var(--machine-pink);
    border-radius: 0;
    color: var(--machine-green);
    background: transparent;
    cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
    color: #030807;
    background: var(--machine-green);
    outline: 1px dashed var(--machine-pink);
    outline-offset: 2px;
}

.controls__body {
    position: relative;
    z-index: 5;
    padding: 0 17px 17px;
    font-family: "JetBrains Mono", monospace;
}

fieldset {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 0;
    padding: 16px 0;
    border: 0;
    border-bottom: 1px dashed rgba(165, 255, 138, 0.3);
}

legend {
    grid-column: 1 / -1;
    padding: 16px 0 0;
    color: var(--machine-pink);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.16em;
}

.field {
    min-width: 0;
}

.field--wide {
    grid-column: 1 / -1;
}

.field label,
.field__label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    color: rgba(210, 255, 201, 0.82);
    font-size: 10px;
    letter-spacing: 0.04em;
}

.field output {
    color: #00eeff;
    font-variant-numeric: tabular-nums;
    text-shadow: 1px 0 var(--machine-pink);
}

input[type="range"],
select,
input[type="number"],
input[type="text"] {
    width: 100%;
}

select,
input[type="number"],
input[type="text"] {
    min-height: 36px;
    padding: 6px 8px;
    border: 1px solid rgba(165, 255, 138, 0.58);
    border-radius: 0;
    color: var(--machine-green);
    background: #07100d;
    outline: none;
}

input[type="range"] {
    accent-color: var(--machine-pink);
    filter: saturate(1.4) contrast(1.2);
}

input[type="checkbox"] {
    accent-color: var(--machine-green);
}

select:focus,
input[type="number"]:focus,
input[type="text"]:focus {
    border-color: #00eeff;
    box-shadow: 2px 2px 0 var(--machine-pink);
}

.hash-error {
    display: block;
    min-height: 16px;
    margin-top: 5px;
    color: #ff6a9f;
    font-size: 11px;
}

select[data-palette-select] {
    border-left-width: 12px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    color: rgba(210, 255, 201, 0.82);
    font-size: 10px;
}

.actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding-top: 16px;
}

.actions button {
    min-height: 38px;
    padding: 8px;
    border: 1px solid rgba(165, 255, 138, 0.55);
    border-radius: 0;
    color: var(--machine-green);
    background: #07100d;
    cursor: pointer;
    transition: color 100ms steps(2, end), background 100ms steps(2, end), transform 100ms steps(2, end);
}

.actions button:hover,
.actions button:focus-visible {
    border-color: var(--machine-pink);
    color: #030807;
    background: var(--machine-green);
    outline: none;
    transform: translate(2px, -2px);
    box-shadow: -3px 3px 0 var(--machine-pink);
}

@keyframes machine-panel-enter {
    0% { opacity: 0; transform: translate(12px, -8px) skewX(2deg); }
    45% { opacity: 0.75; transform: translate(-7px, 3px) skewX(-1deg); }
    100% { opacity: 1; transform: none; }
}

@keyframes machine-panel-drift {
    0%, 91%, 100% { translate: 0 0; }
    92% { translate: -2px 1px; }
    94% { translate: 3px -1px; }
    96% { translate: 0 0; }
}

@keyframes machine-title-glitch {
    0%, 86%, 100% { transform: none; filter: none; }
    87% { transform: translateX(2px); filter: hue-rotate(35deg); }
    89% { transform: translateX(-3px); }
    91% { transform: none; }
}

.site-menu {
    --site-menu-background-colour: var(--animated-background-colour);
    position: fixed;
    z-index: 40;
    left: 50%;
    bottom: 18px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: clamp(6px, 1.2vw, 14px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-50%, 20px);
    transition:
        opacity 500ms ease,
        transform 650ms cubic-bezier(.22, 1, .36, 1),
        visibility 0s linear 650ms;
}

body.poem-is-live .site-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate(-50%, 0);
    transition-delay: 0s;
}

/* Avoid compositing animated installation layers below a scrolling modal. */
body.terminal-is-open canvas,
body.terminal-is-open .poem-layer,
body.terminal-is-open .electronics-layer,
body.terminal-is-open .installation-logo {
    visibility: hidden;
}

.site-menu__item {
    --item-index: 0;
    position: relative;
    display: grid;
    width: clamp(48px, 6vw, 66px);
    height: clamp(48px, 6vw, 66px);
    place-items: center;
    padding: 10px;
    border: 2px solid #ffffff;
    border-radius: 0;
    color: #ffffff;
    background: var(--site-menu-background-colour);
    box-shadow: none;
    cursor: pointer;
    animation: site-menu-float 3.4s ease-in-out infinite;
    animation-delay: calc(var(--item-index) * -0.42s);
    transition: border-color 180ms ease, box-shadow 180ms ease;
}

.site-menu__item:hover,
.site-menu__item:focus-visible,
.site-menu__item.is-active {
    border-color: #ffffff;
    background: var(--site-menu-background-colour);
    box-shadow: 4px 4px 0 #ffffff;
    outline: none;
}

.site-menu__item img {
    display: block;
    width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: brightness(0) invert(1);
    transform: scale(1);
    will-change: transform;
    transition: transform 520ms cubic-bezier(.22, 1, .36, 1);
}

.site-menu__item:hover img {
    transform: scale(1.22);
}

.site-menu__label {
    position: absolute;
    bottom: calc(100% + 9px);
    left: 50%;
    padding: 4px 7px;
    border-radius: 4px;
    color: #ffffff;
    background: #111827;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px;
    line-height: 1;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 4px);
    transition: opacity 160ms ease, transform 160ms ease;
}

.site-menu__item:hover .site-menu__label,
.site-menu__item:focus-visible .site-menu__label,
.site-menu__item.is-active .site-menu__label {
    opacity: 1;
    transform: translate(-50%, 0);
}

.terminal-layer {
    position: fixed;
    z-index: 35;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 0;
    background: var(--animated-background-colour);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 220ms ease, visibility 0s linear 220ms;
}

.terminal-layer.is-open,
.terminal-layer.is-closing {
    visibility: visible;
    transition-delay: 0s;
}

.terminal-layer.is-open {
    opacity: 1;
    pointer-events: auto;
}

.terminal-window {
    --terminal-header-height: 54px;
    --terminal-font-size: clamp(12px, 0.95vw, 15px);
    --terminal-line-height: 1.55;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    color: #ffffff;
    background: var(--animated-background-colour);
    box-shadow: none;
    isolation: isolate;
    font-family: "JetBrains Mono", monospace;
    -webkit-font-smoothing: antialiased;
    transform: translateY(20px) scale(0.985);
    transition: transform 240ms cubic-bezier(.22, 1, .36, 1);
}

.terminal-layer.is-open .terminal-window {
    transform: none;
}

.terminal-layer.is-closing .terminal-window {
    transform: translateY(14px) scale(0.99);
}

.terminal-window__bar {
    flex: 0 0 var(--terminal-header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--terminal-header-height);
    padding: 6px 28px;
    border: 0;
    color: #0222b9;
    background: transparent;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

.terminal-window__lights {
    display: none;
}

.terminal-window__light {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #f3723c;
}

.terminal-window__light:nth-child(2) { background: #f49ac1; }
.terminal-window__light:nth-child(3) { background: #a5d171; }

.terminal-window__title {
    flex: 0 0 auto;
    padding: 0;
    background: transparent;
}

.terminal-window__logo {
    display: block;
    width: 86px;
    height: 38px;
    background: #ffffff;
    -webkit-mask: url('/assets/v2/logo-meltdown.svg') center / contain no-repeat;
    mask: url('/assets/v2/logo-meltdown.svg') center / contain no-repeat;
}

.terminal-window__close {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.terminal-window__viewport {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    max-height: none;
    margin: 0;
    padding: 6px clamp(28px, 5vw, 58px) 30px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    color: #ffffff;
    background: var(--animated-background-colour);
    font-family: inherit;
    font-size: var(--terminal-font-size);
    font-weight: 400;
    line-height: var(--terminal-line-height);
    tab-size: 4;
    white-space: normal;
    text-shadow: none;
    scrollbar-color: #ffffff #b8b8b8;
    scrollbar-gutter: stable;
    scrollbar-width: auto;
}

.terminal-window__content {
    min-height: 100%;
    margin: 0;
    overflow: visible;
    color: inherit;
    background: transparent;
    font: inherit;
    white-space: normal;
}

.terminal-window__content[hidden] {
    display: none;
}

.terminal-content__title {
    margin: 0 0 1.25rem;
    font: inherit;
    font-size: clamp(1.15rem, 1.6vw, 1.7rem);
    font-weight: 700;
    line-height: 1.1;
}

.terminal-content__body {
    width: min(100%, 76rem);
}

.terminal-content__body p {
    margin: 0 0 1.5em;
}

.terminal-content__body h3 {
    margin: 2.5em 0 1em;
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.terminal-content__artists {
    display: grid;
    gap: clamp(2.5rem, 6vw, 5rem);
}

.terminal-content__about {
    width: min(100%, 76rem);
}

.terminal-content__about > p {
    margin: 0 0 2em;
}

.about-lead {
    max-width: 62rem;
    font-size: inherit;
    line-height: inherit;
}

.about-motifs {
    display: grid;
    gap: 0.35rem;
    margin: clamp(2.5rem, 6vw, 5rem) 0;
}

.about-motifs p {
    margin: 0;
}

.terminal-window__content--poems {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.terminal-window__content--poems[hidden] {
    display: none;
}

.poems-infinite-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-color: #ffffff #b8b8b8;
    scrollbar-gutter: stable;
}

.poems-infinite-scroll:focus-visible {
    outline: 1px solid currentColor;
    outline-offset: 6px;
}

.poems-sequence {
    display: grid;
    gap: clamp(4rem, 10vw, 8rem);
    padding-bottom: clamp(4rem, 10vw, 8rem);
}

.poem-entry {
    width: min(100%, 68rem);
}

.poem-entry h3 {
    margin: 0 0 1.5rem;
    font: inherit;
    font-weight: 700;
}

.poem-entry pre {
    margin: 0;
    overflow: visible;
    font: inherit;
    white-space: pre-wrap;
}

.terminal-content__artist h3 {
    margin-top: 0;
}

.terminal-content__artist p {
    max-width: 72rem;
    margin-bottom: 0;
}

.artist-credits {
    width: min(100%, 68rem);
    margin-top: clamp(4rem, 10vw, 8rem);
}

.production-credits {
    display: grid;
    gap: 0.85rem;
    margin: 0;
}

.production-credits__row {
    display: grid;
    grid-template-columns: minmax(9rem, 0.3fr) minmax(0, 1fr);
    gap: 0.5rem 1.5rem;
}

.production-credits dt {
    font-weight: 700;
}

.production-credits dd {
    margin: 0;
}

.terminal-content__exhibition {
    width: min(100%, 68rem);
}

.exhibition-statement {
    width: min(100%, 76rem);
}

.exhibition-statement p {
    margin: 0 0 1.65em;
}

.exhibition-credits,
.exhibition-practical {
    width: min(100%, 68rem);
    margin-top: clamp(4rem, 10vw, 8rem);
}

.exhibition-details {
    display: grid;
    gap: 0.85rem;
    margin: 0;
}

.exhibition-details__row {
    display: grid;
    grid-template-columns: minmax(9rem, 0.3fr) minmax(0, 1fr);
    gap: 0.5rem 1.5rem;
}

.exhibition-details dt {
    font-weight: 700;
}

.exhibition-details dd {
    margin: 0;
}

.exhibition-hours h3 {
    margin-bottom: 0.75rem;
}

.exhibition-hours ul {
    display: grid;
    gap: 0.55rem;
    margin: 0;
    padding-left: 1.4em;
}

@media (max-width: 640px) {
    .exhibition-details__row,
    .production-credits__row {
        grid-template-columns: 1fr;
    }
}

.terminal-content__prompt {
    margin: 2.5rem 0 0;
}

.terminal-window__viewport::-webkit-scrollbar {
    width: 56px;
}

.terminal-window__viewport::-webkit-scrollbar-track {
    border-left: 3px solid #ffffff;
    background: repeating-linear-gradient(
        45deg,
        #b8b8b8 0,
        #b8b8b8 10px,
        #ffffff 10px,
        #ffffff 20px
    );
}

.terminal-window__viewport::-webkit-scrollbar-thumb {
    min-height: 110px;
    border: 6px solid #ffffff;
    border-radius: 0;
    background: #0222b9;
    box-shadow: inset 0 0 0 3px #b8b8b8;
}

.terminal-window__viewport::-webkit-scrollbar-thumb:hover {
    border-color: #0222b9;
    background: #ffffff;
    box-shadow: inset 0 0 0 3px #0222b9;
}

.terminal-window__viewport::-webkit-scrollbar-button {
    display: block;
    height: 54px;
    border-left: 3px solid #ffffff;
    background: #ffffff;
}

@keyframes site-menu-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@media (max-width: 520px) {
    .poem-layer {
        padding: 24px;
    }

    .controls {
        top: 8px;
        right: 8px;
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
    }

    fieldset {
        grid-template-columns: 1fr;
    }

    .field--wide,
    legend {
        grid-column: 1;
    }

    .site-menu {
        bottom: 12px;
        gap: 6px;
    }

    .site-menu__item {
        width: 50px;
        height: 50px;
        padding: 9px;
    }

    .terminal-layer {
        padding: 0;
    }

    .terminal-window {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
    }

    .terminal-window__viewport {
        min-height: 0;
        height: auto;
        max-height: none;
        padding: 4px 18px 24px;
    }

    .terminal-window__viewport::-webkit-scrollbar {
        width: 38px;
    }

    .terminal-window__viewport::-webkit-scrollbar-button {
        height: 38px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .site-menu,
    .site-menu__item,
    .electronic-component,
    .terminal-window,
    .terminal-layer {
        animation: none;
        transition-duration: 1ms;
    }
}
