:root {
  /* Carcasa: turquesa de fábrica; cada persona la cambia en Estado → Color del aparato (ui/theme.js). */
  --shell: #4fd1c5;
  --shell-dark: #2a9d92;
  --shell-light: #b6f2ec;
  --bezel: #2b2b3a;
  --lcd: #dfe8c8;
  --lcd-ink: #2b2b3a;
  --bg: #2a2140;
  --bg-2: #3b2f5c;
  --text: #2b2b3a;
  --radius: 28px;
}

@media (prefers-color-scheme: light) {
  :root { --bg: #f6e9ff; --bg-2: #ffe3ef; }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* la columna nunca es más ancha que la pantalla */
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at 30% 20%, var(--bg-2), var(--bg));
  font: 15px/1.4 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
}

/* El aparato ocupa toda la pantalla disponible (celu) o una columna alta (compu). */
.device {
  width: min(100%, 620px);
  height: 100%;
  max-height: 1000px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--shell-light), var(--shell) 40%, var(--shell-dark));
  box-shadow: inset -6px -8px 0 rgba(0, 0, 0, .1), 0 18px 40px rgba(0, 0, 0, .35);
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.brand {
  margin: 0 4px;
  font-weight: 800;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 2px 0 var(--shell-dark);
}

.account-chip {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .85);
  font: inherit;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.account-chip.guest { background: #fff; font-weight: 700; }

/* Pantalla LCD */
.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 10px;
  border-radius: 18px;
  background: var(--bezel);
}

.lcd-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  overflow: hidden;
  background: var(--lcd);
  /* retícula sutil de LCD */
  background-image: linear-gradient(rgba(0, 0, 0, .04) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, .04) 1px, transparent 1px);
  background-size: 4px 4px;
}

#lcd {
  display: block;
  cursor: pointer; /* se puede tocar: la mascota reacciona y los símbolos se explican */
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.call {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 22px;
  font-weight: 900;
  color: #d33;
  opacity: 0;
}
.call.on { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 1; } }

