/* 5.41 Studio — shell: load sequence (boot + fly-in clip), montage layer, HOME = Big Six, HUD bars,
   frame lines, nav card, screens. Uses only the tokens from base.css.
   Layers (z-index): hero 0 · main 1 · frame 40 · nav 44 · screens 45 · page overlays 46-49 · HUD 50 ·
   fly-in clip 90 · boot 100 */

:root {
  --gr-top: calc(var(--hud-h) + env(safe-area-inset-top, 0px));      /* height of the top bar */
  --gr-bottom: calc(var(--hud-h) + env(safe-area-inset-bottom, 0px)); /* height of the bottom bar */
}

html { scrollbar-gutter: stable; }  /* no layout shift when scroll is locked (boot, screens) */
html.gr-boot-lock, html.gr-screen-open { overflow: hidden; }

/* Lenis (desktop smooth scroll; shell.js only adds the class when it is active) */
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }
.lenis.lenis-smooth [data-lenis-prevent] { overscroll-behavior: contain; }
.lenis.lenis-stopped { overflow: hidden; }
.lenis.lenis-smooth:not(.lenis-stopped) iframe { pointer-events: none; }

/* ---------- Montage layer ----------
   #gr-hero is fixed and full-bleed; the chapters scroll over it. The scrim keeps the Big Six readable. */
#gr-hero { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: #000; pointer-events: none; }
.gr-hero-box { position: absolute; inset: 0; }
.gr-hero-in { position: absolute; inset: 0; transform: scale(1.1); transform-origin: 50% 50%; will-change: transform; backface-visibility: hidden; }
.gr-hero-in video { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; }
.gr-hero-box::after { content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, .55); } /* flat scrim, no gradient */

/* ---------- Main ---------- */
#gr-main { position: relative; z-index: 1; outline: none; }
body.gr-booting #gr-main { visibility: hidden; }
.gr-chapter { position: relative; display: block; }
.gr-page-err { padding: var(--gutter); color: var(--dim); font-family: var(--font-mono); font-size: var(--step-osd); letter-spacing: .06em; text-transform: uppercase; }
#gr-story { position: relative; background: #000; }

/* ---------- HOME = Big Six ----------
   A compact camera-display panel (16:10) centred over the dimmed montage: status strip, 3 x 2 cells
   split by hairlines, soft-key row. .gr-six is the panel's box (boot.js measures it); .gr-six-in is
   the LCD (fill, border, scroll-away motion). The lens ruler sits thin on the viewport's bottom edge. */
#gr-open {
  --six-w: min(680px, calc(100vw - 32px), max(440px, calc((100svh - 96px) * 1.6)));
  position: relative; height: 100vh; height: 100svh; min-height: 400px; overflow: hidden;
}
.gr-six { position: absolute; inset: 0; margin: auto; width: var(--six-w); height: calc(var(--six-w) * .625); }
.gr-six-in {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: rgba(18, 18, 18, .86); border: 1px solid var(--line);
  will-change: transform, opacity;
}

