/* WAFER live Forth shell. Visual language mirrored from kaizenkodo.no
   (website/main.css) via the hel/ precedent: washi-paper cream, ocean blue,
   hanko red, Poppins / Inter / JetBrains Mono — wrapped around a dark,
   machine-like terminal panel that sits on the paper page like a device. */

:root {
  --cream: #f4f0e8;
  --paper: #fbf8f2;
  --ink: #15181b;
  --muted: #6a675e;
  --line: #ddd6c6;
  --ocean: #1b4161;
  --ocean-2: #2f6286;
  --deep: #0a2540;
  --seal: #e23b2e;
  --disp: "Poppins", system-ui, sans-serif;
  --body: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --maxw: 1100px;
  --gutter: clamp(16px, 3.5vw, 48px);
  --radius: 16px;
  /* terminal palette: deep ocean-black, not pure #000 */
  --term-bg: #081420;
  --term-bg-2: #0a1826;
  --term-text: #c3cbd3;
  --term-bright: #e8e4d8;
  --term-accent: #56c8d8;
  --term-green: #7fd98a;
  --term-red: #ff6b6b;
  --term-dim: #5c6a78;
  --term-border: #16283a;
}

/* Self-hosted fonts, bundled with the page so it makes NO external requests
   (no Google Fonts, no CDN). Latin subset only. */
@font-face { font-family:"Poppins"; font-style:normal; font-weight:600; font-display:swap; src:url("./assets/fonts/Poppins-600.woff2") format("woff2"); }
@font-face { font-family:"Poppins"; font-style:normal; font-weight:700; font-display:swap; src:url("./assets/fonts/Poppins-700.woff2") format("woff2"); }
@font-face { font-family:"Inter"; font-style:normal; font-weight:400; font-display:swap; src:url("./assets/fonts/Inter-400.woff2") format("woff2"); }
@font-face { font-family:"Inter"; font-style:normal; font-weight:500; font-display:swap; src:url("./assets/fonts/Inter-500.woff2") format("woff2"); }
@font-face { font-family:"JetBrains Mono"; font-style:normal; font-weight:400; font-display:swap; src:url("./assets/fonts/JetBrainsMono-400.woff2") format("woff2"); }
@font-face { font-family:"JetBrains Mono"; font-style:normal; font-weight:500; font-display:swap; src:url("./assets/fonts/JetBrainsMono-500.woff2") format("woff2"); }

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; overflow-x: hidden; overscroll-behavior-x: none; }

body {
  min-height: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--cream);
  background-image:
    linear-gradient(rgba(27, 65, 97, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(27, 65, 97, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding-inline: var(--gutter); }

/* Header — installed as a PWA the page owns the status-bar strip
   (viewport-fit=cover), so the sticky bar pays the top inset and its blur
   covers it. In a browser tab the inset is 0 and nothing moves. */
.site {
  position: sticky; top: 0; z-index: 50;
  padding-top: env(safe-area-inset-top);
  background: rgba(244, 240, 232, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.nav { display: flex; align-items: center; gap: 14px; height: 68px; }
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; }
.enso { width: 36px; height: 36px; display: block; flex: none; object-fit: contain; }
.wordmark { font-family: var(--disp); font-weight: 700; font-size: 22px; color: var(--ocean); letter-spacing: -0.01em; }
.tagline { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }
.nav-spacer { flex: 1; }
.backlink { display: inline-flex; align-items: center; gap: 5px; flex: none; font-family: var(--mono); font-size: 12px; letter-spacing: 0.03em; color: var(--muted); text-decoration: none; white-space: nowrap; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); }
.backlink:hover { color: var(--ocean); border-color: var(--ocean); background: rgba(27, 65, 97, 0.05); }
.backlink .arr { font-size: 14px; line-height: 1; }

/* Buttons (header GitHub link) */
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; white-space: nowrap;
  font-family: var(--disp); font-weight: 600; font-size: 14px;
  background: var(--ocean); color: var(--cream); text-decoration: none;
  border: 1px solid var(--ocean); border-radius: 999px; padding: 10px 20px;
  transition: transform .15s, background .15s, border-color .15s;
}
.btn:hover { transform: translateY(-1px); background: var(--deep); border-color: var(--deep); }
.btn.ghost { background: transparent; color: var(--ocean); }
.btn.ghost:hover { background: rgba(27, 65, 97, 0.06); border-color: var(--ocean); }
.btn.small { padding: 7px 15px; font-size: 13px; }

main { padding: clamp(20px, 3vw, 34px) 0 56px; display: grid; grid-template-columns: minmax(0, 1fr); gap: clamp(16px, 2.4vw, 24px); }

/* Hero strip: kanji eyebrow + one machine line */
.hero-strip { display: flex; align-items: center; gap: 16px; padding: 2px 4px 0; }
.hero-strip .kanji {
  font-size: clamp(30px, 4.5vw, 42px); line-height: 1; color: var(--ocean);
  opacity: 0.85; flex: none; user-select: none;
}
.hero-line {
  font-family: var(--mono); font-size: clamp(11px, 1.6vw, 13px); letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--ocean);
  display: inline-flex; align-items: center; gap: 10px;
}
.hero-line::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: var(--seal); box-shadow: 0 0 0 3px rgba(226, 59, 46, 0.16);
}