/* Panel: menús y pantallas de información encima de la mascota */
.panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 16px;
  background: rgba(223, 232, 200, .97);
  color: var(--lcd-ink);
}
.panel p { margin: 0 0 8px; }
.panel .title { font-weight: 800; font-size: 17px; }
.panel .hint { opacity: .65; font-size: 13px; }
.panel .big { font-size: 34px; font-weight: 900; margin: 4px 0 8px; }
.panel .tier { font-weight: 900; }
.panel .warn { color: #b3261e; font-weight: 700; }
.panel .stats { font-size: 13px; }
.panel small { font-size: 12px; opacity: .85; }
.panel-center { text-align: center; display: grid; align-content: center; min-height: 100%; }
.panel-list { display: grid; gap: 8px; align-content: start; }
.reveal .tier { color: var(--tier); text-shadow: 0 0 8px var(--tier); }

/* Pelea: el texto va debajo de la escena, sin taparla */
.panel.strip {
  position: static;
  flex: none;
  padding: 10px 14px;
  background: rgba(43, 43, 58, .08);
  text-align: center;
}

/* Botones táctiles (mínimo 44 px de alto) */
.option, .action {
  min-height: 44px;
  padding: 10px 14px;
  border: 2px solid var(--lcd-ink);
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.option:active, .action:active { transform: scale(.98); }
.option.selected { background: var(--lcd-ink); color: var(--lcd); }
.option.small { min-width: 44px; padding: 6px 8px; text-align: center; }
.option.google { background: #fff; font-weight: 700; text-align: center; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.action { flex: 1 1 140px; text-align: center; font-weight: 700; }
.action.primary { background: var(--lcd-ink); color: var(--lcd); }
.panel.strip .actions { margin-top: 6px; }
.actions.hands { flex-wrap: nowrap; }
.actions.hands .action { flex: 1 1 0; min-width: 0; font-size: 26px; padding: 6px; }

.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.item-row { margin: 0; flex-wrap: nowrap; justify-content: stretch; }
.item-row .option:first-child { flex: 1; }

.bar { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; margin-bottom: 4px; }
/* Barras retro: marco grueso, sin bordes redondeados y relleno en bloques */
.bar meter {
  width: 100%; height: 14px; -webkit-appearance: none; appearance: none;
  border: 2px solid var(--lcd-ink); border-radius: 0; background: #f4f4f4; padding: 1px;
}
.bar meter::-webkit-meter-bar { background: transparent; border: 0; border-radius: 0; height: 8px; }
.bar meter::-webkit-meter-optimum-value, .bar meter::-moz-meter-bar {
  background: repeating-linear-gradient(90deg, #38b764 0 6px, transparent 6px 8px);
}
.bar meter::-webkit-meter-suboptimum-value { background: repeating-linear-gradient(90deg, #ef7d57 0 6px, transparent 6px 8px); }
.bar meter::-webkit-meter-even-less-good-value { background: repeating-linear-gradient(90deg, #b13e53 0 6px, transparent 6px 8px); }
.bar meter:-moz-meter-sub-optimum::-moz-meter-bar { background: repeating-linear-gradient(90deg, #ef7d57 0 6px, transparent 6px 8px); }
.bar meter:-moz-meter-sub-sub-optimum::-moz-meter-bar { background: repeating-linear-gradient(90deg, #b13e53 0 6px, transparent 6px 8px); }
.genes { margin: 6px 0; padding-left: 18px; font-size: 13px; }
.genes li { margin-bottom: 2px; }
.gene-list summary { cursor: pointer; font-weight: 700; min-height: 32px; display: flex; align-items: center; }
.panel .combat { margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(43, 43, 58, .3); }

.panel .account { margin-top: 12px; padding: 10px; border: 1px dashed rgba(43, 43, 58, .4); border-radius: 12px; text-align: center; }
.panel .account p { font-size: 13px; }



/* Íconos: toda la botonera, táctil y con nombre */
.icons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 60px;
  padding: 6px 2px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, .55);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.icon:active { transform: scale(.96); background: #fff; }
.icon.selected { background: #fff; box-shadow: 0 0 0 2px var(--lcd-ink); }
.icon.disabled { opacity: .4; }
.icon:focus-visible { outline: 3px solid var(--lcd-ink); }
.icon-emoji { font-size: 24px; line-height: 1.1; }
/* Íconos pixel art (reemplazan a los emojis del sistema): se escalan sin suavizar */
img.px { width: 1.15em; height: 1.15em; vertical-align: -0.2em; image-rendering: pixelated; image-rendering: crisp-edges; }
.icon-emoji img.px { width: 28px; height: 28px; vertical-align: middle; }
.icon-label { font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .25);
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  z-index: 2;
}
.toast.visible { opacity: 1; }

@media (min-width: 700px) {
  body { font-size: 16px; }
  .icon-emoji { font-size: 28px; }
  .icon-label { font-size: 12px; }
}

/* Golpes en la pelea: el número salta sobre quien lo recibe */
.floats { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.float {
  position: absolute; top: 30%; transform: translateX(-50%); font-weight: 900; font-size: 24px;
  color: #ff4d4d; -webkit-text-stroke: 1px #2b2b3a;
  text-shadow: 0 3px 0 #2b2b3a, 3px 0 0 #2b2b3a, -3px 0 0 #2b2b3a, 0 -3px 0 #2b2b3a, 2px 2px 0 #2b2b3a, -2px -2px 0 #2b2b3a, 2px -2px 0 #2b2b3a, -2px 2px 0 #2b2b3a;
  animation: float-up .9s ease-out forwards; white-space: nowrap;
}
.float.left { left: 27%; }
.float.right { left: 73%; }
.float.crit { color: #ffd84d; font-size: 26px; }
.float.miss { color: #9cd3ff; font-size: 18px; }
.float.heal { color: #a7f070; }
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(.8); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.2); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -32px) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .call.on { animation: none; opacity: 1; }
  .float { animation: none; transform: translateX(-50%); }
  .defense .claim { animation: none; }
}

/* Selector de color del aparato */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 6px 0; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid rgba(43, 43, 58, .25); cursor: pointer; }
.swatch.selected { border-color: var(--lcd-ink); box-shadow: 0 0 0 2px var(--lcd); }
.panel .legal { margin-top: 10px; font-size: 12px; opacity: .8; text-align: center; }
.panel .legal a { color: inherit; }
.option.danger { border-color: #b3261e; color: #b3261e; }
.linklike { border: 0; background: none; padding: 4px; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }

/* Ayuda */
.topbar-actions { display: flex; flex: 1; justify-content: flex-end; gap: 8px; align-items: center; min-width: 0; }
.topbar .brand { flex: none; }
.help-chip { width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .85); font-size: 16px; cursor: pointer; }
.guide { display: grid; gap: 6px; }
.guide-section { border: 2px solid var(--lcd-ink); border-radius: 12px; padding: 0 12px; }
.guide-section[open] { background: rgba(255, 255, 255, .35); }
.guide-section summary { min-height: 44px; display: flex; align-items: center; font-weight: 800; cursor: pointer; list-style: none; }
.guide-section summary::-webkit-details-marker { display: none; }
.guide-section summary::after { content: '＋'; margin-left: auto; }
.guide-section[open] summary::after { content: '－'; }
.guide-section ul { margin: 0 0 10px; padding-left: 18px; }
.guide-section li, .guide-section p { font-size: 14px; }
.panel .tip { font-size: 13px; background: rgba(255, 255, 255, .45); border-radius: 10px; padding: 8px 10px; }
.bar small { opacity: .7; font-size: 11px; }
.adv.good { color: #2e7d32; font-weight: 700; }
.adv.bad { color: #b3261e; font-weight: 700; }

/* Anuncio de prueba */
.ad-overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-content: center; gap: 16px; padding: 24px; background: rgba(15, 18, 28, .92); color: #fff; text-align: center; white-space: pre-line; font-size: 18px; }
.ad-overlay .action { color: #fff; border-color: #fff; }
.action.ad { border-style: dashed; }

/* Acceso directo a la mascota elegida desde cualquier pantalla. */
.pet-chip {
  position: absolute; top: 10px; left: 10px; z-index: 3; max-width: 60%;
  min-height: 36px; padding: 0 12px; border: 2px solid var(--lcd-ink); border-radius: 999px;
  background: rgba(255, 255, 255, .9); color: var(--lcd-ink); font: inherit; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.pet-chip[hidden] { display: none; }
.panel.with-chip { padding-top: 58px; }

/* Cuenta regresiva del huevo */
.countdown {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 2; margin: 0;
  padding: 6px 14px; border: 2px solid var(--lcd-ink); background: rgba(244, 244, 244, .92);
  color: var(--lcd-ink); font-weight: 900; font-size: 18px; white-space: nowrap; pointer-events: none;
}
.countdown[hidden] { display: none; }

/* ---- Ranking y defensas: tarjetas retro ---- */
.card { border: 2px solid var(--lcd-ink); border-radius: 6px; background: rgba(244, 244, 244, .7); box-shadow: 3px 3px 0 rgba(43, 43, 58, .35); }
.thumb { position: relative; display: inline-grid; place-items: center; flex: none; border: 2px solid var(--tier); border-radius: 6px; background: rgba(255, 255, 255, .6); }
.thumb img { width: 85%; height: 85%; object-fit: contain; image-rendering: pixelated; }
.thumb-role { position: absolute; right: -6px; bottom: -6px; line-height: 0; }
.thumb-role img.px { width: 16px; height: 16px; }
.me-card { display: flex; gap: 12px; align-items: center; padding: 10px; border-left: 8px solid var(--tier); }
.me-card p { margin: 0 0 2px; }
.me-card .hot { color: #b13e53; font-weight: 800; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; min-height: 44px; border: 2px solid var(--lcd-ink); border-radius: 6px; background: transparent; color: var(--lcd-ink); font: inherit; font-weight: 800; cursor: pointer; }
.tab.on { background: var(--lcd-ink); color: var(--lcd); }
.tab .badge { display: inline-block; min-width: 20px; margin-left: 6px; padding: 0 5px; border-radius: 10px; background: #b13e53; color: #fff; font-size: 12px; }
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 6px; margin: 4px 0 10px; }
.step { display: grid; justify-items: center; gap: 3px; padding: 8px 4px; border: 2px solid var(--lcd-ink); border-top: 6px solid var(--tier); border-radius: 6px 6px 0 0; background: rgba(244, 244, 244, .7); text-align: center; min-width: 0; }
.step b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-1 { padding-top: 14px; background: #ffcd75; }
.step-2 { background: #d5dde6; }
.step-3 { background: #f2c3a8; }
.step.mine { outline: 3px solid #b13e53; }
.medal img.px { width: 26px; height: 26px; }
.board, .defense-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rank-row { display: grid; grid-template-columns: 38px 36px 1fr auto auto; gap: 8px; align-items: center; padding: 6px 8px; border-left: 6px solid var(--tier); }
.rank-row .pos { font-weight: 900; }
.rank-row .who, .defense .who { display: grid; min-width: 0; }
.rank-row .who b, .defense .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .tier { color: var(--tier); font-weight: 700; filter: brightness(.75); }
.rank-row .pts { font-weight: 900; }
.rank-row.mine { background: var(--lcd-ink); color: var(--lcd); }
.rank-row.mine .tier { filter: none; }
.summary { padding: 8px 10px; margin-bottom: 8px; }
.summary p { margin: 0 0 6px; }
.winbar { height: 10px; border: 2px solid var(--lcd-ink); background: #b13e53; }
.winbar i { display: block; height: 100%; background: #38b764; }
.defense { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 8px; border-left: 6px solid; }
.defense.won { border-left-color: #38b764; }
.defense.lost { border-left-color: #b13e53; }
.defense .result img.px { width: 24px; height: 24px; }
.defense .chip { padding: 2px 8px; border-radius: 10px; font-weight: 800; font-size: 12px; color: #fff; }
.defense.won .chip { background: #38b764; }
.defense.lost .chip { background: #b13e53; }
.icon.news { position: relative; }
.icon.news::after { content: ''; position: absolute; top: 6px; right: 8px; width: 10px; height: 10px; border: 2px solid var(--lcd-ink); background: #b13e53; }
.defense .claim { min-height: 36px; padding: 0 10px; border: 2px solid var(--lcd-ink); border-radius: 6px; background: #ffcd75; color: var(--lcd-ink); font: inherit; font-weight: 900; cursor: pointer; animation: need-pulse 1.2s steps(2) infinite; }
@keyframes need-pulse { 50% { background: #ef7d57; } }
.set-box { margin: 6px 0; padding: 6px 8px; border: 2px dashed var(--lcd-ink); border-radius: 6px; font-size: 13px; }
.set-box.done { border-style: solid; background: #a7f070; font-weight: 800; }
.set-tag { color: #5d275d; font-weight: 800; }
