/* ==========================================================================
   Home — intro (test card, boot terminal), portrait stage, name, side labels
   ========================================================================== */

body.home {
  --name-size: min(26vh, 22vw);
  height: 100vh;
  overflow: hidden;
  background: #050505;
}

/* ---------- Screen ---------- */

.screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--screen);
  transform-origin: 50% 50%;
}

html:not(.no-intro):not(.is-on) .screen {
  visibility: hidden;
}

html.is-on:not(.no-intro) .screen {
  animation: crt-on 0.75s cubic-bezier(0.5, 0, 0.2, 1) both;
}

@keyframes crt-on {
  0% {
    transform: scale(0.06, 0.004);
    filter: brightness(5) saturate(0);
  }
  30% {
    transform: scale(1, 0.004);
    filter: brightness(4) saturate(0);
  }
  100% {
    transform: none;
    filter: none;
  }
}

.topo,
.stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.topo {
  z-index: 0;
}

.stage {
  z-index: 1;
}

.slide {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  will-change: transform;
}

/* The portrait box is measured by the WebGL stage; the <img> only shows when WebGL is missing.
   The chin sits just above the caption (whose height home.js sets) and the face is drawn
   about 35% larger than before, growing upwards but stopping --headroom from the top, below
   the nav. In the image the chin is 17.3% up from the bottom and the top of the hair 91.5%.
   The bottom and side edges fade out (in the shader, and in the mask below). */
.portrait {
  --headroom: calc(var(--bezel-corner) + 76px);
  --chin: calc(var(--bezel-corner) + var(--name-size) * 0.8 + 20px + var(--caption-h, 36px));
  --h: min(89.1vh, 135vw, (100vh - var(--headroom) - var(--chin)) / 0.7419);
  position: absolute;
  left: 50%;
  bottom: calc(var(--chin) - var(--h) * 0.1734);
  height: var(--h);
  aspect-ratio: 961 / 1240;
  transform: translateX(-50%);
}

.portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: grayscale(1) contrast(1.05);
  visibility: hidden;
  -webkit-mask-image: linear-gradient(to top, transparent, #000 20%), linear-gradient(to right, transparent, #000 12%, #000 88%, transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to top, transparent, #000 20%), linear-gradient(to right, transparent, #000 12%, #000 88%, transparent);
  mask-composite: intersect;
}

html.no-fluid .portrait img {
  visibility: visible;
}

/* ---------- Giant slot-machine name ---------- */

.name {
  position: absolute;
  left: 50%;
  bottom: calc(var(--bezel-corner) - 0.2em);
  display: flex;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: var(--name-size);
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
  text-transform: uppercase;
  mix-blend-mode: multiply;
}

/* Slot reels (built by home.js): one clipped cell per character */
.rs {
  display: inline-block;
  vertical-align: top;
  height: 1.08em;
  overflow: hidden;
  transition: width 0.8s var(--ease-out), opacity 0.5s;
}

.rr {
  display: block;
  will-change: transform;
}

.rr span {
  display: block;
  height: 1.08em;
  line-height: 1.08em;
  text-align: center;
}

.nav__name {
  display: inline-flex;
  white-space: nowrap;
}

/* ---------- Caption strip (TV lower third) above the name ---------- */

.caption {
  position: absolute;
  left: 50%;
  bottom: calc(var(--bezel-corner) + var(--name-size) * 0.8 + 10px);
  z-index: 3;
  display: flex;
  align-items: stretch;
  transform: translateX(-50%);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.9s var(--ease-out) 0.6s;
}

html.is-ready .caption {
  clip-path: inset(0 0 0 0);
}

.caption > span {
  display: flex;
  align-items: center;
  padding: 9px 14px;
}

.caption__live {
  gap: 8px;
  background: var(--about);
  color: #fff;
}

.caption__live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1.2s steps(1) infinite;
}

.caption__role {
  background: var(--ink);
  color: var(--paper);
}