/* About / how-it-works (collapsible <details>) — hel pattern */
.about { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.about > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px;
  padding: clamp(14px, 2.2vw, 19px) clamp(16px, 2.6vw, 28px);
  font-family: var(--disp); font-weight: 600; font-size: clamp(16px, 2vw, 20px); color: var(--ocean);
}
.about > summary::-webkit-details-marker { display: none; }
.about > summary:hover { color: var(--ocean-2); }
.about-badge {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: #fff; background: var(--seal); border-radius: 999px; padding: 3px 10px; flex: none;
  animation: badgePulse 2.2s ease-out infinite;
}
@keyframes badgePulse {
  0% { box-shadow: 0 0 0 0 rgba(226, 59, 46, 0.45); }
  70% { box-shadow: 0 0 0 9px rgba(226, 59, 46, 0); }
  100% { box-shadow: 0 0 0 0 rgba(226, 59, 46, 0); }
}
@media (prefers-reduced-motion: reduce) { .about-badge { animation: none; } }
.about-hint { font-family: var(--mono); font-size: 11px; font-weight: 400; color: var(--muted); }
.about[open] .about-badge, .about[open] .about-hint { display: none; }
@media (max-width: 680px) { .about-hint { display: none; } }
.about .about-toggle {
  margin-left: auto; width: 9px; height: 9px; flex: none;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg); transition: transform .2s;
}
.about[open] .about-toggle { transform: rotate(-135deg); }
.about-body { padding: 0 clamp(16px, 2.6vw, 28px) clamp(16px, 2.6vw, 24px); }
.about-body p { color: var(--muted); font-size: 14.5px; }
.about-body > p:first-child { color: var(--ink); font-size: 15.5px; }
.about-body code { font-family: var(--mono); font-size: 12px; color: var(--ocean-2); background: rgba(27,65,97,.06); padding: 1px 5px; border-radius: 5px; }
.about-body a { color: var(--ocean); }
.about-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin: 18px 0 6px; }
.about-grid h4 { font-family: var(--disp); font-weight: 600; font-size: 14px; color: var(--ink); margin-bottom: 5px; }
.about-grid p { font-size: 13.5px; }
.about-note { font-family: var(--mono); font-size: 12px; margin-top: 10px; }
.about-privacy {
  margin: 6px 0 2px; padding: 13px 16px; border-radius: 12px;
  border: 1px solid var(--line); border-left: 3px solid var(--ocean);
  background: rgba(27, 65, 97, 0.045); color: var(--ink); font-size: 14.5px;
}
.about-privacy strong { color: var(--ocean); }
@media (max-width: 680px) { .about-grid { grid-template-columns: 1fr; } }

