/* Layout: una columna centrada tipo consola de arcade; pantallas que se intercambian.
   Estética: monitor de fósforo ámbar sobre tinta ciruela, con acentos cian para direcciones de memoria.
   Diseño de un solo tema oscuro, elegido a propósito. */
:root {
  color-scheme: dark;
  --ink: #17121c;
  --panel: #221a29;
  --panel-2: #2c2235;
  --line: #3d3149;
  --fg: #f3e9dc;
  --muted: #a99bb1;
  --amber: #ffb547;
  --amber-deep: #c97d14;
  --cyan: #63d4e6;
  --good: #7ee08a;
  --bad: #ff6b6b;
  --font-display: "Bungee", "Impact", "Arial Black", sans-serif;
  --font-body: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 10px;
}

[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(255, 181, 71, 0.10), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 3px);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding-block: 20px 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.screen { display: flex; flex-direction: column; gap: 18px; }

h1, h2, h3 { margin: 0; text-wrap: balance; line-height: 1.15; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
  font-weight: 600;
}
.muted { color: var(--muted); }
.fineprint { font-size: 0.78rem; color: var(--muted); }
.error { color: var(--bad); font-size: 0.9rem; }

/* ---------- Marca ---------- */
.brand { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; }
.logo {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.6rem, 12vw, 4rem);
  line-height: 0.95;
  color: var(--amber);
  text-shadow: 0 0 18px rgba(255, 181, 71, 0.35), 3px 3px 0 var(--amber-deep);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.25em;
}
.logo b { color: var(--cyan); text-shadow: 0 0 18px rgba(99, 212, 230, 0.4); font-weight: 400; }
.tagline { color: var(--cyan); max-width: 40ch; font-weight: 600; }

