/* BBC Micro MODE 7 Authentic Interface */

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

/* Import authentic BBC Micro Bedstead font */
@font-face {
    font-family: 'Bedstead';
    src: url('../fonts/bedstead.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

/* Import Bedstead Ultra Condensed for double-height text */
@font-face {
    font-family: 'Bedstead Ultra Condensed';
    src: url('../fonts/bedstead-ultracondensed.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

:root {
    --char-width: 2.2vmin;
    --char-height: 2.7vmin;
    --cols: 40;
    --rows: 25;
}

body {
    font-family: 'Bedstead', 'Courier New', monospace;
    background: #1a1a1a;
    color: #fff;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* MODE 7 screen - exactly 40x25 characters */
.container {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000 url('../images/cub-monitor.png') no-repeat center center;
    background-size: contain;
    position: relative;
}

/* CRT Toggle Button on Bezel */
.bezel-button {
    position: fixed;
    width: 60px;
    height: 60px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border: 2px solid #444;
    border-radius: 50%;
    color: #888;
    font-family: 'Bedstead', 'Courier New', monospace;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.5),
        inset 0 2px 4px rgba(255,255,255,0.1),
        inset 0 -2px 4px rgba(0,0,0,0.5);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sound button positioning (right side, top button) */
#sound-toggle {
    bottom: 26%;
    right: 8%;
    font-size: 24px;
}

/* CRT button positioning (right side, middle button) */
#crt-toggle {
    bottom: 17%;
    right: 8%;
}

/* Map button positioning (right side, above GitHub) */
#map-button {
    bottom: 35%;
    right: 8%;
    font-size: 10px;
}

/* GitHub button positioning (right side, bottom button) */
#github-link {
    position: fixed;
    bottom: 8%;
    right: 8%;
    font-size: 9px;
    text-decoration: none;
}

.bezel-button:hover {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border-color: #666;
    color: #aaa;
    box-shadow: 
        0 6px 12px rgba(0,0,0,0.6),
        inset 0 2px 4px rgba(255,255,255,0.15),
        inset 0 -2px 4px rgba(0,0,0,0.5);
}

.bezel-button:active {
    transform: translateY(2px);
    box-shadow: 
        0 2px 4px rgba(0,0,0,0.5),
        inset 0 2px 6px rgba(0,0,0,0.7);
}

.bezel-button.active {
    background: linear-gradient(145deg, #1a4a1a, #0a3a0a);
    border-color: #0f0;
    color: #0f0;
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.5),
        inset 0 2px 4px rgba(0,255,0,0.3),
        0 0 20px rgba(0,255,0,0.3);
}

.button-label {
    text-align: center;
    line-height: 1.2;
}

.screen {
    display: none;
    width: calc(var(--char-width) * var(--cols));
    background: #000;
    color: #fff;
    position: relative;
    z-index: 1;
    border-radius: 4px;
    box-shadow: 
        0 0 20px rgba(0, 255, 0, 0.1),
        inset 0 0 100px rgba(0, 0, 0, 0.3);
}

/* CRT scanline effect - always visible */
.screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 1000;
}

/* CRT glow effect - always visible */
.screen::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at center, transparent 0%, rgba(0, 0, 0, 0.2) 100%);
    pointer-events: none;
    z-index: 999;
}

/* Enhanced CRT Filter Effects (togglable) */
.screen.crt-filter {
    animation: crt-flicker 0.15s infinite;
}

/* Stronger scanlines when CRT filter is on */
.screen.crt-filter::before {
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.3) 0px,
        rgba(0, 0, 0, 0.3) 1px,
        transparent 1px,
        transparent 2px
    );
}

/* RGB chromatic aberration effect */
.screen.crt-filter .game-container,
.screen.crt-filter .login-container {
    text-shadow: 
        0.5px 0 0 rgba(255, 0, 0, 0.5),
        -0.5px 0 0 rgba(0, 255, 255, 0.5);
}

/* Screen curvature effect */
.screen.crt-filter {
    border-radius: 8px;
    transform: perspective(1000px) rotateY(0deg);
}

/* Phosphor glow effect */
.screen.crt-filter::after {
    background: radial-gradient(
        ellipse at center, 
        rgba(0, 255, 0, 0.05) 0%, 
        rgba(0, 0, 0, 0.3) 100%
    );
    box-shadow: inset 0 0 100px rgba(0, 255, 0, 0.1);
}

/* CRT flicker animation */
@keyframes crt-flicker {
    0% { opacity: 0.98; }
    50% { opacity: 1; }
    100% { opacity: 0.98; }
}

/* Vignette effect when CRT filter is on */
.screen.crt-filter {
    box-shadow: 
        0 0 20px rgba(0, 255, 0, 0.2),
        inset 0 0 100px rgba(0, 0, 0, 0.5),
        inset 0 0 200px rgba(0, 0, 0, 0.3);
}

.screen.active {
    display: block;
}

.screen {
    display: none;
}

