/* The page is the photo of the desk; the terminal is laid over the monitor glass.
   terminal.js sets --s (scale) and --ox/--oy (offset) for the 1448x1086 image,
   and everything pinned to the image is positioned from those three numbers. */

@property --s { syntax: '<number>'; inherits: true; initial-value: 1; }
@property --ox { syntax: '<number>'; inherits: true; initial-value: 0; }
@property --oy { syntax: '<number>'; inherits: true; initial-value: 0; }

:root {
  --s: 1;
  --ox: 0;
  --oy: 0;

  --c-fg: #c6c9cf;
  --c-dim: #6b7383;
  --c-hi: #ffffff;
  --c-cyan: #55ffff;
  --c-yellow: #ffff55;
  --c-green: #55ff55;
  --c-red: #ff5555;
  --c-glow: rgba(150, 190, 255, 0.35);
  --font: 'VT323', 'Lucida Console', 'Courier New', monospace;
  --ease: cubic-bezier(0.6, 0, 0.2, 1);
  color-scheme: dark;
}

:root.animate {
  transition: --s 0.7s var(--ease), --ox 0.7s var(--ease), --oy 0.7s var(--ease);
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #03050b;
}

body {
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* A blurred copy fills whatever the photo doesn't cover (tall phones, very wide screens). */
#scene::before {
  content: '';
  position: absolute;
  inset: -10%;
  background: url('/assets/station.webp') center / cover no-repeat;
  filter: blur(28px) brightness(0.4);
}

/* The picture, pixelated by terminal.js and drawn with hard pixel edges. */
#room {
  position: absolute;
  left: 0;
  top: 0;
  width: 1448px;
  height: 1086px;
  max-width: none;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  transform-origin: 0 0;
  transform: translate(calc(var(--ox) * 1px), calc(var(--oy) * 1px)) scale(var(--s));
  user-select: none;
  -webkit-user-drag: none;
  /* Soft edges so the photo melts into the blurred copy behind it. */
  -webkit-mask-image:
    linear-gradient(to bottom, transparent, #000 5%, #000 95%, transparent),
    linear-gradient(to right, transparent, #000 4%, #000 96%, transparent);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to bottom, transparent, #000 5%, #000 95%, transparent),
    linear-gradient(to right, transparent, #000 4%, #000 96%, transparent);
  mask-composite: intersect;
}

#power {
  all: unset;
}

/* Pinned to a rectangle of the image, in image pixels (--x, --y, --w, --h). */
#screen,
#led,
#power {
  position: fixed;
  left: calc((var(--ox) + var(--x) * var(--s)) * 1px);
  top: calc((var(--oy) + var(--y) * var(--s)) * 1px);
  width: calc(var(--w) * var(--s) * 1px);
  height: calc(var(--h) * var(--s) * 1px);
}

/* ---------- monitor glass ---------- */

#screen {
  --x: 437;
  --y: 155;
  --w: 594;
  --h: 462;
  border-radius: calc(46px * var(--s)) / calc(64px * var(--s));
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(120% 110% at 50% 45%, #0a1122 0%, #050914 55%, #020308 100%);
  color: var(--c-fg);
  font-size: max(12px, calc(21px * var(--s)));
  line-height: 1.08;
  /* VT323 has an "fi" ligature, which would break column alignment. */
  font-variant-ligatures: none;
  font-feature-settings: 'liga' 0, 'clig' 0;
  text-shadow: 0 0 calc(3px * var(--s)) var(--c-glow), 0 0 1px rgba(255, 255, 255, 0.25);
}

#tube {
  position: absolute;
  inset: 0;
}

#screen.off #tube {
  visibility: hidden;
}

#screen.powering-off #tube {
  animation: crt-off 0.45s ease-in forwards;
}

#screen.powering-on #tube {
  animation: crt-on 0.55s ease-out;
}

@keyframes crt-off {
  0% { transform: none; filter: none; opacity: 1; }
  55% { transform: scale(1, 0.006); filter: brightness(3); opacity: 1; }
  100% { transform: scale(0, 0.006); filter: brightness(6); opacity: 0; }
}

