/* ============================================================
   Neal Meinke — painted homepage
   Above the fold, always. No page scroll, ever.

   Motion system ported from the painted-ui wiki:
     wiki/techniques/motion-physics.md  — analytic damped springs,
       spatial/effects families, the six-token table
     wiki/concepts/four-loops.md        — producers mutate, renderer samples
     wiki/concepts/client-side-compositing.md — canvas, never waits
   ============================================================ */

:root {
  --surface:        #0e0f13;
  --surface-c:      #16181e;
  --surface-c-high: #1d2029;
  --outline:        #2a2e39;
  --outline-soft:   #1f222a;
  --on-surface:     #e6e7ea;
  --on-surface-var: #a2a7b4;
  --on-surface-dim: #6b7180;

  --exp:  #a8c7fa;
  --skl:  #7dd3c0;
  --prj:  #ffb77c;
  --app:  #d3bbff;
  --cpt:  #f7a8c4;
  --core: #f2f3f5;

  /* Deliberately hotter than --cpt. The node palette is muted so the graph
     reads as one object; this has to read as an action, not a category. */
  --biz:     #ff7eb6;
  --biz-lit: #ffa3cc;
  --biz-ink: #2d0c1c;

  --disp: 'Space Grotesk', system-ui, sans-serif;
  --body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;              /* above the fold. non-negotiable. */
  overscroll-behavior: none;
}

body {
  background: var(--surface);
  color: var(--on-surface);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

#app {
  position: fixed; inset: 0;
  height: 100dvh;
  display: grid;
  /* the reading column takes the space; the graph gets what's left.
     --rail-w is driven by the splitter. */
  --rail-w: 41vw;
  grid-template-columns: minmax(340px, var(--rail-w)) 7px 1fr;
}

/* ---------------- mobile top bar (hidden on desktop) ---------------- */

.topbar { display: none; }
.navstrip { display: none; }
.sheet-handle { display: none; }   /* mobile-only; see the 820px block */

/* ---------------- splitter ---------------- */

.split {
  position: relative; z-index: 5;
  background: var(--surface);
  cursor: col-resize;
  display: flex; align-items: center; justify-content: center;
  border-left: 1px solid var(--outline-soft);
  border-right: 1px solid var(--outline-soft);
  transition: background .2s;
  touch-action: none;
}
.split::before {
  content: ''; width: 3px; height: 34px; border-radius: 999px;
  background: var(--outline); transition: background .2s, height .2s;
}
.split:hover::before, .split:focus-visible::before, .split.dragging::before {
  background: var(--skl); height: 60px;
}
.split:focus-visible { outline: none; }
.split.dragging { background: var(--surface-c); }
body.resizing { cursor: col-resize; user-select: none; }

/* ---------------- left rail: identity + the read ---------------- */

.rail {
  position: relative; z-index: 3;
  display: flex; flex-direction: column;
  padding: clamp(22px, 3vh, 36px) clamp(24px, 2.4vw, 46px) clamp(16px, 2vh, 26px);
  border-right: 1px solid var(--outline-soft);
  background: linear-gradient(180deg, var(--surface-c) 0%, var(--surface) 100%);
  min-height: 0;
  /* type below scales against THIS column, not the viewport — so everything
     grows when you drag the splitter, instead of stopping at a fixed cap */
  container-type: inline-size;
  container-name: read;
}

.mark {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 1.4px;
  text-transform: uppercase; color: var(--on-surface-dim);
  display: flex; align-items: center; gap: 7px; margin-bottom: 14px;
}
.mark .pulse {
  width: 5px; height: 5px; border-radius: 50%; background: var(--skl); flex: 0 0 auto;
}

.head-row {
  display: flex; align-items: flex-end; gap: clamp(16px, 2vw, 34px);
  margin-bottom: 18px; flex: 0 0 auto;
}
h1 {
  font-family: var(--disp); font-weight: 700;
  font-size: clamp(30px, 8cqi, 58px);
  line-height: .98; letter-spacing: -1.8px;
  margin: 0; flex: 0 0 auto;
}
.role {
  font-size: clamp(12.5px, 1.7cqi, 16.5px); line-height: 1.52;
  color: var(--on-surface-var); margin: 0 0 4px; flex: 1 1 auto;
}
.role b { color: var(--on-surface); font-weight: 600; }