.screen.active {
    display: flex;
    flex-direction: column;
    width: calc(var(--char-width) * var(--cols));
    height: calc(var(--char-height) * var(--rows));
    background: #000;
    color: #fff;
    position: relative;
    z-index: 1;
    border-radius: 4px;
    box-shadow: 
        0 0 20px rgba(0, 255, 0, 0.1),
        inset 0 0 100px rgba(0, 0, 0, 0.3);
}

/* Graphics area - appears in scrolling content, not fixed height */
/* Graphics overlay - positioned absolutely over scrolled text */
.graphics-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: #000;
    text-align: center;
    z-index: 10;
    pointer-events: none; /* Allow clicking through to text below */
    max-height: 70%; /* Don't cover the entire scrolling area - leave room for prompt */
    overflow: hidden;
}

.graphics-overlay img {
    width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
}

/* Status area - rows 0-5 (6 rows) */
.status-area {
    height: calc(var(--char-height) * 6);
    border-bottom: 1px solid #444;
    padding: 0;
    overflow: hidden;
    background: #000;
    position: relative;
    z-index: 20; /* Above graphics overlay */
}

#status-messages {
    height: 100%;
    padding: 2px 4px;
    overflow-y: auto;
    overflow-x: hidden;
    color: #ffff00;
    font-family: 'Bedstead', 'Courier New', monospace;
    font-size: 2.2vmin;
    line-height: var(--char-height);
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

/* Hide scrollbar in status area */
#status-messages::-webkit-scrollbar {
    width: 0;
    display: none;
}

#status-messages {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

/* Main game area - rows 7-23 (17 rows) with inline prompt */
.main-game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Message log - scrolling area with inline prompt */
#message-log {
    flex: 1;
    padding: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #000;
    color: #fff;
    font-family: 'Bedstead', 'Courier New', monospace;
    font-size: 2.2vmin;
    line-height: var(--char-height);
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

/* Hide scrollbar but keep functionality */
#message-log::-webkit-scrollbar {
    width: 0;
    display: none;
}

#message-log {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

/* Prompt and command display inline within message log */
#prompt, #command-display, .cursor {
    display: inline; /* Force inline display even in flex container */
}

.prompt {
    color: #ffff00;
}

.command-display {
    color: #ffff00;
}

/* Hidden input field for capturing keystrokes */
.hidden-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

/* Terminal container - full 40x25 scrolling area */
.terminal-container {
    width: calc(var(--char-width) * var(--cols));
    height: calc(var(--char-height) * var(--rows));
    background: #000;
    position: relative;
    z-index: 10;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Terminal text output - scrolling pre element */
.terminal-text {
    font-family: 'Bedstead', 'Courier New', monospace;
    font-size: 2.2vmin;
    line-height: var(--char-height);
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    padding: 4px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    color: #fff;
}

/* Hide scrollbar but keep functionality */
.terminal-text::-webkit-scrollbar {
    width: 0;
    display: none;
}

.terminal-text {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

/* Inline prompt at bottom of terminal */
.prompt-inline {
    color: #ffff00;
    font-family: 'Bedstead', 'Courier New', monospace;
    font-size: 2.2vmin;
    line-height: var(--char-height);
}

/* Command display inline with prompt */
.command-inline {
    color: #ffff00;
    font-family: 'Bedstead', 'Courier New', monospace;
    font-size: 2.2vmin;
    line-height: var(--char-height);
}

/* Hidden input field for capturing keystrokes */
.hidden-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

.cursor {
    animation: blink 1s step-end infinite;
}

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

/* Message styling within terminal */
.msg-system {
    color: #00ffff;
}

.msg-error {
    color: #ff0000;
}

.msg-action {
    color: #ffff00;
}

.msg-combat {
    color: #ff00ff;
}

.msg-death {
    color: #ff0000;
    animation: blink 0.5s infinite;
}

.msg-normal {
    color: #fff;
}

/* Double-height text (MODE 7 teletext style) */
.double-height {
    font-family: 'Bedstead Ultra Condensed', 'Bedstead', 'Courier New', monospace;
    font-size: 4.4vmin;
    line-height: 5.4vmin;
}

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

/* Responsive - scale down on smaller screens */
@media (max-width: 800px) {
    :root {
        --char-width: 1.5vmin;
        --char-height: 2vmin;
    }
    
    .game-container, #message-log, #command-input, #status-messages {
        font-size: 1.75vmin;
    }
}

@media (max-width: 600px) {
    :root {
        --char-width: 1.25vmin;
        --char-height: 1.75vmin;
    }
    
    .game-container, #message-log, #command-input, #status-messages {
        font-size: 1.5vmin;
    }
}

/* Hide elements not needed in MODE 7 */
.room-graphic, .header, .room-info, .status-bar, .inventory-area, .power-led {
    display: none !important;
}

/* BBC Micro Teletext Color Classes */
/* Based on MODE 7 Teletext palette */
.teletext-red {
    color: #ff0000;
}

.teletext-green {
    color: #00ff00;
}

.teletext-yellow {
    color: #ffff00;
}

.teletext-blue {
    color: #0000ff;
}

.teletext-magenta {
    color: #ff00ff;
}

.teletext-cyan {
    color: #00ffff;
}

.teletext-white {
    color: #ffffff;
}
