*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --term-color: #bbf877;
    --term-bg: #071008;
    --term-glow: rgba(187, 248, 119, 0.4);
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    background-color: #000;
    font-family: 'VT323', monospace;
    overflow: hidden;
}

#crt {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: var(--term-bg);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.08'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
}

#crt::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(to bottom,
            rgba(255, 255, 255, 0) 50%,
            rgba(0, 0, 0, 0.25) 50%);
    background-size: 100% 4px;
    z-index: 10;
    pointer-events: none;
}

#terminal-container {
    position: relative;
    z-index: 5;
    flex-grow: 1;
    padding: 30px 40px;
    overflow-y: auto;
    color: var(--term-color);
    font-size: 1.5rem;
    letter-spacing: 1px;
    line-height: 1.3;
    text-shadow: 0 0 3px var(--term-glow);
    box-sizing: border-box;
}

.output {
    margin-bottom: 10px;
    white-space: pre-wrap;
}

.inverted {
    background-color: var(--term-color);
    color: var(--term-bg);
    text-shadow: none;
    display: inline-block;
    padding: 0 8px;
}

.prompt-line {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.prompt {
    margin-right: 15px;
}

pre {
    font-family: inherit;
    font-size: inherit;
}

#cmd-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    border: none;
    outline: none;
    padding: 0;
}

#cmd-before,
#cmd-cursor,
#cmd-after {
    white-space: pre;
}

.cursor {
    background-color: var(--term-color);
    color: var(--term-bg);
    text-shadow: none;
    animation: blink 1s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

footer {
    position: relative;
    z-index: 5;
    padding: 15px;
    border-top: 1px dashed rgba(187, 248, 119, 0.5);
    display: flex;
    justify-content: center;
    gap: 40px;
    font-size: 1.2rem;
}

footer button {
    background: transparent;
    border: none;
    color: var(--term-color);
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    text-shadow: inherit;
    transition: all 0.2s ease;
}

footer button:hover {
    color: var(--term-bg);
    background-color: var(--term-color);
    text-shadow: none;
}

/* --- MODAL UI STYLES --- */
#modal-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 50;
    justify-content: center;
    align-items: center;
}

.tui-modal {
    display: none;
    position: relative;
    width: 90%;
    max-width: 500px;
    background: var(--term-bg);
    border: 2px solid var(--term-color);
    padding: 25px;
    color: var(--term-color);
    box-shadow: 0 0 20px var(--term-glow);
}

.tui-modal-title {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--term-bg);
    padding: 0 10px;
    font-weight: bold;
    letter-spacing: 2px;
}

.tui-modal-content {
    font-size: 1.3rem;
    margin-bottom: 20px;
}

.tui-modal-content a {
    color: var(--term-color);
    text-decoration: underline;
    text-underline-offset: 4px;
}

.tui-textarea {
    width: 100%;
    background: transparent;
    border: 1px solid rgba(187, 248, 119, 0.4);
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    padding: 10px;
    margin-top: 10px;
    box-sizing: border-box;
    resize: none;
    outline: none;
}

.tui-textarea:focus {
    border-color: var(--term-color);
    box-shadow: inset 0 0 5px var(--term-glow);
}

.tui-modal-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

.tui-btn {
    background: transparent;
    border: none;
    color: var(--term-color);
    font-family: inherit;
    font-size: 1.4rem;
    cursor: pointer;
    outline: none;
    padding: 2px 8px;
}

.tui-btn:hover {
    background: var(--term-color);
    color: var(--term-bg);
    text-shadow: none;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(187, 248, 119, 0.3);
}

/* --- MARKDOWN STYLING --- */
/* Standardize and color-match inline preview images */
.markdown-body img {
    height: 200px !important;
    width: auto;
    max-width: 100%;
    object-fit: contain;

    margin: 20px 0;
    border: 1px dashed rgba(187, 248, 119, 0.4);
    cursor: pointer;

    /* --- COLOR MATCHING FILTER --- */
    /*         grayscale(100%) isolates luminescence.
               sepia(100%) pushes it to yellow.
               hue-rotate(70deg) shifts it precisely to #bbf877 yellowish-green.
               saturate(200%) adds the phosphor intensity.
               contrast(1.2) adds definition. */
    filter: grayscale(100%) sepia(100%) hue-rotate(70deg) saturate(200%) contrast(1.2);
    opacity: 0.9;
    transition: all 0.2s ease;
    display: block;
}

/* Subtle hover effect, matching #bbf877 glow */
.markdown-body img:hover {
    opacity: 1;
    /* Dialed back saturation on hover, increased contrast for definition */
    filter: grayscale(100%) sepia(100%) hue-rotate(70deg) saturate(250%) contrast(1.4);
    border: 1px solid rgba(187, 248, 119, 0.8);
    box-shadow: 0 0 10px rgba(187, 248, 119, 0.3);
}

.markdown-body h1,
h2,
h3,
h4,
h5,
h6 {
    margin-block-start: 0.2em;
    margin-bottom: 0;
}

.markdown-body p {
    margin-top: 0;
    margin-bottom: 0;
    max-width: 100ch;
}

.markdown-body ul,
.markdown-body ol {
    margin-top: 0;
    margin-bottom: 0;
    max-width: 100ch;
}

.markdown-body li {
    margin-bottom: 0;
}

.markdown-body code,
.markdown-body pre,
.markdown-body pre code {
    font-size: 1.1rem;
}

.markdown-body code:not(pre code) {
    color: #74a65f;
    margin: 0.15em 0.3em;
    border-radius: 2px;
}

.markdown-body pre {
    background-color: rgba(0, 0, 0, 0.5);
    border: 1px dashed var(--term-color);
    padding: 15px;
    margin: 1.2rem 0;
    overflow-x: auto;
    max-width: 120ch;
    box-sizing: border-box;
}

.markdown-body pre code {
    background-color: transparent;
    color: inherit;
    padding: 0;
}

/* --- MARKDOWN LINKS --- */
.markdown-body a,
a:visited,
a code {
    color: #ffff00 !important;
    text-decoration: none;
    border-bottom: 1px dashed #ffff00;
    transition: all 0.1s ease;
    background-color: transparent;
}

.markdown-body a:hover,
a:hover code {
    background-color: #ffff00;
    color: #000 !important;
    /* Invert the text color on hover for a block-cursor feel */
    border-bottom-style: solid;
}

/* --- BOOT LOGO --- */
.boot-logo-container {
    margin: 20px 0;
    display: flex;
    align-items: center;
}

.boot-logo {
    width: 60px;
    height: auto;
    filter: grayscale(100%) sepia(100%) hue-rotate(70deg) saturate(200%) contrast(1.2);
    opacity: 0.9;
    filter: grayscale(100%) sepia(100%) hue-rotate(70deg) saturate(200%) contrast(1.2) drop-shadow(0 0 5px rgba(187, 248, 119, 0.4));
}

/* --- SYSTEM LOCKDOWN STATE --- */
body.system-lockdown {
    --term-color: #ff3333;
    --term-glow: rgba(255, 51, 51, 0.6);
    pointer-events: none;
}

body.system-lockdown #crt {
    background-color: #1a0505;
}

body.system-lockdown footer {
    border-top-color: rgba(255, 51, 51, 0.5);
}

body.system-lockdown .cursor {
    animation: none;
    opacity: 1;
}

body.system-lockdown #cmd-input {
    display: none;
}

body.system-lockdown .moving-scanline {
    animation-play-state: paused;
}