/* a ship's console, late 1970s: pressed-steel plates, cream keycaps, and a
   green phosphor tube */
:root {
    --steel: #2a2d2b;
    --steel-dark: #171918;
    --steel-light: #3d413e;
    --cream: #d6cfb6;
    --cream-dark: #8f8973;
    --ink: #1c1d1a;
    --phosphor: #8dffb4;
    --phosphor-dim: #3f8f5f;
    --amber: #ffb43a;
    --alarm: #ff5a3c;
    --well: #060807;
    --label: "Helvetica Neue", "Arial Narrow", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #0a0b0a;
    color: var(--phosphor);
    font: 13px/1.4 var(--mono);
    -webkit-font-smoothing: antialiased;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overscroll-behavior: none;
}

.console {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
}

/* ---- plates: the pressed-steel panels the controls are mounted on */

.plate {
    position: relative;
    background:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 3px),
        linear-gradient(180deg, var(--steel-light), var(--steel) 18%, var(--steel-dark));
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    border-bottom: 1px solid #000;
    box-shadow:
        inset 0 -6px 12px rgba(0, 0, 0, 0.35),
        0 0 0 1px #000;
}

/* a screw in each corner */
.plate::before,
.plate::after {
    content: "";
    position: absolute;
    top: 7px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background:
        linear-gradient(45deg, transparent 44%, rgba(0, 0, 0, 0.65) 44% 56%, transparent 56%),
        radial-gradient(circle at 35% 30%, #8b8f8a, #4a4d4a 60%, #262827);
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
}

.plate::before {
    left: 8px;
}

.plate::after {
    right: 8px;
}

.label,
.stamp {
    font: 700 10px/1 var(--label);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--cream);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.7);
}

/* ---- wells: recessed windows with something glowing inside */

.well {
    background: var(--well);
    border: 1px solid #000;
    border-radius: 3px;
    box-shadow:
        inset 0 2px 5px rgba(0, 0, 0, 0.9),
        0 1px 0 rgba(255, 255, 255, 0.1);
}

.phosphor,
.digits,
.hint {
    color: var(--phosphor);
    text-shadow: 0 0 6px rgba(141, 255, 180, 0.55);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.digits {
    font-variant-numeric: tabular-nums;
}

/* the strip and the deck share a layout: whatever sits in the middle column
   is at the exact centre of the console, with the rest to either side of it */
.strip,
.deck {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: 14px;
}

.strip {
    padding: 12px max(28px, env(safe-area-inset-right)) 12px max(28px, env(safe-area-inset-left));
}

.side {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

/* the first thing in a side sits against the centre, the last against the edge */
.side:first-child > :last-child {
    margin-left: auto;
}

.side:last-child > :last-child {
    margin-left: auto;
}

.strip .side:last-child > :last-child {
    margin-left: 0;
}

.strip .side:last-child > :nth-child(2) {
    margin-left: auto;
}

.level {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font: inherit;
    white-space: nowrap;
    cursor: pointer;
}

.level:hover,
.level:focus-visible,
.help:hover,
.help:focus-visible {
    border-color: var(--phosphor-dim);
    outline: none;
}

.help {
    width: 30px;
    height: 30px;
    padding: 0;
    font: inherit;
    color: var(--phosphor);
    text-shadow: 0 0 6px rgba(141, 255, 180, 0.55);
    cursor: pointer;
}

/* the fuel warning: lit only when the ship has none */
.flag {
    padding: 7px 10px;
    font: 700 10px/1 var(--label);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--alarm);
    text-shadow: 0 0 6px rgba(255, 90, 60, 0.6);
    border-color: #4a1a12;
    animation: blink 1.1s steps(1) infinite;
}

.flag[hidden] {
    display: none;
}

.digits.amber {
    min-width: 4.2ch;
    padding: 7px 8px;
    text-align: right;
    color: var(--amber);
    text-shadow: 0 0 6px rgba(255, 180, 58, 0.5);
}

/* the matter gauge: a row of amber lamps that go out as matter is spent */
.meter {
    display: block;
    width: clamp(70px, 24vw, 300px);
    height: 16px;
    padding: 3px;
    overflow: hidden;
}

.meter-fill {
    display: block;
    height: 100%;
    width: 100%;
    background: repeating-linear-gradient(90deg, var(--amber) 0 6px, transparent 6px 9px);
    filter: drop-shadow(0 0 3px rgba(255, 180, 58, 0.7));
}

.meter.refused {
    border-color: var(--alarm);
}

/* ---- the tube */

.screen {
    position: relative;
    min-height: 0;
    margin: 0 10px;
    border: 10px solid #101211;
    border-radius: 18px;
    background: #05060a;
    box-shadow:
        0 0 0 1px #000,
        0 1px 0 2px rgba(255, 255, 255, 0.06),
        inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

.screen canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
}

/* scan lines, a faint green cast, and the glass darkening towards its edges */
.crt {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.2) 0 1px, transparent 1px 3px),
        radial-gradient(ellipse at 50% 45%, rgba(141, 255, 180, 0.035), transparent 60%),
        radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55));
    box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.85);
    animation: flicker 5s steps(1) infinite;
}