/* Terminal card: paper frame around the dark device */
.term-card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(12px, 2vw, 20px);
}

/* Card head: demo chips on the left, the fullscreen toggle pinned right */
.term-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 12px; }

/* Demo chips — styled like the site's tag chips. One row, always: wrapping
   would eat a second line of a phone screen, so the row scrolls instead. */
.chips {
  display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0;
  flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips-label { flex: none; font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-right: 4px; }
.chip {
  flex: none;
  font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: 0.06em;
  color: var(--ocean); background: rgba(27, 65, 97, 0.06);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px;
  cursor: pointer; transition: color .15s, border-color .15s, background .15s, transform .15s;
}
.chip:hover { color: var(--cream); background: var(--ocean); border-color: var(--ocean); transform: translateY(-1px); }
.chip:active { transform: none; }
body:not(.ready) .chip { opacity: 0.45; pointer-events: none; }

/* Fullscreen toggle — quiet mono pill, same family as the version badge */
.shell-btn {
  flex: none; display: flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); background: transparent;
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; transition: color .15s, border-color .15s, background .15s;
}
.shell-btn:hover { color: var(--ocean); border-color: var(--ocean); background: rgba(27, 65, 97, 0.05); }
.shell-btn:focus-visible { outline: none; border-color: var(--ocean); box-shadow: 0 0 0 3px rgba(27, 65, 97, 0.12); }
.shell-btn .sb-out { display: none; }
body.shell-mode .shell-btn { color: var(--ocean); border-color: var(--ocean); }
body.shell-mode .shell-btn .sb-in { display: none; }
body.shell-mode .shell-btn .sb-out { display: flex; }

/* The terminal — the hero. Deep ocean-black device with a soft outer glow,
   subtle CSS-only scanlines, and a faint enso watermark in the corner. */
.term {
  position: relative;
  font-variant-ligatures: none;   /* a shell shows raw chars: >= never ≥ */
  background: linear-gradient(180deg, var(--term-bg-2), var(--term-bg) 42%);
  border: 1px solid var(--term-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 10px 40px rgba(10, 37, 64, 0.28),
    0 2px 10px rgba(10, 37, 64, 0.18);
}
/* scanlines (static, CSS only) */
.term::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: repeating-linear-gradient(
    0deg, rgba(255, 255, 255, 0.015) 0 1px, transparent 1px 3px);
}
/* faint enso watermark, bottom-right (the PNG is dark ink → invert to glow) */
.term::after {
  content: ""; position: absolute; right: -34px; bottom: -34px; z-index: 0;
  width: 220px; height: 220px; pointer-events: none;
  background: url("./assets/enso.png") center / contain no-repeat;
  filter: invert(1); opacity: 0.05;
}

.term-out {
  position: relative; z-index: 1;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.55;
  color: var(--term-text);
  height: clamp(340px, 52vh, 620px);
  overflow-y: auto; overflow-x: hidden;
  padding: 18px 18px 10px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
  cursor: text;
  -webkit-overflow-scrolling: touch;
  text-shadow: 0 0 8px rgba(86, 200, 216, 0.10);   /* phosphor glow */
}
@supports (height: 100dvh) {
  .term-out { height: clamp(340px, 52dvh, 620px); }
}
.term-out::-webkit-scrollbar { width: 6px; }
.term-out::-webkit-scrollbar-track { background: transparent; }
.term-out::-webkit-scrollbar-thumb { background: var(--term-border); border-radius: 3px; }

/* Lines */
.line { min-height: 1.55em; }
.line-ok .echo-input { color: var(--term-dim); }
.line-ok .ok-marker { color: var(--term-green); font-weight: 500; }
.line-error { color: var(--term-red); }
.line-input { color: var(--term-dim); }
.line-output { color: var(--term-text); }

