/* Terminal v2 — mytekOS */

/*
 * JetBrains Mono Nerd Font (SIL OFL 1.1, license in assets/fonts/).
 * Subset to Latin + box drawing + the specific icon glyphs the prompt uses,
 * which is why it is ~14KB per weight instead of the 2.5MB full font.
 * Self-hosting matters beyond the glyphs: the old stack named JetBrains Mono,
 * Fira Code and Cascadia Code without shipping any of them, so Chromebook and
 * Linux students fell through to the generic monospace default and saw a
 * different terminal than Mac and Windows students did.
 * The Mono variant is used deliberately: every icon has the same 600-unit
 * advance as 'M', so glyphs never break column alignment in tmux, top, or the
 * terminal games.
 */
@font-face {
    font-family: 'JetBrainsMono NF';
    src: url('/assets/fonts/jetbrainsmono-nf-400.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'JetBrainsMono NF';
    src: url('/assets/fonts/jetbrainsmono-nf-700.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --term-bg: #0d1117;
    --term-text: #c9d1d9;
    --term-accent: #7c3aed;
    --term-green: #3fb950;
    --term-red: #f85149;
    --term-blue: #58a6ff;
    --term-yellow: #d29922;
    --term-muted: #6e7681;
    --term-font: 'JetBrainsMono NF', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', 'Monaco', monospace;
    --term-font-size: 13px;
    --term-scrollbar-track: #161b22;
    --term-scrollbar-thumb: #30363d;
    --term-scrollbar-thumb-hover: #484f58;
}

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

body {
    background: var(--term-bg);
    color: var(--term-text);
    font-family: var(--term-font);
    font-size: var(--term-font-size);
    line-height: 1.5;
    overflow: hidden;
}

#terminal {
    width: 100%;
    height: 100vh;
    padding: 12px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#output {
    white-space: pre-wrap;
    word-wrap: break-word;
    flex: 1;
    user-select: text;
    -webkit-user-select: text;
    display: flex;
    flex-direction: column;
}

/* Spacer pushes output content to the bottom when there's little output.
   Collapses to nothing when output fills the container. */
#output::before {
    content: '';
    flex: 1 1 auto;
}

#output > div,
#output > pre,
#output > table {
    min-height: 1.5em;
    flex-shrink: 0;
}

#input-line {
    display: flex;
    align-items: baseline;
    flex-shrink: 0;
    padding: 2px 0;
}

#prompt {
    color: var(--term-green);
    font-weight: 600;
    white-space: nowrap;
    padding-right: 6px;
    opacity: 0.85;
    transition: opacity 0.2s ease;
}

#input-line:focus-within #prompt {
    opacity: 1;
}

#input {
    flex: 1;
    background: none;
    border: none;
    color: var(--term-text);
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    outline: none;
    caret-color: var(--term-accent);
}

/* Output styling */
.error {
    color: var(--term-red);
}

.success {
    color: var(--term-green);
}

.info {
    color: var(--term-blue);
}

.muted {
    color: var(--term-muted);
}

.bold {
    font-weight: 700;
}

/* Command echo line */
.cmd-line .cmd-prompt {
    color: var(--term-green);
    font-weight: 600;
}

.cmd-line .cmd-text {
    color: var(--term-text);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 4px 0;
}

th {
    text-align: left;
    padding: 2px 8px 2px 0;
    color: var(--term-blue);
    font-weight: 600;
    border-bottom: 1px solid var(--term-scrollbar-thumb);
}

td {
    padding: 1px 8px 1px 0;
    text-align: left;
}

/* Preformatted blocks */
pre {
    margin: 4px 0;
    font-family: inherit;
    white-space: pre-wrap;
}

/* Links in output */
a {
    color: var(--term-blue);
    text-decoration: underline;
}

a:hover {
    color: var(--term-accent);
}

/* Loading animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#loading-indicator {
    color: var(--term-accent);
    animation: pulse 1.2s ease-in-out infinite;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--term-scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--term-scrollbar-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--term-scrollbar-thumb-hover);
}

/* Text selection */
::selection {
    background: rgba(124, 58, 237, 0.35);
    color: inherit;
}

