/* Red CS — amber P3 phosphor terminal.
   Single committed look: no light/dark split. Every colour is a token on :root
   and body paints its own background explicitly. */

:root {
  --bg: #0a0a0a;
  --bg-lift: #151008;
  --fg: #ffb000;
  --dim: #8a5f00;
  --hi: #ffd27f;
  --danger: #ff6b3d;

  /* Base size tracks the viewport so a narrow phone shows more columns; the
     A-/A+ control multiplies it rather than replacing it. */
  --fs-scale: 1;
  --fs: calc(clamp(10.5px, 3.15vw, 15px) * var(--fs-scale));
  --lh: 1.35;
  --gutter: 0.75rem;
  --col: min(100%, 720px);

  --glow: 0 0 6px rgba(255, 176, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: var(--fs);
  line-height: var(--lh);

  /* --vvh is set from visualViewport so the on-screen keyboard shrinks the
     layout instead of pushing the input under it. Falls back to dvh. */
  height: 100dvh;
  height: var(--vvh, 100dvh);

  display: flex;
  flex-direction: column;
  overflow: hidden;

  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* `display: contents` so the window wrapper has no effect at all on the
   mobile layout; the desktop media query turns it into a real box. */
.win { display: contents; }

.bar__title { display: none; }
.status { display: none; }

/* ---- CRT dressing -------------------------------------------------------
   Own fixed layer behind everything. Never background-attachment: fixed —
   iOS drops it. No filter/blend animation: mobile paint cost. */

.crt {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 45%, rgba(255, 176, 0, 0.055) 0%, rgba(0, 0, 0, 0) 62%),
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0) 0px,
      rgba(0, 0, 0, 0) 2px,
      rgba(0, 0, 0, 0.28) 3px,
      rgba(0, 0, 0, 0.28) 3px
    ),
    var(--bg);
}

.crt::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(130% 100% at 50% 50%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.75) 100%);
}

/* ---- top bar ------------------------------------------------------------ */

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem var(--gutter);
  border-bottom: 1px solid rgba(255, 176, 0, 0.22);
  width: var(--col);
  margin-inline: auto;
}

.bar__brand {
  font-weight: 700;
  letter-spacing: 0.12em;
  text-shadow: var(--glow);
}

.bar__meta {
  color: var(--dim);
  font-size: 0.82em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}

.bar__tools {
  flex: 0 0 auto;
  display: flex;
  gap: 0.15rem;
}

.bar__btn {
  /* 44px both ways on touch — Apple HIG minimum. The desktop window shrinks
     them, where there is a pointer. */
  min-width: 44px;
  min-height: 44px;
  font: inherit;
  font-size: 0.85em;
  color: var(--fg);
  background: transparent;
  border: 1px solid rgba(255, 176, 0, 0.3);
  border-radius: 3px;
  cursor: pointer;
  padding: 0 0.3rem;
}

.bar__btn:active { background: rgba(255, 176, 0, 0.16); }

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

.screen {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  width: var(--col);
  margin-inline: auto;
  padding: 0.5rem var(--gutter) 0.75rem;
}

.out {
  margin: 0;
  font: inherit;
  /* 80-column content reflows rather than forcing the page to scroll sideways. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-shadow: var(--glow);
}

.out .dim { color: var(--dim); text-shadow: none; }
.out .hi { color: var(--hi); }
.out .sim,
.sim { color: var(--dim); font-style: italic; }

.line {
  display: flex;
  align-items: baseline;
  margin: 0;
}

.line__prompt {
  white-space: pre-wrap;
  text-shadow: var(--glow);
  flex: 0 0 auto;
}

.line__input {
  flex: 1 1 auto;
  min-width: 2ch;
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  outline: none;
  caret-color: var(--fg);
  text-shadow: var(--glow);
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

/* echo OFF — the original prints nothing at all for a password, not dots.
   The caret stays visible so the field is still usable. */
.line__input.is-noecho { color: transparent; text-shadow: none; }

.line.is-idle { visibility: hidden; }

/* block cursor parked at the prompt while the BBS is talking */
.line__prompt::after {
  content: "";
  display: none;
}
.line.is-idle .line__prompt::after { display: none; }

/* ---- quick keys --------------------------------------------------------- */

.keys {
  flex: 0 0 auto;
  display: flex;
  gap: 0.25rem;
  padding: 0.3rem var(--gutter) 0.4rem;
  border-top: 1px solid rgba(255, 176, 0, 0.22);
  width: var(--col);
  margin-inline: auto;
  overflow-x: auto;
}

.keys__k {
  flex: 1 1 0;
  min-width: 44px;
  min-height: 44px;
  font: inherit;
  color: var(--fg);
  background: rgba(255, 176, 0, 0.06);
  border: 1px solid rgba(255, 176, 0, 0.28);
  border-radius: 3px;
  cursor: pointer;
}

.keys__k:active { background: rgba(255, 176, 0, 0.2); }

/* ---- modal -------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: var(--gutter);
}

.modal[hidden] { display: none; }

.modal__scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
}

.modal__panel {
  position: relative;
  width: min(100%, 560px);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--bg-lift);
  border: 1px solid rgba(255, 176, 0, 0.35);
  border-radius: 4px;
  padding: 1rem;
  color: var(--fg);
}

.modal__panel[hidden] { display: none; }

.modal__title {
  margin: 0 0 0.5rem;
  font-size: 1.15em;
  letter-spacing: 0.1em;
  text-shadow: var(--glow);
}

.modal__panel h2 {
  margin: 1.1rem 0 0.3rem;
  font-size: 0.95em;
  color: var(--hi);
}

.modal__panel p, .modal__panel li { margin: 0.4rem 0; }
.modal__panel ul { margin: 0.4rem 0; padding-left: 1.1rem; }
.modal__panel code {
  color: var(--hi);
  background: rgba(255, 176, 0, 0.1);
  padding: 0 0.25em;
  border-radius: 2px;
}
.modal__note { color: var(--dim); margin-top: 1rem; }

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.2rem;
}

.btn {
  flex: 1 1 auto;
  min-height: 44px;
  font: inherit;
  color: var(--bg);
  background: var(--fg);
  border: 1px solid var(--fg);
  border-radius: 3px;
  cursor: pointer;
  padding: 0 0.8rem;
}

.btn--ghost { color: var(--fg); background: transparent; }
.btn--danger { color: var(--bg); background: var(--danger); border-color: var(--danger); }

/* ---- storage-failure banner --------------------------------------------- */

.banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 0.6rem var(--gutter);
  padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
  background: var(--danger);
  color: #1a0900;
  text-align: center;
}

