:root {
	/* Colors */
	--terminal-bg: black;
	--terminal-text: #00ff00;
	--terminal-shadow: rgba(0, 255, 0, 0.2);
	--terminal-selection: rgba(255, 255, 255, 0.3);
	--terminal-border: #000;
	
	/* Classic Terminal Dimensions */
	--char-width: 0.6em;    /* Approximate width of a monospace character */
	--char-height: 1.2em;   /* Line height for good readability */
	--cols: 80;             /* Classic terminal width in characters */
	--rows: 24;             /* Classic terminal height in characters */
	--base-font-size: 16px;
	--terminal-padding: 20px;
	
	/* Calculated Dimensions */
	--terminal-width: calc(var(--char-width) * var(--cols));
	--terminal-height: calc(var(--char-height) * var(--rows));
	
	/* Other Dimensions */
	--terminal-border-radius: 20px;
	--terminal-padding: 20px;
	--terminal-border-width: 2px;
	
	/* Font */
	--terminal-font: monospace;
	--base-font-size: 16px;
}


/* Base styles - update these at the top of the file */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background-color: var(--terminal-bg);
    color: var(--terminal-text);
    font-family: var(--terminal-font);
    font-size: var(--base-font-size);
    overflow: hidden; /* Prevent scrollbars on body/html */
    position: fixed; /* Ensure full viewport coverage */
    top: 0;
    left: 0;
}

canvas {
    filter: blur(0.4px);
}

/* Terminal container with classic dimensions */
.terminal {
	display: flex;
	flex-direction: column;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: calc(var(--terminal-width) + (var(--terminal-padding) * 2));
	height: calc(var(--terminal-height) + (var(--terminal-padding) * 2));
	border: var(--terminal-border-width) solid var(--terminal-border);
	box-sizing: border-box;
	box-shadow: 0 0 20px var(--terminal-shadow);
	border-radius: var(--terminal-border-radius);
	overflow: hidden;
	max-width: 95vw;  /* Prevent horizontal overflow */
	max-height: 95vh; /* Prevent vertical overflow */
	filter: blur(0.4px); /* added to mimic the old text shadow crt effect */
}

.user-input {
    outline: none;
    border: none;
    color: var(--terminal-text);
    flex: 1;
    background: transparent;  /* Ensure background is transparent */
    caret-color: var(--terminal-text);
    -webkit-user-select: text;  /* Ensure text is still selectable */
    user-select: text;
    -webkit-user-modify: read-write;  /* For older WebKit browsers */
    -webkit-tap-highlight-color: transparent;  /* Remove mobile tap highlight */
}

.user-input.masked-input {
    letter-spacing: 0.25em;
}

.user-input.masked-input-revealed {
    letter-spacing: normal;
}

.user-input:focus {
    outline: none;
    background: transparent;
}

.user-input::selection {
    background-color: var(--terminal-selection);
}

#output {
    margin: 0;
    padding: var(--terminal-padding);
    overflow-y: scroll;
    flex: 1;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--terminal-text);
    font-size: inherit;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.llm-stream {
    display: block;
    margin-top: 0.5rem;
    white-space: pre-wrap;
}

.floating-output {
    /* Remove conflicting scroll settings from this class */
    flex: 1;
    display: flex; /* Added to ensure proper flex behavior */
}

#output::-webkit-scrollbar {
    display: none;
}

.floating-input {
	display: flex;
	color: var(--terminal-text);
	padding: 0 var(--terminal-padding) var(--terminal-padding);
	box-sizing: border-box;
	font-size: inherit;
}

/* Game overlay settings */
.game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Only enable during gameplay */
    z-index: 100; /* Between terminal and CRT effect */
}

.game-active .game-overlay {
    pointer-events: auto;
}

/* Style for the snake menu container */
#snake-menu {
    display: none;
    flex-direction: column;
    align-items: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8); /* Semi-transparent black background */
    padding: 20px;
    border: 2px solid #0f0; /* Green border to match Matrix theme */
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5); /* Green glow for CRT effect */
    z-index: 101; /* Ensure it stays above other elements */
}

/* Style for all buttons in the menu */
#snake-menu button {
    display: block;
    width: 200px; /* Sets a consistent width for all buttons */
    margin: 10px auto;
    padding: 10px 20px;
    font-size: 16px;
    color: var(--terminal-text); /*#0f0; Bright green text to match Matrix style */
    background: rgba(0, 0, 0, 0.7); /* Dark background with slight transparency */
    border: 1px solid var(--terminal-text); /* Green border */
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.3s ease; /* Smooth hover effect */
}