::-moz-selection {
    background: rgba(124, 58, 237, 0.35);
    color: inherit;
}

/* Directory entries in ls */
.dir-entry {
    color: var(--term-blue);
    font-weight: 600;
}

/* Executable file entries in ls */
.exec-entry {
    color: var(--term-green);
    font-weight: 600;
}

/* Shared file entries in ls */
.shared-entry {
    color: #56d4dd;
}

/* Permission string */
.perm {
    color: var(--term-yellow);
}

/* Section headers for help */
.section-header {
    color: var(--term-accent);
    font-weight: 700;
    margin-top: 4px;
}

/* ── Python Syntax Highlighting ──────────────────────── */

.py-keyword   { color: var(--term-accent); }
.py-string    { color: var(--term-green); }
.py-comment   { color: var(--term-muted); font-style: italic; }
.py-number    { color: var(--term-yellow); }
.py-builtin   { color: var(--term-blue); }
.py-decorator { color: var(--term-yellow); }

.lua-keyword   { color: var(--term-accent); }
.lua-string    { color: var(--term-green); }
.lua-comment   { color: var(--term-muted); font-style: italic; }
.lua-number    { color: var(--term-yellow); }
.lua-builtin   { color: var(--term-blue); }

.c-keyword   { color: var(--term-accent); }
.c-string    { color: var(--term-green); }
.c-comment   { color: var(--term-muted); font-style: italic; }
.c-number    { color: var(--term-yellow); }
.c-builtin   { color: var(--term-blue); }
.c-preproc   { color: var(--term-red); }

.js-keyword   { color: var(--term-accent); }
.js-string    { color: var(--term-green); }
.js-comment   { color: var(--term-muted); font-style: italic; }
.js-number    { color: var(--term-yellow); }
.js-builtin   { color: var(--term-blue); }

.php-keyword   { color: var(--term-accent); }
.php-string    { color: var(--term-green); }
.php-comment   { color: var(--term-muted); font-style: italic; }
.php-number    { color: var(--term-yellow); }
.php-builtin   { color: var(--term-blue); }
.php-variable  { color: var(--term-red); }
.php-tag       { color: var(--term-red); }

/* HTML, CSS, shell and vim script. Same four roles as every language above,
   so a student moving between files reads the same colours as the same kinds
   of thing: accent for the structural word, green for text, grey for a note to
   yourself, yellow for a number. */
.html-tag     { color: var(--term-accent); }
.html-attr    { color: var(--term-blue); }
.html-value   { color: var(--term-green); }
.html-comment { color: var(--term-muted); font-style: italic; }

.css-selector { color: var(--term-accent); }
.css-prop     { color: var(--term-blue); }
.css-string   { color: var(--term-green); }
.css-number   { color: var(--term-yellow); }
.css-comment  { color: var(--term-muted); font-style: italic; }

.sh-keyword   { color: var(--term-accent); }
.sh-builtin   { color: var(--term-blue); }
.sh-string    { color: var(--term-green); }
.sh-var       { color: var(--term-red); }
.sh-comment   { color: var(--term-muted); font-style: italic; }

.vim-command  { color: var(--term-accent); }
.vim-option   { color: var(--term-blue); }
.vim-string   { color: var(--term-green); }
.vim-number   { color: var(--term-yellow); }
.vim-comment  { color: var(--term-muted); font-style: italic; }

.editor-highlight-layer {
    position: absolute;
    top: 0;
    left: 48px;
    right: 0;
    bottom: 0;
    padding: 8px 12px;
    font-family: var(--term-font);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre;
    tab-size: 2;
    overflow: hidden;
    pointer-events: none;
    color: var(--term-text);
    margin: 0;
    z-index: 0;
}

/* ── Turtle Graphics Overlay ─────────────────────────── */

#turtle-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 30px;
    z-index: 100;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: auto;
}