/* ---------------- small-business CTA ----------------
   Lives between the head row and the reading card. The one element on this
   page addressed to somebody who isn't hiring me. */

.biz-cta {
  display: inline-flex; align-items: center; gap: 9px;
  align-self: flex-start; flex: 0 0 auto;
  margin: 0 0 16px;
  padding: 10px 17px;
  border-radius: 999px;
  background: var(--biz);
  color: var(--biz-ink);
  text-decoration: none;
  font-family: var(--disp); font-weight: 600;
  font-size: clamp(12.5px, 1.45cqi, 14.5px);
  letter-spacing: -.2px; line-height: 1;
  border: 1px solid var(--biz);
  animation: bizpulse 3.6s ease-in-out infinite;
  transition: transform .2s cubic-bezier(.2,.6,.2,1), background .2s;
}
.biz-cta:hover  { transform: translateY(-2px); background: var(--biz-lit); }
.biz-cta:active { transform: translateY(0); }
.biz-cta:focus-visible { outline: 2px solid var(--biz-lit); outline-offset: 3px; }
.biz-cta .ar { font-size: 15px; line-height: 1; transition: transform .2s; }
.biz-cta:hover .ar { transform: translateX(3px); }

/* draws the eye once every few seconds without moving anything — the ring
   expands out of the button rather than the button itself scaling, so it
   never nudges the layout */
@keyframes bizpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,126,182,.40); }
  55%      { box-shadow: 0 0 0 10px rgba(255,126,182,0); }
}
/* the engine reads this preference too — the button shouldn't be the one
   thing on the page that ignores it */
@media (prefers-reduced-motion: reduce) {
  .biz-cta { animation: none; }
  .biz-cta:hover { transform: none; }
  .biz-cta:hover .ar { transform: none; }
  /* reading mode still works, it just arrives instead of sliding */
  .rail, .stage, .sheet-handle .grip { transition: none; }
  .sheet-handle, .sheet-handle .grip, .sheet-handle .txt { animation: none; }
}

/* the reading card — takes every pixel the rail can spare */
.detail {
  background: var(--surface-c-high);
  border: 1px solid var(--outline-soft);
  border-left: 2px solid var(--accent-live, var(--outline));
  border-radius: 6px 18px 18px 6px;
  padding: clamp(16px, 2.2vh, 24px) clamp(18px, 1.8vw, 30px);
  flex: 1 1 auto;
  min-height: 0;
  display: flex; flex-direction: column;
  transition: border-color .35s;
}

.detail .kicker {
  font-family: var(--mono); font-size: clamp(10px, 1.1cqi, 13px);
  letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--accent-live, var(--on-surface-dim));
  margin-bottom: 9px; flex: 0 0 auto;
}
.detail h2 {
  font-family: var(--disp); font-weight: 600;
  font-size: clamp(18px, 4.6cqi, 46px);
  letter-spacing: -.5px; margin: 0 0 14px; line-height: 1.12; flex: 0 0 auto;
}

/* one scroll region: short read, rule, long read */
.detail .scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: 8px;
  scrollbar-width: thin; scrollbar-color: var(--outline) transparent;
}
.detail .scroll::-webkit-scrollbar { width: 4px; }
.detail .scroll::-webkit-scrollbar-thumb { background: var(--outline); border-radius: 4px; }

/* No fixed character cap — the text fills whatever width the splitter gives it.
   Line length is held steady by scaling the type with the column instead.
   The ratio matters: chars-per-line ≈ 2 / (cqi factor), so 2.7cqi holds the
   measure near 70 characters whether the rail is 500px or 1200px wide. */
.detail .body {
  font-size: clamp(14px, 2.7cqi, 30px); line-height: 1.58;
  color: var(--on-surface); margin: 0; white-space: pre-wrap;
}
.detail .body::after {
  content: '▍'; color: var(--accent-live, var(--skl)); opacity: var(--caret, 0);
}
.detail .rule {
  height: 1px; background: var(--outline-soft); margin: 20px 0;
}
.detail .long {
  font-size: clamp(13px, 2.4cqi, 27px); line-height: 1.68;
  color: var(--on-surface-var); margin: 0; white-space: pre-wrap;
}
.detail .long strong { color: var(--on-surface); font-weight: 600; }
.detail .foot-note {
  font-family: var(--mono); font-size: clamp(10px, 1.05cqi, 12.5px);
  color: var(--on-surface-dim); margin-top: 16px; line-height: 1.7;
}

