/**
 * MusicZone Terminal v3.x - CRT TTY Emulator
 * Retro terminal with authentic CRT effects
 * See js/config.js for current version
 */

:root {
    /* Default: Green phosphor (P1) */
    --terminal-color: #00ff00;
    --terminal-color-dim: #00aa00;
    --terminal-bg: #0a0a0a;
    --terminal-glow: rgba(0, 255, 0, 0.5);
    --scanline-color: rgba(0, 255, 0, 0.08);
    --font-size: 18px;
    --line-height: 1.3;
}

/* Green phosphor (P1) - Classic */
body.phosphor-green {
    --terminal-color: #00ff00;
    --terminal-color-dim: #00aa00;
    --terminal-glow: rgba(0, 255, 0, 0.5);
    --scanline-color: rgba(0, 255, 0, 0.08);
}

/* Amber phosphor (P3) - Warm */
body.phosphor-amber {
    --terminal-color: #ffb000;
    --terminal-color-dim: #cc8800;
    --terminal-glow: rgba(255, 176, 0, 0.5);
    --scanline-color: rgba(255, 176, 0, 0.08);
}

/* White phosphor (P4) - Modern */
body.phosphor-white {
    --terminal-color: #e0e0e0;
    --terminal-color-dim: #a0a0a0;
    --terminal-glow: rgba(224, 224, 224, 0.4);
    --scanline-color: rgba(224, 224, 224, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--terminal-bg);
}

body {
    color: var(--terminal-color);
    font-family: 'VT323', 'Courier New', monospace;
    font-size: var(--font-size);
    line-height: var(--line-height);
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: unset;
}

/* CRT Overlay - vignette effect */
.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: radial-gradient(
        ellipse at center,
        transparent 0%,
        transparent 60%,
        rgba(0, 0, 0, 0.3) 90%,
        rgba(0, 0, 0, 0.6) 100%
    );
}

/* Scanline effect - horizontal lines */
.crt-overlay::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
}

/* Moving scanline */
.scanline {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 10px;
    background: linear-gradient(
        to bottom,
        transparent,
        var(--scanline-color),
        transparent
    );
    animation: scanline-move 8s linear infinite;
    pointer-events: none;
    z-index: 1001;
    opacity: 0.7;
}

@keyframes scanline-move {
    0% { transform: translateY(-100%); }
    100% { transform: translateY(100vh); }
}

/* Terminal container */
.terminal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: text;
}