.caption__meta {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-osd);
  font-size: 18px;
  font-weight: normal;
  letter-spacing: 0.03em;
  text-transform: none;
}

@media (max-width: 768px) {
  .caption {
    flex-wrap: wrap;
    justify-content: center;
    width: max-content;
    max-width: calc(100vw - 2 * var(--gutter));
    font-size: 10px;
    white-space: normal;
  }
  .caption > span {
    flex: 1 1 auto;
    justify-content: center;
    padding: 7px 10px;
  }
  .caption__meta {
    flex-basis: 100%;
    justify-content: center;
    font-size: 15px;
  }
}

/* ---------- Side labels ---------- */

.side {
  position: absolute;
  z-index: 3;
  top: 50%;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 0.8s var(--ease-out), transform 0.8s var(--ease-out), color 0.35s;
}

.side--left {
  --accent: var(--about);
  left: calc(var(--gutter) - 6px);
  transform: translate(-28px, -50%);
}

.side--right {
  --accent: var(--services);
  right: calc(var(--gutter) - 6px);
  transform: translate(28px, -50%);
}

html.is-ready .side {
  opacity: 1;
  transform: translate(0, -50%);
}

.side__label {
  writing-mode: vertical-rl;
}

.side--left .side__label {
  transform: rotate(180deg);
}

.side__label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.side__arrow {
  display: inline-block;
  transition: transform 0.5s var(--ease-out);
}

/* The number box keeps its upright footprint; the digits inside are turned
   on their side to run along the label. */
.side__nr {
  position: relative;
  flex: none;
  width: 1.08em;
  height: 0.86em;
  font-family: var(--font-display);
  font-size: clamp(84px, 14.5vh, 156px);
  line-height: 1;
}

.side__digits {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  transition: filter 0.9s ease;
}

/* Which way each number lies at rest (01 reads bottom-to-top, 02 top-to-bottom),
   and which way it whirls on hover: the two sides spin in opposite directions. */
.side--left {
  --turn: -90deg;
  --whirl: -720deg;
  --nudge: 0.3em;
}

.side--right {
  --turn: 90deg;
  --whirl: 720deg;
  --nudge: -0.42em;
}

/* Grow/Turn (as in PowerPoint): on hover the number shrinks away, then grows
   back while spinning about two and a quarter turns, landing upright at 1.69x
   (30% + 30%) and in colour, drifting inward so it clears its label.
   Leaving the side turns it back onto its side. */
.side__num {
  display: block;
  color: rgba(28, 27, 25, 0.14);
  transform: rotate(var(--turn));
  transition: transform 0.9s cubic-bezier(0.22, 1, 0.36, 1), color 0.9s ease;
}

.side.is-active {
  color: var(--accent);
}

