/* santillan.io — SNES-aesthetic landing page
   --------------------------------------------
   The "screen" (canvas) is pixel-locked at 256×224 logical, integer-scaled.
   The bezel, stand, and console around it are higher-res CSS chrome —
   they're framing, not content. */

: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;
  place-items: center;
  /* The room is just centering. The TV does all the visual work. */
}

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

.tv {
  position: relative;
  /* Scales with viewport, keeps everything proportional. */
  width: min(92vw, calc(92vh * 1.18));
  aspect-ratio: 1.18 / 1;
  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: 256 / 224;
  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);
}

#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);
}

/* 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. Hidden on desktop, revealed on mobile.
   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: none;
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 14px max(14px, env(safe-area-inset-bottom));
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 14px 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. */
.pad-dpad {
  position: relative;
  width: 144px; height: 144px;
  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: 64px; height: 64px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-family: var(--pixel-font);
  font-size: 18px;
  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); }

/* ---------------------------------------------------------------- Mobile */

@media (max-width: 820px), (pointer: coarse) and (max-height: 900px) {
  .snes { display: none; }
  .room {
    /* Stack TV near the top, pad anchored to the bottom. Tighter than
       a 1fr filler so they read as a single handheld unit. */
    grid-template-rows: auto 1fr;
    align-items: start;
    padding-top: max(2vh, env(safe-area-inset-top));
    gap: 2vh;
  }
  .tv {
    width: 98vw;
    grid-row: 1;
  }
  .pad {
    display: grid;
    grid-row: 2;
    align-self: end;
    padding: 8px 14px max(14px, env(safe-area-inset-bottom));
  }
  /* Pull the audio toggle in so it doesn't overlap the pad. */
  .audio-toggle { top: max(1.5vh, env(safe-area-inset-top)); }
}

/* Very tall narrow screens: phones in portrait. Give the pad more room. */
@media (max-width: 480px) {
  .tv { width: 100vw; }
  .pad-dpad { width: 132px; height: 132px; }
  .pad-btn { width: 56px; height: 56px; font-size: 16px; }
}

/* ---------------------------------------------------------------- Landscape
   Phones held sideways: Switch/PSP layout. TV center, d-pad on the left,
   A/B on the right, SELECT/START below. Height is the binding constraint. */

@media (orientation: landscape) and (max-height: 600px) {
  .snes { display: none; }

  .room {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 1fr auto;
    align-items: center;
    justify-items: center;
    padding: 1vh max(2vw, env(safe-area-inset-left)) max(1vh, env(safe-area-inset-bottom));
    column-gap: 2vw;
    row-gap: 0;
  }

  /* TV shrinks to fit height, width follows aspect ratio. */
  .tv {
    width: auto;
    height: min(94vh, calc(70vw / 1.18));
    grid-column: 2; grid-row: 1;
  }

  /* .pad becomes a passthrough so its children land in the room grid. */
  .pad {
    display: contents;
  }

  .pad-dpad {
    grid-column: 1; grid-row: 1;
    width: min(34vh, 160px); height: min(34vh, 160px);
  }
  .pad-ab {
    grid-column: 3; grid-row: 1;
    transform: rotate(0deg);
  }
  .pad-btn { width: min(16vh, 72px); height: min(16vh, 72px); }

  .pad-startselect {
    grid-column: 2; grid-row: 2;
    transform: rotate(0deg);
    padding-top: 6px;
  }

  .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: 420px) {
  .tv { height: 92vh; }
  .pad-dpad { width: 32vh; height: 32vh; }
  .pad-btn { width: 14vh; height: 14vh; font-size: 14px; }
  .pad-startselect { transform: scale(0.85); }
}

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