/* ===========================================================================
   haydn.ca

   A terminal in a void. CLI grammar — prompts, // separators, [01] indices,
   hard selection blocks — inside four corner brackets.

   Monochrome. There is no accent colour: the amber that used to exist was
   there to tint the orbiting glyphs, and the orbit is gone. If you add a
   colour, give it a reason first.
   =========================================================================== */

@font-face {
  font-family: 'Departure Mono';
  src: url('../fonts/DepartureMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ---------------------------------------------------------------------------
   Tokens — dark is the default, light is the alternate.
   --------------------------------------------------------------------------- */
:root {
  --ground:      #0a0a0a;
  --ground-lift: #1c1c1c;   /* gradient centre */
  --ground-edge: #000000;   /* gradient edge   */
  --ground-dim:  #5c5c58;   /* dim text sitting *on* an inverted block */
  --ink:         #e8e8e6;
  --ink-dim:     #6e6e6a;
  --rule:        #3d3d3a;   /* on near-black, anything darker reads as nothing */
  --scan:        rgba(255, 255, 255, 0.026);

  /* The one colour on this site, and it only ever appears for about a second
     after a successful copy. Confirmation is the single case where monochrome
     genuinely costs you something: "it worked" has to be unmistakable. */
  --ok:          #4ade80;

  /* Pixel fonts fall apart at fractional sizes — fixed integers, not clamp(). */
  --fs-micro: 11px;
  --fs-small: 12px;
  --fs-body:  14px;
  --fs-lead:  18px;
  --fs-hero:  24px;
  --fs-huge:  20px;

  --track: 0.18em;
  --frame-inset: 22px;
  --stage: 620px;

  --font: 'Departure Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

:root[data-theme='light'] {
  --ground:      #f2f2f0;
  --ground-lift: #ffffff;
  --ground-edge: #dcdcd8;
  --ground-dim:  #a8a8a3;
  --ink:         #101010;
  --ink-dim:     #8a8a86;
  --rule:        #c4c4c0;
  --scan:        rgba(0, 0, 0, 0.032);
  --ok:          #15803d;   /* the dark-theme green is unreadable on paper */
}

/* ---------------------------------------------------------------------------
   Reset
   --------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, p, ol, ul, pre, figure { margin: 0; }
ol[class], ul[class] { list-style: none; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--ground);
  background-image: radial-gradient(
    ellipse 78% 62% at 50% 46%,
    var(--ground-lift) 0%,
    var(--ground) 46%,
    var(--ground-edge) 100%
  );
  -webkit-font-smoothing: none;   /* pixel font: keep the edges hard */
  font-smooth: never;
  overflow-x: hidden;
}

/* Zero radius, everywhere. Depth comes from inversion, never from shadow. */
button, a, input, div, span, li, pre { border-radius: 0; }

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

/* ---------------------------------------------------------------------------
   Frame — four corner brackets, not a continuous border
   --------------------------------------------------------------------------- */
.frame__bracket {
  position: fixed;
  /* Large enough to read as a bracket rather than a smudge, and large enough
     that the clock sits inside its angle instead of colliding with it. */
  width: 46px;
  height: 46px;
  border: 0 solid var(--rule);
  z-index: 3;
  pointer-events: none;
}
.frame__bracket--tl { top: var(--frame-inset);    left: var(--frame-inset);  border-top-width: 1px;    border-left-width: 1px; }
.frame__bracket--tr { top: var(--frame-inset);    right: var(--frame-inset); border-top-width: 1px;    border-right-width: 1px; }
.frame__bracket--bl { bottom: var(--frame-inset); left: var(--frame-inset);  border-bottom-width: 1px; border-left-width: 1px; }
.frame__bracket--br { bottom: var(--frame-inset); right: var(--frame-inset); border-bottom-width: 1px; border-right-width: 1px; }

.texture {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom, var(--scan) 0 1px, transparent 1px 3px);
}

/* ---------------------------------------------------------------------------
   HUD — clock top-left, role top-right, status + sun bottom
   --------------------------------------------------------------------------- */
.hud {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(var(--frame-inset) + 8px) calc(var(--frame-inset) + 22px);
  font-size: var(--fs-micro);
  letter-spacing: var(--track);
  text-transform: uppercase;
  color: var(--ink-dim);
}

.hud__clock  { color: var(--ink); font-variant-numeric: tabular-nums; }
.hud__status { color: var(--ink-dim); }

/* --- theme toggle: bottom-right, per the sketch -------------------------- */
.theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  color: var(--ink-dim);
  cursor: pointer;
}
.theme:hover { color: var(--ink); border-color: var(--rule); }

.theme__icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
}
/* Show the icon for the theme you'd switch TO. */
:root[data-theme='dark']  .theme__icon--moon { display: none; }
:root[data-theme='light'] .theme__icon--sun  { display: none; }

/* ---------------------------------------------------------------------------
   Stage
   --------------------------------------------------------------------------- */
