:root {
  --bg1: #0b1f33;
  --bg2: #1d4268;
  --ink: #eaf6ff;
  --muted: #9fc3dd;
  --panel: rgba(9, 27, 45, 0.92);
  --ok: #4cd98a;
  --bad: #ff6b7a;
  --warn: #ffd24a;
  --accent: #38bdf8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 38%, var(--bg2), var(--bg1) 70%);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
}

#app {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

#app button, #app img { pointer-events: auto; }

/* Barra superior */
#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  padding: 10px 14px 18px;
  background: linear-gradient(rgba(5, 16, 28, 0.9), rgba(5, 16, 28, 0));
}

.brand { min-width: 0; }
.badge { display: block; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
#level-title { margin: 0; font-size: 20px; font-weight: 800; }
.stats { display: flex; gap: 18px; }
.stat { display: flex; flex-direction: column; min-width: 56px; }
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .value.warn { color: var(--bad); animation: pulse 0.8s ease-in-out infinite; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(9, 27, 45, 0.8);
  color: var(--ink);
  font: 600 14px system-ui, sans-serif;
  cursor: pointer;
}

.chip:disabled { opacity: 0.4; cursor: default; }

/* Panel de la misión */
#goal {
  position: absolute;
  top: 88px;
  left: 12px;
  width: 232px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  pointer-events: auto;
}

.goal-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.formula { font-size: 36px; font-weight: 800; line-height: 1.1; }
.mission { margin: 6px 0 10px; font-size: 14px; color: var(--muted); line-height: 1.35; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.row { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.row .txt { flex: 1; color: var(--muted); }
.row .need { font-weight: 700; }
.row.ok .txt { color: var(--ok); }
.row.extra .txt { color: var(--bad); }

.sym {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--c, #888);
  color: var(--fg, #111);
  font-weight: 800;
  font-size: 14px;
}

/* Zona inferior: mascota, paleta y acciones */
#bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 10px 14px;
  padding: 26px 12px 12px;
  background: linear-gradient(rgba(5, 16, 28, 0), rgba(5, 16, 28, 0.85));
  pointer-events: none;
}

#bottom > * { pointer-events: auto; }

#feed { display: flex; align-items: center; gap: 10px; flex: 0 1 380px; min-width: 0; }
#mascot {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  object-fit: cover;
}

#toast {
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--panel);
  border-left: 4px solid var(--accent);
  font-size: 15px;
  line-height: 1.35;
  min-height: 44px;
}

#toast[data-tone="ok"] { border-left-color: var(--ok); }
#toast[data-tone="error"] { border-left-color: var(--bad); }
#toast.bump { animation: bump 0.35s ease-out; }

#palette {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  max-width: 100%;
  padding: 4px;
  scrollbar-width: none;
}

.el-btn {
  flex-shrink: 0;
  width: 88px;
  min-height: 92px;
  padding: 8px 4px;
  border-radius: 16px;
  border: 2px solid var(--c);
  background: rgba(9, 27, 45, 0.92);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font: inherit;
}

.el-btn:active { transform: scale(0.96); }
.el-btn .sym { width: 40px; height: 40px; font-size: 20px; }
.el-btn .nm { font-size: 12px; color: var(--muted); }
.el-btn .val { font-size: 11px; color: var(--muted); opacity: 0.8; }
.el-btn .cnt { font-size: 13px; font-weight: 800; color: var(--warn); min-height: 16px; }

#actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.foot { margin: 0; flex-basis: 100%; text-align: center; font-size: 12px; color: var(--muted); }

.btn {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--accent);
  color: #04121f;
  font: 700 16px system-ui, sans-serif;
  cursor: pointer;
}

.btn.ghost { background: transparent; color: var(--ink); border-color: rgba(255, 255, 255, 0.35); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .chip:focus-visible, .el-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* Papelera (aparece al arrastrar un átomo) */
#trash {
  position: fixed;
  right: 14px;
  top: 40%;
  width: 116px;
  height: 116px;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  border: 3px dashed rgba(255, 107, 122, 0.85);
  border-radius: 20px;
  background: rgba(60, 10, 20, 0.5);
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
}

#trash.show { display: flex; }
#trash.active { background: rgba(255, 80, 100, 0.5); transform: scale(1.06); }

/* Tarjetas emergentes */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 12, 22, 0.72);
  backdrop-filter: blur(2px);
}

.card {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow: auto;
  padding: 24px;
  border-radius: 20px;
  background: #0f2740;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  animation: pop-in 0.3s ease-out;
}

.card.wide { max-width: 680px; }
.card h2 { margin: 0 0 12px; font-size: 26px; }
.card h3 { margin: 16px 0 6px; font-size: 16px; color: var(--muted); }
.card p { margin: 8px 0; line-height: 1.45; }
.lead { font-size: 17px; }
.muted { color: var(--muted); font-size: 14px; }
.formula-big { font-size: 44px; font-weight: 800; margin: 4px 0; }
.score-line { font-weight: 700; }
.stars-line { font-size: 34px; color: var(--warn); letter-spacing: 4px; }
.fact { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); line-height: 1.45; }
.steps { padding-left: 20px; line-height: 1.6; }
.collection { padding-left: 20px; margin: 0; line-height: 1.6; }
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* Móvil vertical (390 px) */
@media (max-width: 720px) {
  #topbar { padding: 8px 10px 14px; }
  #level-title { font-size: 16px; }
  .stat .value { font-size: 18px; }
  .stats { gap: 12px; }
  #goal {
    top: 96px;
    left: 8px;
    right: 8px;
    width: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    padding: 8px 12px;
  }
  .goal-label { display: none; }
  .formula { font-size: 24px; }
  .mission { display: none; }
  .rows { display: flex; flex-wrap: wrap; gap: 4px 10px; }
  .row { font-size: 13px; }
  .el-btn { width: 74px; min-height: 80px; }
  .el-btn .val { display: none; }
  #feed { flex-basis: 100%; }
  #mascot { width: 52px; height: 52px; }
  #toast { font-size: 14px; }
}

@media (min-width: 1600px) {
  #level-title { font-size: 26px; }
  .stat .value { font-size: 30px; }
  .formula { font-size: 46px; }
  .row { font-size: 18px; }
  .el-btn { width: 104px; min-height: 110px; }
  .el-btn .sym { width: 50px; height: 50px; font-size: 25px; }
  #toast { font-size: 18px; }
  #feed { flex-basis: 460px; }
}

@keyframes pulse { 50% { opacity: 0.5; } }
@keyframes bump { 0% { transform: scale(0.97); } 60% { transform: scale(1.02); } 100% { transform: scale(1); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
