@font-face {
    font-family: 'Xylver';
    src:
        local('Xylver'),
        local('XYLVER'),
        url('./assets/fonts/xylver.woff2') format('woff2');
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('./assets/fonts/ibm-plex-mono-400-latin.woff2') format('woff2');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('./assets/fonts/ibm-plex-mono-500-latin.woff2') format('woff2');
    font-style: normal;
    font-weight: 500;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('./assets/fonts/ibm-plex-mono-700-latin.woff2') format('woff2');
    font-style: normal;
    font-weight: 700;
    font-display: swap;
}

@font-face {
    font-family: 'JetBrains Mono';
    src: url('./assets/fonts/jetbrains-mono-latin.woff2') format('woff2');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'JetBrains Mono';
    src: url('./assets/fonts/jetbrains-mono-latin.woff2') format('woff2');
    font-style: normal;
    font-weight: 500;
    font-display: swap;
}

@font-face {
    font-family: 'JetBrains Mono';
    src: url('./assets/fonts/jetbrains-mono-latin.woff2') format('woff2');
    font-style: normal;
    font-weight: 700;
    font-display: swap;
}

:root {
    --bg: #000000;
    --bg-soft: #0d0d0d;
    --fg: #ffffff;
    --muted: #bfbfbf;
    --accent: #ffffff;
    --accent-soft: #f2f2f2;
    --good: #ffffff;
    --warn: #ffffff;
    --danger: #ffffff;
    --glow-a: rgba(255, 255, 255, 0.08);
    --glow-b: rgba(255, 255, 255, 0.06);
    --scanline: rgba(255, 255, 255, 0.03);
    --font-xylver: 'Xylver', 'IBM Plex Mono', monospace;
    --font-ibm: 'IBM Plex Mono', monospace;
    --font-jetbrains: 'JetBrains Mono', 'IBM Plex Mono', monospace;
    --font-mono: var(--font-xylver);
}

html[data-font='xylver'] {
    --font-mono: var(--font-xylver);
}

html[data-font='ibm'] {
    --font-mono: var(--font-ibm);
}

html[data-font='jetbrains'] {
    --font-mono: var(--font-jetbrains);
}

html[data-theme='amber'] {
    --bg: #120d00;
    --bg-soft: #1a1200;
    --fg: #ffd38a;
    --muted: #c7a068;
    --accent: #ffbb3c;
    --accent-soft: #ffd38a;
    --good: #ffd38a;
    --warn: #ffd38a;
    --danger: #ffd38a;
    --glow-a: rgba(255, 196, 91, 0.14);
    --glow-b: rgba(255, 166, 0, 0.1);
    --scanline: rgba(255, 205, 128, 0.05);
}

html[data-theme='matrix'] {
    --bg: #010b01;
    --bg-soft: #031403;
    --fg: #9aff9a;
    --muted: #6ec76e;
    --accent: #7eff7e;
    --accent-soft: #c8ffc8;
    --good: #9aff9a;
    --warn: #9aff9a;
    --danger: #9aff9a;
    --glow-a: rgba(0, 255, 106, 0.1);
    --glow-b: rgba(97, 255, 97, 0.08);
    --scanline: rgba(154, 255, 154, 0.035);
}

html[data-theme='ice'] {
    --bg: #071118;
    --bg-soft: #0b1a24;
    --fg: #ddf4ff;
    --muted: #9dc6d8;
    --accent: #9fdfff;
    --accent-soft: #c8eeff;
    --good: #ddf4ff;
    --warn: #ddf4ff;
    --danger: #ddf4ff;
    --glow-a: rgba(130, 212, 255, 0.12);
    --glow-b: rgba(175, 231, 255, 0.08);
    --scanline: rgba(221, 244, 255, 0.035);
}

html[data-theme='evangelion'] {
    --bg: #0d0713;
    --bg-soft: #170c20;
    --fg: #f4e9ff;
    --muted: #bea8d9;
    --accent: #8f4dff;
    --accent-soft: #ff9a3d;
    --good: #b9ff57;
    --warn: #ffb84d;
    --danger: #ff5f86;
    --glow-a: rgba(143, 77, 255, 0.16);
    --glow-b: rgba(185, 255, 87, 0.1);
    --scanline: rgba(255, 154, 61, 0.04);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    font-weight: 600;
    width: 100%;
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: 16px;
    line-height: 1.55;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: repeating-linear-gradient(
        to bottom,
        var(--scanline) 0,
        var(--scanline) 1px,
        transparent 2px,
        transparent 4px
    );
    opacity: 0.35;
    animation: screenDrift 12s linear infinite;
    z-index: 1;
}

