* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,176,80,.15), transparent 28%),
    radial-gradient(circle at 80% 15%, rgba(115,255,120,.08), transparent 22%),
    radial-gradient(circle at center, #4b3426 0%, #1e1713 75%);
  color: #fff4df;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
}

#game-shell {
  width: min(100vw, 760px);
  margin: 0 auto;
  padding: 10px;
  position: relative;
  z-index: 1;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 5vw, 44px);
  letter-spacing: 2px;
  text-shadow: 3px 3px 0 #000;
}

#hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  font-size: 14px;
  align-items: center;
}

#hud span,
#sound-toggle {
  background: rgba(0,0,0,.35);
  border: 2px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 6px 10px;
  color: #fff4df;
}

#sound-toggle {
  cursor: pointer;
  min-width: 46px;
  font-size: 16px;
}

canvas {
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
  display: block;
  width: min(100%, calc(100vh - 120px) * 0.875);
  max-height: calc(100vh - 120px);
  aspect-ratio: 7 / 8;
  margin: 0 auto;
  image-rendering: auto;
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
  background: #241914;
}

#message {
  margin: 8px auto 0;
  max-width: 672px;
  text-align: center;
  font-size: 13px;
  line-height: 1.35;
  color: #ffe7bd;
}

/* START SCREEN */
#start-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 22% 18%, rgba(255,186,94,.22), transparent 26%),
    radial-gradient(circle at 78% 14%, rgba(96,255,105,.10), transparent 20%),
    radial-gradient(circle at 50% 60%, rgba(109,69,39,.20), transparent 38%),
    linear-gradient(135deg, rgba(17,12,10,.96), rgba(37,24,17,.92));
  transition: opacity .35s ease, visibility .35s ease, transform .35s ease;
}

#start-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .55;
  background-image:
    radial-gradient(circle, rgba(255,255,220,.45) 1px, transparent 1.5px),
    radial-gradient(circle, rgba(255,206,150,.24) 1px, transparent 1.5px);
  background-size: 34px 34px, 56px 56px;
  background-position: 0 0, 14px 22px;
  filter: blur(.2px);
}

.start-card {
  position: relative;
  width: min(1100px, 100%);
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  gap: 28px;
  align-items: center;
  padding: 34px;
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,.08);
  background:
    linear-gradient(180deg, rgba(70,43,28,.78), rgba(27,18,14,.86));
  box-shadow: 0 30px 70px rgba(0,0,0,.45);
  overflow: hidden;
}

.start-card::before {
  content: "";
  position: absolute;
  inset: auto -10% -30% auto;
  width: 300px;
  height: 300px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(110,255,120,.16), transparent 62%);
  pointer-events: none;
}

.start-copy {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 10px 0;
  letter-spacing: 2px;
  font-size: 12px;
  color: #ffcc84;
  font-weight: 700;
}

.start-copy h2 {
  margin: 0 0 14px;
  font-size: clamp(44px, 9vw, 84px);
  line-height: .95;
  letter-spacing: 2px;
  color: #fff5e3;
  text-shadow: 4px 4px 0 #000;
}

.lead {
  margin: 0 0 18px;
  color: #ffe7bd;
  font-size: clamp(15px, 2vw, 18px);
  line-height: 1.45;
  max-width: 560px;
}

.feature-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 22px;
}

.feature-pills span {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.08);
  color: #fff4df;
  font-size: 14px;
}

.start-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.big-btn,
.ghost-btn {
  border: none;
  cursor: pointer;
  border-radius: 999px;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.big-btn:hover,
.ghost-btn:hover,
#sound-toggle:hover {
  transform: translateY(-1px);
}

.big-btn {
  padding: 14px 26px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #1b120e;
  background: linear-gradient(180deg, #ffd17b, #ffb24b);
  box-shadow: 0 10px 22px rgba(255,172,70,.25);
}

.ghost-btn {
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 700;
  color: #fff4df;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
}

.hero-visual {
  position: relative;
  min-height: 360px;
  display: grid;
  place-items: center;
}

.hero-glow {
  position: absolute;
  width: min(70vw, 420px);
  height: min(70vw, 420px);
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(255,198,110,.38), rgba(255,198,110,.10) 46%, transparent 66%);
  filter: blur(8px);
}

#hero-tank {
  position: relative;
  z-index: 1;
  width: min(58vw, 470px);
  height: auto;
  image-rendering: auto;
  background: transparent;
  transform: rotate(-3deg);
  filter: drop-shadow(0 28px 34px rgba(0,0,0,.58));
  animation: floatTank 2.8s ease-in-out infinite;
}

@keyframes floatTank {
  0%, 100% { transform: rotate(-3deg) translateY(0px); }
  50% { transform: rotate(-1deg) translateY(-9px); }
}

