:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fff;
  --ink: #181a18;
  --muted: #777b75;
  --line: #e5e6e1;
  --accent: #284f40;
  --accent-hover: #1e3d31;
  --font-sans: system-ui, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  background: linear-gradient(160deg, hsl(var(--hue, 150) 70% 96%), hsl(calc(var(--hue, 150) + 60) 70% 94%)) fixed;
  transition: background-color .6s;
  color: var(--ink);
  font-family: var(--font-sans);
  display: grid;
  place-items: center;
  padding: 10px 18px;
}
button, input { font: inherit; }
button, .upload-btn { cursor: pointer; }
/* El campo ocupa todo lo que permita la ventana: hasta 1480 px de ancho, limitado por el alto
   (la parte fija de la página mide unos 145 px) para que se vea entero sin hacer scroll. */
.app-shell {
  width: min(100%, 1480px, max(640px, calc((100vh - 150px) * var(--ratio, 1.6))));
  width: min(100%, 1480px, max(640px, calc((100dvh - 150px) * var(--ratio, 1.6))));
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 10px; }
.brand { white-space: nowrap; display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 19px; font-weight: 700; letter-spacing: -.06em; }
.brand-mark { width: 18px; height: 18px; border: 2px solid var(--accent); border-radius: 5px; transform: rotate(-8deg); position: relative; }
.brand-mark::after { content: ''; position: absolute; width: 7px; height: 3px; border-radius: 4px; background: var(--accent); bottom: -5px; left: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
button, .upload-btn { min-height: 38px; padding: 0 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 600; transition: background .15s, border-color .15s, transform .15s; }
button:hover, .upload-btn:hover { border-color: #b7c1ba; transform: translateY(-1px); }
.primary-btn { background: var(--accent); border-color: var(--accent); color: white; }
.primary-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.upload-btn { position: relative; display: inline-flex; align-items: center; }
.upload-btn input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.mobile-label { display: none; }
.game-heading { display: flex; align-items: end; gap: 32px; padding: 0 2px 8px; }
.stat { display: flex; flex-direction: column; gap: 3px; min-width: 52px; }
.stat-label { color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.stat strong { font-family: var(--font-mono); font-size: 17px; font-weight: 500; }
.status { margin: 0 0 2px auto; color: var(--muted); font-size: 12px; text-align: right; }
.game-panel { overflow: hidden; border: 1px solid #e1e3dc; border-radius: 10px; background: #fbfcfa; box-shadow: 0 8px 30px rgb(26 39 28 / 5%); }
canvas { display: block; width: 100%; height: auto; touch-action: none; }
.credit { margin: 0; }
.credit a { color: inherit; font-weight: 700; }
.game-footer { display: flex; flex-wrap: wrap; align-items: start; justify-content: space-between; gap: 12px 24px; padding: 8px 2px; color: var(--muted); font-size: 11px; }
.controls-hint { margin: 0; }
.mode-link { color: var(--accent); font-weight: 600; text-decoration: none; }
.mode-link:hover { text-decoration: underline; }
kbd { display: inline-block; min-width: 20px; padding: 1px 5px; border: 1px solid #dfe1da; border-radius: 4px; background: white; color: #555950; font: 10px var(--font-mono); text-align: center; }
.power-guide { max-width: 520px; }
.power-guide summary { cursor: pointer; color: var(--accent); font-weight: 600; text-align: right; }
.power-count { margin-left: 4px; color: var(--muted); font-weight: 500; font-family: var(--font-mono); }
.power-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 7px; }
.power-list li { display: flex; align-items: flex-start; gap: 9px; line-height: 1.45; }
.power-list li.unseen { opacity: .6; }
.power-list li.found strong { color: var(--ink); }
.power-list li.unseen .power-dot { filter: grayscale(1); }
.power-dot { flex: none; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; }
.power-dot svg { width: 14px; height: 14px; }

/* Aviso de power-up nuevo (dentro del campo, también en pantalla completa). */
.game-panel { position: relative; }
.power-popup { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 16px; background: rgb(251 252 250 / 76%); backdrop-filter: blur(3px); animation: popup-in .18s ease-out; }
.power-popup[hidden] { display: none; }
.power-card { width: min(100%, 340px); padding: 22px 22px 20px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 18px 50px rgb(26 39 28 / 16%); }
.power-kicker { margin: 0 0 12px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.power-badge { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%; box-shadow: 0 6px 16px rgb(0 0 0 / 14%); }
.power-badge svg { width: 34px; height: 34px; }
.power-card h2 { margin: 0 0 6px; font-size: 21px; letter-spacing: -.03em; }
.power-desc { margin: 0 0 12px; color: #3b423d; font-size: 14px; line-height: 1.5; }
.power-meta { margin: 0 0 14px; color: var(--muted); font-size: 11px; }
.power-card button { width: 100%; }
@keyframes popup-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }
/* En pantallas chicas el campo es más bajo que la tarjeta: se ancla a la ventana, no al campo. */
@media (max-width: 600px), (max-height: 520px) {
  .power-popup { position: fixed; }
  .power-card { max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; }
  .picker-card { max-height: calc(100dvh - 32px); }
}
@media (max-height: 520px) {
  .power-card { padding: 14px 18px; }
  .power-badge { display: none; }
  .power-meta { margin-bottom: 10px; }
}

/* Atajos del modo limpio (?clean / ?tiktok): invisibles hasta que se mueve el mouse o se toca la pantalla,
   y se vuelven a ocultar solos para no salir en las grabaciones. */
.clean-tools { display: none; }
body.clean .clean-tools { display: flex; position: absolute; top: 10px; right: 10px; z-index: 4; gap: 6px; opacity: 0; pointer-events: none; transition: opacity .25s; }
body.clean .clean-tools.show { opacity: 1; pointer-events: auto; }
.clean-tools button, .tool-link { display: inline-flex; align-items: center; min-height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: rgb(255 255 255 / 92%); color: var(--ink); font-size: 12px; font-weight: 600; text-decoration: none; box-shadow: 0 2px 10px rgb(0 0 0 / 10%); }
.tool-link:hover { border-color: #b7c1ba; }

/* Selector de bloques al importar imagen: reutiliza la tarjeta del aviso, pero deja ver el campo. */
.picker { background: rgb(251 252 250 / 55%); }
.picker-card { width: min(100%, 400px); max-height: 100%; overflow-y: auto; }
.picker-preview { width: 100%; height: auto; margin: 0 0 12px; border: 1px solid var(--line); border-radius: 8px; background: #f2f3ef; }
.picker-readout { margin: 0 0 8px; font-size: 14px; }
.picker-readout span { color: var(--muted); font-size: 12px; }
.picker-range { width: 100%; margin: 0; accent-color: var(--accent); }
.picker-scale { display: flex; justify-content: space-between; margin: 2px 0 14px; color: var(--muted); font-size: 11px; }
.picker-actions { display: flex; gap: 8px; }
.power-card .picker-actions button { width: auto; flex: 1; }
.picker-actions button:disabled { opacity: .5; cursor: default; }

/* Formato vertical (?portrait) con interfaz: canvas angosto y centrado. */
body.portrait:not(.clean) .app-shell { width: min(100%, 1000px); }
body.portrait:not(.clean) .game-panel {
  width: min(100%, calc((100vh - 150px) * var(--ratio, .5625)));
  width: min(100%, calc((100dvh - 150px) * var(--ratio, .5625)));
  margin-inline: auto;
}

/* Modo limpio (?clean / ?tiktok): solo el canvas, ajustado a la pantalla, para grabar. */
body.clean { padding: 0; min-height: 100vh; min-height: 100dvh; }
body.clean .app-shell { width: auto; }
body.clean .topbar,
body.clean .game-heading,
body.clean .game-footer { display: none; }
body.clean .game-panel {
  width: min(100vw, calc(100vh * var(--ratio, 1.6)));
  width: min(100vw, calc(100dvh * var(--ratio, 1.6)));
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
body.clean canvas { cursor: none; }

/* Pantalla completa: nativa (:fullscreen) o, donde el navegador no la permite (iPhone), .pseudo-fs.
   Van con !important para ganar a las reglas de ?clean y ?portrait. */
.game-panel:fullscreen,
.game-panel:-webkit-full-screen,
.game-panel.pseudo-fs {
  display: grid !important;
  place-items: center;
  width: 100vw !important;
  width: 100dvw !important;
  height: 100vh !important;
  height: 100dvh !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: #fbfcfa;
}
.game-panel.pseudo-fs { position: fixed; inset: 0; z-index: 100; }
.game-panel:fullscreen canvas,
.game-panel:-webkit-full-screen canvas,
.game-panel.pseudo-fs canvas {
  width: min(100vw, calc(100vh * var(--ratio, 1.6)));
  width: min(100dvw, calc(100dvh * var(--ratio, 1.6)));
  height: auto;
  cursor: none;
}
html.fs-lock, html.fs-lock body { overflow: hidden; }

@media (max-width: 600px) {
  body { padding: 18px 12px; }
  .topbar { margin-bottom: 20px; flex-wrap: wrap; row-gap: 10px; }
  .topbar-actions { gap: 6px; }
  button, .upload-btn { min-height: 38px; padding: 0 10px; font-size: 12px; }
  .desktop-label { display: none; }
  .mobile-label { display: inline; }
  .game-heading { gap: 18px; }
  .status { font-size: 11px; }
  .game-footer { flex-direction: column; }
  .power-guide { width: 100%; }
  .power-guide summary { text-align: left; }
  body.clean { padding: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; } }