#turtle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-family: var(--term-font);
    font-size: 13px;
}

#turtle-canvas {
    position: relative;
    width: 500px;
    height: 350px;
    margin: 8px auto;
    background: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

#turtle-canvas canvas {
    position: absolute;
    top: 0;
    left: 0;
}

/* ── Text Editor Overlay ─────────────────────────────── */

#editor-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--term-bg);
    z-index: 100;
}

#editor-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid var(--term-scrollbar-thumb);
    flex-shrink: 0;
}

#editor-filename {
    color: var(--term-accent);
    font-weight: 600;
}

#editor-modified {
    color: var(--term-yellow);
    font-size: 0.9em;
}

#editor-status {
    margin-left: auto;
    color: var(--term-muted);
    font-size: 0.9em;
}

#editor-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

#editor-line-numbers {
    width: 48px;
    padding: 8px 8px 8px 4px;
    text-align: right;
    color: var(--term-muted);
    font-family: var(--term-font);
    font-size: var(--term-font-size);
    line-height: 1.5;
    white-space: pre;
    overflow: hidden;
    user-select: none;
    border-right: 1px solid var(--term-scrollbar-thumb);
    flex-shrink: 0;
}

#editor-textarea {
    flex: 1;
    padding: 8px 12px;
    background: transparent;
    color: var(--term-text);
    font-family: var(--term-font);
    font-size: var(--term-font-size);
    line-height: 1.5;
    border: none;
    outline: none;
    resize: none;
    white-space: pre;
    overflow-y: auto;
    overflow-x: auto;
    tab-size: 2;
}

#editor-textarea::selection {
    background: rgba(124, 58, 237, 0.35);
}

#editor-footer {
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-top: 1px solid var(--term-scrollbar-thumb);
    color: var(--term-muted);
    font-size: 0.85em;
    flex-shrink: 0;
}

#editor-footer span {
    color: var(--term-text);
    font-weight: 600;
}

/* ── Vim Editor Overlay ──────────────────────────────────── */

#vim-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--term-bg);
    z-index: 100;
}

#vim-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid var(--term-scrollbar-thumb);
    flex-shrink: 0;
}

#vim-filename {
    color: var(--term-accent);
    font-weight: 600;
}

#vim-modified {
    color: var(--term-yellow);
    font-size: 0.9em;
}

#vim-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#vim-line-numbers {
    width: 48px;
    padding: 8px 8px 8px 4px;
    text-align: right;
    color: var(--term-muted);
    font-family: var(--term-font);
    font-size: var(--term-font-size);
    line-height: 1.5;
    white-space: pre;
    overflow: hidden;
    user-select: none;
    border-right: 1px solid var(--term-scrollbar-thumb);
    flex-shrink: 0;
}

#vim-textarea-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#vim-textarea {
    width: 100%;
    height: 100%;
    padding: 8px 12px;
    background: transparent;
    color: var(--term-text);
    font-family: var(--term-font);
    font-size: var(--term-font-size);
    line-height: 1.5;
    border: none;
    outline: none;
    resize: none;
    white-space: pre;
    overflow-y: auto;
    overflow-x: auto;
    tab-size: 2;
    caret-color: transparent;
}

#vim-textarea:not([readonly]) {
    caret-color: var(--term-accent);
}

#vim-textarea::selection {
    background: rgba(124, 58, 237, 0.35);
}

/* A listing without --color. The classes stay on the names so the markup keeps
   its meaning, but they stop carrying colour. */
.ls-nocolor .dir-entry,
.ls-nocolor .exec-entry,
.ls-nocolor .shared-entry,
.ls-nocolor .perm {
    color: inherit;
}

#vim-cursor {
    position: absolute;
    background: var(--term-text);
    opacity: 0.7;
    pointer-events: none;
    animation: vim-blink 1s step-end infinite;
}

/* Unfocused: a hollow outline that does not blink, the way a real terminal
   shows it. The blink is the promise that typing will land somewhere, so the
   editor must stop making it the moment it loses the keyboard. */
