* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b0d14;
  color: #e8e8ee;
  font-family: system-ui, -apple-system, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* fijo al viewport visible: en iPhone 100vh es más alto que la pantalla y tapa lo de abajo */
canvas { display: block; position: fixed; inset: 0; width: 100%; height: 100%; }

/* ---------- Ayuda ---------- */
/* botón "🧑‍🚀 Ayuda" en la pantalla de inicio (menú de stages), arriba a la izquierda */
#gear {
  position: absolute; z-index: 1;
  top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left));
  padding: 8px 14px; border-radius: 12px; border: 1px solid #ffffff33;
  background: #2a2f3a; color: #e8e8ee; font: inherit; font-size: 14px; cursor: pointer;
}
#gear:hover, #gear.selected { border-color: #ffd24a; }
#gear.selected { outline: 3px solid #ffd24a; outline-offset: 2px; }
/* salir del stage: arriba a la derecha, como mantener B */
#exit {
  position: fixed; z-index: 10;
  top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right));
  width: 30px; height: 30px; padding: 0; border-radius: 50%;
  border: 1px solid #ffffff33; background: #1f222b99; color: #e8e8ee;
  font-size: 14px; line-height: 1; cursor: pointer; opacity: .6;
  display: flex; align-items: center; justify-content: center;
}
#exit[hidden] { display: none; }
#exit:hover, #exit:active { opacity: 1; background: #e8473a; border-color: #e8473a; }
#exit::after { content: ''; position: absolute; inset: -10px; }

