/* ==========================================================================
   fsociety CRT Terminal - Fullscreen & Mobile-Optimized Stylesheet
   Retro 80s/90s Convex CRT Television & Hacker Terminal
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=VT323&family=Share+Tech+Mono&family=Fira+Code:wght@400;700&display=swap');

:root {
    /* Classic Green Phosphor (P1 Phosphor) */
    --phosphor-color: #33ff33;
    --phosphor-dim: #198019;
    --phosphor-bright: #78ff78;
    --phosphor-glow: rgba(51, 255, 51, 0.7);
    --phosphor-bloom: rgba(51, 255, 51, 0.22);
    --phosphor-bg: #030a04;
    --cursor-color: #33ff33;
    --osd-bg: rgba(6, 20, 8, 0.65);
    --osd-border: rgba(51, 255, 51, 0.3);
    /* Viewport visual height fallback */
    --vvh: 100vh;
}

/* Theme: Amber CRT */
body.theme-amber {
    --phosphor-color: #ffb000;
    --phosphor-dim: #996a00;
    --phosphor-bright: #ffd266;
    --phosphor-glow: rgba(255, 176, 0, 0.7);
    --phosphor-bloom: rgba(255, 176, 0, 0.22);
    --phosphor-bg: #0d0802;
    --cursor-color: #ffb000;
    --osd-bg: rgba(24, 15, 4, 0.65);
    --osd-border: rgba(255, 176, 0, 0.3);
}

/* Theme: Evil Corp Cyan */
body.theme-blue {
    --phosphor-color: #00e5ff;
    --phosphor-dim: #007a8a;
    --phosphor-bright: #80f2ff;
    --phosphor-glow: rgba(0, 229, 255, 0.7);
    --phosphor-bloom: rgba(0, 229, 255, 0.22);
    --phosphor-bg: #010a0e;
    --cursor-color: #00e5ff;
    --osd-bg: rgba(4, 18, 24, 0.65);
    --osd-border: rgba(0, 229, 255, 0.3);
}

/* Theme: Monochrome White */
body.theme-white {
    --phosphor-color: #e0e8f0;
    --phosphor-dim: #7d8894;
    --phosphor-bright: #ffffff;
    --phosphor-glow: rgba(224, 232, 240, 0.7);
    --phosphor-bloom: rgba(224, 232, 240, 0.22);
    --phosphor-bg: #06080a;
    --cursor-color: #e0e8f0;
    --osd-bg: rgba(16, 20, 24, 0.65);
    --osd-border: rgba(224, 232, 240, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    height: var(--vvh, 100dvh);
    margin: 0;
    padding: 0;
    background-color: #000000;
    color: var(--phosphor-color);
    font-family: 'VT323', 'Share Tech Mono', monospace;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* ==========================================================================
   FULLSCREEN CONVEX CRT SCREEN (ВЫПУКЛЫЙ ЭКРАН КИНЕСКОПА)
   ========================================================================== */
.crt-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: var(--vvh, 100vh);
    height: var(--vvh, 100dvh);
    max-height: var(--vvh, 100dvh);
    background-color: var(--phosphor-bg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1;
    /* Convex glass curvature effect: deep vignette along curved tube border */
    box-shadow: 
        inset 0 0 100px 35px rgba(0, 0, 0, 0.96),
        inset 0 0 180px 70px rgba(0, 0, 0, 0.88),
        inset 0 0 35px rgba(0, 0, 0, 1);
    transition: background-color 0.4s ease;
}

/* Turn On / Warm-up Animation */
.crt-screen.power-on {
    animation: crtTurnOn 0.65s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

.crt-screen.power-off {
    animation: crtTurnOff 0.5s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

/* ==========================================================================
   CRT Convex Glass Overlays: Reflections, Scanlines & Phosphor Grid
   ========================================================================== */

/* Convex Glass Reflection & Vignette (Spherical curvature across entire screen) */
.crt-glass-reflection {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 20;
    background: 
        /* Upper-left curved specular bulb reflection */
        radial-gradient(ellipse 95% 60% at 25% 15%, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0) 55%),
        /* Deep barrel distortion vignette */
        radial-gradient(ellipse 120% 100% at 50% 50%, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.5) 82%, rgba(0, 0, 0, 0.94) 100%);
}

/* Scanlines and RGB sub-pixel grid */
.crt-scanlines {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 21;
    background: 
        linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.42) 50%),
        linear-gradient(90deg, rgba(255, 0, 0, 0.025), rgba(0, 255, 0, 0.015), rgba(0, 0, 255, 0.025));
    background-size: 100% 3px, 4px 100%;
    animation: crtFlicker 0.12s infinite;
}

/* Rolling cathode scan beam */
.crt-scan-beam {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 16%;
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.035) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    pointer-events: none;
    z-index: 22;
    animation: scanlineRoll 8s linear infinite;
}

