:root {
  --masa: #e9c46a;
  --masa-osc: #b8862b;
  --verde: #2a9d8f;
  --verde-osc: #1d5c4f;
  --chile: #e63946;
  --tinta: #1b1b1b;
  --papel: #fff8e7;
  --sombra: rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #10201c;
  color: var(--papel);
  font-family: "Trebuchet MS", system-ui, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #10201c;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; padding: 12px; }
.hud-top, .hud-bottom { display: flex; gap: 10px; }
.hud-top { justify-content: flex-start; }
.hud-bottom { position: absolute; left: 12px; right: 12px; bottom: 12px; align-items: flex-end; justify-content: space-between; }
.hud-box {
  background: rgba(16, 32, 28, .75);
  border: 2px solid var(--masa);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex; flex-direction: column; align-items: center;
  font-size: 22px; font-weight: bold; min-width: 80px;
}
.hud-box.speed { font-size: 34px; }
.lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: .8; font-weight: normal; }
.oil-wrap { background: rgba(16, 32, 28, .75); border: 2px solid var(--masa); border-radius: 10px; padding: 6px 12px; width: min(300px, 45vw); }
.oil-bar { height: 14px; background: #333; border-radius: 7px; overflow: hidden; margin-top: 4px; }
#hud-oil { height: 100%; width: 0; background: linear-gradient(90deg, #f4a261, #ffd166); transition: width .1s; }
#hud-oil.full { box-shadow: 0 0 12px #ffd166; animation: pulso .6s infinite alternate; }
@keyframes pulso { to { filter: brightness(1.4); } }

#hud-msg {
  position: absolute; top: 30%; left: 0; right: 0; text-align: center;
  font-size: clamp(32px, 8vw, 72px); font-weight: 900;
  color: var(--masa); text-shadow: 4px 4px 0 var(--chile), 0 0 20px #000;
}

/* ---------- Controles táctiles ---------- */
#touch { position: absolute; inset: auto 0 80px 0; display: flex; justify-content: space-between; padding: 0 16px; }
#touch .t-left, #touch .t-right { display: flex; align-items: flex-end; }
@media (orientation: portrait) {
  #touch { bottom: 110px; }
  #hud .hud-top::after {
    content: '📱 Gira tu celular para jugar mejor';
    position: absolute; top: 90px; left: 0; right: 0; text-align: center; font-size: 14px; opacity: .8;
  }
}
#touch button {
  width: 68px; height: 68px; border-radius: 50%;
  border: 3px solid var(--masa); background: rgba(16, 32, 28, .55);
  color: var(--papel); font-size: 26px; margin: 4px; touch-action: none;
}
#touch .t-gas { background: rgba(42, 157, 143, .7); }
#touch .t-oil { background: rgba(244, 162, 97, .7); }
@media (hover: hover) and (pointer: fine) { #touch { display: none !important; } }

/* ---------- Pantallas ---------- */
#screens:empty { display: none; }
#screens {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at top, rgba(42,157,143,.35), rgba(10,20,18,.92) 70%);
  overflow-y: auto; padding: 24px 16px;
}
.screen { max-width: 920px; margin: 0 auto; }
.logo {
  text-align: center; font-size: clamp(40px, 9vw, 84px); font-weight: 900; line-height: .95; margin: 10px 0 4px;
  color: var(--masa); text-shadow: 5px 5px 0 var(--chile), 9px 9px 0 var(--verde-osc);
}
.sub { text-align: center; opacity: .85; margin: 0 0 20px; }
h2 { color: var(--masa); margin: 0 0 12px; font-size: 30px; }
.fila { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.entre { justify-content: space-between; }
.centro { justify-content: center; }

.btn {
  font: inherit; font-weight: bold; font-size: 18px; cursor: pointer;
  padding: 12px 22px; border-radius: 12px; border: 3px solid var(--tinta);
  background: var(--masa); color: var(--tinta);
  box-shadow: 0 5px 0 var(--masa-osc);
  transition: transform .08s, box-shadow .08s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--masa-osc); }
.btn.verde { background: var(--verde); color: var(--papel); box-shadow: 0 5px 0 var(--verde-osc); }
.btn.rojo { background: var(--chile); color: var(--papel); box-shadow: 0 5px 0 #8d1d26; }
.btn.chico { font-size: 14px; padding: 8px 14px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

.monedas {
  background: var(--tinta); border: 2px solid var(--masa); border-radius: 30px;
  padding: 6px 14px; font-weight: bold; font-size: 18px;
}

.panel {
  background: rgba(16, 32, 28, .85); border: 2px solid rgba(233, 196, 106, .5);
  border-radius: 16px; padding: 16px; margin-bottom: 16px;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.tarjeta {
  background: rgba(0, 0, 0, .3); border: 2px solid rgba(255, 248, 231, .15);
  border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px;
}
.tarjeta.activa { border-color: var(--masa); box-shadow: 0 0 0 2px var(--masa) inset; }
.tarjeta.bloq { opacity: .55; }
.tarjeta h3 { margin: 0; font-size: 18px; }
.tarjeta p { margin: 0; font-size: 14px; opacity: .85; }
.tarjeta .emoji { font-size: 34px; }

.niveles { display: flex; gap: 4px; }
.niveles i { flex: 1; height: 8px; border-radius: 4px; background: #444; }
.niveles i.on { background: var(--masa); }

.stat { display: grid; grid-template-columns: 110px 1fr 36px; gap: 8px; align-items: center; font-size: 14px; margin: 6px 0; }
.stat .barra { height: 12px; background: #333; border-radius: 6px; overflow: hidden; }
.stat .barra div { height: 100%; background: linear-gradient(90deg, var(--verde), var(--masa)); }

.pista-img { height: 110px; border-radius: 8px; background-size: cover; }

input[type=text], input[type=email] {
  user-select: text;
  -webkit-user-select: text;
  font: inherit; font-size: 20px; padding: 10px 14px; border-radius: 10px;
  border: 3px solid var(--masa); background: var(--papel); color: var(--tinta); width: min(340px, 100%);
}

table.resultados { width: 100%; border-collapse: collapse; font-size: 18px; }
table.resultados td { padding: 8px; border-bottom: 1px solid rgba(255,255,255,.1); }
table.resultados tr.yo { background: rgba(233, 196, 106, .25); font-weight: bold; }

.aviso { font-size: 13px; opacity: .7; text-align: center; margin-top: 8px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--tinta); border: 2px solid var(--masa); padding: 10px 18px; border-radius: 10px; z-index: 10;
}

.form-cuenta { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.form-cuenta label { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 14px; width: min(340px, 100%); }
.form-cuenta input { width: 100%; }
input[type=password] {
  user-select: text; -webkit-user-select: text;
  font: inherit; font-size: 20px; padding: 10px 14px; border-radius: 10px;
  border: 3px solid var(--masa); background: var(--papel); color: var(--tinta);
}
.enlace { color: var(--masa); }

#pago {
  position: absolute; inset: 0; z-index: 5; overflow-y: auto;
  background: rgba(10, 20, 18, .85); padding: 24px 16px;
}
.pago-caja {
  max-width: 560px; margin: 0 auto; background: #fff; color: var(--tinta);
  border-radius: 16px; padding: 16px; border: 3px solid var(--masa);
}
.pago-caja h2 { color: var(--tinta); font-size: 20px; }
#checkout { margin-top: 12px; min-height: 300px; }

#preview { display: block; margin: 0 auto; width: 260px; height: 170px; }
