/* zdezk CLI — see docs/cli-spec.md */

:root {
  --bg: #0b0d10;
  --bg-window: #101318;
  --fg: #c8d0d8;
  --fg-dim: #6d7a88;
  --accent: #7fd6a2;
  --accent-rgb: 127, 214, 162;   /* same colour, for rgba() — see .codec */
  --accent-2: #e0b978;
  --rule: #1e242c;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
  --prose: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --pixel: "Tiny5", var(--mono);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.55;
}

/* ---- no-JS fallback ------------------------------------------------ */
/* #screen is hidden until the inline head script proves JS is running, so a
   crawler or a JS-off visitor gets the plain index instead of a dead shell. */
#screen { display: none; }
.js #screen { display: grid; }
.js #fallback { display: none; }

#fallback { max-width: 44rem; margin: 0 auto; padding: 2rem 1.25rem 6rem; }
#fallback a { color: var(--accent); }
.fb-nav, .fb-meta, .fb-note { color: var(--fg-dim); font-size: 0.85rem; }
.fb-post, .fb-list { font-family: var(--prose); }
.fb-list ul { list-style: none; padding: 0; }
.fb-list li { border-top: 1px solid var(--rule); padding: 1rem 0; }

/* ---- screen layout ------------------------------------------------- */
#screen {
  height: 100%;
  grid-template-columns: 1fr;
  transition: grid-template-columns 320ms cubic-bezier(.4, 0, .2, 1);
}
/* The terminal column must not be narrower than the welcome text, or the
   help rows wrap mid-sentence. */
/* 58ch of content + the column's own horizontal padding. Without the padding
   term the welcome text wraps mid-sentence. */
#screen.state-split { grid-template-columns: minmax(calc(58ch + 5rem), 0.8fr) 1.2fr; }

/* Narrow desktops: shrink the terminal rather than let the window get squeezed. */
@media (max-width: 1180px) {
  #screen.state-split { grid-template-columns: minmax(calc(56ch + 2.5rem), 0.7fr) 1.3fr; }
  .state-split #terminal { padding-left: 1.25rem; padding-right: 1.25rem; font-size: 13.5px; }
}

/* ---- terminal ------------------------------------------------------ */
/* The whole column scrolls, so the prompt sits directly under the last line of
   output the way a real terminal does — not pinned to the viewport floor. */
#terminal {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 1.5rem;
  overflow-y: auto;
  cursor: text;
}
#terminal::-webkit-scrollbar { width: 8px; }
#terminal::-webkit-scrollbar-thumb { background: var(--rule); }
/* Solo state centres the terminal; split state pins it left. */
/* Wide enough for the portrait plus the full command column beside it. */
.state-solo #terminal { max-width: 106ch; margin: 0 auto; width: 100%; }
.state-split #terminal { border-right: 1px solid var(--rule); }

#scrollback {
  flex: 0 0 auto;
  overflow-wrap: anywhere;
}

.line { white-space: pre-wrap; margin: 0; }
/* Blank lines are spacing, not nothing — keep their height. */
.line:empty::before { content: '\00a0'; }
.line.dim { color: var(--fg-dim); }
.line.accent { color: var(--accent); }
.line.warn { color: var(--accent-2); }
.line.echo { color: var(--fg-dim); margin-top: 0.9rem; }
.line.echo b { color: var(--fg); font-weight: normal; }
.rule { color: var(--rule); }
.banner { color: var(--accent); }
/* Figlet art needs tighter leading than body text to read as letterforms —
   but not 1.0, or the strokes collide. */
.banner-line { line-height: 1.25; }

/* ---- welcome: photo beside the greeting ---------------------------- */
.welcome-row { display: flex; gap: 1.25rem; align-items: flex-start; }
.welcome-row.stacked { flex-direction: column; gap: 0.9rem; }
.welcome-text { min-width: 0; }

/* Codec screen: the duotone grade is baked into the JPEG by
   tools/portrait.py; the scanlines, glow and flicker are here so they stay one
   screen pixel wide at any size. */
.codec {
  position: relative;
  flex: 0 0 auto;
  display: block;
  width: 168px;
  height: 168px;
  border: 1px solid rgba(var(--accent-rgb), 0.26);
  border-radius: 2px;
  overflow: hidden;
  background: #071310;
  box-shadow: 0 0 18px rgba(var(--accent-rgb), 0.12),
              inset 0 0 22px rgba(0, 0, 0, 0.55);
}
.welcome-photo { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Scanlines. */
.codec::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.38) 0 1px,
    rgba(0, 0, 0, 0) 1px 3px);
  pointer-events: none;
}

/* Vignette plus a slow horizontal sweep, like a CRT refresh. */
.codec::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom,
      rgba(var(--accent-rgb), 0.12) 0%,
      rgba(var(--accent-rgb), 0) 14%,
      rgba(var(--accent-rgb), 0) 86%,
      rgba(var(--accent-rgb), 0.08) 100%),
    radial-gradient(120% 100% at 50% 45%,
      rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.55) 100%);
  animation: codec-sweep 7s linear infinite;
}

