/* ==========================================================
   DOS-style homepage
   Font: Web437 IBM VGA 8x16, (c) VileR, int10h.org, CC BY-SA 4.0
   ========================================================== */

@font-face {
  font-family: "VGA";
  src: url("../fonts/Web437_IBM_VGA_8x16.woff") format("woff");
  font-display: swap;
}

:root {
  /* the classic 16-colour palette (the bits we use) */
  --blue:   #0000AA;
  --navy:   #000033;
  --grey:   #AAAAAA;
  --white:  #FFFFFF;
  --black:  #000000;
  --cyan:   #00AAAA;
  --lcyan:  #55FFFF;
  --yellow: #FFFF55;
  --lred:   #FF5555;
  --green:  #55FF55;
  --hot:    #800000;           /* menu hotkey letter */
  --dim:    #8A8A8A;

  --shadow-x: 2ch;
  --shadow: var(--shadow-x) 1em 0 rgba(0, 0, 0, .9);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--blue);
  color: var(--white);
  font: 16px/1.25 "VGA", ui-monospace, "DejaVu Sans Mono", Menlo, Consolas, monospace;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

a { color: var(--yellow); }
p { margin: .5em 0; }
h1, h2 { font-size: 1em; font-weight: normal; }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
::selection { background: var(--cyan); color: var(--black); }
.dim { color: var(--dim); }

/* show keyboard hints only to keyboard-ish devices */
.touch-only { display: none; }
@media (pointer: coarse) {
  .kb-only { display: none; }
  .touch-only { display: inline; }
}

/* ---------- menu bar ---------- */
.menubar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: stretch;
  background: var(--grey);
  color: var(--black);
  padding: 0 1ch;
}
.menubar nav { display: flex; flex-wrap: wrap; }
.menubar a {
  display: block;
  padding: .2em 1ch;
  color: inherit;
  text-decoration: none;
}
.hk { color: var(--hot); }
.menubar a:hover,
.menubar a:focus-visible,
.menubar a[aria-current] { background: var(--black); color: var(--grey); outline: none; }
.menubar a:hover .hk,
.menubar a:focus-visible .hk,
.menubar a[aria-current] .hk { color: var(--white); }
.clock { margin-left: auto; padding: .2em 1ch; }
.zulu { color: var(--hot); }

/* ---------- desk ---------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2em 16px 3em;
}
.view {
  width: 100%;
  max-width: 66ch;
  padding-right: var(--shadow-x);   /* room for the drop shadow */
  display: flex;
  flex-direction: column;
  align-items: center;
}
.view.wide { max-width: 84ch; }
.view[hidden] { display: none; }

/* ---------- windows ---------- */
.window {
  --bg: var(--grey);
  --fg: var(--black);
  --line: var(--black);
  --hl-bg: var(--black);
  --hl-fg: var(--white);
  position: relative;
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  padding: .5em 1ch;
  box-shadow: var(--shadow);
  margin-bottom: 1.5em;
}
.frame {
  position: relative;
  border: 4px double var(--line);
  padding: 1.25em 2ch 1em;
}
.title {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 0 1ch;
  background: var(--bg);
  white-space: nowrap;
  line-height: 1;
}
.title:focus { outline: none; }
.title:focus-visible { background: var(--fg); color: var(--bg); }

.rule { border-top: 1px solid var(--line); margin: .75em -2ch; }
.dialog .frame { text-align: center; }
.sub { opacity: .8; }
.hint { font-size: .9em; opacity: .85; margin: .5em 0 0; }