@keyframes crt-on {
  0% { transform: scale(0, 0.006); filter: brightness(6); opacity: 0; }
  40% { transform: scale(1, 0.006); filter: brightness(3); opacity: 1; }
  100% { transform: none; filter: none; opacity: 1; }
}

/* Scanlines, the curved-glass shadow and a faint reflection. */
#glass {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
  background:
    linear-gradient(170deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0) 38%),
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.26) 0 1px, transparent 1px 3px);
  box-shadow:
    inset 0 0 calc(34px * var(--s)) calc(8px * var(--s)) rgba(0, 0, 0, 0.78),
    inset 0 0 calc(4px * var(--s)) 1px rgba(0, 0, 0, 0.9);
}

#screen.running #glass {
  background:
    linear-gradient(170deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0) 38%),
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.1) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 calc(18px * var(--s)) calc(3px * var(--s)) rgba(0, 0, 0, 0.7);
}

/* ---------- terminal ---------- */

#term {
  position: absolute;
  inset: 0;
  padding: 5.5% 6.5% 5%;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  cursor: text;
}

#term::-webkit-scrollbar {
  display: none;
}

#out > div {
  min-height: 1.08em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#out a {
  color: var(--c-cyan);
}

#input-line {
  display: flex;
}

#prompt {
  white-space: pre;
}

/* Opacity, not visibility: a hidden input would lose focus and drop keystrokes. */
#screen.busy #input-line {
  opacity: 0;
}

#cmd-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#cmd {
  all: unset;
  display: block;
  box-sizing: border-box;
  width: 100%;
  font: inherit;
  color: inherit;
  text-shadow: inherit;
  caret-color: transparent;
}

#cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--caret, 0) * 1ch - var(--scroll, 0) * 1px);
  width: 1ch;
  pointer-events: none;
}

#cursor::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.1em;
  height: 0.14em;
  background: currentColor;
  box-shadow: 0 0 4px var(--c-glow);
  animation: blink 1.06s steps(1) infinite;
}

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

::selection {
  background: var(--c-fg);
  color: #000;
  text-shadow: none;
}

.c-hi { color: var(--c-hi); }
.c-dim { color: var(--c-dim); }
.c-cyan { color: var(--c-cyan); }
.c-yellow { color: var(--c-yellow); }
.c-green { color: var(--c-green); }
.c-red { color: var(--c-red); }

/* ---------- a program running on the screen ---------- */

#app {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
}

#app[hidden] {
  display: none;
}

#app-bar {
  display: flex;
  align-items: baseline;
  gap: 0.8ch;
  padding: 2.4% 8% 0.25em;
  font-size: 0.8em;
  color: var(--c-dim);
  white-space: nowrap;
}

#app-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--c-fg);
}

#app-bar button {
  all: unset;
  cursor: pointer;
  color: var(--c-dim);
}

#app-bar button::before { content: '['; }
#app-bar button::after { content: ']'; }

#app-bar button:hover,
#app-bar button:focus-visible {
  color: #000;
  background: var(--c-fg);
  text-shadow: none;
}

#app-view {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

/* terminal.js sizes and scales the frame when the game sets "display". */
#app-frame {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  display: block;
  transform-origin: 0 0;
}

/* ---------- power switch and LED ---------- */

#led {
  --x: 998.5;
  --y: 660;
  --w: 7;
  --h: 7;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 calc(7px * var(--s)) calc(1.5px * var(--s)) rgba(90, 255, 90, 0.5);
  transition: background 0.2s, box-shadow 0.2s;
}

body.power-off #led {
  background: #18201a;
  box-shadow: none;
}

#power {
  --x: 982;
  --y: 646;
  --w: 40;
  --h: 48;
  cursor: pointer;
  border-radius: 30%;
}

#power:focus-visible {
  outline: 2px dashed var(--c-green);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  :root.animate { transition: none; }
  #screen.powering-off #tube,
  #screen.powering-on #tube { animation: none; }
  #cursor::after { animation: none; }
}