/* ---------------- inline looping clip ----------------
   Silent, autoplaying, repeating. Shows a thing instead of describing it. */

.clip { margin: 0 0 18px; }
.clip video, .clip img {
  width: 100%; display: block;
  border: 1px solid var(--outline);
  border-radius: 14px;
  background: var(--surface-c);
}
.clip figcaption {
  font-family: var(--mono); font-size: clamp(10px, 1.05cqi, 12px);
  color: var(--on-surface-dim);
  margin-top: 9px; line-height: 1.5;
}

/* ---------------- embedded demo video ----------------
   Click-to-load facade: a thumbnail until you press play, then the real
   player. Embedding an iframe on every node would pull ~1MB of YouTube
   script and set third-party cookies before anyone asked to watch. */

.video { margin-top: 20px; }
.video:empty { margin-top: 0; }

.vfacade {
  position: relative; display: block; width: 100%;
  aspect-ratio: 16 / 9;
  padding: 0; border: 1px solid var(--outline); border-radius: 14px;
  overflow: hidden; background: var(--surface-c); cursor: pointer;
  transition: border-color .25s;
}
.vfacade:hover { border-color: var(--accent-live, var(--skl)); }
.vfacade img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: .78; transition: opacity .3s, transform .5s cubic-bezier(.2,.8,.2,1);
}
.vfacade:hover img { opacity: 1; transform: scale(1.03); }

.vplay {
  position: absolute; inset: 0; margin: auto;
  width: 58px; height: 58px; border-radius: 50%;
  background: rgba(14,15,19,.66);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center;
  transition: background .25s, transform .25s;
}
.vfacade:hover .vplay { background: rgba(14,15,19,.85); transform: scale(1.07); }
.vplay svg { margin-left: 3px; }

.vcap {
  position: absolute; left: 12px; bottom: 10px;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .4px;
  color: #fff; text-shadow: 0 1px 8px rgba(0,0,0,.9);
}

.video iframe {
  width: 100%; aspect-ratio: 16 / 9;
  border: 0; border-radius: 14px; display: block;
}

/* outbound links to things hosted elsewhere */
.golinks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; flex: 0 0 auto; }
.golinks:empty { margin-top: 0; }
.golink {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--disp); font-weight: 500;
  font-size: clamp(12.5px, 1.35cqi, 15.5px);
  padding: 7px 13px; border-radius: 10px;
  border: 1px solid var(--outline); background: var(--surface-c);
  text-decoration: none; opacity: 0; transform: translateY(4px);
}
.golink:hover { background: var(--surface-c-high); }
.golink .arr { font-size: 11px; opacity: .75; }

/* the filled one — the action you'd most like a visitor to take */
.golink.primary { font-weight: 600; }
.golink.primary:hover { filter: brightness(1.1); }
.golink.primary .arr { opacity: .6; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; flex: 0 0 auto; }
.chip {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .3px;
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--outline); color: var(--on-surface-var);
  background: var(--surface-c);
  opacity: 0; transform: translateY(4px);
}

.rail-foot { margin-top: 14px; flex: 0 0 auto; }
.links { display: flex; gap: 14px; }
.links a {
  font-family: var(--mono); font-size: 10.5px; color: var(--on-surface-dim);
  text-decoration: none; border-bottom: 1px solid transparent; padding-bottom: 2px;
}
.links a:hover { color: var(--skl); border-bottom-color: var(--skl); }

/* ---------------- stage ---------------- */

.stage { position: relative; min-width: 0; min-height: 0; }
canvas {
  display: block; width: 100%; height: 100%; cursor: default;
  touch-action: none;              /* so a drag is a drag, not a scroll */
}

/* Instrumentation. Hidden for visitors; revealed with ?lab on the URL so the
   engine can still be demonstrated without maintaining a second build. */
.lab { display: none !important; }
body.lab .lab { display: flex !important; }
body.lab .hud.lab { display: block !important; }