.side.is-active .side__num {
  color: var(--accent);
  transform: translateX(var(--nudge)) scale(1.69);
  animation: grow-turn 1.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.side.is-active .side__digits {
  filter: drop-shadow(0 0 18px color-mix(in srgb, var(--accent) 60%, transparent));
}

@keyframes grow-turn {
  from {
    transform: rotate(calc(var(--turn) + var(--whirl))) scale(0.05);
    opacity: 0;
  }
  to {
    transform: translateX(var(--nudge)) scale(1.69);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .side.is-active .side__num {
    animation: none;
  }
}

.side--left.is-active .side__arrow {
  transform: translateY(4px);
}

.side--right.is-active .side__arrow {
  transform: translateY(4px);
}

/* ---------- Entrance ---------- */

.reveal-nav {
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.8s var(--ease-out), transform 0.8s var(--ease-out);
}

html.is-ready .reveal-nav {
  opacity: 1;
  transform: none;
}

/* ---------- Phones: labels move under the nav, name cycles on its own ---------- */

@media (max-width: 768px) {
  /* Phones keep the head below the label row */
  .portrait {
    --headroom: 146px;
    --h: min(78.3vh, 159.3vw, (100vh - var(--headroom) - var(--chin)) / 0.7419);
  }

  body.home {
    --name-size: 23vw;
  }

  .name {
    bottom: calc(var(--bezel-corner) - 0.16em);
  }

  .side {
    top: calc(var(--bezel-corner) + 18px + 44px + 14px);
    gap: 8px;
  }

  .side--left {
    transform: translate(0, -8px);
  }

  .side--right {
    transform: translate(0, -8px);
  }

  html.is-ready .side {
    transform: none;
  }

  .side__label {
    writing-mode: horizontal-tb;
    font-size: 10px;
    letter-spacing: 0.16em;
  }

  .side--left .side__label {
    transform: none;
  }

  .side__nr {
    width: auto;
    height: 1.08em;
    font-size: 40px;
  }

  .side__digits {
    position: static;
    transform: none;
  }

  .side--left,
  .side--right {
    --turn: 0deg;
  }
}

/* Wider than a phone, the labels sit well clear of the head, so it can rise to the nav */
@media (min-width: 561px) and (max-width: 768px) {
  .portrait {
    --headroom: 92px;
  }
}

/* ==========================================================================
   Intro
   ========================================================================== */

.intro {
  position: fixed;
  inset: 0;
  z-index: 44;
  background: #050505;
  overflow: hidden;
  transform-origin: 50% 50%;
}

html.no-intro .intro {
  display: none;
}

.intro.is-off {
  animation: crt-off 0.6s cubic-bezier(0.6, 0, 0.8, 0.4) forwards;
}

@keyframes crt-off {
  0% {
    transform: none;
    filter: none;
  }
  50% {
    transform: scale(1, 0.004);
    filter: brightness(3);
  }
  80% {
    transform: scale(0.08, 0.004);
    filter: brightness(5);
  }
  100% {
    transform: scale(0, 0);
    opacity: 0;
  }
}

/* ---------- Test card ---------- */

.testcard {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #7b7b79;
}

.testcard__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.7) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.7) 2px, transparent 2px);
  background-size: 7.5vh 7.5vh;
  background-position: center center;
}

.testcard__disc {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(76vh, 88vw);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #f4f4f4;
  box-shadow: 0 0 0 7px #121212;
}

.tc-band {
  flex: none;
  display: flex;
}

.tc-band i {
  flex: 1;
}

