:root {
  --bg: #0b1030;
  --panel: rgba(8, 12, 40, 0.88);
  --line: rgba(255, 255, 255, 0.18);
  --accent: #7be8ff;
  --good: #4dff6a;
  --warn: #ffd23f;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

canvas#game { position: fixed; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
[hidden] { display: none !important; }

h1, h2 { margin: 0; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55), 0 0 18px rgba(0, 0, 0, 0.45); letter-spacing: 0.5px; }

/* ----- botones ----- */
.btn {
  appearance: none; border: 3px solid #000; border-radius: 12px; padding: 12px 22px;
  font: inherit; font-size: 1.1rem; color: #fff; cursor: pointer;
  background: linear-gradient(#3d4a9c, #232d70);
  box-shadow: 0 4px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.25);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  transition: transform 0.08s, filter 0.12s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.25); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.btn:disabled { filter: grayscale(0.8) brightness(0.7); cursor: not-allowed; }
.btn-primary { background: linear-gradient(#52e86c, #1fa83b); }
.btn-danger { background: linear-gradient(#f05a5a, #b02020); }
.btn-xl { font-size: 1.7rem; padding: 14px 44px; }
.btn-small { padding: 8px 14px; font-size: 0.95rem; }
.btn-install { background: linear-gradient(#ffcc33, #e08a00); }

.icon-btn {
  appearance: none; width: 44px; height: 44px; border: 3px solid #000; border-radius: 12px;
  background: rgba(10, 14, 50, 0.75); color: #fff; font: inherit; font-size: 1.05rem; cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 3px 0 #000;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }

/* ----- pantallas ----- */
.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  gap: 14px; text-align: center;
}
.screen.modal { background: rgba(0, 0, 8, 0.55); z-index: 5; }
.panel {
  background: var(--panel); border: 3px solid #000; border-radius: 18px; padding: 22px 28px;
  display: flex; flex-direction: column; gap: 12px; min-width: min(86vw, 340px); max-height: 94vh; overflow: auto;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.5);
}
.panel h2 { font-size: 1.9rem; }
.level-name { margin: 0; color: var(--accent); font-size: 1.2rem; }
.stats { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 6px; font-size: 1.1rem; }
.stats li { display: flex; justify-content: space-between; gap: 24px; }
.stats b { color: var(--warn); }

.title {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 0.15em 0.3em;
  font-size: clamp(2rem, 8vw, 4.6rem); line-height: 1.05; margin-bottom: 6px;
  -webkit-text-stroke: 2px #000; paint-order: stroke fill;
}
.title .t-small { font-size: 0.55em; color: #fff; }
.title .t-big { color: var(--warn); }
.title span.letter {
  display: inline-block; color: var(--warn);
  animation: hop 1.6s ease-in-out infinite; animation-delay: calc(var(--i) * 0.08s);
}
@keyframes hop { 0%, 55%, 100% { transform: translateY(0); } 25% { transform: translateY(-0.22em); } }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; align-items: stretch; min-width: min(80vw, 280px); }
.hint { margin: 0; color: rgba(255, 255, 255, 0.8); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7); max-width: 34em; }
.hint.small { font-size: 0.85rem; font-weight: 700; }

.chip {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); z-index: 4;
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px;
  background: rgba(8, 12, 40, 0.85); border: 3px solid #000; font-size: 1.05rem; box-shadow: 0 3px 0 #000;
}
.coin-ico { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff3a0, #ffd23f 55%, #c78a00); border: 2px solid #7a4a00; }

.screen-head { display: flex; align-items: center; gap: 14px; width: 100%; max-width: 1100px; justify-content: flex-start; padding-top: 38px; }
.screen-head h2 { font-size: 1.7rem; }
#screen-levels, #screen-shop { justify-content: flex-start; }

/* ----- selector de niveles ----- */
.level-list {
  display: flex; gap: 14px; width: 100%; max-width: 1200px; overflow-x: auto; overflow-y: auto; padding: 8px 6px 18px; min-height: 0;
  scroll-snap-type: x proximity; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; align-items: stretch;
}
.level-card {
  flex: 0 0 min(78vw, 262px); scroll-snap-align: center; border: 3px solid #000; border-radius: 16px; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center; position: relative;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.5); color: #fff;
}
.level-card .num { font-size: 0.85rem; opacity: 0.9; }
.level-card .lname { font-size: 1.2rem; line-height: 1.1; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6); }
.diffs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; }
.dbtn {
  appearance: none; border: 3px solid #000; border-radius: 10px; padding: 4px 6px; font: inherit; color: #fff; cursor: pointer;
  background: rgba(0, 0, 0, 0.45); display: flex; flex-direction: column; align-items: center; line-height: 1.1;
  box-shadow: 0 3px 0 #000; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.8); transition: transform 0.08s, filter 0.12s;
}
.dbtn .dn { font-size: 0.85rem; color: var(--c); }
.dbtn .dp { font-size: 0.78rem; opacity: 0.9; }
.dbtn.sel { background: var(--c); border-color: #fff; box-shadow: 0 3px 0 #000, 0 0 12px var(--c); }
.dbtn.sel .dn { color: #000; text-shadow: none; }
.dbtn.sel .dp { color: #000; text-shadow: none; opacity: 0.85; }
.dbtn.off { filter: grayscale(0.7) brightness(0.75); }
.dbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.diff-name { margin: 0; font-size: 1.1rem; letter-spacing: 0.5px; }
.hint.extra { color: #d9a8ff; font-size: 1rem; }
.unlock-hint { font-size: 0.72rem; color: rgba(255, 255, 255, 0.75); line-height: 1.15; }
.level-card .prog { font-size: 0.9rem; display: grid; gap: 2px; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.7); }
.level-card .coins { letter-spacing: 3px; color: var(--warn); font-size: 1.1rem; }
.level-card .acts { display: flex; gap: 8px; margin-top: auto; flex-wrap: wrap; justify-content: center; }
.level-card.locked { filter: grayscale(0.85) brightness(0.65); }
.level-card .lock { font-size: 2rem; }
.level-card .reward { font-size: 0.8rem; opacity: 0.9; }

/* ----- tienda ----- */
.skin-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; width: 100%; max-width: 1100px;
  overflow-y: auto; padding: 6px 6px 24px; touch-action: pan-y; align-content: start; flex: 1;
}
.skin-card {
  background: var(--panel); border: 3px solid #000; border-radius: 14px; padding: 10px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.5);
}
.skin-card.equipped { border-color: var(--good); }
.skin-card canvas { width: 88px; height: 88px; }
.skin-card .sname { font-size: 1rem; }
.skin-card .price { font-size: 0.9rem; color: var(--warn); }
.skin-card .btn { padding: 6px 14px; font-size: 0.95rem; width: 100%; }

/* ----- HUD ----- */
.hud { position: fixed; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; gap: 8px; z-index: 3; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(8, 12, 40, 0.92); border: 3px solid #000; border-radius: 12px; padding: 10px 18px; z-index: 9;
  pointer-events: none; animation: toast-in 0.2s ease-out; text-align: center; max-width: 90vw;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

.rotate-hint {
  position: fixed; left: 50%; top: max(52px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 8;
  background: rgba(255, 210, 63, 0.95); color: #000; padding: 8px 16px; border-radius: 999px; border: 3px solid #000;
  pointer-events: none; font-size: 0.9rem; text-align: center; max-width: 92vw;
}
@media (orientation: landscape) { .rotate-hint { display: none !important; } }

@media (max-height: 520px) {
  .screen { gap: 8px; }
  .btn-xl { font-size: 1.3rem; padding: 10px 34px; }
  .title { font-size: clamp(1.6rem, 6vw, 3rem); }
  .screen-head { padding-top: 34px; }
  .panel { padding: 14px 22px; gap: 8px; }
  .menu-buttons { gap: 8px; }
  .btn { padding: 9px 18px; font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) { .title span.letter { animation: none; } }
