/* ═══════════════════════════════════════════════════════════
   5-in-1 GAME STICK — Mobile Only
   Layout : Header (fixed) | Screen 70% | Controller 30%
   Control: D-pad 49% | Center 20% | A/B 40%
   D-pad  : True 3×3 CSS Grid cross — all arms equal
═══════════════════════════════════════════════════════════ */

/* ── TOKENS ── */
:root {
  --gs-bg:          #0d0d1a;
  --gs-header-h:    44px;
  --gs-accent:      #7c3aed;

  --gs-dpad-face:   #252540;
  --gs-dpad-press:  #4a4a80;
  --gs-dpad-border: rgba(255,255,255,0.13);
  --gs-dpad-shadow: #08080f;

  --gs-a-face:      #dc2626;
  --gs-a-shadow:    #7f1d1d;
  --gs-a-glow:      rgba(220,38,38,0.5);
  --gs-b-face:      #ca8a04;
  --gs-b-shadow:    #78350f;
  --gs-b-glow:      rgba(202,138,4,0.5);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button {
  font-family: inherit; cursor: pointer; border: none; outline: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}

/* ── BODY ── */
.gs-body {
  background: var(--gs-bg);
  font-family: 'Inter', sans-serif;
  /*
   * --gs-vh = visualViewport.height set by JS.
   * This is the ONLY value that correctly excludes Android system nav bar
   * AND browser chrome on first paint. CSS units (svh/dvh) both miss this.
   */
  height: var(--gs-vh, 100svh);
  padding-top:   env(safe-area-inset-top);
  padding-left:  env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ══════════════════════════════════════════════
   HEADER
══════════════════════════════════════════════ */
.gs-header {
  height: var(--gs-header-h);
  flex-shrink: 0;
  background: linear-gradient(135deg, #1e1b4b 0%, #1a1a2e 100%);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  z-index: 10;
}

.gs-back {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: #a5b4fc;
  text-decoration: none;
  flex-shrink: 0;
}

.gs-header-title {
  flex: 1;
  font-family: 'Orbitron', monospace;
  font-size: 18px;
  font-weight: 800;
  color: #c4b5fd;
  letter-spacing: 0.15em;
  text-align: center;
  text-shadow: 0 0 16px rgba(124,58,237,0.7);
}

/* ══════════════════════════════════════════════
   SHELL
   Uses --gs-shell-h (set by JS = visualViewport.height - header)
   so the 70:30 split is of the TRUE available zone only —
   no system nav bar, no browser chrome.
══════════════════════════════════════════════ */
.gs-shell {
  /* Explicit height from JS — never rely on flex remainder */
  height: var(--gs-shell-h, calc(100svh - var(--gs-header-h)));
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #1a1a2e 0%, #0f0f22 100%);
  overflow: hidden;
  border-left: 3px solid #08080f;
  border-right: 3px solid #08080f;
}

/* ══════════════════════════════════════════════
   SCREEN — top 70%
══════════════════════════════════════════════ */
.gs-screen-wrap {
  flex: 7;
  display: flex; align-items: center; justify-content: center;
  padding: 10px 12px 6px;
}

.gs-bezel {
  width: 100%; height: 100%;
  background: #0a0a18;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.06);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.6), 0 4px 16px rgba(0,0,0,0.5);
  padding: 8px;
  display: flex; align-items: center; justify-content: center;
}

.gs-screen {
  width: 100%; height: 100%;
  background: #050510;
  border-radius: 8px;
  position: relative; overflow: hidden;
  box-shadow: inset 0 0 40px rgba(124,58,237,0.06);
}

/* Splash */
.gs-splash {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px; padding: 12px;
}
.gs-splash-logo {
  font-size: 36px;
  filter: drop-shadow(0 0 12px rgba(124,58,237,0.8));
  animation: gs-float 3s ease-in-out infinite;
}
@keyframes gs-float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.gs-splash-title {
  font-family: 'Orbitron', monospace;
  font-size: clamp(13px, 4vw, 18px); font-weight: 800;
  color: #c4b5fd; letter-spacing: 0.06em;
  text-shadow: 0 0 16px rgba(124,58,237,0.7);
}
.gs-splash-hint { font-size: 11px; color: #4b5563; margin-bottom: 8px; }

.gs-game-slots {
  display: flex; flex-direction: column; gap: 5px;
  width: 100%; max-width: 240px;
}
.gs-slot {
  display: none;   /* hidden until a game registers into this slot */
  align-items: center; gap: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.gs-slot.has-game {
  display: flex;   /* appears the moment register() adds this class */
  background: rgba(124,58,237,0.12);
  border-color: rgba(124,58,237,0.35);
  cursor: pointer;
}
.gs-slot.active-slot {
  background: rgba(124,58,237,0.28);
  border-color: rgba(124,58,237,0.7);
}
.gs-slot-num  { font-size: 16px; }
.gs-slot-name { font-size: 12px; color: #6b7280; font-style: italic; }
.gs-slot.has-game   .gs-slot-name { color: #c4b5fd; font-style: normal; font-weight: 500; }
.gs-slot.active-slot .gs-slot-name { color: #e9d5ff; font-style: normal; font-weight: 700; }

.gs-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: none;
}
.gs-canvas.active { display: block; }

/* ══════════════════════════════════════════════
   CONTROLLER — bottom 30%
══════════════════════════════════════════════ */
.gs-controller {
  flex: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 8px;
  border-top: 2px solid #08080f;
  background: linear-gradient(180deg, #141428 0%, #111124 100%);
  position: relative;
  overflow: hidden;
}

.gs-controller::before {
  content: '';
  position: absolute; top: 0; left: 8%; right: 8%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(124,58,237,0.3), transparent);
}

/* ──────────────────────────────────────────────
   COLUMNS — D-pad 49% | Right (start/reset + A/B) 51%
────────────────────────────────────────────── */
.gs-col {
  display: flex; align-items: center; justify-content: center;
  height: 100%; min-width: 0; overflow: hidden;
}
.gs-col-dpad  { flex: 49 0 0; }
.gs-col-right {
  flex: 51 0 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 0;
}

/* ══════════════════════════════════════════════
   D-PAD — NES Classic unified cross
   ─────────────────────────────────────────────
   Visual trick: ALL cross cells share the same
   flat base colour (#232336). Each arm's outer
   face is lighter (bevel via per-arm gradient).
   The 4 corner cells are transparent → the grid
   container's filter:drop-shadow() draws one
   shadow around the whole cross shape.
   Result: looks like one solid moulded piece.
══════════════════════════════════════════════ */
.gs-dpad {
  display: grid;
  grid-template-rows:    1fr 1fr 1fr;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  width:  min(134px, 82%);
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
  position: relative;
  /* Shadow wraps entire cross as one silhouette */
  filter:
    drop-shadow(0 6px 14px rgba(0,0,0,0.95))
    drop-shadow(0 2px 4px  rgba(0,0,0,0.7));
}

/* ── Grid placement ── */
.gs-dpad-up     { grid-area: 1 / 2; border-radius: 10px 10px 0 0; }
.gs-dpad-left   { grid-area: 2 / 1; border-radius: 10px 0 0 10px; }
.gs-dpad-center { grid-area: 2 / 2; position: relative; z-index: 0; }
.gs-dpad-right  { grid-area: 2 / 3; border-radius: 0 10px 10px 0; }
.gs-dpad-down   { grid-area: 3 / 2; border-radius: 0 0 10px 10px; }

/* ── Center — same base colour + a sunken circular dot ── */
.gs-dpad-center {
  background: #232336;
}
.gs-dpad-center::after {
  content: '';
  position: absolute;
  inset: 20%;
  border-radius: 50%;
  background: #131320;
  box-shadow:
    inset 0 2px 5px rgba(0,0,0,0.9),
    inset 0 1px 2px rgba(0,0,0,0.6);
}

/* ── All arm buttons — base colour + outer-face bevel ── */
.gs-dpad-btn {
  width: 100%; height: 100%;
  border: none;
  color: rgba(255,255,255,0.38);
  display: flex; align-items: center; justify-content: center;
  z-index: 1;
  position: relative;
  transition: filter 0.07s;
}

/* Each arm: lighter on its own outer face → sunken-3D bevel illusion */
.gs-dpad-up    { background: linear-gradient(to bottom, #363650 0%, #232336 50%); }
.gs-dpad-left  { background: linear-gradient(to right,  #363650 0%, #232336 50%); }
.gs-dpad-right { background: linear-gradient(to left,   #363650 0%, #232336 50%); }
.gs-dpad-down  { background: linear-gradient(to top,    #1a1a2a 0%, #232336 50%); }

.gs-dpad-btn svg { width: 12px; height: 12px; }

/* Press: brighten the whole arm uniformly — no seam between cells */
.gs-dpad-btn:active,
.gs-dpad-btn.pressed {
  filter: brightness(1.55);
  color: rgba(255,255,255,0.9);
}

/* ══════════════════════════════════════════════
   START / RESET — above A/B circle
   Long-press protected during gameplay
══════════════════════════════════════════════ */
.gs-action-row {
  display: flex;
  flex-direction: row;      /* side by side */
  gap: 6px;
  align-items: center;
  width: min(120px, 88%);
  margin-bottom: 6px;       /* breathing room above A/B circle */
}

.gs-pill-btn {
  position: relative;
  flex: 1;
  padding: 5px 4px;
  border-radius: 20px;
  font-size: 8px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase;
  background: #1e1e38;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 3px 0 #08080f, inset 0 1px 0 rgba(255,255,255,0.07);
  overflow: hidden;
  transition: transform 0.08s, box-shadow 0.08s;
}
.gs-pill-btn:active, .gs-pill-btn.pressed {
  box-shadow: 0 1px 0 #08080f;
  transform: translateY(2px);
}
.gs-btn-start .gs-pill-label { color: #86efac; }
.gs-btn-reset .gs-pill-label { color: #fca5a5; }

/* Hold-progress SVG ring — visible only during long-press in gameplay */
.gs-hold-ring {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
}
.gs-hold-track {
  fill: none;
  stroke: rgba(255,255,255,0.1);
  stroke-width: 3;
}
.gs-hold-progress {
  fill: none;
  stroke: #a78bfa;
  stroke-width: 3;
  stroke-linecap: round;
  /* circumference of r=15 circle ≈ 94.25 */
  stroke-dasharray: 94.25;
  stroke-dashoffset: 94.25;     /* starts empty */
  transform-origin: center;
  transform: rotate(-90deg);
  transition: stroke-dashoffset linear;
}

/* When holding — show ring + animate fill */
.gs-pill-btn.gs-holding .gs-hold-ring      { opacity: 1; }
.gs-pill-btn.gs-holding .gs-hold-progress  {
  stroke-dashoffset: 0;
  /* duration set inline by JS to match LONG_PRESS_MS */
}

/* ══════════════════════════════════════════════
   A & B CLUSTER — circular pad, right column
══════════════════════════════════════════════ */
.gs-ab-cluster {
  position: relative;
  /* Square circle — fits inside column, never overflows */
  width: min(120px, 88%);
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #1e1e3a, #0e0e1e);
  box-shadow:
    0 6px 20px rgba(0,0,0,0.8),
    inset 0 2px 6px rgba(255,255,255,0.05),
    inset 0 -3px 6px rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
}

.gs-ab-btn {
  position: absolute;
  /* 36% of cluster diameter — both buttons equal */
  width: 36%; height: 36%;
  border-radius: 50%;
  font-family: 'Orbitron', monospace;
  font-size: clamp(10px, 3vw, 14px);
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.08s;
}

/* A — top-right */
.gs-btn-a {
  background: radial-gradient(circle at 35% 35%, #f87171, var(--gs-a-face));
  color: #fff;
  top: 8%; right: 8%;
  box-shadow: 0 4px 0 var(--gs-a-shadow), 0 0 10px var(--gs-a-glow),
              inset 0 1px 0 rgba(255,255,255,0.3);
}
.gs-btn-a:active, .gs-btn-a.pressed {
  box-shadow: 0 1px 0 var(--gs-a-shadow), 0 0 6px var(--gs-a-glow);
  transform: translateY(3px);
}

/* B — bottom-left */
.gs-btn-b {
  background: radial-gradient(circle at 35% 35%, #fbbf24, var(--gs-b-face));
  color: #1a0800;
  bottom: 8%; left: 8%;
  box-shadow: 0 4px 0 var(--gs-b-shadow), 0 0 10px var(--gs-b-glow),
              inset 0 1px 0 rgba(255,255,255,0.3);
}
.gs-btn-b:active, .gs-btn-b.pressed {
  box-shadow: 0 1px 0 var(--gs-b-shadow), 0 0 6px var(--gs-b-glow);
  transform: translateY(3px);
}

/* ── TURBO TOGGLE — fixed bottom-right corner ── */
.gs-turbo-btn {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  right: 10px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: #0e0e1e;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 5px 7px 4px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.gs-turbo-btn:active { background: #1a1a33; }

/* LED indicator dot */
.gs-turbo-led {
  display: block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #2a2a40;          /* OFF = dark */
  box-shadow: none;
  transition: background 0.2s, box-shadow 0.2s;
}

/* TURBO label */
.gs-turbo-label {
  font-family: 'Orbitron', monospace;
  font-size: 6px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #4a4a70;
  transition: color 0.2s;
}

/* ── ON state (toggled via JS) ── */
.gs-turbo-btn.turbo-on .gs-turbo-led {
  background: #22ff88;
  box-shadow: 0 0 6px #22ff88, 0 0 12px #22ff8866;
}
.gs-turbo-btn.turbo-on .gs-turbo-label {
  color: #22ff88;
}

/* ══════════════════════════════════════════════
   SCORE BAR (injected by games)
══════════════════════════════════════════════ */
.gs-score-bar {
  position: absolute; top: 0; left: 0; right: 0; height: 28px;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px;
  font-family: 'Orbitron', monospace; font-size: 11px; color: #c4b5fd;
  z-index: 5; border-bottom: 1px solid rgba(124,58,237,0.2);
}

/* ══════════════════════════════════════════════
   GAME OVER / PAUSE OVERLAY
══════════════════════════════════════════════ */
.gs-overlay {
  position: absolute; inset: 0;
  background: rgba(5,5,16,0.88); backdrop-filter: blur(3px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; z-index: 20;
}
.gs-overlay-title {
  font-family: 'Orbitron', monospace;
  font-size: clamp(16px, 5vw, 24px); font-weight: 800;
  color: #c4b5fd; text-shadow: 0 0 20px rgba(124,58,237,0.8);
}
.gs-overlay-sub { font-size: 12px; color: #6b7280; }
.gs-overlay-actions { display: flex; gap: 10px; margin-top: 6px; }
.gs-overlay-btn {
  font-family: 'Orbitron', monospace; font-size: 10px; font-weight: 700;
  color: #e9d5ff; background: rgba(124,58,237,0.22);
  border: 1px solid rgba(124,58,237,0.55); border-radius: 8px;
  padding: 9px 16px; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none;
  transition: background 0.1s;
}
.gs-overlay-btn:active, .gs-overlay-btn.pressed { background: rgba(124,58,237,0.50); }

/* ══════════════════════════════════════════════
   WELCOME SCREEN (overlays the canvas)
   Shown after selecting a game, before START.
══════════════════════════════════════════════ */
.gs-welcome {
  background: rgba(4, 4, 18, 0.96);
  gap: 6px;
}
.gs-welcome-icon {
  font-size: 36px;
  filter: drop-shadow(0 0 14px rgba(124,58,237,0.9));
  animation: gs-float 2.8s ease-in-out infinite;
  margin-bottom: 4px;
}
@keyframes gs-float {
  0%,100% { transform: translateY(0);    }
  50%      { transform: translateY(-6px); }
}
.gs-welcome-title {
  font-family: 'Orbitron', monospace;
  font-size: clamp(15px, 5.5vw, 22px);
  font-weight: 800;
  color: #e9d5ff;
  letter-spacing: 0.08em;
  text-shadow: 0 0 24px rgba(124,58,237,0.8);
  margin-bottom: 6px;
}
.gs-welcome-controls {
  font-size: 10px;
  color: #4b5563;
  text-align: center;
  line-height: 1.6;
  max-width: 85%;
  margin-bottom: 14px;
}
.gs-welcome-cta {
  font-family: 'Orbitron', monospace;
  font-size: 11px;
  color: #86efac;
  letter-spacing: 0.12em;
  animation: gs-pulse 1.3s ease-in-out infinite;
}
.gs-welcome-back {
  font-size: 10px;
  color: #374151;
  margin-top: 4px;
  letter-spacing: 0.06em;
}
.gs-welcome-btn {
  color: #a78bfa;
  font-weight: 700;
}
@keyframes gs-pulse {
  0%,100% { opacity: 1;   }
  50%      { opacity: 0.2; }
}
