/*
 * Page shell for the web build.
 *
 * The stock template pins the game inside a fixed, rounded, bordered box with
 * a heading above it and a credit below. This replaces all of that with a
 * frame that fills the window while holding the 16:9 of the 1280x720 design
 * resolution, so the game letterboxes against black instead of stretching.
 *
 * `!important` is not decoration: the generated markup writes the frame size
 * as an inline style on #GameDiv, and inline styles outrank the sheet.
 */
html {
  min-height: 100%;
  margin: 0;
  padding: 0;
  background-color: #04050c;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 0;
  border: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background-color: #04050c;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  cursor: default;
  font-family: Orbitron, Helvetica, Arial, sans-serif;
}

body, canvas, div {
  outline: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/*
 * Mobile gesture suppression.
 *
 * `touch-action: none` hands every touch straight to the game: no double-tap
 * zoom, no pan, no 300ms click delay. `-webkit-touch-callout` is what stops
 * iOS raising the copy/share menu on a long press -- and holding to tether is
 * a long press, so without it the menu appears mid-orbit. `overscroll-behavior`
 * kills the rubber-band bounce that would otherwise fire on a downward flick.
 */
html, body, #GameDiv, #Cocos3dGameContainer, #GameCanvas {
  touch-action: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

/* Page furniture from the stock template. */
.header, .footer { display: none !important; }

#GameDiv {
  width: min(100vw, calc(100vh * 16 / 9)) !important;
  height: min(100vh, calc(100vw * 9 / 16)) !important;
  margin: 0 auto !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

#Cocos3dGameContainer, #GameCanvas {
  width: 100%;
  height: 100%;
}

canvas { background-color: transparent; }


/* ---------------------------------------------------------------- overlay
 *
 * Everything below sits inside #GameDiv rather than the viewport, so it tracks
 * the letterboxed 16:9 frame instead of drifting into the black bars.
 *
 * These layers also swallow the taps that land on them: Cocos listens on the
 * canvas, so anything above it never reaches the game. That is what keeps a
 * tap on the settings button from also launching a run.
 */
#tools {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 40;
  display: flex;
  gap: 0.6vmin;
  padding: 1.4vmin;
}

#tools button {
  /* vmin, so the chrome scales with the frame like the drawn HUD does. */
  width: 6.4vmin;
  height: 6.4vmin;
  min-width: 34px;
  min-height: 34px;
  padding: 1.2vmin;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #26d6ff;
  background: rgba(6, 12, 24, 0.55);
  border: 1px solid rgba(38, 214, 255, 0.45);
  border-radius: 0.9vmin;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  /* The page blocks browser gestures wholesale; a control still needs taps. */
  touch-action: manipulation;
}

#tools button:hover { background: rgba(38, 214, 255, 0.18); }
#tools button:active { background: rgba(38, 214, 255, 0.3); }
#tools button[hidden] { display: none; }

#tools svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#settings {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(2, 4, 10, 0.82);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  touch-action: manipulation;
}

#settings[hidden] { display: none; }

#settings .panel {
  width: min(78vw, 46vmin);
  padding: 4vmin;
  color: #a0f6ff;
  background: rgba(6, 12, 24, 0.94);
  border: 1px solid rgba(38, 214, 255, 0.5);
  border-radius: 1.4vmin;
  box-shadow: 0 0 6vmin rgba(38, 214, 255, 0.22);
}

#settings h2 {
  margin: 0 0 3vmin;
  font-size: 3.4vmin;
  letter-spacing: 0.3vmin;
  text-align: center;
  color: #26d6ff;
}

#settings .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.4vmin;
  font-size: 2.4vmin;
  letter-spacing: 0.16vmin;
  cursor: pointer;
}

#settings input[type="checkbox"] {
  width: 4vmin;
  height: 4vmin;
  min-width: 20px;
  min-height: 20px;
  accent-color: #26d6ff;
  cursor: pointer;
  touch-action: manipulation;
}

#btn-close {
  width: 100%;
  margin-top: 2vmin;
  padding: 1.8vmin;
  font: inherit;
  font-size: 2.4vmin;
  letter-spacing: 0.24vmin;
  color: #04050c;
  background: #26d6ff;
  border: 0;
  border-radius: 0.9vmin;
  cursor: pointer;
  touch-action: manipulation;
}

/*
 * --- Adsterra Sponsored Ad Banner (Separated Panel under Game Screen) ---
 *
 * Rendered below the game canvas with anti-redirect sandbox protection.
 * Shown on all non-gameplay screens: Title, Scoreboard / Game Over / Dead,
 * Settings modal, and Continue states.
 */
.adsterra-panel {
  width: min(94vw, 920px);
  max-width: 920px;
  margin: 16px auto 28px;
  padding: 12px 16px;
  text-align: center;
  background: #080d1a;
  border: 2px solid rgba(38, 214, 255, 0.4);
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(38, 214, 255, 0.15), 3px 3px 0 rgba(0, 0, 0, 0.4);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
  touch-action: manipulation;
}

.adsterra-panel:hover {
  border-color: #26d6ff;
  box-shadow: 0 0 25px rgba(38, 214, 255, 0.3), 4px 4px 0 rgba(0, 0, 0, 0.6);
}

.adsterra-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(38, 214, 255, 0.25);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #a0f6ff;
  flex-wrap: wrap;
  gap: 8px;
}

.adsterra-tag {
  background: #ffb43d;
  color: #04050c;
  font-family: Orbitron, monospace;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.3);
  letter-spacing: 0.8px;
}

.adsterra-title {
  color: #26d6ff;
  font-weight: 700;
  letter-spacing: 1.5px;
  font-size: 12px;
}

.adsterra-sub {
  color: rgba(160, 246, 255, 0.65);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.adsterra-slot {
  min-height: 90px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #050811;
  border: 1px solid rgba(38, 214, 255, 0.2);
  border-radius: 6px;
  padding: 8px;
  overflow: hidden;
  max-width: 100%;
}

.adsterra-iframe {
  width: 100%;
  max-width: 920px;
  height: 160px;
  max-height: 280px;
  border: none;
  display: block;
  background: transparent;
}

/* Visibility rules: Visible on non-gameplay screens, hidden during active run */
html:not([data-mode="play"]) .adsterra-panel,
html[data-settings="open"] .adsterra-panel,
html[data-mode="title"] .adsterra-panel,
html[data-mode="dead"] .adsterra-panel {
  display: block !important;
}

html[data-mode="play"]:not([data-settings="open"]) .adsterra-panel {
  display: none !important;
}

@media (max-width: 768px) {
  .adsterra-panel {
    margin: 12px auto 20px;
    padding: 10px 12px;
  }
  .adsterra-iframe {
    height: 220px;
  }
}
