:root {
  --bg: #06080a;
  --bg-2: #0b0f13;
  --panel: #0d1116;
  --panel-2: #11161c;
  --fg: #e6e8eb;
  --fg-dim: #5c6570;
  --fg-mute: #3a4048;
  --accent: #7ee787;
  --accent-2: #58a6ff;
  --accent-3: #d2a8ff;
  --warn: #f0883e;
  --err: #ff7b72;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --serif: "Iowan Old Style", "Charter", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(126,231,135,0.07), transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(88,166,255,0.06), transparent 55%),
    radial-gradient(ellipse at 50% 60%, rgba(210,168,255,0.04), transparent 60%),
    var(--bg);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.018) 0,
    rgba(255,255,255,0.018) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 1;
}

main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  z-index: 2;
}

.stage {
  width: 100%;
  max-width: 760px;
}

/* ---------- terminal ---------- */

.terminal {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid rgba(126,231,135,0.18);
  border-radius: 10px;
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.4),
    0 30px 60px -25px rgba(126,231,135,0.18),
    0 0 90px -40px rgba(88,166,255,0.25);
  overflow: hidden;
  font-size: clamp(13px, 1.85vw, 15px);
  line-height: 1.55;
}

.termbar {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  background: #090c10;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  gap: 12px;
}

.dotgroup { display: inline-flex; gap: 6px; }
.bdot {
  width: 11px; height: 11px; border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}
.bdot.red    { background: #ff5f56; }
.bdot.yellow { background: #ffbd2e; }
.bdot.green  { background: #27c93f; }

.termtitle {
  flex: 0 1 auto;
  margin-left: 6px;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
  text-transform: lowercase;
}
.termfill { flex: 1; }

.termbody {
  padding: 18px 18px 6px;
  min-height: 280px;
  max-height: 50vh;
  overflow-y: auto;
}
.termbody::-webkit-scrollbar { width: 8px; }
.termbody::-webkit-scrollbar-track { background: transparent; }
.termbody::-webkit-scrollbar-thumb { background: rgba(126,231,135,0.15); border-radius: 4px; }

.line {
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 2px;
}
.line.spacer { height: 0.6em; }
.line.boot { color: #b8bec5; }
.line.boot .cyan { color: var(--accent-2); }
.line .green { color: var(--accent); }
.line .dim { color: var(--fg-dim); }
.line .muted { color: var(--fg-mute); }
.line .warn { color: var(--warn); }
.line .err { color: var(--err); }
.line.echo {
  color: var(--fg);
}
.line.echo .cwd { color: var(--accent-2); }
.line.echo .caret-glyph { color: var(--accent-3); }
.line.out { color: #c8ced5; }
.line.out .accent { color: var(--accent); }
.line.out .accent2 { color: var(--accent-2); }
.line.out .accent3 { color: var(--accent-3); }
.line.out .bold { color: var(--fg); font-weight: 600; }
.line.banner {
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.line.headline {
  font-size: clamp(20px, 3.4vw, 28px);
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 8px 0 2px;
  color: var(--fg);
}

.kbd {
  font-family: var(--mono);
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.9em;
  color: var(--accent);
}

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

.prompt {
  display: flex;
  align-items: baseline;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 8px 18px 16px;
  font-family: var(--mono);
  position: relative;
  margin: 0;
}
.cwd {
  color: var(--accent-2);
  white-space: nowrap;
  flex: 0 0 auto;
}
.prompt-glyph {
  color: var(--accent-3);
  font-weight: 600;
  flex: 0 0 auto;
  text-shadow: 0 0 8px rgba(210,168,255,0.35);
}
.input-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-family: var(--mono);
  /* Important: do NOT set `white-space: pre` here — it would render the
     HTML newlines/indentation between the inner spans as visible breaks,
     pushing the `_` caret onto its own line. Spaces inside the typed
     string are preserved by `.user-text` below. */
  white-space: nowrap;
}
.user-text {
  color: var(--fg);
  white-space: pre;
}
.blink-caret {
  display: inline-block;
  margin-left: 1px;
  color: var(--accent);
  font-weight: 700;
  text-shadow:
    0 0 6px rgba(126,231,135,0.85),
    0 0 14px rgba(126,231,135,0.45);
  animation: termblink 1.05s steps(2, start) infinite;
}
@keyframes termblink {
  to { opacity: 0; }
}
/* fully hide the real input — keep it focusable + key-receiving */
#cmd {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  outline: 0;
  box-shadow: none;
  color: transparent;
  caret-color: transparent;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  font: inherit;
  letter-spacing: inherit;
  text-shadow: none;
}
#cmd:focus,
#cmd:focus-visible {
  outline: 0;
  box-shadow: none;
  border: 0;
}
#cmd::selection { background: rgba(126,231,135,0.25); color: transparent; }
.ghost {
  display: inline;
  pointer-events: none;
  color: var(--fg-mute);
  white-space: pre;
  font-family: var(--mono);
  font-size: inherit;
}
.ghost:empty { display: none; }

.hint {
  margin: 14px 4px 0;
  font-size: 12px;
  color: var(--fg-dim);
  letter-spacing: 0.02em;
}
.hint .muted { color: var(--fg-mute); margin-right: 4px; }

/* ---------- footer ---------- */

footer {
  padding: 22px;
  text-align: center;
  font-size: 11.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-dim);
  position: relative;
  z-index: 2;
}
footer .dot { margin: 0 8px; color: var(--fg-mute); }
footer .muted { color: var(--fg-dim); }

/* ---------- 404 fallback (still uses .answer) ---------- */
.line.answer {
  color: var(--accent);
  padding-left: 1.2em;
}
.caret {
  display: inline-block;
  color: var(--accent);
  animation: blink 1.05s steps(2, start) infinite;
}
@keyframes blink {
  to { visibility: hidden; }
}

/* ---------- story page ---------- */

.story-shell {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 64px 28px 96px;
  position: relative;
  z-index: 2;
}
.story-shell .crumbs {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
  margin-bottom: 24px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.story-shell .crumbs a {
  color: var(--accent);
  text-decoration: none;
}
.story-shell .crumbs a:hover { text-decoration: underline; }
.story-shell .crumbs .sep { color: var(--fg-mute); }

.story-title {
  font-family: var(--mono);
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: -0.01em;
  margin: 0 0 6px;
  color: var(--fg);
}
.story-title .accent { color: var(--accent); }
.story-sub {
  font-family: var(--mono);
  font-size: clamp(13.5px, 2.1vw, 15px);
  color: var(--fg-dim);
  letter-spacing: 0.02em;
  margin: 0 0 56px;
}

.chapter {
  margin: 84px 0 0;
}
.chapter:first-of-type { margin-top: 24px; }
.chapter .num {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.chapter h2 {
  font-family: var(--mono);
  font-size: clamp(22px, 3.4vw, 28px);
  letter-spacing: -0.01em;
  margin: 0 0 20px;
  color: var(--fg);
}
.chapter p {
  font-family: var(--serif);
  font-size: clamp(16px, 2.2vw, 18px);
  line-height: 1.7;
  color: #d6dade;
  margin: 0 0 18px;
}
.chapter p code,
.chapter li code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--accent);
  background: rgba(126,231,135,0.06);
  border: 1px solid rgba(126,231,135,0.12);
  border-radius: 4px;
  padding: 0 5px;
}
.chapter ul {
  font-family: var(--serif);
  font-size: clamp(15px, 2.1vw, 17px);
  line-height: 1.65;
  color: #c9ced4;
  padding-left: 22px;
  margin: 0 0 18px;
}
.chapter ul li { margin-bottom: 6px; }

.aside {
  border-left: 2px solid var(--accent);
  padding: 4px 0 4px 18px;
  margin: 28px 0;
  color: #b8bec5;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
}

.figure {
  margin: 36px -8px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
  background: var(--panel);
  box-shadow: 0 30px 60px -30px rgba(0,0,0,0.7);
}
.figure img {
  display: block;
  width: 100%;
  height: auto;
}
.figure figcaption {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
  padding: 10px 14px;
  background: var(--panel-2);
  border-top: 1px solid rgba(255,255,255,0.05);
}

.outro {
  margin-top: 96px;
  padding: 32px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--fg-dim);
  text-align: center;
  letter-spacing: 0.04em;
}
.outro .pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 8px;
  vertical-align: middle;
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1.05); }
}