.tc-band--checker {
  height: 14%;
  background: repeating-conic-gradient(#121212 0 25%, #f4f4f4 0 50%) 0 0 / 16% 100%;
}

.tc-band--bars {
  height: 26%;
}

.tc-band--bars i {
  background: var(--c);
}

.tc-band--title,
.tc-band--meter {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0d0d0d;
  color: #f2f2f2;
  font-family: var(--font-osd);
}

.tc-band--title {
  height: 18%;
}

.tc-title {
  font-size: min(5.6vh, 6.4vw);
  letter-spacing: 0.18em;
  line-height: 1;
}

.tc-sub {
  margin-top: 0.4em;
  font-size: min(2.6vh, 3.2vw);
  letter-spacing: 0.36em;
  color: #b9b9b9;
  animation: blink 1.1s steps(1) infinite;
}

.tc-band--meter {
  height: 12%;
  flex-direction: row;
  gap: 3%;
  border-top: 2px solid #2a2a2a;
}

.tc-meter {
  width: 44%;
  height: 34%;
  padding: 3px;
  border: 2px solid #eee;
}

.tc-meter__fill {
  display: block;
  width: 0;
  height: 100%;
  background: repeating-linear-gradient(90deg, #eee 0 7px, transparent 7px 10px);
}

.tc-pct {
  width: 3.2em;
  font-size: min(3.2vh, 3.8vw);
}

.tc-band--wedge {
  height: 14%;
}

.tc-band--wedge i:nth-child(1) { background: #000; }
.tc-band--wedge i:nth-child(2) { background: #333; }
.tc-band--wedge i:nth-child(3) { background: #666; }
.tc-band--wedge i:nth-child(4) { background: #999; }
.tc-band--wedge i:nth-child(5) { background: #ccc; }
.tc-band--wedge i:nth-child(6) { background: #fff; }

.tc-band--gratings {
  height: 16%;
}

.tc-band--gratings i:nth-child(1) { background: repeating-linear-gradient(90deg, #f4f4f4 0 9px, #111 9px 18px); }
.tc-band--gratings i:nth-child(2) { background: repeating-linear-gradient(90deg, #f4f4f4 0 5px, #111 5px 10px); }
.tc-band--gratings i:nth-child(3) { background: repeating-linear-gradient(90deg, #f4f4f4 0 3px, #111 3px 6px); }
.tc-band--gratings i:nth-child(4) { background: repeating-linear-gradient(90deg, #f4f4f4 0 2px, #111 2px 4px); }

.testcard__osd {
  position: absolute;
  top: calc(var(--bezel-corner) + 3.4vh);
  font-family: var(--font-osd);
  font-size: clamp(28px, 4.6vh, 50px);
  color: var(--osd);
  text-shadow: 0 0 10px rgba(125, 255, 140, 0.6);
}

.testcard__osd--ch {
  left: calc(var(--gutter) + 4px);
}

.testcard__osd--clock {
  right: calc(var(--gutter) + 4px);
}

.testcard__skip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--bezel-corner) + 3vh);
  text-align: center;
  font-family: var(--font-osd);
  font-size: clamp(16px, 2.3vh, 24px);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
}

.only-touch {
  display: none;
}

@media (hover: none) {
  .only-desktop {
    display: none;
  }
  .only-touch {
    display: inline;
  }
}

/* Short bursts of signal loss */
.testcard.is-glitch {
  animation: tc-glitch 0.22s steps(3) 1;
}

@keyframes tc-glitch {
  0% {
    transform: translateX(-1.6%) skewX(-2deg);
    filter: hue-rotate(40deg) saturate(1.6);
    clip-path: inset(12% 0 64% 0);
  }
  33% {
    transform: translateX(2.2%);
    filter: invert(0.1) contrast(1.4);
    clip-path: none;
  }
  66% {
    transform: translateY(1.2%) translateX(-0.6%);
    filter: hue-rotate(-30deg);
  }
  100% {
    transform: none;
    filter: none;
  }
}

/* ---------- Boot terminal ---------- */

.boot {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
  padding: calc(var(--bezel-corner) + 6vh) calc(var(--gutter) + 2vw) calc(var(--bezel-corner) + 4vh);
  background: radial-gradient(120% 90% at 50% 45%, #1a1610, #0c0a07 75%);
  color: var(--amber);
  font-family: var(--font-osd);
  font-size: clamp(15px, 2.35vh, 25px);
  line-height: 1.28;
  text-shadow: 0 0 7px rgba(241, 182, 92, 0.55);
  white-space: pre;
}

.boot.is-on {
  display: block;
}

.boot .head {
  display: block;
  max-width: 100%;
  font-size: clamp(26px, 5.6vh, 60px);
  letter-spacing: 0.08em;
  line-height: 1.1;
  white-space: pre-wrap;
}

.boot .dim {
  opacity: 0.55;
}

.boot .ok {
  color: #ffd892;
}

.boot .big {
  font-size: 1.45em;
}

.boot .rule {
  display: block;
  width: min(46ch, 100%);
  height: 0;
  margin: 0.45em 0;
  border-top: 1px dashed rgba(241, 182, 92, 0.45);
}

.boot .caret {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 0.15em;
  vertical-align: -0.14em;
  background: currentColor;
  animation: blink 0.8s steps(1) infinite;
}

@media (max-width: 600px) {
  .boot {
    white-space: pre-wrap;
    font-size: 15px;
  }
  .boot .head {
    letter-spacing: 0.2em;
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}