#bg-animation-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.42;
    background-color: var(--bg);
    filter: brightness(0.92) contrast(1.12) saturate(0.88);
    animation: bgHueShift 24s linear infinite;
}

.cp-background-frame {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    background: var(--bg);
    transition: opacity 180ms ease;
}

.cp-background-frame.is-active {
    opacity: 0.48;
    visibility: visible;
}

.terminal-container,
#terminal-output,
.output-line,
.output-pre,
.prompt,
#terminal-input {
    text-shadow:
        0 0 5px rgba(255, 255, 255, 0.28),
        0 0 12px rgba(255, 255, 255, 0.2);
    animation: textBloomPulse 2.6s ease-in-out infinite;
}

@keyframes textBloomPulse {
    0%,
    100% {
        text-shadow:
            0 0 5px rgba(255, 255, 255, 0.24),
            0 0 12px rgba(255, 255, 255, 0.18);
    }
    50% {
        text-shadow:
            0 0 9px rgba(255, 255, 255, 0.42),
            0 0 18px rgba(255, 255, 255, 0.3);
    }
}

@media (prefers-reduced-motion: reduce) {
    .terminal-container,
    #terminal-output,
    .output-line,
    .output-pre,
    .prompt,
    #terminal-input {
        animation: none;
    }
}

@keyframes bgHueShift {
    0% {
        filter: brightness(0.9) contrast(1.08) saturate(0.84) hue-rotate(0deg);
    }
    100% {
        filter: brightness(0.9) contrast(1.08) saturate(0.84) hue-rotate(360deg);
    }
}

@keyframes screenDrift {
    0% {
        transform: translateY(0);
    }
    100% {
        transform: translateY(4px);
    }
}

::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-thumb {
    background: #ffffff;
}

.terminal-container {
    position: relative;
    z-index: 2;
    width: min(940px, calc(100% - 360px));
    margin: 0 auto;
    min-height: 100vh;
    padding: 24px 18px 40px;
}

.sigil-side {
    position: fixed;
    top: 24px;
    right: 16px;
    bottom: 24px;
    width: clamp(210px, 21vw, 300px);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    overflow: hidden;
    background: linear-gradient(to left, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0));
}

.sigil-preview {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sigil-preview-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 5;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.sigil-preview-placeholder {
    display: none;
}

.sigil-preview-media,
.sigil-preview-base,
.sigil-preview-overlay {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sigil-preview-media {
    position: absolute;
    inset: 0;
    opacity: 0;
}

.sigil-preview-media.is-visible {
    opacity: 1;
}

.sigil-preview-pair {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
}

.sigil-preview-item {
    display: block;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.28);
    overflow: hidden;
    cursor: zoom-in;
}

.sigil-preview-item:focus-visible {
    outline: 1px solid rgba(255, 255, 255, 0.45);
    outline-offset: 2px;
}

.sigil-preview-video {
    object-fit: cover;
}

body.is-media-viewer-open {
    overflow: hidden;
}

.sigil-media-viewer {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background: rgba(0, 0, 0, 0.84);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
}

.sigil-media-viewer.is-open {
    opacity: 1;
    pointer-events: auto;
}

.sigil-media-viewer-stage {
    width: min(92vw, 1400px);
    max-height: 92vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sigil-media-viewer-media {
    display: block;
    max-width: 100%;
    max-height: 92vh;
    width: auto;
    height: auto;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    background: rgba(4, 4, 4, 0.9);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.7);
}

.sigil-media-viewer-media.is-video {
    width: min(92vw, 1400px);
    height: auto;
}

.sigil-media-viewer-close {
    position: absolute;
    top: 18px;
    right: 18px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 999px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.6);
    color: #ffffff;
    font-family: var(--font-mono);
    font-size: 13px;
    cursor: pointer;
}

.sigil-media-viewer-close:hover,
.sigil-media-viewer-close:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    outline: none;
}

.sigil-preview-label {
    display: none;
}

.sigil-side-grid {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    pointer-events: auto;
}

.sigil-part {
    appearance: none;
    display: block;
    width: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
    transition:
        background-color 160ms ease,
        border-color 160ms ease,
        transform 160ms ease,
        box-shadow 160ms ease;
}