@keyframes flicker {
    0%,
    100% {
        opacity: 1;
    }
    47% {
        opacity: 0.94;
    }
    48% {
        opacity: 1;
    }
    81% {
        opacity: 0.97;
    }
    82% {
        opacity: 1;
    }
}

/* ---- panning: arrows at the tube's edges, for screens too small to show the whole field */

.pan,
.zoom {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: var(--phosphor);
    background: rgba(6, 8, 7, 0.7);
    border: 1px solid var(--phosphor-dim);
    border-radius: 4px;
    box-shadow: 0 0 8px rgba(141, 255, 180, 0.15);
    cursor: pointer;
    touch-action: none;
}

.pan[hidden],
.zoom[hidden] {
    display: none;
}

.pan {
    width: 40px;
    height: 40px;
}

/* the arrowhead */
.pan::before {
    content: "";
    width: 10px;
    height: 10px;
    border-top: 2px solid currentColor;
    border-left: 2px solid currentColor;
}

.pan:active,
.zoom:active {
    background: rgba(141, 255, 180, 0.25);
}

.pan-left {
    left: 8px;
    top: 50%;
    margin-top: -20px;
}

.pan-left::before {
    transform: translateX(2px) rotate(-45deg);
}

.pan-right {
    right: 8px;
    top: 50%;
    margin-top: -20px;
}

.pan-right::before {
    transform: translateX(-2px) rotate(135deg);
}

.pan-up {
    top: 8px;
    left: 50%;
    margin-left: -20px;
}

.pan-up::before {
    transform: translateY(2px) rotate(45deg);
}

.pan-down {
    bottom: 8px;
    left: 50%;
    margin-left: -20px;
}

.pan-down::before {
    transform: translateY(-2px) rotate(-135deg);
}

.zoom {
    top: 8px;
    right: 8px;
    height: 32px;
    padding: 0 10px;
    font: 11px/1 var(--mono);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-shadow: 0 0 6px rgba(141, 255, 180, 0.55);
}

/* ---- the deck: message window, keys, maker's stamp */

.deck {
    column-gap: 22px;
    row-gap: 14px;
    padding: 14px max(28px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
}

.hint {
    margin: 0;
    min-height: 3.4em;
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.5;
}

.hint::before {
    content: "> ";
    color: var(--phosphor-dim);
}

.hint.alert {
    color: var(--alarm);
    text-shadow: 0 0 6px rgba(255, 90, 60, 0.55);
}

.stamp {
    margin: 0;
    text-align: right;
    line-height: 1.7;
    color: var(--cream-dark);
}

.logo {
    display: block;
    width: 260px;
    max-width: 70%;
    height: auto;
    margin: 0 0 20px;
}

/* a keycap: it stands proud of the plate and travels when pressed */
.key {
    position: relative;
    min-width: 96px;
    padding: 13px 18px 11px;
    font: 700 12px/1 var(--label);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink);
    background: linear-gradient(180deg, #e9e3cc, var(--cream) 45%, #bdb69c);
    border: 1px solid #000;
    border-radius: 5px;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.7),
        0 5px 0 var(--cream-dark),
        0 6px 0 #000,
        0 9px 10px rgba(0, 0, 0, 0.55);
    cursor: pointer;
    transition:
        transform 0.05s,
        box-shadow 0.05s;
}

.key:focus-visible {
    outline: 2px solid var(--phosphor);
    outline-offset: 5px;
}

.key:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        0 1px 0 var(--cream-dark),
        0 2px 0 #000,
        0 3px 4px rgba(0, 0, 0, 0.5);
}

