.console_page {
    display: grid;
    grid-template-columns: minmax(300px, 380px) 1fr;
    gap: clamp(20px, 3vw, 32px);
    min-height: 100vh;
    min-height: 100svh;
    align-items: start;
    align-content: start; /* the row stays as tall as the console, even on tall windows */
    padding: calc(var(--nav-height) + clamp(16px, 3vw, 40px)) var(--gutter) 64px;
    box-sizing: border-box;
}

/* Command list: exactly as tall as the console and scrolls on its own.
   contain: size keeps its content from stretching the row, so the console sets the height. */
.commands {
    align-self: stretch;
    contain: size;
    overflow-y: auto;
    padding: 24px;
    box-sizing: border-box;
    background-color: var(--color-card);
    border: 2px solid var(--color-line);
    border-radius: 12px;
    box-shadow: 6px 6px 0 var(--color-shadow);  /* same panel as the projects on the portfolio page */
    color: var(--color-text-soft);
}

.commands h1 {
    margin: 0 0 8px;
    color: var(--color-primary);
    font-size: 36px;
    font-weight: normal;
}

.commands h2 {
    margin: 24px 0 8px;
    color: var(--color-primary);
    font-size: 26px;
    font-weight: normal;
}

.hint {
    margin: 0;
    font-size: 20px;
    line-height: 1.3;
    color: var(--color-secondary);
}

kbd {
    padding: 0 6px;
    border-radius: 4px;
    background-color: var(--color-card-bar);
    color: var(--color-primary);
    font-family: inherit;
}

.commands ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.cmd {
    display: block;
    width: 100%;
    min-height: 44px;  /* comfortable tap target */
    padding: 6px 10px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: inherit;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.cmd:focus-visible {
    background-color: var(--color-card-bar);
    outline: none;
}

@media (hover: hover) {
    .cmd:hover {
        background-color: var(--color-card-bar);
    }
}

.cmd code {
    display: block;
    font-family: inherit;
    font-size: 22px;
    color: var(--color-border);
    overflow-wrap: anywhere;
}

.cmd code i {
    font-style: normal;
    color: var(--color-secondary);
}

.cmd span {
    display: block;
    font-size: 19px;
    line-height: 1.2;
}

.shortcuts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 16px;
    margin: 0;
    padding: 0 10px;
    font-size: 20px;
}

.shortcuts dt {
    color: var(--color-border);
}

.shortcuts dd {
    margin: 0;
}

/* Console */
.terminal {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.terminal_bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    padding: 10px clamp(12px, 2vw, 20px);
    background-color: var(--color-card-bar);
    border: 2px solid var(--color-line);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
}

.terminal_bar h1 {
    margin: 0;
    font-size: 30px;
    font-weight: normal;
}

.status {
    min-width: 0;
    font-size: 22px;
    color: var(--color-secondary);
    overflow-wrap: anywhere;  /* a long error message (e.g. a URL) wraps instead of widening the page */
}

.status::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 8px;
    background-color: var(--color-secondary);
}

.status[data-state="busy"]::before { background-color: #F2C94C; }
.status[data-state="on"]::before { background-color: var(--color-live); }
.status[data-state="error"] { color: var(--color-accent); }
.status[data-state="error"]::before { background-color: var(--color-accent); }

.bar_buttons {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.bar_button {
    min-height: 36px;
    padding: 4px 16px;
    border: 0;
    border-radius: 8px;
    background-color: var(--color-line);
    color: var(--color-primary);
    font-family: inherit;
    font-size: 22px;
    cursor: pointer;
}

@media (hover: hover) {
    .bar_button:hover {
        filter: brightness(1.2);
    }
}

.screen {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%; /* fixed width, so capping the height below does not shrink it via the aspect ratio */
    aspect-ratio: 4 / 3;
    /* Fit the window (nav, top gap, 58px title bar, bottom gap) so the page does not scroll */
    max-height: calc(100vh - var(--nav-height) - 40px - 58px - 64px);
    max-height: calc(100svh - var(--nav-height) - 40px - 58px - 64px);
    min-height: 360px;
    box-sizing: border-box;
    overflow: hidden;
    background-color: #000000;
    border: 2px solid var(--color-line);
    border-radius: 0 0 12px 12px;
}

/* v86 writes text mode into this div and graphics mode into the canvas */
/* Each row is as tall as the font's glyphs, so a row's background never covers the row above */
.screen_text {
    white-space: pre;
    font: 15px monospace;
    line-height: 18px;
}

.screen_text > div {
    height: 18px;
}

/* 1px taller than the row: the next row covers it, which hides seams from the scaling */
.screen_text span {
    display: inline-block;
    height: 19px;
    vertical-align: top;
}

#screen_container canvas {
    image-rendering: pixelated;
}

#screen_container {
    flex: none;
}

/* Keyboard for touch screens: a text field that types into the console, shown only on
   devices without a mouse (phones, tablets), where the on-screen keyboard needs a field to open for */
.touch_input {
    display: none;
    gap: 8px;
    padding: 8px;
    background-color: var(--color-page);
    border: 2px solid var(--color-line);
    border-top: 0;
    border-radius: 0 0 12px 12px;
}

@media (pointer: coarse) {
    .touch_input {
        display: flex;
    }

    .screen {
        border-radius: 0;
    }
}

.touch_input input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 4px 12px;
    border: 2px solid var(--color-line);
    border-radius: 8px;
    background-color: #000000;
    color: #FFFFFF;  /* part of the black terminal, in both themes */
    font: 20px monospace;
}

.touch_input input:focus {
    outline: none;
    border-color: var(--color-border);
}

.touch_input button {
    min-width: 44px;
}

/* Sits below the console without adding to its height, so the command list ends with the screen */
.terminal_note {
    position: absolute;
    top: 100%;
    left: 4px;
    margin: 12px 0 0;
    font-size: 20px;
    color: var(--color-secondary);
}

.terminal_note a {
    color: var(--color-border);
}

/* Fullscreen: the console fills the whole display, the bar stays for the Exit/Restart buttons */
.terminal:fullscreen {
    padding: 0;
    background-color: #000000;
}

.terminal:fullscreen .terminal_bar {
    border-radius: 0;
}

.terminal:fullscreen .screen {
    flex: 1;
    aspect-ratio: auto;
    max-height: none;
    min-height: 0;
    border-radius: 0;
}

.terminal:fullscreen .touch_input {
    border-radius: 0;
}

.terminal:fullscreen .terminal_note {
    display: none;
}

/* Narrow screens and tablets: console on top, full width, the command list below it */
@media screen and (max-width: 1000px) {
    .console_page {
        grid-template-columns: 1fr;
        padding-top: clamp(16px, 3vw, 40px);
        padding-bottom: 40px;
    }

    .terminal {
        order: -1;
    }

    .commands {
        align-self: auto;
        contain: none;
        overflow: visible;
    }

    .screen {
        /* Width decides the size; on short screens the height caps it */
        max-height: 75vh;
        max-height: 75svh;
        min-height: 0;
    }

    .terminal_note {
        position: static;
        margin: 12px 0 0;
    }
}

/* Phones: <main> is the scroll area between the top of the screen and the tab bar (see general.css) */
@media screen and (max-width: 760px) {
    .console_page {
        min-height: 0;
        padding-top: 56px;  /* the row the light/dark switch floats in */
    }
}

/* Phones: tighter spacing inside the command list */
@media screen and (max-width: 480px) {
    .commands {
        padding: 16px;
    }

    .terminal_bar h1 {
        font-size: 26px;
    }
}
