/* ═══════════════════════════════════════════════════════════════════════════
   VISI'S ROOM: the gaming nook from the Visigames app, Visi playing at the
   TV, the reader saying hi (scripts/studio/room.js, scripts/studio/tv.js).

     .visi__nook   the room, in points, behind everything the pinned screen
                   shows; its camera puts the TV's screen where `.visi__tv`
                   is, so the TV is wherever this sheet puts it
     .visi__tv     the TV's screen: Visi's game as the game draws it, on the
                   GPU (`.visi__game`), with the game's HUD over it
                   (`.visi__hud`), seated in the TV's bezel and lighting the
                   wall round it; where the GPU cannot draw it, the game as
                   a grid of points; coming on like a screen the first time
                   it is seen
     .visi__hit    Visi, as a button: placed over Visi every frame by the
                   script; saying hi
     .visi__say    Visi's line, over its head, placed every frame by the
                   script
     .visi__body   Visi, the app's own model, over the nook and in front of
                   the TV, drawn through the same camera
     .visi__mind   Visi's mind: its network seen working (`.visi__net`),
                   the same in words for a screen reader (what it sees,
                   imagines, chooses and does), what a reader can ask of
                   it, and its brain's numbers; a hand on the TV draws a
                   route or drops a crate

   On a desk the words stand on the left and the TV on the right, the PLAY
   sign over it and Visi at the console under it; on a phone the TV is the
   window's width under the words, the sign between them, Visi on the rug
   under it, to its hips, and Visi's mind under Visi.
   ═════════════════════════════════════════════════════════════════════════ */

/* Positioned (styles/portfolio.css: relative, or sticky in the handoff), so
   what the script places is placed in it. */
.visi .work-pin {
  --tv: 100%;
  isolation: isolate;
  min-height: 100svh;
  box-sizing: border-box;
}
.visi__nook {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
/* Visi, as the app draws it, over the nook and in front of the TV, as it
   stands in the room; under the words and what a hand finds. */
.visi__body {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.visi__tv {
  position: relative;
  width: var(--tv);
  aspect-ratio: 16 / 9;
  margin: 38vw auto 0;
  border-radius: 3px;
  overflow: hidden;
  container-type: inline-size;
  background: #05070c;
}
.visi__tv canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.visi__game { visibility: hidden; }
.visi__tv.is-3d .visi__game { visibility: visible; }
.visi__tv.is-3d canvas:not(.visi__game) { visibility: hidden; }
/* The points' screen: a faint row structure and the glass's curve of light. */
.visi__tv::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px),
    radial-gradient(120% 90% at 50% 40%, rgba(255, 255, 255, 0.05), transparent 60%, rgba(0, 0, 0, 0.35));
}
/* The game's screen: seated in the bezel (a hairline of its black, the
   panel's inner shadow) and lighting the wall round it in the sky's blue. */
.visi__tv.is-3d {
  box-shadow: 0 0 34px -6px rgba(120, 190, 255, 0.34), 0 0 140px 6px rgba(70, 150, 240, 0.12);
}
.visi__tv.is-3d::after {
  background: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.75), inset 0 0 14px rgba(0, 0, 0, 0.42), inset 0 1px 0 1px rgba(255, 255, 255, 0.03);
}

/* The game's HUD (Tiltit's GameplayHUD): chips of deep navy with a hairline
   edge, rounded heavy figures; the pause and the clock at the top left, the
   parcel's integrity and the deliveries at the top right, the house gold.
   Sized to the screen, not the page. Only over the game as the game draws
   it. */
