/* ==========================================================
   REX RUSH — styles
   Mobile-first, neo-brutalist pixel. 960×540 logical canvas
   letterboxed above a banner-ad strip.
   ========================================================== */

:root {
  --ink: #1A1A2E;
  --paper: #FFF8DC;
  --sky-top: #87CEEB;
  --sky-bottom: #FFE5B4;
  --pink: #E91E63;
  --gold: #FFD700;
  --aqua: #4ECDC4;
  --grass: #5BC85B;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  /* Banner-ad height — game canvas sits above this. Larger on tablet+. */
  --ad-h: 60px;
}
@media (min-width: 768px)  { :root { --ad-h: 72px; } }
@media (min-width: 1024px) { :root { --ad-h: 88px; } }

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: #1A1A2E;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- BOOT SPLASH ---------- */
#boot {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, #FFE5B4 0%, transparent 60%),
    linear-gradient(180deg, #87CEEB 0%, #b8e0f0 50%, #FFE5B4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 240ms ease;
}
#boot.hide { opacity: 0; pointer-events: none; visibility: hidden; }
#boot.gone { display: none; }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.boot-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(28px, 6vw, 56px);
  color: var(--ink);
  text-shadow: 4px 4px 0 var(--pink);
  letter-spacing: 0.02em;
}
.boot-bar {
  width: min(72vw, 360px);
  height: 22px;
  background: #fff;
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  position: relative;
  overflow: hidden;
}
.boot-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--pink) 0, var(--pink) 8px, #ff4682 8px, #ff4682 16px);
  transition: width 140ms linear;
}
.boot-pct { font-family: 'Press Start 2P', monospace; font-size: 11px; color: var(--ink); }

/* ---------- STAGE — fills everything above the ad banner ---------- */
#stage {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: calc(var(--ad-h) + var(--safe-b));
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 90% 70% at 50% 0%, #FFE5B4 0%, transparent 60%),
    linear-gradient(180deg, #87CEEB 0%, #2a2a48 100%);
}

#game {
  display: block;
  background: #87CEEB;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
  touch-action: none;
  user-select: none;
  border: 4px solid var(--ink);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.06), 12px 12px 0 var(--ink);
}

/* Mobile: no chrome around canvas — let it eat the stage. */
@media (max-width: 820px) {
  #game { border-width: 0; box-shadow: none; }
}

/* ---------- MOBILE HUD (always-visible pause + sound) ---------- */
.mobile-hud {
  position: absolute;
  display: none;
  top: max(52px, calc(12px + var(--safe-t)));
  left: calc(8px + var(--safe-l));
  gap: 6px;
  z-index: 25;
  pointer-events: none;
}
.mobile-hud.show { display: flex; }
.hud-btn {
  pointer-events: auto;
  appearance: none;
  background: rgba(255,255,255,0.55);
  border: 3px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.hud-icon {
  display: block;
  width: 22px;
  height: 22px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.hud-icon-pause {
  width: 16px;
  height: 20px;
}
.hud-icon-sound {
  width: 14px;
  height: 20px;
}
/* Muted state: dim the sound icon */
.hud-btn.is-off .hud-icon {
  opacity: 0.35;
  filter: grayscale(1);
}
/* Play icon swap handled via JS class */
.hud-btn.is-playing .hud-icon-pause {
  content: url("ui/icon_play.svg");
}
.hud-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
  background: var(--gold);
}
.hud-btn.is-off {
  background: rgba(26,26,46,0.35);
  color: rgba(255,255,255,0.6);
}

/* ---------- TOUCH CONTROLS ---------- */
#touch {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  z-index: 20;
}
#touch.show { display: block; }

/* Touch buttons: only visible on tablet & mobile screens */
@media (min-width: 1025px) {
  #touch { display: none !important; }
}

.touchBtn {
  position: absolute;
  width: 22vmin;
  height: 22vmin;
  max-width: 110px;
  max-height: 110px;
  min-width: 64px;
  min-height: 64px;
  border: 3px solid var(--ink);
  background: rgba(255,255,255,0.50);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  box-shadow: 4px 4px 0 var(--ink);
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(18px, 5vmin, 32px);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  touch-action: none;
  padding: 0;
  line-height: 1;
  gap: 3px;
}
.touchBtn small {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(8px, 2.2vmin, 12px);
  letter-spacing: 0.06em;
  opacity: 0.8;
}
.touchBtn:active {
  background: var(--pink);
  color: #fff;
  transform: translate(3px, 3px);
  box-shadow: 3px 3px 0 var(--ink);
}

