/* Super Peliad Bros — the page and the embedded game "cabinet".
   The level is drawn in WebGL inside #viewport; everything here frames it on a
   scrollable page (header + viewport window + notes), with the HUD, overlays and
   touch controls positioned inside the viewport. Dark-fantasy swamp palette in
   :root so the whole thing can be restyled from one place. */

:root {
  --bg: #0a110c;
  --ink: #dbead0;
  --amber: #e7b24a;
  --amber-dim: #9c7526;
  --rune: #54d17a;
  --rune-dim: #2f7d4a;
  --stone: #141b16;
  --stone-line: #2c3a2f;
  --danger: #d1594f;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 26% 12%, rgba(40, 74, 48, 0.35), transparent 60%),
    radial-gradient(ellipse at 80% 88%, rgba(22, 44, 30, 0.35), transparent 55%),
    radial-gradient(ellipse at 50% 50%, rgba(10, 22, 14, 0.35), transparent 72%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ---- Full-page layout: the game screen centred on the themed background ---- */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(0.5rem, 2.2vw, 1.6rem);
}
html.touch #app { padding: 0; justify-content: flex-start; }

#game-root {
  position: relative;
  width: 100%;
  max-width: 1280px;
  height: 100%;
  max-height: 760px;
  display: flex;
  align-items: center;
  justify-content: center;
}
html.touch #game-root { max-width: none; max-height: none; }

/* The WebGL canvas mounts here; overlays/HUD/controls are positioned inside. */
#viewport {
  position: relative;
  width: 100%;
  height: 100%;
  background: #05090a;
  border: 1px solid var(--stone-line);
  border-radius: 0.85rem;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  touch-action: none; /* no browser scroll/zoom over the board */
  display: flex;
  align-items: center;
  justify-content: center;
}
html.touch #viewport { border-radius: 0; border: none; }
#viewport > canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* Fullscreen: #game-root fills the screen and the viewport fills it. */
#game-root:fullscreen { max-width: none; max-height: none; width: 100%; height: 100%; }
#game-root:fullscreen #viewport { border-radius: 0; border: none; }

.frame-btn {
  position: absolute;
  top: 0.6rem; right: 0.6rem;
  z-index: 30;
  width: 2.1rem; height: 2.1rem;
  font-size: 1rem; line-height: 1;
  color: var(--amber); background: rgba(20, 27, 22, 0.8);
  border: 1px solid var(--stone-line); border-radius: 0.5rem; cursor: pointer;
}
.frame-btn:hover { color: #ffd257; }

/* ---- Overlays (title / ready / level clear / game over / paused / error) ---- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: radial-gradient(ellipse at center, rgba(6, 12, 8, 0.72), rgba(4, 8, 6, 0.94));
  text-align: center;
}
.overlay.hidden,
.hidden { display: none !important; }

.panel {
  max-width: 30rem;
  padding: clamp(1.2rem, 3vw, 2rem) clamp(1.2rem, 3vw, 2.25rem);
  border: 1px solid var(--stone-line);
  border-radius: 1rem;
  background: linear-gradient(180deg, rgba(20, 27, 22, 0.96), rgba(6, 12, 8, 0.96));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 0 40px rgba(84, 209, 122, 0.05);
}
.panel h2 { margin: 0 0 0.5rem; font-size: 1.6rem; color: var(--amber); letter-spacing: 0.05em; }
.panel p { margin: 0.35rem 0; color: #c3d2ba; }

.title-panel { max-width: 32rem; }
.logo {
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2.8rem) !important;
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--rune) !important;
  text-shadow: 0 0 16px rgba(84, 209, 122, 0.5), 0 3px 0 #143a22;
}
.tagline { margin: 0.6rem 0 1.2rem; color: #a9bda0; font-style: italic; }

.arcade-btn {
  margin-top: 0.5rem;
  padding: 0.75rem 2.1rem;
  font-family: var(--font);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #0a1810;
  background: linear-gradient(180deg, #7ce39a, var(--rune));
  border: none;
  border-radius: 0.7rem;
  box-shadow: 0 6px 0 #1c5233, 0 10px 22px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  animation: pulse 1.6s ease-in-out infinite;
}
.arcade-btn:hover { filter: brightness(1.05); }
.arcade-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #1c5233, 0 4px 12px rgba(0, 0, 0, 0.5); }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }

.controls {
  list-style: none;
  margin: 1.2rem 0 0.5rem;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1.9;
  color: #b3c4a8;
}
.keys {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  margin: 0 0.1rem;
  border: 1px solid var(--stone-line);
  border-radius: 0.35rem;
  background: #0b130d;
  color: var(--amber);
  font-weight: 700;
  font-size: 0.82rem;
}
.hs { color: var(--amber-dim); font-weight: 700; letter-spacing: 0.05em; }

.banner {
  font-size: clamp(1.4rem, 6vw, 2.8rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--amber);
  text-shadow: 0 0 16px rgba(231, 178, 74, 0.55);
  text-align: center;
}
.ready-banner { animation: blink 0.5s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---- HUD ---- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: clamp(0.5rem, 2vw, 1.1rem);
  padding: 0.5rem 0.85rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  background: linear-gradient(180deg, rgba(6, 12, 8, 0.85), rgba(6, 12, 8, 0));
  pointer-events: none;
}
.hud-item { display: flex; align-items: baseline; gap: 0.35rem; }
.hud-label { font-size: 0.62rem; text-transform: uppercase; color: var(--amber-dim); letter-spacing: 0.1em; }
#hud-score, #hud-high, #hud-gems, #hud-world { font-size: 1rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.lives { display: inline-flex; gap: 0.22rem; }
.lives .pip {
  width: 0.8rem; height: 0.8rem; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #7ce39a, var(--rune));
  box-shadow: 0 0 6px rgba(84, 209, 122, 0.5);
}
.hud-btn {
  margin-left: auto;
  pointer-events: auto;
  width: 2rem; height: 2rem;
  font-weight: 900; letter-spacing: 0.1em;
  color: var(--amber); background: rgba(20, 27, 22, 0.8);
  border: 1px solid var(--stone-line); border-radius: 0.5rem; cursor: pointer;
}
.hud-btn:hover { color: #ffd257; }

/* ---- Boss health bar (World 4) ---- */
#boss-hud {
  position: absolute;
  top: 2.6rem; left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  pointer-events: none;
}
.boss-name {
  font-size: 0.7rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--danger); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
