/* ==========================================================================
   DUM Studio · home.css
   Layout: one photographed room (2880×1800 master) fills the screen.
   Everything in the scene is positioned in % of that master, so it stays
   glued to the photo at any size. The menu sits on the empty wall (desktop);
   on phones the TV centres and channels change by swipe.
   ========================================================================== */

body { overflow: hidden; }

.room {
  position: fixed; inset: 0; overflow: hidden;
  container: room / size;
  background: linear-gradient(180deg, var(--wall-hi) 0%, var(--wall) 55%, var(--floor) 100%);
}

/* ---------- The scene (photo + TV) ---------- */
/* Only the original photo is used. It always covers the screen and is pinned
   to the bottom-right corner, so any cropping comes off the LEFT and TOP
   (the floor, bottom-left and the TV are kept). */
.stage {
  position: absolute; right: 0; bottom: 0;
  aspect-ratio: 2880 / 1800;
  width: max(100cqw, 160cqh);
}
.stage > * { position: absolute; }
.stage__photo  { inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; }

/* light from the screen onto the wall */
.tv-glow {
  left: 56%; top: 28%; width: 44%; height: 74%;
  pointer-events: none; mix-blend-mode: screen;
  background: radial-gradient(closest-side, var(--glow, rgba(200,220,255,.5)), transparent 75%);
  opacity: var(--glow-amount, .22);
  transition: opacity .4s, background .25s;
}

/* ---------- The CRT screen ---------- */
/* box = bounding box of the glass on the 2880 master (1936,911 → 2556,1428) */
.screen {
  left: 67.222%; top: 50.611%; width: 21.528%; height: 28.722%;
  overflow: hidden;
  -webkit-mask: url("../assets/img/screen-mask.png") center / 100% 100% no-repeat;
          mask: url("../assets/img/screen-mask.png") center / 100% 100% no-repeat;
  background: var(--screen-black);
  transition: background-color .5s .45s;
}

/* Channel art is shown exactly as drawn (no warp).
   .screen__warp holds only the scanlines + OSD and is mapped onto the tilted
   glass with a matrix3d set by home.js, so they follow the TV's perspective. */
.crt { position: absolute; inset: 0; transform-origin: 50% 50%; --tilt: 4.94deg; }
.crt > * { position: absolute; inset: 0; width: 100%; height: 100%; }
.crt > .screen__warp { transform-origin: 0 0; pointer-events: none; }
.screen__warp > * { position: absolute; inset: 0; width: 100%; height: 100%; }

.channel { opacity: 0; display: grid; place-items: center; }
.channel.is-on { opacity: 1; }
.channel img { width: 100%; height: 100%; max-width: none; object-fit: cover; }
.channel__placeholder { font: 400 1em/1 var(--display); text-align: center; color: var(--phosphor); text-shadow: 0 0 .25em var(--phosphor-glow); }

.static { image-rendering: pixelated; opacity: 0; transition: opacity .06s; }
.static.is-on { opacity: .82; }

.scanlines {
  pointer-events: none;
  background:
    repeating-linear-gradient(180deg, rgba(0,0,0,.24) 0 1px, transparent 1px 3px),
    radial-gradient(120% 110% at 50% 50%, transparent 55%, rgba(0,0,0,.6) 100%);
}
.screen.is-flicker .channel.is-on { animation: flicker 4s infinite steps(1); }
@keyframes flicker { 0%,100% {opacity:1} 47% {opacity:.92} 48% {opacity:1} 83% {opacity:.96} }

.osd {
  inset: auto !important; width: auto !important; height: auto !important;
  left: 7% !important; top: 8% !important;
  font: 400 1em/1 var(--mono); letter-spacing: .06em; white-space: nowrap;
  color: var(--phosphor);
  text-shadow: 0 0 .3em var(--phosphor-glow), .06em .06em 0 rgba(0,0,0,.85);
  opacity: 0; transition: opacity .3s;
}
.osd.is-on { opacity: 1; transition: none; }

