:root {
    --bg-color: #121212;
    --text-color: #33ff00;
    --accent-color: #33ff00;
    --secondary-bg: #000000;
    --border-color: #33ff00;
    --border-width: 4px;
    --tape-cell-bg: #000000;
    --tape-cell-active: #33ff00;
    --highlight-color: rgba(51, 255, 0, 0.3);
    --crt-overlay: rgba(18, 16, 16, 0.1);
    --shadow-color: rgba(51, 255, 0, 0.4);
}

@font-face {
    font-family: 'PrintChar21';
    src: url('https://db.onlinewebfonts.com/t/056353a27c582b1d9d7028d4f8089882.woff') format('woff');
    /* Fallback to monospace if this specific font isn't available or reliable */
}

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

body {
    font-family: 'PrintChar21', 'VT323', 'Courier New', monospace;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.4;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    text-shadow: 0 0 4px var(--shadow-color);
    overflow-x: hidden;
    font-size: 20px;
    padding: 10px;
}

/* CRT Scanline & Warp Effect */
body::before {
    content: " ";
    display: block;
    position: fixed;
    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: 100;
    background-size: 100% 3px, 3px 100%;
    pointer-events: none;
}

body::after {
    content: " ";
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: rgba(18, 16, 16, 0.1);
    opacity: 0;
    z-index: 100;
    pointer-events: none;
    animation: flicker 0.15s infinite;
}

.screen-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    animation: textShadow 1.6s infinite;
}

