/* ============================================================================
 * Alpha Archers 2D — game.css
 * Canvas & stage layout, page background, loading screen, global overlays
 * and body-state effects (in-game cursor, high-contrast filter, errors).
 * ========================================================================== */

body {
  font-family: var(--font-ui);
  color: var(--c-text);
  background: var(--c-bg);
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Letterbox bars around the stage, with a soft vignette so the game reads as
     a framed screen rather than a window that failed to fill. */
  background:
    radial-gradient(ellipse at 50% 50%, rgba(24, 20, 46, 0.55), transparent 70%),
    var(--c-bg);
}

/* ---------------------------------------------------------------- stage ---
 * Height-locked to 720 design px and scaled to fill the screen. This is what
 * makes a phone in landscape frame EXACTLY what a desktop frames: every piece
 * of UI is authored against that height, so only the scale differs. The width
 * follows the viewport instead of being pinned to 1280, so the game fills a
 * widescreen monitor edge to edge rather than sitting between black bars.
 * ------------------------------------------------------------------------ */
#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  /* A 720px-tall design space whose width tracks the viewport. Every piece of
     UI is authored once at desktop size and lands pixel-identically on a phone,
     a tablet and a desktop — only the scale factor differs. --stage-scale and
     --stage-w are set by the renderer on every resize. */
  width: var(--stage-w, 1280px);
  height: 720px;
  transform: translate(-50%, -50%) scale(var(--stage-scale, 1));
  transform-origin: center center;
  overflow: hidden;
  background: var(--c-bg);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 24px 90px rgba(0, 0, 0, 0.75);
  /* No browser gestures inside the play area: no scroll chaining, no
     double-tap zoom, no pull-to-refresh eating a drag mid-shot. */
  touch-action: none;
  overscroll-behavior: contain;
  /* Promote to its own layer so the scale transform never repaints the page */
  will-change: transform;
  backface-visibility: hidden;
}

/* ------------------------------------------------------------------ canvas */
#canvas-wrap {
  position: absolute;
  inset: 0;
}

#game-canvas {
  width: 100%;
  height: 100%;
  cursor: default;
}

body.in-game #game-canvas {
  cursor: crosshair;
}

/* Pointer lock hides the hardware cursor; the game draws its own crosshair. */
body.cursor-locked #game-canvas {
  cursor: none;
}

/* --------------------------------------------------------- device safe area
 * On mobile devices notches, rounded corners and dynamic islands can clip UI
 * placed at the very edge. Gameplay still fills the screen — only the HUD and
 * menus are inset.
 * ------------------------------------------------------------------------ */
#hud,
#ui-root,
#overlay-root,
#modal-root,
#touch-controls {
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}

body.high-contrast #game-canvas {
  filter: contrast(1.14) saturate(1.18) brightness(1.1);
}

/* ------------------------------------------------------------- containers */
#hud,
#ui-root,
#overlay-root,
#modal-root,
#touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Battle overlays sit above the HUD and below the toast layer. */
#overlay-root {
  z-index: 50;
}

#overlay-root > * {
  pointer-events: auto;
}

#ui-root > .screen {
  pointer-events: auto;
}

#modal-root {
  z-index: 60;
}

#hud {
  z-index: 20;
}

#ui-root {
  z-index: 40;
}

#touch-controls {
  z-index: 30;
}

.hidden {
  display: none !important;
}

/* --------------------------------------------------------- loading screen */
#loading-screen {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(62, 198, 168, 0.09), transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(185, 142, 255, 0.07), transparent 50%),
    var(--c-bg);
  transition: opacity var(--t-slow) ease, visibility var(--t-slow);
}

#loading-screen.done {
  opacity: 0;
  visibility: hidden;
}

.loading-inner {
  text-align: center;
  animation: fadeInUp 0.8s var(--ease-out) both;
}

.loading-logo {
  font-size: clamp(48px, 9vw, 84px);
  filter: drop-shadow(0 6px 18px rgba(62, 198, 168, 0.4));
  animation: floatBob 2.6s ease-in-out infinite;
}

.loading-title {
  font-family: var(--font-display);
  font-size: clamp(28px, 5.5vw, 52px);
  letter-spacing: 0.14em;
  margin: 12px 0 26px;
  color: var(--c-text);
  text-shadow: var(--shadow-text);
}