/* Links inside terminal output (OSC 8) */
.terminal-link {
  color: var(--term-accent);
  text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px;
  cursor: pointer; transition: color 0.15s;
}
.terminal-link:hover { color: var(--term-bright); text-decoration-style: solid; }

/* Loading pulse */
.loading { color: var(--term-dim); animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* Input line */
.term-in {
  position: relative; z-index: 1;
  display: flex; align-items: center;
  padding: 10px 18px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--term-border);
  background: rgba(8, 20, 32, 0.6);
}
.term-prompt {
  font-family: var(--mono); font-size: 13.5px; color: var(--term-accent);
  font-weight: 500; flex: none; user-select: none;
}
.term-field { position: relative; flex: 1; display: flex; min-width: 0; }
#input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  color: var(--term-bright);
  font-family: var(--mono); font-size: 13.5px;
  caret-color: transparent;              /* the block cursor replaces the caret */
  padding: 2px 0;
  -webkit-appearance: none; border-radius: 0;
}
#input::placeholder { color: var(--term-dim); opacity: 0.8; }
/* iOS zooms (and stays zoomed) on focus if the field is under 16px */
@media (pointer: coarse) {
  #input, .term-prompt { font-size: 16px; }
  #input { caret-color: var(--term-accent); }  /* trust the native caret on touch */
  .cursor { display: none; }
}

/* Blinking block cursor (desktop); positioned from selectionStart in JS */
.cursor {
  position: absolute; left: 0; top: 50%; margin-top: -0.6em;
  width: 1ch; height: 1.2em;
  font-family: var(--mono); font-size: 13.5px;
  background: rgba(86, 200, 216, 0.75);
  opacity: 0; pointer-events: none;
}
.cursor.on { opacity: 1; animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 0%, 60% { opacity: 1; } 60.01%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor.on { animation: none; opacity: 0.75; } }

/* Footer */
.foot { color: var(--muted); font-family: var(--mono); font-size: 12px; text-align: center; padding-block: 8px 40px; }
.foot a { color: var(--ocean); text-decoration: none; border-bottom: 1px solid rgba(27, 65, 97, 0.3); }
.foot a:hover { border-bottom-color: var(--ocean); }

/* Phones */
@media (max-width: 680px) {
  .nav { gap: 9px; height: 60px; }
  .tagline { display: none; }
  body { font-size: 15px; }
  .backlink { padding: 5px 9px; }
  .hero-strip { gap: 12px; }
  .term-out { height: clamp(300px, 48vh, 560px); font-size: 13px; }
  @supports (height: 100dvh) {
    .term-out { height: clamp(300px, 48dvh, 560px); }
  }
}
@media (max-width: 540px) { .wordmark { display: none; } }

/* ---- changelog overlay (footer version badge), mirrors ../hel/ ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(10, 16, 24, 0.45);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 90;
}
.modal-bg.show { display: flex; }
.modal { background: var(--paper); border-radius: 18px; border: 1px solid var(--line);
  width: 100%; max-width: 680px; padding: 24px; }
.modal h3 { font-family: var(--disp); font-weight: 600; margin-bottom: 10px; }
.modal .row { display: flex; gap: 10px; margin-top: 14px; }

/* Version badge: a quiet mono pill under the footer prose; click opens the
   changelog overlay. */
.ver {
  display: inline-block; margin-top: 10px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em;
  color: var(--muted); background: transparent;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 11px;
  cursor: pointer; transition: color .15s, border-color .15s, background .15s;
}
.ver:hover { color: var(--ocean); border-color: var(--ocean); background: rgba(27, 65, 97, 0.05); }
.ver:focus-visible { outline: none; border-color: var(--ocean); box-shadow: 0 0 0 3px rgba(27, 65, 97, 0.12); }