/* Screen Warp */
@keyframes textShadow {
    0% { text-shadow: 0.4389924193300864px 0 1px rgba(0,30,255,0.5), -0.4389924193300864px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    5% { text-shadow: 2.7928974010788217px 0 1px rgba(0,30,255,0.5), -2.7928974010788217px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    10% { text-shadow: 0.02956275843481219px 0 1px rgba(0,30,255,0.5), -0.02956275843481219px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    15% { text-shadow: 0.4021853855287816px 0 1px rgba(0,30,255,0.5), -0.4021853855287816px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    20% { text-shadow: 3.4794037899852017px 0 1px rgba(0,30,255,0.5), -3.4794037899852017px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    25% { text-shadow: 1.612563040114954px 0 1px rgba(0,30,255,0.5), -1.612563040114954px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    30% { text-shadow: 0.7015590085143956px 0 1px rgba(0,30,255,0.5), -0.7015590085143956px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    35% { text-shadow: 3.896914047650351px 0 1px rgba(0,30,255,0.5), -3.896914047650351px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    40% { text-shadow: 3.870905614848819px 0 1px rgba(0,30,255,0.5), -3.870905614848819px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    45% { text-shadow: 2.231056963361899px 0 1px rgba(0,30,255,0.5), -2.231056963361899px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    50% { text-shadow: 0.08084290417898504px 0 1px rgba(0,30,255,0.5), -0.08084290417898504px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    55% { text-shadow: 2.3758461067427543px 0 1px rgba(0,30,255,0.5), -2.3758461067427543px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    60% { text-shadow: 2.202193051050636px 0 1px rgba(0,30,255,0.5), -2.202193051050636px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    65% { text-shadow: 2.8638780614874975px 0 1px rgba(0,30,255,0.5), -2.8638780614874975px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    70% { text-shadow: 0.48874025155497314px 0 1px rgba(0,30,255,0.5), -0.48874025155497314px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    75% { text-shadow: 1.8948491305757957px 0 1px rgba(0,30,255,0.5), -1.8948491305757957px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    80% { text-shadow: 0.0833037308038857px 0 1px rgba(0,30,255,0.5), -0.0833037308038857px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    85% { text-shadow: 0.09769827255241735px 0 1px rgba(0,30,255,0.5), -0.09769827255241735px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    90% { text-shadow: 3.443339761481782px 0 1px rgba(0,30,255,0.5), -3.443339761481782px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    95% { text-shadow: 2.1841838852799786px 0 1px rgba(0,30,255,0.5), -2.1841838852799786px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
    100% { text-shadow: 2.6208764473832513px 0 1px rgba(0,30,255,0.5), -2.6208764473832513px 0 1px rgba(255,0,80,0.3), 0 0 3px; }
}

/* Container for Warp Effect */
.crt-container {
    width: 100%;
    height: 100%;
    padding: 20px;
    animation: flicker 0.15s infinite;
    /* Slight curve at edges */
    transform: perspective(1000px) rotateX(0.5deg) scale(0.98);
    transform-origin: 50% 50%;
}

/* Vignette */
.vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-shadow: 0 0 150px rgba(0,0,0,0.9) inset;
    pointer-events: none;
    z-index: 90;
}


/* Screen Flicker Animation */
@keyframes flicker {
    0% { opacity: 0.97; }
    5% { opacity: 0.95; }
    10% { opacity: 0.9; }
    15% { opacity: 0.95; }
    20% { opacity: 0.99; }
    25% { opacity: 0.95; }
    30% { opacity: 0.9; }
    35% { opacity: 0.96; }
    40% { opacity: 0.98; }
    45% { opacity: 0.95; }
    50% { opacity: 0.99; }
    55% { opacity: 0.93; }
    60% { opacity: 0.9; }
    65% { opacity: 0.96; }
    70% { opacity: 1; }
    75% { opacity: 0.97; }
    80% { opacity: 0.95; }
    85% { opacity: 0.92; }
    90% { opacity: 0.98; }
    95% { opacity: 0.99; }
    100% { opacity: 0.94; }
}

.container {
    max-width: 100%;
    margin: 0;
    padding: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 30px;
    flex: 1;
}

header {
    text-align: center;
    border-bottom: var(--border-width) double var(--border-color);
    padding: 20px 0;
    margin-bottom: 10px;
    background: var(--text-color);
    color: var(--bg-color);
}

h1 {
    color: var(--bg-color);
    margin-bottom: 0;
    font-size: 3rem;
    text-transform: uppercase;
    letter-spacing: 4px;
    line-height: 1;
}

p {
    font-size: 1.5rem;
    text-transform: uppercase;
    font-weight: bold;
}

main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

/* Editor Section */
.editor-section {
    display: flex;
    flex-direction: column;
}

.code-container {
    position: relative;
    border: var(--border-width) solid var(--border-color);
    border-radius: 0;
    background-color: var(--secondary-bg);
    overflow: hidden;
    min-height: 300px;
    box-shadow: 8px 8px 0 var(--shadow-color);
}

#code-input, #code-display {
    width: 100%;
    padding: 20px;
    font-family: 'PrintChar21', 'VT323', 'Courier New', monospace;
    font-size: 24px;
    border: none;
    resize: none;
    background: transparent;
    color: var(--text-color);
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: hidden;
    outline: none;
    caret-color: var(--text-color);
    line-height: 1.5;
}

#code-input {
    position: relative;
    z-index: 1;
    display: block;
    height: auto;
    min-height: 200px;
}

#code-display {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    pointer-events: none;
    color: transparent;
    height: 100%;
}

#code-display .highlight {
    background-color: var(--text-color);
    color: var(--secondary-bg);
    border-radius: 0;
    font-weight: bold;
}

/* Controls Section */
.controls-section {
    display: flex;
    gap: 20px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    border: var(--border-width) solid var(--border-color);
    padding: 20px;
    background-color: var(--secondary-bg);
    box-shadow: 8px 8px 0 var(--shadow-color);
}

button {
    padding: 15px 30px;
    background-color: var(--secondary-bg);
    border: var(--border-width) solid var(--border-color);
    color: var(--text-color);
    cursor: pointer;
    border-radius: 0;
    font-size: 20px;
    font-family: 'PrintChar21', 'VT323', 'Courier New', monospace;
    text-transform: uppercase;
    transition: all 0.0s; /* Instant transition for retro feel */
    box-shadow: 4px 4px 0 var(--border-color);
    font-weight: bold;
}

button:hover:not(:disabled) {
    background-color: var(--text-color);
    color: var(--secondary-bg);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--border-color);
}

button:active:not(:disabled) {
    box-shadow: none;
    transform: translate(4px, 4px);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-style: dashed;
}

#btn-run {
    background-color: var(--secondary-bg);
    border-color: var(--border-color);
    color: var(--text-color);
}

#btn-run:hover:not(:disabled) {
    background-color: var(--text-color);
    color: var(--bg-color);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 10px;
    text-transform: uppercase;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 150px;
    height: 10px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 25px;
    background: var(--text-color);
    cursor: pointer;
    border: none;
}

input[type="range"]::-moz-range-thumb {
    width: 15px;
    height: 25px;
    background: var(--text-color);
    cursor: pointer;
    border: none;
    border-radius: 0;
}

/* Visualization Section */
.visualization-section {
    background-color: var(--secondary-bg);
    padding: 15px;
    border-radius: 0;
    border: 2px solid var(--border-color);
    box-shadow: 0 0 10px var(--shadow-color);
}

.tape-container {
    overflow-x: auto;
    padding-bottom: 15px;
    margin-bottom: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--text-color) var(--secondary-bg);
}

.tape-container::-webkit-scrollbar {
    height: 8px;
}

.tape-container::-webkit-scrollbar-track {
    background: var(--secondary-bg);
}

.tape-container::-webkit-scrollbar-thumb {
    background-color: var(--text-color);
    border-radius: 0;
}

.tape {
    display: flex;
    gap: 2px;
    min-width: min-content;
}

.cell {
    width: 60px;
    height: 70px;
    background-color: var(--tape-cell-bg);
    border: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'PrintChar21', 'VT323', 'Courier New', monospace;
    border-radius: 0;
    flex-shrink: 0;
}

.cell.active {
    background-color: var(--tape-cell-active);
    color: var(--secondary-bg);
    border-color: var(--text-color);
    box-shadow: 0 0 20px var(--text-color);
    font-weight: bold;
}

.cell-index {
    font-size: 14px;
    margin-bottom: 5px;
    opacity: 1;
}

.cell-value {
    font-size: 24px;
    font-weight: bold;
}

.pointer-info {
    text-align: center;
    font-family: 'PrintChar21', 'VT323', 'Courier New', monospace;
    color: var(--text-color);
    text-transform: uppercase;
    border-top: 2px dashed var(--border-color);
    padding-top: 15px;
    font-size: 1.2rem;
}

/* IO Section */
.io-section {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.input-group, .output-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 200px;
}

label {
    text-transform: uppercase;
    font-weight: bold;
}

input[type="text"] {
    padding: 15px;
    background-color: var(--secondary-bg);
    border: var(--border-width) solid var(--border-color);
    color: var(--text-color);
    border-radius: 0;
    font-family: 'PrintChar21', 'VT323', 'Courier New', monospace;
    font-size: 20px;
    outline: none;
    box-shadow: 4px 4px 0 var(--shadow-color);
}

.output-box {
    min-height: 150px;
    max-height: 600px;
    background-color: var(--secondary-bg);
    border: var(--border-width) solid var(--border-color);
    border-radius: 0;
    padding: 15px;
    font-family: 'PrintChar21', 'VT323', 'Courier New', monospace;
    white-space: pre-wrap;
    overflow-y: auto;
    box-shadow: 8px 8px 0 var(--shadow-color);
    font-size: 20px;
    line-height: 1.4;
}

.output-box::-webkit-scrollbar {
    width: 16px;
}

.output-box::-webkit-scrollbar-track {
    background: var(--secondary-bg);
    border-left: 2px solid var(--border-color);
}

.output-box::-webkit-scrollbar-thumb {
    background-color: var(--text-color);
    border: 2px solid var(--secondary-bg);
}

@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 1.8rem;
    }

    .controls-section {
        gap: 10px;
        padding: 10px;
    }

    button {
        padding: 8px 12px;
        font-size: 14px;
        flex: 1 1 auto;
    }

    .speed-control {
        width: 100%;
        justify-content: center;
        margin-left: 0;
        margin-top: 5px;
    }

    .speed-control input {
        flex: 1;
    }

    .io-section {
        flex-direction: column;
        gap: 15px;
    }

    .input-group, .output-group {
        min-width: 100%;
    }
}