/* a dead key sits lower and loses its colour */
.key:disabled {
    color: #5d5a4d;
    background: linear-gradient(180deg, #8f8b7a, #7b7767);
    transform: translateY(3px);
    box-shadow:
        0 2px 0 #4b4839,
        0 3px 0 #000;
    cursor: default;
}

.key-launch,
.key-go {
    color: #fff4ea;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
    background: linear-gradient(180deg, #f07a4c, #d84f22 50%, #b23c15);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.45),
        0 5px 0 #7a280d,
        0 6px 0 #000,
        0 9px 10px rgba(0, 0, 0, 0.55);
}

.key-launch {
    min-width: 132px;
    padding: 17px 22px 15px;
    font-size: 13px;
}

.key-launch:active:not(:disabled),
.key-go:active:not(:disabled) {
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        0 1px 0 #7a280d,
        0 2px 0 #000,
        0 3px 4px rgba(0, 0, 0, 0.5);
}

/* the launch key sits in a hazard-striped surround, under a lamp */
.guard {
    position: relative;
    padding: 10px 12px 14px;
    border: 1px solid #000;
    border-radius: 6px;
    background: repeating-linear-gradient(-45deg, #d9a521 0 9px, #1a1a17 9px 18px);
    box-shadow:
        inset 0 0 0 2px rgba(0, 0, 0, 0.35),
        inset 0 2px 6px rgba(0, 0, 0, 0.6),
        0 1px 0 rgba(255, 255, 255, 0.1);
}

.lamp {
    position: absolute;
    top: -7px;
    left: 50%;
    width: 12px;
    height: 12px;
    margin-left: -6px;
    border: 1px solid #000;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #c8ffd9, var(--phosphor) 45%, #1f7a44);
    box-shadow: 0 0 9px rgba(141, 255, 180, 0.8);
}

.lamp.flying {
    background: radial-gradient(circle at 35% 30%, #ffd9cf, var(--alarm) 45%, #7a1d0c);
    box-shadow: 0 0 10px rgba(255, 90, 60, 0.9);
    animation: blink 0.7s steps(1) infinite;
}

.lamp.dark {
    background: radial-gradient(circle at 35% 30%, #5a5d5a, #2c2e2c);
    box-shadow: none;
}

@keyframes blink {
    50% {
        filter: brightness(0.35);
    }
}

/* ---- transmissions: the panels that come up over the tube */

.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.6);
}

.overlay[hidden] {
    display: none;
}

.panel {
    width: min(460px, 100%);
    max-height: 100%;
    overflow: auto;
    padding: 26px 26px 30px;
    background:
        repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.25) 0 1px, transparent 1px 3px),
        #050806;
    border: 1px solid var(--phosphor-dim);
    border-radius: 6px;
    box-shadow:
        0 0 0 8px #101211,
        0 0 0 9px #000,
        0 20px 50px rgba(0, 0, 0, 0.8),
        inset 0 0 40px rgba(141, 255, 180, 0.06);
}

.panel h1 {
    margin: 0 0 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--phosphor-dim);
    font: 400 14px/1.3 var(--mono);
    letter-spacing: 0.3em;
    text-transform: uppercase;
    text-shadow: 0 0 6px rgba(141, 255, 180, 0.55);
}

.panel p {
    margin: 0 0 26px;
    white-space: pre-wrap;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    line-height: 1.9;
    text-shadow: 0 0 6px rgba(141, 255, 180, 0.4);
}

.panel-actions {
    display: flex;
    justify-content: flex-end;
    gap: 14px;
    padding-bottom: 6px;
}

/* a key that sits apart from the rest, at the start of the row */
.panel-actions .first {
    margin-right: auto;
}

.panel-wide {
    width: min(620px, 100%);
}

.manual {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px 18px;
    margin: 0 0 26px;
    line-height: 1.6;
}

.manual dt {
    color: var(--amber);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-shadow: 0 0 6px rgba(255, 180, 58, 0.4);
    white-space: nowrap;
}

.manual dd {
    margin: 0;
    text-shadow: 0 0 6px rgba(141, 255, 180, 0.35);
}

/* twenty sectors, in two columns of ten read downwards */
.level-list {
    list-style: none;
    margin: 0 0 26px;
    padding: 0;
    display: grid;
    grid-template-rows: repeat(10, auto);
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 4px 14px;
}

.level-list button {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 8px 10px;
    font: inherit;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--phosphor);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 2px;
    cursor: pointer;
}

.level-list button:hover:not(:disabled),
.level-list button:focus-visible {
    border-color: var(--phosphor-dim);
    outline: none;
}

.level-list button[aria-current="true"] {
    color: #05080a;
    background: var(--phosphor);
}

.level-list button:disabled {
    color: #2f5c40;
    cursor: default;
}

.level-list span {
    white-space: nowrap;
}

.level-list .best {
    color: var(--amber);
}

.level-list button[aria-current="true"] .best {
    color: #05080a;
}