/* status strip */
.gr-six-top { flex: 0 0 28px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 10px; border-bottom: 1px solid var(--line); }
.gr-six-brand { margin: 0; padding-top: 1px; font-size: 19px; line-height: 1; letter-spacing: .01em; color: #fff; white-space: nowrap; }
.gr-six-stat { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 10px; line-height: 1; color: var(--ink); white-space: nowrap; }
.gr-six-tc { order: 1; letter-spacing: .06em; }
.gr-six-stby { order: 2; color: var(--dim); }
.gr-six-stat .gr-hud-dot { order: 3; width: 5px; height: 5px; }

/* 3 x 2 cells, hairlines only */
.gr-six-grid { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }
.gr-six-box {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 0; min-height: 0; padding: 12px 6px 0; border: 0 solid var(--line);
  text-decoration: none; color: var(--ink); -webkit-tap-highlight-color: transparent;
}
.gr-six-box:not(:nth-child(3n)) { border-right-width: 1px; }
.gr-six-box:nth-child(-n+3) { border-bottom-width: 1px; }
.gr-six-box:focus, .gr-six-box:focus-visible { outline: none; }  /* the amber selection is the focus indicator */
.gr-six-box.is-sel, .gr-six-box.is-sel:focus-visible { outline: 1px solid var(--amber); outline-offset: -1px; }
.gr-six-lab { position: absolute; left: 8px; top: 7px; display: flex; gap: 6px; font-size: 10px; line-height: 1; color: var(--dim); white-space: nowrap; }
.gr-six-box.is-sel .gr-six-lab { color: var(--amber); }
.gr-six-val { margin: 0; font-size: 34px; line-height: .9; color: #fff; white-space: nowrap; font-variant-numeric: tabular-nums; }
.gr-six-sub { margin-top: 8px; font-size: 10px; line-height: 1; color: var(--dim); white-space: nowrap; }

/* soft-key row */
.gr-six-keys { flex: 0 0 26px; display: flex; align-items: stretch; border-top: 1px solid var(--line); font-size: 10px; line-height: 1; color: var(--dim); }
.gr-six-keys > * { flex: 1 1 0; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 0; letter-spacing: .08em; white-space: nowrap; }
.gr-six-cue { font-size: 10px; color: var(--dim); }
.gr-six-cue:hover, .gr-six-cue:focus-visible { color: var(--amber); }
.gr-six-cue:focus-visible { outline-offset: -3px; }

/* lens focus-distance scale: thin, on the bottom edge; slides sideways as the page scrolls */
.gr-ruler { position: absolute; left: 5vw; width: 90vw; bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); height: 22px; pointer-events: none; will-change: transform; }
.gr-rl-t { position: absolute; bottom: 0; width: 1px; height: 3px; background: rgba(236, 235, 231, .28); }
.gr-rl-t.is-mid { height: 5px; background: rgba(236, 235, 231, .4); }
.gr-rl-t.is-major { height: 8px; background: rgba(236, 235, 231, .6); }
.gr-rl-n { position: absolute; bottom: 11px; transform: translateX(-50%); font: 500 9px/1 var(--font-mono); letter-spacing: .06em; color: var(--dim); }
.gr-rl-ft { transform: translateX(-100%); }
.gr-ruler-ptr { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); width: 1px; height: 14px; background: var(--amber); pointer-events: none; }

/* phones: full width minus gutters, 2 x 3, big touch cells (>= 64px), fits the first viewport */
@media (max-width: 600px) {
  #gr-open { --six-w: calc(100vw - 32px); }
  .gr-six { height: min(336px, calc(100svh - 120px)); }
  .gr-six-top { padding: 0 8px; }
  .gr-six-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(64px, 1fr)); }
  .gr-six-grid .gr-six-box:nth-child(n) { border-width: 0; }
  .gr-six-grid .gr-six-box:nth-child(2n+1) { border-right-width: 1px; }
  .gr-six-grid .gr-six-box:nth-child(-n+4) { border-bottom-width: 1px; }
  .gr-six-val { font-size: 26px; }
  .gr-six-keys { flex-basis: 30px; font-size: 9px; }
  .gr-six-cue { font-size: 9px; }
  .gr-rl-n:nth-of-type(even) { display: none; }
}

/* load-sequence hand-off: the panel dives in from the camera screen (zoom + de-blur) */
body.gr-dive .gr-six { animation: gr-dive var(--dive-ms, 600ms) cubic-bezier(.16, 1, .3, 1) both; will-change: transform, filter, opacity; }
body.gr-dive-clip { --dive-ms: 420ms; --dive-s: 1.06; --dive-b: 10px; }
body.gr-dive-fall { --dive-ms: 600ms; --dive-s: 1.25; --dive-b: 18px; }
body.gr-dive-skip { --dive-ms: 340ms; --dive-s: 1.12; --dive-b: 8px; }
@keyframes gr-dive {
  from { transform: scale(var(--dive-s, 1.25)); filter: blur(var(--dive-b, 18px)); opacity: 0; }
  45% { opacity: 1; }
  to { transform: scale(1); filter: blur(0); opacity: 1; }
}
/* then the cells cut in like firmware, one by one */
body.gr-six-draw .gr-six-box { animation: gr-step-in 120ms steps(2, end) both; animation-delay: calc(60ms + var(--i, 0) * 60ms); }
body.gr-six-draw .gr-six-top, body.gr-six-draw .gr-six-keys { animation: gr-step-in 120ms steps(2, end) 40ms both; }
body.gr-six-draw .gr-ruler, body.gr-six-draw .gr-ruler-ptr { animation: gr-step-in 300ms steps(4, end) 420ms both; }
@keyframes gr-step-in { from { opacity: 0; } }

