/* santillan.io — SNES-aesthetic landing page
   --------------------------------------------
   The "screen" (canvas) is pixel-locked and integer-scaled: 384×256 (3:2)
   in landscape, 256×384 (2:3) in portrait — app.js swaps the backing
   resolution off the same (orientation) media query, so CSS and canvas
   always agree. The bezel, stand, and console around it are higher-res CSS
   chrome — framing, not content.

   Layout modes (vertical space decides where the controls go):
   - Desktop / tablet, landscape with room to spare: TV centered, pad at
     the bottom.
   - Landscape phone (short viewport): screen pulled left, all controls
     stacked on the right.
   - Portrait anything: screen on top, pad below — handheld. */

:root {
  --bg: #0a0a0a;
  --wall: #1a1410;
  --wood-1: #3a2515;
  --wood-2: #2a1a0d;
  --wood-3: #4a3020;
  --bezel-1: #1a1a1f;
  --bezel-2: #2a2a30;
  --bezel-hi: #4a4a55;
  --screen-bg: #000;
  --snes-grey-1: #d8d4ce;
  --snes-grey-2: #b8b4ae;
  --snes-grey-3: #6a6863;
  --snes-purple: #4a3a6a;
  --snes-purple-d: #2a1a3a;

  --pixel-font: "Press Start 2P", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: #eaeaea;
  font-family: var(--pixel-font);
  overflow: hidden;
  /* Subtle radial wall behind the TV. */
  background:
    radial-gradient(ellipse at 50% 35%, #2a1a14 0%, #14100c 55%, #050402 100%);
}

/* Screen-reader / SEO content. Visually hidden but present. */
.sr-content {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- Room */

.room {
  position: relative;
  height: 100%;
  width: 100%;
  display: grid;
  /* Desktop default: TV row + pad row. */
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  align-items: center;
  row-gap: 4px;
  padding: 1.5vh 2vw calc(10px + env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------------- TV */

.tv {
  position: relative;
  grid-row: 1;
  /* Width-driven sizing; the vh term keeps the whole set (bezel + stand)
     plus the bottom pad inside the viewport. */
  width: min(80vw, calc((100vh - 200px) * 1.15));
  display: grid;
  grid-template-rows: 1fr auto;
}

.tv-bezel {
  position: relative;
  background:
    linear-gradient(180deg, var(--bezel-2) 0%, var(--bezel-1) 100%);
  border-radius: 2.2% / 2.6%;
  padding: 4.5% 5% 6%;
  box-shadow:
    inset 0 0 0 0.4cqw rgba(255,255,255,0.04),
    inset 0 0 0 1.2cqw rgba(0,0,0,0.5),
    0 2cqw 5cqw rgba(0,0,0,0.7);
}

/* Subtle plastic highlights on the bezel. */
.tv-bezel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255,255,255,0.07), transparent 60%),
    radial-gradient(100% 40% at 50% 100%, rgba(0,0,0,0.4), transparent 70%);
  pointer-events: none;
}

.tv-screen {
  position: relative;
  width: 100%;
  aspect-ratio: 384 / 256;
  /* The engine's tap-to-select-then-tap-to-confirm pattern is a double-tap;
     without this iOS Safari intercepts it as a zoom gesture. */
  touch-action: manipulation;
  background: var(--screen-bg);
  border-radius: 1.5% / 1.7%;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 0.3cqw #000,
    inset 0 0 6cqw rgba(0,0,0,0.9);
}

/* Faint phosphor-purple idle glow — a slow breathing pulse on the screen
   housing. Purely decorative; off entirely if the visitor prefers reduced
   motion. */
@media (prefers-reduced-motion: no-preference) {
  .tv-screen {
    animation: tv-glow-pulse 6s ease-in-out infinite;
  }
}
@keyframes tv-glow-pulse {
  0%, 100% {
    box-shadow:
      inset 0 0 0 0.3cqw #000,
      inset 0 0 6cqw rgba(0,0,0,0.9),
      0 0 2cqw rgba(140,100,220,0.14);
  }
  50% {
    box-shadow:
      inset 0 0 0 0.3cqw #000,
      inset 0 0 6cqw rgba(0,0,0,0.9),
      0 0 3.6cqw rgba(140,100,220,0.32);
  }
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* Subtle barrel-ish curvature via transform; full warp is in JS later. */
  filter: saturate(1.05) contrast(1.05);
  cursor: default;
}

/* CRT overlay — scanlines, vignette, faint horizontal mask.
   Sits on top of the canvas; pointer-events: none. */
.crt-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  background:
    /* Scanlines */
    repeating-linear-gradient(
      to bottom,
      rgba(0,0,0,0) 0,
      rgba(0,0,0,0) 2px,
      rgba(0,0,0,0.22) 2px,
      rgba(0,0,0,0.22) 3px
    ),
    /* Faint RGB mask */
    repeating-linear-gradient(
      to right,
      rgba(255,0,0,0.04) 0,
      rgba(255,0,0,0.04) 1px,
      rgba(0,255,0,0.04) 1px,
      rgba(0,255,0,0.04) 2px,
      rgba(0,0,255,0.04) 2px,
      rgba(0,0,255,0.04) 3px
    ),
    /* Vignette */
    radial-gradient(120% 100% at 50% 50%, transparent 55%, rgba(0,0,0,0.55) 100%);
  mix-blend-mode: multiply;
  opacity: 0.85;
}

