@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;700&display=swap');

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

:root {
    --fg: #e0e0e0;
    --fg-dim: #808080;
    --fg-bright: #ffffff;
    --green: #4af626;
    --amber: #ffb000;
    --cyan: #00d4ff;
    --red: #ff4444;
    --bg: #0a0a0a;
    --glow: rgba(74, 246, 38, 0.08);
    --phosphor: rgba(74, 246, 38, 0.5);
    --phosphor-strong: rgba(74, 246, 38, 0.95);
}

body.theme-amber {
    --fg: #ffd78a;
    --fg-dim: #9a7b3d;
    --fg-bright: #fff4d4;
    --green: #ffb000;
    --amber: #ffd77a;
    --phosphor: rgba(255, 176, 0, 0.55);
    --phosphor-strong: rgba(255, 176, 0, 0.95);
}

body.theme-ibm {
    --fg: #8fc8d4;
    --fg-dim: #507880;
    --fg-bright: #d4ebf0;
    --green: #22d3ee;
    --amber: #fbbf24;
    --phosphor: rgba(34, 211, 238, 0.55);
    --phosphor-strong: rgba(34, 211, 238, 0.9);
}

html, body {
    height: 100%;
    overflow: hidden;
    background: #000;
    color: var(--fg);
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    font-size: 15px;
    line-height: 1.5;
}

body {
    padding: 14px;
}

#power-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
    transition: opacity 0.45s ease-out;
    user-select: none;
    outline: none;
}

#power-overlay.off {
    opacity: 0;
    pointer-events: none;
}

#power-button {
    width: 110px;
    height: 110px;
    color: var(--fg-dim);
    transition: color 0.25s, filter 0.25s, transform 0.15s;
}

#power-overlay:hover #power-button,
#power-overlay:focus-visible #power-button {
    color: var(--green);
    filter: drop-shadow(0 0 24px rgba(74, 246, 38, 0.55));
    transform: scale(1.03);
}

#power-overlay:active #power-button {
    transform: scale(0.94);
}

#power-overlay.pressed #power-button {
    color: var(--green);
    filter: drop-shadow(0 0 42px rgba(74, 246, 38, 0.95));
    transform: scale(0.9);
    transition: color 0.25s, filter 0.3s ease-out, transform 0.3s ease-out;
}

#power-hint {
    margin-top: 28px;
    color: var(--fg-dim);
    font-size: 12px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    animation: hint-blink 2.5s infinite;
}

#power-overlay.pressed #power-hint {
    animation: none;
    opacity: 0;
    transition: opacity 0.15s;
}

@keyframes hint-blink {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 0.85; }
}

#crt {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 24px;
    background: var(--bg);
    box-shadow:
        inset 0 0 90px rgba(0, 0, 0, 0.7),
        inset 0 0 30px rgba(74, 246, 38, 0.04),
        0 0 40px rgba(74, 246, 38, 0.08);
    animation: crt-flicker 6s infinite;
}

#crt::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: inherit;
    background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
    z-index: 11;
}

#crt.warming-up::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 2px;
    background: #fff;
    box-shadow: 0 0 20px 2px rgba(255, 255, 255, 0.85);
    transform-origin: center center;
    z-index: 20;
    animation: crt-warmup 0.55s ease-out forwards;
}

@keyframes crt-warmup {
    0% {
        transform: scale(0.02, 0.2);
        opacity: 1;
        filter: brightness(3);
    }
    35% {
        transform: scale(1, 0.04);
        opacity: 1;
    }
    80% {
        transform: scale(1, 1);
        opacity: 0.5;
        filter: brightness(2);
    }
    100% {
        transform: scale(1, 1);
        opacity: 0;
        filter: brightness(1);
    }
}

@keyframes crt-flicker {
    0%, 100% { opacity: 1; }
    97.5% { opacity: 1; }
    98% { opacity: 0.94; }
    98.3% { opacity: 1; }
    99% { opacity: 0.97; }
    99.4% { opacity: 1; }
}

#terminal #output,
#terminal #input-line {
    visibility: hidden;
}

#terminal.powered-on #output,
#terminal.powered-on #input-line {
    visibility: visible;
}

#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 3px
    );
    animation: scanline-drift 7s linear infinite;
}

@keyframes scanline-drift {
    from { background-position: 0 0; }
    to { background-position: 0 3px; }
}

#noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9;
    opacity: 0.04;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    animation: noise-shift 0.35s steps(3) infinite;
}

@keyframes noise-shift {
    0% { transform: translate(0, 0); }
    33% { transform: translate(-4px, 2px); }
    66% { transform: translate(3px, -2px); }
    100% { transform: translate(0, 0); }
}

.burn-in {
    animation: burn-in 0.45s ease-out;
}

@keyframes burn-in {
    0% { filter: brightness(1.8); text-shadow: 0 0 14px var(--phosphor-strong), 0 0 3px currentColor; }
    100% { filter: brightness(1); }
}

#crt.powering-off::before {
    content: '';
    position: absolute;
    inset: 0;
    background: #000;
    z-index: 30;
    pointer-events: none;
    animation: crt-poweroff 0.6s ease-in forwards;
    border-radius: inherit;
}

@keyframes crt-poweroff {
    0%   { clip-path: inset(0 0 0 0); }
    40%  { clip-path: inset(48% 0 48% 0); background: #000; }
    70%  { clip-path: inset(49.5% 48% 49.5% 48%); background: #fff; }
    100% { clip-path: inset(50% 50% 50% 50%); background: #fff; }
}

#crt.off-final {
    background: #000 !important;
}
#crt.off-final #terminal,
#crt.off-final #scanlines,
#crt.off-final #noise { visibility: hidden; }

#terminal {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#output {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--fg-dim) transparent;
}

#output::-webkit-scrollbar {
    width: 6px;
}

#output::-webkit-scrollbar-thumb {
    background: var(--fg-dim);
    border-radius: 3px;
}

#output .line {
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 1.5em;
}

#output .line.green { color: var(--green); text-shadow: 0 0 8px rgba(74, 246, 38, 0.5), 0 0 2px currentColor; }
#output .line.amber { color: var(--amber); text-shadow: 0 0 7px rgba(255, 176, 0, 0.45), 0 0 2px currentColor; }
#output .line.cyan { color: var(--cyan); text-shadow: 0 0 7px rgba(0, 212, 255, 0.4), 0 0 2px currentColor; }
#output .line.red { color: var(--red); text-shadow: 0 0 6px rgba(255, 68, 68, 0.4), 0 0 2px currentColor; }
#output .line.dim { color: var(--fg-dim); }
#output .line.bright { color: var(--fg-bright); font-weight: 700; text-shadow: 0 0 10px rgba(224, 224, 224, 0.4), 0 0 2px currentColor; }
#output .line.wopr { color: var(--amber); font-weight: 700; letter-spacing: 0.05em; text-shadow: 0 0 10px rgba(255, 176, 0, 0.6), 0 0 3px currentColor; }

.prompt { text-shadow: 0 0 8px rgba(74, 246, 38, 0.5); }

#output .line a {
    color: var(--cyan);
    text-decoration: underline;
    text-underline-offset: 2px;
}

#output .line a:hover {
    color: var(--fg-bright);
}

#output .cmd-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

#output .cmd-btn {
    background: none;
    border: 1px solid var(--fg-dim);
    color: var(--green);
    font-family: inherit;
    font-size: inherit;
    padding: 4px 12px;
    cursor: pointer;
    border-radius: 2px;
}

#output .cmd-btn:hover {
    border-color: var(--green);
    background: rgba(74, 246, 38, 0.1);
}

#input-line {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding-top: 4px;
}

.prompt {
    color: var(--green);
    white-space: nowrap;
    font-weight: 700;
}

#input {
    background: none;
    border: none;
    color: var(--fg);
    font-family: inherit;
    font-size: inherit;
    outline: none;
    caret-color: transparent;
    min-width: 1px;
    white-space: pre;
    display: inline;
}

#cursor {
    color: var(--fg);
    animation: blink 1s step-end infinite;
    margin-left: -2px;
}

#input-line {
    overflow: hidden;
}

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

#pong {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    background: var(--bg);
}

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

    body {
        padding: 6px;
    }

    #crt {
        border-radius: 14px;
    }

    #terminal {
        padding: 12px;
    }

    #input-line {
        padding: 8px 0 4px;
        border-top: 1px solid rgba(255,255,255,0.05);
    }

    #power-button {
        width: 88px;
        height: 88px;
    }

    #power-hint {
        font-size: 11px;
    }
}