/* ---- the turn-your-phone notice, shown to touch devices held upright */

.rotate {
    display: none;
}

.rotate .panel {
    text-align: center;
}

.rotate .panel p {
    margin-bottom: 0;
}

/* a handset outline that keeps tipping onto its side */
.handset {
    display: block;
    width: 34px;
    height: 58px;
    margin: 6px auto 26px;
    border: 2px solid var(--phosphor);
    border-radius: 6px;
    box-shadow: 0 0 10px rgba(141, 255, 180, 0.4);
    animation: tip 2.4s ease-in-out infinite;
}

@keyframes tip {
    0%,
    25% {
        transform: rotate(0);
    }
    60%,
    100% {
        transform: rotate(90deg);
    }
}

@media (orientation: portrait) and (pointer: coarse) {
    .rotate {
        position: fixed;
        inset: 0;
        z-index: 10;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 28px;
        background: #0a0b0a;
    }
}

/* ---- small screens: the message window moves above the keys */

@media (max-width: 760px) {
    /* the message window takes a row of its own, above the keys */
    .hint {
        grid-column: 1 / -1;
    }

    .deck > .guard {
        grid-column: 2;
    }

    .stamp,
    #level-name {
        display: none;
    }

    .strip {
        padding-left: 22px;
        padding-right: 22px;
    }

    .screen {
        margin: 0 4px;
        border-width: 6px;
    }
}

@media (max-width: 480px) {
    .strip .label {
        display: none;
    }

    .strip {
        column-gap: 10px;
    }

    #hole-count {
        margin-left: auto;
    }

    /* room for undo beside a centred launch key */
    .deck {
        column-gap: 12px;
        padding-left: 14px;
        padding-right: 14px;
    }

    .deck .key:not(.key-launch) {
        min-width: 0;
        padding-left: 12px;
        padding-right: 12px;
    }

    .key-launch {
        min-width: 112px;
    }
}

/* ---- a phone on its side: height is scarce, so the deck stands up the
   right-hand edge as a column of keys and the strip slims down */

@media (max-height: 540px) and (orientation: landscape) {
    .console {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .strip {
        grid-column: 1 / -1;
        padding-top: 5px;
        padding-bottom: 5px;
    }

    .strip .level {
        padding: 4px 9px;
    }

    .strip .digits.amber {
        padding: 4px 7px;
    }

    .plate::before,
    .plate::after {
        top: 4px;
        width: 7px;
        height: 7px;
    }

    .screen {
        margin: 0 0 6px max(6px, env(safe-area-inset-left));
        border-width: 6px;
        border-radius: 14px;
    }

    .deck {
        grid-template-columns: 1fr;
        align-content: center;
        justify-items: stretch;
        row-gap: 14px;
        width: 148px;
        padding: 16px max(14px, env(safe-area-inset-right)) 14px 14px;
        overflow: hidden;
    }

    .deck .hint {
        grid-column: 1;
        min-height: 0;
        padding: 6px 8px;
        font-size: 10px;
        line-height: 1.45;
    }

    .deck > .guard {
        grid-column: 1;
        padding: 8px 8px 12px;
    }

    .deck .side {
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
    }

    .deck .key {
        width: 100%;
        min-width: 0;
        padding: 11px 8px 9px;
    }

    .deck .key-launch {
        padding: 14px 8px 12px;
    }

    .stamp {
        display: none;
    }

    .strip .help {
        width: 26px;
        height: 24px;
    }

    /* the panels have little height to work with */
    .panel {
        padding: 16px 18px 20px;
    }

    .panel h1 {
        margin-bottom: 10px;
        padding-bottom: 6px;
    }

    .overlay {
        padding: 10px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left));
    }

    /* the instructions run in two columns, to fit the height without scrolling */
    .panel-wide {
        width: 100%;
    }

    .manual {
        grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 7px 12px;
        margin-bottom: 14px;
        font-size: 10.5px;
        line-height: 1.4;
    }

    .panel .key {
        padding: 10px 14px 8px;
    }

    /* no height to spare for the title card on a phone */
    .panel .logo {
        display: none;
    }

    .level-list {
        margin-bottom: 14px;
        gap: 2px 12px;
    }

    .level-list button {
        padding: 3px 8px;
        font-size: 11px;
    }

    .strip .flag {
        padding: 5px 7px;
    }
}

@media (max-width: 560px) {
    .level-list {
        grid-template-rows: none;
        grid-auto-flow: row;
    }

    .manual {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .manual dd {
        margin-bottom: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .crt,
    .lamp.flying,
    .flag,
    .handset {
        animation: none;
    }
}
