/* FART BUBBLE — full-bleed game canvas with a floating HUD, floating touch controls and
   overlays. No external fonts or assets. */
:root {
  --bg: #0d1a14;
  --panel: #163024;
  --panel-dark: #0a140f;
  --ink: #0b0f14;
  --text: #f4ffe8;
  --dim: #9fc3a4;
  --accent: #7be05b;
  --accent-dark: #2a7a3c;
  --hot: #f9a9bc;
  --hot-dark: #b0456a;
  /* Translucent "glass" for controls that float over the live game. */
  --glass: rgba(8, 16, 12, 0.42);
  --glass-strong: rgba(8, 16, 12, 0.62);
  --edge: rgba(244, 255, 232, 0.78);
  --edge-dim: rgba(244, 255, 232, 0.34);
  --glow: rgba(123, 224, 91, 0.6);
  --glow-hot: rgba(249, 169, 188, 0.65);
  --veil: 5, 10, 8;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --font: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Roboto Mono', Menlo, Consolas, 'Courier New', monospace;
}

/* Authentic 4-shade DMG Game Boy green */
body.dmg {
  --bg: #081820;
  --panel: #346856;
  --panel-dark: #081820;
  --ink: #081820;
  --text: #e0f8d0;
  --dim: #88c070;
  --accent: #88c070;
  --accent-dark: #346856;
  --hot: #e0f8d0;
  --hot-dark: #346856;
  --glass: rgba(8, 24, 32, 0.5);
  --glass-strong: rgba(8, 24, 32, 0.7);
  --edge: rgba(224, 248, 208, 0.82);
  --edge-dim: rgba(224, 248, 208, 0.36);
  --glow: rgba(136, 192, 112, 0.7);
  --glow-hot: rgba(224, 248, 208, 0.6);
  --veil: 8, 24, 32;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-weight: 700;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* Crisp pixel icons: square-edged inline SVG that inherits the button colour. */
.ico {
  display: block;
  width: 18px;
  height: 18px;
  fill: currentColor;
  shape-rendering: crispEdges;
  flex: none;
}
.when-on { display: none; }
[aria-pressed='true'] > .when-on { display: block; }
[aria-pressed='true'] > .when-off { display: none; }

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ---------------------------------------------------------------- Canvas */
/* Edge to edge: the game owns every pixel, under notches and home bars too. */
#canvas {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--bg);
}

/* Invisible probe so the renderer can read the safe-area insets. */
#safe {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  visibility: hidden;
  pointer-events: none;
}

/* ------------------------------------------------------------------ HUD */
/* Hearts, score and height are drawn in-canvas at the top-left; these icon
   buttons float at the top-right. */
#hud {
  position: absolute;
  top: calc(var(--sat) + 8px);
  right: calc(var(--sar) + 8px);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

.hud-btns { display: flex; gap: 6px; pointer-events: auto; }

.hbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--text);
  background: var(--glass);
  border: 2px solid var(--edge-dim);
  border-radius: 9px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  transition: transform 0.05s, background-color 0.12s, border-color 0.12s;
}
.hbtn:hover { border-color: var(--edge); background: var(--glass-strong); }
.hbtn:active { transform: translateY(2px); box-shadow: none; }
.hbtn:focus-visible, .opt-btn:focus-visible, .big-btn:focus-visible, .opt-btn.gp-focus, .big-btn.gp-focus { outline: 2px solid var(--text); outline-offset: 2px; }
.hbtn[aria-pressed='true'] {
  color: var(--ink);
  background: var(--accent);
  border-color: var(--text);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45), 0 0 12px var(--glow);
}
/* Sound and Pause are states, not "modes": keep them glassy either way. */
#btn-sound[aria-pressed='true'], #btn-pause[aria-pressed='false'] {
  color: var(--text);
  background: var(--glass);
  border-color: var(--edge-dim);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}
#btn-sound[aria-pressed='false'] { color: var(--dim); }
#btn-sound.audio-locked { color: var(--dim); border-color: var(--hot); }
#btn-sound[aria-pressed='true'] > .when-on, #btn-sound[aria-pressed='false'] > .when-off { display: block; }
#btn-pause[aria-pressed='true'] { background: var(--hot); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45), 0 0 12px var(--glow-hot); }

