:root {
  --ink: #2c2016;
  --paper: #f7efdf;
  --paper-2: #eadcc2;
  --accent: #e2731c;
  --accent-dark: #a24d0c;
  --leaf: #4f8a2e;
  --danger: #e2392b;
  --hud-ink: #fffaf0;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #23301a;
  color: var(--ink);
  font-family: "Trebuchet MS", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
#fx-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.hidden { display: none !important; }

body.danger #stage::after {
  content: '';
  position: absolute; inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 120px rgba(226, 57, 43, 0.55);
  animation: danger-pulse 0.9s ease-in-out infinite;
}
@keyframes danger-pulse { 50% { opacity: 0.35; } }

/* ------------------------------------------------------------------ HUD */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 14px 0;
  color: var(--hud-ink);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
#hud button { pointer-events: auto; }
.hud-block .label { font-weight: 800; font-size: 16px; letter-spacing: 0.5px; }
.hud-block .label b { font-size: 20px; }
.hud-block .sub { font-size: 12px; font-weight: 700; opacity: 0.85; }
.hud-block.center { text-align: center; }
.hud-block.right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#hud-score { font-size: 30px; font-weight: 900; letter-spacing: 1px; line-height: 1; font-variant-numeric: tabular-nums; }
#hud-lives { font-size: 16px; letter-spacing: 2px; }
#hud-lives .life.lost { filter: grayscale(1); opacity: 0.3; }
.hud-buttons { display: flex; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 12px;
  background: rgba(255, 248, 232, 0.85);
  color: var(--ink);
  font-weight: 900; font-size: 16px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
  cursor: pointer;
  text-shadow: none;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); }

#bars {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}
.bar { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; }
.bar .track {
  width: min(160px, 28vw); height: 9px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}