/* variants */
.window.panel { --bg: var(--blue); --fg: var(--white); --line: var(--lcyan); --hl-bg: var(--cyan); --hl-fg: var(--black); }
.window.help  { --bg: var(--cyan); --fg: var(--black); --line: var(--black); }
.window.term  { --bg: var(--grey); --fg: var(--black); --line: var(--black); }
.term .screen { color: #CCCCCC; }
.window.game  { --bg: var(--black); --fg: var(--white); --line: var(--grey); --hl-bg: var(--grey); --hl-fg: var(--black); }

/* ---------- buttons ---------- */
.btns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .4em 2ch;
  margin: 1em 0 .25em;
}
.btn {
  display: inline-block;
  padding: 0 .5ch;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.btn::before { content: "< "; }
.btn::after  { content: " >"; }
.btn:hover,
.btn:focus-visible { background: var(--hl-bg, var(--black)); color: var(--hl-fg, var(--white)); outline: none; }

/* buttons sitting directly on the blue desk (Bootstrap-DOS style) */
.on-blue .btn {
  background: var(--grey);
  color: var(--black);
  padding: .15em 1ch;
  box-shadow: 1ch .5em 0 var(--black);
}
.on-blue .btn:hover,
.on-blue .btn:focus-visible { background: var(--white); color: var(--black); }

/* ---------- home ---------- */
.hero { width: 100%; text-align: center; margin-bottom: 2em; }
.banner svg,
.banner-out svg {
  display: block;
  margin: 0 auto;
  width: min(100%, calc(var(--cols) * 10px));   /* ~10px per block column at most */
  height: auto;
}
.banner .b { fill: var(--yellow); }
.banner .s { fill: var(--navy); }
.tagline { color: var(--lcyan); margin-top: 1em; }

/* ---------- about ---------- */
.facts, .keys {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: .25em 2ch;
  margin: 0;
}
.facts dt, .keys dt { color: var(--hot); }
.facts dd, .keys dd { margin: 0; overflow-wrap: anywhere; }
.keys dt { color: var(--white); background: var(--black); padding: 0 1ch; justify-self: start; }
.bio p { margin: 0 0 .75em; }

/* ---------- contact (file panel) ---------- */
.files-head,
.file {
  display: grid;
  grid-template-columns: 9ch 5ch minmax(0, 1fr);
  gap: 0 1ch;
  padding: .1em .5ch;
}
.files-head { color: var(--yellow); border-bottom: 1px solid var(--line); margin-bottom: .25em; }
.files { list-style: none; margin: 0; padding: 0; }
.file {
  width: 100%;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file span:first-child { color: var(--lcyan); }
.file:hover,
.file:focus-visible { background: var(--cyan); color: var(--black); outline: none; }
.file:hover span,
.file:focus-visible span { color: var(--black); }
.status {
  border-top: 1px solid var(--line);
  margin: .75em -2ch 0;
  padding: .4em 2ch 0;
  color: var(--lcyan);
}

/* ---------- terminal (plain old linux tty) ---------- */
.term .frame { padding: 1.25em 1ch .75em; }
.screen {
  background: var(--black);
  border: 1px solid #555;
  padding: .5em 1ch;
  min-height: 20em;
  cursor: text;
  overflow-wrap: anywhere;
}
.ln { white-space: pre-wrap; min-height: 1.25em; }
.ln .u, .ps1 .u { color: var(--green); }
.ln .p, .ps1 .p { color: #5555FF; }
.ln.err { color: var(--lred); }
.ln.accent, .ln .accent { color: var(--lcyan); }
.ln.ok { color: var(--green); }
.ln.yellow { color: var(--yellow); }
.ln.dim { color: var(--dim); }
.out pre { margin: 0; font: inherit; white-space: pre; overflow-x: auto; line-height: 1.25; }
.banner-out { margin: .25em 0; }
.banner-out svg { margin: 0; width: min(100%, calc(var(--cols) * 6px)); }
.banner-out .b { fill: var(--white); }
.banner-out .s { fill: #333; }
.out pre.matrix { color: var(--green); line-height: 1.1; overflow: hidden; }
.out a { color: var(--lcyan); }
.cmd {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--lcyan);
  cursor: pointer;
  text-decoration: underline;
}
.prompt { display: flex; align-items: baseline; margin: 0; }
.ps1 { white-space: nowrap; margin-right: 1ch; }
#term-in {
  flex: 1;
  min-width: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: inherit;
  font: inherit;
  font-size: 16px;            /* stops iOS zooming on focus */
  line-height: 1.25;
  caret-color: var(--white);
  caret-shape: block;
  outline: none;
}
.chips { display: flex; flex-wrap: wrap; gap: .5em 1ch; margin-top: .75em; }
.chip {
  background: var(--grey);
  border: 0;
  border-radius: 0;
  padding: .1em 1ch;
  color: var(--black);
  font: inherit;
  cursor: pointer;
  min-height: 2em;
  box-shadow: .5ch .25em 0 #444;
}
.chip:hover, .chip:focus-visible { background: var(--white); outline: none; }
.chip:active { transform: translate(.25ch, .15em); box-shadow: none; }

/* ---------- WORM.EXE ---------- */
.scorebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1ch;
  margin-bottom: .5em;
}
.scorebar b { color: var(--yellow); font-weight: normal; }
.board-wrap { position: relative; display: flex; justify-content: center; }
.board {
  margin: 0;
  font-size: min(16px, calc((100vw - 80px) / 20));
  line-height: 1;
  white-space: pre;
  background: var(--navy);
  outline: 1px solid var(--grey);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
.board .w { color: var(--yellow); }
.board .h { color: var(--white); }
.board .f { color: var(--lred); }
.board .x { color: var(--lred); }
.msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
}
.msg:empty { display: none; }
.msg > div {
  background: var(--grey);
  color: var(--black);
  padding: .5em 2ch;
  box-shadow: 1ch .5em 0 var(--black);
  max-width: 90%;
}
.dpad {
  display: none;
  grid-template-columns: repeat(3, 4em);
  grid-template-rows: repeat(2, 3em);
  gap: .5em;
  justify-content: center;
  margin: 1.25em 0 .5em;
}
.dpad button {
  font: inherit;
  font-size: 1.25em;
  background: var(--grey);
  color: var(--black);
  border: 0;
  box-shadow: .5ch .25em 0 #444;
  touch-action: manipulation;
  cursor: pointer;
}
.dpad button:active { transform: translate(.25ch, .15em); box-shadow: none; }
.dpad [data-dir="up"]    { grid-column: 2; grid-row: 1; }
.dpad [data-dir="left"]  { grid-column: 1; grid-row: 2; }
.dpad [data-dir="down"]  { grid-column: 2; grid-row: 2; }
.dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }
@media (pointer: coarse) { .dpad { display: grid; } }