.loading-title span {
  color: var(--c-accent);
  text-shadow: 0 0 24px rgba(62, 198, 168, 0.55);
}

.loading-bar {
  width: min(340px, 70vw);
  height: 10px;
  margin: 0 auto 14px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--c-panel-border);
  overflow: hidden;
}

#loading-bar-fill {
  width: 0%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--c-accent), #7ae2cc);
  box-shadow: var(--shadow-glow-accent);
  transition: width 0.35s var(--ease-out);
}

#loading-label {
  color: var(--c-text-dim);
  font-size: 14px;
  letter-spacing: 0.06em;
  animation: pulseSoft 1.6s ease-in-out infinite;
}

/* ------------------------------------------------------------ fatal error */
.fatal-error {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 5, 12, 0.9);
  pointer-events: auto;
}

.fatal-inner {
  max-width: min(480px, 88vw);
  padding: 32px;
  text-align: center;
  background: var(--c-panel);
  border: 1px solid var(--c-danger);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
}

.fatal-inner h2 {
  font-family: var(--font-display);
  margin-bottom: 12px;
}

.fatal-inner p {
  color: var(--c-text-dim);
  font-size: 13px;
  font-family: var(--font-mono);
  margin-bottom: 20px;
  word-break: break-word;
}

.fatal-inner button {
  padding: 10px 22px;
  border-radius: var(--radius-md);
  background: var(--c-danger);
  color: #fff;
  font-weight: 700;
}

/* ------------------------------------------------------------- minimap --
 * The overhead minimap is drawn on the canvas in the top-right corner, so the
 * DOM HUD column there has to start below it. The canvas is a fixed 1280px
 * wide in stage space, so the minimap is min(34% of 1280, 380) = 380px, and
 * its height is that times the level aspect (~0.13).
 * ---------------------------------------------------------------------- */
body.in-game .hud-top-right {
  padding-top: calc(380px * 0.13 + 30px);
}

body.no-minimap.in-game .hud-top-right {
  padding-top: 0;
}

/* ============================================================================
 * PORTRAIT GATE
 *
 * The game is landscape-only. In portrait this covers the entire screen, the
 * game pauses and the SDK is told gameplay stopped; turning the device brings
 * it straight back. Shown only on devices that can actually rotate — a narrow
 * desktop window is not asked to do anything it cannot do.
 * ==========================================================================*/
#rotate-gate {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  pointer-events: auto;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(28, 22, 54, 0.9), transparent 65%),
    var(--c-bg);
  animation: fadeIn 0.25s ease both;
}

.rotate-inner {
  max-width: 340px;
  animation: fadeInUp 0.45s var(--ease-out) both;
}

/* A phone that tips from portrait to landscape, on a loop */
.rotate-phone {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 auto 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rotate-phone-body {
  display: block;
  width: 54px;
  height: 92px;
  border: 3px solid var(--c-accent);
  border-radius: 10px;
  box-shadow:
    0 0 22px color-mix(in srgb, var(--c-accent) 55%, transparent),
    inset 0 0 18px color-mix(in srgb, var(--c-accent) 22%, transparent);
  animation: rotateHint 2.6s ease-in-out infinite;
}

.rotate-phone-body::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 12px;
  width: 16px;
  height: 3px;
  margin-left: -8px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--c-accent) 70%, transparent);
}

.rotate-arrow {
  position: absolute;
  right: -4px;
  bottom: 2px;
  font-size: 26px;
  color: var(--c-gold);
  text-shadow: 0 0 14px color-mix(in srgb, var(--c-gold) 80%, transparent);
  animation: pulseSoft 1.6s ease-in-out infinite;
}

.rotate-title {
  font-family: var(--font-display);
  font-size: clamp(20px, 6vw, 28px);
  letter-spacing: 0.12em;
  margin-bottom: 10px;
  text-shadow: var(--shadow-text);
}

.rotate-note {
  font-size: clamp(12.5px, 3.4vw, 15px);
  line-height: 1.6;
  color: var(--c-text-dim);
}

/* While the gate is up nothing behind it may be touched */
body.portrait-blocked #stage {
  pointer-events: none;
  filter: blur(3px) brightness(0.5);
}