.boss-pips { display: inline-flex; gap: 0.3rem; }
.boss-pips .bpip {
  width: 1.1rem; height: 1.1rem; border-radius: 0.2rem;
  border: 1px solid rgba(0, 0, 0, 0.5);
  background: radial-gradient(circle at 40% 35%, #ff8a6a, var(--danger));
  box-shadow: 0 0 6px rgba(209, 89, 79, 0.6);
}
.boss-pips .bpip.spent {
  background: #241b1a; box-shadow: none; opacity: 0.5;
}

/* ---- Vignette over the canvas (below HUD/overlays) ---- */
#vignette {
  position: absolute; inset: 0; z-index: 10; pointer-events: none;
  border-radius: 0.85rem;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.35) 82%, rgba(0, 0, 0, 0.6) 100%);
}

/* ---- Touch controls, overlaid inside the viewport ----
   Hidden on desktop; on touch devices a left/right pad sits at the lower-left
   and Jump (A)/Run (B) at the lower-right, over the canvas. */
#controls { display: none; }
html.touch #controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 16;
  padding: 0 clamp(0.6rem, 3vw, 1.6rem) calc(0.8rem + env(safe-area-inset-bottom));
  pointer-events: none; /* only the pads capture touches */
  touch-action: none;
}
.pad-group { display: flex; align-items: center; gap: clamp(0.5rem, 3vw, 1.3rem); pointer-events: none; }
.pad {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(56px, 15vw, 84px);
  height: clamp(56px, 15vw, 84px);
  font-family: var(--font);
  font-size: clamp(1.2rem, 4.5vw, 1.7rem);
  font-weight: 900;
  color: var(--ink);
  border-radius: 50%;
  border: 2px solid rgba(84, 209, 122, 0.4);
  background: radial-gradient(circle at 50% 40%, rgba(44, 74, 52, 0.7), rgba(16, 26, 19, 0.65));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), inset 0 0 16px rgba(0, 0, 0, 0.35);
  touch-action: none;
  cursor: pointer;
  will-change: transform, filter;
  transition: transform 0.05s ease, filter 0.05s ease;
  -webkit-user-select: none;
  user-select: none;
}
.pad.is-down { transform: translateY(3px) scale(0.94); filter: brightness(1.5); }
.pad-a {
  color: #0a1810;
  border-color: rgba(124, 227, 154, 0.6);
  background: radial-gradient(circle at 50% 38%, #7ce39a, var(--rune-dim));
  width: clamp(68px, 18vw, 100px);
  height: clamp(68px, 18vw, 100px);
}
.pad-b {
  color: #1a1206;
  border-color: rgba(231, 178, 74, 0.55);
  background: radial-gradient(circle at 50% 38%, #ffd257, var(--amber-dim));
}
/* Kenney Mobile Controls (CC0) glyphs on the directional pads; label text stays
   for screen readers but is hidden so the icon reads instead. */
#pad-left, #pad-right {
  color: transparent;
  background-image: var(--icon);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 58%;
}
#pad-left { --icon: url("./assets/sprites/ui/ctrl_left.png"); }
#pad-right { --icon: url("./assets/sprites/ui/ctrl_right.png"); }