@media (max-width: 900px) {
  #start-screen { padding: 16px; }
  .start-card {
    grid-template-columns: 1fr;
    text-align: center;
    padding: 24px 18px;
  }
  .feature-pills,
  .start-actions {
    justify-content: center;
  }
  .lead {
    margin-left: auto;
    margin-right: auto;
  }
  .hero-visual {
    order: -1;
    min-height: 220px;
  }
  #hero-tank {
    width: min(78vw, 350px);
  }
}


/* CONTROLES TÁCTILES */
#touch-controls {
  width: min(210px, 52vw);
  margin: 8px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 44px);
  gap: 6px;
  justify-content: center;
  align-items: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.dir-btn {
  width: 54px;
  height: 44px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.35);
  color: #fff4df;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 12px rgba(0,0,0,.25);
  touch-action: manipulation;
}

.dir-btn:active {
  transform: translateY(1px) scale(.98);
  background: rgba(255,191,90,.28);
}

.dir-btn.center {
  font-size: 13px;
  opacity: .45;
}

.dir-btn.empty {
  visibility: hidden;
  pointer-events: none;
}

@media (min-width: 760px) and (pointer: fine) {
  #touch-controls {
    display: none;
  }
}

@media (max-height: 820px) {
  #touch-controls {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 36px);
    gap: 5px;
    margin-top: 4px;
  }

  .dir-btn {
    width: 44px;
    height: 36px;
    font-size: 17px;
    border-radius: 12px;
  }

  #message {
    font-size: 12px;
    margin-top: 4px;
  }

  canvas {
    max-height: calc(100vh - 172px);
    width: min(100%, calc(100vh - 172px) * 0.875);
  }
}


/* v9h estable: cruceta oculta en escritorio, compacta en móvil */
@media (min-width: 761px) and (pointer: fine) {
  #touch-controls {
    display: none !important;
  }

  canvas {
    max-height: calc(100vh - 112px);
    width: min(100%, calc(100vh - 112px) * 0.875);
  }
}

@media (max-width: 760px), (pointer: coarse) {
  #touch-controls {
    display: grid !important;
    width: 144px;
    margin: 5px auto 0;
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 34px);
    gap: 5px;
  }

  .dir-btn {
    width: 42px;
    height: 34px;
    font-size: 16px;
    border-radius: 11px;
    padding: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  canvas {
    max-height: calc(100vh - 174px);
    width: min(100%, calc(100vh - 174px) * 0.875);
  }

  #message {
    font-size: 11.5px;
    line-height: 1.25;
    margin-top: 4px;
  }
}


/* v9p: recuperación desde v9j. No se toca la lógica de movimiento. */
@media (min-width: 761px) and (pointer: fine) {
  #touch-controls {
    display: none !important;
  }

  canvas {
    max-height: calc(100vh - 112px);
    width: min(100%, calc(100vh - 112px) * 0.875);
  }
}

@media (max-width: 760px), (pointer: coarse) {
  #touch-controls {
    display: grid !important;
    width: 144px;
    margin: 5px auto 0;
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 34px);
    gap: 5px;
  }

  .dir-btn {
    width: 42px;
    height: 34px;
    font-size: 16px;
    border-radius: 11px;
    padding: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  canvas {
    max-height: calc(100vh - 174px);
    width: min(100%, calc(100vh - 174px) * 0.875);
  }

  #message {
    font-size: 11.5px;
    line-height: 1.25;
    margin-top: 4px;
  }
}


/* v9w: ajustes muy suaves para Safari, sin tocar la física del movimiento */
@supports (-webkit-touch-callout: none) {
  canvas {
    transform: translateZ(0);
    backface-visibility: hidden;
  }
}


/* v10: modo experto */
.expert-toggle {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  margin: 0 0 20px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(0,0,0,.24);
  border: 1px solid rgba(255,255,255,.11);
  cursor: pointer;
  text-align: left;
  max-width: 560px;
}

.expert-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.expert-box {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255,255,255,.16);
  border: 2px solid rgba(255,255,255,.16);
  position: relative;
  flex: 0 0 auto;
  transition: background .18s ease, border-color .18s ease;
}

.expert-box::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  border-radius: 999px;
  background: #fff4df;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
  transition: transform .18s ease;
}

.expert-toggle input:checked + .expert-box {
  background: rgba(92,255,105,.28);
  border-color: rgba(120,255,120,.45);
}

.expert-toggle input:checked + .expert-box::after {
  transform: translateX(20px);
}

.expert-toggle b {
  display: block;
  color: #fff4df;
  font-size: 15px;
}

.expert-toggle small {
  display: block;
  color: #ffdca3;
  font-size: 12.5px;
  line-height: 1.25;
  margin-top: 2px;
}

@media (max-width: 900px) {
  .expert-toggle {
    margin-left: auto;
    margin-right: auto;
    text-align: left;
  }
}