.hud {
  position: absolute; top: 14px; right: 16px; z-index: 4;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .4px;
  color: var(--on-surface-dim); text-align: right; line-height: 1.85;
  pointer-events: none; user-select: none;
}
.hud b { color: var(--on-surface-var); font-weight: 500; }
.hud .state { color: var(--skl); }
.hud .state.quiesced { color: var(--on-surface-dim); }

.controls {
  position: absolute; left: 14px; bottom: 14px; z-index: 4;
  display: flex; gap: 7px; align-items: center; flex-wrap: wrap;
}
.seg {
  display: flex; background: var(--surface-c); border: 1px solid var(--outline-soft);
  border-radius: 999px; padding: 3px; gap: 2px;
}
.seg button {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .5px;
  text-transform: uppercase; color: var(--on-surface-dim);
  background: none; border: none; cursor: pointer;
  padding: 6px 11px; border-radius: 999px;
  transition: background .25s, color .25s;
}
.seg button[aria-pressed="true"] { background: var(--surface-c-high); color: var(--on-surface); }
.seg button:hover { color: var(--on-surface); }

.hint {
  position: absolute; right: 16px; bottom: 14px; z-index: 4;
  font-family: var(--mono); font-size: 9.5px; color: var(--on-surface-dim);
  pointer-events: none; opacity: .75;
}

/* ---------------- responsive: still no page scroll ---------------- */

@media (max-width: 1180px) {
  #app { --rail-w: 46vw; }
}

