/* Font: "ToshibaSat 8x16" from The Ultimate Oldschool PC Font Pack by VileR (int10h.org), CC BY-SA 4.0 */
@font-face {
  font-family: 'ToshibaSat 8x16';
  src: url('../fonts/WebPlus_ToshibaSat_8x16.woff') format('woff');
  font-display: block;
}

/* braille (Steam comment art) in the same 8x16 cell: tools/make-braille-font.py */
@font-face {
  font-family: 'Loco Braille 8x16';
  src: url('../fonts/LocoBraille-8x16.woff2') format('woff2');
  unicode-range: U+2800-28FF;
  font-display: block;
}

:root {
  --bg: #09090b;
  --fg: #afafaf;
  --dim: #55555e;
  --bright: #f4f4f6;
  --accent: #c67ef6;
  --deep: #850cd5;
  --cw: 8px;
  --ch: 16px;
  color-scheme: dark;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

body {
  color: var(--fg);
  font-family: 'ToshibaSat 8x16', 'Loco Braille 8x16', ui-monospace, Menlo, Consolas, monospace;
  -webkit-font-smoothing: none;
  -webkit-tap-highlight-color: transparent;
}

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

#stage {
  position: absolute;
  overflow: hidden;
}

#screen {
  display: block;
}

/* CRT: scanlines + soft vignette */
#stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.45) 100%),
    repeating-linear-gradient(to bottom, transparent 0, transparent 2px, rgba(0, 0, 0, 0.22) 2px, rgba(0, 0, 0, 0.22) 3px);
  z-index: 3;
}

/* ---------- text overlays share the grid metrics ---------- */
#menu,
#footer,
#skip,
#soundctl {
  position: absolute;
  font-family: inherit;
  font-size: var(--ch);
  line-height: var(--ch);
  white-space: pre;
  z-index: 2;
}

#menu {
  font-size: calc(var(--ch) * var(--ms, 1));
  line-height: calc(var(--ch) * var(--ms, 1));
}

#menu .ln {
  display: block;
  height: calc(var(--ch) * var(--ms, 1));
  width: calc(var(--w) * 1ch);
  overflow: hidden;
  background: var(--bg);
  animation: type 0.26s steps(42, end) both;
  animation-delay: calc(var(--i) * 70ms);
}

#menu.instant .ln {
  animation: none;
}

#menu .tag {
  background: transparent;
  text-align: center;
  color: var(--dim);
}

#menu .tag span {
  background: var(--bg);
}

#menu .frame {
  color: var(--deep);
}

#menu a.item {
  position: relative;
  color: var(--fg);
  text-decoration: none;
  outline: none;
  cursor: pointer;
}

/* taller invisible tap area without breaking the box lines */
#menu a.item::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -0.45em;
  bottom: -0.45em;
}

#menu a.item .cur {
  visibility: hidden;
  color: var(--accent);
}

#menu a.item .dots {
  color: var(--dim);
}

#menu a.item.sel {
  background: #1f0b33;
}

#menu a.item.sel .cur {
  visibility: visible;
  animation: blink 0.9s steps(1) infinite;
}

#menu a.item.sel .lbl {
  color: var(--bright);
}

#menu a.item.sel .val {
  color: var(--accent);
}

#menu a.item.nope .val {
  animation: nope 0.16s steps(1) 4;
}

#footer {
  left: 0;
  right: 0;
  height: var(--ch);
  display: flex;
  justify-content: space-between;
  padding: 0 calc(var(--cw) * 2);
  color: var(--dim);
  animation: fade 0.6s steps(4) both;
}

#footer a {
  color: var(--dim);
  text-decoration: none;
}

@media (max-width: 640px) {
  #footer .wide {
    display: none;
  }
}

#footer a:hover,
#footer a:focus-visible {
  color: var(--accent);
  outline: none;
}

#skip {
  right: calc(var(--cw) * 2);
  bottom: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  cursor: pointer;
  animation: blink 1.6s steps(1) infinite;
  opacity: 0;
}

.ready #skip {
  opacity: 1;
}

#soundctl {
  top: 0;
  right: calc(var(--cw) * 2);
  display: flex;
  opacity: 0;
}

.ready #soundctl {
  opacity: 1;
}

#soundctl button {
  padding: 0 calc(var(--cw) * 0.5);
  border: 0;
  background: var(--bg);
  color: var(--dim);
  font: inherit;
  line-height: inherit;
  cursor: pointer;
  white-space: pre;
}

#soundctl button:hover,
#soundctl button:focus-visible {
  color: var(--fg);
  outline: none;
}

#soundctl #voldown,
#soundctl #volup,
#soundctl #songnext {
  display: none;
}

#soundctl.on #voldown,
#soundctl.on #volup,
#soundctl.on #songnext {
  display: block;
}

#soundctl.on #sound {
  color: var(--accent);
}