@keyframes codec-sweep {
  0%   { background-position: 0 -100%, 0 0; opacity: 0.9; }
  50%  { opacity: 1; }
  100% { background-position: 0 200%, 0 0; opacity: 0.9; }
}

.welcome-row.stacked .codec { width: 132px; height: 132px; }
.spacer { height: 0.75rem; }

/* Anything printed that is also a command: click to run it. */
.run {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px dotted transparent;
}
.run:hover, .run:focus-visible { border-bottom-color: var(--accent); outline: none; }
.idx { color: var(--fg-dim); }
.dir { color: var(--accent-2); }

#prompt-form { display: flex; align-items: baseline; gap: 0.6ch; flex: 0 0 auto; padding-top: 0.9rem; }
#prompt-label { color: var(--accent); white-space: pre; }
#cmd {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--fg);
  font: inherit;
  padding: 0;
  caret-color: var(--accent);
}
#cmd:focus { outline: none; }

#touchbar { display: none; gap: 0.5rem; flex-wrap: wrap; padding-top: 0.75rem;
  position: sticky; bottom: 0; background: var(--bg); }
#touchbar button {
  background: transparent; border: 1px solid var(--rule); color: var(--fg-dim);
  font: inherit; font-size: 0.8rem; padding: 0.3rem 0.6rem; border-radius: 3px;
}

/* ---- window -------------------------------------------------------- */
#window {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-window);
}
#window[hidden] { display: none; }

#window-chrome {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--rule);
  flex: 0 0 auto;
}
#window-chrome button {
  background: transparent; border: 0; color: var(--fg-dim);
  font: inherit; cursor: pointer; padding: 0.1rem 0.45rem; border-radius: 3px;
}
#window-chrome button:hover:not(:disabled) { color: var(--fg); background: var(--rule); }
#window-chrome button:disabled { opacity: 0.3; cursor: default; }
#window-path {
  flex: 1; color: var(--fg-dim); font-size: 0.8rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 0 0.5rem;
}
[data-win="close"] { margin-left: auto; }

#window-body { flex: 1 1 auto; overflow-y: auto; padding: clamp(1.25rem, 3vw, 2.5rem); }
#window-body:focus { outline: none; }

/* ---- window content ------------------------------------------------ */
.doc { max-width: 68ch; margin: 0 auto; font-family: var(--prose); font-size: 1.05rem; line-height: 1.7; }
.doc h1 { font-size: 1.8rem; line-height: 1.25; margin: 0 0 0.4rem; }
.doc h2 { font-size: 1.25rem; margin: 2rem 0 0.5rem; }
.doc h3 { font-size: 1.05rem; margin: 1.5rem 0 0.4rem; }
.doc p { margin: 0 0 1.1rem; }
.doc a { color: var(--accent); }
.doc img { max-width: 100%; height: auto; display: block; margin: 1.5rem auto; }
.doc code { font-family: var(--mono); font-size: 0.85em; background: #171c22; padding: 0.1em 0.35em; border-radius: 3px; }
.doc pre { background: #171c22; padding: 1rem; overflow-x: auto; border-radius: 4px; }
.doc pre code { background: none; padding: 0; }
.doc blockquote { border-left: 2px solid var(--rule); margin: 1.2rem 0; padding-left: 1rem; color: var(--fg-dim); }
.doc table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }

.doc-meta { font-family: var(--mono); font-size: 0.8rem; color: var(--fg-dim); margin: 0 0 2rem; }
.doc-meta .tag { color: var(--accent-2); }

.doc-index { list-style: none; padding: 0; margin: 0; }
.doc-index li { border-top: 1px solid var(--rule); padding: 1.1rem 0; }
.doc-index li:last-child { border-bottom: 1px solid var(--rule); }
.doc-index h2 { margin: 0 0 0.2rem; font-size: 1.15rem; }
.doc-index a { text-decoration: none; }
.doc-index p { margin: 0.3rem 0 0; color: var(--fg-dim); font-size: 0.95rem; }

/* ---- mobile: window becomes a full-screen overlay ------------------ */
@media (max-width: 768px) {
  #screen, #screen.state-split { grid-template-columns: 1fr; }
  .state-split #terminal { border-right: 0; }
  #terminal { margin-top: auto; }
  #touchbar { display: flex; }
  #terminal { font-size: 13px; padding: 1rem 1rem 0.75rem; }
  .codec, .welcome-row.stacked .codec { width: 116px; height: 116px; }

  /* iOS zooms the page whenever a focused input is under 16px, and it does
     not zoom back out afterwards. The scrollback stays at 13px for the extra
     columns; the whole prompt row goes to 16px so the label and the caret
     still line up with each other. */
  #prompt-form { font-size: 16px; }

  #window {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    background: var(--bg-window);
  }
  /* Set by syncViewport() while the page is pinch-zoomed. A fixed element
     pins to the layout viewport, which is larger than what you can see. */
  #window.vv-tracked {
    position: fixed;
    top: var(--vv-top); left: var(--vv-left);
    width: var(--vv-width); height: var(--vv-height);
  }
  .doc { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  #screen { transition: none; }
  .codec::after { animation: none; }
}