.terminal-content {
    height: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Output area */
.terminal-output {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
    /* Hide scrollbar but allow scrolling */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.terminal-output::-webkit-scrollbar {
    display: none;
}

/* Terminal lines */
.terminal-line {
    min-height: calc(var(--font-size) * var(--line-height));
    text-shadow: 0 0 5px var(--terminal-glow);
}

/* Input wrapper */
.terminal-input-wrapper {
    display: flex;
    align-items: center;
    min-height: calc(var(--font-size) * var(--line-height));
    flex-shrink: 0;
    line-height: var(--line-height);
}

.terminal-prompt {
    color: var(--terminal-color);
    text-shadow: 0 0 5px var(--terminal-glow);
    white-space: nowrap;
    flex-shrink: 0;
    line-height: inherit;
}

/* The actual input field - contenteditable div */
.terminal-input {
    flex: 0 1 auto;
    outline: none;
    color: var(--terminal-color);
    background: transparent;
    border: none;
    max-width: calc(100% - 12ch); /* Leave room for prompt */
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    text-shadow: 0 0 5px var(--terminal-glow);
    word-break: break-all;
    white-space: pre-wrap;
    caret-color: transparent; /* Hide native caret, we use our own */
    min-width: 1px;
    min-height: 1em;
    /* Prevent Chrome from wrapping input in divs */
    -webkit-user-modify: read-write-plaintext-only;
}

.terminal-input:focus {
    outline: none;
}

/* Prevent Chrome from adding elements inside contenteditable */
.terminal-input br,
.terminal-input div {
    display: none;
}

/* Blinking cursor */
.cursor {
    display: inline-block;
    width: 0.6em;
    height: 1.1em;
    background: var(--terminal-color);
    animation: cursor-blink 1s steps(1, end) infinite;
    vertical-align: text-bottom;
    margin-left: 1px;
    flex-shrink: 0;
    box-shadow: 0 0 5px var(--terminal-glow);
    vertical-align: middle;
    flex-shrink: 0;
    margin-left: 1px;
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Typing cursor for animations */
.typing-cursor {
    display: inline;
    animation: cursor-blink 0.75s step-end infinite;
}

/* --MORE-- pagination prompt */
.terminal-more {
    color: var(--terminal-color);
    font-weight: bold;
    animation: more-blink 1s step-end infinite;
    cursor: pointer;
    text-shadow: 0 0 8px var(--terminal-glow);
}

@keyframes more-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* Bell/glitch effect on terminal */
.terminal.bell {
    animation: terminal-bell 0.15s;
}

@keyframes terminal-bell {
    0%, 100% { filter: none; }
    25% { filter: hue-rotate(90deg) brightness(1.5); }
    50% { filter: hue-rotate(-90deg) brightness(0.8); }
    75% { filter: hue-rotate(45deg) brightness(1.2); }
}

/* Glitch effect on output */
.terminal-output.glitch {
    animation: glitch 0.3s;
}

@keyframes glitch {
    0%, 100% {
        text-shadow: 0 0 5px var(--terminal-glow);
        transform: translate(0);
    }
    20% {
        text-shadow: -2px 0 #ff0000, 2px 0 #00ffff;
        transform: translate(2px, 0);
    }
    40% {
        text-shadow: 2px 0 #ff0000, -2px 0 #00ffff;
        transform: translate(-2px, 0);
    }
    60% {
        text-shadow: 0 0 5px var(--terminal-glow);
        transform: translate(0);
    }
    80% {
        text-shadow: -1px 0 #ff0000, 1px 0 #00ffff;
        transform: translate(1px, 0);
    }
}

/* Color classes */
.terminal-error {
    color: #ff4444;
    text-shadow: 0 0 5px rgba(255, 68, 68, 0.5);
}

.terminal-warning {
    color: #ffff00;
    text-shadow: 0 0 5px rgba(255, 255, 0, 0.5);
}

.terminal-info {
    color: #00ffff;
    text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
}

.terminal-success {
    color: var(--terminal-color);
}

/* Player indicator */
.player-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--terminal-color);
    text-shadow: 0 0 5px var(--terminal-glow);
    z-index: 100;
    background: rgba(0, 0, 0, 0.8);
    padding: 8px 12px;
    border: 1px solid var(--terminal-color);
}

.player-indicator-icon {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #333;
}

.player-indicator-icon.playing {
    background: var(--terminal-color);
    box-shadow: 0 0 10px var(--terminal-glow);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

/* Video popup */
.video-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 60px; /* Leave space to see terminal at bottom on desktop */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    pointer-events: none;
    padding: 20px; /* Relative border/margin around video */
    box-sizing: border-box;
}

.video-popup-container {
    position: relative;
    width: 100%;
    max-width: min(800px, 80vw); /* Responsive max width */
    min-width: 100px;
    min-height: 100px;
    background: #000;
    border: 2px solid var(--terminal-color);
    box-shadow: 0 0 30px var(--terminal-glow);
    pointer-events: auto;
}

.video-popup-container video {
    width: 100%;
    height: auto;
    max-height: calc(100vh - 140px); /* Leave room for terminal peek */
    min-height: 56px; /* Minimum video height */
    display: block;
    object-fit: contain;
}

.video-popup-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 28px;
    height: 28px;
    background: #000;
    color: var(--terminal-color);
    border: 2px solid var(--terminal-color);
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    line-height: 1;
}

.video-popup-close:hover {
    background: var(--terminal-color);
    color: #000;
}

/* Hide scanlines when disabled */
body.no-scanlines .crt-overlay::before,
body.no-scanlines .scanline {
    display: none;
}

/* Responsive */
@media (max-width: 768px) {
    :root {
        --font-size: 16px;
    }
    
    .terminal-content {
        padding: 10px;
    }
    
    .player-indicator {
        bottom: 10px;
        right: 10px;
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .player-indicator-text {
        display: none;
    }
    
    /* Video popup - tablet */
    .video-popup {
        padding: 15px;
        bottom: 40px;
    }
    
    .video-popup-container {
        width: 95%;
        max-width: none;
    }
    
    .video-popup-container video {
        max-height: calc(100vh - 100px);
    }
    
    .video-popup-close {
        width: 32px;
        height: 32px;
        font-size: 18px;
        top: -10px;
        right: -10px;
    }
}

@media (max-width: 480px) {
    :root {
        --font-size: 14px;
    }
    
    /* Video popup - mobile */
    .video-popup {
        padding: 10px;
        bottom: 30px;
    }
    
    .video-popup-container {
        width: 100%;
        min-width: 100px;
    }
    
    .video-popup-container video {
        max-height: calc(100vh - 80px);
        min-height: 80px;
    }
    
    .video-popup-close {
        width: 36px;
        height: 36px;
        font-size: 20px;
        top: -8px;
        right: -8px;
    }
}

/* iOS fixes */
@supports (-webkit-touch-callout: none) {
    .terminal {
        height: -webkit-fill-available;
    }
}

/* Hide keyboard when video popup is open (mobile) */
body.video-popup-active .terminal-input {
    pointer-events: none;
}

@media (max-width: 768px) {
    body.video-popup-active .terminal-input {
        visibility: hidden;
        height: 0;
        overflow: hidden;
    }
}