.bar .fill { height: 100%; width: 0; border-radius: 6px; transition: width 0.15s linear; }
.fill.clear { background: linear-gradient(90deg, #7ccf4a, #c8f06b); }
.fill.danger { background: linear-gradient(90deg, #f2c94c, #f2994a); }
.fill.danger.alert { background: linear-gradient(90deg, #f2994a, var(--danger)); animation: danger-pulse 0.5s infinite; }
.bar-num { min-width: 2.5em; font-variant-numeric: tabular-nums; }

#power-badge {
  grid-column: 1 / -1;
  justify-self: center;
  background: rgba(255, 210, 60, 0.92);
  color: var(--ink);
  text-shadow: none;
  font-weight: 900;
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 14px;
}

/* ------------------------------------------------------- bola actual */
#ammo {
  position: fixed;
  z-index: 4;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 8px 10px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 248, 232, 0.88);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
#ammo:active { transform: translateY(2px); }
.ammo-dot {
  --c: #e53935;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #fff 0 12%, var(--c) 40%, color-mix(in srgb, var(--c) 60%, #000) 100%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
}
.ammo-dot.big { width: 34px; height: 34px; }
.ammo-swap { font-weight: 900; font-size: 18px; }

/* ------------------------------------------------------------ pantallas */
.overlay {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(20, 28, 12, 0.35), rgba(10, 14, 6, 0.75));
  backdrop-filter: blur(2px);
}
.panel {
  width: min(420px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--paper);
  border-radius: 22px;
  padding: 22px 22px 20px;
  text-align: center;
  box-shadow: 0 6px 0 #c7b38f, 0 18px 40px rgba(0, 0, 0, 0.45);
  animation: pop 0.25s ease-out;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.panel h1 { margin: 6px 0 8px; font-size: 32px; color: var(--accent-dark); letter-spacing: 0.5px; }
.panel h2 { margin: 0 0 10px; font-size: 26px; }
.panel p { margin: 8px 0; font-weight: 700; line-height: 1.35; }
.tagline { font-size: 15px; }
.how {
  text-align: left;
  background: var(--paper-2);
  border-radius: 14px;
  padding: 10px 14px 10px 30px;
  margin: 12px 0;
  font-size: 14px;
  line-height: 1.55;
}
.best-line { font-size: 14px; }
.big-score { font-size: 34px; font-weight: 900; color: var(--accent-dark); margin: 6px 0 2px !important; }

.logo { display: flex; justify-content: center; gap: 6px; margin-top: 4px; }
.seed {
  width: 26px; height: 26px; border-radius: 50%;
  box-shadow: inset -4px -5px 0 rgba(0, 0, 0, 0.18), 0 3px 4px rgba(0, 0, 0, 0.25);
  animation: roll 1.6s ease-in-out infinite;
}
.seed.s1 { background: #e53935; }
.seed.s2 { background: #fdd835; animation-delay: 0.1s; }
.seed.s3 { background: #1e88e5; animation-delay: 0.2s; }
.seed.s4 { background: #43a047; animation-delay: 0.3s; }
@keyframes roll { 50% { transform: translateY(-6px); } }

.panel-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.panel-actions.column { flex-direction: column; align-items: stretch; }
.btn {
  display: inline-block;
  border: none; border-radius: 14px;
  padding: 12px 22px;
  font: inherit; font-weight: 900; font-size: 17px;
  background: var(--accent); color: #fff;
  box-shadow: 0 4px 0 var(--accent-dark);
  cursor: pointer;
  text-decoration: none;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn.ghost { background: var(--paper-2); color: var(--ink); box-shadow: 0 4px 0 #bfa983; }
#btn-play { font-size: 22px; padding: 14px 40px; letter-spacing: 2px; }

/* -------------------------------------------------- textos flotantes */
.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 22px;
  color: #fff;
  -webkit-text-stroke: 1.5px rgba(40, 25, 10, 0.9);
  paint-order: stroke fill;
  white-space: nowrap;
  animation: float-up 1.1s ease-out forwards;
}
.float-text.big { font-size: 28px; color: #ffe66b; }
.float-text.combo { font-size: 30px; color: #ff9d2e; animation-duration: 1.4s; }
.float-text.streak { font-size: 20px; color: #9be15d; }
.float-text.power { font-size: 30px; color: #6be3ff; animation-duration: 1.5s; }
@keyframes float-up {
  0% { transform: translate(-50%, -30%) scale(0.6); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -160%) scale(1); opacity: 0; }
}

/* ----------------------------------------------- transición de nivel */
#level-banner {
  position: fixed; inset: 0;
  z-index: 6;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
  color: #fff;
  text-align: center;
  -webkit-text-stroke: 2px rgba(40, 25, 10, 0.9);
  paint-order: stroke fill;
}
#level-banner.anim { animation: banner 2.6s ease-in-out forwards; }
.banner-n { font-size: clamp(36px, 9vw, 64px); font-weight: 900; letter-spacing: 2px; }
.banner-name { font-size: clamp(20px, 5vw, 32px); font-weight: 900; color: #ffd76b; }
@keyframes banner {
  0% { opacity: 0; transform: scale(1.4); }
  15%, 75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.9); }
}

#loading {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: #23301a; color: #f7efdf; font-weight: 800; font-size: 20px;
}

/* ------------------------------------------------------------ móvil */
@media (max-width: 600px) {
  #hud { padding-left: 10px; padding-right: 10px; gap: 4px; }
  #hud-score { font-size: 24px; }
  .hud-block .label { font-size: 13px; }
  .hud-block .label b { font-size: 16px; }
  .hud-block .sub { font-size: 10px; }
  .icon-btn { width: 36px; height: 36px; font-size: 14px; border-radius: 10px; }
  .bar .track { width: 24vw; }
  .bar { font-size: 9px; }
  .panel h1 { font-size: 26px; }
  .how { font-size: 13px; }
}
#hud-lives { display: flex; gap: 2px; color: #ffe2b8; filter: drop-shadow(0 2px 0 rgba(0,0,0,0.45)); }
#hud-lives svg { width: 20px; height: 20px; display: block; }
.icon-btn svg { display: block; margin: auto; }

/* ------------------------------------------------- niveles y clasificación */
.panel.wide { width: min(560px, 100%); }
.world-tabs { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.world-tabs button { border: none; border-radius: 10px; padding: 7px 12px; font: inherit; font-weight: 800; cursor: pointer; background: var(--paper-2); color: var(--ink); }
.world-tabs button.sel { background: var(--accent); color: #fff; }
#levels-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-height: 52vh; overflow-y: auto; padding: 2px; }
.lvl { border: none; border-radius: 12px; padding: 10px 4px; font: inherit; font-weight: 900; font-size: 18px; background: #fff; color: var(--ink);
  box-shadow: 0 3px 0 #c7b38f; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.lvl small { font-size: 10px; font-weight: 700; opacity: 0.7; line-height: 1.1; }
.lvl:disabled { opacity: 0.4; cursor: not-allowed; }
.lvl.done { background: #d9f0c6; }
.boards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; }
.boards h3 { margin: 0 0 6px; font-size: 15px; }
.boards ol { margin: 0; padding-left: 22px; font-weight: 700; font-size: 14px; line-height: 1.6; }
@media (max-width: 520px) { .boards { grid-template-columns: 1fr; } #levels-grid { grid-template-columns: repeat(3, 1fr); } }
.duel-tip { font-size: 13px; opacity: 0.8; margin-top: 12px !important; }

/* ------------------------------------------------------------ duelo */
#opp {
  grid-column: 1 / -1; justify-self: end;
  background: rgba(20, 14, 8, 0.55); border-radius: 12px; padding: 6px 10px; display: flex; flex-direction: column; gap: 3px;
  border: 2px solid rgba(255, 120, 60, 0.7);
}
.opp-head { font-size: 13px; font-weight: 800; display: flex; gap: 6px; align-items: center; }
#opp-score { margin-left: auto; font-variant-numeric: tabular-nums; }
#opp .track { width: 110px; height: 7px; }
.vs-count { font-size: 72px; font-weight: 900; color: var(--accent-dark); line-height: 1; margin: 6px 0; }
#vs-scores { font-weight: 800; }
#vs-scores div { display: flex; justify-content: space-between; background: var(--paper-2); border-radius: 10px; padding: 6px 12px; margin: 4px 0; }