/* Hover effect for buttons */
#snake-menu button:hover {
    background: rgba(0, 255, 0, 0.2); /* Light green hover effect */
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.7); /* Enhanced green glow on hover */
    transform: scale(1.05); /* Slight scale for interactivity */
}

/* Focus effect for accessibility */
#snake-menu button:focus {
    outline: 2px solid #0f0;
    outline-offset: 2px;
}

/* Ensure buttons are hidden when not needed (handled by JavaScript) */
#start-game, #restart-game, #quit-game {
    display: none; /* Default hidden, shown via JavaScript */
}

/* Autocomplete button for mobile */
.floating-input {
	position: relative; /* For absolute positioning of the button */
}

/* Special elements for mobile devices */
.autocomplete-button {
    display: none; /* Hidden by default on desktop */
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 1px solid var(--terminal-text);
    color: var(--terminal-text);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--terminal-font);
    font-size: 0.8em;
    cursor: pointer;
    outline: none;
}

.autocomplete-button:active {
    background: rgba(0, 255, 0, 0.2);
}

.mobile-controls {
    display: none; /* Hidden by default on desktop */
}

.command-button {
    display: none;
    position: absolute;
    right: 45px; /* Position next to autocomplete button */
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 1px solid var(--terminal-text);
    color: var(--terminal-text);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--terminal-font);
    font-size: 0.8em;
    cursor: pointer;
    outline: none;
}

.command-list {
    display: block;
    position: fixed;
    bottom: -100%; /* Start below the viewport */
    right: 20px; /* Align with the command button */
    background: var(--terminal-bg);
    border: 1px solid var(--terminal-text);
    border-radius: 8px;
    padding: 10px 0;
    z-index: 1000;
    max-height: 60vh;
    overflow-y: auto;
    width: 80%;
    max-width: 300px;
    transition: bottom 0.3s ease-out;
    opacity: 0;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.1);
}

.command-list.active {
    bottom: 20px; /* Final position above the input area */
    opacity: 1;
}

.command-list button {
    display: block;
    width: 100%;
    padding: 12px 20px;
    background: transparent;
    border: none;
    color: var(--terminal-text);
    font-family: var(--terminal-font);
    font-size: 14px; /* Match floating-input size */
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.command-list button:hover,
.command-list button:active {
    background: rgba(0, 255, 0, 0.1);
}

.command-button.abort-mode {
    background: rgba(255, 0, 0, 0.1);
    border-color: #ff4444;
    color: #ff4444;
}

.abort-command {
    color: #ff4444 !important;
    border-top: 1px solid rgba(255, 68, 68, 0.2);
    margin-top: 5px;
    padding-top: 10px;
}

.command-overlay {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.command-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Custom scrollbar for the command list */
.command-list::-webkit-scrollbar {
    width: 6px;
}

.command-list::-webkit-scrollbar-track {
    background: var(--terminal-bg);
}

.command-list::-webkit-scrollbar-thumb {
    background: var(--terminal-text);
    border-radius: 3px;
}

/* Touch device styles - only enable buttons */
.touch-device .autocomplete-button,
.touch-device .command-button {
    display: block;
}

.touch-device .floating-input {
    padding-right: 85px; /* Make room for both buttons */
}


/* Mobile-specific styles */
@media screen and (max-width: 768px),
screen and (any-pointer: coarse) and (any-hover: none) {
	:root {
		--base-font-size: clamp(4px, calc(100vw / 55), 16px);
		--terminal-padding: 10px;
		--cols: 80;  /* Reduce columns for mobile */
		--rows: auto;  /* Slightly reduce rows for mobile */
	}
	
	.terminal {
		position: fixed; /* Use fixed instead of absolute for mobile */
		border-radius: 10px; /* Smaller border radius for mobile */
		width: 95vw;    /* Use viewport width */
		height: 85vh;   /* Use viewport height */
	}
	
	
	/* Adjust padding for mobile */
	#output {
		padding: 10px;
	}
	
    .floating-input {
        padding-right: 85px; /* Make room for both buttons */
        font-size: 14px;
	}
	
    .touch-device .command-button,
    .touch-device .autocomplete-button {
        display: block;
	}
	
	/* Add some right padding to input to prevent text overlap with button */
	.user-input {
		padding-right: 45px;
	}
	
    .mobile-controls {
        display: block;
	}
}




/*CRT effect, thx http://aleclownes.com/2017/02/01/crt-display.html*/
.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200; /* High z-index to ensure it's above other content */
    pointer-events: none; /* Crucial - makes the div not capture any mouse events */
    overflow: hidden; /* Prevent overlay scrollbars */
}

