:root {
  --gold: #c8aa6e;
  --gold-light: #f0e6d2;
  --gold-dark: #463714;
  --blue: #0a1428;
  --ink: #010a13;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--gold-light);
  font-family: 'Segoe UI', system-ui, sans-serif;
}

canvas { display: block; position: fixed; inset: 0; touch-action: none; image-rendering: pixelated; }
#gl { pointer-events: none; }

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  overflow-y: auto;
  padding: 24px 16px;
  background: radial-gradient(ellipse at center, rgba(1, 10, 19, 0.8), rgba(1, 10, 19, 0.97));
}
.screen.overlay { background: rgba(1, 10, 19, 0.72); }
.hidden { display: none !important; }

.panel {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

h1, h2 { font-family: 'Cinzel', Georgia, serif; letter-spacing: 3px; }
h1 {
  font-size: clamp(36px, 7vw, 72px);
  text-shadow: 0 0 24px rgba(200, 170, 110, 0.45);
}
h1 span { color: var(--gold); }
h2 { font-size: clamp(28px, 5vw, 48px); color: var(--gold); }
h2.victory { color: #5fd3ff; text-shadow: 0 0 24px rgba(95, 211, 255, 0.5); }
h2.defeat { color: #e84a4a; text-shadow: 0 0 24px rgba(232, 74, 74, 0.5); }
.sub { color: var(--gold); font-size: 17px; }
.hint { color: #8a8f99; font-size: 13px; }

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Selección de campeón ---------- */
.champ-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 210px));
  gap: 14px;
}
@media (max-width: 920px) {
  .champ-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
}
.champ-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 12px;
  background: linear-gradient(180deg, #0f1e33, var(--blue));
  border: 2px solid var(--gold-dark);
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.champ-card:hover, .champ-card:focus-visible {
  outline: none;
  border-color: var(--gold);
  transform: translateY(-3px);
  box-shadow: 0 0 18px rgba(200, 170, 110, 0.35);
}
.portrait {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--c) 55%, #0a1428), #0a1428 75%);
  border: 3px solid var(--a);
}
.portrait-img {
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-position: 0 0;
  image-rendering: pixelated;
  transform: scale(2.1) translateY(14%);
}
.portrait-img.sheet { transform: scale(2) translateY(24%); }
.cname { font-family: 'Cinzel', Georgia, serif; font-size: 20px; font-weight: 700; }
.ctitle { color: var(--gold); font-size: 12px; font-style: italic; }
.cstats { font-size: 13px; color: #c9d1dc; }
.cab { font-size: 13px; font-weight: 600; }
.cpassive { font-size: 12px; color: #9aa3ad; line-height: 1.35; }

/* ---------- Subida de nivel ---------- */
.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; }
.choice {
  position: relative;
  width: 220px;
  min-height: 230px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 14px;
  background: linear-gradient(180deg, #13243d, var(--blue));
  border: 2px solid var(--gold-dark);
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.choice:hover, .choice:focus-visible {
  outline: none;
  border-color: var(--c);
  transform: translateY(-4px);
  box-shadow: 0 0 22px color-mix(in srgb, var(--c) 45%, transparent);
}
.choice-key {
  position: absolute;
  top: 8px;
  left: 10px;
  color: #6b7380;
  font-size: 12px;
  font-weight: 700;
}
.choice-icon {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  font-size: 32px;
  border: 2px solid var(--c);
  background: rgba(0, 0, 0, 0.35);
}
.choice-name { font-weight: 700; font-size: 16px; }
.choice-kind { color: var(--gold); font-size: 12px; }
.choice-desc { color: #c9d1dc; font-size: 13px; line-height: 1.4; }
.tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  font-size: 11px;
  background: #24324a;
  color: var(--gold-light);
  vertical-align: middle;
}
.tag.new { background: #c8aa6e; color: #10141c; }

/* ---------- Pausa / fin de partida ---------- */
.build { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 640px; }
.chip {
  padding: 5px 10px;
  font-size: 13px;
  background: var(--blue);
  border: 1px solid var(--c);
}
.chip b { color: var(--gold); margin-left: 4px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  width: min(640px, 100%);
}
.stats div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  background: var(--blue);
  border: 1px solid var(--gold-dark);
}
.stats span { color: #8a8f99; font-size: 12px; }
.stats b { font-size: 20px; }

.buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.buttons button {
  min-width: 170px;
  padding: 12px 22px;
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #1e2328, #0f1317);
  border: 2px solid var(--gold);
  color: var(--gold-light);
}
.buttons button:hover { background: linear-gradient(180deg, #2a3038, #151a20); box-shadow: 0 0 14px rgba(200, 170, 110, 0.4); }
.buttons button.secondary { border-color: #5b5a56; color: #a09b8c; }

/* ---------- Etapas ---------- */
.stage-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.stage-chip {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--gold-light);
  background: var(--blue);
  border: 1px solid var(--gold-dark);
}
.stage-chip small { color: #8a8f99; }
.next-stage { max-width: 520px; color: #c9d1dc; line-height: 1.5; }
.next-stage b { color: var(--gold); }

/* ---------- Audio ---------- */
.audio-settings { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; }
.audio-settings label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.audio-settings input { accent-color: var(--gold); width: 130px; }
.mute-btn {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  width: 40px;
  height: 40px;
  font-size: 20px;
  background: rgba(10, 20, 40, 0.8);
  border: 1px solid var(--gold-dark);
}
.mute-btn:hover { border-color: var(--gold); }

/* Iconos importados (pixel art) */
.px-icon {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  vertical-align: middle;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}
.choice-icon .px-icon { width: 46px; height: 46px; }

/* ---------- Móvil y PWA ---------- */
:root {
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
html, body {
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
.screen { padding-left: max(16px, var(--sal)); padding-right: max(16px, var(--sar)); }

/* Botón de pausa: sólo en pantallas táctiles durante la partida */
.pause-btn {
  display: none;
  position: fixed;
  top: calc(22px + var(--sat));
  right: calc(10px + var(--sar));
  z-index: 20;
  width: 42px;
  height: 42px;
  font-size: 14px;
  letter-spacing: -2px;
  color: var(--gold-light);
  background: rgba(10, 20, 40, 0.7);
  border: 1px solid var(--gold-dark);
  border-radius: 50%;
}
body.touch.in-game .pause-btn { display: block; }
body.touch.in-game .mute-btn { display: none; }
.mute-btn { right: calc(12px + var(--sar)); bottom: calc(12px + var(--sab)); }

/* Aviso para girar el móvil */
.rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px;
  text-align: center;
  font-family: 'Cinzel', Georgia, serif;
  font-size: 20px;
  color: var(--gold-light);
  background: var(--ink);
}
.rotate-phone {
  width: 54px;
  height: 92px;
  border: 4px solid var(--gold);
  border-radius: 10px;
  animation: rotate-phone 1.8s ease-in-out infinite;
}
@keyframes rotate-phone {
  0%, 20% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}
@media (orientation: portrait) and (pointer: coarse) {
  .rotate { display: flex; }
}

/* Pantallas bajas (móvil en horizontal) */
@media (max-height: 520px) {
  .panel { gap: 10px; }
  h1 { font-size: 34px; }
  h2 { font-size: 26px; }
  .sub { font-size: 13px; }
  .hint, .stage-list { display: none; }
  .champ-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; width: min(100%, 900px); }
  .champ-card { padding: 8px 4px; gap: 3px; }
  .portrait { width: 52px; height: 52px; }
  .cname { font-size: 13px; }
  .ctitle, .cstats, .cpassive { display: none; }
  .cab { font-size: 10px; line-height: 1.2; }
  .choices { gap: 8px; flex-wrap: nowrap; }
  .choice { width: 31vw; max-width: 220px; min-height: 0; padding: 10px 8px; gap: 4px; }
  .choice-icon { width: 44px; height: 44px; font-size: 24px; }
  .choice-icon .px-icon { width: 36px; height: 36px; }
  .choice-name { font-size: 14px; }
  .choice-desc { font-size: 12px; }
  .stats { gap: 6px; }
  .stats div { padding: 6px; }
  .stats b { font-size: 16px; }
  .buttons button { min-width: 140px; padding: 9px 14px; }
}
@media (max-height: 520px) and (max-width: 700px) {
  .champ-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.audio-settings select {
  font: inherit;
  color: var(--gold-light);
  background: var(--blue);
  border: 1px solid var(--gold-dark);
  padding: 3px 6px;
}

/* Aviso para instalar como app */
.install {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--sab));
  z-index: 110; /* por encima del aviso de girar el móvil */
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #13243d, var(--blue));
  border: 1px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
  animation: install-in 0.35s ease-out;
}
@keyframes install-in { from { transform: translate(-50%, 30px); opacity: 0; } }
.install img { width: 48px; height: 48px; border-radius: 10px; image-rendering: pixelated; flex: none; }
.install-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 1.35; text-align: left; }
.install-text b { font-family: 'Cinzel', Georgia, serif; color: var(--gold-light); font-size: 15px; }
.install-text span { color: #c9d1dc; }
.install-btn {
  flex: none;
  padding: 9px 16px;
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  color: #10141c;
  background: var(--gold);
  border: none;
  border-radius: 8px;
}
.install-close { flex: none; width: 32px; height: 32px; color: #8a8f99; background: none; border: none; font-size: 16px; }
body.in-game .install { display: none; }