#songtoast {
  position: absolute;
  top: 100%;
  right: 0;
  padding: 0 calc(var(--cw) * 0.5);
  white-space: pre;
  color: var(--accent);
  background: var(--bg);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.45s ease, transform 0.45s ease;
  pointer-events: none;
}

#songtoast.show {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  #songtoast {
    transition: none;
  }
}

.noscript {
  color: var(--fg);
  font-size: 16px;
  padding: 2rem;
}

.noscript a {
  color: var(--accent);
}

@keyframes type {
  from {
    width: 0;
  }
}

@keyframes blink {
  50% {
    visibility: hidden;
  }
}

@keyframes nope {
  50% {
    color: var(--bg);
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

/* ---------- 404 ---------- */
body.lost {
  display: grid;
  place-items: center;
  overflow: auto;
}

.lost main {
  padding: 2rem 1rem;
  font-size: 16px;
  line-height: 16px;
}

.lost pre {
  margin: 0 0 2rem;
  font: inherit;
  color: var(--fg);
}

.lost h1 {
  margin: 0 0 1rem;
  font-size: 16px;
  font-weight: normal;
  color: var(--accent);
}

.lost a {
  color: var(--accent);
}

/* ---------- projects BBS ---------- */
#bbs {
  position: absolute;
  z-index: 2;
  visibility: hidden;
  font-size: calc(var(--ch) * var(--ms, 1));
  line-height: calc(var(--ch) * var(--ms, 1));
}

.ready #bbs.on {
  visibility: visible;
}

#bbs ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

#bbs .ln,
#bbs .row {
  display: block;
  height: calc(var(--ch) * var(--ms, 1));
  width: calc(var(--w) * 1ch);
  overflow: hidden;
  white-space: pre;
  background: var(--bg);
}

#bbs.on .ln,
#bbs.on .row {
  animation: type 0.2s steps(44, end) both;
  animation-delay: calc(var(--i) * 40ms);
}

#bbs.instant .ln,
#bbs.instant .row {
  animation: none;
}

#bbs .frame {
  color: var(--deep);
}

#bbs .hdr {
  color: var(--dim);
}

#bbs a.file {
  display: block;
  color: var(--fg);
  text-decoration: none;
  outline: none;
  cursor: pointer;
}

#bbs a.file .key {
  color: var(--accent);
}

#bbs a.file .name {
  color: var(--bright);
}

#bbs a.file .dots {
  color: var(--dim);
}

#bbs a.file .type {
  color: #8fb0e6;
}

#bbs a.file .desc {
  color: var(--fg);
}

#bbs a.file.sel .in {
  background: #2a0d45;
}

#bbs a.file.sel .key {
  background: var(--accent);
  color: var(--bg);
}

#bbs a.file.sel .name {
  color: #fff;
}

#bbs .prompt .psel,
#bbs .prompt .cur {
  color: var(--accent);
}

#bbs .prompt .cur {
  animation: blink 1s steps(1) infinite;
}

#status {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  height: calc(var(--ch) * var(--ms, 1));
  padding: 0 var(--cw);
  font-size: calc(var(--ch) * var(--ms, 1));
  line-height: calc(var(--ch) * var(--ms, 1));
  white-space: pre;
  background: var(--deep);
  color: var(--bright);
  animation: fade 0.4s steps(4) both;
}

#status a {
  color: var(--bright);
  text-decoration: none;
}

#status a:hover,
#status a:focus-visible {
  background: var(--accent);
  color: var(--bg);
  outline: none;
}

#status .hint {
  color: #dcc6ff;
}

@media (max-width: 640px) {
  #status .hint {
    display: none;
  }
}

/* ---------- leaving a page (with the glitch wipe on the canvas) ---------- */
body.leaving #menu,
body.leaving #footer,
body.leaving #soundctl,
body.leaving #skip,
body.leaving #bbs,
body.leaving #status {
  animation: leave 0.45s steps(4) forwards !important;
}

@keyframes leave {
  to {
    opacity: 0;
  }
}

/* ---------- project launch ("dialing") window ---------- */
#launch {
  position: absolute;
  z-index: 3;
  box-shadow: 0 0 0 100vmax rgba(9, 9, 11, 0.6);
}

#launch .ln {
  width: calc(var(--lw) * 1ch);
}

#launch .fill {
  color: var(--accent);
}

#launch .empty {
  color: var(--deep);
}

#launch .dim {
  color: var(--dim);
}

#launch .warn {
  color: #ff6b8b;
}

#launch .ok {
  color: var(--bright);
  animation: blink 0.5s steps(1) infinite;
}

#launch a.retry {
  color: var(--bg);
  background: var(--accent);
  text-decoration: none;
  outline: none;
}

#launch.closing {
  animation: leave 0.3s steps(3) forwards;
}

#bbs a.file.dialing .in {
  animation: dialing 0.16s steps(1) infinite;
}

@keyframes dialing {
  50% {
    background: var(--accent);
  }
}

