:root {
  --black: #0e0e0b;
  --ink: #151124;
  --purple: #2a1743;
  --gold: #fbb703;
  --gold-light: #f8c911;
  --bun: #d05413;
  --cream: #f6f2e8;
  color-scheme: dark;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #08070d;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: grid;
  place-items: center;
}

#app {
  position: relative;
  width: min(100vw, 480px);
  height: 100dvh;
  max-height: 1000px;
  overflow: hidden;
  background: var(--ink);
  box-shadow: 0 0 50px #000;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(28px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
  text-align: center;
  background: linear-gradient(180deg, rgba(17, 10, 34, .2), rgba(14, 14, 11, .92));
}

.screen.active { display: flex; }

#start-screen { padding: 0; }

.poster {
  position: absolute;
  inset: 0;
  background: url("./assets/ogb-menu-background-9x16-v2.png") center / cover no-repeat;
  filter: saturate(1.08) contrast(1.04);
}

.screen-content, .panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 370px;
}

.menu-layout {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: none;
  padding: max(28px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
}

.menu-title { position: relative; z-index: 2; width: 100%; }

.menu-cast {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.menu-don,
.menu-sidekicks {
  position: absolute;
  background-position: 0 0;
  background-repeat: no-repeat;
  background-size: 400% 100%;
  image-rendering: pixelated;
  filter: drop-shadow(0 9px 0 rgba(0, 0, 0, .4));
  animation: menu-sprite 760ms linear infinite;
}

.menu-don {
  left: -1%;
  bottom: 16dvh;
  width: min(44vw, 174px);
  aspect-ratio: 543 / 724;
  background-image: url("./assets/don-gafas-run-v2.png");
  animation-duration: 610ms;
}

.menu-sidekicks {
  right: -2%;
  bottom: 12.5dvh;
  width: min(43vw, 168px);
  aspect-ratio: 543 / 724;
  background-image: url("./assets/ogb-sidekicks-v2.png");
}

.menu-controls {
  position: absolute;
  top: clamp(158px, 19.5dvh, 178px);
  left: 50%;
  z-index: 3;
  width: min(calc(100% - 64px), 296px);
  padding: 7px 9px 9px;
  border: 3px solid #100b0b;
  border-radius: 11px;
  background: rgba(24, 13, 31, .8);
  box-shadow: inset 0 0 0 2px rgba(251, 183, 3, .25), 0 5px 0 rgba(0, 0, 0, .65);
  transform: translateX(-50%);
}

.menu-controls .instructions { margin: 0 auto 7px; font-size: 12px; line-height: 1.35; }
.menu-controls button { width: 100%; min-width: 0; min-height: 45px; border-width: 3px; font-size: 22px; box-shadow: 0 5px #9b3707, 0 8px #000; }
.menu-controls .secondary { min-height: 41px; margin-top: 8px; font-size: 18px; box-shadow: 0 4px #8d8171, 0 7px #000; }
.menu-controls .best { margin-top: 10px; font-size: 12px; }

@keyframes menu-sprite {
  0%, 24.99% { background-position: 0 0; }
  25%, 49.99% { background-position: 33.333% 0; }
  50%, 74.99% { background-position: 66.666% 0; }
  75%, 100% { background-position: 100% 0; }
}

.compact { min-height: 46px; font-size: 18px; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold-light);
  font: 800 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 1.6px;
  text-shadow: 2px 2px #000;
}

h1, h2 {
  margin: 0;
  color: #ffe4a4;
  letter-spacing: -2px;
  -webkit-text-stroke: 3px #111;
  paint-order: stroke fill;
  text-shadow: 0 5px #d85409, 0 9px #050505;
  transform: skew(-4deg);
}

h1 { font-size: clamp(54px, 15vw, 76px); line-height: .98; }
h2 { font-size: 48px; line-height: 1; }

.subtitle {
  display: inline-block;
  margin: 8px 0 0;
  padding: 4px 16px 5px;
  color: #67e31d;
  background: #14120f;
  border: 3px solid #000;
  border-radius: 5px;
  font-size: 18px;
  letter-spacing: 1px;
  transform: skew(-3deg);
  box-shadow: 0 4px #d85409;
}

.hero {
  display: block;
  width: min(58vw, 245px);
  max-height: 35dvh;
  object-fit: contain;
  margin: 8px auto -2px;
  image-rendering: pixelated;
  filter: drop-shadow(0 10px 0 rgba(0, 0, 0, .45));
}

.instructions {
  margin: 8px auto 16px;
  color: var(--cream);
  font: 800 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-shadow: 2px 2px #000;
}

button {
  min-width: 210px;
  min-height: 56px;
  border: 4px solid #100b0b;
  border-radius: 9px;
  color: #13100b;
  background: linear-gradient(#ffd64d, #f49b00);
  box-shadow: 0 7px #9b3707, 0 11px #000;
  font: 900 25px/1 Impact, Haettenschweiler, sans-serif;
  letter-spacing: 1.5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:active {
  transform: translateY(5px);
  box-shadow: 0 2px #9b3707, 0 5px #000;
}

.best {
  color: var(--cream);
  font: 900 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 1px;
  text-shadow: 2px 2px #000;
  margin: 18px 0 0;
}

#game-over-screen {
  background: radial-gradient(circle at 50% 30%, #df5b12 0 12%, #371541 52%, #0e0e0b 100%);
}

#level-screen { background: radial-gradient(circle at 50% 32%, #f18110 0 14%, #401541 55%, #0e0e0b 100%); }
.level-stars { margin: 16px 0 2px; color: #ffd320; font-size: 50px; letter-spacing: 3px; -webkit-text-stroke: 3px #111; paint-order: stroke fill; text-shadow: 0 5px #ad4c08; }
.level-result, .final-level { color: #75e835; font: 900 15px/1.2 ui-monospace, monospace; letter-spacing: 1px; }
.level-panel .result-hero { width: 145px; height: 145px; }
.level-panel button { margin-top: 8px; }

.panel {
  padding: 22px 18px 25px;
  border: 5px solid #0e0e0b;
  border-radius: 13px;
  background: rgba(28, 16, 32, .88);
  box-shadow: inset 0 0 0 3px #6e3f28, 0 13px #090607;
}

.result-hero {
  width: 105px;
  height: 105px;
  object-fit: contain;
  margin: 8px auto -2px;
  image-rendering: pixelated;
}

.score-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto 12px;
  padding: 11px 15px;
  max-width: 290px;
  border: 3px solid #100b0b;
  background: #f4a01e;
  color: #191117;
  font: 900 15px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.score-card strong { font-size: 23px; }
.new-record { color: #73ed28; margin: 0 0 13px; letter-spacing: 1px; }
.hidden { visibility: hidden; }
.secondary { margin-top: 16px; min-height: 46px; font-size: 18px; background: #f6f2e8; box-shadow: 0 6px #8d8171, 0 10px #000; }

.submit-score {
  display: grid;
  gap: 7px;
  max-width: 290px;
  margin: 0 auto 15px;
}

.submit-score label {
  color: var(--gold);
  font: 900 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 1px;
  text-align: left;
}

.submit-score input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 3px solid #0e0e0b;
  border-radius: 5px;
  outline: none;
  color: #171019;
  background: var(--cream);
  font: 900 17px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
}

.submit-score button { min-width: 100%; }
.score-status { min-height: 13px; margin: 0; color: #73ed28; font: 800 11px/1.2 ui-monospace, monospace; }

.ranking-panel { max-height: calc(100dvh - 48px); overflow: hidden; }
.ranking-mode { margin: 12px 0 8px; color: #f6f2e8; font: 800 11px/1 ui-monospace, monospace; letter-spacing: 1px; }
.ranking-list { margin: 0; padding: 0; list-style: none; counter-reset: position; }
.ranking-list li {
  counter-increment: position;
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  align-items: center;
  gap: 8px;
  min-height: 39px;
  padding: 4px 10px;
  border-bottom: 2px solid rgba(251, 183, 3, .22);
  color: var(--cream);
  font: 900 14px/1 ui-monospace, monospace;
  text-align: left;
}
.ranking-list li::before { content: counter(position) "."; color: var(--gold); }
.ranking-list li:nth-child(1) { color: #ffe35a; font-size: 17px; }
.ranking-list li:nth-child(2) { color: #e6e6e6; }
.ranking-list li:nth-child(3) { color: #e99a54; }
.ranking-list strong { color: var(--gold); font-size: 14px; }
.ranking-list em { color: #75e835; font-size: 11px; font-style: normal; }
.ranking-list .empty { display: block; padding: 32px 10px; text-align: center; color: #c9bdad; }
.ranking-list .empty::before { content: ""; }

.sound {
  position: absolute;
  z-index: 9;
  top: auto;
  bottom: max(18px, env(safe-area-inset-bottom));
  right: 12px;
  min-width: 42px;
  min-height: 42px;
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 21px;
  border-width: 3px;
  box-shadow: 0 4px #9b3707, 0 7px #000;
}

.tap-hint {
  position: absolute;
  left: 50%;
  bottom: max(55px, calc(env(safe-area-inset-bottom) + 34px));
  z-index: 3;
  transform: translateX(-50%);
  width: max-content;
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, .8);
  color: white;
  background: rgba(0, 0, 0, .65);
  font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  opacity: 0;
  transition: opacity .2s;
}

.tap-hint.show { opacity: 1; animation: pulse .9s steps(2) infinite; }

@keyframes pulse { 50% { transform: translateX(-50%) scale(1.06); } }

@media (max-height: 700px) {
  .hero { width: 175px; max-height: 29dvh; }
  .instructions { margin: 4px auto 10px; }
  h1 { font-size: 54px; }
  button { min-height: 50px; }
  #game-over-screen .panel { transform: scale(.88); }
  .menu-layout { padding-top: max(16px, env(safe-area-inset-top)); }
  .menu-controls { top: 166px; width: min(calc(100% - 76px), 280px); padding-block: 6px 8px; }
  .menu-controls .instructions { font-size: 11px; }
  .menu-controls button { min-height: 40px; }
  .menu-controls .secondary { min-height: 37px; }
  .menu-don { bottom: 110px; width: min(38vw, 145px); }
  .menu-sidekicks { right: -1%; bottom: 82px; width: min(38vw, 145px); }
}