/* Subtle phosphor noise */
.crt-noise {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 23;
    opacity: 0.03;
    background-image: radial-gradient(#fff 15%, transparent 16%), radial-gradient(#fff 15%, transparent 16%);
    background-size: 4px 4px;
    background-position: 0 0, 2px 2px;
}

/* ==========================================================================
   TERMINAL WRAPPER (FULLSCREEN CONTENT)
   ========================================================================== */
.terminal-wrapper {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    padding: 16px 28px 14px 28px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    cursor: text;
}

/* ==========================================================================
   TOP CRT OSD (ON-SCREEN DISPLAY) HEADER
   ========================================================================== */
.crt-osd-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--osd-bg);
    border: 1px solid var(--osd-border);
    border-radius: 4px;
    margin-bottom: 8px;
    backdrop-filter: blur(2px);
    box-shadow: 0 0 10px var(--phosphor-bloom);
    user-select: none;
}

.osd-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.power-led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #2b0000;
    box-shadow: 0 0 2px #ff0000;
    transition: all 0.3s ease;
}

.power-led.on {
    background-color: #ff2222;
    box-shadow: 0 0 8px #ff2222, 0 0 16px rgba(255, 34, 34, 0.85);
}

.osd-brand {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.88rem;
    font-weight: bold;
    letter-spacing: 0.14em;
    color: var(--phosphor-bright);
    text-shadow: 0 0 8px var(--phosphor-glow);
}

.osd-channel {
    font-family: 'VT323', monospace;
    font-size: 1.1rem;
    color: var(--phosphor-dim);
    letter-spacing: 0.08em;
}

.osd-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.osd-btn {
    background: rgba(0, 0, 0, 0.6);
    color: var(--phosphor-color);
    border: 1px solid var(--osd-border);
    border-radius: 3px;
    padding: 3px 8px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.74rem;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}

.osd-btn:hover {
    background: var(--phosphor-color);
    color: #000;
    box-shadow: 0 0 10px var(--phosphor-glow);
}

.osd-btn:active {
    transform: translateY(1px);
}

.osd-btn.active {
    background: var(--phosphor-bright);
    color: #000;
    font-weight: bold;
    box-shadow: 0 0 10px var(--phosphor-glow);
}

/* ==========================================================================
   TERMINAL CONTENT BODY (TOUCH-SCROLLABLE WITH MIN-HEIGHT: 0)
   ========================================================================== */
.terminal-content {
    flex: 1 1 auto;
    min-height: 0; /* CRITICAL FOR FLEXBOX OVERFLOW SCROLLING */
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* iOS momentum inertia scroll */
    touch-action: pan-y;               /* Touch dragging scrolls vertically */
    overscroll-behavior-y: contain;   /* Prevents pull-to-refresh reload */
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 1.5rem;
    line-height: 1.35;
    letter-spacing: 0.04em;
    color: var(--phosphor-color);
    text-shadow: 
        0 0 2px var(--phosphor-bright),
        0 0 7px var(--phosphor-glow),
        0 0 14px var(--phosphor-bloom);
    scrollbar-width: thin;
    scrollbar-color: var(--phosphor-dim) transparent;
    padding-right: 6px;
}

.terminal-content::-webkit-scrollbar {
    width: 6px;
}
.terminal-content::-webkit-scrollbar-thumb {
    background: var(--phosphor-dim);
    border-radius: 3px;
}
.terminal-content::-webkit-scrollbar-track {
    background: transparent;
}

/* Lines */
.term-line {
    word-break: break-word;
    white-space: pre-wrap;
    animation: lineFadeIn 0.08s ease-out;
}

.term-line.highlight {
    color: var(--phosphor-bright);
    font-weight: bold;
}

.term-line.dim {
    color: var(--phosphor-dim);
}

.term-line.warning {
    color: #ff3344;
    text-shadow: 0 0 6px rgba(255, 51, 68, 0.7);
}

.term-line.success {
    color: #33ff88;
    text-shadow: 0 0 6px rgba(51, 255, 136, 0.7);
}

.term-line.ascii-art {
    line-height: 1.15;
    font-family: 'Share Tech Mono', 'VT323', monospace;
    font-size: 1.2rem;
    color: var(--phosphor-bright);
}

/* ==========================================================================
   TERMINAL FOOTER: PROMPT + QUICK COMMAND PILLS
   ========================================================================== */
.terminal-footer {
    flex-shrink: 0; /* CRITICAL: Never gets squashed or hidden by keyboard */
    display: flex;
    flex-direction: column;
    margin-top: 6px;
    gap: 6px;
    z-index: 15;
    user-select: none;
}

.input-row {
    display: flex;
    align-items: center;
    font-size: 1.5rem;
    min-height: 2.2rem;
    position: relative;
    cursor: text;
}

.prompt-label {
    margin-right: 10px;
    white-space: nowrap;
    user-select: none;
    color: var(--phosphor-color);
    font-weight: bold;
    flex-shrink: 0;
}

.terminal-input-display {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex: 1;
    min-width: 60px;
    word-break: break-all;
}