.banner[hidden] { display: none; }

/* ---- desktop: an 800x600 telnet window ----------------------------------
   The one place this app departs from "desktop is the mobile layout centred":
   at 800x600 the terminal becomes a windowed telnet client, 80 columns wide,
   sitting on a desktop backdrop. app.js measures the character advance and
   scales the font so exactly 80 columns fit — never hardcode font metrics. */

@media (min-width: 900px) and (min-height: 680px) {
  body {
    display: grid;
    place-items: center;
    /* Still honour the insets: a landscape iPad lands in this branch and has a
       home indicator. */
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
      env(safe-area-inset-bottom) env(safe-area-inset-left);
    background:
      radial-gradient(90% 70% at 50% 0%, #10161f 0%, #070a0e 70%),
      #070a0e;
  }

  .win {
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    width: 800px;
    height: 600px;
    background: var(--bg);
    border: 1px solid #3a2a08;
    border-radius: 5px;
    box-shadow:
      0 0 0 1px rgba(255, 176, 0, 0.12),
      0 24px 60px rgba(0, 0, 0, 0.75);
  }

  .crt {
    position: absolute;
    z-index: 0;
  }

  .bar,
  .screen,
  .status {
    position: relative;
    z-index: 1;
    width: 100%;
    margin-inline: 0;
  }

  .bar {
    background: linear-gradient(#241a06, #1a1204);
    border-bottom: 1px solid #3a2a08;
    padding: 0.2rem 0.45rem;
    flex: 0 0 auto;
  }

  .bar__brand { display: none; }
  .bar__meta { display: none; }

  .bar__title {
    display: block;
    flex: 1 1 auto;
    text-align: center;
    color: var(--hi);
    font-size: 0.82rem;
    letter-spacing: 0.04em;
  }

  .bar__tools { order: 3; }

  .bar__btn {
    min-width: 30px;
    min-height: 24px;
    font-size: 0.72rem;
    border-color: #4a3608;
  }

  .bar__btn--close:hover,
  .bar__btn--close:active {
    background: var(--danger);
    color: #1a0900;
    border-color: var(--danger);
  }

  /* Spacer so the centred title is not pushed off-centre by the buttons. */
  .bar::before {
    content: "";
    flex: 0 0 auto;
    width: 134px;
  }

  .screen {
    flex: 1 1 auto;
    padding: 0.35rem 0.6rem 0.4rem;
  }

  /* Physical keyboard present: the thumb bar is noise here. */
  .keys { display: none; }

  .status {
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    flex: 0 0 auto;
    padding: 0.15rem 0.6rem 0.2rem;
    border-top: 1px solid #3a2a08;
    background: linear-gradient(#1a1204, #241a06);
    color: var(--dim);
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
  }

  .status span:nth-child(2) { flex: 1 1 auto; text-align: center; }
  .status span:last-child { text-align: right; }
}

/* ---- boot animation ----------------------------------------------------- */
/* Gated on .is-animate so it runs once per boot and never replays on a
   keystroke or a button press. */

@keyframes warmup {
  from { opacity: 0; transform: scaleY(0.4); }
  to { opacity: 1; transform: scaleY(1); }
}

.screen.is-animate { animation: warmup 420ms ease-out both; transform-origin: center; }

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