/* ---------- guestbook ---------- */
#gb {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 4ch;
  visibility: hidden;
  font-size: calc(var(--ch) * var(--ms, 1));
  line-height: calc(var(--ch) * var(--ms, 1));
}

.ready #gb.on {
  visibility: visible;
}

#gb.one {
  flex-direction: column;
  gap: calc(var(--ch) * var(--ms, 1));
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--deep) var(--bg);
}

#gb .ln,
#gb .editor {
  display: block;
  height: calc(var(--ch) * var(--ms, 1));
  width: calc(var(--w) * 1ch);
  overflow: hidden;
  white-space: pre;
  background: var(--bg);
}

#gb .editor {
  display: flex;
  height: auto;
}

#gb.on .ln,
#gb.on .editor {
  animation: type 0.2s steps(44, end) both;
  animation-delay: calc(min(var(--i, 0), 24) * 35ms);
}

#gb.instant .ln,
#gb.instant .editor {
  animation: none;
}

#gb .frame {
  color: var(--deep);
}

#gb .dim {
  color: var(--dim);
}

#gb .warn {
  color: #ff6b8b;
}

#gb .ok {
  color: var(--accent);
}

#gb .fill {
  color: var(--accent);
}

#gb .empty {
  color: var(--deep);
}

#compose {
  flex: none;
  margin: 0;
}

#compose .ruler {
  color: var(--dim);
}

#compose .side {
  white-space: pre;
}

#msg {
  display: block;
  width: calc(40 * 1ch);
  height: calc(8 * var(--ch) * var(--ms, 1));
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  resize: none;
  overflow-y: auto;
  scrollbar-width: none;
  font: inherit;
  line-height: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--bright);
  background: var(--bg);
  caret-color: var(--accent);
}

#msg::placeholder {
  color: var(--dim);
  opacity: 1;
}

#compose .send {
  padding: 0;
  border: 0;
  font: inherit;
  line-height: inherit;
  color: var(--bg);
  background: var(--accent);
  cursor: pointer;
}

#compose .send:hover,
#compose .send:focus-visible {
  background: var(--bright);
  outline: none;
}

#compose .send:disabled {
  color: var(--dim);
  background: var(--deep);
  cursor: wait;
}

#compose .hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

#board {
  flex: none;
  height: 100%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--deep) var(--bg);
}

#gb.one #board {
  height: auto;
  overflow: visible;
}

#msgs {
  list-style: none;
  margin: 0;
  padding: 0;
}

#msgs .msg {
  margin: 0 0 calc(var(--ch) * var(--ms, 1));
}

#msgs .id {
  color: var(--bright);
}

#msgs .who {
  color: var(--accent);
}

#msgs .meta {
  color: var(--dim);
}

#msgs .txt {
  color: var(--fg);
}

#msgs .msg.new .txt {
  animation: freshmsg 0.22s steps(1) 6;
}

@keyframes freshmsg {
  50% {
    color: var(--bg);
    background: var(--accent);
  }
}

#more {
  display: block;
  width: calc(var(--w) * 1ch);
  margin: 0 0 calc(var(--ch) * var(--ms, 1));
  padding: 0;
  border: 0;
  font: inherit;
  line-height: inherit;
  color: var(--accent);
  background: var(--bg);
  cursor: pointer;
}

#more:hover,
#more:focus-visible {
  color: var(--bg);
  background: var(--accent);
  outline: none;
}

body.leaving #gb {
  animation: leave 0.45s steps(4) forwards !important;
}

/* ---------- first-load "press S / tap for sound" hint ---------- */
#soundhint {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  font-size: max(var(--ch), 14px);
  line-height: max(var(--ch), 14px);
  white-space: pre;
  text-align: left;
  color: var(--fg);
  background: var(--bg);
  cursor: pointer;
  opacity: 0;
  transform: translate(-50%, calc(-50% + 8px));
  transition: opacity 0.7s ease, transform 0.7s ease, box-shadow 0.7s ease;
  box-shadow: 0 0 28px rgba(133, 12, 213, 0.18);
}

#soundhint.show {
  opacity: 1;
  transform: translate(-50%, -50%);
}

#soundhint .ln {
  display: block;
}

#soundhint .frame {
  color: var(--deep);
}

#soundhint .hl {
  color: var(--bright);
  animation: hintglow 2.6s ease-in-out infinite;
}

#soundhint .dim {
  color: var(--dim);
}

#soundhint:hover,
#soundhint:focus-visible {
  outline: none;
  box-shadow: 0 0 36px rgba(198, 126, 246, 0.35);
}

#soundhint:hover .hl,
#soundhint:focus-visible .hl {
  color: var(--accent);
  animation: none;
}

@keyframes hintglow {
  50% {
    color: var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  #soundhint {
    transition: none;
  }

  #soundhint .hl {
    animation: none;
  }
}

body.leaving #soundhint {
  opacity: 0;
}