.stage {
  position: relative;
  z-index: 2;
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem calc(var(--frame-inset) + 22px) 2rem;
}

.view { width: 100%; max-width: var(--stage); text-align: center; }
.view[hidden] { display: none; }

.prompt { color: var(--ink-dim); margin-right: 0.6ch; }

/* ---------------------------------------------------------------------------
   Home — the two big buttons
   --------------------------------------------------------------------------- */
.action-menu {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.action-menu__button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 200px;
  min-height: 88px;
  padding: 1.25rem 2rem;
  border: 1px solid var(--rule);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--fs-huge);
  letter-spacing: var(--track);
}
/* Hard invert — the same terminal-selection language the rows use. */
.action-menu__button:hover,
.action-menu__button:focus-visible {
  background: var(--ink);
  color: var(--ground);
  border-color: var(--ink);
}

/* ---------------------------------------------------------------------------
   Contact — address bar, own socials
   --------------------------------------------------------------------------- */
.address {
  display: block;
  width: 100%;
  font: inherit;
  font-size: var(--fs-hero);
  color: var(--ink);
  background: none;
  border: 1px solid var(--rule);
  padding: 1.1rem 1.25rem;
  cursor: pointer;
  letter-spacing: 0.01em;
}
.address:hover,
.address:focus-visible { background: var(--ink); color: var(--ground); border-color: var(--ink); }

.address__hint {
  margin-top: 0.85rem;
  font-size: var(--fs-micro);
  letter-spacing: var(--track);
  text-transform: uppercase;
  color: var(--ink-dim);
  /* Reserve the tick's width always, so the line does not jump sideways when
     it appears. */
  min-height: 1.4em;
}

.address__tick {
  width: 12px;
  height: 12px;
  margin-right: 0.6ch;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: square;
  stroke-linejoin: miter;
  vertical-align: -1px;
  /* Hidden by clip rather than display:none so its width is reserved. */
  visibility: hidden;
}

.address__hint.is-copied { color: var(--ok); }
.address__hint.is-copied .address__tick { visibility: visible; }

/* The stroke draws itself on rather than blinking into existence — short
   enough to read as part of the glitch, not as a separate animation. */
@keyframes tick-draw {
  from { stroke-dashoffset: 30; }
  to   { stroke-dashoffset: 0; }
}
.address__hint.is-copied .address__tick polyline {
  stroke-dasharray: 30;
  animation: tick-draw 220ms steps(4, end) 1;
}

.socials {
  display: flex;
  justify-content: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 1.75rem;
}

.socials__link {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--rule);
  color: var(--ink-dim);
  text-decoration: none;
  font-size: var(--fs-micro);
  letter-spacing: var(--track);
  text-transform: uppercase;
}
.socials__link:hover,
.socials__link:focus-visible { background: var(--ink); color: var(--ground); border-color: var(--ink); }

/* ---------------------------------------------------------------------------
   Back
   --------------------------------------------------------------------------- */
.view__back {
  display: inline-block;
  margin-top: 2.5rem;
  font-size: var(--fs-micro);
  letter-spacing: var(--track);
  text-transform: uppercase;
  color: var(--ink-dim);
  text-decoration: none;
  padding: 0.4rem 0.6rem;
}
.view__back:hover,
.view__back:focus-visible { color: var(--ink); }

/* ---------------------------------------------------------------------------
   Clients listing — kept from the version that worked
   --------------------------------------------------------------------------- */
.view[data-view='clients'] { text-align: left; }

.listing__cmd {
  font-size: var(--fs-body);
  color: var(--ink-dim);
  margin-bottom: 1.1rem;
}

.listing {
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 0.75rem 0;
}

.state { font-size: var(--fs-small); color: var(--ink-dim); padding: 0.5rem 10px; }

