/* ---- Design tokens: change the look here. ---- */
:root {
  --bg: #151517; /* a softer black */
  --fg: #fff;
  --grotesk: 'Neue Haas Grotesk Display', system-ui, sans-serif; /* weights 100 150 200 300 400 500 700 900, + italics */
  --serif: 'Cormorant Garamond', serif;                              /* a text or RSVP cell's other font (editor), weight 200 */
  --dot: 'BDot', monospace;                                      /* weights 100 200 300 400 700 800, + italics */

  --big-font: var(--grotesk);   --big-weight: 200;   --big-size: 6vmin;   /* projector */
  --small-font: var(--grotesk); --small-weight: 200; --small-size: 11vmin; /* phones */
  --label-font: var(--dot);     --label-weight: 400; --label-size: .35em;  /* thread names, relative to the text */
  --rsvp-font: var(--grotesk);  --rsvp-weight: 200;                          /* 200 = Haas 35 Thin, as everywhere */

  /* each thread's colour (the RSVP focus letter uses it); --thread-main outside forks */
  /* a phone's frame (/debug for now): an Apple Intelligence-style glow in the thread's colour, square outside, rounded inside.
     In cqmin (1% of the frame's shorter side), so it looks the same on any phone and in /debug's small copies. */
  --portal-width: .6cqmin; --portal-radius: 12cqmin; /* = debug.html's phone mockups (12% of the width); real screens: later */ --portal-glow: 2.5cqmin; --portal-soft: .2cqmin; --portal-tint: 45%; --portal-hue: 12; --portal-out: 8cqmin;
  /* width: the crisp line; glow: how far in the light reaches; soft: the line's blur; tint: white in the light shades; hue: how far the near hues stray (degrees); out: room for the blur past the edge */

  --thread-a: #ff5353; --thread-b: #69f0ae; --thread-c: #80d8fe; --thread-d: #ff80ab; /* the four button colours: ○ △ ✕ □ */
  --thread-main: var(--thread-a); /* no fork: thread A, red (so a phone joins red too) */
}

/* ---- Shared ---- */
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; }
#stage { position: fixed; inset: 0; display: grid; grid-template-columns: repeat(var(--cols, 1), 1fr); align-content: center; }
.cue { width: 100%; height: 100%; min-width: 0; overflow: hidden; }
.cue.image, .cue.video { display: block; object-fit: contain; object-position: center; } /* centred in its screen or frame */
.cue.text { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3em; text-align: center; white-space: pre-line; }
.cue { --thread: var(--thread-main); }
.cue[data-id="0"] { --thread: var(--thread-a); } /* by thread, wherever it sits */
.cue[data-id="1"] { --thread: var(--thread-b); }
.cue[data-id="2"] { --thread: var(--thread-c); }
.cue[data-id="3"] { --thread: var(--thread-d); }
.cue.rsvp { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3em; font-family: var(--rsvp-font); font-weight: var(--rsvp-weight); }
.cue[data-font=serif], .cue[data-font=serif] .body { font-family: var(--serif); } /* a cell set to serif (editor); same weight */
.rsvp .line { display: grid; grid-template-columns: 1fr auto 1fr; width: 100%; white-space: pre; }
/* the coloured letter's centre is the screen's centre; it's the letter nearest the word's middle (rsvp.js middle), so
   the word is centred to within half a letter */
.rsvp .pre { text-align: right; }
.rsvp .focus { color: var(--thread); }
.cue .label { font: var(--label-weight) var(--label-size)/1 var(--label-font); letter-spacing: .05em; text-transform: uppercase; opacity: .7; }
/* per thread: .cue[data-id="0"] … [data-id="3"]; its place: [data-lane]; inside a fork [data-lanes="2"] etc.; .cue.empty = a thread with nothing on now */

/* ---- Host (projector) ---- */
.host { font: var(--big-weight) var(--big-size)/1.2 var(--big-font); }
/* each thread is a small copy of the whole screen: 1/cols of its width, the same shape, text scaled to match */
.host .cue { height: calc(100vh / var(--cols, 1)); font-size: calc(var(--big-size) / var(--cols, 1)); }
/* projected: the screen pure black (no light past the frames), the frames themselves our black; over a film, none */
html:has(body.host), .host { background: #000; }
.host .cue { background: var(--bg); }
#film ~ #stage .cue { background: none; }
/* split: black round each frame (the same gap across and down: 2vmin between frames, 1vmin at the screen's edge),
   then its outline in its thread's colour just inside that */
.host #stage:has(> :nth-child(2)) .cue { box-sizing: border-box; border: 1vmin solid #000; outline: 2px solid var(--thread); outline-offset: calc(-1vmin - 2px); }
#film { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#panel { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px; background: #111e; font: 13px/1.6 ui-monospace, monospace; }
#panel input { width: 4em; }
#go { font-weight: bold; }
#go.ok { color: #30d158; }
#go.wait { color: #ffd60a; }
.bare #panel { display: none; }
.debug.host:not(.panel) #panel { display: none; } /* /debug's header has the controls; its "host panel" button shows this */
.bare { cursor: none; }
/* /debug only: a white line around the screen and around each thread's frame (empty ones too) */
.debug #stage { outline: 1px solid #fff; outline-offset: -1px; }
.debug.host .cue { outline: 1px solid var(--thread); outline-offset: -1px; } /* the projector: just a line, in its thread's colour */
/* a phone's frame: an Apple Intelligence-style glow in its thread's colour (thread one's before the film and
   while joining). Three rings (index.html's #portal), square outside and rounded inside, each a slowly turning
   gradient of the colour, its tint and two near hues: a crisp one at the edge, two wider ones blurred into it. */
/* the gradient turns by transform (i::before), not by an animated angle: an animated angle re-rasterises the gradient,
   its mask and the blur every frame (/debug with 8 phones: 32 → 46fps headless); a turning layer is drawn once */
@keyframes portal-turn { to { rotate: 360deg; } }
@keyframes portal-breathe { from { opacity: .55; } to { opacity: .95; } }
#portal { display: none; position: fixed; inset: 0; max-width: 500px; margin: auto; pointer-events: none; overflow: hidden;
  container-type: size; z-index: 2; --portal: var(--frame, var(--thread-a)); }