#vim-cursor.vim-cursor-unfocused {
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--term-text);
    opacity: 0.5;
    animation: none;
}

#vim-focus-hint {
    color: var(--term-accent);
    white-space: nowrap;
    padding: 0 12px;
    font-weight: 600;
}

@keyframes vim-blink {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 0.3; }
}

#vim-statusbar {
    display: flex;
    align-items: center;
    padding: 4px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-top: 1px solid var(--term-scrollbar-thumb);
    flex-shrink: 0;
    font-size: 0.9em;
    min-height: 28px;
}

#vim-mode-indicator {
    font-weight: 700;
    min-width: 120px;
}

.vim-mode-normal {
    color: var(--term-accent);
}

.vim-mode-insert {
    color: var(--term-green);
}

/* Visual mode borrows the yellow real vim uses, so the three modes are told
   apart by colour before the word is read. */
.vim-mode-visual {
    color: var(--term-yellow, #e5c07b);
}

#vim-status-msg {
    flex: 1;
    color: var(--term-muted);
    padding: 0 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#vim-cursor-info {
    color: var(--term-muted);
    white-space: nowrap;
}

#vim-commandline {
    display: flex;
    align-items: center;
    padding: 4px 16px;
    background: var(--term-bg);
    border-top: 1px solid var(--term-scrollbar-thumb);
    flex-shrink: 0;
}

#vim-command-prefix {
    color: var(--term-text);
    font-weight: 600;
    margin-right: 2px;
}

#vim-command-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--term-text);
    font-family: var(--term-font);
    font-size: var(--term-font-size);
    outline: none;
}

/* Responsive */
@media (max-width: 600px) {
    :root {
        --term-font-size: 12px;
    }

    #terminal {
        padding: 8px 10px;
    }
}

/* ── tmux Multiplexer ──────────────────────────── */

.tmux-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tmux-split-h {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
}

.tmux-split-v {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.tmux-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--term-scrollbar-thumb);
    min-width: 0;
    min-height: 0;
}

.tmux-pane.active {
    border-color: var(--term-green);
}

.tmux-pane:not(.active) .tmux-pane-output,
.tmux-pane:not(.active) .tmux-pane-input-line {
    opacity: 0.7;
}

.tmux-pane.zoomed {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 24px;
    z-index: 50;
    border-color: var(--term-green);
}

.tmux-pane.zoomed .tmux-pane-output,
.tmux-pane.zoomed .tmux-pane-input-line {
    opacity: 1;
}

.tmux-pane-output {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: var(--term-font);
    font-size: var(--term-font-size);
    line-height: 1.5;
    color: var(--term-text);
}

.tmux-pane-output::-webkit-scrollbar { width: 6px; }
.tmux-pane-output::-webkit-scrollbar-track { background: var(--term-scrollbar-track); }
.tmux-pane-output::-webkit-scrollbar-thumb { background: var(--term-scrollbar-thumb); border-radius: 3px; }
.tmux-pane-output::-webkit-scrollbar-thumb:hover { background: var(--term-scrollbar-thumb-hover); }

.tmux-pane-output .error { color: var(--term-red); }
.tmux-pane-output .success { color: var(--term-green); }
.tmux-pane-output .info { color: var(--term-muted); }
.tmux-pane-output .dir-entry { color: var(--term-blue); font-weight: 600; }
.tmux-pane-output .shared-entry { color: #39c5cf; }
.tmux-pane-output .exec-entry { color: var(--term-green); font-weight: 600; }
.tmux-pane-output .cmd-line { display: flex; gap: 0; }
.tmux-pane-output .cmd-prompt { color: var(--term-green); font-weight: 600; white-space: pre; }
.tmux-pane-output .cmd-text { white-space: pre-wrap; }

.tmux-pane-input-line {
    display: flex;
    align-items: baseline;
    flex-shrink: 0;
    padding: 2px 8px 4px;
    border-top: 1px solid var(--term-scrollbar-track);
}

.tmux-pane-prompt {
    color: var(--term-green);
    font-weight: 600;
    white-space: nowrap;
    padding-right: 0;
}

.tmux-pane-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--term-text);
    font-family: var(--term-font);
    font-size: var(--term-font-size);
    line-height: 1.5;
    outline: none;
    caret-color: var(--term-accent);
    padding: 0;
}

