/*
 * An early-1980s terminal, not a modern application wearing a terminal skin.
 *
 * Two rules constrain everything here. The transcript is wrapped by CSS rather
 * than by inserted newlines, so the stored text stays exactly what the story
 * wrote; and nothing decorative is allowed to make the text harder to read.
 */

:root {
    --phosphor: #33ff66;
    --phosphor-dim: #1f9e3d;
    --background: #05100a;
    --panel: #0a1a10;
    --columns: 80;
}

/* Amber, for players who prefer it. Set by the terminal-polish milestone. */
:root[data-phosphor="amber"] {
    --phosphor: #ffb642;
    --phosphor-dim: #a8722a;
    --background: #120c02;
    --panel: #1d1405;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--background);
}

body {
    margin: 0;
    padding: 1rem;
    background: var(--background);
    color: var(--phosphor);
    font-family: "SF Mono", "DejaVu Sans Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    font-size: 1rem;
    line-height: 1.35;
}

.screen {
    /* Roughly eighty columns of this typeface, and never wider than the phone
       it is being read on. */
    max-width: calc(var(--columns) * 1ch + 2rem);
    margin: 0 auto;
}

a {
    color: var(--phosphor);
}

h1,
h2 {
    font-size: 1rem;
    font-weight: normal;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--phosphor-dim);
}

/* ---- the status bar --------------------------------------------------- */

.status-bar {
    display: flex;
    gap: 1.5ch;
    justify-content: space-between;
    padding: 0.15rem 0.5ch;
    background: var(--phosphor);
    color: var(--background);
    font-weight: bold;
    /* Present even when the engine has reported nothing, so the transcript
       does not jump a line the first time a status line arrives. */
    min-height: 1.65em;
}

.status-bar .room {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-bar .score,
.status-bar .moves,
.status-bar .clock {
    white-space: nowrap;
}

/* ---- the screen ------------------------------------------------------- */

/*
 * The upper window overlays fixed screen positions. Folding a long line would
 * destroy the alignment that is its only purpose, so it is allowed to overhang
 * and scroll sideways instead.
 */
.upper-window {
    margin: 0;
    overflow-x: auto;
    white-space: pre;
    color: var(--phosphor-dim);
}

.upper-window:empty {
    display: none;
}

/*
 * pre-wrap is the whole wrapping strategy: the story's blank lines, its
 * indentation and its trailing prompt survive untouched, and the browser folds
 * the long lines.
 */
.transcript {
    margin: 0;
    padding: 0.5rem 0.5ch;
    min-height: 60vh;
    max-height: 70vh;
    overflow-y: auto;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    font: inherit;
}

.transcript:focus-visible,
.prompt input:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--phosphor);
    outline-offset: 2px;
}

/* ---- the command line ------------------------------------------------- */

.prompt {
    display: flex;
    align-items: baseline;
    gap: 0.5ch;
    padding: 0 0.5ch 0.5rem;
}

.prompt .caret {
    color: var(--phosphor);
}

.prompt input {
    flex: 1 1 auto;
    min-width: 0;
    border: none;
    border-bottom: 1px solid var(--phosphor-dim);
    background: transparent;
    color: var(--phosphor);
    font: inherit;
    /* iOS zooms the page when a field smaller than this is focused. */
    font-size: max(1rem, 16px);
    padding: 0.2rem 0;
    caret-color: var(--phosphor);
}

.prompt .caret {
    white-space: nowrap;
}

.prompt .cancel {
    white-space: nowrap;
}

/* ---- named saves ------------------------------------------------------ */

/*
 * The selector reads as a numbered list because that is how a terminal offered
 * a choice. The numbers are the list's own; what a button posts is the save's
 * identifier, which is the database's business and never the player's.
 */
.saves {
    margin: 0.25rem 0 0.75rem;
    padding-left: 3ch;
}

.saves li {
    padding: 0.15rem 0;
}

.saves .name {
    color: var(--phosphor);
}

.saves .detail {
    color: var(--phosphor-dim);
    margin-left: 1ch;
}

.saves form {
    display: inline;
    margin-left: 1.5ch;
}