.phone.joined #portal { display: none; } /* off for now: the balls say which thread (phone.js); was block, once joined */
.phone [data-thread="main"] { --frame: var(--thread-main); }
.phone [data-thread="a"] { --frame: var(--thread-a); }
.phone [data-thread="b"] { --frame: var(--thread-b); }
.phone [data-thread="c"] { --frame: var(--thread-c); }
.phone [data-thread="d"] { --frame: var(--thread-d); }
#portal b { position: absolute; inset: 0; filter: blur(var(--blur)); }
#portal i {
  position: absolute; inset: calc(-1 * var(--portal-out)); /* past the screen, so the blur never shows an outer edge */
  --in: calc(var(--portal-out) + var(--w)); --r: var(--portal-radius);
  /* the ring: everything, minus a rounded rectangle (two bars and four corner circles) */
  mask: linear-gradient(#000 0 0),
    linear-gradient(#000 0 0) center / calc(100% - 2 * var(--in)) calc(100% - 2 * var(--in) - 2 * var(--r)) no-repeat,
    linear-gradient(#000 0 0) center / calc(100% - 2 * var(--in) - 2 * var(--r)) calc(100% - 2 * var(--in)) no-repeat,
    radial-gradient(circle var(--r) at calc(var(--in) + var(--r)) calc(var(--in) + var(--r)), #000 99%, #0000),
    radial-gradient(circle var(--r) at calc(100% - var(--in) - var(--r)) calc(var(--in) + var(--r)), #000 99%, #0000),
    radial-gradient(circle var(--r) at calc(var(--in) + var(--r)) calc(100% - var(--in) - var(--r)), #000 99%, #0000),
    radial-gradient(circle var(--r) at calc(100% - var(--in) - var(--r)) calc(100% - var(--in) - var(--r)), #000 99%, #0000);
  mask-composite: exclude, add, add, add, add, add, add;
}
/* the gradient: a square that covers the ring at any turn, centred where the gradient's centre was */
#portal i::before { content: ''; position: absolute; left: 50%; top: 50%; width: calc(150cqmax + 3 * var(--portal-out)); aspect-ratio: 1; translate: -50% -50%;
  background: conic-gradient(var(--portal), color-mix(in oklch, var(--portal), white var(--portal-tint)),
    oklch(from var(--portal) l c calc(h + var(--portal-hue))), var(--portal), color-mix(in oklch, var(--portal), white var(--portal-tint)),
    oklch(from var(--portal) l c calc(h - var(--portal-hue))), var(--portal));
  animation: portal-turn var(--spin) linear infinite var(--dir, normal);
}
#portal b:nth-child(1) { --blur: var(--portal-soft); }        #portal b:nth-child(1) i { --w: var(--portal-width); --spin: 7s; }
#portal b:nth-child(2) { --blur: calc(var(--portal-glow) / 4); } #portal b:nth-child(2) i { --w: calc(var(--portal-glow) / 3); --spin: 11s; --dir: reverse; }
#portal b:nth-child(3) { --blur: calc(var(--portal-glow) / 1.5); animation: portal-breathe 2.6s ease-in-out infinite alternate; }
#portal b:nth-child(3) i { --w: var(--portal-glow); --spin: 16s; }

/* ---- Phone (every listener) ---- */
.phone { font: var(--small-weight) var(--small-size)/1.2 var(--small-font); }
.phone #stage { max-width: 500px; margin: auto; grid-template-rows: 100%; } /* the one cue fills the screen (else its row is the video's own height and it sits wherever that lands) */ /* a laptop that joins as a listener gets the phone column */
#join { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; font-size: 16px; }
#join button { font: 400 24px var(--dot); color: var(--fg); background: none; border: 0; padding: 0; } /* "join": just the word */
#msg { font: 400 24px var(--dot); color: #888; }
#msg.joined { color: var(--fg); }
#count { font-family: var(--dot); }
#count, #msg small { display: block; font-size: 14px; opacity: .5; } /* how many phones have joined (phone.js) */
/* which thread this phone is on (threads.js): metaballs just above the words */
#threads { position: fixed; top: 30%; /* phone.js moves it to just above the words */ transition: top .4s ease; left: 0; right: 0; margin: auto; /* no transform: keeps text on whole pixels */
  width: min(80vw, 400px); height: min(40vw, 200px); /* = 4 balls across, 2 rows down (threads.js) */ z-index: 1; display: none; }
#threads svg { position: absolute; inset: 0; width: 100%; height: 100%; }
#threads span { position: absolute; font: 400 1em/1 var(--dot); white-space: pre; color: #fff; } /* placed and coloured by threads.js */
.host #threads { display: block; top: calc(50vh - 12.2vmin); width: 53.1vmin; height: 24.4vmin; } /* balls 4.8 radii apart (host.js APART), the same size: 3.125vmin radius */ /* the projector: the balls in the screen's centre (host.js lifts one thread's ball above the words) */
.host .cue .label { display: none; } /* the projector names its threads with the balls instead */
.bare #note { display: none; } /* H: no debug info (live.js hideWithH) */
#note { position: fixed; bottom: 8px; width: 100%; text-align: center; font: 200 12px var(--grotesk); opacity: .5; }
