/* ─── keytap — the site is a terminal ───
   Two regions: a hairline title strip and the screen. Hard rules, flat
   color, no ornament. Palette and fonts come from theme.css, shared with
   the nearby page. */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  height: var(--vvh, 100dvh); /* JS syncs --vvh to the visual viewport */
  display: flex;
  flex-direction: column;
  font: 16px/1.6 var(--body);
  color: var(--fg);
  background: var(--bg);
}

::selection {
  background: var(--accent);
  color: var(--accent-fg);
}

/* ─── title strip ─── */

.term-chrome {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px max(var(--pad), calc((100vw - var(--measure)) / 2 + var(--pad)));
  border-bottom: 1px solid var(--line);
}

.term-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font: 700 1rem var(--display);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg);
}

.term-title img {
  display: block;
  image-rendering: pixelated;
}

.term-tagline {
  color: var(--muted);
  font-size: 0.78rem;
}

.term-link {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.term-link:hover {
  color: var(--fg);
}

/* ─── screen ─── */

:root {
  --pad: clamp(16px, 2.5vw, 28px);
  --measure: 1120px;
}

.term-shell {
  position: relative;
  flex: 1;
  min-height: 0;
}

.term-screen {
  width: min(100%, var(--measure));
  margin-inline: auto;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px var(--pad) 28px;
  font-size: 1rem;
  line-height: 1.6;
}

.term-screen .ln {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-height: 1.6em;
  color: var(--fg);
}

.term-screen .ln.err {
  color: var(--error);
}

.term-screen .ln.echo .p {
  color: var(--accent);
}

.term-screen .ln.hint {
  color: var(--muted);
}

/* Tap-to-run command strings: dotted underline says "pressable" without
   adding chrome. The label IS the command. */
button.cmd {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline dotted var(--accent);
  text-underline-offset: 3px;
  cursor: pointer;
}

button.cmd {
  position: relative;
}

button.cmd:hover,
button.cmd:focus-visible {
  color: var(--accent);
  text-decoration-style: solid;
}

/* Previews "this echoes into the prompt", not "this navigates away". */
button.cmd:hover::before,
button.cmd:focus-visible::before {
  content: "$ ";
  position: absolute;
  right: 100%;
  color: var(--muted);
  text-decoration: none;
}

.suggestion {
  display: grid;
  grid-template-columns: minmax(18rem, max-content) 1fr;
  gap: 0 2rem;
  padding-left: 1.5rem;
}

.suggestion span {
  color: var(--muted);
}

/* The ceremony line: state, reassurance, and cancel in one button. */
button.ln.busy {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: none;
  border: 0;
  color: var(--busy);
  cursor: pointer;
}

button.ln.busy:focus-visible {
  outline: 1px solid var(--busy);
  outline-offset: 2px;
}

/* Screen-reader-only text (ceremony alerts, key-block summaries). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Copy chip on pipeline output. */
.term-screen .ln.res {
  position: relative;
  padding-right: 4.5em;
}

.copy {
  position: absolute;
  top: 0;
  right: 0;
  font: 700 0.65rem var(--body);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  background: none;
  border: 1px solid currentColor;
  padding: 1px 8px;
  cursor: pointer;
}

.copy[data-state="copied"] {
  color: var(--accent);
}

.copy[data-state="failed"] {
  color: var(--error);
}

@media (hover: hover) {
  .ln.res .copy {
    opacity: 0;
  }

  .ln.res:hover .copy,
  .copy:focus-visible {
    opacity: 1;
  }
}

@media (hover: none) {
  .copy {
    opacity: 0.55;
    top: auto;
    bottom: 0;
  }
}

@media (pointer: coarse) {
  /* 44px-ish hit areas without layout shift. */
  button.cmd,
  .copy {
    padding: 10px 8px;
    margin: -10px -8px;
  }
}

.term-line {
  position: relative;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--fg);
}

/* While a command runs, the prompt keeps its place (and the keyboard its
   focus) but shows nothing. */
.term-line.running #term-mirror {
  visibility: hidden;
}

.term-prompt {
  color: var(--accent);
}

.term-cursor {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--accent);
  color: var(--fg);
}

.focused .term-cursor {
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: none;
  animation: blink 1.1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    background: transparent;
    color: var(--fg);
    box-shadow: inset 0 0 0 1px var(--accent);
  }
}

/* The real keyboard target, laid invisibly over the prompt line it mirrors.
   Because the focused element IS the line — in flow, inside the scroller —
   the browser's own focus handling reveals it when the software keyboard
   appears; no scripted scrolling. Inherits the line's 16px font so iOS
   doesn't zoom on focus. */
#term-kbd {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  font: inherit;
  opacity: 0;
  border: none;
  background: transparent;
  color: transparent;
  caret-color: transparent;
}

/* ─── focus visibility ─── */

.term-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#term-kbd:focus-visible {
  outline: none; /* the block cursor is the focus indicator */
}

@media (forced-colors: active) {
  .term-cursor {
    outline: 1px solid CanvasText;
  }
}

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

@media (max-width: 620px) {
  .term-tagline {
    display: none;
  }

  .suggestion {
    grid-template-columns: 1fr;
    padding: 0.35rem 0 0.55rem 1rem;
    line-height: 1.35;
  }

  .suggestion span {
    font-size: 0.85rem;
  }
}