.changelog { max-height: 62vh; overflow-y: auto; padding-right: 6px; }
.cl-entry { padding: 16px 0; border-top: 1px solid var(--line); }
.cl-entry:first-child { border-top: none; padding-top: 2px; }
.cl-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 3px; }
.cl-ver { font-family: var(--disp); font-weight: 700; font-size: 16px; color: var(--ocean); letter-spacing: -0.01em; }
.cl-date { font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; color: var(--muted); }
.cl-latest {
  margin-left: auto; flex: none; align-self: center;
  font-family: var(--mono); font-size: 9.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: #fff; background: var(--seal); border-radius: 999px; padding: 2px 9px;
}
.cl-title { font-family: var(--disp); font-weight: 600; font-size: 14px; color: var(--ink); margin: 0 0 12px; }
.changelog ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 9px; }
.changelog li { display: flex; align-items: baseline; gap: 12px; color: var(--ink); font-size: 14px; line-height: 1.5; }
.cl-tag {
  flex: none; width: 68px; text-align: center; box-sizing: border-box;
  font-family: var(--mono); font-size: 9.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 3px 0; border-radius: 6px; transform: translateY(-1px);
}
.cl-tag-new { color: var(--ocean); background: rgba(27, 65, 97, 0.10); }
.cl-tag-improved { color: var(--muted); background: rgba(106, 103, 94, 0.13); }
.cl-tag-fixed { color: var(--seal); background: rgba(226, 59, 46, 0.10); }
.cl-text { min-width: 0; }
.changelog code { font-family: var(--mono); font-size: 12px; color: var(--ocean-2); background: rgba(27,65,97,.06); padding: 1px 5px; border-radius: 5px; }
@media (max-width: 540px) {
  .changelog li { flex-wrap: wrap; gap: 5px 10px; }
}

/* Shell mode: the terminal card fills the viewport, at any window size. It is
   a sticky state (toggle button / Esc / a tap on a touch screen) — never
   focus-driven. On a phone the height + translateY come from visualViewport
   (JS, inline) so the card sits above the software keyboard, like ../hel/;
   100svh is both the desktop rule and the no-visualViewport fallback. */
body.shell-mode { overflow: hidden; }            /* freeze the page behind it */
body.shell-mode .term-card {
  position: fixed; inset: 0 0 auto 0; z-index: 60;
  height: 100svh;                                /* JS overrides inline on phones */
  margin: 0; border-radius: 0; border: 0;
  /* Installed as a PWA the card covers the whole screen, status bar included,
     so the top inset is ours to pay. */
  padding-top: calc(8px + env(safe-area-inset-top));
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  padding-left: max(clamp(8px, 2vw, 22px), env(safe-area-inset-left));
  padding-right: max(clamp(8px, 2vw, 22px), env(safe-area-inset-right));
  display: flex; flex-direction: column;
}
/* Software keyboard up: the card bottom is already pinned to the visual
   viewport, but iOS keeps reporting the home-indicator inset — paying it too
   leaves ~34px of dead space stranded behind the keyboard. */
body.kb-open.shell-mode .term-card { padding-bottom: 8px; }
body.kb-open .term-in { padding-bottom: 12px; }
body.shell-mode .term {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; border-radius: 10px;
}
body.shell-mode .term-out { flex: 1 1 auto; min-height: 0; height: auto; }
@media (max-width: 680px) {
  /* tighter head so the terminal keeps the screen */
  body.shell-mode .term-head { padding: 0 2px 8px; }
  /* the row always overflows at this width — fade the edge so it reads as
     scrollable rather than clipped */
  .chips {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 20px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 20px), transparent);
  }
}

/* Update-ready bar (PWA): only shown when an update installs mid-session. */
.update-bar {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%);
  background: var(--ocean); color: var(--cream); font-family: var(--mono); font-size: 13px; font-weight: 600;
  border: none; cursor: pointer; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(10, 16, 24, 0.35); z-index: 90;
}
.update-bar[hidden] { display: none; }
.update-bar:hover { background: var(--deep); }
