/* THE LABYRINTH -- CGA mode 4, palette 1.
   Four colors. That is the whole budget:
   black, cyan, magenta, white. Nothing else gets in. */
:root {
  --blk: #000000;
  --cyn: #55ffff;
  --mag: #ff55ff;
  --wht: #ffffff;
  --mono: "Perfect DOS VGA 437", "Px437 IBM VGA8", Consolas, "Lucida Console",
          "DejaVu Sans Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--blk);
  color: var(--cyn);
  font-family: var(--mono);
  overflow: hidden;
  /* Text selection would ruin a keyboard game. */
  -webkit-user-select: none;
  user-select: none;
}

.c-cyn { color: var(--cyn); }
.c-mag { color: var(--mag); }
.c-wht { color: var(--wht); }
.hidden { display: none !important; }

.blink { animation: blink 1s steps(1, end) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- CRT shell ---------- */
#crt {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse 120% 120% at 50% 50%, #000000 55%, #000000 100%);
}

#frame {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 6px 8px 4px;
  gap: 3px;
}

/* Held still while it closes on you: a tight, fast tremor, not the
   full shake. You are frozen, and it should feel like being frozen. */
#frame.seen { animation: seen-tremor 60ms steps(2, end) infinite; }
@keyframes seen-tremor {
  0%   { transform: translate(0, 0); }
  50%  { transform: translate(-1px, 1px); }
  100% { transform: translate(1px, 0); }
}

/* Violent shake for the jump scare. */
#frame.scare { animation: scare-shake 90ms steps(2, end) infinite; }
@keyframes scare-shake {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-9px, 5px) rotate(-0.6deg); }
  50%  { transform: translate(7px, -7px) rotate(0.5deg); }
  75%  { transform: translate(-5px, -4px) rotate(0.3deg); }
  100% { transform: translate(6px, 6px) rotate(-0.4deg); }
}

/* ---------- header ---------- */
#header {
  flex: 0 0 auto;
  line-height: 1.05;
  font-size: 11px;
  color: var(--cyn);
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
}
.hdr-rule { letter-spacing: 0; }
.hdr-body { display: flex; align-items: baseline; justify-content: space-between; }
.hdr-text { flex: 1 1 auto; text-align: center; overflow: hidden; text-overflow: ellipsis; }
.hdr-pipe { flex: 0 0 auto; color: var(--cyn); }
#header .c-mag { text-shadow: 0 0 6px var(--mag); }

/* ---------- toolbar ---------- */
#toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  padding: 2px 2px 3px;
  border-bottom: 1px solid var(--cyn);
}
.tb-item { display: flex; align-items: center; gap: 6px; }

#style-select {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--blk);
  color: var(--wht);
  border: 1px solid var(--cyn);
  padding: 1px 4px;
  outline: none;
  cursor: pointer;
}
#style-select:focus { border-color: var(--mag); color: var(--mag); }
#style-select option { background: var(--blk); color: var(--wht); }

#toolbar button {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--blk);
  color: var(--cyn);
  border: 1px solid var(--cyn);
  padding: 1px 6px;
  cursor: pointer;
  letter-spacing: 0.5px;
}
#toolbar button:hover  { background: var(--cyn); color: var(--blk); }
#toolbar button:active { background: var(--mag); color: var(--blk); border-color: var(--mag); }
#ping-btn { color: var(--mag); border-color: var(--mag); }
#ping-btn:hover { background: var(--mag); color: var(--blk); }
#ping-btn:disabled {
  color: var(--cyn); border-color: var(--cyn);
  opacity: 0.45; cursor: default; background: var(--blk);
}

/* ---------- status ---------- */
#status {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  padding: 2px 2px;
  white-space: nowrap;
  overflow: hidden;
}
#status b { color: var(--wht); font-weight: normal; }
.st-sep { color: var(--cyn); }
#st-msg { color: var(--mag); overflow: hidden; text-overflow: ellipsis; }

/* ---------- stage ---------- */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border: 3px double var(--cyn);
  background: var(--blk);
  overflow: hidden;
}
#screen { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--blk);
  text-align: center;
  padding: 12px;
  z-index: 5;
}
.big-msg {
  font-size: clamp(20px, 5vw, 46px);
  letter-spacing: 4px;
  text-shadow: 0 0 14px currentColor;
}
.sub-msg { font-size: clamp(11px, 1.7vw, 15px); color: var(--wht); letter-spacing: 1px; }
.sub-msg b { color: var(--mag); }

#boot { justify-content: center; gap: 6px; }
#boot-art {
  margin: 0;
  color: var(--mag);
  font-size: clamp(5px, 1.15vw, 11px);
  line-height: 1.02;
  letter-spacing: 0;
  text-shadow: 0 0 10px var(--mag);
  white-space: pre;
}
#boot-log {
  color: var(--cyn);
  font-size: clamp(9px, 1.3vw, 12px);
  line-height: 1.35;
  min-height: 7.5em;
  text-align: left;
  white-space: pre;
}
#boot-go { color: var(--wht); font-size: clamp(11px, 1.8vw, 16px); letter-spacing: 2px; }

/* ---------- footer ---------- */
#footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 2px 0;
  border-top: 1px solid var(--cyn);
  font-size: 11px;
}
#legend { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#legend b { font-weight: normal; text-shadow: 0 0 6px currentColor; }

/* Touch d-pad: hidden on real keyboards, shown on touch devices. */
#dpad { display: none; }
#dpad .dpad-row { display: flex; gap: 4px; }
#dpad button {
  font-family: var(--mono);
  width: 38px; height: 30px;
  background: var(--blk);
  color: var(--cyn);
  border: 1px solid var(--cyn);
  font-size: 13px;
  cursor: pointer;
}
#dpad button:active { background: var(--cyn); color: var(--blk); }
#dpad .dpad-ping { color: var(--mag); border-color: var(--mag); }
#dpad .dpad-ping:active { background: var(--mag); color: var(--blk); }
body.touch #dpad { display: flex; flex-direction: column; align-items: center; gap: 4px; }
body.touch #legend { font-size: 10px; gap: 6px; }

/* ---------- scanlines + flash ---------- */
#scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.38) 3px,
    rgba(0, 0, 0, 0.38) 4px
  );
}

/* Full-screen strobe, driven from JS. */
#flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  opacity: 0;
  background: var(--mag);
}

@media (prefers-reduced-motion: reduce) {
  .blink { animation: none; }
  #frame.scare { animation: none; }
  #frame.seen { animation: none; }
}

/* Small windows: shed chrome before shedding playfield. */
@media (max-height: 420px) {
  #header .hdr-rule { display: none; }
  #footer { font-size: 10px; }
}
@media (max-width: 520px) {
  #header { font-size: 9px; }
  #status { font-size: 10px; }
  #toolbar { font-size: 10px; }
  #style-select, #toolbar button { font-size: 10px; }
}
