/* The terminal page (/terminal). The box is the site's `.terminal` from
   site.css, made tall enough to fill the window under the nav; this adds the
   prompt, the full-screen programs (top, matrix, the train) and the games. */

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

.term-top {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline;
  gap: 8px 24px; padding: 0 0 16px;
}
.term-heading { margin: 0; font-family: var(--mono); font-size: 14px; font-weight: 400; line-height: 1.5; letter-spacing: 0; color: var(--dim); }
.term-heading kbd { font-family: var(--mono); color: var(--lime); }

/* The box: the window's height less the nav, so the page doesn't scroll */
.term {
  --term-font: 14px;
  position: relative; display: flex; flex-direction: column; gap: 0; padding: 0;
  height: clamp(380px, calc(100svh - 190px), 900px); margin-bottom: 48px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.term .terminal-bar { flex: none; align-items: center; }
.term-title {
  flex: 1; margin-right: 52px; text-align: center; font-family: var(--mono); font-size: 13px;
  color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* The output scrolls; full-screen programs cover it */
.term-body { position: relative; flex: 1; min-height: 0; }
.term-screen {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; font-variant-ligatures: none;
  padding: 16px 20px 20px; font-family: var(--mono); font-size: var(--term-font); line-height: 1.6;
  color: var(--muted); cursor: text; scrollbar-color: var(--line) transparent;
}
.term-output, .term-line { white-space: pre-wrap; overflow-wrap: anywhere; }
.term-line { min-height: 1.6em; }
.term-noscript { margin: 0; color: var(--pink); }

/* Output colors. site.css has lime, cyan and pink. */
.t-yellow { color: var(--yellow); }
.t-dim { color: var(--dim); }
.t-text { color: var(--text); }
.t-bold { font-weight: 600; }
.term-screen a { color: var(--cyan); }
.term-screen a:hover { color: var(--lime); }
/* Commands in `help` can be tapped to run them */
.term-cmd {
  padding: 0; border: 0; background: none; font: inherit; color: var(--lime); cursor: pointer;
  text-decoration: underline dotted color-mix(in srgb, var(--lime) 40%, transparent); text-underline-offset: 3px;
}
.term-cmd:hover, .term-cmd:focus-visible { color: var(--lime-light); text-decoration-style: solid; outline: none; }

/* The prompt. The real input is invisible on top of the line, so taps on it
   bring up the phone keyboard; what's typed shows in `.term-typed`, with a
   block cursor. */
/* Only the prompt and what's typed keep their spaces, not the markup's */
.term-input-line { position: relative; overflow-wrap: anywhere; min-height: 1.6em; }
.term-prompt, .term-typed { white-space: pre-wrap; }
.term-input-line[hidden] { display: none; }
.term-input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0;
  /* 16px stops iPhones zooming in when it's focused */
  font-size: 16px; color: transparent; background: transparent; caret-color: transparent;
  opacity: 0; outline: none;
}
.term-typed { color: var(--text); }
.term-cursor { background: var(--lime); color: var(--bg-deep); }
.term:not(.focused) .term-cursor { background: none; color: inherit; outline: 1px solid var(--lime); outline-offset: -1px; }
.term.focused .term-cursor { animation: term-blink 1.1s steps(1) infinite; }
@keyframes term-blink { 50% { background: none; color: var(--text); } }
.term.focused { border-color: #443b8a; }

/* On-screen keys for phones, which have no Tab, arrows or Ctrl */
.term-keys { flex: none; display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--card); overflow-x: auto; }
.term-keys[hidden] { display: none; }
/* Full-screen programs have their own buttons */
.term.app-running .term-keys { display: none; }
.term-keys button {
  flex: 1 0 auto; min-width: 44px; min-height: 36px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg-deep); color: var(--text); font: 13px var(--mono); cursor: pointer;
}
.term-keys button:active { border-color: var(--lime); color: var(--lime); }

/* Full-screen programs (top, matrix, sl and the games) cover the output */
.term-app {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  font-family: var(--mono); font-size: var(--term-font); font-variant-ligatures: none; color: var(--muted);
  background: var(--bg-deep); overflow: hidden; cursor: default; outline: none;
}
.term-app[hidden] { display: none; }
/* Measures a character cell (util.js charCell) without being seen */
.char-probe { position: absolute; visibility: hidden; white-space: pre; }
.term-app pre { margin: 0; padding: 16px 20px; font: inherit; line-height: 1.35; white-space: pre; overflow: hidden; }
.term-app canvas { display: block; flex: 1; min-height: 0; width: 100%; touch-action: none; }
.term-app .app-hint { position: absolute; right: 12px; bottom: 8px; font-size: 12px; color: var(--dim); }

.top-head { display: inline-block; min-width: 100%; background: var(--lime); color: var(--bg-deep); font-weight: 600; }

