/* SPACE DOG terminal — green phosphor CRT */

:root {
    --green: #3bff6f;
    --green-dim: rgba(59, 255, 111, 0.45);
    --green-faint: rgba(59, 255, 111, 0.14);
    --magenta: #ff5fd7;
    --magenta-dim: rgba(255, 95, 215, 0.45);
    --amber: #ffb347;
    --bg-deep: #000300;
    --bg-center: #06180b;
    --bg-edge: #020a05;
    --font: 'VT323', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg-deep);
    overflow: hidden;
}

body {
    font-family: var(--font);
    color: var(--green);
}

::selection {
    background: var(--green);
    color: #000;
}

/* ---- CRT shell ---- */

.crt {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 50% 40%, var(--bg-center) 0%, var(--bg-edge) 60%, #000300 100%);
    animation: crt-on 0.6s cubic-bezier(0.23, 1, 0.32, 1) both;
}

/* scanlines */
.crt::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 8;
    pointer-events: none;
    background: repeating-linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0px,
        rgba(0, 0, 0, 0) 2px,
        rgba(0, 0, 0, 0.22) 2px,
        rgba(0, 0, 0, 0.22) 4px
    );
}

/* vignette + slow phosphor flicker */
.crt::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 9;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
    animation: flicker 6s steps(60) infinite;
}

@keyframes crt-on {
    0%   { transform: scaleY(0.005) scaleX(0.6); filter: brightness(8); }
    45%  { transform: scaleY(0.005) scaleX(1);   filter: brightness(8); }
    100% { transform: scaleY(1)     scaleX(1);   filter: brightness(1); }
}

@keyframes flicker {
    0%, 100% { opacity: 1; }
    8%  { opacity: 0.94; }
    9%  { opacity: 1; }
    42% { opacity: 0.97; }
    43% { opacity: 1; }
    71% { opacity: 0.93; }
    72% { opacity: 1; }
}

/* disco easter egg */
.crt.disco { animation: hue-spin 1.6s linear infinite; }
@keyframes hue-spin { to { filter: hue-rotate(360deg); } }

/* ---- starfield ---- */

#starfield {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

#starfield span {
    position: absolute;
    color: var(--green-dim);
    opacity: 0;
    animation: twinkle 4s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0; }
    50%      { opacity: 0.7; }
}

/* ---- terminal layout ---- */

.terminal {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 18px 20px 14px;
    text-shadow: 0 0 6px var(--green-dim);
    font-size: 21px;
    line-height: 1.25;
}

.masthead {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 28px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--green-faint);
    padding-bottom: 10px;
    margin-bottom: 10px;
}

#banner {
    margin: 0;
    font-family: monospace;
    font-size: clamp(5px, 1.25vw, 11px);
    line-height: 1.18;
    letter-spacing: 0;
    color: var(--green);
    text-shadow: 0 0 10px var(--green-dim);
}

#dog {
    margin: 0;
    font-size: 17px;
    line-height: 1.05;
    color: var(--green);
}

/* ---- output ---- */

#screen {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--green-faint) transparent;
    padding-right: 6px;
    padding-bottom: 8px;
}

#screen::-webkit-scrollbar { width: 6px; }
#screen::-webkit-scrollbar-thumb { background: var(--green-faint); }

.line {
    margin: 0 0 2px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.line.sys { color: var(--green); opacity: 0.85; }

.line.you .ps1 { opacity: 0.7; }

.line.sd {
    color: var(--magenta);
    text-shadow: 0 0 6px var(--magenta-dim);
}

.line.sd .who { opacity: 0.75; }

.line a {
    color: var(--amber);
    text-decoration: none;
    text-shadow: 0 0 6px rgba(255, 179, 71, 0.5);
}

.line a:hover { text-decoration: underline; }

.ok { color: var(--green); }

/* ---- prompt ---- */

#prompt-line {
    display: flex;
    align-items: baseline;
    gap: 0.6ch;
    border-top: 1px solid var(--green-faint);
    padding-top: 8px;
    margin-top: 6px;
}

.ps1 { white-space: nowrap; }

#cli {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--green);
    font-family: var(--font);
    font-size: inherit;
    text-shadow: inherit;
    caret-color: var(--green);
    caret-shape: block;
    padding: 0;
}

#cli:disabled { opacity: 0.4; }

/* ---- soft keys ---- */

.softkeys {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 10px;
}

.softkeys button {
    background: transparent;
    border: 1px solid var(--green);
    color: var(--green);
    font-family: var(--font);
    font-size: 17px;
    padding: 3px 12px;
    cursor: pointer;
    text-shadow: 0 0 6px var(--green-dim);
    transition: background 0.12s ease, color 0.12s ease;
}

.softkeys button:hover,
.softkeys button:focus-visible {
    background: var(--green);
    color: #000;
    text-shadow: none;
    outline: none;
}

/* ---- small screens ---- */

@media (max-width: 640px) {
    .terminal { font-size: 18px; padding: 12px 12px 10px; }
    .masthead { gap: 12px; }
    #banner { font-size: 1.55vw; }
    #dog { font-size: 13px; }
    .softkeys button { font-size: 15px; padding: 2px 8px; }
}

/* ---- reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
    .crt { animation: none; }
    .crt::after { animation: none; }
    .crt.disco { animation: none; }
    #starfield span { animation: none; opacity: 0.4; }
}

/* ---- hyperspace warp canvas ---- */

.warp-canvas {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.45s ease, visibility 0s linear 0.45s;
}

.warp-canvas.warp-on {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.45s ease;
}

#starfield { transition: opacity 0.45s ease; }
#crt:has(.warp-canvas.warp-on) #starfield { opacity: 0.1; }
.crt.disco .warp-canvas.warp-on { filter: saturate(1.8) brightness(1.1); }

/* ---- stunts ---- */

.crt.shake { animation: crt-shake 0.5s linear; }
@keyframes crt-shake {
    0%, 100% { transform: translate(0, 0); }
    15% { transform: translate(-6px, 3px); }
    30% { transform: translate(5px, -4px); }
    45% { transform: translate(-4px, -3px); }
    60% { transform: translate(6px, 2px); }
    75% { transform: translate(-3px, 4px); }
    90% { transform: translate(2px, -2px); }
}

.barrel { animation: barrel-roll 1.2s cubic-bezier(0.45, 0, 0.3, 1); }
@keyframes barrel-roll {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.crt.alert { animation: red-alert 0.3s steps(2) 4; }
@keyframes red-alert {
    50% { filter: sepia(1) hue-rotate(-50deg) saturate(4) brightness(1.1); }
}

@media (prefers-reduced-motion: reduce) {
    .crt.shake, .barrel, .crt.alert { animation: none; }
}

/* ---- mascot liveliness ---- */
#dog { transition: transform 0.15s ease; }
#dog.excited { animation: dog-bounce 0.42s ease-in-out infinite; }
@keyframes dog-bounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-7px); }
}
@media (prefers-reduced-motion: reduce) { #dog.excited { animation: none; } }