.row {
  position: relative;
  display: block;
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

/* Both the row and its glitch ghost use this identical grid so the ghost lands
   exactly on top. Character-cell widths (ch) are exact in a monospace face —
   that's what makes every `//` align down the page. */
/* Flex, not a fixed grid. The name used to sit in an 18ch grid cell, so any
   name longer than that collided with what followed — removing the fixed
   column is the actual fix for the overlap, not just dropping the URL.
   The name takes its natural width, // follows it, and a very long name wraps
   onto the next line instead of running into anything. */
.row__layer {
  display: flex;
  align-items: baseline;
  gap: 0 1ch;
  padding: 5px 10px;
}

/* Index keeps its own column; everything else is one inline run, so a long
   name wraps as text with // trailing the last word rather than each piece
   breaking onto a separate line. min-width:0 is what actually permits the
   flex child to shrink and wrap at all. */
.row__idx  { color: var(--ink-dim); flex: none; width: 4ch; }
.row__body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row__name { color: var(--ink); }
.row__sep  { color: var(--ink-dim); white-space: nowrap; }

.row:hover,
.row:focus-visible,
.row[aria-expanded='true'] { background: var(--ink); color: var(--ground); }

.row:hover .row__idx,  .row:focus-visible .row__idx,  .row[aria-expanded='true'] .row__idx,
.row:hover .row__sep,  .row:focus-visible .row__sep,  .row[aria-expanded='true'] .row__sep {
  color: var(--ground-dim);
}
.row:hover .row__name, .row:focus-visible .row__name, .row[aria-expanded='true'] .row__name {
  color: var(--ground);
}

/* --- glitch 1: ghost slice displacement ---------------------------------- */
/* A ghost copy of the row, clipped to a moving band and knocked sideways.
   Monochrome slice displacement, not the usual RGB split — there's no chroma
   here for a chromatic aberration to act on. steps() keeps it digital, and it
   fires ONCE and resolves: a row that glitches forever can't be read. */
.row__ghost {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: var(--ground);
}
.row__ghost .row__idx,
.row__ghost .row__sep { color: var(--ground-dim); }
.row__ghost .row__name { color: var(--ground); }

@keyframes glitch-burst {
  0%   { opacity: 1; clip-path: inset(8%  0 78% 0); transform: translateX(-3px); }
  20%  { opacity: 1; clip-path: inset(44% 0 38% 0); transform: translateX(4px);  }
  40%  { opacity: 1; clip-path: inset(70% 0 14% 0); transform: translateX(-2px); }
  60%  { opacity: 1; clip-path: inset(24% 0 58% 0); transform: translateX(3px);  }
  80%  { opacity: 1; clip-path: inset(58% 0 26% 0); transform: translateX(-1px); }
  100% { opacity: 0; clip-path: inset(0   0 100% 0); transform: translateX(0);   }
}

.row:hover .row__ghost,
.row:focus-visible .row__ghost { animation: glitch-burst 200ms steps(1, end) 1; }

/* --- glitch 2: self-jitter ------------------------------------------------ */
/* Needs no duplicate layer, so it applies to anything — buttons, the clock,
   a random element on the ambient timer. */
@keyframes jitter {
  0%   { clip-path: inset(0 0 0 0);     transform: translateX(0);   }
  12%  { clip-path: inset(18% 0 64% 0); transform: translateX(-3px); }
  24%  { clip-path: inset(0 0 0 0);     transform: translateX(0);   }
  38%  { clip-path: inset(56% 0 26% 0); transform: translateX(4px);  }
  50%  { clip-path: inset(0 0 0 0);     transform: translateX(0);   }
  64%  { clip-path: inset(32% 0 48% 0); transform: translateX(-2px); }
  78%  { clip-path: inset(0 0 0 0);     transform: translateX(2px);  }
  100% { clip-path: inset(0 0 0 0);     transform: translateX(0);   }
}
.is-glitching { animation: jitter 260ms steps(1, end) 1; }

/* --- the expansion tree --------------------------------------------------- */
.panel { padding: 0.35rem 10px 0.85rem calc(5ch + 10px); }
.panel[hidden] { display: none; }

.tree__node {
  display: grid;
  grid-template-columns: 2ch 9ch 1fr;
  gap: 0 1ch;
  align-items: baseline;
  font-size: var(--fs-small);
  /* Box-drawing glyphs only join into a continuous tree when the line box is
     the height of the glyph cell — which is why real terminal output connects.
     At the body's 1.6 this renders as disconnected ticks. */
  line-height: 1.25;
}

.tree__branch { color: var(--ink-dim); }
.tree__label  { color: var(--ink-dim); letter-spacing: 0.1em; }
.tree__empty  { color: var(--ink-dim); font-style: normal; opacity: 0.75; }
.tree__node--empty { grid-template-columns: 2ch 1fr; }

.tree__link {
  color: var(--ink);
  text-decoration: none;
  padding: 1px 4px;
  justify-self: start;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree__link:hover,
.tree__link:focus-visible { background: var(--ink); color: var(--ground); }

/* ---------------------------------------------------------------------------
   Focus — hover-only affordances are an anti-pattern; never remove the ring
   --------------------------------------------------------------------------- */
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.row:focus-visible { outline-offset: -2px; }

/* ---------------------------------------------------------------------------
   Reduced motion — the invert and the clock stay (they carry meaning).
   Everything that moves on its own stops.
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .row__ghost { display: none; }
}

/* ---------------------------------------------------------------------------
   Narrow screens
   --------------------------------------------------------------------------- */
@media (max-width: 640px) {
  :root { --frame-inset: 12px; --fs-hero: 16px; --fs-huge: 16px; }

  .action-menu { flex-direction: column; align-items: stretch; }
  .action-menu__button { min-width: 0; min-height: 72px; }

  .address { font-size: 15px; padding: 0.9rem; }


  .panel { padding-left: calc(4ch + 10px); }
  .tree__node { grid-template-columns: 2ch 1fr; }
  .tree__label { display: none; }

  .hud   { padding: calc(var(--frame-inset) + 8px) calc(var(--frame-inset) + 12px); }
  .stage { padding-inline: calc(var(--frame-inset) + 12px); }
}