/* ---------- HUD bars ---------- */
#gr-hud-top, #gr-hud-bottom {
  position: fixed; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
  color: var(--ink);
  font-family: var(--font-mono); font-size: var(--step-osd); line-height: 1;
  letter-spacing: .06em; text-transform: uppercase; font-variant-numeric: tabular-nums;
  user-select: none; -webkit-user-select: none;
}
/* top bar: transparent over the opening, solid once you scroll (--bar 0..1 set by shell.js) */
#gr-hud-top {
  --bar: 0;
  top: 0; height: var(--gr-top); padding-top: env(safe-area-inset-top, 0px);
  background: rgba(0, 0, 0, calc(.86 * var(--bar)));
  border-bottom: 1px solid rgba(236, 235, 231, calc(.22 * var(--bar)));
}
#gr-hud-bottom {
  bottom: 0; height: var(--gr-bottom); padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(0, 0, 0, .86); border-top: 1px solid var(--line);
  opacity: 0; visibility: hidden;
}
#gr-hud-top { visibility: hidden; opacity: 0; }  /* shell.js reveals it once the Big Six has scrolled away */
#gr-frame { opacity: 0; }
body.gr-booting #gr-hud-top, body.gr-booting #gr-hud-bottom, body.gr-booting #gr-frame { visibility: hidden; }
/* screens are full OSD */
html.gr-screen-open #gr-hud-top { --bar: 1 !important; opacity: 1 !important; visibility: visible !important; }
html.gr-screen-open #gr-hud-bottom { opacity: 1 !important; visibility: visible !important; }

.gr-hud-grp { display: flex; align-items: center; gap: 14px; min-width: 0; white-space: nowrap; }
.gr-hud-l { flex: 0 0 auto; }
.gr-hud-m { flex: 1 1 auto; justify-content: center; gap: 18px; overflow: hidden; color: var(--dim); }
.gr-hud-r { flex: 0 0 auto; margin-left: auto; gap: 12px; }

.gr-hud-p { text-transform: none; } /* 23.98p, s709 keep their real casing */
.gr-hud-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); flex: 0 0 auto; }
.gr-hud-stby { color: var(--dim); }
.gr-hud-tc { color: var(--ink); font-size: calc(var(--step-osd) + 1px); letter-spacing: .08em; }
.gr-hud-mode { color: var(--ink); }

.gr-menu-btn {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  height: 20px; padding: 0 8px; border: 1px solid var(--line); color: var(--ink);
  font: inherit; letter-spacing: inherit; text-transform: inherit; -webkit-tap-highlight-color: transparent;
}
.gr-menu-btn::after { content: ""; position: absolute; inset: -8px -6px; } /* bigger touch target */
.gr-menu-btn:hover { border-color: var(--ink); }
.gr-menu-btn:active { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); }

