@font-face {
    font-family: 'VT323';
    font-style: normal;
    font-weight: 400;
    src: url('/fonts/vt323.woff2') format('woff2');
    font-display: swap;
}

:root {
    --bg: #ffffff;
    --text: #000000;
    --border: #000000;
    --muted: #555555;
}

:root[data-theme="dark"] {
    --bg: #000000;
    --text: #ffffff;
    --border: #ffffff;
    --muted: #9a9a9a;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 1.125rem;
    line-height: 1.5;
}

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg); border-left: 1px solid var(--border); }
::-webkit-scrollbar-thumb { background: var(--text); }
* { scrollbar-width: thin; scrollbar-color: var(--text) var(--bg); }
::selection { background: var(--text); color: var(--bg); }

a { color: var(--text); text-decoration: underline; }
a:hover { background: var(--text); color: var(--bg); }
a, button, .tb-btn { cursor: pointer; }

/* --- Window chrome (matches the rest of the site) --- */

.window.editor-window {
    height: 100vh;
    max-width: 1100px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

body.maximize .window.editor-window { max-width: none; }

.window.editor-window.minimized .menu-bar,
.window.editor-window.minimized .app-container { display: none; }

.title-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.3rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: #d4d4d4;
}

:root[data-theme="dark"] .title-bar {
    background: #2b2b2b;
}

.tb-btn {
    width: 1.25rem;
    height: 1.25rem;
    border: 1px solid var(--border);
    user-select: none;
    flex-shrink: 0;
    position: relative;
    cursor: pointer;
    background: var(--bg);
}
.tb-btn:hover { background: var(--text); }
.tb-close-btn::before,
.tb-close-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0.65rem;
    height: 1px;
    background: var(--text);
}
.tb-close-btn::before { transform: translate(-50%, -50%) rotate(45deg); }
.tb-close-btn::after { transform: translate(-50%, -50%) rotate(-45deg); }
.tb-close-btn:hover { background: var(--text); }
.tb-close-btn:hover::before,
.tb-close-btn:hover::after { background: var(--bg); }
.tb-min-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0.6rem;
    height: 2px;
    background: var(--text);
}
.tb-min-btn:hover::after { background: var(--bg); }
.tb-max-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0.55rem;
    height: 0.55rem;
    border: 1px solid var(--text);
}
.tb-max-btn:hover::after { border-color: var(--bg); }
.tb-theme-btn {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23000000" d="M20.9 13.9a8.4 8.4 0 1 1-9.8-9.8 6.7 6.7 0 0 0 9.8 9.8z"/></svg>');
    background-size: 68%;
    background-position: center;
    background-repeat: no-repeat;
}
.tb-theme-btn:hover {
    background-color: var(--text);
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23ffffff" d="M20.9 13.9a8.4 8.4 0 1 1-9.8-9.8 6.7 6.7 0 0 0 9.8 9.8z"/></svg>');
}
:root[data-theme="dark"] .tb-theme-btn {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4.2" fill="%23ffffff"/><g stroke="%23ffffff" stroke-width="1.8" stroke-linecap="round"><path d="M12 2.5v2.4"/><path d="M12 19.1v2.4"/><path d="M2.5 12h2.4"/><path d="M19.1 12h2.4"/><path d="M5 5l1.7 1.7"/><path d="M17.3 17.3L19 19"/><path d="M19 5l-1.7 1.7"/><path d="M6.7 17.3L5 19"/></g></svg>');
}
:root[data-theme="dark"] .tb-theme-btn:hover {
    background-color: var(--text);
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4.2" fill="%23000000"/><g stroke="%23000000" stroke-width="1.8" stroke-linecap="round"><path d="M12 2.5v2.4"/><path d="M12 19.1v2.4"/><path d="M2.5 12h2.4"/><path d="M19.1 12h2.4"/><path d="M5 5l1.7 1.7"/><path d="M17.3 17.3L19 19"/><path d="M19 5l-1.7 1.7"/><path d="M6.7 17.3L5 19"/></g></svg>');
}

.tb-title { flex: 1; font-size: 1.25rem; }
.tb-title a { text-decoration: none; }
.tb-title a:hover { text-decoration: underline; }

.menu-bar {
    display: flex;
    flex-wrap: wrap;
    row-gap: 0.25rem;
    gap: 1.5rem;
    padding: 0.35rem 1rem;
    border-bottom: 1px solid var(--border);
}
.menu-bar a { text-decoration: none; }
.menu-bar a:hover, .menu-bar a.active { text-decoration: underline; }

/* --- Layout --- */

.app-container {
    flex: 1;
    min-height: 0;
    display: flex;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    padding: 16px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    scrollbar-width: none;
    display: flex;
    flex-direction: column;
}
.sidebar::-webkit-scrollbar { display: none; }

#logo {
    display: block;
    width: 60%;
    margin: 0 auto 24px;
    filter: grayscale(1) contrast(1.05) blur(0.5px);
}