/* The train runs along one line, so it is drawn a little tighter */
.sl-track { flex: 1; display: flex; align-items: center; }
.sl-track pre { line-height: 1.15; color: var(--text); padding: 0; }

/* Games: a score bar over the canvas */
.arcade-hud {
  flex: none; display: flex; align-items: center; gap: 8px 18px; flex-wrap: wrap;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--card); font-size: 13px;
}
.arcade-hud .arcade-name { color: var(--lime); font-weight: 600; }
.arcade-hud .arcade-score { color: var(--text); }
.arcade-hud .arcade-best { color: var(--dim); }
.arcade-hud .arcade-buttons { margin-left: auto; display: flex; gap: 6px; }
.arcade-hud button {
  min-height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-deep); color: var(--text); font: 13px var(--mono); cursor: pointer;
}
.arcade-hud button:hover, .arcade-hud button:focus-visible { border-color: var(--lime); color: var(--lime); outline: none; }

/* crawl: the map, the System's narration, pop-ups and phone buttons */
/* touch-action: swipes on the map move, so the phone mustn't scroll instead */
.crawl-stage {
  position: relative; flex: 1; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.term-app pre.crawl-map { padding: 8px; line-height: 1.2; color: var(--muted); }
.crawl-floor { color: var(--dim); opacity: 0.5; }
.crawl-remembered { color: var(--line); }
/* Princess Pastry stands out from the monsters */
.crawl-pet { color: var(--bg-deep); background: var(--yellow); font-weight: 600; border-radius: 3px; }
.crawl-log {
  flex: none; max-height: 36%; overflow-y: auto; padding: 8px 14px; border-top: 1px solid var(--line);
  background: var(--bg); font-size: 12.5px; line-height: 1.35;
}
.crawl-line { white-space: pre-wrap; }
.crawl-toast {
  position: absolute; top: 10px; right: 10px; max-width: min(320px, calc(100% - 20px)); padding: 10px 14px;
  border: 1px solid var(--yellow); border-radius: 10px; background: var(--card); color: var(--muted);
  font-size: 12.5px; line-height: 1.45; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); animation: crawl-pop 0.35s ease both;
}
.crawl-toast-head { color: var(--yellow); font-weight: 600; letter-spacing: 0.04em; }
.crawl-toast-title { color: var(--text); font-weight: 600; font-size: 15px; }
@keyframes crawl-pop { from { opacity: 0; transform: translateY(-8px) scale(0.96); } to { opacity: 1; transform: none; } }
.crawl-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 16px; text-align: center; white-space: pre-wrap; background: color-mix(in srgb, var(--bg-deep) 88%, transparent);
}
.crawl-overlay > div { max-width: 62ch; min-height: 1.3em; }
.crawl-overlay .t-bold { font-size: 20px; letter-spacing: 0.06em; }
.crawl-box { border: 0; }
.crawl-toast[hidden], .crawl-overlay[hidden], .crawl-pad[hidden] { display: none; }
.crawl-pad { flex: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); background: var(--card); }
.crawl-pad button {
  flex: 1 0 auto; min-width: 44px; min-height: 40px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-deep); color: var(--text); font: 13px var(--mono); cursor: pointer;
}
.crawl-pad button:active { border-color: var(--lime); color: var(--lime); }

/* rm -rf /: parts of the page "deleted" for a moment, then put back */
.rm-gone { visibility: hidden; opacity: 0; transform: translateY(16px) rotate(-1.5deg); filter: blur(3px); }
.rm-fading { transition: opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease, visibility 0s linear 0.35s; }
.rm-back { animation: rm-back 0.5s ease both; }
@keyframes rm-back { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
.term.rm-shake { animation: rm-shake 0.4s linear 2; }
@keyframes rm-shake {
  0%, 100% { transform: none; }
  25% { transform: translate(-3px, 1px); }
  50% { transform: translate(2px, -2px); }
  75% { transform: translate(-1px, 2px); }
}

@media (max-width: 640px) {
  .term { --term-font: 12.5px; height: clamp(360px, calc(100svh - 220px), 900px); margin-bottom: 32px; }
  .term-screen { padding: 12px 14px 16px; }
  .term-title { margin-right: 0; text-align: right; }
  .term-app pre { padding: 12px 14px; }
  .arcade-hud { gap: 4px 12px; padding: 6px 10px; font-size: 12px; }
  .crawl-log { max-height: 30%; padding: 6px 10px; font-size: 11.5px; }
  .arcade-hud button { min-height: 30px; padding: 0 10px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .term.focused .term-cursor { animation: none; }
  .rm-fading { transition: none; }
  .rm-back, .term.rm-shake, .crawl-toast { animation: none; }
  .rm-gone { transform: none; filter: none; }
}