/* glass reflection from the original photo, over everything */
.screen__glass { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; mix-blend-mode: screen; opacity: .2; pointer-events: none; transition: opacity .5s .45s; }

/* afterglow dot left behind when the set switches off */
.afterglow {
  position: absolute; left: 50%; top: 50%; width: 8%; aspect-ratio: 1; translate: -50% -50%;
  border-radius: 50%; pointer-events: none; opacity: 0;
  background: radial-gradient(circle, #fff 0 18%, rgba(220,255,220,.7) 35%, transparent 70%);
}

/* ---------- Power (the little red button – easter egg) ---------- */
.power {
  left: 86.458%; top: 89.056%; width: 3.125%; height: 5%;
  padding: 0; border: 0; border-radius: 50%; background: transparent;
}
.power:focus-visible { outline: 2px dashed var(--stroke); outline-offset: 2px; }

/* off */
.room.tv-off .screen { background-color: #0b0c0b; }               /* dead tube */
.room.tv-off .screen__glass { opacity: .38; }                   /* the photo's own glass reflection */
.room.tv-off .crt { animation: crt-off .55s cubic-bezier(.5,0,.8,.4) forwards; }
.room.tv-off .afterglow { animation: afterglow 1.8s .3s ease-out forwards; }
.room.tv-off .tv-glow { opacity: 0; }
.room.tv-warming .crt { animation: crt-on .7s cubic-bezier(.2,.6,.3,1) both; }

/* The collapsing picture tilts to the glass's centre line (≈4.9°, fitted from
   the screen mask) so the bright line matches the TV's perspective. */
@keyframes crt-off {
  0%   { transform: skewY(0)           scale(1, 1);       filter: brightness(1); opacity: 1; }
  40%  { transform: skewY(var(--tilt)) scale(1, .008);    filter: brightness(4); opacity: 1; }
  75%  { transform: skewY(var(--tilt)) scale(.006, .008); filter: brightness(6); opacity: 1; }
  100% { transform: skewY(var(--tilt)) scale(0, 0);       filter: brightness(6); opacity: 0; }
}
@keyframes crt-on {
  0%   { transform: skewY(var(--tilt)) scale(.006, .008); filter: brightness(6); }
  30%  { transform: skewY(var(--tilt)) scale(1, .008);    filter: brightness(4); }
  70%  { transform: skewY(0)           scale(1, 1.02);    filter: brightness(1.6); }
  100% { transform: skewY(0)           scale(1, 1);       filter: brightness(1); }
}
@keyframes afterglow { 0% {opacity:0} 15% {opacity:1} 100% {opacity:0; scale:.4} }

/* ---------- UI on the wall (desktop) ---------- */
/* --u = one pixel of the 1800px-tall master, so the UI keeps the mock-up's proportions */
.ui {
  position: absolute; inset: 0; pointer-events: none;
  --u: calc(min(100cqh, 80cqw) / 1800);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.ui a, .ui button, .ui nav { pointer-events: auto; }
/* ---------- Poster + basket ----------
   The poster sits where the basket used to be in the mock-up and is nudged so
   it stays on screen and clear of the logo/tagline. It never shrinks: it hangs
   on the wall INSIDE the photo layer, so if it reaches the TV it simply goes
   behind it (.stage__tv is a cut-out of the TV laid over the poster).
   It never drops lower than the halfway line of the TV screen (--cymax), so on
   short, wide windows it can't slide down onto the floor.
   The basket is pinned to the top-right corner, level with the DUM STUDIO line. */
.stage, .ui {
  --u: calc(min(100cqh, 80cqw) / 1800);
  --sw: max(100cqw, 160cqh);                           /* photo width on screen */
  --ph: calc(var(--sw) * .17118);                       /* poster height = photo scale (493px on the master) */
  --pw: calc(var(--sw) * .23368);                       /* poster width  = photo scale (673px on the master) */
  --cx: clamp(calc(var(--u) * 1330 + var(--pw) / 2),
              calc(100cqw - var(--sw) * .36979 - var(--u) * 58.5),
              calc(100cqw - var(--pw) / 2 - 16px));
  --by: calc(var(--u) * 183.5);                         /* basket centre = middle of the DUM STUDIO line (top 112u + 143u/2) */
  /* halfway line of the TV screen on screen: photo top + (50.611% + 28.722% / 2) of the photo height */
  --cymax: calc(100cqh - var(--sw) * .625 + var(--sw) * .625 * .64972 - var(--ph) / 2);
  --cy: min(max(calc(var(--ph) / 2 + 16px), var(--by)), var(--cymax));   /* poster centre: header line, pushed down to stay on screen, never below --cymax */
}
.stage__poster {
  width: var(--pw); height: var(--ph);
  /* screen position minus the photo's own offset (it's pinned bottom-right) */
  left: calc(var(--cx) - var(--pw) / 2 - (100cqw - var(--sw)));
  top:  calc(var(--cy) - var(--ph) / 2 - (100cqh - var(--sw) * .625));
}
.stage__tv { left: 61.806%; top: 42.222%; width: 35.069%; height: 38.889%; pointer-events: none; }
.basket {
  position: absolute; width: calc(var(--u) * 117);
  right: max(16px, env(safe-area-inset-right, 0px), calc(var(--u) * 110)); top: calc(var(--by) - var(--u) * 59.5);
}
.basket img { display: block; width: 100%; }

.brand { position: absolute; left: calc(var(--u) * 250); top: calc(var(--u) * 112); }
.brand__name { margin: 0; font-size: calc(var(--u) * 143); line-height: 1; letter-spacing: .01em; white-space: nowrap; }
.brand__home { color: inherit; text-decoration: none; pointer-events: auto; }      /* the header takes you home */
.brand__home:focus-visible { outline: 2px dashed var(--stroke); outline-offset: 4px; }
.brand__tag  { margin: calc(var(--u) * 40) 0 0 calc(var(--u) * 8); font-size: calc(var(--u) * 50); line-height: 1; white-space: nowrap; }
.brand__basket { display: none; }

.menu { position: absolute; left: calc(var(--u) * 250); top: calc(var(--u) * 505); margin: 0; padding: 0; list-style: none; }
.menu a {
  display: flex; align-items: center; gap: calc(var(--u) * 34);
  height: calc(var(--u) * 170);
  font-size: calc(var(--u) * 92); line-height: 1; text-decoration: none;
  transition: transform .12s steps(2);
}
.menu a:focus-visible { outline: none; }
.menu .eye { width: calc(var(--u) * 107); height: auto; visibility: hidden; }
.menu a.is-active { transform: translateX(calc(var(--u) * 18)); }
.menu a.is-active .eye { visibility: visible; }

.foot { position: absolute; left: calc(var(--u) * 239); bottom: calc(var(--u) * 45); display: flex; align-items: center; gap: calc(var(--u) * 60); }
.foot a img { display: block; width: calc(var(--u) * 142); }
.sound-toggle {
  padding: 0; border: 0; background: none;
  font: 400 calc(var(--u) * 64)/1 var(--mono); letter-spacing: .06em;
  color: var(--stroke); text-shadow: var(--ring-mono);
}
.sound-toggle[aria-pressed="false"] { opacity: .65; }
.sound-toggle.is-locked { animation: blink 1.2s steps(1) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.tuner { display: none; }
.tuner__back { display: none; }

/* ---------- Section windows (About, …) on desktop ----------
   Sit between the menu and the TV; on narrower screens they're allowed
   to overlap the TV so they stay at least ~680px wide. */
.ui { --rpg-size: clamp(10px, calc(var(--u) * 30), 18px); --rpg-gap: calc(var(--u) * 60); }
.ui .windows {
  /* --win-left = the menu's real right edge (set by home.js), so windows never cover the menu or the eye */
  left: var(--win-left, calc(var(--u) * 880));
  top: calc(var(--u) * 380);
  bottom: calc(var(--u) * 190);
  right: max(16px, min(calc(var(--sw) * .36458 + 24px), calc(100cqw - var(--win-left, calc(var(--u) * 880)) - 680px)));
}

/* menu swap when entering / leaving a section */
.menu.is-swapping li { animation: menu-in .32s steps(4, end) both; }
.menu.is-swapping li:nth-child(2) { animation-delay: .05s; }
.menu.is-swapping li:nth-child(3) { animation-delay: .1s; }
.menu.is-swapping li:nth-child(4) { animation-delay: .15s; }
.menu.is-swapping li:nth-child(5) { animation-delay: .2s; }
@keyframes menu-in { from { opacity: 0; transform: translateX(calc(var(--u) * -40)); } }
.menu__back { margin-top: calc(var(--u) * 30); }

/* ---------- Phones (portrait) ---------- */
@container room (aspect-ratio < 0.85) {
  .stage {
    right: auto; bottom: auto;
    width: calc(100cqw / .36);
    left: calc(50cqw - (100cqw / .36) * .782);          /* 78.2% across the photo sits in the middle (between the original 80% and the TV's brand label at 76.4%) */
    top:  calc(49cqh - (100cqw / .36) * .4306);
    -webkit-mask: linear-gradient(180deg, transparent 0, #000 14%, #000 88%, transparent 100%);
            mask: linear-gradient(180deg, transparent 0, #000 14%, #000 88%, transparent 100%);
  }
  .basket, .menu { display: none; }
  .stage__poster { left: 71.076%; top: 7.556%; width: 23.368%; height: auto; }   /* phones: poster in its photo spot */
  .power { left: 85.9%; top: 88.2%; width: 4.4%; height: 7%; }   /* bigger tap target */

  .ui {
    --u: 1px;
    display: flex; flex-direction: column; justify-content: space-between;
    padding-top: max(20px, env(safe-area-inset-top, 0px));
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
  }
  .brand { position: static; display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 4px 12px; }
  .brand__name { font-size: min(10.2cqw, 52px); }
  .brand__tag  { grid-column: 1 / -1; margin: 6px 0 0 2px; font-size: min(4.3cqw, 22px); }
  .brand__basket { display: block; pointer-events: auto; }
  .brand__basket img { display: block; width: min(10cqw, 48px); }

  .tuner { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: auto 0 4px; pointer-events: auto; }
  .tuner__row { display: flex; align-items: center; justify-content: center; gap: 14px; width: 100%; }
  .tuner__step {
    padding: 8px 10px; border: 0; background: none;
    font: 400 44px/1 var(--mono); color: var(--stroke);
    text-shadow: 0 2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
  }
  .tuner__go { min-width: 0; text-align: center; font-size: min(11cqw, 50px); line-height: 1.1; text-decoration: none; }
  .tuner__dots { display: flex; gap: 8px; }
  .tuner__dots i { width: 8px; height: 8px; background: var(--stroke); opacity: .35; box-shadow: 0 0 0 2px var(--ink); }
  .tuner__dots i.is-on { opacity: 1; }

  /* section windows on phones: a scrolling column over the scene */
  .ui { --rpg-size: 11px; --rpg-gap: 22px; }
  .ui .windows {
    left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px));
    top: 118px; bottom: 236px;
    display: flex; flex-direction: column; align-items: stretch;
  }
  .ui .rpg { --rpg-b: 3px; }
  .room.in-section .tuner__back {
    display: block; padding: 6px 10px; border: 0; background: none;
    font: 400 20px/1 var(--mono); letter-spacing: .12em; color: var(--stroke); text-shadow: var(--ring-mono);
  }

  .foot { position: static; gap: 22px; }
  .foot a img { width: 44px; }
  .sound-toggle { font-size: 24px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .menu a, .tv-glow, .osd { transition: none; }
  .menu.is-swapping li { animation: none; }
  .screen.is-flicker .channel.is-on { animation: none; }
  .room.tv-off .crt { animation: fade-out .2s forwards; }
  .room.tv-warming .crt { animation: none; }
  .room.tv-off .afterglow { animation: none; }
  .sound-toggle.is-locked { animation: none; }
  @keyframes fade-out { to { opacity: 0; } }
}