@keyframes flicker {
	0% {
		opacity: 0.27861;
	}
	5% {
		opacity: 0.34769;
	}
	10% {
		opacity: 0.23604;
	}
	15% {
		opacity: 0.90626;
	}
	20% {
		opacity: 0.18128;
	}
	25% {
		opacity: 0.83891;
	}
	30% {
		opacity: 0.65583;
	}
	35% {
		opacity: 0.67807;
	}
	40% {
		opacity: 0.26559;
	}
	45% {
		opacity: 0.84693;
	}
	50% {
		opacity: 0.96019;
	}
	55% {
		opacity: 0.08594;
	}
	60% {
		opacity: 0.20313;
	}
	65% {
		opacity: 0.71988;
	}
	70% {
		opacity: 0.53455;
	}
	75% {
		opacity: 0.37288;
	}
	80% {
		opacity: 0.71428;
	}
	85% {
		opacity: 0.70419;
	}
	90% {
		opacity: 0.7003;
	}
	95% {
		opacity: 0.36108;
	}
	100% {
		opacity: 0.24387;
	}
}

.crt-screen::after {
	content: " ";
	display: block;
	position: absolute;
	top: 0;
	left: 0;
	bottom: 0;
	right: 0;
	background: rgba(18, 16, 16, 0.1);
	opacity: 0;
	z-index: 2;
	pointer-events: none;
	animation: flicker 0.15s infinite;
}


.crt-screen::before {
	content: " ";
	display: block;
	position: absolute;
	top: 0;
	left: 0;
	bottom: 0;
	right: 0;
	background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
	z-index: 2;
	background-size: 100% 2px, 3px 100%;
	pointer-events: none;
}

/* Base styles for any element with crt-shadow class */
.crt-shadow {
    position: relative;
    transform: translateZ(0);
    will-change: transform;
}

/* Shadow layers */
.crt-shadow::before,
.crt-shadow::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    will-change: transform;
    white-space: pre;  /* Changed from pre-wrap to maintain exact positioning */
    padding: inherit;  /* Maintain padding consistency */
    font: inherit;    /* Ensure font properties match */
    line-height: inherit;
}

/* Output-specific adjustments */
#output.crt-shadow {
    position: relative;
    color: #00ff00;
}

#output.crt-shadow::before,
#output.crt-shadow::after {
    white-space: pre-wrap;  /* Keep pre-wrap for output area */
}

/* Input area specific adjustments */
.floating-input.crt-shadow {
    position: relative;
    display: flex;  /* Maintain flex layout */
    align-items: center;
}

.floating-input.crt-shadow::before,
.floating-input.crt-shadow::after {
    display: flex;  /* Match the flex layout */
    align-items: center;
}

/* Shadow colors and animations */
.crt-shadow::before {
    color: rgba(0,30,255,0.5);
    mix-blend-mode: screen;
    transform-origin: 50% 50%;
    animation: textShadowBlue 1.6s infinite;
}

.crt-shadow::after {
    color: rgba(255,0,80,0.3);
    mix-blend-mode: screen;
    transform-origin: 50% 50%;
    animation: textShadowRed 1.6s infinite;
}

@keyframes textShadowBlue {
    0% { transform: translateX(0.4389924193300864px); }
    5% { transform: translateX(2.7928974010788217px); }
    10% { transform: translateX(0.02956275843481219px); }
    15% { transform: translateX(0.40218538552878136px); }
    20% { transform: translateX(3.4794037899852017px); }
    25% { transform: translateX(1.6125630401149584px); }
    30% { transform: translateX(0.7015590085143956px); }
    35% { transform: translateX(3.896914047650351px); }
    40% { transform: translateX(3.870905614848819px); }
    45% { transform: translateX(2.231056963361899px); }
    50% { transform: translateX(0.08084290417898504px); }
    55% { transform: translateX(2.3758461067427543px); }
    60% { transform: translateX(2.202193051050636px); }
    65% { transform: translateX(2.8638780614874975px); }
    70% { transform: translateX(0.48874025155497314px); }
    75% { transform: translateX(1.8948491305757957px); }
    80% { transform: translateX(0.0833037308038857px); }
    85% { transform: translateX(0.09769827255241735px); }
    90% { transform: translateX(3.443339761481782px); }
    95% { transform: translateX(2.1841838852799786px); }
    100% { transform: translateX(2.6208764473832513px); }
}

