/* Steven Bremel, version 01: a teletext service on a CRT. */

:root {
  --glow: #3343ff;
  --cw: 24px;
  --ch: 28.8px;
  --fs: 28px;
  --mx: 0.9;
  --my: 0.45;
}

* { box-sizing: border-box; }

html { background: #060608; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(120% 80% at 50% 0%, #121218 0%, #060608 60%),
    #060608;
  color: #cfcfd4;
  font-family: 'Archivo Narrow', 'Arial Narrow', sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.room {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  padding: 24px;
  isolation: isolate;
}

/* Light from the screen falling on the room. */
.room::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(55% 60% at 44% 50%, var(--glow), transparent 72%);
  opacity: 0.17;
  pointer-events: none;
}

/* ---------- The set ---------- */

.tv {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  padding: clamp(16px, 2.2vw, 30px) clamp(16px, 2.2vw, 30px) 60px;
  border-radius: 26px;
  background: linear-gradient(160deg, #3a3a41 0%, #222227 42%, #141417 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -3px 0 rgba(0, 0, 0, 0.6),
    0 0 0 1px #000,
    0 50px 90px rgba(0, 0, 0, 0.7);
}

.screen {
  position: relative;
  padding: calc(var(--ch) * var(--my)) calc(var(--cw) * var(--mx));
  background: #020203;
  border-radius: calc(var(--cw) * 1.6) / calc(var(--ch) * 1.3);
  overflow: hidden;
  box-shadow: 0 0 0 3px #08080a, 0 0 0 7px #26262c, 0 0 0 8px #050506;
}

.tt-in {
  position: relative;
  width: calc(var(--cw) * 40);
  height: calc(var(--ch) * 25);
}

.tt-cells,
.tt-regions,
.tt-hot {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(40, var(--cw));
  grid-template-rows: repeat(25, var(--ch));
}

.tt-cells {
  z-index: 1;
  right: auto;
  width: calc(var(--cw) * 40 / var(--sx, 1));
  grid-template-columns: repeat(40, calc(var(--cw) / var(--sx, 1)));
  transform: scaleX(var(--sx, 1));
  transform-origin: 0 0;
  font-family: 'VT323', ui-monospace, monospace;
  font-size: var(--fs);
  line-height: var(--ch);
  white-space: pre;
  user-select: none;
}

.tt-cells span {
  display: block;
  min-width: 0;
  text-align: center;
  text-shadow: 0 0 calc(var(--fs) * 0.3) currentColor;
}

.tt-cells .dh {
  grid-row: span 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tt-cells .dh i {
  display: block;
  font-style: normal;
  line-height: var(--ch);
  transform: scaleY(2);
}

.tt-cells .mi { transform: scaleX(-1); }

.f0 { color: #050505; }
.f1 { color: #ff2b2b; }
.f2 { color: #2dff4a; }
.f3 { color: #fff23a; }
.f4 { color: #3343ff; }
.f5 { color: #ff45f2; }
.f6 { color: #3cfcff; }
.f7 { color: #f6f6ee; }
.b0 { background: #050505; }
.b1 { background: #ff2b2b; }
.b2 { background: #2dff4a; }
.b3 { background: #fff23a; }
.b4 { background: #3343ff; }
.b5 { background: #ff45f2; }
.b6 { background: #3cfcff; }
.b7 { background: #f6f6ee; }

.f0 { text-shadow: none !important; }

.fl { animation: tt-flash 1.2s step-end infinite; }
.fb { animation: tt-flashbg 1.2s step-end infinite; }
@keyframes tt-flash { 50% { color: transparent; text-shadow: none; } }
@keyframes tt-flashbg { 50% { background: transparent; } }

/*
  Concealed text stays hidden until REVEAL. Each hidden letter shows as a dim
  block in its own colour, so the shape of the words says something is there.
*/
.tt-cells span { position: relative; }
.f0 { --k: #050505; }
.f1 { --k: #ff2b2b; }
.f2 { --k: #2dff4a; }
.f3 { --k: #fff23a; }
.f4 { --k: #3343ff; }
.f5 { --k: #ff45f2; }
.f6 { --k: #3cfcff; }
.f7 { --k: #f6f6ee; }

.screen:not(.rv) .tt-cells .cc { color: transparent !important; text-shadow: none !important; }

.screen:not(.rv) .tt-cells .cc.t::after,
.screen.rv.rv-go .tt-cells .cc.t::after {
  content: "";
  position: absolute;
  left: 9%;
  right: 9%;
  top: 22%;
  bottom: 22%;
  background: rgba(246, 246, 238, 0.28);
  background: color-mix(in srgb, var(--k, #f6f6ee) 46%, transparent);
  pointer-events: none;
}

.screen:not(.rv) .tt-cells .cc.t::after { animation: tt-hidden 2.4s steps(1, end) infinite; }

@keyframes tt-hidden { 50% { opacity: 0.6; } }

/* REVEAL: the blocks flash and collapse letter by letter, left to right and down the page. */
.screen.rv.rv-go .tt-cells .cc.t {
  animation: tt-untext 0.5s linear both;
  animation-delay: var(--dl, 0ms);
}

.screen.rv.rv-go .tt-cells .cc.t::after {
  animation: tt-unblock 0.5s steps(6, end) both;
  animation-delay: var(--dl, 0ms);
}

@keyframes tt-untext {
  0%, 44% { color: transparent; text-shadow: none; }
  45%, 60% { color: #ffffff; text-shadow: 0 0 calc(var(--fs) * 0.5) #ffffff; }
}

@keyframes tt-unblock {
  0% { opacity: 1; transform: none; }
  35% { opacity: 1; background: #ffffff; transform: scale(1.15, 1.3); }
  100% { opacity: 0; transform: scale(0.3, 0.05); }
}

.tt-mos {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.tt-regions { z-index: 2; pointer-events: none; }

.tt-region {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: cover;
  filter: saturate(1.2) contrast(1.05);
}

.tt-region.flip { transform: scaleX(-1); }

.tt-hot { z-index: 3; }

.hs {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.hs:hover,
.hs:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.13);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.hs:active { background: rgba(255, 255, 255, 0.28); }

/* The Open chapter bar breathes so it reads as the way in. */
.hs-open { animation: tt-open 1.8s ease-in-out infinite; }

@keyframes tt-open {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0); }
  50% { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85), 0 0 18px rgba(255, 255, 255, 0.3); }
}

.hs-open:hover,
.hs-open:focus-visible {
  animation: none;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 0 3px #ffffff;
}

/* Typed page number, large over the top left of the screen. */
.tt-osd {
  position: absolute;
  z-index: 4;
  top: calc(var(--ch) * 0.2);
  left: calc(var(--cw) * 0.4);
  padding: 0 calc(var(--cw) * 0.7);
  background: rgba(5, 5, 5, 0.92);
  box-shadow: 0 0 0 2px currentColor;
  color: #2dff4a;
  font: calc(var(--ch) * 2.4)/1.1 'VT323', ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-shadow: 0 0 calc(var(--ch) * 0.5) currentColor;
  pointer-events: none;
}

.tt-osd.typing { color: #fff23a; }
.tt-osd[hidden] { display: none; }

/* Time left on the subpage. */
.tt-prog {
  position: absolute;
  z-index: 4;
  left: calc(var(--cw) * var(--pc, 0));
  top: calc(var(--ch) * var(--pr, 0) + var(--ch) * 0.4);
  width: calc(var(--cw) * var(--pw, 7));
  height: max(2px, calc(var(--ch) * 0.18));
  background: rgba(246, 246, 238, 0.2);
  pointer-events: none;
}

.tt-prog i {
  display: block;
  width: 0;
  height: 100%;
  background: #f6f6ee;
  box-shadow: 0 0 6px rgba(246, 246, 238, 0.7);
}

.tt-prog.held i { background: #ff2b2b; box-shadow: 0 0 6px #ff2b2b; }
.tt-prog[hidden] { display: none; }

@keyframes tt-prog { from { width: 0; } to { width: 100%; } }

/* MIX: the programme behind the page, text kept in boxes. */
.tt-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  filter: saturate(1.15) contrast(1.05);
}

.tt-collage {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}

.tt-collage img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: cover;
  filter: saturate(1.15) contrast(1.05);
}

.tt-collage[hidden],
.tt-snow[hidden] { display: none; }

.tt-snow {
  position: absolute;
  left: -4%;
  top: -4%;
  width: 108%;
  height: 108%;
  z-index: 0;
  opacity: 0.5;
  image-rendering: pixelated;
  animation: tt-snow 0.3s steps(3, end) infinite;
}

@keyframes tt-snow {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-3%, 2%); }
  66% { transform: translate(2%, -3%); }
}

.screen.mix .tt-cells span { background: transparent; }
.screen.mix .tt-cells span.t { background: #050505; }
.screen.mix .tt-mos,
.screen.mix .tt-regions { opacity: 0; }

/* ---------- Tube effects ---------- */

.tt-noise {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  image-rendering: pixelated;
}

.tt-noise.on { opacity: 0.92; }

.glass {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  border-radius: inherit;
  background:
    radial-gradient(110% 80% at 28% 14%, rgba(255, 255, 255, 0.075), transparent 40%),
    radial-gradient(ellipse at center, transparent 56%, rgba(0, 0, 0, 0.5) 100%),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 2px, rgba(0, 0, 0, 0.24) 2px, rgba(0, 0, 0, 0.24) 3px);
  box-shadow:
    inset 0 0 calc(var(--cw) * 2.4) rgba(0, 0, 0, 0.85),
    inset 0 0 2px rgba(255, 255, 255, 0.1);
}

/* Phosphor stripes. */
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(to right, rgba(255, 0, 0, 0.05) 0, rgba(255, 0, 0, 0.05) 1px, rgba(0, 255, 0, 0.04) 1px, rgba(0, 255, 0, 0.04) 2px, rgba(0, 0, 255, 0.05) 2px, rgba(0, 0, 255, 0.05) 3px);
  mix-blend-mode: screen;
}

/* A slow band of interference and a faint flicker. */
.glass::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -30%;
  height: 30%;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.035) 50%, rgba(255, 255, 255, 0));
  animation: tt-band 9s linear infinite, tt-flicker 7s steps(1, end) infinite;
}

@keyframes tt-band {
  from { transform: translateY(0); }
  to { transform: translateY(440%); }
}

@keyframes tt-flicker {
  0% { opacity: 1; }
  41% { opacity: 0.4; }
  42% { opacity: 1; }
  77% { opacity: 0.6; }
  78% { opacity: 1; }
}

.screen.roll .tt-cells,
.screen.roll .tt-mos,
.screen.roll .tt-regions {
  animation: tt-arrive 0.32s steps(10, end) both;
}

@keyframes tt-arrive {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}

.screen.pwr .tt-in { animation: tt-power 0.8s cubic-bezier(0.2, 0.7, 0.2, 1) both; }

@keyframes tt-power {
  0% { transform: scale(0.2, 0.004); filter: brightness(5); }
  30% { transform: scale(1, 0.004); filter: brightness(4); }
  70% { transform: scale(1, 1); filter: brightness(1.8); }
  100% { transform: none; filter: none; }
}

/* ---------- Set furniture ---------- */

.tv-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 clamp(16px, 2.2vw, 30px);
  color: #8b8b93;
  font: 700 12px/1 'Archivo Narrow', sans-serif;
  letter-spacing: 0.42em;
}

.tv-name { white-space: nowrap; }

.tv-led {
  margin-left: auto;
  padding: 4px 8px 3px;
  border-radius: 4px;
  background: #170505;
  color: #ff4a36;
  font: 22px/1 'VT323', monospace;
  letter-spacing: 0.08em;
  text-shadow: 0 0 8px rgba(255, 50, 30, 0.85);
  white-space: nowrap;
}

.tv-basket {
  color: #ff45f2;
  font: 20px/1 'VT323', monospace;
  letter-spacing: 0.05em;
  text-shadow: 0 0 8px rgba(255, 69, 242, 0.6);
  white-space: nowrap;
}

.tv-power {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2dff4a;
  box-shadow: 0 0 8px #2dff4a;
}

/* ---------- Remote ---------- */

.remote {
  position: relative;
  flex: 0 0 216px;
  width: 216px;
  min-width: 0;
  display: grid;
  gap: 16px;
  padding: 26px 16px 24px;
  border-radius: 32px 32px 44px 44px;
  background: linear-gradient(170deg, #2e2e34, #1a1a1d 60%, #121214);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09), 0 30px 60px rgba(0, 0, 0, 0.6);
}

/* The lamp that blinks when a key sends. */
.rk-ir {
  position: absolute;
  top: 10px;
  left: 50%;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  border-radius: 50%;
  background: #3a1010;
  transition: background 0.08s, box-shadow 0.08s;
}

.rk-ir.on { background: #ff3b2b; box-shadow: 0 0 10px #ff3b2b; }

.rk-fast {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.rk-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas: ". up ." "left ok right" ". down .";
  gap: 6px;
}

.p-up { grid-area: up; }
.p-left { grid-area: left; }
.p-ok { grid-area: ok; }
.p-right { grid-area: right; }
.p-down { grid-area: down; }

.rk-side { display: grid; gap: 10px; min-width: 0; }

.rk-fn {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.rk-digits {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.rk-digits .rk:last-child { grid-column: 2; }

.rk {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(#3c3c43, #26262b);
  color: #ececf1;
  font: 700 18px/1 'Archivo Narrow', sans-serif;
  box-shadow: 0 3px 0 #0a0a0c, inset 0 1px 0 rgba(255, 255, 255, 0.13);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.07s ease, box-shadow 0.07s ease, filter 0.07s ease;
}

.rk:hover { background: linear-gradient(#46464e, #2c2c32); }

.rk:active,
.rk.hit {
  transform: translateY(2px) scale(0.96);
  box-shadow: 0 1px 0 #0a0a0c, inset 0 1px 0 rgba(255, 255, 255, 0.06);
  filter: brightness(1.35);
}

.rk:focus-visible { outline: 2px solid #fff23a; outline-offset: 2px; }

/* Colour keys: a coloured bar with its name underneath. */
.fk {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 50px;
  padding: 7px 2px 6px;
  border-radius: 10px;
}

.fk i {
  display: block;
  width: 100%;
  max-width: 38px;
  height: 14px;
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.fk span {
  max-width: 100%;
  overflow: hidden;
  font: 700 10.5px/1 'Archivo Narrow', 'Arial Narrow', sans-serif;
  letter-spacing: 0.01em;
  color: #d4d4da;
  white-space: nowrap;
}

.k-red i { background: linear-gradient(#ff5a5a, #c01616); }
.k-green i { background: linear-gradient(#5dff6e, #13a524); }
.k-yellow i { background: linear-gradient(#fff56a, #c9b800); }
.k-cyan i { background: linear-gradient(#7afdff, #0fb3c4); }

.k-red span { color: #ff8a8a; }
.k-green span { color: #8dff98; }
.k-yellow span { color: #fff38a; }
.k-cyan span { color: #9cfdff; }

.pk { font-size: 15px; }

.p-ok {
  border-radius: 50%;
  aspect-ratio: 1;
  justify-self: center;
  width: 100%;
  max-width: 56px;
  background: linear-gradient(#55555e, #2f2f35);
  font-size: 15px;
  letter-spacing: 0.04em;
}

.fn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lamp {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3e3e45;
}

/* Hold, Mix and Reveal stay lit while they are on. */
.rk[aria-pressed="true"] {
  color: #fff23a;
  box-shadow: inset 0 0 0 2px #fff23a, 0 1px 0 #0a0a0c, 0 0 14px rgba(255, 242, 58, 0.35);
  transform: translateY(1px);
}

.rk[aria-pressed="true"] .lamp { background: #ff3b2b; box-shadow: 0 0 8px #ff3b2b; }

.k-cyan[aria-pressed="true"] { box-shadow: inset 0 0 0 2px #3cfcff, 0 1px 0 #0a0a0c, 0 0 16px rgba(60, 252, 255, 0.45); }
.k-cyan[aria-pressed="true"] i { box-shadow: 0 0 10px #3cfcff, inset 0 1px 0 rgba(255, 255, 255, 0.5); }
.k-cyan[aria-pressed="true"] span { color: #ffffff; }

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Phones ---------- */

@media (max-width: 819px) {
  :root { --mx: 0.45; --my: 0.3; }

  .room {
    flex-direction: column;
    justify-content: flex-start;
    gap: 14px;
    padding: 8px 8px 24px;
  }

  .tv {
    padding: 6px 6px 40px;
    border-radius: 16px;
  }

  .screen {
    border-radius: calc(var(--cw) * 1.2) / calc(var(--ch) * 0.9);
    box-shadow: 0 0 0 2px #08080a, 0 0 0 4px #26262c;
  }

  .tv-foot {
    height: 40px;
    gap: 10px;
    padding: 0 10px;
    font-size: 10px;
    letter-spacing: 0.3em;
  }

  .tv-led { font-size: 18px; padding: 3px 6px 2px; }
  .tv-basket { font-size: 17px; }

  .remote {
    flex: none;
    width: 100%;
    max-width: 480px;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    grid-template-areas: "fast fast" "pad side";
    align-items: center;
    gap: 10px;
    padding: 18px 12px 12px;
    border-radius: 18px;
  }

  .rk-ir { top: 6px; }
  .rk-fast { grid-area: fast; gap: 6px; }
  .rk-pad { grid-area: pad; gap: 5px; }
  .rk-side { grid-area: side; gap: 6px; }
  .rk-fn { gap: 6px; }
  .rk-digits { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .rk-digits .rk:last-child { grid-column: auto; }
  .rk { font-size: 17px; border-radius: 10px; }
  .pk { min-height: 42px; }
  .p-ok { max-width: 48px; min-height: 0; }
  .fn { font-size: 12px; letter-spacing: 0.04em; }
  .fk { min-height: 48px; }
  .fk span { font-size: 11.5px; }
  .fk i { max-width: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .glass::after,
  .fl,
  .fb { animation: none !important; }
  .screen.roll .tt-cells,
  .screen.roll .tt-mos,
  .screen.roll .tt-regions,
  .screen.pwr .tt-in { animation: none !important; }
  .screen .tt-cells .cc.t::after,
  .hs-open,
  .tt-snow { animation: none !important; }
  .rk { transition: none; }
}