:root[data-theme="dark"] #logo {
    filter: invert(1) grayscale(1) contrast(1.05) blur(0.5px);
}

.sidebar-group { margin-bottom: 16px; }
.sidebar-group h4 {
    margin: 0 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
    font-weight: 400;
    text-transform: lowercase;
}

.sidebar button, .sidebar select, .sidebar a.resource-link {
    box-sizing: border-box;
    display: block;
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 1rem;
    text-align: left;
    margin-bottom: 8px;
    text-decoration: none;
    cursor: pointer;
    text-transform: lowercase;
}
.sidebar button:hover, .sidebar select:hover, .sidebar a.resource-link:hover {
    background: var(--text);
    color: var(--bg);
}
.sidebar select { appearance: none; -webkit-appearance: none; }
.sidebar a.resource-link { display: flex; justify-content: space-between; align-items: center; }
.sidebar a.resource-link::after { content: '\2197'; }

.feature-list { list-style: none; padding-left: 0; margin: 0; font-size: 1rem; line-height: 1.6; text-transform: lowercase; }
.feature-list li { margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.feature-list kbd {
    padding: 1px 5px;
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 0.875rem;
    margin-left: auto;
}

/* --- Editor --- */

.editor-wrapper { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#editor-source { display: none; }

.editor-title-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 15px;
    border-bottom: 1px solid var(--border);
    background: #d4d4d4;
    font-size: 1.125rem;
}

:root[data-theme="dark"] .editor-title-bar {
    background: #2b2b2b;
}
.editor-title-bar::before { content: '\25CF'; font-size: 18px; color: var(--text); opacity: 0; transition: opacity 0.3s; }
body.has-unsaved-changes .editor-title-bar::before { opacity: 1; }
.filename-input { background: transparent; border: none; outline: none; font-family: inherit; font-size: inherit; color: var(--text); padding: 2px 5px; }
.filename-input:focus { box-shadow: 0 0 0 1px var(--text); }
.file-extension { opacity: 0.7; margin-left: 1px; }

.CodeMirror {
    flex: 1;
    min-height: 0;
    height: 100%;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 1.125rem;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.35);
}

:root[data-theme="dark"] .CodeMirror {
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.25);
}
.CodeMirror-gutters { background: var(--bg); border-right: 1px solid var(--border); }
.CodeMirror-linenumber { color: var(--muted); }
.CodeMirror-cursor { border-left: 2px solid var(--text); }
.CodeMirror-selected { background: var(--text); opacity: 0.2; }
.CodeMirror-focused .CodeMirror-selected { background: var(--text); opacity: 0.3; }
.CodeMirror-matchingbracket { background: var(--text); color: var(--bg); }

.cm-comment { color: var(--muted); font-style: italic; }
.cm-keyword, .cm-type, .cm-builtin { font-weight: bold; }
.cm-atom, .cm-number { color: var(--muted); }

.status-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 20px;
    padding: 6px 15px;
    border-top: 1px solid var(--border);
    font-size: 1rem;
    color: var(--text);
}

/* --- CodeMirror dialog & hints, mono style --- */

.CodeMirror-dialog {
    background: var(--bg);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    font-family: inherit;
}
.CodeMirror-dialog input { font-family: inherit; }
.CodeMirror-hints {
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
}
.CodeMirror-hint { color: var(--text); }
li.CodeMirror-hint-active { background: var(--text); color: var(--bg); }
.CodeMirror-hint.snippet-hint { font-weight: bold; }

/* --- Noise overlay --- */

.noise-svg {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    mix-blend-mode: multiply;
    opacity: 0.4;
    z-index: 9999;
}

.noise-white { display: none; }

:root[data-theme="dark"] .noise-svg {
    mix-blend-mode: screen;
}

:root[data-theme="dark"] .noise-black { display: none; }
:root[data-theme="dark"] .noise-white { display: block; }

/* --- Shutdown --- */

.shutdown-screen {
    position: fixed;
    inset: 0;
    background: #000;
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    z-index: 10000;
    cursor: pointer;
}

body.shutdown .shutdown-screen {
    display: flex;
}

.shutdown-text {
    font-size: 1.5rem;
    line-height: 1.6;
    animation: shutdown-flicker 3s infinite;
}

.reboot-hint {
    color: #888;
    font-size: 1.125rem;
}

@keyframes shutdown-flicker {
    0%, 100% { opacity: 1; }
    91% { opacity: 1; }
    92% { opacity: 0.55; }
    93% { opacity: 1; }
    96% { opacity: 0.8; }
    97% { opacity: 1; }
}

@media (max-width: 820px) {
    .app-container { flex-direction: column; }
    .sidebar {
        width: 100%;
        max-height: 30vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .menu-bar { font-size: 0.875rem; gap: 0.5rem; padding: 0.25rem 0.5rem; }
    .tb-btn { width: 1rem; height: 1rem; }
}