/* ---------- responsive ---------- */
/* defaults: assume desktop / non-touch — mobile media query below overrides */
.hint .touch-only { display: none; }
.hint .desktop-only { display: inline; }

@media (max-width: 640px) {
  main { padding: 14px; }
  .stage { max-width: 100%; }

  .terminal {
    font-size: 13px;
    line-height: 1.5;
    border-radius: 8px;
  }
  .termbar { padding: 7px 10px; gap: 8px; }
  .termtitle { display: none; }
  .bdot { width: 9px; height: 9px; }

  .termbody {
    padding: 12px 12px 2px;
    min-height: 220px;
    max-height: 60vh;
  }
  .line { margin-bottom: 1px; }
  .line.boot .muted { display: inline; opacity: 0.7; }

  .prompt {
    padding: 6px 12px 12px;
    align-items: baseline;
    gap: 6px;
  }
  /* On phones we drop the cwd to keep `> _` on a single line */
  .cwd { display: none; }
  /* iOS Safari auto-zooms on focus if font-size < 16px — pin the
     real (invisible) input to 16px to suppress that, while the visible
     mirror keeps the smaller terminal type */
  #cmd { font-size: 16px; }

  .hint {
    margin: 12px 4px 0;
    font-size: 11.5px;
    line-height: 1.5;
  }
  .hint .desktop-only { display: none; }
  .hint .touch-only { display: inline; }

  footer { padding: 18px 12px; font-size: 10.5px; letter-spacing: 0.14em; }
  footer .dot { margin: 0 6px; }

  /* story page */
  .story-shell { padding: 36px 18px 60px; }
  .story-title { line-height: 1.15; margin-bottom: 4px; }
  .story-sub { margin-bottom: 36px; }
  .crumbs { margin-bottom: 18px; }
  .chapter { margin-top: 56px; }
  .chapter:first-of-type { margin-top: 12px; }
  .chapter h2 { margin-bottom: 14px; }
  .chapter p { margin-bottom: 14px; }
  .chapter ul { padding-left: 20px; margin-bottom: 14px; }
  .figure { margin: 24px 0; border-radius: 8px; }
  .figure figcaption { font-size: 11px; padding: 8px 12px; letter-spacing: 0.03em; }
  .aside { margin: 22px 0; padding-left: 14px; font-size: 13px; }
  .outro { margin-top: 64px; padding: 24px 12px; font-size: 12px; line-height: 1.6; }
}

@media (max-width: 380px) {
  .terminal { font-size: 12px; }
  .termbody { padding: 10px 10px 0; }
  .prompt { padding: 6px 10px 10px; }
  .story-shell { padding: 28px 14px 48px; }
  .chapter { margin-top: 44px; }
}