.audio-hint {
  pointer-events: auto;
  padding: 5px 9px;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text);
  background: var(--glass-strong);
  border: 2px solid var(--hot);
  border-radius: 8px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

@keyframes beat-pop {
  0% { transform: scale(1.2); filter: brightness(1.5); }
  100% { transform: scale(1); filter: none; }
}
.beat { animation: beat-pop 0.2s ease-out; }

/* -------------------------------------------------------------- Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: calc(var(--sat) + 56px) calc(var(--sar) + 14px) calc(var(--sab) + 18px) calc(var(--sal) + 14px);
  background: linear-gradient(to bottom, transparent 46%, rgba(var(--veil), 0.5) 62%, rgba(var(--veil), 0.9) 84%);
  overflow: hidden;
  z-index: 3;
}
.overlay.centered { justify-content: center; background: rgba(var(--veil), 0.55); }

.card {
  width: min(100%, 360px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.centered .card {
  padding: 18px 16px;
  background: rgba(var(--veil), 0.78);
  border: 2px solid var(--edge);
  border-radius: 12px;
  box-shadow: 0 0 0 2px var(--ink), 0 6px 0 2px var(--ink), 0 0 30px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
}

h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 3px;
  color: var(--hot);
  text-shadow: 3px 3px 0 var(--ink);
}

.tagline { margin: 0; font-size: 13px; line-height: 1.45; color: var(--text); text-shadow: 1px 1px 0 var(--ink), 0 0 8px var(--ink); }
.hint { margin: 0; font-size: 11px; line-height: 1.5; color: var(--dim); font-weight: 400; text-shadow: 1px 1px 0 var(--ink); }
.best { margin: 0; font-size: 13px; color: var(--accent); letter-spacing: 1px; text-shadow: 1px 1px 0 var(--ink); }
.hint-touch, .hint-gamepad { display: none; }
body.touch .hint-touch { display: block; }
body.touch .hint-keys { display: none; }
body.gamepad .hint-gamepad { display: block; }
body.gamepad .hint-keys, body.gamepad .hint-touch { display: none; }
@media (min-width: 480px) { .hint-keys, .hint-gamepad { white-space: nowrap; } }

.big-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 190px;
  padding: 13px 24px;
  font-size: 22px;
  letter-spacing: 4px;
  color: var(--ink);
  background: var(--accent);
  border: 3px solid var(--text);
  border-radius: 10px;
  box-shadow: 0 6px 0 var(--accent-dark), 0 6px 0 3px var(--ink), 0 0 26px var(--glow);
  animation: bob 1.1s ease-in-out infinite;
  flex: none;
}
.big-btn .ico { width: 20px; height: 20px; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-dark); animation: none; }
@keyframes bob { 50% { transform: translateY(-3px); } }

.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.opt-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text);
  background: var(--glass-strong);
  border: 2px solid var(--edge-dim);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--ink);
}
.opt-btn .ico { width: 14px; height: 14px; }
.opt-btn:hover { border-color: var(--edge); }
.opt-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.opt-btn[aria-pressed='true'] { background: var(--hot); color: var(--ink); border-color: var(--text); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 18px;
  margin: 0;
  width: 100%;
}
.stats div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 2px dotted var(--edge-dim); padding-bottom: 2px; }
.stats dt { color: var(--dim); font-size: 12px; }
.stats dd { margin: 0; font-size: 15px; color: var(--text); }

/* ------------------------------------------------------- Touch controls */
/* Floating over the bottom of the live game: the wrapper ignores touches,
   only the stick zone and the buttons take them. */
#touch { display: none; }

body.touch.playing #touch {
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

#joy {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: auto;
  touch-action: none;
}

#joy-base {
  position: absolute;
  left: 0;
  top: 0;
  width: 118px;
  height: 118px;
  margin: -59px 0 0 -59px;
  border-radius: 50%;
  background: var(--glass);
  border: 2px solid var(--edge-dim);
  box-shadow: inset 0 0 0 5px rgba(0, 0, 0, 0.18), 0 2px 0 rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  will-change: transform, opacity;
  transition: opacity 0.1s ease-out, border-color 0.1s, box-shadow 0.1s;
}
#joy-base .ico { position: absolute; width: 14px; height: 14px; color: var(--edge-dim); }
.joy-l { left: 7px; top: 50%; margin-top: -7px; }
.joy-r { right: 7px; top: 50%; margin-top: -7px; }
.joy-d { bottom: 7px; left: 50%; margin-left: -7px; }