.sigil-part:hover,
.sigil-part:focus-visible,
.sigil-part.is-active {
    background: rgba(255, 255, 255, 0.03);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    transform: none;
    outline: none;
}

.sigil-part:disabled,
.sigil-part.is-locked {
    cursor: not-allowed;
    opacity: 0.45;
}

.sigil-part-pre {
    margin: 0;
    width: 100%;
    color: rgba(255, 255, 255, 0.94);
    font-family: var(--font-mono);
    font-size: clamp(4.4px, min(0.62vw, 0.95vh), 11px);
    font-weight: 700;
    line-height: 0.96;
    white-space: pre;
    overflow: hidden;
    max-height: 100%;
    max-width: 100%;
    transform-origin: center center;
    text-rendering: geometricPrecision;
    text-shadow:
        0 0 4px rgba(255, 255, 255, 0.55),
        0 0 10px rgba(255, 255, 255, 0.38),
        0 0 18px rgba(255, 255, 255, 0.22);
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.22));
}

.sigil-part[data-sigil-part='part-1'] .sigil-part-pre {
    transform: translateX(3.1ch);
}

.sigil-waveform {
    margin: 0;
    width: 100%;
    color: var(--accent-soft);
    font-family: var(--font-mono);
    font-size: clamp(8px, 0.75vw, 11px);
    line-height: 1.1;
    white-space: pre;
    text-align: center;
    letter-spacing: 0.08em;
    overflow: hidden;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.sigil-waveform.is-active {
    opacity: 1;
    transform: translateY(0);
}

.sigil-waveform.is-active {
    animation: waveformFlicker 900ms steps(2, end) infinite;
}

@keyframes waveformFlicker {
    0%,
    100% {
        opacity: 1;
        text-shadow: 0 0 0 rgba(0, 0, 0, 0);
    }
    50% {
        opacity: 0.72;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.12);
    }
}

#terminal-output {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: clamp(72px, 11vh, 120px);
}

.output-block {
    word-break: break-word;
    overflow-wrap: anywhere;
}

.design-image {
    display: block;
    width: min(100%, 760px);
    height: auto;
    margin: 18px auto 0;
    border: 1px solid rgba(255, 255, 255, 0.42);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    cursor: default;
}

.output-line {
    display: block;
    margin-bottom: 2px;
    line-height: 1.42;
    overflow-wrap: anywhere;
}

.terminal-input-line {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    z-index: 3;
    padding: 10px 0 calc(12px + env(safe-area-inset-bottom, 0px));
}

.prompt {
    margin-right: 8px;
    white-space: nowrap;
    font-weight: 500;
}

.prompt-user,
.prompt-host {
    color: var(--good);
}

.prompt-at,
.prompt-colon,
.prompt-char {
    color: var(--fg);
}

.prompt-path {
    color: var(--accent-soft);
}

#terminal-input {
    flex: 0 1 auto;
    width: 1ch;
    min-width: 1ch;
    background: transparent;
    border: none;
    outline: none;
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    caret-color: transparent;
}

.cursor {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 0.68ch;
    margin-left: 0;
    background: var(--fg);
    opacity: 0.92;
    pointer-events: none;
    mix-blend-mode: normal;
}

.cursor.is-hidden {
    opacity: 0;
}

@keyframes blink {
    0%,
    49% {
        opacity: 1;
    }
    50%,
    100% {
        opacity: 0;
    }
}

.hidden-width-helper {
    position: absolute;
    visibility: hidden;
    white-space: pre;
    font: inherit;
    inset: auto;
    pointer-events: none;
}

.text-green {
    color: var(--good);
}

.text-cyan {
    color: #f0f0f0;
}

.text-pink {
    color: #f0f0f0;
}

.text-orange {
    color: var(--accent);
}

.text-purple {
    color: #f0f0f0;
}

.text-yellow {
    color: var(--warn);
}

.text-comment {
    color: var(--muted);
}

.text-red {
    color: var(--danger);
}

.output-pre {
    margin: 6px 0;
    color: var(--fg);
    white-space: pre;
    overflow-x: auto;
    max-width: 100%;
    font-family: var(--font-mono);
    font-size: clamp(10px, 1.6vw, 15px);
    line-height: 1.14;
    tab-size: 4;
    text-rendering: geometricPrecision;
}