/* Status bar */
.tmux-status-bar {
    height: 22px;
    line-height: 22px;
    background: var(--term-scrollbar-track);
    border-top: 1px solid var(--term-scrollbar-thumb);
    padding: 0 8px;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    color: var(--term-muted);
}

.tmux-status-pane {
    padding: 0 5px;
    border-radius: 2px;
}

.tmux-status-pane.active {
    background: var(--term-green);
    color: var(--term-bg);
    font-weight: 600;
}

.tmux-status-right {
    margin-left: auto;
}

.tmux-prefix-indicator {
    color: var(--term-yellow);
    font-weight: 600;
    margin-right: 6px;
}

/* === Dyslexia mode (very narrow subset) ===
   Terminal is intentionally monospace and tight for visual alignment.
   We deliberately do NOT change:
     - letter-spacing (breaks ASCII art, columns, tables)
     - line-height (breaks box-drawing characters that must touch vertically:
       e.g. ╔╗║╚╝ in MOTD art lose vertical continuity at any value > 1.5)
     - font-size (would widen cells and shift right-aligned MOTD columns)
     - background (terminal stays dark by design)
   Safe wins: font-weight on regular text, and Comic Mono when the user picks it. */
html.dyslexia body {
    /* Bump minimum font-size in dyslexia mode so em-based letter/word
       spacing translates to enough absolute pixels to feel like the rest
       of the site (where body text is 16-20px instead of 13px).
       max() preserves any larger user-configured terminal font-size set
       via /etc/terminal.conf. */
    font-size: max(16px, var(--term-font-size));
    font-weight: var(--dx-font-weight, 600);
}

/* ASCII art lives in <pre> blocks (boot banner, neofetch, etc.). Box-drawing
   characters can shift metrics slightly when bolded, breaking visual
   continuity between adjacent rows. Keep <pre> at normal weight. */
html.dyslexia pre {
    font-weight: 400;
}

/* When dyslexia mode is on, swap the terminal to Comic Mono (the only
   monospace dyslexia-friendly option in our font list), and apply the
   user's letter/word spacing preferences so terminal text reads like the
   rest of the platform. OpenDyslexic and Lexend are proportional and
   would shred column alignment even if the user picked them. */
html.dyslexia #terminal,
html.dyslexia #terminal * {
    font-family: 'Comic Mono', var(--term-font) !important;
    letter-spacing: var(--dx-letter-spacing) !important;
    word-spacing: var(--dx-word-spacing) !important;
}

/* Keep ASCII art, code blocks, and tabular output column-aligned by
   resetting spacing inside <pre>, <code>, and <table>. Higher specificity
   (extra element selector) wins over the rule above. */
html.dyslexia #terminal pre,
html.dyslexia #terminal pre *,
html.dyslexia #terminal code,
html.dyslexia #terminal code *,
html.dyslexia #terminal table,
html.dyslexia #terminal table * {
    letter-spacing: normal !important;
    word-spacing: normal !important;
}

/* dyslexia.css sets line-height: var(--dx-line-height) (~2.0) directly on
   every <span>. CSS line boxes use the MAX line-height of inline content,
   so even when the MOTD <pre style="line-height:1.3"> is tight, the spans
   inside push the line box back up to 2.0. That gap is what breaks the
   vertical continuity of ╔ on top connecting to ║ below.
   Force inline elements inside #terminal to inherit line-height from their
   parent: spans inside <pre> get 1.3 (preserving alignment), spans in
   regular output still inherit the body's reading-friendly line-height. */
html.dyslexia #terminal span,
html.dyslexia #terminal a,
html.dyslexia #terminal code,
html.dyslexia #terminal kbd {
    line-height: inherit !important;
}
