: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 {
  max-width: 70%;
  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;
  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; }

.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; }
.bar meter { width: 100%; height: 12px; }
.genes { margin: 6px 0; padding-left: 18px; columns: 2; font-size: 13px; }
.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; }

.ranking ol { list-style: none; margin: 0; padding: 0; }
.ranking li { display: grid; grid-template-columns: 48px 1fr 56px 56px; gap: 6px; padding: 6px 8px; font-size: 14px; }
.ranking li.mine { background: var(--lcd-ink); color: var(--lcd); border-radius: 8px; }
.ranking .me { font-weight: 700; }

/* Í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; }
.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; }
}

@media (prefers-reduced-motion: reduce) {
  .call.on { animation: none; opacity: 1; }
}

/* 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; }
.account-chip { min-width: 0; max-width: 100%; }
.adv.good { color: #2e7d32; font-weight: 700; }
.adv.bad { color: #b3261e; font-weight: 700; }