@media (max-width: 820px) {
  /* four stacked rows: header, graph, nav strip, reading card */
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
  }
  .split { display: none; }

  .navstrip {
    order: 2;
    display: block;
    padding: 10px 12px;
    border-top: 1px solid var(--outline-soft);
    background: var(--surface);
  }

  .navselect {
    -webkit-appearance: none; appearance: none;
    width: 100%; min-height: 46px;
    padding: 0 40px 0 16px;
    border-radius: 12px;
    border: 1px solid var(--outline);
    background-color: var(--surface-c);
    color: var(--on-surface);
    font-family: var(--disp); font-weight: 600; font-size: 15px;
    letter-spacing: -.2px;
    touch-action: manipulation;
    /* chevron, drawn rather than shipped as an asset */
    background-image:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'><path d='M1 1l6 6 6-6' fill='none' stroke='%237dd3c0' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 15px center;
  }
  .navselect:focus { outline: none; border-color: var(--skl); }
  .navselect option { background: var(--surface-c); color: var(--on-surface); }
  .navselect optgroup { background: var(--surface); color: var(--on-surface-dim); }

  .topbar {
    order: 0;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 10px 14px calc(10px + env(safe-area-inset-top, 0px));
    border-bottom: 1px solid var(--outline-soft);
    background: var(--surface-c);
    min-height: 46px;
  }
  .wordmark {
    display: inline-flex; align-items: center; gap: 9px;
    text-decoration: none; color: var(--on-surface);
    font-family: var(--disp); font-weight: 600; font-size: 15px;
    letter-spacing: -.3px;
  }
  .wordmark svg { color: var(--skl); flex: 0 0 auto; }
  .topnav { display: flex; gap: 14px; }
  .topnav a {
    font-family: var(--mono); font-size: 10.5px; color: var(--on-surface-dim);
    text-decoration: none; padding: 6px 0;
  }
  .topnav a:active { color: var(--skl); }

  .stage { order: 1; }

  /* the rail is now nothing but the reading card */
  .rail {
    order: 3; border-right: none; border-top: 1px solid var(--outline-soft);
    padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0px));
    max-height: 48dvh;
    transition: max-height .42s cubic-bezier(.2, .7, .2, 1);
  }

  /* ---- reading mode ----------------------------------------------------
     At 48dvh, minus the CTA, the title and the chips, the actual scroll
     region is about an inch. This trades the graph for reading space.
     Only max-height moves: the stage sits in the 1fr row, so growing the
     rail shrinks it through the grid with nothing else to keep in sync. */

  .sheet-handle {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%; margin: 10px 0 0; padding: 9px 12px 10px;
    background: none; border: none; cursor: pointer;
    font-family: var(--mono); font-size: 10px; letter-spacing: .9px;
    text-transform: uppercase; color: var(--on-surface-dim);
    -webkit-tap-highlight-color: transparent;
    min-height: 40px;                       /* stays a comfortable tap target */
  }
  .sheet-handle .grip {
    width: 32px; height: 4px; border-radius: 999px; background: var(--outline);
    transition: background .2s, width .25s cubic-bezier(.2,.7,.2,1);
  }
  .sheet-handle:active .grip { background: var(--skl); width: 44px; }
  .sheet-handle:focus-visible { outline: 2px solid var(--skl); outline-offset: -3px; border-radius: 10px; }

  /* Pulses whenever the sheet is closed, so the handle reads as an action
     rather than a divider. It's self-limiting by design: the motion stops
     the moment the sheet opens, and at that point the reader is reading —
     movement under the text would just be noise. */
  @keyframes gripPulse {
    0%, 100% { background: var(--outline); width: 32px;
               box-shadow: 0 0 0 0 rgba(125, 211, 192, 0); }
    45%      { background: var(--skl); width: 52px;
               box-shadow: 0 0 14px 3px rgba(125, 211, 192, .45); }
  }
  @keyframes hintGlow {
    0%, 100% { color: var(--on-surface-dim); }
    45%      { color: var(--skl); }
  }
  @keyframes hintHalo {
    0%, 100% { background: rgba(125, 211, 192, 0); }
    45%      { background: rgba(125, 211, 192, .07); }
  }
  .sheet-handle       { border-radius: 12px; animation: hintHalo 2.4s ease-in-out infinite; }
  .sheet-handle .grip { animation: gripPulse 2.4s ease-in-out infinite; }
  .sheet-handle .txt  { animation: hintGlow  2.4s ease-in-out infinite; }

  /* open: hold the highlighted state, stop moving */
  body.reading .sheet-handle,
  body.reading .sheet-handle .grip,
  body.reading .sheet-handle .txt { animation: none; }

  .stage { transition: opacity .42s ease; }

  body.reading .rail    { max-height: 82dvh; }
  body.reading .stage   { opacity: .16; }
  body.reading .biz-cta { display: none; }   /* ~58px back */
  body.reading .chips   { display: none; }   /* the pills at the bottom */
  body.reading .sheet-handle .grip { width: 44px; background: var(--skl); }

  body.reading .detail            { margin-top: 6px; padding: 12px 14px; }
  body.reading .detail h2         { font-size: 16.5px; margin-bottom: 8px; }
  body.reading .detail .kicker    { margin-bottom: 6px; }
  body.reading .detail .body      { font-size: 15px; }
  body.reading .detail .long      { font-size: 14.5px; }
  .mark, .head-row, .rail-foot { display: none; }

  /* the head row goes away on mobile; this deliberately doesn't. Full-width
     pill sitting above the reading card. */
  .biz-cta {
    margin: 12px 0 0; width: 100%;
    justify-content: center; padding: 12px 16px; font-size: 14px;
  }

  .detail {
    border-radius: 14px; padding: 14px 16px;
    border-left-width: 2px; margin-top: 12px;
  }
  .detail h2 { font-size: 18px; margin-bottom: 10px; }
  .detail .body { font-size: 14.5px; }
  .detail .long { font-size: 13.5px; }
  .hint { display: none; }

  /* zoom becomes two small round buttons in the corner rather than a pill —
     the graph needs the real estate more than the label does */
  .controls { bottom: 10px; left: 10px; right: auto; gap: 6px; }
  .controls .seg {
    background: none; border: none; padding: 0; gap: 6px;
  }
  .controls .seg button {
    width: 38px; height: 38px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; font-size: 17px; line-height: 1;
    background: rgba(22,24,30,.82); border: 1px solid var(--outline-soft);
    color: var(--on-surface-var);
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  }
  .controls .seg button:active { background: var(--surface-c-high); }
  /* "Fit" is redundant on touch — double-tap resets, and the nav strip
     re-frames on every selection */
  #b-fit { display: none; }
  body.lab .seg.lab button { min-height: 40px; padding: 9px 12px; font-size: 10px;
    width: auto; height: auto; border-radius: 999px; }
}

@media (max-width: 820px) and (orientation: landscape) {
  /* phone on its side — the graph needs the height more than the text does */
  .rail { max-height: 62dvh; }
  .topbar { min-height: 40px; padding-top: 6px; padding-bottom: 6px; }
}