/* ---------- F-key bar ---------- */
.fkeys {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 0 2ch;
  padding: .2em 1ch;
  padding-bottom: max(.2em, env(safe-area-inset-bottom));
  background: var(--cyan);
  color: var(--black);
}
.fkeys button {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  padding: .15em .5ch;
  cursor: pointer;
  text-align: left;
}
.fkeys kbd { font: inherit; background: var(--black); color: var(--white); padding: 0 .5ch; }
.fkeys button:hover,
.fkeys button:focus-visible { background: var(--black); color: var(--lcyan); outline: none; }

/* ---------- boot screen ---------- */
#boot { display: none; }
.booting body { overflow: hidden; }
.booting #boot {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--black);
  color: var(--grey);
  padding: 1em 16px;
  overflow: hidden;
  cursor: pointer;
}
#boot-log { margin: 0; font: inherit; white-space: pre-wrap; }
#boot-log .w { color: var(--white); }
#boot-log .ok { color: var(--green); }
.boot-skip { position: absolute; left: 16px; bottom: 1em; margin: 0; color: #555; }
.cursor { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  :root { --shadow-x: 1ch; --shadow: 1ch .5em 0 rgba(0, 0, 0, .9); }
  main { padding: 1.5em 16px 2em; }
  .window { padding: .4em .5ch; }
  .frame { padding: 1.25em 1.5ch .75em; }
  .rule { margin-left: -1.5ch; margin-right: -1.5ch; }
  .status { margin-left: -1.5ch; margin-right: -1.5ch; padding-left: 1.5ch; }
  .btns { gap: .6em 1ch; }
  .clock { display: none; }
  .menubar { padding: 0; }
  .menubar a { padding: .35em 1ch; }
  .fkeys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
  .fkeys button { padding: .4em .5ch; }
  .files-head, .file { grid-template-columns: 8ch minmax(0, 1fr); }
  .files-head span:nth-child(2), .file span:nth-child(2) { display: none; }
  .file { padding: .35em .5ch; }
}

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
}