#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(123, 224, 91, 0.5);
  border: 2px solid var(--edge);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.28), 0 3px 0 rgba(0, 0, 0, 0.4);
  will-change: transform;
}
body.dmg #joy-knob { background: rgba(136, 192, 112, 0.6); }
#joy.live #joy-base { opacity: 1; visibility: visible; border-color: var(--edge); box-shadow: inset 0 0 0 5px rgba(0, 0, 0, 0.18), 0 0 20px var(--glow); }
#joy.live #joy-knob { background: var(--accent); }

.pad {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0;
  border-radius: 50%;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text);
  background: var(--glass);
  border: 2px solid var(--edge);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.14), 0 3px 0 rgba(0, 0, 0, 0.4);
  text-shadow: 1px 1px 0 var(--ink);
  pointer-events: auto;
  touch-action: none;
  transition: transform 0.04s, background-color 0.08s, box-shadow 0.08s;
}
.pad .ico { width: 24px; height: 24px; filter: drop-shadow(1px 1px 0 var(--ink)); }
.pad.down { transform: translateY(3px) scale(0.94); color: var(--ink); text-shadow: none; }
.pad.down .ico { filter: none; }

#pad-jump {
  right: calc(var(--sar) + 16px);
  bottom: calc(var(--sab) + 24px);
  width: 88px;
  height: 88px;
  border-color: var(--hot);
  background: rgba(249, 169, 188, 0.2);
}
body.dmg #pad-jump { background: var(--glass); }
#pad-jump.down { background: var(--hot); box-shadow: 0 0 24px var(--glow-hot); }
#pad-fart {
  right: calc(var(--sar) + 110px);
  bottom: calc(var(--sab) + 50px);
  width: 80px;
  height: 80px;
  border-color: var(--accent);
  background: rgba(123, 224, 91, 0.18);
}
body.dmg #pad-fart { background: var(--glass); }
#pad-fart.down { background: var(--accent); box-shadow: 0 0 24px var(--glow); }
.hbtn.hbtn-auto {
  width: auto;
  padding: 0 9px;
  gap: 5px;
  font-size: 11px;
  letter-spacing: 1px;
}
.hbtn.hbtn-auto .ico { width: 14px; height: 14px; }
body.auto .pad { display: none; }

/* Phones held sideways (and other short screens): the title card slides to the
   right-hand side so the attract demo stays visible, and menus tighten up. */
@media (orientation: landscape) and (max-height: 540px) {
  .hbtn { width: 34px; height: 34px; }
  .hbtn.hbtn-auto { width: auto; padding: 0 8px; }
  .overlay { padding: calc(var(--sat) + 50px) calc(var(--sar) + 14px) calc(var(--sab) + 10px) calc(var(--sal) + 14px); }
  #title {
    align-items: flex-end;
    justify-content: center;
    background: linear-gradient(to right, transparent 52%, rgba(var(--veil), 0.55) 68%, rgba(var(--veil), 0.9) 100%);
  }
  #title .card { width: min(31%, 262px); }
  .card { gap: 8px; }
  .centered .card { width: min(100%, 460px); padding: 12px 16px; }
  .tagline { font-size: 12px; }
  h2 { font-size: 22px; }
  .big-btn { min-width: 170px; padding: 9px 20px; font-size: 18px; }
  .hint { display: none !important; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 4px 12px; }
  .stats div { flex-direction: column; align-items: center; gap: 0; }
  #pad-jump { bottom: calc(var(--sab) + 16px); }
  #pad-fart { bottom: calc(var(--sab) + 34px); }
}

@media (max-width: 380px) {
  .hbtn { width: 33px; height: 33px; }
  .hbtn.hbtn-auto { width: auto; padding: 0 7px; gap: 4px; font-size: 10px; }
  .hud-btns { gap: 4px; }
  #joy-base { width: 106px; height: 106px; margin: -53px 0 0 -53px; }
  #pad-jump { width: 80px; height: 80px; right: calc(var(--sar) + 12px); }
  #pad-fart { width: 72px; height: 72px; right: calc(var(--sar) + 98px); }
}

@media (max-height: 420px) and (orientation: portrait) {
  .tagline, .hint { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .big-btn, .beat { animation: none; }
}