#panel {
  position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 46px); left: max(12px, env(safe-area-inset-left)); z-index: 10;
  display: none;
  min-width: 220px;
  max-width: min(340px, calc(100vw - 24px));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 12px 16px;
  background: #1f222bee;
  border: 1px solid #ffffff22;
  border-radius: 12px;
  box-shadow: 0 8px 24px #0008;
}
#panel.open { display: block; }
#panel h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; opacity: .7; }
#panel h3:not(:first-child) { margin-top: 16px; }
#panel label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 0; font-size: 15px; cursor: pointer;
}
#panel input { width: 20px; height: 20px; cursor: pointer; }
#panel p, #panel ol { margin: 4px 0; font-size: 14px; line-height: 1.45; }
#panel ol { padding-left: 20px; }
#panel li { margin-bottom: 6px; }
#panel .hint { font-size: 12px; opacity: .6; }
#panel dl { margin: 4px 0; font-size: 14px; line-height: 1.45; }
#panel dt { font-weight: 600; margin-top: 8px; }
#panel dd { margin: 2px 0 0; opacity: .85; }
#panel .num { color: #8fd0ff; font-weight: 600; white-space: nowrap; }
#panel .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* pestañas */
.tabs { display: flex; gap: 4px; margin: -4px 0 12px; border-bottom: 1px solid #ffffff1a; }
.tab {
  flex: 1; padding: 8px 4px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: #e8e8ee; font: inherit; font-size: 14px; opacity: .6; cursor: pointer;
}
.tab.active { opacity: 1; border-bottom-color: #8fd0ff; }
.tabs .close {
  flex: none; width: 34px; border: 0; background: none; color: #e8e8ee;
  font: inherit; font-size: 16px; opacity: .6; cursor: pointer;
}
.tabs .close:hover { opacity: 1; }
.pane { display: none; }
.pane.active { display: block; }
.credits { text-align: center; }
/* idioma (en la pestaña Ayuda) */
.lang-btns { display: flex; gap: 8px; margin: 6px 0 4px; }
.lang-btn {
  flex: 1; padding: 8px 10px; border-radius: 10px; border: 1px solid #ffffff33;
  background: #2a2f3a; color: #e8e8ee; font: inherit; font-size: 14px; cursor: pointer;
}
.lang-btn.current { border-color: #8fd0ff; background: #2f4a63; }
.lang-btn:hover, #panel .lang-btn.selected { border-color: #ffd24a; }
#panel .lang-btn.selected { outline: 2px solid #ffd24a; outline-offset: 2px; }
#panel .credits h3 { color: #ffd24a; letter-spacing: .3em; opacity: 1; }
#panel .credits dt { font-size: 12px; font-weight: 400; opacity: .6; text-transform: uppercase; letter-spacing: .05em; }


/* ---------- Botones táctiles ---------- */
#touch { display: none; }
#touch.on { display: block; }
#steer, #thrust {
  position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 5;
  touch-action: none; -webkit-touch-callout: none;
}
#steer { left: max(24px, env(safe-area-inset-left)); display: flex; gap: 12px; }
#thrust { right: max(24px, env(safe-area-inset-right)); width: 110px; height: 110px; font-size: 40px; }
.tbtn {
  width: 84px; height: 84px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: #ffffffb0;
  background: #ffffff12; border: 2px solid #ffffff30;
  pointer-events: none;   /* el contenedor recibe el toque */
}
#thrust.tbtn { pointer-events: auto; }
.tbtn.down { background: #ffffff38; border-color: #ffffff80; color: #fff; }
#thrust.down { background: #ff9a3c55; border-color: #ffb36b; }

/* ---------- Menú de stages y stage completo ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 8;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 16px;
  background: radial-gradient(ellipse at center, #0b0d14aa, #0b0d14ee);
}
.overlay[hidden] { display: none; }
/* Xbox: el oscurecido lo pinta el canvas (js/main.js, drawMenuDim). Una capa translúcida a pantalla
   completa encima del canvas baja el menú a la mitad de fps en la consola. */
body.xbox .overlay { background: none; }
.overlay h1 { margin: 0; font-size: 44px; letter-spacing: .3em; color: #ffd24a; }
.overlay .sub { margin: 0 0 8px; opacity: .7; }
/* el color apagado va en el texto (no con opacity) para que los botones del mando se vean enteros */
.overlay .hint { margin: 8px 0 0; font-size: 12px; color: #e8e8ee80; }

/* ---------- Botones del mando en los textos (js/ui/buttons.js) ---------- */
.pbtn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.55em; height: 1.55em; margin: 0 .1em; border-radius: 50%;
  vertical-align: middle; position: relative; top: -.08em;
  background: #555b6b; color: #fff; font-size: .9em; font-weight: 800; line-height: 1;
  box-shadow: inset 0 -2px 0 #0004, 0 1px 2px #0008;
}
.pbtn-a { background: #3fa535; }
.pbtn-b { background: #e8473a; }
.pbtn-x { background: #2f7de1; }
.pbtn-y { background: #d9a400; }
.pbtn-rt { border-radius: .45em .45em .7em .7em; padding: 0 .4em; }   /* gatillo: pastilla */

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(3, minmax(90px, 120px));
}
.tile {
  position: relative; aspect-ratio: 1; padding: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 2px solid #ffd24a66; border-radius: 18px;
  background: linear-gradient(160deg, #2a3350, #161a28);
  color: #e8e8ee; font: inherit; cursor: pointer;
  box-shadow: 0 6px 0 #0a0c14, 0 10px 20px #0008;
  transition: transform .08s;
}
.tile:hover:not(:disabled) { transform: translateY(-2px); border-color: #ffd24a; }
.tile:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 3px 0 #0a0c14; }
.tile .num { font-size: 32px; font-weight: 800; }
.tile .name { font-size: 11px; opacity: .75; text-align: center; }
.tile .best { font-size: 10px; opacity: .5; font-family: ui-monospace, Menlo, monospace; }
.tile.locked { cursor: default; opacity: .4; border-color: #ffffff22; }
.tile .lock { font-size: 18px; }

.done { font-size: 11px; color: #ffffff55; }
.done.on { color: #78ffa0; font-weight: 700; text-shadow: 0 0 6px #78ffa088; }
.done.big { font-size: 48px; line-height: 1; }

.card {
  padding: 24px 28px; text-align: center;
  background: #1f222bee; border: 1px solid #ffd24a55; border-radius: 18px;
  box-shadow: 0 12px 40px #000a;
}
.card h2 { margin: 0 0 8px; color: #ffd24a; }
.card .time { margin: 8px 0 16px; opacity: .85; }
.buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.buttons button, #panel button.wide {
  padding: 10px 18px; border-radius: 12px; border: 1px solid #ffffff33;
  background: #2a2f3a; color: #e8e8ee; font: inherit; font-size: 15px; cursor: pointer;
}
.buttons button.primary { background: #ffd24a; color: #1a1a1a; border-color: #ffd24a; font-weight: 700; }
#panel button.wide { width: 100%; margin-bottom: 12px; font-size: 14px; padding: 8px; }

/* ---------- Stage completo ---------- */
/* Sin `gap` en los flex: EdgeHTML (Xbox) no lo soporta, así que el espaciado va con márgenes. */
#complete .card {
  min-width: 320px; max-width: calc(100vw - 32px); box-sizing: border-box;
  padding: 30px 36px 28px;
  background: #12151df2; border: 1px solid #ffffff22; border-radius: 22px;
}
#complete .badge {
  width: 60px; height: 60px; margin: 0 auto 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800; line-height: 1;
  color: #78ffa0; background: #78ffa01f; border: 2px solid #78ffa0;
}
#complete .card h2 { margin: 0; font-size: 22px; color: #ffd24a; }
#complete .stage-name { margin: 6px 0 0; font-size: 14px; color: #9aa0ad; }
#complete .result {
  margin: 22px 0 26px; padding: 14px 0;
  border-top: 1px solid #ffffff1a; border-bottom: 1px solid #ffffff1a;
}
#complete .result .lbl {
  display: block; margin-bottom: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #9aa0ad;
}
#complete .result .val { font: 700 30px ui-monospace, Menlo, monospace; color: #e8e8ee; }
#complete .result .record {
  display: table; margin: 10px auto 0; padding: 3px 12px;   /* table: se ajusta al texto (sin fit-content en EdgeHTML) */ border-radius: 999px;
  background: #ffd24a; color: #1a1a1a; font-size: 12px; font-weight: 800; letter-spacing: .04em;
}
#complete .buttons { gap: 0; margin: 0 -8px; flex-wrap: nowrap; }
#complete .buttons button {
  flex: 1 1 0; min-width: 104px; margin: 0 8px; padding: 12px 14px;
  border: 2px solid #ffffff2e; border-radius: 14px;
  background: #1f2430; color: #e8e8ee; font-size: 15px; font-weight: 600; white-space: nowrap;
  outline: none; transition: transform .08s;
}
#complete .buttons .ico { margin-right: 7px; opacity: .8; }
#complete .buttons .ico.end { margin: 0 0 0 7px; }
#complete .buttons button.primary { border-color: #ffd24a99; color: #ffd24a; }
#complete .buttons button:hover { border-color: #ffd24a; }
/* seleccionado (mando / teclado): el único botón relleno, apenas más grande */
#complete .buttons button.selected {
  background: #ffd24a; border-color: #ffd24a; color: #1a1a1a; font-weight: 800;
  outline: none; transform: scale(1.06);
  box-shadow: 0 0 0 4px #ffd24a40;
}
#complete .buttons button.selected .ico { opacity: 1; }
#complete .buttons button:active { transform: scale(.98); }

/* capítulos */
.grid.chapters { grid-template-columns: repeat(4, minmax(70px, 180px)); }   /* los 4 capítulos en una sola fila */
.tile.chapter { aspect-ratio: 4 / 5; }
.tile .icon { font-size: 40px; line-height: 1.1; }
.tile.chapter .num { font-size: 18px; }
.tile.chapter .name { font-size: 14px; opacity: .9; }
.tile .count { font-size: 12px; color: #ffd24a; }
.overlay .back {
  margin-top: 4px; padding: 8px 16px; border-radius: 12px; border: 1px solid #ffffff33;
  background: #2a2f3a; color: #e8e8ee; font: inherit; font-size: 14px; cursor: pointer;
}
.overlay .back[hidden] { display: none; }

/* selección (mando / teclado / mouse) */
.tile:focus { outline: none; }
.tile.selected {
  border-color: #ffd24a;
  background: linear-gradient(160deg, #3a4670, #20263a);
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 6px 0 #0a0c14, 0 0 0 3px #ffd24a, 0 0 24px #ffd24a88;
}
/* el brillo que late: una capa aparte a la que solo le cambia la opacidad (animar box-shadow
   obliga a repintar todo en cada frame, y en la Xbox eso baja mucho los fps) */
.tile.selected::after {
  content: ''; position: absolute; inset: -2px; border-radius: inherit; pointer-events: none;
  box-shadow: 0 0 36px #ffd24acc; opacity: 0;
  animation: tileGlow 1.2s ease-in-out infinite;
}
@keyframes tileGlow { 50% { opacity: 1; } }
.buttons button.selected, .overlay .back.selected, #panel button.wide:focus {
  outline: 3px solid #ffd24a; outline-offset: 2px;
}
/* flechita que apunta al casillero seleccionado */
.tile.selected::before {
  content: '▼'; position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
  color: #ffd24a; font-size: 14px; text-shadow: 0 0 8px #ffd24a;
  animation: tileArrow .8s ease-in-out infinite alternate;
}
@keyframes tileArrow { to { transform: translateX(-50%) translateY(6px); } }   /* transform: sin rehacer el layout */

/* ---------- Mando / teclado en el panel de ayuda ---------- */
#panel .tab.selected { opacity: 1; outline: 2px solid #ffd24a; outline-offset: -2px; border-radius: 6px; }