.touchBtn-jump {
  right: calc(16px + var(--safe-r));
  bottom: calc(16px + var(--safe-b));
}
.touchBtn-duck {
  left: calc(16px + var(--safe-l));
  bottom: calc(16px + var(--safe-b));
}

/* Settings: controller layout swap */
body.controller-swap .touchBtn-jump {
  right: auto;
  left: calc(16px + var(--safe-l));
}
body.controller-swap .touchBtn-duck {
  left: auto;
  right: calc(16px + var(--safe-r));
}

/* ---------- TWEAKS / WARDROBE / SETTINGS PANELS ---------- */
.panel,
.tweaks-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: min(94vw, 660px);
  max-height: min(86vh, calc(100dvh - var(--ad-h) - 20px));
  overflow: auto;
  background: #FFF8DC;
  border: 4px solid #1A1A2E;
  box-shadow: 10px 10px 0 #1A1A2E;
  z-index: 100;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: #1A1A2E;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  display: none;
  transition: opacity 140ms ease, transform 140ms ease;
}
.panel.show,
.tweaks-panel.show {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  display: block;
  transform: translate(-50%, -50%) scale(1);
}
.tp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #E91E63;
  color: #FFF8DC;
  border-bottom: 4px solid #1A1A2E;
}
.tp-header-wardrobe { background: #5BC85B; color: #1A1A2E; }
.tp-header-settings { background: #FFD93D; color: #1A1A2E; }
.tp-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  letter-spacing: 0.04em;
}
.tp-close {
  appearance: none;
  background: #FFF8DC;
  color: #1A1A2E;
  border: 3px solid #1A1A2E;
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  width: 40px;
  height: 40px;
  line-height: 32px;
  cursor: pointer;
  padding: 0;
  box-shadow: 3px 3px 0 #1A1A2E;
}
.tp-close:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #1A1A2E;
}
.tp-progress-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 4px solid #1A1A2E;
  background: #fff;
}
.tp-prog {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  border: 3px solid #1A1A2E;
  background: #FFF8DC;
  box-shadow: 3px 3px 0 #1A1A2E;
}
.tp-prog-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  letter-spacing: 0.06em;
  color: #1A1A2E;
}
.tp-prog-val {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: #E91E63;
  margin-top: 4px;
}
.tp-body { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 16px; }
.tp-section { display: flex; flex-direction: column; gap: 8px; }
.tp-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
}
.tp-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Grid of skin/hat cards in the wardrobe */
.tp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
@media (max-width: 480px) {
  .tp-grid { grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 8px; }
}
.tp-card {
  appearance: none;
  background: #fff;
  border: 3px solid #1A1A2E;
  box-shadow: 3px 3px 0 #1A1A2E;
  padding: 0;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 80ms ease;
}
.tp-card:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 #1A1A2E; }
.tp-card:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #1A1A2E; }
.tp-card.is-on  { background: #FFD93D; }
.tp-card.is-locked {
  filter: grayscale(0.75);
  opacity: 0.65;
  cursor: default;
  position: relative;
}
.tp-card.is-locked::after {
  content: '🔒';
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 14px;
  line-height: 1;
  pointer-events: none;
}
.tp-card.is-locked .tp-card-art {
  filter: brightness(0.75);
}
.tp-card.is-locked:hover { transform: none; box-shadow: 3px 3px 0 #1A1A2E; }
.tp-card.is-locked .tp-card-meta {
  color: #E91E63;
  opacity: 1;
  font-size: 8px;
}
.tp-card-art {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 3px solid #1A1A2E;
  position: relative;
}
.tp-card-pre {
  display: inline-block;
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--c1) 0 50%, var(--c2) 50% 100%);
  border: 3px solid #1A1A2E;
}
.tp-card-hat { image-rendering: pixelated; image-rendering: crisp-edges; }
.tp-no-hat {
  font-family: 'Press Start 2P', monospace;
  color: #1A1A2E;
  font-size: 22px;
}
.tp-card-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  letter-spacing: 0.04em;
  padding: 8px 8px 2px;
}
.tp-card-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  padding: 0 8px 8px;
  color: #1A1A2E;
  opacity: 0.85;
}

