/* =============================================================================
 * GUNR.DEV — terminal.css
 * GUNR//OS terminal overlay (markup is built by js/terminal.js).
 * Mobile-first: full-screen sheet; >= 768px: a quiet centered window.
 * Reads the site tokens (--ink, --paper, --signal …) from style.css, with
 * fallbacks so it still looks right on a page that does not load style.css.
 * The accent follows html[data-theme] (signal | lime | cyan) via --signal.
 * ========================================================================== */

.term {
  --term-accent: var(--signal, #FF5A1F);
  --term-bg: var(--ink-2, #111113);
  --term-bg-2: var(--ink, #0B0B0C);
  --term-raise: var(--ink-3, #18181B);
  --term-fg: var(--paper, #EDEAE4);
  --term-dim: var(--paper-dim, #9A968F);
  --term-line: var(--line, rgba(237, 234, 228, 0.10));
  --term-line-2: rgba(237, 234, 228, 0.18);
  --term-link: var(--paper, #EDEAE4);
  --term-warm: #D9B98C;           /* secondary highlight (old "amber" lines) */
  --term-danger: #FF6B6B;
  --term-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --term-ease: cubic-bezier(0.16, 1, 0.3, 1); /* expo.out */
  --term-vvh: 100vh;
  --term-vvtop: 0px;

  position: fixed;
  z-index: 1000;
  left: 0;
  right: 0;
  top: var(--term-vvtop);
  height: var(--term-vvh);
  display: flex;
  align-items: stretch;
  justify-content: center;
  font-family: var(--term-mono);
  font-feature-settings: "ss01", "zero";
  color: var(--term-fg);
  -webkit-font-smoothing: antialiased;
}

@supports (height: 100dvh) {
  .term { --term-vvh: 100dvh; }
}

/* Accent themes from the `theme` command. style.css redefines --signal per
   html[data-theme]; the hex values are only fallbacks for pages without it. */
html[data-theme="lime"] .term { --term-accent: var(--signal, #C8F04A); }
html[data-theme="cyan"] .term { --term-accent: var(--signal, #5CE1E6); }

.term[hidden] { display: none !important; }

/* Lock page scroll while open. */
html.term-open,
html.term-open body { overflow: hidden; }

.term__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 11, 12, 0.72);
  -webkit-backdrop-filter: blur(10px) saturate(0.9);
  backdrop-filter: blur(10px) saturate(0.9);
}

/* ---------------------------------------------------------------- window */

.term__window {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--term-bg);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (min-width: 768px) {
  .term { align-items: center; padding: 32px; }
  .term__window {
    width: min(920px, 100%);
    height: min(640px, 100%);
    border: 1px solid var(--term-line);
    border-radius: 14px;
    box-shadow:
      0 1px 0 rgba(237, 234, 228, 0.05) inset,
      0 40px 120px -20px rgba(0, 0, 0, 0.7),
      0 12px 32px -12px rgba(0, 0, 0, 0.5);
    padding-bottom: 0;
  }
}

/* --------------------------------------------------------------- title bar */

.term__bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 52px;
  padding: 0 6px 0 18px;
  padding-top: env(safe-area-inset-top, 0px);
  border-bottom: 1px solid var(--term-line);
  background: var(--term-bg-2);
  flex: none;
}

/* Three hairline markers; the first carries the accent ("live"). */
.term__dots { display: inline-flex; gap: 6px; }
.term__dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--term-line-2);
}
.term__dots i:first-child { background: var(--term-accent); box-shadow: none; }

.term__title {
  flex: 1;
  margin: 0;
  font: 500 11px/1 var(--term-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--term-dim);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.term__close {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--term-dim);
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s;
}
.term__close:hover { color: var(--term-fg); background: rgba(237, 234, 228, 0.06); }

/* ------------------------------------------------------------------ screen */

.term__screen {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px 12px;
  font-size: 13.5px;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: var(--term-line-2) transparent;
}

@media (min-width: 768px) {
  .term__screen { padding: 22px 28px 16px; font-size: 14px; }
}

.term__out { min-width: 0; }

.term-l {
  min-height: 1.6em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.term-echo { color: var(--term-fg); margin-top: 8px; }
.term-p,
.term__prompt { color: var(--term-accent); }

.term-hl { color: var(--term-fg); font-weight: 500; }
.term-acc { color: var(--term-accent); }
.term-amber { color: var(--term-warm); }
.term-dim { color: var(--term-dim); }
.term-err { color: var(--term-danger); }
.term-k { color: var(--term-dim); }

/* Unfilled [[placeholder]] from content.js: visible but clearly unfinished. */
.term-ph {
  color: var(--term-dim);
  font-style: italic;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.term-a {
  color: var(--term-link);
  text-decoration: underline;
  text-decoration-color: var(--term-line-2);
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 0.2s, color 0.2s;
}
.term-a:hover { color: var(--term-accent); text-decoration-color: currentColor; }

/* Inline runnable command (help list, hints). */
.term-cmd {
  display: inline;
  margin: 0;
  padding: 2px 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--term-accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  white-space: pre;
  cursor: pointer;
}
.term-cmd:hover { text-decoration-color: currentColor; }
.term-cmd--dir { color: var(--term-fg); }

/* Touch: ~44px tall targets for inline commands and links. */
@media (pointer: coarse) {
  .term-cmd,
  .term-a { display: inline-block; padding: 11px 0; }
}

/* Wide fixed-width blocks scroll inside themselves, never the page. */
.term-pre {
  margin: 4px 0;
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
  font: inherit;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--term-fg);
}
.term-pre--wide { color: var(--term-accent); }
@media (min-width: 768px) {
  .term-pre { font-size: 12.5px; }
}

/* QR stays dark-on-light with its own quiet zone. */
.term-qr {
  display: inline-block;
  width: min(220px, 62vw);
  margin: 10px 0 4px;
  padding: 10px;
  background: #fff;
  border-radius: 10px;
}
.term-qr svg { display: block; width: 100%; height: auto; }

/* ---------------------------------------------------------------- prompt */

.term__line {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  margin: 10px 0 0;
  font-size: 16px; /* >= 16px keeps iOS from zooming on focus */
  line-height: 1.5;
}

.term__prompt { flex: none; white-space: nowrap; }

.term__field {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

/* The visible text + block cursor; the real input sits on top, invisible. */
.term__mirror {
  min-height: 1.5em;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--term-fg);
}

.term__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 16px;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: transparent;
  -webkit-appearance: none;
  appearance: none;
}
.term__input::selection { background: color-mix(in srgb, var(--term-accent) 30%, transparent); }

.term__cursor {
  display: inline-block;
  min-width: 1ch;
  background: var(--term-accent);
  color: var(--term-bg);
  animation: term-blink 1.1s steps(1, end) infinite;
}

/* Unfocused: hollow, steady block. */
.term__field:not(:focus-within) .term__cursor {
  background: transparent;
  color: inherit;
  box-shadow: inset 0 0 0 1px var(--term-accent);
  animation: none;
}

/* Keyboard focus ring on the prompt row. The plain :focus-within rule is the
   fallback; where :has() works, the ring is limited to keyboard focus. */
.term__field:focus-within {
  outline: 1px solid var(--term-accent);
  outline-offset: 6px;
  border-radius: 2px;
}
@supports selector(:has(*)) {
  .term__field:focus-within:not(:has(.term__input:focus-visible)) { outline: none; }
}

@keyframes term-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ------------------------------------------------------------ quick chips */

.term__chips {
  position: relative;
  z-index: 1;
  display: flex;
  flex: none;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--term-line);
  background: var(--term-bg-2);
  scrollbar-width: none;
  /* Soft fade on the scroll edges so the row reads as swipeable. */
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
}
.term__chips::-webkit-scrollbar { display: none; }

.term-chip {
  flex: none;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--term-line);
  border-radius: 999px;
  background: transparent;
  color: var(--term-dim);
  font: 500 12px/1 var(--term-mono);
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background-color 0.2s;
}
.term-chip:hover {
  border-color: var(--term-line-2);
  color: var(--term-fg);
  background: var(--term-raise);
}
.term-chip:active { transform: translateY(1px); }

@media (min-width: 768px) {
  .term__chips { padding: 12px 18px; }
  .term-chip { min-height: 34px; font-size: 11.5px; }
}
@media (min-width: 768px) and (pointer: coarse) {
  .term-chip { min-height: 44px; }
}

/* ------------------------------------------------------------------ focus */
/* terminal.js traps Tab inside the dialog; every stop gets a visible ring. */

.term__close:focus-visible,
.term-chip:focus-visible,
.term-cmd:focus-visible,
.term-a:focus-visible {
  outline: 2px solid var(--term-accent);
  outline-offset: 2px;
}
.term-chip:focus-visible { color: var(--term-fg); border-color: transparent; }

/* --------------------------------------------------------------- effects */

/* Matrix rain canvas, positioned over .term__screen by terminal.js. */
.term__rain {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.4s ease;
}
.term__rain.is-fading { opacity: 0; }

/* Enter: backdrop fades, window rises and sharpens (terminal.js only adds
   .is-entering when motion is allowed). */
.term.is-entering .term__backdrop { animation: term-fade 0.4s ease-out both; }
.term.is-entering .term__window { animation: term-rise 0.6s var(--term-ease) both; }

@keyframes term-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes term-rise {
  from { opacity: 0; transform: translateY(18px) scale(0.985); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

/* rm -rf / : brief shake with a faint accent split. */
.term__window.is-glitching { animation: term-glitch 0.42s steps(2, end) 1; }

@keyframes term-glitch {
  0% { transform: translate(0, 0); filter: none; }
  20% { transform: translate(-3px, 1px); filter: drop-shadow(2px 0 0 color-mix(in srgb, var(--term-accent) 60%, transparent)); }
  40% { transform: translate(3px, -1px); filter: drop-shadow(-2px 0 0 color-mix(in srgb, var(--term-accent) 60%, transparent)); }
  60% { transform: translate(-2px, 0); filter: none; }
  80% { transform: translate(1px, 1px); filter: none; }
  100% { transform: translate(0, 0); filter: none; }
}

/* ------------------------------------------------------------- utilities */

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

/* Reduced motion. terminal.js sets .term--still on open from window.GUNR_MOTION
   (?motion=full|reduced) or, without it, prefers-reduced-motion. */
.term--still .term__cursor,
.term--still .term__window.is-glitching { animation: none !important; }
.term--still .term-chip,
.term--still .term__close,
.term--still .term-a,
.term--still .term__rain { transition: none; }