button {
    border: 1px solid var(--phosphor-dim);
    background: var(--panel);
    color: var(--phosphor);
    font: inherit;
    padding: 0.3rem 1ch;
    cursor: pointer;
}

button:hover {
    background: var(--phosphor);
    color: var(--background);
}

button.linklike {
    border: none;
    background: none;
    padding: 0;
    text-decoration: underline;
}

button.linklike:hover {
    background: none;
    color: var(--phosphor);
}

/* ---- lobby, login, chrome --------------------------------------------- */

.games,
.stories {
    list-style: none;
    margin: 0 0 1.5rem;
    padding: 0;
}

.games li,
.stories li {
    padding: 0.2rem 0;
}

.games .detail {
    color: var(--phosphor-dim);
    margin-left: 1ch;
}

.games .discard {
    margin-left: 1.5ch;
}

.credentials {
    display: grid;
    gap: 0.35rem;
    max-width: 40ch;
    margin-bottom: 1.5rem;
}

.credentials input {
    border: 1px solid var(--phosphor-dim);
    background: var(--panel);
    color: var(--phosphor);
    font: inherit;
    font-size: max(1rem, 16px);
    padding: 0.35rem 0.5ch;
}

.credentials button {
    margin-top: 0.5rem;
    justify-self: start;
}

.hint,
.notice,
.ended {
    color: var(--phosphor-dim);
    margin: 0.25rem 0.5ch;
}

.notice:empty {
    display: none;
}

.error {
    margin: 0 0 1rem;
    padding: 0.4rem 0.5ch;
    border: 1px solid var(--phosphor);
    color: var(--phosphor);
}

.chrome {
    display: flex;
    gap: 1.5ch;
    align-items: baseline;
    margin-top: 1.5rem;
    color: var(--phosphor-dim);
}

.chrome form {
    display: inline;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---- screen preferences ----------------------------------------------- */

.settings {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75ch;
    align-items: baseline;
    margin-top: 0.75rem;
    color: var(--phosphor-dim);
    font-size: 0.85rem;
}

.settings .label {
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.settings button {
    border-color: var(--phosphor-dim);
    padding: 0.15rem 1ch;
    font-size: inherit;
    color: var(--phosphor-dim);
}

.settings button[aria-pressed="true"] {
    background: var(--phosphor);
    color: var(--background);
    border-color: var(--phosphor);
}

/* Until Alpine has bound the pressed states, the row would show every button
   looking unset. Hide it rather than show a wrong answer; with no JavaScript at
   all the preferences cannot be changed anyway. */
[x-cloak] {
    display: none;
}

/* ---- decoration ------------------------------------------------------- */

/*
 * A restrained glow. It is static rather than animated, so it is not something
 * reduced motion asks about — but it is something contrast asks about, and it
 * goes when more contrast is wanted.
 */
.transcript,
.upper-window,
.prompt .caret {
    text-shadow: 0 0 4px color-mix(in srgb, var(--phosphor) 45%, transparent);
}

@media (prefers-reduced-motion: no-preference) {
    .prompt .caret {
        animation: blink 1.2s step-end infinite;
    }
}

@keyframes blink {
    50% {
        opacity: 0.25;
    }
}

/*
 * Scanlines, off by default and asked for by name.
 *
 * They are laid over the page and never over the meaning of it: the lines are
 * dark on dark, there is no animation to them, and nothing on the screen is
 * said only by the way it looks. Turning them off leaves a plainer terminal
 * that works identically.
 */
:root[data-crt="on"] body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    background:
        repeating-linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.18) 0,
            rgba(0, 0, 0, 0.18) 1px,
            transparent 1px,
            transparent 3px
        ),
        radial-gradient(
            ellipse at center,
            transparent 55%,
            rgba(0, 0, 0, 0.35) 100%
        );
}

@media (prefers-contrast: more) {
    .transcript,
    .upper-window,
    .prompt .caret {
        text-shadow: none;
    }

    /* Scanlines take contrast away, which is the one thing this must not do. */
    :root[data-crt="on"] body::after {
        display: none;
    }
}

@media (max-width: 40rem) {
    body {
        padding: 0.5rem;
    }

    .transcript {
        min-height: 50vh;
    }

    .prompt button {
        display: none;
    }
}