/* bottom bar */
.gr-hud-bl { flex: 1 1 0; display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.gr-hud-slot { display: inline-flex; align-items: center; justify-content: center; width: 13px; height: 13px; border: 1px solid var(--ink); font-size: 9px; }
.gr-hud-bc { flex: 2 1 0; min-width: 0; text-align: center; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-hud-br { flex: 1 1 0; display: flex; align-items: center; justify-content: flex-end; gap: 9px; white-space: nowrap; }
.gr-batt { position: relative; display: inline-flex; gap: 1px; width: 20px; height: 9px; padding: 1px; border: 1px solid var(--ink); margin-right: 3px; }
.gr-batt::after { content: ""; position: absolute; right: -4px; top: 2px; width: 2px; height: 3px; background: var(--ink); }
.gr-batt i { flex: 1; background: var(--ink); }
.gr-batt i:last-child { background: transparent; }

/* narrower desktops: shed the less important readouts first */
@media (max-width: 1100px) { .gr-hud-p4, .gr-hud-p5 { display: none; } }
@media (max-width: 820px)  { .gr-hud-p2 { display: none; } }
/* phones: dot, TC, mode, MENU / info + battery */
@media (max-width: 640px) {
  #gr-hud-top, #gr-hud-bottom { gap: 10px; }
  .gr-hud-m, .gr-hud-stby, .gr-hud-bl { display: none; }
  .gr-hud-l { gap: 8px; }
  .gr-hud-r { gap: 10px; }
  .gr-menu-btn { height: 22px; padding: 0 7px; }
  .gr-hud-bc { flex: 1 1 auto; text-align: left; }
  .gr-hud-br { flex: 0 0 auto; }
}

/* ---------- Frame lines: corner brackets round the Big Six, fading as you scroll off HOME ---------- */
#gr-frame {
  position: fixed; z-index: 40; pointer-events: none;
  left: 12px; right: 12px; top: calc(env(safe-area-inset-top, 0px) + 12px); bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  border: 1px solid var(--line);
}
.gr-fr-c { position: absolute; width: 18px; height: 18px; border: 0 solid rgba(236, 235, 231, .8); }
.gr-fr-tl { left: -1px; top: -1px; border-width: 1px 0 0 1px; }
.gr-fr-tr { right: -1px; top: -1px; border-width: 1px 1px 0 0; }
.gr-fr-bl { left: -1px; bottom: -1px; border-width: 0 0 1px 1px; }
.gr-fr-br { right: -1px; bottom: -1px; border-width: 0 1px 1px 0; }
.gr-fr-x { position: absolute; left: 50%; top: 50%; width: 11px; height: 11px; margin: -5px 0 0 -5px; }
.gr-fr-x::before, .gr-fr-x::after { content: ""; position: absolute; background: var(--line); }
.gr-fr-x::before { left: 5px; top: 0; width: 1px; height: 11px; }
.gr-fr-x::after { left: 0; top: 5px; width: 11px; height: 1px; }
@media (max-width: 640px) { .gr-fr-c { width: 12px; height: 12px; } .gr-fr-x { display: none; } }

/* ---------- Boot overlay (black, LED, three firmware lines) ---------- */
#gr-boot {
  position: fixed; inset: 0; z-index: 100; overflow: hidden; background: #000; cursor: default;
  animation: gr-boot-failsafe 0s linear 12s forwards; /* if JS never runs, don't leave the site black */
}
@keyframes gr-boot-failsafe { to { opacity: 0; visibility: hidden; pointer-events: none; } }
#gr-boot.is-fade { opacity: 0; transition: opacity 220ms linear; transition-duration: 220ms !important; pointer-events: none; }
.gr-boot-txt { position: absolute; left: max(var(--gutter), env(safe-area-inset-left, 0px)); top: calc(env(safe-area-inset-top, 0px) + 22px); transition: opacity 160ms steps(3, end); }
.gr-boot-txt.is-out { opacity: 0; }
.gr-boot-led { display: block; width: 7px; height: 7px; margin-bottom: 22px; border-radius: 50%; background: var(--amber); opacity: 0; }
.gr-boot-led.is-on { opacity: 1; transition: opacity 200ms linear; }
.gr-boot-line {
  min-height: 1.75em; white-space: pre; color: var(--dim);
  font-family: var(--font-mono); font-size: calc(var(--step-osd) + 1px); line-height: 1.75; letter-spacing: .04em;
}
.gr-boot-line.is-head { color: var(--ink); }
.gr-boot-s { display: none; color: var(--ok); }
.gr-boot-line.is-ok .gr-boot-s { display: inline; }
.gr-boot-line.is-typing::after { content: ""; display: inline-block; width: .6em; height: 1em; margin-left: 1px; vertical-align: -.15em; background: var(--dim); }
.gr-boot-skip {
  position: fixed; z-index: 101; right: max(var(--gutter), env(safe-area-inset-right, 0px)); bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  padding: 12px 8px; color: var(--dim);
  font-family: var(--font-mono); font-size: var(--step-osd); letter-spacing: .08em; text-transform: uppercase;
}
.gr-boot-skip:hover { color: var(--ink); }