/* Chips */
.tp-chip {
  --chip-accent: #1A1A2E;
  appearance: none;
  background: #fff;
  color: #1A1A2E;
  border: 3px solid #1A1A2E;
  padding: 8px 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 3px 3px 0 #1A1A2E;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 80ms ease;
}
.tp-chip:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 #1A1A2E; }
.tp-chip:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #1A1A2E; }
.tp-chip.is-on { background: var(--chip-accent); color: #FFF8DC; }
.tp-chip-skin .tp-sw {
  width: 14px;
  height: 14px;
  border: 2px solid #1A1A2E;
  display: inline-block;
}

/* Slider rows */
.tp-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.tp-slider-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  min-width: 90px;
}
.tp-slider-val {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #E91E63;
  min-width: 40px;
  text-align: right;
}
.tp-band, .tp-slider {
  appearance: none;
  -webkit-appearance: none;
  flex: 1;
  height: 12px;
  background: #fff;
  border: 3px solid #1A1A2E;
  box-shadow: 3px 3px 0 #1A1A2E;
  outline: none;
}
.tp-band::-webkit-slider-thumb,
.tp-slider::-webkit-slider-thumb {
  appearance: none;
  width: 22px;
  height: 22px;
  background: #E91E63;
  border: 3px solid #1A1A2E;
  cursor: pointer;
}
.tp-band::-moz-range-thumb,
.tp-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  background: #E91E63;
  border: 3px solid #1A1A2E;
  cursor: pointer;
}
.tp-btn-restart {
  appearance: none;
  background: #FFD93D;
  color: #1A1A2E;
  border: 4px solid #1A1A2E;
  padding: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 5px 5px 0 #1A1A2E;
  width: 100%;
}
.tp-btn-danger {
  appearance: none;
  background: #fff;
  color: #1A1A2E;
  border: 3px solid #1A1A2E;
  padding: 10px;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 3px 3px 0 #1A1A2E;
  width: 100%;
}
.tp-btn-restart:active,
.tp-btn-danger:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 #1A1A2E;
}

/* ---------- BOTTOM STRIP — privacy link ---------- */
#bottomStrip {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--ad-h) + var(--safe-b));
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1A1A2E;
  z-index: 10;
  pointer-events: auto;
}
.bottom-strip-text {
  color: rgba(255,255,255,0.65);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0;
}
.privacy-link {
  background: none;
  border: none;
  color: #ffffff;
  text-decoration: underline;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  opacity: 0.65;
  transition: opacity 150ms;
  letter-spacing: 0.04em;
  -webkit-tap-highlight-color: transparent;
  display: inline;
}
.privacy-link:hover,
.privacy-link:focus { opacity: 1; outline: none; }

/* ---------- PRIVACY POLICY MODAL ---------- */
.privacy-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.82);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.privacy-modal.show { display: flex; }
.privacy-modal-box {
  background: #fff;
  border: 4px solid #1A1A2E;
  box-shadow: 8px 8px 0 #1A1A2E;
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.privacy-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #E91E63;
  border-bottom: 4px solid #1A1A2E;
  flex-shrink: 0;
}
.privacy-modal-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: #fff;
  letter-spacing: 0.04em;
}
.privacy-modal-close {
  background: #fff;
  border: 3px solid #1A1A2E;
  box-shadow: 2px 2px 0 #1A1A2E;
  width: 32px;
  height: 32px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  color: #1A1A2E;
  padding: 0;
  flex-shrink: 0;
}
.privacy-modal-close:active {
  transform: translate(2px,2px);
  box-shadow: none;
}
.privacy-modal-body {
  overflow-y: auto;
  padding: 20px 22px 24px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.75;
  color: #1A1A2E;
  user-select: text;
  -webkit-user-select: text;
}
.privacy-modal-body h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #E91E63;
  margin: 20px 0 8px;
  letter-spacing: 0.04em;
}
.privacy-modal-body p { margin: 0 0 10px; }
.privacy-modal-body a {
  color: #E91E63;
  text-decoration: underline;
}
.privacy-modal-body code {
  background: #f4f4f4;
  border: 1px solid #ddd;
  padding: 1px 5px;
  font-size: 12px;
  border-radius: 2px;
}
@media (max-width: 480px) {
  .privacy-modal-body { font-size: 12px; padding: 14px 14px 18px; }
  .privacy-modal-title { font-size: 11px; }
}