.user-input-text {
    white-space: pre-wrap;
    min-height: 1em;
}

/* Blinking CRT block cursor */
.crt-cursor {
    display: inline-block;
    width: 0.6em;
    height: 1.1em;
    background-color: var(--cursor-color);
    box-shadow: 0 0 8px var(--cursor-color);
    vertical-align: middle;
    margin-left: 2px;
    animation: cursorBlink 0.9s steps(2, start) infinite;
}

/* Co-located Invisible Input Field with font-size 16px to prevent iOS auto-zoom */
.cmd-input-field {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    border: none;
    outline: none;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    font-size: 16px; /* CRITICAL FOR iOS SAFARI (prevents auto-zoom) */
    line-height: normal;
    z-index: 10;
    cursor: text;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Quick command pills */
.quick-commands {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 4px 0 2px 0;
    width: 100%;
    touch-action: pan-x; /* Fluid horizontal swiping on mobile */
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.quick-commands::-webkit-scrollbar {
    display: none;
}

.cmd-pill {
    background: rgba(12, 24, 14, 0.7);
    border: 1px solid var(--phosphor-dim);
    color: var(--phosphor-color);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 12px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 0 6px var(--phosphor-bloom);
    user-select: none;
    flex-shrink: 0;
}

.cmd-pill:hover, .cmd-pill:active {
    background: var(--phosphor-color);
    color: #000;
    box-shadow: 0 0 12px var(--phosphor-glow);
}

/* ==========================================================================
   KEYFRAME ANIMATIONS
   ========================================================================== */
@keyframes cursorBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

@keyframes crtFlicker {
    0% { opacity: 0.985; }
    50% { opacity: 1; }
    52% { opacity: 0.97; }
    54% { opacity: 1; }
    80% { opacity: 0.99; }
    100% { opacity: 0.985; }
}

@keyframes scanlineRoll {
    0% { transform: translateY(-100%); }
    100% { transform: translateY(700%); }
}

@keyframes crtTurnOn {
    0% {
        transform: scaleY(0.005) scaleX(0);
        filter: brightness(25);
        opacity: 1;
    }
    40% {
        transform: scaleY(0.008) scaleX(1);
        filter: brightness(12);
        opacity: 1;
    }
    65% {
        transform: scaleY(1) scaleX(1);
        filter: brightness(3);
        opacity: 1;
    }
    100% {
        transform: scaleY(1) scaleX(1);
        filter: brightness(1);
        opacity: 1;
    }
}

@keyframes crtTurnOff {
    0% {
        transform: scale(1);
        filter: brightness(1);
        opacity: 1;
    }
    40% {
        transform: scaleY(0.008) scaleX(1);
        filter: brightness(8);
        opacity: 1;
    }
    80% {
        transform: scaleY(0.005) scaleX(0.05);
        filter: brightness(20);
        opacity: 1;
    }
    100% {
        transform: scale(0);
        opacity: 0;
    }
}

@keyframes lineFadeIn {
    from { opacity: 0; transform: translateY(-2px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   RESPONSIVE ADAPTATIONS: PC, TABLET, MOBILE
   ========================================================================== */

/* Tablet (768px - 1024px) */
@media screen and (max-width: 1024px) {
    .terminal-wrapper {
        padding: 12px 18px 10px 18px;
    }
    .terminal-content {
        font-size: 1.35rem;
    }
    .input-row {
        font-size: 1.35rem;
    }
    .term-line.ascii-art {
        font-size: 0.95rem;
    }
}

/* Phone / Mobile (< 768px) */
@media screen and (max-width: 767px) {
    .terminal-wrapper {
        padding: 8px 10px 8px 10px;
    }

    .crt-osd-header {
        padding: 3px 6px;
        margin-bottom: 6px;
        gap: 4px;
    }

    .osd-brand {
        font-size: 0.72rem;
        letter-spacing: 0.08em;
    }

    .osd-channel {
        display: none;
    }

    .osd-btn {
        padding: 2px 5px;
        font-size: 0.62rem;
    }

    .terminal-content {
        font-size: 1.15rem;
        line-height: 1.25;
        padding-right: 4px;
    }

    .input-row {
        font-size: 1.15rem;
        min-height: 1.7rem;
    }

    .prompt-label {
        margin-right: 6px;
    }

    .term-line.ascii-art {
        font-size: 0.6rem;
        line-height: 1.05;
        overflow-x: auto;
    }

    .cmd-pill {
        font-size: 0.7rem;
        padding: 3px 7px;
    }
}

/* Compact Mobile Height (When keyboard is open or small screen) */
@media screen and (max-height: 480px) {
    .crt-osd-header {
        margin-bottom: 3px;
        padding: 2px 4px;
    }
    .terminal-wrapper {
        padding: 4px 6px 4px 6px;
    }
    .terminal-footer {
        margin-top: 2px;
        gap: 3px;
    }
    .input-row {
        min-height: 1.5rem;
    }
}