/* ---------- Fly-in clip: full-bleed, above the page, under the boot overlay ---------- */
#gr-flyin { position: fixed; inset: 0; z-index: 90; background: #000; overflow: hidden; pointer-events: none; }
#gr-flyin video, #gr-flyin img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; }
@media (orientation: portrait) { #gr-flyin video, #gr-flyin img { object-fit: contain; } } /* phones: keep the whole camera in frame */
#gr-flyin.is-out { opacity: 0; transition: opacity 420ms linear; }
#gr-flyin.is-fast { transition-duration: 220ms; }

/* ---------- Floating nav card (top centre, just below the HUD bar) ---------- */
#gr-nav {
  position: fixed; z-index: 44; left: 50%; top: calc(var(--gr-top) + 10px); transform: translate(-50%, -8px);
  opacity: 0; visibility: hidden; transition: opacity .25s linear, transform .25s var(--ease), visibility 0s linear .25s;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
}
#gr-nav.is-show { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }
html.gr-screen-open #gr-nav { visibility: hidden; }
.gr-nav-card { display: flex; align-items: stretch; height: 44px; background: #000; border: 1px solid var(--line); }
.gr-nav-l, .gr-nav-r { display: flex; margin: 0; padding: 0; list-style: none; }
.gr-nav-a, .gr-nav-soc a {
  position: relative; display: flex; align-items: center; height: 100%; padding: 0 15px; color: var(--dim); text-decoration: none; white-space: nowrap;
}
.gr-nav-a::after { content: ""; position: absolute; left: 15px; right: 15px; bottom: 9px; height: 2px; background: var(--amber); transform: scaleX(0); transform-origin: 0 50%; transition: transform .2s var(--ease); }
.gr-nav-a[aria-current="true"] { color: var(--ink); }
.gr-nav-a[aria-current="true"]::after { transform: scaleX(1); }
.gr-nav-a:hover, .gr-nav-soc a:hover { color: var(--ink); }
.gr-nav-mark {
  display: flex; align-items: center; padding: 0 18px; color: var(--ink); text-decoration: none; text-transform: none;
  font-size: 26px; line-height: 1; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
}
.gr-nav-mark:hover { color: var(--amber); }
.gr-nav-soc { display: flex; border-left: 1px solid var(--line); margin-left: 4px; }
.gr-nav-soc a { font-size: 10px; }
.gr-nav-cur, .gr-nav-drop { display: none; }
.gr-nav-card a:focus-visible, .gr-nav-cur:focus-visible, .gr-nav-drop a:focus-visible { outline-offset: -3px; }

@media (max-width: 760px) {
  #gr-nav { width: min(calc(100vw - 24px), 360px); }
  .gr-nav-l, .gr-nav-r, .gr-nav-soc { display: none; }
  .gr-nav-card { height: 46px; }
  .gr-nav-mark { border-left: 0; padding: 0 16px; }
  .gr-nav-cur { display: flex; flex: 1 1 auto; align-items: center; justify-content: space-between; gap: 10px; padding: 0 14px; color: var(--ink); text-align: left; font: inherit; letter-spacing: inherit; text-transform: inherit; }
  .gr-nav-cname { position: relative; padding: 4px 0; }
  #gr-nav .gr-nav-cname { box-shadow: inset 0 -2px 0 var(--amber); }
  .gr-nav-caret { color: var(--dim); }
  .gr-nav-drop { display: block; margin: 0; padding: 0; list-style: none; background: #000; border: 1px solid var(--line); border-top: 0; }
  .gr-nav-drop[hidden] { display: none; }
  .gr-nav-da { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 16px; border-top: 1px solid var(--line); color: var(--dim); text-decoration: none; }
  .gr-nav-dn { color: var(--faint); }
  .gr-nav-da[aria-current="true"] { color: var(--ink); box-shadow: inset 2px 0 0 var(--amber); }
  .gr-nav-da.is-menu { color: var(--ink); }
}

/* ---------- Screens (full-monitor pages between the HUD bars) ---------- */
.gr-screen {
  position: fixed; left: 0; right: 0; top: var(--gr-top); bottom: var(--gr-bottom); z-index: 45;
  display: flex; flex-direction: column; background: var(--bg);
}
.gr-screen.is-in { animation: gr-cut-in 120ms steps(2, end) both; }
.gr-screen.is-out { animation: gr-cut-out 120ms steps(2, end) both; pointer-events: none; }
@keyframes gr-cut-in { from { opacity: 0; } }
@keyframes gr-cut-out { to { opacity: 0; } }
.gr-screen-chrome {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 46px;
  padding: 0 max(var(--gutter), env(safe-area-inset-right, 0px)) 0 max(var(--gutter), env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
}
.gr-screen-back { display: inline-flex; align-items: center; height: 100%; padding: 0 12px; margin-left: -12px; color: var(--ink); font: inherit; letter-spacing: inherit; }
.gr-screen-back:hover, .gr-screen-back:focus-visible { color: var(--amber); }
.gr-screen-info { display: flex; align-items: center; gap: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; }
.gr-screen-val { color: var(--dim); }
.gr-screen-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@media (max-width: 640px) { .gr-screen-chrome { height: 50px; } .gr-screen-val { display: none; } }

/* ---------- Reduced motion: no clip, no scroll-scrubbed motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .gr-hero-box, .gr-hero-in, .gr-ruler { will-change: auto; }
  .gr-hero-in { transform: none; }
  body.gr-dive .gr-six, body.gr-six-draw .gr-six-box, body.gr-six-draw .gr-six-top, body.gr-six-draw .gr-six-keys,
  body.gr-six-draw .gr-ruler, body.gr-six-draw .gr-ruler-ptr { animation: none; }
  #gr-nav { transition: none; transform: translate(-50%, 0); }
}