/* ---------- Paneles y formularios ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.stack-form { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
label { font-size: 0.9rem; font-weight: 600; }

input[type="text"], input[type="password"], input[type="email"], select, textarea {
  background: var(--ink);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  min-width: 0;
}
input[type="file"] { color: var(--muted); font: inherit; font-size: 0.85rem; max-width: 100%; }
textarea { font-family: var(--font-code); font-size: 0.78rem; resize: vertical; width: 100%; box-sizing: border-box; word-break: break-all; }
#pin-input { width: 7ch; letter-spacing: 0.3em; }
input:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--fg);
  background: transparent;
  transition: transform 0.08s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--amber); color: var(--ink); box-shadow: 0 3px 0 var(--amber-deep); }
.btn.primary:hover { background: #ffc469; }
.btn.secondary { border-color: var(--cyan); color: var(--cyan); }
.btn.secondary:hover { background: rgba(99, 212, 230, 0.1); }
.btn.ghost { border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { color: var(--fg); border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
kbd {
  font-family: var(--font-code);
  font-size: 0.7em;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid currentColor;
  opacity: 0.7;
  margin-left: 6px;
}

summary { list-style: none; display: inline-block; }
summary::-webkit-details-marker { display: none; }
.new-profile { border-top: 1px dashed var(--line); padding-top: 14px; }

.profile-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.profile-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.profile-btn:hover { border-color: var(--amber); }
.avatar {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  font-family: var(--font-display);
  background: var(--ink);
  color: var(--amber);
  border: 1px solid var(--amber-deep);
  border-radius: 6px;
}
.profile-meta { display: flex; flex-direction: column; min-width: 0; }
.profile-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-meta span { font-size: 0.8rem; color: var(--muted); font-family: var(--font-code); }
.lock { margin-left: auto; font-size: 0.75rem; color: var(--muted); font-family: var(--font-code); }

/* ---------- Mapa ---------- */
.hub-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 14px; }
.hub-name { font-family: var(--font-display); font-weight: 400; color: var(--amber); font-size: 1.8rem; }
.hub-stats { display: flex; gap: 18px; }
.hub-stats > div, .hud-item, .res-grid > div { display: flex; flex-direction: column; }
.stat-label { font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stat-val { font-family: var(--font-code); font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.level-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.level-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 14px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.level-card:hover:not(:disabled) { border-color: var(--amber); background: var(--panel-2); }
.level-card:disabled { cursor: not-allowed; opacity: 0.55; }
.level-card.boss { border-color: var(--bad); }
.level-addr {
  grid-row: span 2;
  font-family: var(--font-code);
  font-size: 0.75rem;
  color: var(--cyan);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.06em;
}
.level-title { font-weight: 700; font-size: 1.05rem; min-width: 0; }
.level-desc { grid-column: 2; font-size: 0.85rem; color: var(--muted); min-width: 0; }
.level-side { grid-column: 3; grid-row: 1 / span 2; text-align: right; display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.stars { color: var(--amber); letter-spacing: 2px; font-size: 1rem; }
.stars .off { color: var(--line); }
.best { font-family: var(--font-code); font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.hub-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Juego ---------- */
.play { gap: 10px; }
.hud {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.hud-level { font-family: var(--font-display); color: var(--amber); font-size: 0.95rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.icon { padding: 6px 10px; border-color: var(--line); font-family: var(--font-code); }
.lives { color: var(--bad); font-size: 1.05rem; letter-spacing: 2px; }
.lives .off { color: var(--line); }
.progress { height: 6px; background: var(--panel); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--amber)); transition: width 0.3s ease; }

.prompt {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.prompt-ask { font-weight: 700; font-size: 1rem; }
.prompt-ask code, .missed-list code { font-family: var(--font-code); color: var(--cyan); font-size: 0.92em; }
.prompt-code {
  margin: 0;
  font-family: var(--font-code);
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--fg);
  overflow-x: auto;
  white-space: pre;
}
.prompt-code:empty { display: none; }
.prompt-code .cm { color: var(--muted); }
.prompt-code .kw { color: var(--amber); }
.prompt-options { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 0.9rem; }
.prompt-options li { display: flex; gap: 8px; }
.prompt-options b { font-family: var(--font-code); color: var(--amber); flex: none; }

.stage { position: relative; }
canvas {
  display: block;
  margin-inline: auto;
  width: 100%;
  height: auto;
  aspect-ratio: 400 / 460;
  max-width: 100%;
  background: #0f0b13;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  touch-action: none;
}

.overlay, .feedback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  background: rgba(15, 11, 19, 0.88);
  border-radius: var(--radius);
}
.overlay h3 { font-family: var(--font-display); font-weight: 400; font-size: 1.6rem; color: var(--amber); }
.overlay p { max-width: 36ch; color: var(--fg); }
.controls-help { font-size: 0.85rem; color: var(--muted) !important; font-family: var(--font-code); }
.feedback { justify-content: flex-end; background: linear-gradient(transparent 20%, rgba(15, 11, 19, 0.95) 55%); }
.feedback .fb-title { font-family: var(--font-display); font-size: 1.3rem; }
.feedback.bad .fb-title { color: var(--bad); }
.feedback.good .fb-title { color: var(--good); }
.fb-text { max-width: 38ch; font-size: 0.95rem; }
.fb-text code { font-family: var(--font-code); color: var(--cyan); }
.feedback:not(.toast) {
  justify-content: center;
  background: rgba(15, 11, 19, 0.94);
  overflow-y: auto;
}
.feedback:not(.toast) .fb-text { font-size: 1rem; line-height: 1.55; max-width: 40ch; }
.btn.wait { position: relative; overflow: hidden; }
.btn.wait::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: var(--ink);
  transform-origin: left;
  animation: fill-wait var(--wait, 1.2s) linear forwards;
}
@keyframes fill-wait { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.world-head { display: flex; flex-direction: column; gap: 2px; padding: 14px 2px 2px; }
.world-head:first-child { padding-top: 0; }
.world-head h3 { font-family: var(--font-display); font-weight: 400; color: var(--fg); font-size: 1.15rem; }
.world-head p { font-size: 0.85rem; }
.feedback.toast {
  inset: 8px 8px auto 8px;
  justify-content: flex-start;
  gap: 2px;
  padding: 8px 12px;
  background: rgba(15, 11, 19, 0.9);
  border: 1px solid var(--line);
}
.feedback.toast .fb-title { font-size: 0.95rem; }
.feedback.toast .fb-text { font-size: 0.85rem; }
.feedback.toast .btn { display: none; }

.touch-controls { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; }
.btn.pad {
  background: var(--panel);
  border-color: var(--line);
  padding: 14px 0;
  font-size: 1.2rem;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.btn.pad.action { color: var(--amber); font-size: 1rem; letter-spacing: 0.06em; text-transform: uppercase; }
.btn.pad.held { background: var(--panel-2); border-color: var(--amber); }

/* ---------- Resultado y repaso ---------- */
.result h2 { font-family: var(--font-display); font-weight: 400; color: var(--amber); font-size: 1.7rem; }
.res-stars { font-size: 2rem; letter-spacing: 6px; color: var(--amber); }
.res-stars .off { color: var(--line); }
.res-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.missed-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.missed-list li { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.missed-list pre { margin: 0; font-family: var(--font-code); font-size: 0.78rem; overflow-x: auto; color: var(--muted); }
.missed-list .q { font-weight: 700; }
.missed-list .a { color: var(--good); font-family: var(--font-code); font-size: 0.9rem; }
.missed-list .why { font-size: 0.88rem; }
.missed-list .tag { font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--cyan); }

.export-box textarea { min-height: 80px; }

@media (min-width: 720px) {
  .touch-controls { display: none; }
  @media (pointer: coarse) { .touch-controls { display: grid; } }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Modos de juego y secciones ---------- */
.hub-nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hub-nav .btn { padding: 6px 12px; font-size: 0.85rem; }
.choice-back { align-self: flex-start; padding: 6px 12px; font-size: 0.85rem; }
.crumb { font-family: var(--font-code); font-size: 0.8rem; color: var(--cyan); letter-spacing: 0.04em; }
.mode-grid { display: flex; flex-direction: column; gap: 12px; }
.view-title { font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: linear-gradient(135deg, rgba(255, 181, 71, 0.10), transparent 55%), var(--panel);
  border: 1px solid var(--amber-deep);
  border-left: 6px solid var(--amber);
  border-radius: var(--radius);
  padding: 18px 20px;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.mode-card:hover { transform: translateY(-2px); border-color: var(--amber); }
.mode-card:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.mode-card.alt {
  background: linear-gradient(135deg, rgba(99, 212, 230, 0.08), transparent 55%), var(--panel);
  border-color: var(--line);
  border-left-color: var(--cyan);
}
.mode-card.alt:hover { border-color: var(--cyan); }
.mode-tag { font-family: var(--font-code); font-size: 0.72rem; color: var(--cyan); letter-spacing: 0.08em; }
.mode-name { font-family: var(--font-display); font-weight: 400; font-size: 1.9rem; line-height: 1.1; color: var(--amber); }
.mode-name.small { font-size: 1.35rem; }
.mode-card.alt .mode-name { color: var(--fg); }
.mode-desc { font-size: 0.92rem; color: var(--muted); max-width: 44ch; }
.mode-meta { font-family: var(--font-code); font-size: 0.78rem; color: var(--fg); margin-top: 4px; }
.soon-chip {
  border: 1px dashed var(--cyan);
  color: var(--cyan);
  border-radius: 999px;
  padding: 2px 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.soon-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 7, 13, 0.82);
}
.soon-box {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--cyan);
  border-radius: var(--radius);
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.soon-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2rem;
  color: var(--amber);
  text-shadow: 0 0 18px rgba(255, 181, 71, 0.35);
  animation: soon-blink 1.2s steps(2, start) infinite;
}
@keyframes soon-blink { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .soon-title { animation: none; } .mode-card { transition: none; } }

/* ---------- Fondo animado del menú de inicio ---------- */
#bg-fight { position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.75; }
#app { position: relative; z-index: 1; }
.arena { position: relative; height: 136px; margin-top: 4px; border-bottom: 1px dashed var(--line); overflow: hidden; }
.arena canvas { position: absolute; inset: 0; opacity: 0.85; }

/* ---------- Botón de sonido ---------- */
.sound-toggle {
  position: fixed;
  top: max(10px, env(safe-area-inset-top, 0px));
  right: max(10px, env(safe-area-inset-right, 0px));
  z-index: 40;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(34, 26, 41, 0.9);
  color: var(--cyan);
  cursor: pointer;
}
.sound-toggle:hover { border-color: var(--cyan); }
.sound-toggle.off, .sound-icon.off { color: var(--muted); }
.sound-icon { display: grid; place-items: center; color: var(--cyan); padding: 5px 8px; }
.sound-toggle:focus-visible, .sound-icon:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.hub-head, .brand { padding-right: 46px; }
@media (max-width: 480px) { .hud { gap: 8px; } }

/* ---------- Cuenta en la nube ---------- */
.stack-form.tight { padding-top: 0; }
.cloud-panel { border-color: rgba(99, 212, 230, 0.45); }
.google-btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; background: #fff; color: #1f1f1f; box-shadow: 0 3px 0 #b9b2c0; }
.google-btn:hover { background: #f1eef4; }
.linkish { background: none; border: 0; padding: 0; color: var(--cyan); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; align-self: flex-start; }
.linkish:hover { color: var(--fg); }
.small { font-size: 0.85rem; }
.save-status { font-family: var(--font-code); font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.save-status.ok { color: var(--good); }
.save-status.err { color: var(--bad); }
select { width: 100%; }
.brand .arena { margin-right: -46px; }

/* ---------- Menú de inicio: elegir cómo jugar ---------- */
#login-choice .view-title { text-align: center; }
#login-choice .mode-card { align-items: center; text-align: center; padding-block: 22px; }
#login-choice .mode-desc { max-width: 40ch; }

/* ---------- Link a GitHub (esquina inferior derecha, fuera del juego) ---------- */
.gh-link {
  position: fixed;
  right: max(12px, env(safe-area-inset-right, 0px));
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  z-index: 40;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(34, 26, 41, 0.9);
  color: var(--muted);
  font-family: var(--font-code);
  font-size: 0.78rem;
  text-decoration: none;
}
.gh-link:hover { color: var(--fg); border-color: var(--cyan); }
.gh-link:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
/* Espacio al final para que el link no tape el último botón en pantallas chicas. */
#screen-login, #screen-hub, #screen-result, #screen-review { padding-bottom: 56px; }
/* En pantallas chicas va al final de la página (no flotando sobre los formularios). */
@media (max-width: 700px) { .gh-link { position: absolute; bottom: 12px; } }

/* ---------- Sorpresa de la C del título ---------- */
.logo-c { cursor: pointer; display: inline-block; border-radius: 6px; }
.logo-c:focus-visible { outline: 2px solid var(--cyan); outline-offset: 4px; }
.logo-c.wobble { animation: c-wobble 0.5s ease-out; }
@keyframes c-wobble { 0% { transform: none; } 30% { transform: translateY(3px) scale(1.06, 0.92); } 60% { transform: translateY(-2px) rotate(-4deg); } 100% { transform: none; } }
.egg-canvas { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; margin: 0; z-index: 60; pointer-events: none; background: transparent; border: 0; border-radius: 0; }
@media (prefers-reduced-motion: reduce) { .logo-c.wobble { animation: none; } }