.tv-brand {
  position: absolute;
  bottom: 1.8%;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(8px, 1.1cqw, 14px);
  letter-spacing: 0.2em;
  color: var(--bezel-hi);
  text-shadow: 0 1px 0 #000;
  user-select: none;
}

.tv-stand {
  margin: 1.5cqw auto 0;
  width: 36%;
  height: 4.5cqw;
  background:
    linear-gradient(180deg, var(--wood-3) 0%, var(--wood-1) 60%, var(--wood-2) 100%);
  border-radius: 0.6cqw 0.6cqw 0.3cqw 0.3cqw / 50% 50% 30% 30%;
  box-shadow: 0 1cqw 2cqw rgba(0,0,0,0.6);
}

/* ---------------------------------------------------------------- SNES */

.snes {
  position: absolute;
  right: 4vw;
  bottom: 4vh;
  width: min(22vw, 260px);
  aspect-ratio: 2.4 / 1;
  display: grid;
  place-items: center;
}

.snes-body {
  width: 100%; height: 100%;
  background: linear-gradient(180deg, var(--snes-grey-1) 0%, var(--snes-grey-2) 100%);
  border-radius: 6% / 14%;
  box-shadow:
    inset 0 -0.5cqw 0 rgba(0,0,0,0.15),
    inset 0 0.4cqw 0 rgba(255,255,255,0.35),
    0 1cqw 2cqw rgba(0,0,0,0.5);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4%;
  padding: 6% 8%;
  align-items: center;
}