.output-block a,
a.terminal-link {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.scramble-text {
    cursor: pointer;
}

.scramble-text.is-scrambling {
    text-shadow:
        0 0 7px rgba(255, 255, 255, 0.34),
        0 0 16px rgba(255, 255, 255, 0.24);
}

.ascii-banner {
    color: var(--accent-soft);
    font-weight: 500;
}

.ascii-scroll-wrap {
    width: 100%;
    overflow: hidden;
}

.ascii-scroll-lane {
    display: flex;
    width: max-content;
    will-change: transform;
    animation: asciiLoop 8s linear infinite;
}

.ascii-scroll-track {
    flex: 0 0 auto;
    margin: 0;
    max-width: none;
    overflow: visible;
}

@keyframes asciiLoop {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-50%);
    }
}

.ascii-image {
    color: #f0f0f0;
}

a.terminal-link {
    color: #ffffff;
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
}

a.terminal-link:hover {
    color: #d9d9d9;
}

html[data-theme='evangelion'] .sigil-side {
    background: linear-gradient(to left, rgba(143, 77, 255, 0.08), rgba(255, 95, 134, 0));
}

html[data-theme='evangelion'] .sigil-preview-frame {
    border: 0;
    box-shadow: none;
}

html[data-theme='evangelion'] .sigil-part-pre {
    text-shadow:
        0 0 4px rgba(255, 154, 61, 0.62),
        0 0 10px rgba(143, 77, 255, 0.42),
        0 0 18px rgba(185, 255, 87, 0.2);
    filter: drop-shadow(0 0 10px rgba(255, 95, 134, 0.18));
}

html[data-theme='evangelion'] .sigil-part:hover,
html[data-theme='evangelion'] .sigil-part:focus-visible,
html[data-theme='evangelion'] .sigil-part.is-active {
    background: rgba(255, 154, 61, 0.05);
    box-shadow: inset 0 0 0 1px rgba(255, 95, 134, 0.2);
}

html[data-theme='evangelion'] .cursor {
    background: var(--accent-soft);
}

html[data-theme='evangelion'] a.terminal-link {
    color: var(--accent-soft);
}

html[data-theme='evangelion'] a.terminal-link:hover {
    color: var(--good);
}

.game-overlay,
.game-over-screen,
#reactive-bg {
    display: none !important;
}

@media (max-width: 1400px) {
    .terminal-container {
        width: min(980px, calc(100% - 24px));
        padding: 20px 12px 34px;
    }

    .sigil-side {
        display: none;
    }

    .sigil-part-pre {
        font-size: clamp(4.8px, min(0.62vw, 0.9vh), 9.4px);
    }

    .sigil-waveform {
        font-size: 9px;
    }

    .output-pre {
        font-size: clamp(10px, 1.8vw, 14px);
        line-height: 1.2;
    }
}

@media (max-width: 900px) {
    .terminal-container {
        width: calc(100% - 18px);
        padding: 18px 10px 32px;
    }

    .sigil-side {
        display: none;
    }

    .terminal-input-line {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 6px;
        padding: 8px 0 12px;
    }

    .prompt {
        flex: 0 0 100%;
        margin-right: 0;
        white-space: normal;
        line-height: 1.35;
    }

    #terminal-input {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
    }

    .output-pre {
        font-size: clamp(10px, 2.4vw, 14px);
    }
}

@media (max-width: 720px) {
    html,
    body {
        font-size: 15px;
    }

    .terminal-container {
        width: calc(100% - 20px);
        padding: 16px 10px 28px;
    }

    .terminal-input-line {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 6px;
        padding: 8px 0 12px;
    }

    .prompt {
        flex: 0 0 100%;
        margin-right: 0;
        white-space: normal;
        line-height: 1.35;
    }

    #terminal-input {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
    }

    .cursor {
        flex: 0 0 auto;
    }

    .output-pre {
        font-size: clamp(10px, 2.8vw, 14px);
        line-height: 1.24;
    }

    .ascii-scroll-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .ascii-scroll-lane {
        width: 100%;
        animation: none;
    }

    .ascii-scroll-track {
        min-width: max-content;
    }

    .design-image {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .terminal-container {
        width: calc(100% - 16px);
        padding: 14px 8px 24px;
    }

    body::before {
        opacity: 0.25;
    }

    #bg-animation-canvas {
        opacity: 0.24;
    }

    .output-pre {
        font-size: clamp(10px, 3.2vw, 13px);
        line-height: 1.28;
    }
}
