/* =====================================================================
   IV-7 tablet OS motion, ported from Immersive Visuals 1.0 (tablet.lua, sched.lua).
   Tablet timings:  page out 150 ms ease-in · page in 220 ms ease-out, 48 px · rows 200 ms, 16 px, 18 ms apart
                    focus glide 110 ms expo · dialogs 200 ms back · toasts 220 ms in / 300 ms out
   Everything that hides content is scoped to html.anim (set in <head>, off for reduced motion).
   ===================================================================== */
:root {
  --e-out: cubic-bezier(.215, .61, .355, 1);      /* sched.ease.out   1-(1-x)^3 */
  --e-in: cubic-bezier(.55, .055, .675, .19);     /* sched.ease.inn   x^3 */
  --e-inout: cubic-bezier(.645, .045, .355, 1);   /* sched.ease.inout */
  --e-expo: cubic-bezier(.19, 1, .22, 1);         /* sched.ease.expo  glides */
  --e-back: cubic-bezier(.3, 1.45, .6, 1);        /* sched.ease.back  open, dialogs */
  --screen: #0A0D0C; --tab-text: #E6E8E3; --tab-dim: #7E8580;
}

/* ---------- the screen itself: static scanlines, grain and an LCD vignette ---------- */
/* grain only: scanlines belong to pictures on a screen (the hero, the boot), not to the text on top */
.fx { background: url(/fx/grain_512.png) 0 0 / 256px 256px repeat; opacity: .26; }
.fx::before { content: ''; position: fixed; inset: 0; background: radial-gradient(ellipse 120% 90% at 50% 45%, transparent 55%, rgba(0,0,0,.55) 100%); opacity: 1.6; }

/* ---------- reveal states (hidden until JS adds .in) ---------- */
.anim:not(.anim-failsafe) :is(
  .section-head > p, .split-side p, .split-side .link-caps, .page-head p, .mod-hero p, .chips a, .card,
  .log-row, .steps li, .gallery-thumbs button, .clip, .feature-list > div, .versions tbody tr,
  .mod-side > *, .entry, .numbered li, .doc-pair .panel, .faq-item, .tags code, .toc a, .block-head p,
  .copybox, .stuck, .tabs a, .footer-top > *, .terminal-head
):not(.in) { opacity: 0; transform: translateX(16px); }

/* Hidden with opacity, never clip-path: Chrome's IntersectionObserver treats a fully clipped element as off screen. */
.anim:not(.anim-failsafe) :is(.section-head h2, .split-side h2, .page-head h1, .mod-hero h1, .h2-sm, .entry-head h2, .hero .lockup-word):not(.in):not(.scanning) { opacity: 0; }
.anim:not(.anim-failsafe) :is(.crumbs, .mod-meta, .badge):not(.in) { opacity: 0; }
.anim:not(.anim-failsafe) :is(.card-img, .gallery-main):not(.in) { opacity: 0; }