@keyframes textShadowRed {
    0% { transform: translateX(-0.4389924193300864px); }
    5% { transform: translateX(-2.7928974010788217px); }
    10% { transform: translateX(-0.02956275843481219px); }
    15% { transform: translateX(-0.40218538552878136px); }
    20% { transform: translateX(-3.4794037899852017px); }
    25% { transform: translateX(-1.6125630401149584px); }
    30% { transform: translateX(-0.7015590085143956px); }
    35% { transform: translateX(-3.896914047650351px); }
    40% { transform: translateX(-3.870905614848819px); }
    45% { transform: translateX(-2.231056963361899px); }
    50% { transform: translateX(-0.08084290417898504px); }
    55% { transform: translateX(-2.3758461067427543px); }
    60% { transform: translateX(-2.202193051050636px); }
    65% { transform: translateX(-2.8638780614874975px); }
    70% { transform: translateX(-0.48874025155497314px); }
    75% { transform: translateX(-1.8948491305757957px); }
    80% { transform: translateX(-0.0833037308038857px); }
    85% { transform: translateX(-0.09769827255241735px); }
    90% { transform: translateX(-3.443339761481782px); }
    95% { transform: translateX(-2.1841838852799786px); }
    100% { transform: translateX(-2.6208764473832513px); }
}

/* ========================================
   LOADING SCREEN STYLES (PHOTOSENSITIVE-SAFE VERSION)
   ======================================== */

#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--terminal-bg);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--terminal-font);
    color: var(--terminal-text);
    overflow: hidden;
    transition: opacity 0.5s ease-out;
}

#loading-screen.fade-out {
    opacity: 0;
}

.loading-content {
    text-align: center;
    max-width: 90vw;
    width: 900px;
}

.loading-ascii {
    color: var(--terminal-text);
    font-size: clamp(8px, 1.5vw, 14px);
    line-height: 1.2;
    margin-bottom: 30px;
    text-shadow: 0 0 10px var(--terminal-shadow);
    /* Removed the flicker animation - now has a subtle glow pulse instead */
    animation: gentleGlow 3s ease-in-out infinite;
}

/* Much gentler glow effect - no position changes, just opacity */
@keyframes gentleGlow {
    0%, 100% { 
        opacity: 0.85; 
        text-shadow: 0 0 10px var(--terminal-shadow);
    }
    50% { 
        opacity: 1; 
        text-shadow: 0 0 15px var(--terminal-shadow);
    }
}

.loading-messages {
    height: 300px;
    text-align: left;
    margin: 0 auto 30px;
    max-width: 600px;
    overflow: hidden;
}

.boot-sequence {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.boot-line {
    opacity: 0;
    transform: translateX(-20px);
    /* Removed the automatic animation - will be controlled by JS */
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
    color: var(--terminal-text);
    font-size: 14px;
    text-shadow: 0 0 5px var(--terminal-shadow);
}

.boot-line .success {
    color: var(--terminal-text);
    font-weight: bold;
    text-transform: uppercase;
}

/* Removed - animation now controlled by JavaScript transitions */

.loading-bar-container {
    margin: 30px auto;
    width: 80%;
    max-width: 400px;
}

.loading-bar {
    height: 20px;
    background: #001100;
    border: 2px solid var(--terminal-text);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 0 10px var(--terminal-shadow);
}

.loading-progress {
    height: 100%;
    background: linear-gradient(90deg, #004400 0%, var(--terminal-text) 50%, #004400 100%);
    background-size: 200% 100%;
    width: 0%;
    transition: width 0.3s ease;
    animation: shimmer 1s linear infinite;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.loading-percentage {
    text-align: center;
    margin-top: 10px;
    font-size: 18px;
    font-weight: bold;
    color: var(--terminal-text);
    text-shadow: 0 0 10px var(--terminal-shadow);
}

.loading-footer {
    margin-top: 40px;
    color: var(--terminal-text);
    font-size: 16px;
}

/* Slower, gentler blink effect */
.blink {
    animation: gentleBlink 2s ease-in-out infinite;
}

@keyframes gentleBlink {
    0%, 45%, 55%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.loading-dots {
    display: inline-block;
    width: 20px;
    text-align: left;
}

/* CRT scan line effect - made more subtle */
#loading-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%, 
        rgba(0, 0, 0, 0.1) 50%  /* Reduced from 0.25 to 0.1 */
    );
    background-size: 100% 4px;
    pointer-events: none;
    animation: scanline 12s linear infinite;  /* Slowed from 8s to 12s */
}

@keyframes scanline {
    0% { transform: translateY(0); }
    100% { transform: translateY(10px); }
}

/* Mobile responsive for loading screen */
@media (max-width: 768px) {
    .loading-ascii {
        font-size: 8px;
    }
    
    .boot-line {
        font-size: 12px;
    }
    
    .loading-messages {
        height: 250px;
    }
}