.visi__hud { display: none; }
.visi__tv.is-3d .visi__hud {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 2.2cqw 2.6cqw;
  pointer-events: none;
  font: 800 2.15cqw/1 ui-rounded, "SF Pro Rounded", "Nunito", var(--font-ui);
  font-variant-numeric: tabular-nums;
  color: #fff;
  letter-spacing: 0.01em;
}
.visi__hud-side { display: flex; flex-direction: column; align-items: flex-end; gap: 1.1cqw; }
.visi__chip {
  display: inline-flex;
  align-items: center;
  gap: 0.9cqw;
  padding: 1.05cqw 1.7cqw;
  border-radius: 999px;
  background: rgba(9, 15, 41, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 0.4cqw 1.4cqw -0.4cqw rgba(9, 15, 41, 0.6);
  white-space: nowrap;
}
.visi__chip b { font-weight: inherit; }
.visi__glyph { width: 1.6cqw; height: 1.6cqw; fill: #fff; flex: none; }
.visi__glyph--parcel { fill: #4fe5ff; }
.visi__glyph-line { fill: none; stroke: rgba(9, 15, 41, 0.75); stroke-width: 1.1; stroke-linejoin: round; }
.visi__glyph--house { fill: #ffcc40; }
.visi__chip--done { transition: box-shadow 0.3s var(--ease-ui), background 0.3s var(--ease-ui); }
.visi__chip--done.is-done {
  background: rgba(64, 44, 6, 0.85);
  box-shadow: inset 0 0 0 1px rgba(255, 204, 64, 0.7), 0 0 2.4cqw -0.2cqw rgba(255, 204, 64, 0.55);
  animation: visi-done 0.5s var(--ease-ui);
}
@keyframes visi-done { 0% { transform: scale(1); } 40% { transform: scale(1.14); } 100% { transform: scale(1); } }
/* Learning: the generation, at the TV's foot, while it learns. */
.visi__chip--learn {
  position: absolute;
  left: 2.6cqw;
  bottom: 2.2cqw;
  color: #ffcc40;
  opacity: 0;
  transition: opacity 0.25s var(--ease-ui);
}
.visi.is-learning .visi__chip--learn { opacity: 1; }
/* Paused while Visi talks: the game's pause, over the greyed game. */
.visi__chip--paused {
  position: absolute;
  left: 50%;
  top: 50%;
  gap: 1.2cqw;
  padding: 1.6cqw 2.8cqw;
  font-size: 2.8cqw;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.92);
  transition: opacity 0.25s var(--ease-ui), transform 0.35s var(--ease-ui);
}
.visi__chip--paused .visi__glyph { width: 2.2cqw; height: 2.2cqw; }
.visi__tv.is-paused .visi__chip--paused { opacity: 1; transform: translate(-50%, -50%); }
/* It comes on like a CRT the first time it is seen: a bright line opening
   into the picture. */
.visi.tv-on .visi__tv canvas { animation: visi-tv-on 0.6s var(--ease-ui) both; }
@keyframes visi-tv-on {
  0% { transform: scale(0.7, 0.006); filter: brightness(4); }
  45% { transform: scale(1, 0.012); filter: brightness(3); }
  100% { transform: none; filter: none; }
}

/* A hand on the TV draws Visi a route, or drops a crate; a finger scrolls
   the page over it until *Draw a route* is on. */
.visi.has-brain .visi__tv { touch-action: pan-y; cursor: crosshair; }
.visi__tv.is-drawing { touch-action: none; box-shadow: 0 0 0 2px rgba(99, 216, 255, 0.55), 0 0 34px -6px rgba(120, 190, 255, 0.34); }

/* Visi's mind, in words: four lines, each a beat of a thought. Over the
   button that finds Visi (which covers everywhere Visi moves), so its own
   buttons take the hand wherever the two meet. */
.visi__mind {
  position: relative;
  z-index: 3;
  max-width: min(100%, 580px);
  margin-top: clamp(18px, 2.6vw, 30px);
}
/* Its network, seen working: a dark glass the light of its connections is
   added on, and its thought in a line under it. Drawn only where the
   script draws it; otherwise the four lines in words stand in for it. */
.visi__net { position: relative; display: none; margin: 0; }
.visi.has-net .visi__net { display: block; }
.visi__net-canvas {
  display: block;
  width: 100%;
  height: clamp(176px, 13.5vw, 212px);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  background: radial-gradient(120% 90% at 40% 50%, rgba(18, 30, 58, 0.55), rgba(4, 7, 15, 0.7));
}
/* Over it: which of its two networks is drawn, and what the stick's marks
   are (the instinct's; the judgment draws a gauge). Under it: its twenty
   futures, then the thought in a line. */
.visi__net-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.visi__net-tabs { display: flex; gap: 4px; }
.visi__net-tab {
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: transparent;
  color: rgba(234, 243, 255, 0.6);
  font: 500 9.5px/1 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}
.visi__net-tab[aria-selected="true"] { border-color: rgba(99, 216, 255, 0.7); background: rgba(99, 216, 255, 0.14); color: var(--bone); }
.visi__net-tab[data-net-tab="value"][aria-selected="true"] { border-color: rgba(185, 164, 255, 0.75); background: rgba(185, 164, 255, 0.14); }
.visi__net-tab:focus-visible { outline: 2px solid var(--signal-hot); outline-offset: 2px; }
.visi[data-net="value"] .visi__net-key { visibility: hidden; }
.visi__futures { display: block; width: 100%; height: 46px; margin-top: 6px; touch-action: pan-y; }
html.has-cursor .visi__futures { cursor: crosshair; }
.visi__net-under { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-top: 8px; }
/* Open to inspection: a hand on it holds the moment; a finger scrolls the
   page over it, and a tap holds it. */
.visi__net-canvas { touch-action: pan-y; }
/* Over it, the system's crosshair, exact, in place of the page's drawn
   cursor, which would cover what is being looked at. */
html.has-cursor .visi__net-canvas { cursor: crosshair; }
html.is-inspecting .cursor { visibility: hidden; }
.visi__net-canvas:focus { outline: none; }
.visi__net-canvas:focus-visible { outline: 2px solid var(--signal-hot); outline-offset: 2px; }
.visi__net-canvas.is-held { border-color: rgba(255, 204, 64, 0.35); }
/* What is under the hand, said: a dark box beside it, its name, then what it is and its numbers. */
.visi__net-tip {
  position: absolute;
  z-index: 2;
  left: 0;
  top: 0;
  width: max-content;
  max-width: min(272px, 100%);
  box-sizing: border-box;
  padding: 9px 11px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: #060a14;
  box-shadow: 0 12px 30px -14px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}
.visi__net-tip[hidden] { display: none; }
.visi__net-tip-title { margin: 0 0 6px; font: 500 10px/1.35 var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; color: #ffcc40; }
.visi__net-tip dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 10px; margin: 0; }
.visi__net-tip dl > div { display: contents; }
.visi__net-tip dt { font: 500 9.5px/1.5 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; color: rgba(234, 243, 255, 0.5); }
.visi__net-tip dd { margin: 0; font: 400 12px/1.45 var(--font-ui); font-variant-numeric: tabular-nums; color: rgba(234, 243, 255, 0.92); }
.visi__net-line { min-height: 1.45em; font: 400 13.5px/1.45 var(--font-ui); color: rgba(234, 243, 255, 0.88); }
.visi__net-key { flex: none; font: 500 9.5px/1 var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; color: rgba(234, 243, 255, 0.5); white-space: nowrap; }
.visi__net-key i { display: inline-block; width: 7px; height: 7px; margin: 0 5px 0 10px; border-radius: 50%; vertical-align: -0.5px; }
.visi__net-own { border: 1.3px solid rgba(99, 216, 255, 0.75); box-sizing: border-box; }
.visi__net-pick { background: #ffcc40; }
/* With the network drawn, the words are for a screen reader. */
.visi.has-net .visi__thought {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.visi__thought { display: grid; gap: 7px; margin: 0; font: 400 13.5px/1.45 var(--font-ui); }
.visi__thought > div { display: grid; grid-template-columns: 6.4em minmax(0, 1fr); gap: 12px; align-items: baseline; }
.visi__thought dt { font: 500 10px/1 var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--signal-hot); }
.visi__thought dd { margin: 0; min-height: 1.45em; color: rgba(234, 243, 255, 0.88); }
.visi__ask { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.visi__btn {
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(9, 15, 41, 0.6);
  color: var(--bone);
  font: 500 10.5px/1 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s var(--ease-ui), background 0.2s var(--ease-ui);
}
.visi__btn:hover { border-color: rgba(99, 216, 255, 0.6); }
.visi__btn[aria-pressed="true"] { border-color: rgba(99, 216, 255, 0.8); background: rgba(99, 216, 255, 0.16); }
.visi__btn:focus-visible { outline: 2px solid var(--signal-hot); outline-offset: 2px; }
/* The one that starts it all over: lit, so it reads as the way in. */
.visi__btn--teach { border-color: rgba(99, 216, 255, 0.55); background: rgba(99, 216, 255, 0.1); }
/* Under a finger the pills are too short to aim at: the two tabs are 22px
   tall and the five challenges 33, against the 44 a fingertip covers. The
   pills keep their size, which is fitted to the panel; what a finger can
   land on grows round each one, 11px above and below a tab and 6px above and
   below a challenge (the insets are measured from inside the 1px border, so
   each is one more), and the challenges' rows open by as much so no two
   areas overlap. Where the pointer is a mouse nothing changes. */
@media (pointer: coarse) {
  .visi__net-tab, .visi__btn { position: relative; }
  .visi__net-tab::after, .visi__btn::after { content: ""; position: absolute; }
  .visi__net-tab::after { inset: -12px -3px; }
  .visi__btn::after { inset: -7px -5px; }
  .visi__ask { row-gap: 12px; }
}
/* Learning from scratch: a line, and the curve of how much each generation delivered. */
.visi__learn { margin-top: 14px; }
.visi__learn[hidden] { display: none; }
.visi__learn-line { margin: 0; font: 400 12.5px/1.5 var(--font-ui); color: rgba(234, 243, 255, 0.82); }
.visi__learn-curve { display: block; width: 100%; max-width: 360px; height: 44px; margin-top: 8px; }
/* Until Visi's brain is there, there is nothing to ask. */
.visi:not(.has-brain) .visi__ask { opacity: 0.4; pointer-events: none; }
.visi__brain { margin: 16px 0 0; font: 400 12px/1.55 var(--font-ui); color: rgba(234, 243, 255, 0.5); }
.visi__brain:empty { display: none; }

/* What is on Visi's TV, in words: the game, the count, and when it waits. */
.visi__now {
  margin: 14px 0 0;
  font: 500 11px/1.4 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(234, 243, 255, 0.55);
}
.visi__now:empty { display: none; }

.visi__hit {
  position: absolute;
  z-index: 2;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  padding: 0;
  border: 0;
  border-radius: 42% 42% 30% 30%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.visi__hit:focus-visible {
  outline: 2px solid var(--signal-hot);
  outline-offset: -6px;
  box-shadow: 0 0 40px -8px rgba(99, 216, 255, 0.6);
}

.visi__say {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  max-width: min(28ch, 70vw);
  margin: 0;
  padding: 11px 15px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(8, 12, 22, 0.88);
  box-shadow: 0 14px 40px -16px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 140, 210, 0.08) inset;
  color: var(--bone);
  font: 400 14px/1.45 var(--font-ui);
  pointer-events: none;
  transform-origin: 50% 100%;
  transform: translate(var(--say-x, 0), var(--say-y, 0)) translate(-50%, calc(-100% - 10px)) scale(0.94);
  opacity: 0;
  transition: opacity 0.2s var(--ease-ui), transform 0.28s var(--ease-ui);
}
/* Who is talking, in Visi's colours (the app's pink, lavender and sky). */
.visi__say::before {
  content: "Visi";
  display: block;
  margin-bottom: 3px;
  font: 500 10px/1 var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  background: linear-gradient(90deg, #ff8cd2, #b9a4ff, #7fd4ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
/* Its tail, toward Visi. */
.visi__say::after {
  content: "";
  position: absolute;
  left: calc(50% + var(--say-tail, 0px));
  bottom: -6px;
  width: 11px;
  height: 11px;
  margin-left: -6px;
  border-right: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(8, 12, 22, 0.88);
  transform: rotate(45deg);
}
.visi__say.is-on {
  opacity: 1;
  transform: translate(var(--say-x, 0), var(--say-y, 0)) translate(-50%, calc(-100% - 10px));
}

@media (min-width: 901px) {
  .visi .work-pin {
    /* As wide as the window allows, and short enough for the window's
       height to hold the PLAY sign over the TV and Visi under it, from its
       head to the controller in its hands (about 2.8 of the TV’s heights
       in all, under the bar). */
    --tv: clamp(380px, min(40vw, (100svh - 96px) * 0.64), 600px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--tv);
    column-gap: clamp(28px, 4vw, 72px);
    align-content: start;
    padding-inline: var(--pad-section);
  }
  .visi .work-pin > .section-intro { grid-column: 1; grid-row: 1; padding-inline: 0; }
  .visi__tv { grid-column: 2; grid-row: 1 / span 2; align-self: start; margin: calc(var(--tv) * 0.3) 0 0; }
  .visi__mind { grid-column: 1; grid-row: 2; align-self: start; }
}

/* On a phone the words of Visi's mind come under the TV, so the TV stands
   where the handoff lands on it. */
@media (max-width: 900px) {
  .visi .work-pin { display: flex; flex-direction: column; }
  /* Under the TV and under Visi, who sits on the rug below it, down to
     its hips (its legs dissolve: about four fifths of the TV's width, so
     the gap is that); over the room, so on a pane of the dark. */
  .visi__mind {
    order: 3;
    margin: 84vw var(--pad-section) 24px;
    padding: 16px 16px 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    background: rgba(5, 8, 16, 0.86);
  }
  .visi__tv { order: 2; }
}

@media (prefers-reduced-motion: reduce) {
  .visi.tv-on .visi__tv canvas { animation: none; }
  .visi__chip--done.is-done { animation: none; }
  .visi__chip--paused { transition: opacity 0.2s linear; transform: translate(-50%, -50%); }
  .visi__say { transition: opacity 0.2s linear; transform: translate(var(--say-x, 0), var(--say-y, 0)) translate(-50%, calc(-100% - 10px)); }
}

/* ── where nothing is drawn: the words alone ───────────────────────────── */
@media (forced-colors: active) {
  .visi__nook, .visi__body, .visi__tv, .visi__hit, .visi__say, .visi__mind { display: none; }
}
@media print {
  .visi__nook, .visi__body, .visi__tv, .visi__hit, .visi__say, .visi__mind { display: none; }
}
@media (scripting: none) {
  .visi__tv, .visi__hit, .visi__say, .visi__mind { display: none; }
}