.in { transition: opacity .2s var(--e-out) var(--d, 0ms), transform .2s var(--e-out) var(--d, 0ms); }
/* images switch on like a CRT: a bright line that opens to the full picture */
:is(.card-img, .gallery-main).in { transition: none; animation: crtFrame .34s var(--e-expo) var(--d, 0ms) both; }
:is(.card-img, .gallery-main).in img { animation: crtOn .5s var(--e-out) var(--d, 0ms) both; }
@keyframes crtFrame { from { clip-path: inset(49.5% 0 49.5% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes crtOn { 0% { filter: brightness(2.6) contrast(.6); } 100% { filter: none; } }

/* scan reveal: a red line sweeps left to right, uncovering the heading behind it (the boot wordmark trick) */
.scan-line { position: absolute; top: -6%; bottom: -6%; width: 3px; margin-left: -3px; background: var(--red);
  box-shadow: 0 0 14px rgba(232,55,46,.75); pointer-events: none; z-index: 2; }
.scan-host { position: relative; }

/* ---------- hero intro ---------- */
.anim:not(.anim-failsafe) .hero:not(.is-live) .hero-media { opacity: 0; }
.anim:not(.anim-failsafe) .hero:not(.is-live) :is(.viewfinder i, .hud > *, .lockup-sub, .hero-copy > p, .hero-copy .btn) { opacity: 0; }
.anim:not(.anim-failsafe) .hero:not(.is-live) .lockup-sub i { transform: scaleX(0); }
.hero .lockup-sub i:first-child { transform-origin: right; }
.hero .lockup-sub i:last-child { transform-origin: left; }

/* ---------- soft keys (main nav) with the gliding inverted chip ---------- */
.softkeys { position: relative; gap: 6px !important; }
.softkeys a { position: relative; z-index: 1; padding: 7px 14px; transition: color .11s; }
.softkey-chip { position: absolute; left: 0; top: 0; z-index: 0; height: 0; width: 0; background: var(--text); border-radius: 2px; opacity: 0;
  transition: transform .16s var(--e-expo), width .16s var(--e-expo), height .16s var(--e-expo), opacity .1s; pointer-events: none; }
.js-on .softkeys a[aria-current] { color: #0A0A0A; }
.softkeys a:hover:not([aria-current]) { color: var(--text); }

/* ---------- focus glide: one highlight that moves between items, like the tablet's row focus ---------- */
.fglide-host { position: relative; }
.fglide { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; opacity: 0;
  transition: transform .11s var(--e-expo), width .11s var(--e-expo), height .11s var(--e-expo), opacity .12s linear; }
.fglide.is-on { opacity: 1; }
.fglide.frame { --c: var(--red); margin: -6px; padding: 6px; box-sizing: content-box;
  background:
    linear-gradient(var(--c), var(--c)) 0 0 / 16px 2px no-repeat, linear-gradient(var(--c), var(--c)) 0 0 / 2px 16px no-repeat,
    linear-gradient(var(--c), var(--c)) 100% 0 / 16px 2px no-repeat, linear-gradient(var(--c), var(--c)) 100% 0 / 2px 16px no-repeat,
    linear-gradient(var(--c), var(--c)) 0 100% / 16px 2px no-repeat, linear-gradient(var(--c), var(--c)) 0 100% / 2px 16px no-repeat,
    linear-gradient(var(--c), var(--c)) 100% 100% / 16px 2px no-repeat, linear-gradient(var(--c), var(--c)) 100% 100% / 2px 16px no-repeat; }
.fglide.bar { background: rgba(242,242,240,.055); box-shadow: inset 2px 0 0 var(--red); }
.fglide.chip { background: rgba(242,242,240,.08); outline: 1px solid rgba(242,242,240,.35); border-radius: 2px; }
.fglide.bar, .fglide.chip { z-index: 0; }
.fglide-host > :not(.fglide, .softkey-chip) { position: relative; z-index: 1; }
.fglide-host :focus-visible { outline: none; }

/* ---------- physical keys: buttons press down and flash like the bezel keys ---------- */
.btn { position: relative; overflow: hidden; transition: background .11s, border-color .11s, transform .07s; }
.btn.is-down { transform: translateY(1px) scale(.985); filter: brightness(.9); }
.btn::before { content: ''; position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.btn.is-key::before { animation: keyFlash .11s var(--e-out); }
@keyframes keyFlash { from { opacity: .35; } to { opacity: 0; } }
.btn-red:hover { background: #F04A41; }
.btn-ghost:hover { background: rgba(242,242,240,.06); }

/* cards: no drift, the focus frame does the talking; the image brightens a touch */
.card { transition: border-color .11s; }
.card-img img { transition: filter .2s var(--e-out); }
.card:hover .card-img img { filter: brightness(1.12) contrast(1.04); }

/* ---------- toasts (tablet.lua: slide in 24 px over 220 ms, fade out over 300 ms) ---------- */
.toasts { position: fixed; right: 24px; bottom: 56px; z-index: 96; display: flex; flex-direction: column-reverse; gap: 10px; pointer-events: none; }
.toast { min-width: 300px; max-width: 380px; padding: 12px 16px 13px; background: rgba(10,13,12,.96); border: 1px solid var(--rule); border-left: 2px solid var(--red);
  box-shadow: 0 12px 40px rgba(0,0,0,.5); pointer-events: auto; }
.toast-k { display: block; font: 400 17px/1 var(--mono); color: var(--red); letter-spacing: .04em; margin-bottom: 6px; }
.toast-t { display: block; font: 700 15px/1.3 var(--display); color: var(--text); }
.toast-d { display: block; font: 400 17px/1.2 var(--mono); color: var(--dim); margin-top: 4px; }
.toast.ok { border-left-color: var(--green); } .toast.ok .toast-k { color: var(--green); }

/* ---------- status bar (the tablet's bottom bar) ---------- */
.statusbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; justify-content: flex-start; align-items: center; gap: 24px;
  height: 34px; padding: 0 var(--gutter); background: rgba(7,8,7,.94); backdrop-filter: blur(8px); border-top: 1px solid var(--rule);
  font: 400 17px/1 var(--mono); color: var(--dim); letter-spacing: .02em; }
.statusbar b { color: var(--red); font-weight: 400; }
.statusbar kbd { font: inherit; color: var(--text); background: #1A1E1C; border: 1px solid #2E3431; border-radius: 2px; padding: 1px 6px; margin: 0 6px 0 14px; }
.statusbar kbd:first-child { margin-left: 0; }
body { padding-bottom: 34px; }
.anim .statusbar { transform: translateY(100%); transition: transform .22s var(--e-out); }
.anim .statusbar.is-on { transform: none; }

/* ---------- top progress hairline while a page loads ---------- */
.nav-progress { position: fixed; top: 0; left: 0; height: 2px; width: 100%; z-index: 100; background: var(--red); transform: scaleX(0); transform-origin: left; opacity: 0; }
.nav-progress.is-on { opacity: 1; transform: scaleX(.7); transition: transform .5s var(--e-out); }
.nav-progress.is-done { opacity: 0; transform: scaleX(1); transition: transform .12s, opacity .2s .1s; }

/* ---------- boot: IV-7 cold boot (2.6 s) ---------- */
.boot { position: fixed; inset: 0; z-index: 95; }
.boot-screen { position: absolute; inset: 0; background: #030404; overflow: hidden; }
.boot-screen::after { content: ''; position: absolute; inset: 0; background: url(/fx/scanlines_4.png) 0 0 / 4px 4px; opacity: .5; pointer-events: none; }
.boot-cursor { position: absolute; left: 50%; top: 50%; width: 12px; height: 22px; margin: -11px 0 0 -6px; background: var(--tab-text); }
.boot-corners { position: absolute; inset: clamp(20px, 5vh, 56px) clamp(20px, 4vw, 64px); opacity: 0; font: 400 20px/1 var(--mono); color: var(--tab-dim); }
.boot-corners i { position: absolute; width: 44px; height: 44px; border: 3px solid var(--tab-dim); }
.boot-corners i:nth-child(1) { left: 0; top: 0; border-right: 0; border-bottom: 0; }
.boot-corners i:nth-child(2) { right: 0; top: 0; border-left: 0; border-bottom: 0; }
.boot-corners i:nth-child(3) { left: 0; bottom: 0; border-right: 0; border-top: 0; }
.boot-corners i:nth-child(4) { right: 0; bottom: 0; border-left: 0; border-top: 0; }
.bc { position: absolute; }
.bc.tl { left: 24px; top: 16px; } .bc.tr { right: 24px; top: 16px; } .bc.bl { left: 24px; bottom: 16px; } .bc.br { right: 24px; bottom: 16px; }
.bc .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--green); margin-right: 8px; }
.bc.br.is-ready { color: var(--green); }
.boot-center { position: absolute; left: 50%; top: 50%; width: min(880px, calc(100vw - 48px)); transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; }
.boot-word { position: relative; height: clamp(62px, 9vw, 112px); width: 0; }
.boot-reveal > span:last-child { margin-right: -.12em; } /* drop the trailing letter-spacing so it centres */
.boot-reveal { display: flex; gap: .28em; height: 100%; overflow: hidden; width: 0; white-space: nowrap;
  font: 600 clamp(52px, 8vw, 104px)/1.05 var(--label); letter-spacing: .12em; color: var(--tab-text); }
.boot-reveal .muted { color: var(--tab-dim); }
.boot-scan { position: absolute; top: -8px; bottom: -8px; left: 0; width: 3px; background: var(--red); box-shadow: 0 0 16px rgba(232,55,46,.8); opacity: 0; }
.boot-rule { display: block; width: 100%; max-width: 760px; height: 2px; margin-top: 10px; background: var(--red); transform: scaleX(0); }
.boot-fw { margin-top: 16px; font: 400 21px var(--mono); letter-spacing: .06em; color: var(--tab-dim); opacity: 0; }
.boot-bar { display: flex; align-items: center; gap: 18px; width: 100%; max-width: 760px; margin-top: 64px; opacity: 0; }
.boot-segs { flex: 1; display: grid; grid-template-columns: repeat(24, 1fr); gap: 4px; }
.boot-segs i { height: 7px; background: #2A302D; }
.boot-segs i.lit { background: var(--red); }
.boot-pct { width: 52px; text-align: right; font: 400 21px var(--mono); color: var(--tab-text); }
.boot-rows { width: 100%; max-width: 760px; margin-top: 18px; display: flex; flex-direction: column; gap: 10px; font: 400 21px/1 var(--mono); }
.boot-row { display: grid; grid-template-columns: 190px 1fr auto; gap: 16px; color: var(--tab-text); opacity: 0; }
.boot-row > span:first-child { color: var(--tab-dim); letter-spacing: .04em; }
.boot-row b { font-weight: 400; }
.boot-row b.green { color: var(--green); } .boot-row b.amber { color: var(--amber); }
.boot-skip { position: absolute; bottom: clamp(24px, 6vh, 64px); left: 0; right: 0; text-align: center; font: 400 17px var(--mono); color: #3A413D; letter-spacing: .1em; }

/* ---------- screen: wake from black on every load (tablet wake: 180 ms), static glass sheen, hairline scrollbar ---------- */
.anim body::after { content: ''; position: fixed; inset: 0; z-index: 99; background: #000; pointer-events: none; animation: wake .24s var(--e-out) .04s both; }
@keyframes wake { from { opacity: 1; } to { opacity: 0; } }
.fx::after { content: ''; position: fixed; inset: 0; background: linear-gradient(115deg, transparent 0 34%, rgba(255,255,255,.05) 45%, transparent 58%); }
html { scrollbar-width: thin; scrollbar-color: #3A413D #070807; }

/* ---------- tablet breadcrumb (PRESETS / NATURAL, current page in red, underlined) ---------- */
.crumbs { display: flex; align-items: baseline; gap: 12px; font: 400 22px/1 var(--mono); letter-spacing: .04em; color: #A3AAA5; }
.crumbs i { font-style: normal; color: var(--faint); }
.crumbs b { position: relative; font-weight: 400; color: var(--red); padding-bottom: 8px; }
.crumbs b::after { content: ''; position: absolute; left: -2px; right: -56px; bottom: 0; height: 2px; background: var(--red); transform-origin: left; }
.crumbs.in b::after { animation: ruleDraw .4s var(--e-out) calc(var(--d, 0ms) + 160ms) both; }
@keyframes ruleDraw { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------- hold to compare (tablet: Hold F9, 160 ms, the UI dims to 22 %) ---------- */
.mod-hero > .cmp-vanilla { opacity: 0; transition: opacity .16s linear; }
.mod-hero.is-comparing > .cmp-vanilla { opacity: .7; }
.mod-hero-inner > div:first-child, .mod-meta { transition: opacity .16s linear; }
.mod-hero.is-comparing .mod-hero-inner > div:first-child, .mod-hero.is-comparing .mod-meta { opacity: .22; }
.mod-hero-side { display: flex; flex-direction: column; align-items: flex-end; gap: 16px; }
.cmp-btn { gap: 8px; user-select: none; touch-action: none; }
.cmp-btn kbd { font: 400 17px/1 var(--mono); letter-spacing: 0; padding: 2px 6px; border: 1px solid #4A524D; border-radius: 2px; }
.mod-hero.is-comparing .cmp-btn { background: var(--text); border-color: var(--text); color: #0A0A0A; }
.mod-hero.is-comparing .cmp-btn kbd { border-color: #0A0A0A; }
.cmp-osd { position: absolute; top: 28px; left: 50%; z-index: 2; display: flex; align-items: center; gap: 14px; padding: 7px 14px 7px 7px;
  background: rgba(10,13,12,.92); border: 1px solid var(--rule); font: 400 20px/1 var(--mono); color: var(--tab-text); letter-spacing: .04em;
  opacity: 0; transform: translate(-50%, -8px); transition: opacity .16s linear, transform .22s var(--e-out); pointer-events: none; }
.cmp-osd b { font-weight: 400; background: var(--text); color: #0A0A0A; padding: 4px 8px; }
.mod-hero.is-comparing .cmp-osd { opacity: 1; transform: translate(-50%, 0); }


/* ---------- context hints in the status bar (the tablet's hint row) ---------- */
.sb-keys.is-swap { animation: hintSwap .14s var(--e-out); }
@keyframes hintSwap { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* ---------- dialog (tablet.lua: 200 ms with a small overshoot, 120 ms out) ---------- */
.dlg { position: fixed; inset: 0; z-index: 97; display: grid; place-items: center; padding: 20px; }
.dlg-back { position: absolute; inset: 0; background: rgba(3,4,4,.74); backdrop-filter: blur(3px); }
.dlg-panel { position: relative; width: min(560px, 100%); padding: 28px 28px 22px; background: var(--screen) url(/fx/scanlines_4.png) 0 0 / 4px 4px;
  border: 1px solid var(--rule); box-shadow: 0 30px 90px rgba(0,0,0,.65); }
.dlg-panel::before { content: ''; position: absolute; left: -1px; top: -1px; width: 64px; height: 2px; background: var(--amber); }
.dlg-k { display: block; margin-bottom: 12px; font: 400 20px/1 var(--mono); letter-spacing: .06em; color: var(--amber); }
.dlg-t { margin: 0 0 12px; font: 600 30px/1.1 var(--label); letter-spacing: .06em; color: var(--tab-text); }
.dlg-b { margin: 0 0 24px; font-size: 16px; line-height: 1.55; color: #B9BEB9; }
.dlg-btns { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding-top: 18px; border-top: 1px solid var(--rule); }
.dlg-btn { display: inline-flex; align-items: center; gap: 10px; padding: 9px 14px; background: none; border: 1px solid #3A413D; border-radius: 2px;
  color: var(--tab-text); font: 400 20px/1 var(--mono); letter-spacing: .04em; cursor: pointer; transition: border-color .11s, background .11s; }
.dlg-btn kbd { font: inherit; color: var(--tab-dim); }
.dlg-btn:hover { border-color: var(--tab-text); }
.dlg-btn.primary { background: var(--tab-text); border-color: var(--tab-text); color: #0A0A0A; }
.dlg-btn.primary kbd { color: #4A524D; }
.dlg-btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .mod-hero-side { align-items: flex-start; }
  .cmp-osd { top: 12px; font-size: 16px; white-space: nowrap; }
  .statusbar { display: none; }
  body { padding-bottom: 0; }
  .softkey-chip { display: none; }
  .js-on .softkeys a[aria-current] { color: var(--text); }
  .boot-row { grid-template-columns: 110px 1fr auto; font-size: 18px; }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
  .toast { min-width: 0; max-width: none; }
}
@media (max-width: 1180px) { .sb-keys { display: none; } }
@media (prefers-reduced-motion: reduce) { .boot { display: none !important; } }