.snes-slot {
  background: var(--snes-grey-3);
  border-radius: 4%;
  height: 80%;
  padding: 6%;
  box-shadow: inset 0 0.3cqw 0.6cqw rgba(0,0,0,0.5);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.snes-cart {
  width: 100%; height: 100%;
  background: linear-gradient(180deg, #c8b4e0 0%, #8a6ab0 100%);
  border-radius: 6%;
  display: grid; place-items: center;
  color: #1a0a2a;
  font-size: clamp(6px, 0.7vw, 10px);
  letter-spacing: 0.1em;
  text-align: center;
  padding: 4%;
  transition: background 200ms ease;
  user-select: none;
}

.snes-buttons {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 12%;
  height: 60%;
  aspect-ratio: 1 / 2;
}
.snes-buttons span {
  display: block;
  background: var(--snes-purple-d);
  border-radius: 50%;
  box-shadow: inset 0 0.2cqw 0.4cqw rgba(0,0,0,0.6);
}

/* ---------------------------------------------------------------- Power-on
   Initial overlay covering the whole viewport. User taps POWER to start —
   that's the gesture browsers require before audio can play. Until then,
   the engine isn't running and nothing has rendered to the canvas. */

.powerup {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 40%, #1a0e30 0%, #060414 60%, #000 100%);
  animation: powerup-fade-in 240ms ease-out;
}
.powerup.hide {
  animation: powerup-fade-out 280ms ease-in forwards;
  pointer-events: none;
}
@keyframes powerup-fade-in  { from { opacity: 0 } to { opacity: 1 } }
@keyframes powerup-fade-out { to   { opacity: 0; transform: scale(0.98); } }

.powerup-screen {
  display: grid;
  gap: 18px;
  justify-items: center;
  padding: 32px 40px;
  background: linear-gradient(180deg, #1a0e36 0%, #0a0620 100%);
  border: 2px solid #2a1a4a;
  box-shadow:
    inset 0 0 0 2px #0a0418,
    inset 0 2px 0 rgba(255,255,255,0.06),
    0 0 40px rgba(180,140,255,0.18);
  border-radius: 4px;
  font-family: var(--pixel-font);
  color: var(--snes-grey-1);
}

.powerup-title {
  font-size: 14px;
  color: #ffd86b;
  letter-spacing: 0.08em;
  text-shadow: 2px 2px 0 #2a1a05, 0 0 12px rgba(255,216,107,0.4);
}
.powerup-sub {
  font-size: 8px;
  color: #a8a4c8;
  letter-spacing: 0.18em;
  margin-bottom: 6px;
}

/* Big chunky pixel-art checkbox. */
.powerup-check {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  font-size: 10px;
  color: #d8d4ce;
  padding: 8px 4px;
}
.powerup-check input {
  /* Visually hidden, still accessible via keyboard. */
  position: absolute;
  width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.powerup-check-box {
  width: 20px; height: 20px;
  background: #0a0418;
  box-shadow:
    inset 0 0 0 2px #c8b0e8,
    inset 0 0 0 3px #3a2068;
  display: grid;
  place-items: center;
  position: relative;
}
.powerup-check-box::after {
  /* Checkmark — pixel-art-style chunky X */
  content: "";
  width: 12px; height: 12px;
  background:
    linear-gradient(45deg, transparent 42%, #7ce078 42%, #7ce078 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, #7ce078 42%, #7ce078 58%, transparent 58%);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 80ms ease, transform 120ms cubic-bezier(0.3, 1.6, 0.5, 1);
}
.powerup-check input:checked + .powerup-check-box::after {
  opacity: 1;
  transform: scale(1);
}
.powerup-check input:focus-visible + .powerup-check-box {
  outline: 2px dashed #ffd86b;
  outline-offset: 2px;
}

/* Power button — chunky SNES-purple plastic. */
.powerup-btn {
  appearance: none;
  border: 0;
  font-family: var(--pixel-font);
  font-size: 14px;
  color: #fff;
  background: linear-gradient(180deg, #8a6ab0 0%, #4a3a6a 100%);
  padding: 16px 32px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  letter-spacing: 0.1em;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
  box-shadow:
    inset 0 3px 0 rgba(255,255,255,0.2),
    inset 0 -4px 0 rgba(0,0,0,0.4),
    0 4px 0 #2a1a3a,
    0 0 24px rgba(180,140,255,0.3);
  transition: transform 60ms ease, box-shadow 60ms ease;
  border-radius: 2px;
}
.powerup-btn:hover { filter: brightness(1.08); }
.powerup-btn:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 3px 0 rgba(255,255,255,0.2),
    inset 0 -4px 0 rgba(0,0,0,0.4),
    0 1px 0 #2a1a3a;
}
.powerup-btn:focus-visible {
  outline: 2px solid #ffd86b;
  outline-offset: 4px;
}
.powerup-btn-glyph {
  font-size: 10px;
  color: #ffd86b;
  animation: powerup-blink 1s steps(2) infinite;
}
@keyframes powerup-blink { 50% { opacity: 0.3 } }

.powerup-hint {
  font-size: 7px;
  color: #6a5890;
  letter-spacing: 0.15em;
  margin-top: 4px;
}

/* ---------------------------------------------------------------- Audio toggle */

.audio-toggle {
  position: absolute;
  top: 1.5vh; right: 1.5vw;
  width: 44px; height: 44px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.4);
  color: #eaeaea;
  font-family: var(--pixel-font);
  font-size: 18px;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0.5;
  transition: opacity 200ms ease, background 200ms ease;
}
.audio-toggle:hover { opacity: 1; background: rgba(0,0,0,0.7); }
.audio-toggle.on    { color: #ffd86b; opacity: 1; }

/* ---------------------------------------------------------------- Pad
   On-screen handheld controls — always visible, placement depends on the
   layout mode (bottom row on desktop/tablet/portrait, right column on
   landscape phones). D-pad on left, A/B on right, SELECT/START pills
   below. Pixel-art via CSS — no images. Wired to the same input handler
   as the keyboard. */

.pad {
  display: grid;
  grid-row: 2;
  width: 100%;
  max-width: 520px;
  padding: 4px 14px max(4px, env(safe-area-inset-bottom));
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 10px 24px;
  align-items: end;
  justify-items: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}


/* D-pad — pixel-art cross built from a 3x3 grid of squares.
   Compact by default (desktop, keyboard-first); touch layouts scale it up. */
.pad-dpad {
  position: relative;
  width: 108px; height: 108px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}
.pad-d {
  appearance: none;
  border: 0;
  background: var(--snes-grey-3, #6a6863);
  color: transparent;
  padding: 0;
  cursor: pointer;
  position: relative;
  box-shadow:
    inset 0 4px 0 rgba(255,255,255,0.18),
    inset 0 -4px 0 rgba(0,0,0,0.45);
  transition: filter 60ms ease;
}
.pad-d::before {
  /* Direction arrow — a small light pixel triangle. */
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(transparent, transparent);
  /* Filled in per-direction below via the triangle hack. */
}
.pad-d-up    { grid-column: 2; grid-row: 1; border-radius: 8px 8px 0 0; }
.pad-d-left  { grid-column: 1; grid-row: 2; border-radius: 8px 0 0 8px; }
.pad-d-right { grid-column: 3; grid-row: 2; border-radius: 0 8px 8px 0; }
.pad-d-down  { grid-column: 2; grid-row: 3; border-radius: 0 0 8px 8px; }
.pad-d-center {
  grid-column: 2; grid-row: 2;
  background: var(--snes-grey-3, #6a6863);
  box-shadow:
    inset 0 0 0 2px rgba(0,0,0,0.25);
  position: relative;
}
.pad-d-center::after {
  /* Small notch dot in the center for that real-d-pad feel. */
  content: "";
  position: absolute;
  inset: 38% 38%;
  background: rgba(0,0,0,0.35);
  border-radius: 2px;
}
.pad-d:active { filter: brightness(0.65); }

/* Direction arrows — chunky pixel triangles, drawn via clip-path. */
.pad-d-up::before    { background: #d8d4ce; clip-path: polygon(50% 28%, 78% 65%, 22% 65%); }
.pad-d-down::before  { background: #d8d4ce; clip-path: polygon(22% 35%, 78% 35%, 50% 72%); }
.pad-d-left::before  { background: #d8d4ce; clip-path: polygon(28% 50%, 65% 22%, 65% 78%); }
.pad-d-right::before { background: #d8d4ce; clip-path: polygon(35% 22%, 35% 78%, 72% 50%); }

/* A / B buttons — round, SNES-purple, hardware shadow. */
.pad-ab {
  display: grid;
  grid-template-columns: auto auto;
  gap: 24px;
  align-items: end;
  transform: rotate(-18deg);
  transform-origin: center;
  padding: 8px 0;
}
.pad-btn {
  appearance: none;
  width: 48px; height: 48px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-family: var(--pixel-font);
  font-size: 14px;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0,0,0,0.5);
  box-shadow:
    inset 0 4px 0 rgba(255,255,255,0.25),
    inset 0 -6px 0 rgba(0,0,0,0.45),
    0 4px 0 rgba(0,0,0,0.3);
  display: grid;
  place-items: center;
  transition: transform 60ms ease, filter 60ms ease;
}
.pad-btn:active { transform: translateY(2px); filter: brightness(0.85); }
.pad-a { background: #c84050; }   /* red, like SNES A */
.pad-b { background: #ffd86b; color: #2a1a05; }  /* yellow, like SNES B */
.pad-btn span { line-height: 1; pointer-events: none; }

/* SELECT / START pills. */
.pad-startselect {
  grid-column: 1 / -1;
  display: flex;
  gap: 18px;
  justify-content: center;
  transform: rotate(-4deg);
  padding-top: 4px;
}
.pad-pill {
  appearance: none;
  border: 0;
  background: #4a4655;
  color: #d8d4ce;
  font-family: var(--pixel-font);
  font-size: 8px;
  letter-spacing: 0.1em;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,0.18),
    inset 0 -3px 0 rgba(0,0,0,0.4),
    0 2px 0 rgba(0,0,0,0.3);
  transition: transform 60ms ease, filter 60ms ease;
}
.pad-pill:active { transform: translateY(1px); filter: brightness(0.85); }

/* ------------------------------------------------------- Decorative console
   The little SNES in the corner only earns its place on wide desktops
   where it doesn't crowd the functional pad. */

@media (max-width: 1100px), (pointer: coarse) {
  .snes { display: none; }
}

/* ---------------------------------------------------------------- Portrait
   Phones, tablets, and portrait monitors: 2:3 screen on top, pad below —
   a handheld. The canvas backing store flips to 256×384 in app.js off the
   same media query. */

@media (orientation: portrait) {
  .tv-screen { aspect-ratio: 256 / 384; }
  .tv-stand { display: none; }

  .room {
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: center;
    padding: max(1.5vh, env(safe-area-inset-top)) 1vw max(10px, env(safe-area-inset-bottom));
    row-gap: 1vh;
  }
  .tv {
    /* Height-bound: bezel adds ~10.5% of its width vertically, screen is
       1.5× width tall; leave ~215px for the pad. */
    width: min(96vw, calc((100vh - 235px) * 0.64));
  }

  /* Touch sizing. */
  .pad { max-width: 560px; gap: 12px 24px; padding: 6px 14px max(12px, env(safe-area-inset-bottom)); }
  .pad-dpad { width: 138px; height: 138px; }
  .pad-btn  { width: 58px;  height: 58px; font-size: 16px; }

  .audio-toggle { top: max(1.5vh, env(safe-area-inset-top)); }
}

/* ---------------------------------------------------- Landscape, but short
   A phone held sideways: not enough height for controls under a 3:2
   screen, so the screen pulls left and every control stacks in a right
   column — D-pad on top, A/B under it, SELECT/START at the bottom. */

@media (orientation: landscape) and (max-height: 620px) {
  .tv-stand { display: none; }

  .room {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 100%;
    align-items: center;
    justify-items: center;
    column-gap: max(2vw, 16px);
    padding: 1vh max(2vw, env(safe-area-inset-right)) 1vh max(2vw, env(safe-area-inset-left));
  }

  .tv {
    grid-column: 1; grid-row: 1;
    /* Height-bound: bezel total ≈ 0.75× its width. */
    width: min(72vw, 122vh);
  }

  /* Right-hand control column. */
  .pad {
    grid-column: 2; grid-row: 1;
    width: auto; max-width: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: max(2.5vh, 10px);
    padding: 0 0 env(safe-area-inset-bottom);
  }
  .pad-dpad { width: min(30vh, 132px); height: min(30vh, 132px); }
  .pad-ab   { transform: rotate(-14deg); gap: 16px; padding: 0; }
  .pad-btn  { width: min(14vh, 56px); height: min(14vh, 56px); font-size: 14px; }
  .pad-startselect { transform: none; padding-top: 0; gap: 10px; }
  .pad-pill { font-size: 7px; padding: 6px 10px; }

  .audio-toggle {
    top: max(1vh, env(safe-area-inset-top));
    right: max(1vw, env(safe-area-inset-right));
    width: 36px; height: 36px;
    font-size: 14px;
  }
}

/* Very short landscape (notched phones): tighten further. */
@media (orientation: landscape) and (max-height: 400px) {
  .tv { width: min(70vw, 118vh); }
  .pad-dpad { width: 27vh; height: 27vh; }
  .pad-btn { width: 12vh; height: 12vh; font-size: 12px; }
  .pad { gap: 2vh; }
}

/* Reduce motion: kill the CRT roll / sparkle animations (engine reads this). */
@media (prefers-reduced-motion: reduce) {
  .crt-overlay { opacity: 0.5; }
}
