/*
 * Micro Play Bit 1.0 — David Bautista Prados
 * Sistema de diseño y reglas adaptativas para las dos orientaciones.
 * Palabras clave: micro:bit, educación primaria, STEAM, interacción física, offline.
 * © David Bautista Prados. Todos los derechos reservados.
 */
/* Sistema visual común: tipografía, paleta, controles y adaptación a pantallas. */
* {
  box-sizing: border-box;
}
[hidden] {
  display: none!important;
}
:root {
  font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  color: #34383E;
  background: #F1F2F4;
  --bg: #F1F2F4;
  --field: #E4E7EA;
  --ink: #34383E;
  --blue: #006DB5;
  --red: #006DB5;
  --line: #B6BDC4;
  --white: #fff;
  --ui-size: 16px;
  --ui-weight: 700;
  --action-height: 44px;
  --gap: 8px;
  --radius: 12px;
  -webkit-font-smoothing: antialiased;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg);
  font-size: var(--ui-size);
  color: var(--ink);
}
main {
  width: min(100%,1200px);
  padding: max(12px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}
body.playing main {
  height: 100vh;
  height: 100dvh;
  max-width: 1440px;
  width: 100%;
  min-height: 0;
}
header {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);
  align-items: center;
  gap: var(--gap);
  min-width: 0;
  flex: none;
}
body.playing header {
  grid-template-columns: minmax(0,1fr) auto;
  grid-template-rows: auto auto;
  row-gap: 6px;
}
.heading,.actions {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.actions {
  justify-content: flex-end;
}
body.playing .heading {
  grid-column: 1;
  grid-row: 1;
}
body.playing .actions {
  grid-column: 2;
  grid-row: 1;
}
#name {
  font-size: var(--ui-size);
  font-weight: var(--ui-weight);
  line-height: 1.2;
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}
#topcenter {
  grid-row: 2;
  grid-column: 1/-1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  font-size: var(--ui-size);
  font-weight: var(--ui-weight);
  min-width: 0;
}
#topcenter:empty {
  display: none;
}
button,select {
  font: inherit;
  color: var(--ink);
  font-weight: var(--ui-weight);
  line-height: 1.2;
  letter-spacing: 0;
  min-height: var(--action-height);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 7px 12px;
  text-align: center;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  transition: background-color .10s,border-color .10s,color .10s;
}
button:active,button.pressed {
  background: #D3D8DD;
  border-color: var(--ink);
}
button:focus-visible,select:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 2px;
}
@media(hover:hover) {
  button:hover {
    border-color: var(--ink);
  }
}
#home,#sound,#restart,#helpbtn {
  width: var(--action-height);
  height: var(--action-height);
  min-width: var(--action-height);
  padding: 0;
  flex: none;
}
#home svg,#sound svg,#restart svg,#test svg {
  width: 22px;
  height: 22px;
  stroke-width: 2.2;
  display: block;
  flex: none;
}
#test small {
  font: inherit;
  white-space: nowrap;
}
#helpbtn {
  font-size: 22px;
}
#level {
  white-space: nowrap;
}
#logo {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  margin: 0;
  font-size: clamp(24px,6.3vw,44px);
  font-weight: 850;
  letter-spacing: -1.5px;
  white-space: nowrap;
  line-height: 1.15;
}
#logo span,#logo i {
  color: var(--red);
}
#logo strong {
  background: var(--ink);
  color: #fff;
  padding: 2px 8px;
  border-radius: 7px;
}
#logo i {
  font-style: normal;
  font-size: .7em;
}
body:not(.playing) main {
  min-height: min(100dvh,840px);
  justify-content: space-between;
  gap: 12px;
}
#menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}
#selector-panel {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(100%,400px);
  padding: 16px 0;
}
#preview-icon {
  width: clamp(70px,18dvh,140px);
  height: clamp(70px,18dvh,140px);
  color: var(--ink);
  display: grid;
  place-items: center;
}
#preview-icon svg {
  width: 100%;
  height: 100%;
}
#preview-name {
  font-size: clamp(24px,5vw,32px);
  font-weight: 700;
  margin: 0;
}
#preview-desc {
  font-size: var(--ui-size);
  font-weight: 500;
  text-align: center;
  margin: 0 0 6px;
  color: #626A73;
}
#game-select,#start-game {
  width: 100%;
  min-height: 48px;
}
#game-select {
  text-align-last: center;
  cursor: pointer;
}
#start-game {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
#start-game:active {
  background: var(--red);
  border-color: var(--red);
}
#start-game svg {
  width: 20px;
  height: 20px;
}
footer {
  margin-top: auto;
  padding: 12px 0 0;
  text-align: center;
  color: #626A73;
  font-size: 12px;
  font-weight: 500;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
#play {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  gap: var(--gap);
}
#stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--field);
  border-radius: 16px;
}
canvas {
  display: block;
  flex: none;
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  touch-action: none;
}
#message {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: var(--ui-size);
  font-weight: var(--ui-weight);
  line-height: 1.25;
  color: var(--ink);
  min-height: 44px;
  height: 44px;
  padding: 0 12px;
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#message:empty {
  visibility: hidden;
}
#controls {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
#controls:empty {
  display: none;
}
#controls button {
  height: var(--action-height);
  min-width: var(--action-height);
  white-space: nowrap;
  padding: 0 12px;
}
#controls button[data-key^="Arrow"],#controls button:not(.wide):not([data-key]) {
  width: var(--action-height);
  padding: 0;
  font-size: 22px;
}
#controls button[data-key=" "] {
  font-size: var(--ui-size);
}
.tools {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.tools button {
  min-width: 100px;
  white-space: nowrap;
}
.queue {
  max-width: 100%;
  min-width: 0;
  width: min(100%,760px);
  height: var(--action-height);
  display: block;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: white;
  text-align: center;
  font-size: var(--ui-size);
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: auto hidden;
  touch-action: pan-x;
  scrollbar-width: thin;
}
.duel-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.duel-player,.duel-play {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.duel-player svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.duel-sep {
  color: #737B84;
}
.padgrid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  grid-template-rows: repeat(2,minmax(0,1fr));
  width: min(100%,760px);
  height: min(100%,520px);
  padding: 12px;
  gap: 10px;
}
.padgrid button {
  min-height: 0;
  min-width: 0;
  border: 1.5px solid #9299A1;
  font-size: clamp(32px,8dvh,64px);
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px #34383E99,0 -1px 1px #34383E66;
  transition: none;
}
.padgrid button.lit {
  background: var(--lit-color)!important;
  border-color: var(--ink);
  box-shadow: inset 0 0 0 5px var(--ink);
  color: white;
}
.padgrid button.pressed:not(.lit) {
  border-color: var(--ink);
}
.piano {
  display: flex;
  align-items: stretch;
  width: min(100%,1000px);
  height: min(65%,320px);
  gap: 6px;
  padding: 12px;
  max-height: 100%;
}
.piano button {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 2px solid var(--ink);
  font-size: clamp(18px,3vw,30px);
  font-weight: 700;
}
.piano button.lit {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.piano button.pressed,.piano button:active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.extra-question {
  width: min(100%,680px);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 12px;
  padding: 12px;
}
.extra-rule {
  font-size: var(--ui-size);
  font-weight: 700;
  text-align: center;
}
.extra-prompt {
  font-size: clamp(24px,6dvh,44px);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  min-height: 1.15em;
}
.extra-rule:empty {
  display: none;
}
.extra-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 8px;
  width: 100%;
}
.extra-grid button {
  min-width: 0;
  min-height: clamp(52px,12dvh,88px);
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: var(--ui-size);
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.choice-arrow {
  font-size: 24px;
  line-height: 1;
  flex: none;
}
.choice-label {
  min-width: 0;
  text-align: center;
}
.extra-grid button.correct {
  background: #B8DFC4;
  border-color: #36825A;
  color: #174C31;
}
.extra-grid button.wrong {
  background: #F0C3BF;
  border-color: var(--red);
  color: #702723;
}
.extra-grid button svg {
  width: 26px;
  height: 26px;
  flex: none;
}
.extra-target {
  width: clamp(45px,10dvh,74px);
  height: clamp(45px,10dvh,74px);
  display: grid;
  place-items: center;
}
.extra-target svg {
  width: 100%;
  height: 100%;
}
.board-layout {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  align-items: center;
  justify-items: center;
  gap: 12px;
  padding: 8px;
}
.board-panel {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.board-panel h3 {
  font-size: var(--ui-size);
  margin: 0;
  font-weight: 700;
  color: var(--ink);
  flex: none;
}
.board-panel svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100% - 26px);
  min-height: 0;
  overflow: visible;
  touch-action: none;
  user-select: none;
}
.board-contact {
  cursor: pointer;
  outline: none;
  touch-action: none;
}
.board-contact .pin-face {
  transition: fill .08s,stroke .08s;
  stroke-width: 1.5;
}
.board-contact:focus-visible .pin-face,.board-contact.pin-active .pin-face {
  stroke: #34383E;
  stroke-width: 3;
}
.board-contact.pin-active .pin-face {
  fill: #FFD43A;
}
.board-contact.pin-active .pin-label {
  fill: #34383E;
  font-weight: 700;
}
@media(max-width:650px) and (orientation:portrait) {
  #test small {
    display: none;
  }
  .piano {
    display: grid;
    grid-template-columns: repeat(12,minmax(0,1fr));
    grid-template-rows: repeat(2,minmax(0,1fr));
    height: clamp(140px,36dvh,260px);
    gap: 5px;
  }
  .piano button {
    grid-column: span 2;
  }
  .piano button:nth-child(7) {
    grid-column: 2/span 2;
  }
  .board-layout {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2,minmax(0,1fr));
    gap: 8px;
  }
  .padgrid {
    height: min(100%,460px);
  }
}
@media(max-width:420px) and (orientation:portrait) {
  :root {
    --ui-size: 14px;
    --action-height: 40px;
    --gap: 6px;
  }
  main {
    padding: 8px;
  }
  header,.heading,.actions {
    gap: 4px;
  }
  #level {
    padding: 0 6px;
  }
  #name {
    font-size: var(--ui-size);
  }
  #home svg,#sound svg,#restart svg,#test svg {
    width: 20px;
    height: 20px;
  }
  #controls button {
    min-height: 44px;
    height: 44px;
    min-width: 44px;
    padding-inline: 9px;
  }
  #controls button[data-key^="Arrow"],#controls button:not(.wide):not([data-key]) {
    width: 44px;
    padding: 0;
  }
  .extra-question {
    padding: 8px;
    gap: 8px;
  }
  .extra-grid button {
    gap: 5px;
  }
  .extra-grid button svg {
    width: 20px;
    height: 20px;
  }
  .choice-arrow {
    font-size: 20px;
  }
}
@media(max-width:355px) and (orientation:portrait) {
  :root {
    --action-height: 36px;
  }
  #level {
    padding: 0 5px;
  }
  #logo {
    font-size: 24px;
  }
  .heading,.actions {
    gap: 3px;
  }
  .extra-grid button {
    gap: 4px;
  }
  .extra-grid button svg {
    width: 18px;
    height: 18px;
  }
}
@media(orientation:landscape) and (max-height:600px) {
  :root {
    --ui-size: 14px;
    --action-height: 36px;
    --gap: 5px;
  }
  main {
    padding: 5px 8px;
  }
  #selector-panel {
    gap: 5px;
    padding: 4px 0;
  }
  #preview-icon {
    width: clamp(46px,17dvh,96px);
    height: clamp(46px,17dvh,96px);
  }
  #preview-name {
    font-size: 22px;
  }
  #preview-desc {
    margin: 0;
  }
  #game-select,#start-game {
    min-height: 36px;
    padding: 5px 12px;
  }
  footer {
    padding: 4px 0 0;
  }
  #home svg,#sound svg,#restart svg,#test svg {
    width: 20px;
    height: 20px;
  }
  .extra-question {
    padding: 5px;
    gap: 5px;
  }
  .extra-grid button {
    min-height: 40px;
    padding: 5px;
  }
  .extra-target {
    width: 38px;
    height: 38px;
  }
  .extra-prompt {
    font-size: clamp(20px,6dvh,32px);
  }
  .padgrid {
    padding: 6px;
    gap: 6px;
  }
  .piano {
    padding: 6px;
    height: min(75%,220px);
  }
  .queue {
    padding: 5px 8px;
  }
}
@media(prefers-reduced-motion:reduce) {
  button {
    transition: none;
  }
}
/* 3.9 — ayuda visual con la misma placa de Conexiones. */
#helpbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--action-height);
  height: var(--action-height);
  min-width: var(--action-height);
  padding: 0;
  font-weight: 800;
  flex: none;
}
#helpmodal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: max(8px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));
}
.help-backdrop {
  position: absolute;
  inset: 0;
  background: #18202b66;
}
.help-card {
  position: relative;
  width: min(850px,100%);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  background: #fff;
  border: 2px solid var(--help-dark);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 12px 36px #18202b26;
  touch-action: pan-y;
}
#helpclose {
  position: sticky;
  top: 0;
  float: right;
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 27px;
  line-height: 1;
  color: var(--help-dark);
  border-color: var(--help-strong);
  background: white;
  z-index: 2;
}
.help-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 50px;
  margin-bottom: 12px;
  min-height: 44px;
}
.help-icon {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--help-soft);
  color: var(--help-dark);
  border-radius: 12px;
}
.help-icon svg {
  width: 30px;
  height: 30px;
}
#helptitle {
  font-size: clamp(20px,3vw,26px);
  margin: 0;
  color: var(--help-dark);
}
.help-grid {
  display: grid;
  grid-template-columns: minmax(0,1.55fr) minmax(0,1fr);
  gap: 18px;
  align-items: start;
  clear: both;
}
.help-grid h4 {
  font-size: 17px;
  line-height: 1.25;
  margin: 0 0 9px;
  color: var(--help-dark);
}
.help-diagrams {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  max-width: 440px;
  margin: auto;
}
.help-diagrams .board-panel {
  height: auto;
  justify-content: start;
  gap: 3px;
}
.help-diagrams .board-panel h3 {
  font-size: 12px;
  color: #48515b;
}
.help-diagrams .board-panel svg {
  width: 100%;
  height: auto;
  max-height: none;
  touch-action: pan-y;
  overflow: hidden;
}
.help-diagrams .board-contact {
  cursor: default;
  touch-action: pan-y;
}
.help-diagrams .board-contact:not(.help-required) {
  opacity: .48;
}
.help-diagrams .help-required .pin-face,.help-diagrams .help-earth {
  fill: var(--help-soft);
  stroke: var(--help-dark);
  stroke-width: 3;
}
.help-diagrams .help-required[data-pin="w"]>rect:first-child,.help-diagrams .help-required[data-pin="a"]>rect:first-child,.help-diagrams .help-required[data-pin="s"]>rect:first-child,.help-diagrams .help-required[data-pin="d"]>rect:first-child,.help-diagrams .help-required[data-pin="f"]>rect:first-child,.help-diagrams .help-required[data-pin="g"]>rect:first-child {
  stroke: var(--help-dark);
  stroke-width: 1.8;
  fill: transparent;
}
.help-caption {
  font-size: 13px;
  line-height: 1.35;
  color: #34383e;
  margin: 9px 0 0;
  font-weight: 500;
}
.help-instructions ol {
  margin: 0;
  padding-left: 24px;
  font-size: 16px;
  line-height: 1.45;
  font-weight: 500;
  color: #34383e;
}
.help-instructions li {
  padding-left: 3px;
}
.help-instructions li+li {
  margin-top: 10px;
}
.help-instructions li::marker {
  font-weight: 800;
  color: var(--help-dark);
}
@media(orientation:portrait) and (max-width:650px) {
  .help-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .help-card {
    padding: 12px;
  }
  .help-instructions ol {
    font-size: 15px;
  }
}
@media(orientation:landscape) and (max-height:600px) {
  .help-card {
    padding: 10px 12px;
    max-height: calc(100dvh - 16px);
  }
  .help-top {
    min-height: 34px;
    margin-bottom: 8px;
  }
  .help-icon {
    width: 34px;
    height: 34px;
  }
  .help-icon svg {
    width: 25px;
    height: 25px;
  }
  #helpclose {
    height: 34px;
    min-height: 34px;
    width: 34px;
  }
  .help-grid {
    grid-template-columns: minmax(0,1.6fr) minmax(0,1fr);
    gap: 12px;
  }
  .help-diagrams:has(.board-panel:nth-child(2)) {
    grid-template-columns: repeat(2,minmax(0,1fr));
    max-width: none;
  }
  .help-diagrams .board-panel svg {
    max-height: calc(100dvh - 176px);
  }
  .help-instructions ol {
    font-size: 14px;
  }
  .help-grid h4 {
    font-size: 15px;
    margin-bottom: 6px;
  }
  .help-caption {
    font-size: 12px;
  }
}
/* 4.0 — puntos de conexión exactos y pulsos didácticos, solo en la ayuda. */
.help-diagrams .help-required .pin-face,.help-diagrams .help-earth {
  fill: color-mix(in srgb,var(--help-soft) 55%,var(--help-strong));
  stroke: var(--help-dark);
  stroke-width: 2.6;
}
.help-diagrams .board-contact:not(.help-required) {
  opacity: .34;
}
.help-markers {
  pointer-events: none;
}
.help-marker-border {
  fill: #FFFFFF;
  stroke: #34383E;
  stroke-width: 1.4;
}
.help-marker-core {
  fill: #FFD43A;
  stroke: #34383E;
  stroke-width: 1.2;
}
.help-halo {
  fill: none;
  stroke: #FFD43A;
  stroke-width: 2.8;
  opacity: .8;
  transform-box: fill-box;
  transform-origin: center;
  animation: help-contact-pulse 2.2s ease-in-out 2;
}
@keyframes help-contact-pulse {
  0%,100% {
    transform: scale(1);
    opacity: .85;
  }
  50% {
    transform: scale(1.38);
    opacity: .28;
  }
}
@media(prefers-reduced-motion:reduce) {
  .help-halo {
    animation: none;
    opacity: .85;
  }
}
/* Indicadores universales de conexión: contraste doble, sin depender del color. */
.help-marker-border {
  fill: #fff;
  stroke: #34383E;
  stroke-width: 1.8;
}
.help-marker-core {
  fill: #FFD43A;
  stroke: #34383E;
  stroke-width: 1.4;
}
.help-halo {
  stroke: #FFD43A;
  stroke-width: 3;
  opacity: .85;
}
.help-diagrams .help-required .pin-face,.help-diagrams .help-earth {
  fill: #D8DDE2;
  stroke: #34383E;
}
.help-card {
  border-color: #B6BDC4;
}
.help-icon {
  color: #34383E;
}
.help-grid h4,#helptitle {
  font-weight: 700;
}
.help-instructions ol {
  font-weight: 500;
}
.help-card #helpclose {
  border-color: #B6BDC4;
  color: #34383E;
}
.help-card #helpclose:active {
  background: #D3D8DD;
}
/* Acabado común: delimitar el campo sin alterar su tamaño lógico. */
canvas {
  outline: 1px solid #B6BDC4;
  outline-offset: -1px;
}
.help-halo-contrast {
  stroke: #fff;
  stroke-width: 1.2;
  opacity: 1;
}
.help-card button {
  font-family: inherit;
  font-weight: 700;
}
/* Posición y tamaño de las etiquetas de los controles; acciones especiales conservan su anchura. */
#controls button {
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}
/* Acabado: ritmo visual, contraste y área útil */
:root {
  --line: #ADB5BD;
  --ui-size: 16px;
  --radius: 12px;
  --field: #E4E7EA;
  --bg: #F1F2F4;
  --control-active: #E9D5D4;
  --control-border: #006DB5;
}
body {
  font-variant-numeric: tabular-nums;
}
#stage {
  background: transparent;
  border-radius: 14px;
}
canvas {
  border-radius: 14px;
  outline: 1px solid #ADB5BD;
  outline-offset: -1px;
}
#stage:has(.padgrid),#stage:has(.piano),#stage:has(.extra-question),#stage:has(.board-layout) {
  background: transparent;
}
#preview-icon {
  color: var(--ink);
}
#preview-name {
  color: var(--ink);
  line-height: 1.15;
}
#preview-desc {
  min-height: 2.5em;
  display: grid;
  place-items: center;
  max-width: 340px;
  line-height: 1.35;
  margin: 0;
}
#selector-panel {
  gap: 12px;
}
#game-select,#start-game {
  height: 48px;
  border-radius: 12px;
}
#game-select {
  appearance: none;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2334383E' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center/18px;
  padding-inline: 36px;
  text-align: center;
  text-align-last: center;
}
#start-game {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
#start-game:active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
#start-game svg {
  width: 18px;
  height: 18px;
}
#name {
  font-size: var(--ui-size);
  font-weight: 750;
  white-space: nowrap;
  overflow-wrap: normal;
}
button:active,button.pressed {
  background: var(--control-active);
  border-color: var(--control-border);
  color: var(--ink);
}
button:focus:not(:focus-visible) {
  outline: none;
}
button:focus-visible {
  outline-offset: 2px;
}
#controls {
  gap: 7px;
}
#controls button {
  font-size: var(--ui-size);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  min-width: var(--action-height);
}
#controls button.direction-key {
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}
#controls button[data-key=" "] {
  min-width: 82px;
}
#controls button:not([data-key]).wide {
  min-width: 76px;
}
#controls button[data-key="w"],#controls button[data-key="s"] {
  width: var(--action-height);
  padding: 0;
}
#message {
  line-height: 1.25;
  min-height: 0;
  max-width: 100%;
  text-wrap: balance;
}
.padgrid {
  width: min(100%,780px);
  height: min(100%,520px);
  padding: 10px;
  gap: 10px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.padgrid button {
  border-radius: 12px;
  font-size: clamp(36px,9dvh,70px);
  font-weight: 800;
  text-shadow: 0 1px 2px #34383E,0 0 2px #34383E88;
  line-height: 1;
}
.padgrid button.pressed:not(.lit) {
  color: white;
}
.piano {
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: 14px;
  padding: 10px;
  gap: 6px;
}
.piano button {
  font-size: clamp(18px,3vw,30px);
  line-height: 1;
  border-radius: 10px;
  min-width: 0;
}
.piano button.lit {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}
.piano button.pressed,.piano button:active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.queue {
  display: block;
  line-height: calc(var(--action-height) - 4px);
  padding: 0 10px;
  letter-spacing: .12em;
  font-variant-numeric: tabular-nums;
}
.extra-question {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(100%,680px);
  padding: 16px;
  gap: 14px;
  max-height: 100%;
}
.extra-grid {
  gap: 8px;
}
.extra-grid button {
  display: grid;
  grid-template-columns: 28px minmax(0,1fr);
  align-items: center;
  justify-items: center;
  gap: 5px;
  padding: 10px;
  min-height: 64px;
  font-size: var(--ui-size);
  white-space: normal;
  overflow-wrap: normal;
}
.extra-grid button:has(>svg) {
  grid-template-columns: 24px minmax(0,1fr) 26px;
}
.extra-grid button:not(:has(.choice-label)) {
  grid-template-columns: 1fr;
}
.extra-grid button .choice-arrow {
  font-size: 24px;
  line-height: 1;
  justify-self: center;
}
.extra-grid button .choice-label {
  justify-self: center;
  line-height: 1.2;
}
.extra-grid button svg {
  width: 24px;
  height: 24px;
}
.extra-grid button.correct {
  background: #D4E9DB;
  color: #174C31;
  border-color: #36825A;
}
.extra-grid button.wrong {
  background: #F0C3BF;
  color: #702723;
  border-color: var(--red);
}
.extra-prompt.short-feedback {
  font-size: clamp(20px,4dvh,32px);
}
.board-layout {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.board-panel h3 {
  font-size: var(--ui-size);
  line-height: 1.25;
}
.board-contact.pin-active .pin-face {
  fill: #FFD43A;
  stroke: #34383E;
  stroke-width: 3;
}
.board-contact.pin-active .pin-label {
  fill: #34383E;
}
.help-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 12px 32px #18202b26;
}
.help-top {
  margin-bottom: 14px;
}
.help-icon {
  background: var(--field);
  color: var(--ink);
}
.help-grid h4,#helptitle {
  color: var(--ink);
}
.help-caption {
  line-height: 1.4;
}
.help-instructions ol {
  font-size: var(--ui-size);
}
.help-diagrams .board-panel svg {
  overflow: visible;
}
.help-diagrams .help-required .pin-face,.help-diagrams .help-earth {
  fill: #E8C2BF;
  stroke: #006DB5;
  stroke-width: 2.4;
}
.help-marker-border {
  fill: white;
  stroke: #34383E;
  stroke-width: 1.8;
}
.help-marker-core {
  fill: #FFD43A;
  stroke: #34383E;
  stroke-width: 1.3;
}
.help-halo {
  stroke: #FFD43A;
}
.help-halo-contrast {
  stroke: #34383E;
  stroke-width: 1.2;
}
@media(max-width:650px) and (orientation:portrait) {
  #stage {
    border-radius: 12px;
  }
  .padgrid {
    height: min(100%,440px);
  }
  .extra-question {
    padding: 12px;
    gap: 12px;
  }
  .extra-grid button {
    min-height: 62px;
  }
  .help-card {
    padding: 12px;
  }
  .help-grid {
    gap: 14px;
  }
  .help-top {
    margin-bottom: 10px;
  }
}
@media(max-width:420px) and (orientation:portrait) {
  :root {
    --ui-size: 14px;
    --action-height: 40px;
    --gap: 6px;
  }
  main {
    padding: 8px;
  }
  #name {
    white-space: normal;
    overflow-wrap: normal;
    font-size: 14px;
    line-height: 1.15;
  }
  #controls button.direction-key {
    font-size: 23px;
  }
  #controls {
    gap: 5px;
  }
  #controls button[data-key=" "] {
    min-width: 76px;
  }
  #controls button:not([data-key]).wide {
    min-width: 68px;
  }
  .extra-grid button {
    grid-template-columns: 22px minmax(0,1fr);
    padding: 8px 5px;
    gap: 4px;
  }
  .extra-grid button:has(>svg) {
    grid-template-columns: 18px minmax(0,1fr) 19px;
  }
  .extra-grid button svg {
    width: 18px;
    height: 18px;
  }
  .extra-grid button .choice-arrow {
    font-size: 20px;
  }
  .extra-grid button:not(:has(.choice-label)) {
    grid-template-columns: 1fr;
  }
  .choice-label {
    font-size: 14px;
  }
  #preview-desc {
    min-height: 2.5em;
  }
}
@media(max-width:355px) and (orientation:portrait) {
  :root {
    --action-height: 36px;
  }
  body.playing header {
    grid-template-columns: 1fr auto;
  }
  .heading {
    display: contents;
  }
  #home {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
  }
  #name {
    grid-column: 1/-1;
    grid-row: 2;
    justify-self: center;
    white-space: nowrap;
  }
  body.playing #topcenter {
    grid-row: 3;
  }
  #level {
    padding-inline: 6px;
  }
  .extra-grid button:has(>svg) {
    grid-template-columns: 16px minmax(0,1fr) 17px;
  }
  .extra-grid button svg {
    width: 17px;
    height: 17px;
  }
  .choice-label {
    font-size: 13px;
  }
  .board-layout {
    padding: 7px;
  }
}
@media(orientation:landscape) and (max-height:600px) {
  :root {
    --ui-size: 14px;
    --action-height: 36px;
    --gap: 5px;
  }
  #selector-panel {
    gap: 5px;
  }
  #preview-desc {
    min-height: 0;
  }
  #game-select,#start-game {
    height: 36px;
  }
  #controls button.direction-key {
    font-size: 21px;
  }
  .extra-question {
    padding: 8px;
    gap: 5px;
  }
  .extra-grid button {
    min-height: 42px;
    padding: 4px 8px;
  }
  .extra-grid button .choice-arrow {
    font-size: 20px;
  }
  .extra-grid button svg {
    width: 20px;
    height: 20px;
  }
  .extra-grid button:has(>svg) {
    grid-template-columns: 22px minmax(0,1fr) 22px;
  }
  .padgrid,.piano {
    padding: 6px;
    gap: 6px;
  }
  .help-card {
    padding: 10px 12px;
  }
  .help-top {
    margin-bottom: 6px;
  }
  .help-grid {
    gap: 12px;
  }
  .help-instructions ol {
    font-size: 14px;
  }
}
@media(prefers-reduced-motion:reduce) {
  .help-halo {
    animation: none;
  }
}
/* Flechas vectoriales y distribución compacta en vertical. */
.direction-icon {
  display: block;
  width: 24px;
  height: 24px;
  flex: none;
}
.padgrid button .direction-icon {
  width: clamp(38px,9dvh,76px);
  height: clamp(38px,9dvh,76px);
  stroke-width: 2.7;
  filter: drop-shadow(0 1px 1px #34383E99);
}
.piano button .direction-icon {
  width: clamp(19px,3vw,30px);
  height: clamp(19px,3vw,30px);
}
.extra-grid .choice-arrow {
  display: grid;
  place-items: center;
}
.extra-grid .choice-arrow .direction-icon {
  width: 22px;
  height: 22px;
}
.extra-grid button:not(:has(.choice-label)) .choice-arrow .direction-icon {
  width: 30px;
  height: 30px;
}
#play:has(.extra-question) {
  justify-content: center;
}
#stage:has(.extra-question) {
  flex: 0 1 auto;
  overflow: auto;
}
@media(max-width:650px) and (orientation:portrait) {
  #play:has(.canvas-stage) {
    justify-content: center;
  }
  #stage.canvas-stage {
    flex: 0 1 auto;
    aspect-ratio: var(--canvas-aspect);
    width: 100%;
    max-height: calc(100dvh - 150px);
  }
  #play:has(.padgrid),#play:has(.piano) {
    justify-content: center;
  }
  #stage:has(.padgrid),#stage:has(.piano) {
    flex: 0 1 auto;
    height: min(55dvh,440px);
  }
  .piano {
    height: 100%;
    max-height: 260px;
  }
  .extra-grid .choice-arrow .direction-icon {
    width: 20px;
    height: 20px;
  }
}
@media(orientation:landscape) and (max-height:600px) {
  .direction-icon {
    width: 21px;
    height: 21px;
  }
  .extra-grid .choice-arrow .direction-icon {
    width: 20px;
    height: 20px;
  }
  .extra-grid button:not(:has(.choice-label)) .choice-arrow .direction-icon {
    width: 24px;
    height: 24px;
  }
}
/* acabado responsivo, accesibilidad y contraste de contactos */
#preview-icon {
  color: var(--ink);
  transition: color .12s ease;
  flex: none;
}
#start-game {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  touch-action: manipulation;
}
@media(hover:hover) and (pointer:fine) {
  #selector-panel:has(#start-game:hover) #preview-icon {
    color: var(--red);
  }
  #start-game:hover {
    background: var(--red);
    border-color: var(--red);
    color: white;
  }
}
#start-game:active,#start-game:focus-visible {
  background: var(--red);
  border-color: var(--red);
  color: white;
}
#selector-panel:has(#start-game:active) #preview-icon,#selector-panel:has(#start-game:focus-visible) #preview-icon {
  color: var(--red);
}
#game-select {
  font-size: max(16px,var(--ui-size));
  touch-action: manipulation;
}
header button,#helpclose {
  touch-action: manipulation;
}
.board-layout .connection-hole {
  fill: #FFFFFF;
  stroke: #9AA3AC;
  stroke-width: 1.2;
}
.board-layout .pin-active .connection-hole {
  fill: #FFD43A;
  stroke: #34383E;
  stroke-width: 1.4;
}
.help-marker-core {
  fill: #FFD43A;
  stroke: #34383E;
  stroke-width: 1.3;
}
.help-marker-border {
  fill: #fff;
  stroke: #34383E;
  stroke-width: 1.4;
}
.help-halo {
  stroke: #FFD43A;
  stroke-width: 3.2;
}
.help-halo-contrast {
  stroke: #34383E;
  stroke-width: 1.1;
}
.help-diagrams .help-required .pin-face,.help-diagrams .help-earth {
  fill: #F6E8AE;
  stroke: #34383E;
  stroke-width: 2;
}
.help-card {
  overscroll-behavior: contain;
}
.help-card #helpclose {
  touch-action: manipulation;
}
#controls button {
  font-weight: 700;
  line-height: 1;
  align-items: center;
  justify-content: center;
  text-align: center;
}
#controls button:has(.direction-icon) {
  gap: 0;
}
#controls button[data-key=" "] {
  white-space: nowrap;
}
#message {
  font-weight: 700;
  overflow-wrap: anywhere;
}
#name {
  overflow: hidden;
  text-overflow: ellipsis;
}
@media(max-width:650px) and (orientation:portrait) {
  main {
    padding: max(8px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));
  }
  #play {
    gap: 10px;
  }
  #controls {
    gap: 6px;
  }
  #controls button {
    min-height: 44px;
    height: 44px;
  }
  #stage.canvas-stage {
    max-height: 100%;
  }
  #selector-panel {
    padding: 10px 0;
    gap: 12px;
  }
  .extra-question {
    max-height: 100%;
  }
  .extra-grid button {
    min-height: 60px;
  }
  .help-grid {
    gap: 12px;
  }
  .help-caption {
    font-size: 14px;
  }
  .help-instructions ol {
    font-size: 15px;
  }
}
@media(max-width:420px) and (orientation:portrait) {
  #controls {
    gap: 5px;
  }
  #controls button {
    padding-inline: 8px;
  }
  #controls button[data-key=" "] {
    min-width: 72px;
  }
  #controls button:not([data-key]).wide {
    min-width: 64px;
  }
  .extra-grid button {
    min-height: 58px;
  }
  .help-card {
    padding: 12px;
  }
  .help-top {
    gap: 9px;
  }
}
@media(orientation:landscape) and (max-height:600px) {
  main {
    padding: max(5px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) max(5px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));
  }
  #play {
    gap: 5px;
  }
  #controls button {
    min-height: 42px;
    height: 42px;
    min-width: 42px;
  }
  #controls button[data-key^="Arrow"],#controls button:not(.wide):not([data-key]),#controls button[data-key="w"],#controls button[data-key="s"] {
    width: 42px;
  }
  #game-select,#start-game {
    min-height: 40px;
    height: 40px;
  }
  #selector-panel {
    gap: 6px;
    padding: 2px 0;
  }
  .help-card #helpclose {
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    height: 40px;
  }
  .extra-grid button {
    min-height: 44px;
  }
  .help-caption {
    line-height: 1.35;
  }
}
@media(orientation:landscape) and (max-height:320px) {
  #selector-panel {
    gap: 4px;
  }
  #preview-icon {
    width: 48px;
    height: 48px;
  }
  #preview-name {
    font-size: 20px;
  }
  #preview-desc {
    font-size: 13px;
  }
  #game-select,#start-game {
    height: 36px;
    min-height: 36px;
  }
  #controls button {
    height: 38px;
    min-height: 38px;
    min-width: 38px;
  }
  .extra-question {
    gap: 4px;
    padding: 5px;
  }
  .extra-grid button {
    min-height: 39px;
  }
  .extra-rule {
    font-size: 13px;
  }
  .extra-prompt {
    font-size: 22px;
  }
}
@media(prefers-reduced-motion:reduce) {
  #preview-icon {
    transition: none;
  }
  .help-halo {
    animation: none;
  }
}
/* Placa: agrupación compacta y equilibrada en pantallas altas. */
@media (orientation:portrait) and (min-height:660px) {
  .board-layout {
    height: auto;
    max-height: 100%;
    grid-template-rows: auto auto;
    gap: 18px;
    padding: 14px;
  }
  .board-layout .board-panel {
    height: auto;
    gap: 6px;
    max-width: 500px;
  }
  .board-layout .board-panel svg {
    max-height: min(34dvh,260px);
  }
}
/* Área de juego estable y panel de controles permanente. */
body.playing main {
  max-width: none;
}
body.playing #play {
  display: flex;
  flex-direction: column;
  justify-content: stretch;
  gap: var(--gap);
  min-height: 0;
}
body.playing #stage,body.playing #stage.canvas-stage {
  flex: 1 1 0;
  align-self: stretch;
  width: 100%;
  height: auto;
  max-height: none;
  min-height: 0;
  aspect-ratio: auto;
}
body.playing #stage:has(.extra-question) {
  overflow: auto;
}
/* Controles centrados y estado fijo en la cabecera. */
#game-footer {
  display: grid;
  grid-template-columns: minmax(0,1fr);
  grid-template-areas: 'queue' 'controls';
  gap: 4px;
  align-items: center;
  justify-items: center;
  flex: none;
  min-width: 0;
  width: 100%;
  margin-inline: auto;
}
#command-slot {
  grid-area: queue;
  min-width: 0;
  width: min(100%,760px);
  display: flex;
  justify-content: center;
}
#command-slot:empty {
  display: none;
}
#command-slot .queue {
  width: 100%;
  max-width: 760px;
}
#game-footer #controls {
  grid-area: controls;
  justify-content: center;
  align-items: center;
  min-width: 0;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
  margin: 0 auto;
}
#game-footer #controls:empty {
  display: none;
}
#game-footer:not(:has(#controls button)):not(:has(#command-slot .queue)):not(:has(#snake-score:not([hidden]))) {
  display: none;
}
/* Two equal wings for points and controls, with a common central axis. */
body:is([data-game="8"],[data-game="14"]) #game-footer {
  width: min(100%,760px);
  grid-template-columns: repeat(2,minmax(0,1fr));
  grid-template-areas: 'controls score';
  gap: 6px;
  min-height: 44px;
}
body:is([data-game="8"],[data-game="14"]) #game-footer #controls {
  flex-wrap: nowrap;
  justify-content: center;
  gap: 4px;
}
#snake-score:not([hidden]) {
  grid-area: score;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  justify-self: center;
  font-weight: 700;
  font-size: var(--ui-size);
  white-space: nowrap;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  height: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #C3C9CF;
  border-radius: 10px;
  background: #fff;
  min-width: 0;
  width: max-content;
  max-width: 100%;
}
body[data-game="5"] #game-footer #controls {
  display: grid;
  grid-template-columns: repeat(2,44px) minmax(80px,100px) repeat(2,44px);
  width: max-content;
  max-width: 100%;
  justify-content: center;
  gap: 6px;
}
body[data-game="5"] #game-footer #controls button {
  width: 100%;
  min-width: 0;
  padding: 0 4px;
}
body[data-game="5"] #game-footer #controls button[data-key=" "] {
  min-width: 0;
}
body[data-game="4"] #game-footer #controls {
  width: min(100%,760px);
}
@media (orientation:portrait) and (max-width:650px) {
  body[data-game="4"] #game-footer #controls {
    display: grid;
    grid-template-columns: repeat(8,minmax(0,1fr));
    width: min(100%,460px);
    gap: 5px;
  }
  body[data-game="4"] #game-footer #controls button {
    grid-column: span 2;
    width: 100%;
    min-width: 0;
    padding: 0 4px;
  }
  body[data-game="4"] #game-footer #controls button[data-key=" "] {
    grid-column: span 4;
  }
  body[data-game="4"] #game-footer #controls button:not([data-key]) {
    font-size: 14px;
  }
  body[data-game="8"] #game-footer #controls {
    gap: 3px;
  }
  body[data-game="8"] #controls button[data-key^="Arrow"] {
    min-width: 38px;
    width: 38px;
    height: 44px;
    padding: 0;
  }
  body[data-game="8"] #snake-score {
    font-size: 14px;
  }
  body[data-game="5"] #game-footer #controls {
    grid-template-columns: repeat(2,minmax(0,44px)) minmax(62px,90px) repeat(2,minmax(0,44px));
    width: min(100%,290px);
    gap: 5px;
  }
}
@media (orientation:portrait) and (max-width:370px) {
  body[data-game="8"] #game-footer #controls {
    display: grid;
    grid-template-columns: repeat(2,44px);
    gap: 4px;
  }
  body[data-game="8"] #controls button[data-key^="Arrow"] {
    width: 44px;
    min-width: 44px;
  }
}
/* Lateral controls for wide landscape playfields. */
@media (orientation:landscape) and (max-height:600px) and (min-aspect-ratio:3/2) {
  body:is([data-game="4"],[data-game="2"]) #play {
    display: grid;
    grid-template-columns: minmax(0,1fr) clamp(160px,24vw,216px);
    grid-template-rows: minmax(0,1fr);
    gap: 10px;
  }
  body:is([data-game="4"],[data-game="2"]) #game-footer {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 0;
  }
  body[data-game="4"] #game-footer #controls {
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 4px;
  }
  body[data-game="4"] #game-footer #controls button {
    min-width: 0;
    width: 100%;
    padding: 0 3px;
  }
  body[data-game="4"] #game-footer #controls button[data-key=" "] {
    grid-column: span 4;
  }
  body[data-game="4"] #game-footer #controls button:not([data-key]) {
    grid-column: span 2;
  }
}
@media (orientation:landscape) and (max-height:600px) and (min-aspect-ratio:2/1) {
  body[data-game="14"] #play {
    display: grid;
    grid-template-columns: minmax(0,1fr) clamp(160px,24vw,216px);
    grid-template-rows: minmax(0,1fr);
    gap: 10px;
  }
  body[data-game="14"] #game-footer {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 0;
  }
  body[data-game="14"] #snake-score {
    order: -1;
  }
  body[data-game="5"] #topcenter {
    display: none;
  }
}
@media (orientation:landscape) and (max-height:600px) {
  #game-footer {
    gap: 3px;
  }
}
/* Las preguntas conservan también su geometría cuando cambia la consigna. */
.extra-question {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 2.5em minmax(70px,auto) auto;
  align-content: center;
  justify-items: center;
  gap: 12px;
  width: min(100%,760px);
}
.extra-rule,.extra-rule:empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5em;
  max-height: 2.5em;
  width: 100%;
}
.extra-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 90px;
  min-height: 90px;
  max-height: 90px;
  width: 100%;
}
@media(orientation:landscape) and (max-height:600px) {
  .extra-question {
    width: 100%;
    max-width: 980px;
    grid-template-columns: minmax(0, .8fr) minmax(0,1.2fr);
    grid-template-rows: 2.5em minmax(0,1fr);
    gap: 8px 16px;
    padding: 12px;
    min-height: min(100%,150px);
  }
  .extra-rule {
    grid-column: 1;
    grid-row: 1;
  }
  .extra-prompt {
    grid-column: 1;
    grid-row: 2;
    height: 70px;
    min-height: 70px;
    max-height: 70px;
  }
  .extra-grid {
    grid-column: 2;
    grid-row: 1/3;
    align-self: stretch;
    grid-template-rows: repeat(2,minmax(0,1fr));
  }
  .extra-grid button {
    min-height: 48px;
  }
}
@media(orientation:landscape) and (max-height:320px) {
  .extra-question {
    padding: 8px;
    gap: 4px 10px;
  }
  .extra-grid button {
    min-height: 40px;
  }
  .extra-prompt {
    height: 60px;
    min-height: 60px;
    max-height: 60px;
  }
}
@media(orientation:portrait) and (max-height:550px) {
  .extra-question {
    padding: 8px;
    gap: 6px;
    grid-template-rows: 2.5em 60px auto;
  }
  .extra-prompt {
    height: 60px;
    min-height: 60px;
    max-height: 60px;
  }
  .extra-grid button {
    min-height: 48px;
  }
}
/* Indicadores estables y cuenta atrás visual. */
.reflex-ring {
  position: relative;
  height: 100%;
  aspect-ratio: 1;
  max-width: 100%;
  display: grid;
  place-items: center;
  flex: none;
  color: #34383E;
}
.reflex-ring>svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke-width: 6;
  overflow: visible;
}
.reflex-track {
  stroke: #C3C9CF;
}
.reflex-progress {
  stroke: #006DB5;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
}
.reflex-symbol {
  display: grid;
  place-items: center;
  font-size: clamp(22px,6dvh,38px);
  line-height: 1;
  width: 54%;
  height: 54%;
}
.reflex-symbol .direction-icon {
  width: 100%;
  height: 100%;
  color: #006DB5;
}
/* Más superficie útil para la señal de Reflejos, sin cambiar al pasar de espera a respuesta. */
body[data-game="7"] .reflex-ring {
  max-height: 150px;
}
@media (orientation:landscape) and (max-height:600px) {
  body[data-game="7"] .extra-question {
    height: min(100%,270px);
    grid-template-rows: 2.5em minmax(0,1fr);
    align-content: stretch;
  }
  body[data-game="7"] .extra-prompt {
    height: 100%;
    min-height: 0;
    max-height: none;
  }
  body[data-game="7"] .extra-grid button {
    min-height: 0;
  }
}
@media (orientation:portrait) and (min-height:551px) {
  body[data-game="7"] .extra-question {
    grid-template-rows: 2.5em 125px auto;
  }
  body[data-game="7"] .extra-prompt {
    height: 125px;
    min-height: 125px;
    max-height: 125px;
  }
}
body[data-game="16"] #controls button[data-key=" "] {
  width: 132px;
  min-width: 132px;
}
/* Group each field and its controls on the same vertical axis on tall screens. */
@media (orientation:portrait) {
  body.playing:is([data-game="0"],[data-game="5"],[data-game="9"],[data-game="10"],[data-game="11"],[data-game="13"],[data-game="16"]) #play {
    justify-content: center;
    gap: 8px;
  }
  body.playing:is([data-game="0"],[data-game="5"],[data-game="9"],[data-game="10"],[data-game="11"],[data-game="13"],[data-game="16"]) #stage.canvas-stage {
    flex: 0 1 auto;
    aspect-ratio: var(--canvas-aspect);
    height: auto;
    max-height: 100%;
    width: 100%;
    align-self: center;
  }
  body.playing[data-game="16"] #stage.canvas-stage {
    max-width: 520px;
  }
  body.playing:is([data-game="1"],[data-game="3"],[data-game="7"],[data-game="12"]) #play {
    justify-content: center;
    gap: 8px;
  }
  body.playing[data-game="1"] #stage {
    flex: 0 1 auto;
    height: min(62dvh,520px);
  }
  body.playing[data-game="3"] #stage {
    flex: 0 1 auto;
    height: min(43dvh,320px);
  }
  body.playing:is([data-game="7"],[data-game="12"]) #stage {
    flex: 0 1 auto;
    min-height: 0;
  }
}
/* Header status: fixed geometry, real horizontal centering and compact fallback. */
body.playing header {
  grid-template-columns: minmax(0,1fr) auto;
  grid-template-rows: none;
  grid-auto-rows: auto;
  column-gap: var(--gap);
  row-gap: 0;
}
body.playing #message {
  grid-column: 1/-1;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  width: 100%;
  height: 28px;
  min-height: 28px;
  max-height: 28px;
  min-width: 0;
  max-width: 100%;
  margin: 3px 0 0;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: var(--ui-size);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
  overflow: hidden;
  text-wrap: balance;
  font-variant-numeric: tabular-nums;
}
body.playing #message:empty {
  visibility: hidden;
}
body.playing #topcenter {
  grid-row: 3;
  grid-column: 1/-1;
  margin-top: 4px;
}
@media (max-width:355px) and (orientation:portrait) {
  body.playing #message {
    grid-row: 3;
  }
  body.playing #topcenter {
    grid-row: 4;
  }
  body.playing #name {
    margin-top: 4px;
    white-space: nowrap;
  }
}
/* Equal wings keep the status centered on the screen, not just between buttons. */
@media (min-width:720px) {
  body.playing header {
    grid-template-columns: minmax(0,1fr) minmax(0,min(480px,calc(100% - 480px))) minmax(0,1fr);
    column-gap: var(--gap);
  }
  body.playing .heading {
    grid-column: 1;
    grid-row: 1;
  }
  body.playing .actions {
    grid-column: 3;
    grid-row: 1;
  }
  body.playing #message {
    grid-row: 1;
    grid-column: 2;
    height: var(--action-height);
    min-height: var(--action-height);
    max-height: var(--action-height);
    margin: 0;
  }
  body.playing #topcenter {
    grid-row: 2;
    grid-column: 1/-1;
  }
}
@media (orientation:landscape) and (max-height:600px) and (min-width:640px) {
  body.playing header {
    grid-template-columns: minmax(0,1fr) minmax(0,min(480px,calc(100% - 420px))) minmax(0,1fr);
  }
  body.playing .heading {
    grid-column: 1;
    grid-row: 1;
  }
  body.playing .actions {
    grid-column: 3;
    grid-row: 1;
  }
  body.playing #message {
    grid-row: 1;
    grid-column: 2;
    height: var(--action-height);
    min-height: var(--action-height);
    max-height: var(--action-height);
    margin: 0;
    font-size: 14px;
  }
  body.playing #topcenter {
    grid-row: 2;
    grid-column: 1/-1;
  }
}
/* The logo gets its own full-width line on narrow phones, without collisions. */
body:not(.playing) #logo {
  font-size: clamp(34px,6.6vw,64px);
  letter-spacing: -.045em;
  gap: .12em;
}
body:not(.playing) #logo strong {
  padding: .055em .22em;
  border-radius: .19em;
}
@media (orientation:portrait) and (max-width:520px) {
  body:not(.playing) header {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    row-gap: 8px;
  }
  body:not(.playing) header .heading {
    display: flex;
    grid-row: 1;
    grid-column: 1;
    justify-self: start;
  }
  body:not(.playing) header .actions {
    grid-row: 1;
    grid-column: 2;
    justify-self: end;
  }
  body:not(.playing) #logo {
    grid-row: 2;
    grid-column: 1/-1;
    justify-self: center;
    font-size: clamp(38px,12vw,58px);
  }
}
@media (orientation:landscape) and (max-height:600px) {
  body:not(.playing) #logo {
    font-size: clamp(32px,6.2vw,48px);
  }
}
@media (orientation:landscape) and (max-height:320px) {
  body:not(.playing) #logo {
    font-size: clamp(30px,6vw,40px);
  }
}
/* Acabado de publicación */
@media (orientation:portrait) and (max-width:355px) {
  body.playing .heading {
    display: contents;
  }
  body.playing #home {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
  }
  body.playing #name {
    grid-column: 1/-1;
    grid-row: 2;
    text-align: center;
    justify-self: center;
    max-width: 100%;
    margin: 2px 0 0;
  }
  body.playing .actions {
    grid-column: 2;
    grid-row: 1;
  }
}
#snake-score:not([hidden]) {
  min-width: 110px;
}
body[data-game="8"] #game-footer #controls,body[data-game="14"] #game-footer #controls {
  justify-self: center;
}
#game-footer #controls button {
  font-variant-numeric: tabular-nums;
}
@media (orientation:landscape) and (max-height:360px) {
  body.playing #topcenter {
    margin-top: 2px;
  }
  body.playing #message {
    font-size: 13px;
  }
}
/* Cabecera anclada: las dos esquinas no cambian al entrar o salir. */
body {
  align-items: flex-start;
}
body:not(.playing) main {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  min-height: 100dvh;
}
header {
  align-items: start;
}
header .heading,header .actions {
  align-self: start;
  align-items: flex-start;
}
#test {
  width: var(--action-height);
  height: var(--action-height);
  min-width: var(--action-height);
  padding: 0;
  flex: none;
}
#test small {
  display: none;
}
body:not(.playing) header .heading {
  display: flex;
  grid-row: 1;
  grid-column: 1;
  justify-self: start;
}
body:not(.playing) header .actions {
  grid-row: 1;
  justify-self: end;
}
body:not(.playing) #logo {
  align-self: center;
}
/* Explicit grid slots keep the logo centered and sound at the far right. */
body:not(.playing) header .actions {
  grid-column: 3;
}
body:not(.playing) #logo {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
}
@media (orientation:portrait) and (max-width:520px) {
  body:not(.playing) header .actions {
    grid-column: 2;
  }
  body:not(.playing) #logo {
    grid-column: 1/-1;
    grid-row: 2;
  }
}
/* Alineación de títulos y cabecera de escritorio. */
body.playing .heading {
  display: flex;
  align-items: center;
  align-self: start;
  min-height: var(--action-height);
}
body.playing #name {
  margin: 0;
  text-align: left;
  align-self: center;
  line-height: 1.15;
  white-space: normal;
  overflow-wrap: anywhere;
  overflow: visible;
  text-overflow: clip;
  min-width: 0;
}
header .actions {
  align-items: center;
}
@media (orientation:portrait) and (max-width:355px) {
  body.playing .heading {
    grid-row: 1;
    grid-column: 1;
    gap: 4px;
  }
  body.playing #name {
    font-size: clamp(11px,3.5vw,13px);
    margin: 0;
  }
  body.playing #message {
    grid-row: 2;
  }
  body.playing #topcenter {
    grid-row: 3;
  }
}
@media (min-width:1100px) and (min-height:650px) {
  header {
    width: min(100%,1040px);
    align-self: center;
    --action-height: 52px;
    --ui-size: 18px;
  }
  header .heading,header .actions {
    gap: 9px;
  }
  header #home svg,header #test svg,header #restart svg,header #sound svg {
    width: 26px;
    height: 26px;
  }
  header #helpbtn {
    font-size: 26px;
  }
  body.playing #name {
    font-size: 19px;
  }
  body.playing header {
    grid-template-columns: minmax(0,1fr) minmax(0,400px) minmax(0,1fr);
  }
}
@media (orientation:portrait) and (max-width:375px) {
  body.playing #name {
    font-size: clamp(11px,3.35vw,13px);
    white-space: nowrap;
    overflow-wrap: normal;
  }
  body.playing #level {
    font-size: 12px;
    padding-inline: 5px;
  }
}
/* Experiencias y juegos ampliados: mismo sistema visual. */
.nx-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  gap: 5px;
  padding: 4px;
  background: #E4E7EA;
  border: 1px solid #C3C9CF;
  border-radius: 12px;
}
.nx-tabs button {
  min-height: 40px;
  padding: 6px 8px;
  border-color: transparent;
  background: transparent;
}
.nx-tabs button[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
#preview-name {
  text-align: center;
  line-height: 1.15;
  max-width: 100%;
  overflow-wrap: break-word;
}
#preview-desc {
  min-height: 2.5em;
  display: grid;
  place-items: center;
}
.nx-panel {
  width: min(100%,760px);
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  align-items: center;
  gap: 12px;
  padding: 14px;
  overflow: auto;
  overscroll-behavior: contain;
}
.nx-title {
  font-size: clamp(16px,3vw,23px);
  text-align: center;
  margin: 0;
  line-height: 1.15;
}
.nx-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}
.nx-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 34px;
  padding: 6px 11px;
  background: #fff;
  border: 1px solid #C3C9CF;
  border-radius: 10px;
  font-size: var(--ui-size);
  font-weight: 700;
  line-height: 1.15;
  max-width: 100%;
}
.nx-big {
  font-weight: 800;
  font-size: clamp(44px,12dvh,100px);
  line-height: 1.1;
  color: var(--red);
}
.nx-diagram {
  width: min(100%,560px);
  min-height: 0;
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nx-diagram svg {
  display: block;
  width: 100%;
  max-height: min(34dvh,260px);
}
.nx-diagram.active .nx-bulb {
  fill: #FFD43A;
}
.nx-diagram.active .nx-wire {
  stroke: #FFD43A;
  stroke-dasharray: none;
}
.nx-bits {
  display: flex;
  justify-content: center;
  gap: 7px;
  max-width: 100%;
  width: min(100%,500px);
}
.nx-bit,.nx-bits button {
  display: grid;
  place-items: center;
  flex: 1;
  min-width: 0;
  min-height: 52px;
  padding: 5px;
  background: #fff;
  border: 1px solid #B6BDC4;
  border-radius: 10px;
  font-size: clamp(16px,3vw,26px);
  font-weight: 750;
}
.nx-history {
  width: min(100%,560px);
  min-height: 42px;
  height: min(27dvh,200px);
  overflow: auto;
  background: #F1F2F4;
  border: 1px solid #C3C9CF;
  border-radius: 10px;
  padding: 6px;
  touch-action: pan-y;
}
.nx-history-line {
  font-size: var(--ui-size);
  padding: 5px;
  text-align: center;
  border-bottom: 1px solid #D3D8DD;
  font-weight: 650;
}
.nx-moles {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  grid-template-rows: repeat(2,minmax(0,1fr));
  gap: 8px;
  width: min(100%,440px);
  height: min(68%,390px);
  min-height: 80px;
}
.nx-moles button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  min-width: 0;
  padding: 5px;
  overflow: hidden;
}
.nx-moles .direction-icon {
  height: 22px;
  width: 22px;
  flex: none;
}
.target {
  border-color: var(--red)!important;
}
.nx-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}
.nx-flow .nx-value {
  flex: 1;
  min-width: 75px;
}
.nx-truth {
  display: grid;
  gap: 3px;
  max-width: 360px;
  width: 100%;
  font-variant-numeric: tabular-nums;
}
.nx-truth-line {
  background: #F1F2F4;
  border-radius: 6px;
  padding: 3px 8px;
  text-align: center;
  font-size: var(--ui-size);
  font-weight: 650;
  white-space: pre;
}
.nx-truth-line.selected {
  background: #D2E5D7;
  border: 1px solid #5EAA77;
}
.nx-panel .on {
  background: var(--red);
  border-color: var(--red);
  color: white;
}
.nx-color {
  width: min(100%,460px);
  min-height: 70px;
  height: min(38dvh,260px);
  border: 2px solid #34383E;
  border-radius: 12px;
}
.nx-seq {
  display: grid;
  grid-template-columns: minmax(45px,auto) repeat(8,minmax(0,1fr));
  gap: 4px;
  width: 100%;
  align-items: center;
}
.nx-seq button {
  min-width: 0;
  width: 100%;
  min-height: clamp(23px,6dvh,50px);
  padding: 0;
  border-radius: 5px;
}
.nx-seq button.selected {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}
.nx-seq button.beat {
  box-shadow: inset 0 0 0 3px #E6B94E;
}
.nx-track {
  font-size: clamp(11px,2vw,15px);
  font-weight: 700;
  text-align: right;
  padding-right: 3px;
}
body.playing:is([data-game="17"],[data-game="20"],[data-game="28"]) #game-footer:has(#snake-score:not([hidden])) {
  grid-template-columns: repeat(2,minmax(0,1fr));
  grid-template-areas: 'controls score';
  width: min(100%,760px);
}
body.playing:is([data-game="17"],[data-game="20"],[data-game="28"]) #game-footer {
  width: min(100%,760px);
}
body.playing[data-game="17"] #stage.canvas-stage {
  background: transparent;
}
body.playing #controls button.nx-labelled {
  width: auto;
  min-width: 44px;
  padding: 0 10px;
  font-size: var(--ui-size);
}
body.playing #controls button.wide {
  max-width: 100%;
  white-space: nowrap;
}
body.playing:is([data-game="17"],[data-game="28"]) #game-footer:has(#snake-score:not([hidden])) {
  grid-template-columns: 1fr;
  grid-template-areas: 'score' 'controls';
}
body.playing:is([data-game="26"],[data-game="27"],[data-game="28"],[data-game="29"]) #controls button {
  font-size: 14px;
}
/* More room for the help button next to Home, preserve their edge positions. */
@media (orientation:portrait) and (max-width:520px) {
  body.playing .heading {
    gap: 4px;
  }
  body.playing #name {
    white-space: normal;
    overflow-wrap: normal;
    font-size: clamp(12px,3.3vw,15px);
  }
  body.playing header {
    grid-template-columns: minmax(0,1fr) auto;
  }
  body.playing #level {
    padding-inline: 6px;
  }
}
@media (orientation:portrait) and (max-width:390px) {
  body.playing #name {
    font-size: 12px;
    line-height: 1.1;
  }
  body.playing .heading {
    flex-wrap: nowrap;
  }
  body.playing #level {
    font-size: 12px;
  }
  body.playing header {
    --action-height: 36px;
  }
}
@media (orientation:portrait) and (max-width:355px) {
  body.playing #name {
    overflow-wrap: anywhere;
    white-space: normal;
    font-size: 11px;
  }
}
@media (orientation:landscape) and (max-height:600px) {
  .nx-panel {
    gap: 6px;
    padding: 6px;
  }
  .nx-tabs button {
    min-height: 32px;
  }
  .nx-tabs {
    padding: 3px;
  }
  #preview-desc {
    min-height: 0;
  }
  body:not(.playing) #selector-panel {
    gap: 6px;
    padding: 0;
  }
  body:not(.playing) #preview-icon {
    width: clamp(40px,14dvh,80px);
    height: clamp(40px,14dvh,80px);
  }
  .nx-diagram svg {
    max-height: 28dvh;
  }
  .nx-value {
    min-height: 28px;
    padding: 4px 8px;
  }
  .nx-truth-line {
    padding: 2px 6px;
  }
  .nx-moles {
    height: 65%;
  }
  .nx-history {
    height: min(27dvh,130px);
  }
  body.playing #controls button.nx-labelled {
    min-width: 38px;
    padding: 0 8px;
  }
}
@media (orientation:landscape) and (max-height:340px) {
  body:not(.playing) #preview-icon {
    width: 42px;
    height: 42px;
  }
  body:not(.playing) #preview-name {
    font-size: 19px;
  }
  body:not(.playing) #preview-desc {
    font-size: 12px;
  }
  .nx-tabs button {
    min-height: 28px;
    padding: 3px;
  }
  .nx-panel {
    gap: 4px;
  }
  .nx-bits button,.nx-bit {
    min-height: 38px;
  }
  .nx-history {
    min-height: 25px;
  }
  .nx-truth-line {
    font-size: 12px;
  }
}
/* Ajuste de microalineación: controles de texto no heredan ancho de las teclas W/S. */
body.playing #controls button.nx-labelled {
  width: max-content;
  max-width: 100%;
  padding-inline: 10px;
  font-size: var(--ui-size);
  min-width: 44px;
  flex: 0 0 auto;
}
.nx-flow .nx-gate {
  background: var(--ink);
  color: #fff;
  min-height: 60px;
  border-color: var(--ink);
  position: relative;
}
.nx-flow .nx-gate:before,.nx-flow .nx-gate:after {
  content: '';
  position: absolute;
  top: 50%;
  width: 7px;
  height: 2px;
  background: var(--ink);
}
.nx-flow .nx-gate:before {
  left: -7px;
}
.nx-flow .nx-gate:after {
  right: -7px;
}
.nx-flow .nx-value {
  min-height: 44px;
}
body[data-game="28"] #game-footer:has(#snake-score:not([hidden])) {
  grid-template-columns: 1fr;
  grid-template-areas: 'score' 'controls';
}
@media (orientation:landscape) and (max-height:600px) {
  body.playing:is([data-game="17"],[data-game="20"]) #play {
    display: grid;
    grid-template-columns: minmax(0,1fr) clamp(170px,30vw,240px);
    grid-template-rows: minmax(0,1fr);
    gap: 8px;
  }
  body.playing:is([data-game="17"],[data-game="20"]) #game-footer:has(#snake-score:not([hidden])) {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    width: 100%;
  }
  body.playing[data-game="17"] #game-footer #controls {
    display: grid;
    grid-template-columns: repeat(2,44px);
    justify-content: center;
    width: 100%;
  }
  body.playing[data-game="17"] #controls button[data-key=" "] {
    grid-column: span 2;
    width: 100%;
  }
  body.playing #controls button.nx-labelled {
    min-width: 38px;
    padding-inline: 8px;
    font-size: 13px;
  }
  body.playing[data-game="28"] #game-footer:has(#snake-score:not([hidden])) {
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-areas: 'controls score';
    width: 100%;
    gap: 6px;
  }
  body.playing[data-game="28"] #game-footer #controls {
    gap: 4px;
  }
  .nx-flow .nx-gate {
    min-height: 46px;
  }
  .nx-flow .nx-value {
    min-height: 35px;
  }
}
@media (orientation:landscape) and (max-height:340px) {
  body.playing[data-game="28"] #game-footer:has(#snake-score:not([hidden])) {
    grid-template-columns: 1fr;
    grid-template-areas: 'score' 'controls';
    gap: 3px;
  }
  body.playing[data-game="28"] #snake-score {
    height: 28px;
    min-height: 28px;
  }
  body.playing[data-game="28"] #game-footer #controls button {
    height: 34px;
    min-height: 34px;
  }
  body.playing[data-game="28"] #stage.canvas-stage {
    min-height: 0;
  }
}
@media (orientation:portrait) and (max-width:420px) {
  body.playing #controls button.nx-labelled {
    padding-inline: 8px;
    font-size: 13px;
  }
  .nx-bits button {
    font-size: 15px;
  }
  .nx-flow .nx-value {
    padding-inline: 5px;
    font-size: 12px;
  }
}
/* Preserve identical header button geometry between menu and activities. */
@media (orientation:portrait) and (max-width:390px) {
  body:not(.playing) header {
    --action-height: 36px;
  }
}
/* Compact home at very short portrait dimensions, keeping every element visible. */
@media (orientation:portrait) and (max-height:580px) {
  body:not(.playing) main {
    gap: 5px;
  }
  body:not(.playing) header {
    row-gap: 4px;
  }
  body:not(.playing) #logo {
    font-size: clamp(30px,10vw,44px);
  }
  body:not(.playing) #selector-panel {
    gap: 5px;
    padding: 2px 0;
  }
  body:not(.playing) #preview-icon {
    width: clamp(46px,13dvh,72px);
    height: clamp(46px,13dvh,72px);
  }
  body:not(.playing) #preview-name {
    font-size: clamp(20px,5.5vw,25px);
  }
  body:not(.playing) #preview-desc {
    min-height: 0;
    font-size: 13px;
    margin: 0;
    line-height: 1.2;
  }
  body:not(.playing) .nx-tabs button {
    min-height: 34px;
    padding: 4px 6px;
  }
  body:not(.playing) #game-select,body:not(.playing) #start-game {
    min-height: 40px;
    height: 40px;
  }
  body:not(.playing) footer {
    padding-top: 2px;
    font-size: 10px;
  }
}
/* En pantallas altas, el experimento y sus controles forman un conjunto compacto. */
@media (orientation:portrait) and (min-height:650px) {
  body.playing:is([data-game="21"],[data-game="22"],[data-game="23"],[data-game="24"],[data-game="25"],[data-game="27"],[data-game="30"]) #play {
    justify-content: center;
    gap: 10px;
  }
  body.playing:is([data-game="21"],[data-game="22"],[data-game="23"],[data-game="24"],[data-game="25"],[data-game="27"],[data-game="30"]) #stage {
    flex: 0 1 auto;
    height: auto;
    max-height: 100%;
  }
  body.playing:is([data-game="21"],[data-game="22"],[data-game="23"],[data-game="24"],[data-game="25"],[data-game="27"],[data-game="30"]) .nx-panel {
    height: auto;
    max-height: 100%;
    padding-block: 10px;
  }
  body[data-game="19"] .nx-moles {
    height: min(40dvh,390px);
  }
  body.playing:is([data-game="26"],[data-game="28"],[data-game="29"]) #play {
    justify-content: center;
    gap: 8px;
  }
  body.playing:is([data-game="26"],[data-game="28"],[data-game="29"]) #stage.canvas-stage {
    flex: 0 1 auto;
    aspect-ratio: var(--canvas-aspect);
    height: auto;
    max-height: 100%;
    width: 100%;
    align-self: center;
  }
}
/* experiencia frontal, teclas legibles y filas de controles iguales. */
body.playing #controls.nx-uniform {
  display: grid;
  grid-template-columns: repeat(120,minmax(0,1fr));
  gap: 4px 0;
  width: min(100%,760px);
  max-width: 100%;
  margin-inline: auto;
  align-items: stretch;
}
body.playing #controls.nx-uniform button {
  grid-column: var(--nx-wide-start)/span var(--nx-wide-span);
  grid-row: var(--nx-wide-row);
  width: auto!important;
  min-width: 0!important;
  max-width: none!important;
  margin-inline: 3px;
  padding: 2px 3px!important;
  height: 44px;
  min-height: 44px;
  line-height: 1.05;
  font-size: 14px;
  justify-content: center;
  align-items: center;
}
body.playing #controls.nx-uniform button.nx-labelled {
  display: flex;
  flex-direction: column;
  gap: 2px;
  white-space: normal;
}
.nx-key {
  font-size: 10px;
  font-weight: 650;
  color: #626A73;
  line-height: 1;
  letter-spacing: .025em;
  white-space: nowrap;
}
.nx-action {
  font-size: clamp(11px,1.9vw,14px);
  line-height: 1.1;
  font-weight: 700;
  text-align: center;
  overflow-wrap: normal;
}
.nx-panel button.nx-labelled {
  flex-direction: column;
  gap: 3px;
}
.nx-panel button.on .nx-key {
  color: #fff;
}
body[data-game="24"] .nx-row {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  width: min(100%,460px);
}
body[data-game="24"] .nx-row button {
  min-width: 0;
  padding: 4px;
}
.nx-bit-columns {
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  gap: 6px;
  width: min(100%,500px);
}
.nx-bit-column {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 4px;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #F1F2F4;
  min-width: 0;
  text-align: center;
}
.nx-bit-column.selected {
  border-color: var(--red);
}
.nx-weight {
  font-size: 13px;
  font-weight: 700;
  color: #626A73;
}
.nx-digit {
  font-size: clamp(30px,8dvh,62px);
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.nx-bit-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.nx-bit-columns .nx-bit-pair button {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  height: 38px;
  padding: 0;
  font-size: 18px;
  border-radius: 7px;
}
.nx-binary-result {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  font-variant-numeric: tabular-nums;
}
.nx-sum {
  font-weight: 700;
  font-size: clamp(13px,3vw,20px);
  color: var(--ink);
}
.nx-decimal {
  font-size: clamp(28px,6dvh,52px);
  color: var(--red);
  line-height: 1;
}
.nx-action-menu {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 8px;
  background: #34383E88;
}
.nx-action-card {
  width: min(100%,460px);
  max-height: 100%;
  overflow: auto;
  background: #F1F2F4;
  border: 1.5px solid #B6BDC4;
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 7px;
  text-align: center;
}
.nx-action-heading {
  font-weight: 800;
  font-size: var(--ui-size);
}
.nx-action-options {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 5px;
}
.nx-action-options button {
  min-width: 0;
  min-height: 36px;
  padding: 5px;
  font-size: 13px;
  white-space: normal;
}
.nx-action-options button.selected {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.nx-action-hint {
  font-weight: 650;
  font-size: 12px;
  color: #626A73;
}
@media (max-width:650px) {
  body.playing #controls.nx-uniform button {
    grid-column: var(--nx-mobile-start)/span var(--nx-mobile-span);
    grid-row: var(--nx-mobile-row);
  }
}
@media (orientation:landscape) and (max-height:600px) {
  body.playing #controls.nx-uniform button {
    height: 36px;
    min-height: 36px;
  }
  .nx-bit-column {
    padding: 3px;
    gap: 2px;
  }
  .nx-bit-columns .nx-bit-pair button {
    min-height: 30px;
    height: 30px;
  }
  .nx-digit {
    font-size: 32px;
  }
  .nx-binary-result {
    min-height: 26px;
  }
  .nx-action-card {
    padding: 5px;
    gap: 4px;
  }
  .nx-action-options button {
    min-height: 28px;
    padding: 3px;
    font-size: 12px;
  }
  .nx-action-hint {
    font-size: 11px;
  }
}
@media (max-width:355px) {
  .nx-bit-column {
    padding: 3px;
  }
  .nx-bit-columns {
    gap: 4px;
  }
  .nx-bit-columns .nx-bit-pair button {
    min-height: 34px;
    height: 34px;
  }
  .nx-action {
    font-size: 11px;
  }
}
body.playing #game-footer #controls.nx-uniform {
  gap: 4px 0;
  justify-content: stretch;
  justify-items: stretch;
}
.nx-labelled[data-key^="Arrow"] .nx-key {
  font-size: 14px;
  font-weight: 800;
  color: #34383E;
}
.nx-panel button.on .nx-key {
  color: #fff;
}
/* La paleta no queda recortada por los lienzos de poca altura. */
.nx-action-menu {
  position: fixed;
  inset: 0;
  z-index: 900;
  padding: max(10px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-right)) max(10px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left));
}
.nx-action-options button:last-child:nth-child(odd) {
  grid-column: 1/-1;
  width: calc((100% - 5px)/2);
  justify-self: center;
}
/* Binario: cuatro teclas iguales; el propio dígito es el interruptor. */
body[data-game="30"] .nx-bit-columns {
  width: min(100%,520px);
  gap: clamp(5px,1.4vw,12px);
}
body[data-game="30"] .nx-bit-column {
  grid-template-rows: auto auto;
  gap: 6px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}
body[data-game="30"] .nx-bit-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 100%;
  height: clamp(68px,17dvh,124px);
  min-height: 0;
  padding: 5px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
body[data-game="30"] .nx-bit-toggle.on {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
body[data-game="30"] .nx-bit-toggle .nx-digit {
  color: inherit;
  font-size: clamp(32px,8dvh,64px);
  line-height: 1;
}
body[data-game="30"] .nx-bit-key {
  font-size: clamp(15px,3dvh,24px);
  line-height: 1;
  color: #626A73;
}
body[data-game="30"] .nx-bit-toggle.on .nx-bit-key {
  color: #fff;
}
body[data-game="30"] .nx-bit-toggle.pressed {
  outline: 2px solid var(--ink);
  outline-offset: -3px;
}
body[data-game="30"] #game-footer #controls.nx-uniform {
  width: min(100%,220px);
}
body[data-game="30"] .nx-binary-result {
  gap: 9px;
}
@media (orientation:landscape) and (max-height:400px) {
  body[data-game="30"] .nx-bit-toggle {
    height: 66px;
    gap: 2px;
  }
  body[data-game="30"] .nx-bit-toggle .nx-digit {
    font-size: 32px;
  }
  body[data-game="30"] .nx-bit-key {
    font-size: 15px;
  }
  body[data-game="30"] .nx-bit-column {
    gap: 3px;
  }
}
/* Ajustes de distribución después de revisar las 30 actividades. */
@media (orientation:landscape) and (max-height:340px) {
  body[data-game="22"] .nx-panel {
    gap: 3px;
    padding: 4px;
  }
  body[data-game="22"] .nx-truth {
    gap: 2px;
  }
  body[data-game="22"] .nx-truth-line {
    padding: 1px 5px;
    line-height: 1.15;
  }
  body[data-game="22"] .nx-flow .nx-gate {
    min-height: 38px;
  }
}
@media (orientation:portrait) and (min-height:650px) {
  body.playing:is([data-game="18"],[data-game="20"],[data-game="31"]) #play {
    justify-content: center;
    gap: 8px;
  }
  body.playing:is([data-game="20"],[data-game="31"]) #stage.canvas-stage {
    flex: 0 1 auto;
    aspect-ratio: var(--canvas-aspect);
    height: auto;
    max-height: 100%;
    width: 100%;
    align-self: center;
  }
  body.playing[data-game="18"] #stage {
    flex: 0 1 auto;
    height: auto;
    max-height: 100%;
  }
  body.playing[data-game="18"] .nx-panel {
    height: auto;
    max-height: 100%;
  }
}
body[data-game="24"] #game-footer #controls.nx-uniform {
  width: min(100%,220px);
}
/* Experiencias directas, simétricas y sin menús intermedios. */
body.playing[data-game="21"] #stage {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
  align-items: center;
  justify-content: center;
}
.mp-conduct {
  width: min(100%,760px);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px,2vw,24px);
  min-height: 0;
}
.mp-conduct svg {
  width: 100%;
  height: 100%;
  max-height: 620px;
  display: block;
}
.mp-conduct.active .mp-bulb-glass {
  fill: #FFD43A;
}
.mp-conduct.active .mp-rays,.mp-conduct.active .mp-contact-bridge {
  opacity: 1;
}
.mp-conduct .mp-bulb-glass,.mp-conduct .mp-rays,.mp-conduct .mp-contact-bridge {
  transition: fill .1s,opacity .1s;
}
.mp-pair {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 8px;
  width: min(100%,420px);
}
.mp-wave {
  width: min(100%,620px);
  min-height: 0;
  display: grid;
  place-items: center;
  flex: 0 1 auto;
}
.mp-wave svg {
  width: 100%;
  max-height: min(35dvh,260px);
  display: block;
}
.mp-color-result {
  position: relative;
  width: min(100%,500px);
  height: clamp(90px,30dvh,260px);
  min-height: 0;
  flex: 0 1 auto;
  border: 1.5px solid #929BA4;
  border-radius: 12px;
  display: grid;
  place-items: center;
}
.mp-color-name {
  font-size: clamp(19px,4.5vw,32px);
  line-height: 1.1;
}
.mp-color-grid,.mp-beat-grid {
  display: grid;
  grid-template-columns: repeat(6,minmax(0,1fr));
  gap: 7px;
  width: min(100%,500px);
  min-width: 0;
}
.mp-color-grid button {
  grid-column: span 2;
  width: 100%;
  height: clamp(52px,10dvh,72px);
  min-height: 0;
  min-width: 0;
  padding: 4px;
  position: relative;
  background: var(--swatch);
  color: var(--swatch-ink);
  border: 2px solid transparent;
  box-shadow: none;
  flex-direction: column;
  gap: 3px;
  white-space: normal;
}
.mp-color-grid button:nth-child(4) {
  grid-column: 2/span 2;
}
.mp-color-grid button:nth-child(5) {
  grid-column: 4/span 2;
}
.mp-color-grid button .nx-key,.mp-color-grid button .nx-action {
  color: inherit!important;
  font-size: clamp(12px,3vw,16px);
}
.mp-color-grid button .nx-key {
  font-size: 16px!important;
}
.mp-color-grid button.chosen {
  border-color: #34383E;
  box-shadow: inset 0 0 0 2px #fff;
}
.mp-color-grid button:after {
  content: '';
  position: absolute;
  right: 5px;
  top: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid currentColor;
  background: transparent;
}
.mp-color-grid button.chosen:after {
  background: currentColor;
}
.mp-machine {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: clamp(8px,2vw,20px);
  width: min(100%,640px);
  align-items: stretch;
}
.mp-machine-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-width: 0;
  aspect-ratio: 1/1.1;
  background: #F1F2F4;
  border: 2px solid #B6BDC4;
  border-radius: 12px;
  padding: 8px;
  text-align: center;
}
.mp-machine-cell:not(:last-child):after {
  content: '›';
  position: absolute;
  right: calc(-1 * clamp(8px,2vw,20px));
  top: 50%;
  transform: translate(50%,-50%);
  z-index: 1;
  font-size: clamp(17px,3vw,26px);
  font-weight: 800;
  color: #626A73;
}
.mp-machine-cell.lit {
  border-color: var(--red);
  background: #fff;
}
.mp-machine-label {
  font-size: clamp(12px,2.4vw,18px);
  font-weight: 750;
  line-height: 1.15;
  white-space: normal;
}
.mp-machine-icon {
  width: min(100%,88px);
  aspect-ratio: 1;
  color: #34383E;
  transition: transform .18s;
}
.mp-machine-icon svg,.mp-beat-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.mp-beat-grid {
  grid-template-columns: repeat(2,minmax(0,1fr));
  width: min(100%,440px);
  gap: 8px;
}
.mp-beat-grid button {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: clamp(75px,18dvh,140px);
  min-height: 0;
  min-width: 0;
  padding: 6px;
  border: 2px solid #B6BDC4;
  border-radius: 12px;
  background: #fff;
}
.mp-beat-grid button.chosen {
  background: #F3E2E0;
  border-color: var(--red);
}
.mp-beat-grid button.beat-flash {
  background: var(--red);
  color: white;
}
.mp-beat-grid button.beat-flash .nx-key {
  color: white;
}
.mp-beat-icon {
  width: clamp(22px,6dvh,44px);
  height: clamp(22px,6dvh,44px);
  flex: none;
}
.mp-beat-grid .nx-key,.mp-beat-grid .nx-action {
  font-size: 13px;
  line-height: 1.05;
}
.mp-beat-steps {
  display: grid;
  grid-template-columns: repeat(8,1fr);
  gap: 6px;
  width: min(100%,440px);
}
.mp-beat-step {
  height: 8px;
  border-radius: 4px;
  background: #B6BDC4;
}
.mp-beat-step.current {
  background: var(--red);
}
body[data-game="27"] #game-footer #controls.nx-uniform {
  width: min(100%,220px);
}
.nx-code-last,.nx-code-slots {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0,1fr);
  gap: 6px;
  width: min(100%,500px);
  max-width: 100%;
}
.nx-code-last[hidden] {
  display: grid!important;
  visibility: hidden;
}
.nx-code-tile {
  position: relative;
  height: clamp(44px,12dvh,78px);
  min-height: 0;
  padding: 4px;
  line-height: 1.15;
  font-size: clamp(21px,5vw,32px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
}
.nx-code-last .nx-code-tile {
  height: clamp(38px,9dvh,60px);
  font-size: clamp(16px,4vw,23px);
}
.nx-code-tile.code-ok {
  background: #D0E8D6;
  color: #195A31;
  border-color: #36814F;
}
.nx-code-tile.code-no {
  background: #F3D0CD;
  color: #892A25;
  border-color: #B74A41;
}
.nx-code-mark {
  font-size: 12px;
  line-height: 1;
}
.nx-code-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 2px;
}
.nx-code-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #C3C9CF;
}
.nx-code-dot.used {
  background: #34383E;
}
.nx-code-dot.success {
  background: #36814F;
}
body.playing[data-game="28"] #game-footer:has(#snake-score:not([hidden])) {
  grid-template-columns: 1fr;
  grid-template-areas: 'score' 'controls';
  gap: 4px;
  width: min(100%,760px);
}
body[data-game="28"] #snake-score {
  min-height: 30px;
  height: 30px;
}
@media (orientation:landscape) and (max-height:600px) {
  .mp-color-result {
    height: clamp(55px,23dvh,145px);
  }
  .mp-color-grid {
    grid-template-columns: repeat(5,minmax(0,1fr));
    width: min(100%,620px);
    gap: 6px;
  }
  .mp-color-grid button,.mp-color-grid button:nth-child(4),.mp-color-grid button:nth-child(5) {
    grid-column: span 1;
    height: 52px;
  }
  .mp-machine {
    width: min(100%,520px);
  }
  .mp-machine-cell {
    aspect-ratio: auto;
    height: min(38dvh,180px);
    gap: 3px;
  }
  .mp-machine-icon {
    width: min(60%,65px);
  }
  .mp-beat-grid {
    grid-template-columns: repeat(4,minmax(0,1fr));
    width: min(100%,560px);
    gap: 6px;
  }
  .mp-beat-grid button {
    height: clamp(66px,24dvh,100px);
  }
  .mp-beat-steps {
    width: min(100%,560px);
  }
  .mp-wave svg {
    max-height: 30dvh;
  }
  .nx-code-tile {
    height: 46px;
  }
  .nx-code-last .nx-code-tile {
    height: 37px;
  }
  .nx-code-dot {
    width: 7px;
    height: 7px;
  }
  body.playing[data-game="28"] #game-footer:has(#snake-score:not([hidden])) {
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-areas: 'controls score';
    gap: 6px;
  }
}
@media (max-width:360px) and (orientation:portrait) {
  .mp-machine-cell {
    padding: 4px;
    gap: 5px;
  }
  .mp-machine-label {
    font-size: 11px;
  }
  .mp-color-grid button {
    font-size: 12px;
  }
  .mp-color-grid button:after {
    width: 5px;
    height: 5px;
    right: 3px;
    top: 3px;
  }
}
@media (orientation:portrait) and (max-width:650px) {
  body:is([data-game="18"],[data-game="29"]) #game-footer #controls.nx-uniform {
    grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 5px;
    width: min(100%,480px);
  }
  body:is([data-game="18"],[data-game="29"]) #controls.nx-uniform button {
    grid-column: auto;
    grid-row: 1;
    margin: 0;
  }
  body:is([data-game="18"],[data-game="29"]) #controls.nx-uniform button:last-child {
    grid-column: 2/4;
    grid-row: 2;
  }
  body[data-game="23"] #game-footer #controls.nx-uniform {
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 5px;
    width: min(100%,420px);
  }
  body[data-game="23"] #controls.nx-uniform button {
    grid-column: auto;
    grid-row: auto;
    margin: 0;
  }
  body[data-game="23"] #controls.nx-uniform button:last-child {
    grid-column: 1/-1;
    width: 50%!important;
    justify-self: center;
  }
  body[data-game="28"] #game-footer #controls.nx-uniform {
    grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 5px;
    width: min(100%,480px);
  }
  body[data-game="28"] #controls.nx-uniform button {
    grid-column: auto;
    grid-row: 1;
    margin: 0;
  }
  body[data-game="28"] #controls.nx-uniform button:nth-last-child(2) {
    grid-column: 1/3;
    grid-row: 2;
  }
  body[data-game="28"] #controls.nx-uniform button:last-child {
    grid-column: 3/5;
    grid-row: 2;
  }
}
@media (orientation:portrait) and (max-width:650px) {
  body[data-game="28"] #controls.nx-uniform button:nth-last-child(2) {
    grid-column: auto;
    grid-row: 1;
  }
  body[data-game="28"] #controls.nx-uniform button:last-child {
    grid-column: 2/4;
    grid-row: 2;
  }
}
/* mezclas de pintura, fracciones, secuencias y personaje. */
.mp-color-grid button {
  border-color: rgba(52,56,62,.24);
}
.mp-color-grid button.chosen {
  border-color: #34383E;
  box-shadow: inset 0 0 0 2px #fff,0 0 0 1px #34383E;
}
.mp-color-grid button:after {
  width: 9px;
  height: 9px;
  right: 6px;
  top: 6px;
}
.mp-fraction-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px,5vw,56px);
  width: min(100%,560px);
  min-height: 0;
}
.mp-fraction-pie {
  width: min(65%,320px);
  min-width: 0;
  flex-shrink: 1;
}
.mp-fraction-pie svg {
  width: 100%;
  height: auto;
  max-height: 42dvh;
  display: block;
}
.mp-fraction-number {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  width: clamp(64px,18vw,140px);
  font-size: clamp(32px,8dvh,76px);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: #34383E;
}
.mp-fraction-top {
  color: #006DB5;
  border-bottom: 3px solid #34383E;
  width: 100%;
  text-align: center;
  padding-bottom: 4px;
}
.mp-fraction-bottom {
  padding-top: 4px;
}
.mp-fraction-caption {
  font-size: clamp(14px,2.4vw,20px);
  font-weight: 650;
  text-align: center;
}
.mp-sequence {
  display: grid;
  grid-template-columns: repeat(8,minmax(0,1fr));
  gap: 5px;
  width: min(100%,560px);
}
.mp-sequence-slot {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: clamp(38px,8dvh,64px);
  border: 1.5px solid #B6BDC4;
  border-radius: 7px;
  background: #F1F2F4;
  color: #626A73;
}
.mp-sequence-index {
  font-size: 10px;
  line-height: 1;
}
.mp-sequence-note {
  height: clamp(17px,4dvh,28px);
  width: clamp(17px,4dvh,28px);
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}
.mp-sequence-note svg {
  width: 100%;
  height: 100%;
}
.mp-sequence-slot.filled {
  background: #fff;
  color: var(--instrument);
  border-color: var(--instrument);
}
.mp-sequence-slot.current {
  background: var(--instrument);
  color: #fff;
  border-color: var(--instrument);
}
body[data-game="27"] .mp-beat-grid {
  width: min(100%,560px);
}
body[data-game="27"] .mp-beat-pad .mp-beat-icon {
  color: var(--instrument);
}
body[data-game="27"] .mp-beat-pad.beat-flash .mp-beat-icon {
  color: #fff;
}
body[data-game="27"] .mp-beat-pad.beat-flash {
  background: var(--instrument);
}
body[data-game="27"] .mp-beat-pad:disabled {
  opacity: 1;
}
body[data-game="27"] #game-footer #controls.nx-uniform {
  width: min(100%,420px);
}
@media (orientation:portrait) and (max-width:650px) {
  body[data-game="25"] #game-footer #controls.nx-uniform {
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 5px;
    width: min(100%,420px);
  }
  body[data-game="25"] #controls.nx-uniform button {
    grid-column: auto;
    grid-row: auto;
    margin: 0;
  }
  body[data-game="25"] #controls.nx-uniform button:last-child {
    grid-column: 1/-1;
    width: 50%!important;
    justify-self: center;
  }
  body[data-game="28"] #controls.nx-uniform button:nth-last-child(2) {
    grid-column: 1/3;
    grid-row: 2;
  }
  body[data-game="28"] #controls.nx-uniform button:last-child {
    grid-column: 3/5;
    grid-row: 2;
  }
}
@media (orientation:landscape) and (max-height:600px) {
  .mp-fraction-pie svg {
    max-height: 36dvh;
  }
  .mp-fraction-caption {
    font-size: 13px;
  }
  .mp-fraction-number {
    font-size: clamp(25px,9dvh,48px);
  }
  .mp-sequence-slot {
    height: 39px;
  }
  .mp-sequence-note {
    width: 19px;
    height: 19px;
  }
  body[data-game="27"] .mp-beat-grid button {
    height: clamp(58px,19dvh,100px);
  }
}
/* Keep the circle and fraction optically grouped, including short landscape screens. */
.mp-fraction-pie {
  width: min(65%,320px,42dvh);
}
@media (orientation:landscape) and (max-height:600px) {
  .mp-fraction-pie {
    width: min(60%,43dvh,260px);
  }
  .mp-fraction-pie svg {
    max-height: 43dvh;
  }
  .mp-fraction-number {
    width: clamp(64px,18dvh,112px);
  }
  .mp-fraction-visual {
    gap: clamp(18px,4vw,36px);
  }
}
/* Selector alfabético con dos vistas, sin cambios en el área de juego. */
.menu-toolbar {
  display: flex;
  align-items: stretch;
  width: 100%;
  gap: 6px;
  flex: none;
  min-width: 0;
}
.menu-toolbar .nx-tabs {
  flex: 1;
  min-width: 0;
  width: auto;
}
.menu-toolbar .nx-tabs button {
  min-width: 0;
  white-space: nowrap;
  touch-action: manipulation;
}
.menu-views {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 4px;
  padding: 4px;
  background: var(--field);
  border: 1px solid #C3C9CF;
  border-radius: 12px;
  flex: none;
}
.menu-views button {
  width: 40px;
  min-height: 0;
  padding: 0;
  background: transparent;
  border-color: transparent;
  touch-action: manipulation;
  border-radius: 8px;
}
.menu-views button[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.menu-views svg {
  width: 21px;
  height: 21px;
  flex: none;
}
body:not(.playing)[data-menu-view="grid"] main {
  height: 100dvh;
  min-height: 0;
  max-height: 100dvh;
  gap: 8px;
}
body:not(.playing)[data-menu-view="grid"] #menu {
  min-height: 0;
  overflow: hidden;
}
body:not(.playing)[data-menu-view="grid"] #selector-panel {
  width: min(100%,760px);
  max-height: 100%;
  min-height: 0;
  gap: 10px;
  padding: 4px 0;
  justify-content: flex-start;
  margin: auto;
}
#activity-grid {
  --cols: 5;
  --tile-gap: 8px;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: var(--tile-gap);
  padding: 3px 4px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  touch-action: pan-y;
}
.activity-tile {
  flex: 0 0 calc((100% - (var(--cols) - 1)*var(--tile-gap))/var(--cols));
  min-width: 0;
  height: 100px;
  min-height: 0;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px;
  touch-action: pan-y;
  border-radius: 12px;
}
.activity-icon {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.activity-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.activity-label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4em;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere;
  pointer-events: none;
}
/* Resalte del catálogo: toda la tarjeta cambia de color, sin variar su tamaño.
   Los SVG heredan currentColor, igual que el texto. */
.activity-tile:active,
.activity-tile.touch-pressed,
.activity-tile:focus-visible {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}
.activity-tile:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -4px;
}
@media (hover:hover) and (pointer:fine) {
  .activity-tile:hover {
    color: #fff;
    background: var(--red);
    border-color: var(--red);
  }
}
@media (max-width:650px) {
  #activity-grid {
    --cols: 4;
    --tile-gap: 6px;
  }
  .activity-tile {
    height: 88px;
  }
  .activity-icon {
    width: 32px;
    height: 32px;
  }
  .activity-label {
    font-size: 12px;
  }
}
@media (max-width:430px) and (orientation:portrait) {
  #activity-grid {
    --cols: 3;
  }
  .activity-tile {
    height: 88px;
  }
  .menu-views button {
    width: 32px;
  }
  .menu-toolbar .nx-tabs button {
    padding-inline: 3px;
  }
}
@media (orientation:landscape) and (max-height:600px) {
  body:not(.playing)[data-menu-view="grid"] #selector-panel {
    width: min(100%,900px);
    gap: 5px;
    padding: 0;
  }
  #activity-grid {
    --cols: 7;
    --tile-gap: 6px;
  }
  .activity-tile {
    height: 70px;
    gap: 3px;
    padding: 4px 2px;
  }
  .activity-icon {
    width: 27px;
    height: 27px;
  }
  .activity-label {
    font-size: 11px;
  }
  .menu-views {
    padding: 3px;
  }
  .menu-views button {
    width: 34px;
  }
  .menu-toolbar .nx-tabs button {
    padding-inline: 5px;
  }
}
@media (orientation:landscape) and (max-width:650px) {
  #activity-grid {
    --cols: 5;
  }
}
@media (orientation:portrait) and (max-height:580px) {
  body:not(.playing)[data-menu-view="grid"] #selector-panel {
    gap: 5px;
  }
  .activity-tile {
    height: 78px;
  }
  .activity-icon {
    width: 29px;
    height: 29px;
  }
}
@media (orientation:portrait) and (max-width:430px) and (min-height:581px) {
  .activity-tile {
    height: 82px;
  }
}
@media (orientation:landscape) and (min-width:651px) and (max-height:600px) {
  #activity-grid[data-category="experiences"] {
    --cols: 5;
  }
}
/* Selector de vista centrado, independiente de las pestañas. */
.menu-toolbar {
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.menu-toolbar .nx-tabs {
  flex: none;
  width: 100%;
}
.menu-views {
  width: auto;
  align-self: center;
  gap: 3px;
  padding: 3px;
}
.menu-views button {
  width: 44px;
  height: 34px;
  min-height: 34px;
}
@media (orientation:landscape) and (max-height:600px) {
  .menu-toolbar {
    gap: 4px;
  }
  .menu-views {
    padding: 2px;
  }
  .menu-views button {
    height: 28px;
    min-height: 28px;
    width: 40px;
  }
  .menu-views svg {
    width: 18px;
    height: 18px;
  }
  body:not(.playing) #selector-panel {
    gap: 4px;
  }
  body:not(.playing)[data-menu-view="list"] #preview-icon {
    width: clamp(34px,11dvh,70px);
    height: clamp(34px,11dvh,70px);
  }
}
@media (orientation:portrait) and (max-height:580px) {
  .menu-toolbar {
    gap: 4px;
  }
  .menu-views button {
    height: 30px;
    min-height: 30px;
    width: 40px;
  }
  body:not(.playing)[data-menu-view="list"] #selector-panel {
    gap: 4px;
  }
  body:not(.playing)[data-menu-view="list"] #preview-icon {
    width: 52px;
    height: 52px;
  }
}
@media (orientation:landscape) and (max-height:340px) {
  body:not(.playing)[data-menu-view="list"] main {
    gap: 5px;
  }
  body:not(.playing)[data-menu-view="list"] #selector-panel {
    gap: 3px;
  }
  body:not(.playing)[data-menu-view="list"] footer {
    padding-top: 2px;
    font-size: 10px;
  }
  body:not(.playing)[data-menu-view="list"] #preview-icon {
    width: 34px;
    height: 34px;
  }
}
@media (orientation:landscape) and (max-height:340px) {
  body:not(.playing)[data-menu-view="list"] main {
    gap: 3px;
  }
  body:not(.playing)[data-menu-view="list"] #selector-panel {
    gap: 2px;
  }
}
/* Catálogo: en móviles altos caben las siete filas de juegos sin recortar la última.
   En pantallas más pequeñas se conserva el desplazamiento interior y el tamaño táctil. */
@media (orientation:portrait) and (max-width:430px) and (min-height:780px) and (max-height:900px) {
  #activity-grid[data-category="games"] .activity-tile {
    height: 74px;
    gap: 4px;
    padding: 5px 4px;
  }
}

/* Portada: el selector de vista y las pestañas no saltan al cambiar de categoría.
   La ficha individual usa el espacio restante para centrar su contenido. */
body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) main {
  height: 100dvh;
  min-height: 0;
  max-height: 100dvh;
  gap: 8px;
}
body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) #menu {
  min-height: 0;
  overflow: hidden;
}
body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) #selector-panel {
  width: min(100%,760px);
  max-height: 100%;
  min-height: 0;
  margin: 0 auto auto;
  justify-content: flex-start;
  padding: 4px 0;
  gap: 10px;
}
body:not(.playing)[data-menu-view="list"] #selector-panel {
  flex: 1 1 auto;
}
body:not(.playing)[data-menu-view="list"] #preview-icon { margin-top: auto; }
body:not(.playing)[data-menu-view="list"] #start-game { margin-bottom: auto; }
body:not(.playing)[data-menu-view="list"] :is(#game-select,#start-game,#preview-desc) {
  max-width: 400px;
}
@media (orientation:landscape) and (max-height:600px) {
  body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) #selector-panel {
    width: min(100%,900px);
    gap: 4px;
    padding: 0;
  }
}
@media (orientation:portrait) and (max-height:580px) {
  body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) #selector-panel {
    gap: 4px;
    padding: 0;
  }
}
@media (orientation:landscape) and (max-height:340px) {
  body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) main { gap: 3px; }
  body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) #selector-panel { gap: 2px; }
}

/* Topos: una única ilustración escalable mantiene el borde y el personaje unidos. */
.nx-moles .nx-hole-art {
  display: block;
  width: min(100%, 150px);
  height: 0;
  min-height: 0;
  flex: 1 1 0;
  overflow: hidden;
}
.nx-mole-art { transform: translateY(90px); transition: transform .10s ease-out; }
.nx-moles .target .nx-mole-art { transform: translateY(0); }
@media (prefers-reduced-motion: reduce) { .nx-mole-art { transition: none; } }

/* Las flechas de la caja de ritmos son contactos, no anotaciones decorativas. */
body[data-game="27"] .mp-beat-pad .nx-key {
  font-size: clamp(14px, 2.5dvh, 20px);
  font-weight: 700;
  line-height: 1;
}
@media (min-height: 500px) {
  body[data-game="27"] .mp-beat-pad .nx-action { font-size: 15px; }
}

/* Portada: aire bajo la marca y ficha agrupada con sus pestañas.
   En pantallas bajas se reduce el espaciado para mantener todos los controles visibles. */
body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) main {
  gap: 28px;
}
body:not(.playing)[data-menu-view="list"] #preview-icon {
  margin-top: 16px;
}
body:not(.playing)[data-menu-view="grid"] #selector-panel { gap: 6px; }
@media (orientation:portrait) and (max-width:430px) and (min-height:780px) and (max-height:900px) {
  #activity-grid[data-category="games"] .activity-tile { height: 72px; }
}
@media (orientation:landscape) and (max-height:600px), (orientation:portrait) and (max-height:580px) {
  body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) main { gap: 16px; }
  body:not(.playing)[data-menu-view="list"] #preview-icon { margin-top: 4px; }
  body:not(.playing)[data-menu-view="grid"] #selector-panel { gap: 3px; }
}
@media (orientation:landscape) and (max-height:340px) {
  body:not(.playing):is([data-menu-view="grid"],[data-menu-view="list"]) main { gap: 8px; }
  body:not(.playing)[data-menu-view="list"] #preview-icon { margin-top: 0; }
  body:not(.playing)[data-menu-view="grid"] #selector-panel { gap: 2px; }
}

/* La solución ocupa la fila del intento anterior, sin mover los controles. */
.nx-code-last.solution { position: relative; }
.nx-code-last.solution::before { content: "Solución"; position: absolute; bottom: 100%; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 700; line-height: 12px; color: #34383E; }

/* Adaptaciones exclusivas de micro:bit: sensores, simulación y marca de tres palabras. */
.panel{width:min(100%,780px);max-height:100%;overflow:auto;display:flex;flex-direction:column;align-items:center;gap:12px;padding:8px;text-align:center}.panel h3,.panel p{margin:0}.panel p{font-size:14px;font-weight:500}.reading{font-size:clamp(32px,8vw,80px);font-weight:800;color:var(--blue);font-variant-numeric:tabular-nums}.meter{height:25px;border:1px solid var(--line);background:white;border-radius:8px;width:90%;overflow:hidden}.meter div{height:100%;background:var(--blue);transition:width .1s}.sensor-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;width:100%}.sensor-card{border:1px solid var(--line);border-radius:12px;background:white;padding:10px;display:flex;flex-direction:column;gap:5px}.sensor-card strong{font-size:clamp(18px,4vw,36px);color:var(--blue)}.led-grid{display:grid;grid-template-columns:repeat(5,1fr);gap:7px;padding:12px;border-radius:12px;background:var(--ink);width:min(260px,100%);aspect-ratio:1}.led-grid button{min-width:0;min-height:0;padding:0;aspect-ratio:1;border:0;background:#626A73;border-radius:5px}.led-grid button[aria-pressed=true]{background:#F35A53}.sim{display:flex;align-items:center;gap:5px;background:white;border:1px solid #CFD5DB;border-radius:8px;padding:4px 8px;font-size:12px}.sim input{width:clamp(65px,12vw,130px);accent-color:var(--blue)}.config-row{display:flex;flex-wrap:wrap;gap:8px;margin:12px 0}.board{width:min(250px,100%);display:block;margin:10px auto}.notice{border-left:3px solid var(--blue);padding:8px 10px;background:white;border-radius:5px}a{color:var(--blue)}.badge{padding:4px 8px;background:var(--field);border-radius:7px;font-size:12px}.small{font-size:12px;color:#626A73}.message-input{width:100%;padding:10px;border:1px solid var(--line);border-radius:8px;background:white}.row{display:flex;flex-wrap:wrap;justify-content:center;gap:8px;align-items:center}.sample{font-size:13px;font-weight:600}.panel svg.big{height:min(32vh,210px);max-width:100%}
#modal { --help-dark: var(--ink); --help-soft: var(--field); --help-strong: var(--blue); margin:auto; color:var(--ink); }
#modal::backdrop { background:#18202b66; }
#modalBody { clear:both; font-size:var(--ui-size); line-height:1.45; }
#modalBody p { margin:8px 0; }
#modalBody button { touch-action:manipulation; }
#modal .help-diagrams .board { width:min(100%,300px); max-height:34dvh; }
#modal .help-instructions p { font-weight:500; }
#modal .notice { border-left:3px solid var(--blue); padding:8px 10px; background:var(--field); border-radius:5px; }
.primary { background:var(--ink); color:white; border-color:var(--ink); }
#simControls { display:flex; flex-wrap:wrap; justify-content:center; gap:4px; width:100%; flex:none; max-height:22dvh; overflow:auto; touch-action:pan-y; }
#simControls:empty { display:none; }
#modeLabel { text-align:center; font-size:11px; color:#626A73; flex:none; }
#game-footer #controls button.wide { width:auto; min-width:var(--action-height); font-size:var(--ui-size); padding:0 12px; white-space:normal; }
#stage .panel { width:min(100%,780px); min-height:0; max-height:100%; overflow:auto; touch-action:pan-y; }
#stage.canvas-stage canvas { max-width:100%; max-height:100%; width:auto; height:auto; object-fit:contain; }
/* Misma caja de cabecera; solo se escala la marca porque tiene una palabra más. */
body:not(.playing) #logo { font-size:clamp(28px,5.4vw,54px); }
@media (orientation:portrait) and (max-width:520px) { body:not(.playing) #logo { font-size:clamp(29px,9vw,46px); } }
@media (orientation:landscape) and (max-height:600px) { body:not(.playing) #logo { font-size:clamp(25px,5vw,39px); } }
@media (max-width:700px) { .sensor-grid {grid-template-columns:repeat(2,minmax(0,1fr));} }
@media (orientation:landscape) and (max-height:500px) { .panel{gap:5px;padding:4px;} .led-grid{width:130px;gap:4px;padding:7px;} .sensor-card{padding:4px;} #simControls {max-height:18dvh;} }
@media (prefers-reduced-motion:reduce) { * {transition:none!important;} }

/* Preparación USB: el mismo sistema visual, con instrucciones escalonadas. */
.mpb-setup{display:flex;flex-direction:column;align-items:center;gap:10px;width:100%;max-width:560px;margin:0 auto;text-align:center;min-width:0}
.mpb-setup>svg.board{width:min(190px,65%);height:auto;max-height:108px;flex-shrink:0}
.mpb-setup p{margin:0;line-height:1.35;overflow-wrap:anywhere}
.mpb-setup .notice{width:100%;padding:9px 12px;border:1px solid #B6BDC4;border-radius:10px;background:#F1F2F4;color:#34383E;font-weight:700}
.mpb-setup .notice[data-state="ready"]{border-color:#006DB5;color:#006DB5;background:#E7F3FA}
.mpb-setup .small{font-size:12px;color:#626A73}
.mpb-hint{background:#E4E7EA;padding:9px;border-radius:9px;font-size:12px}
.mpb-primary-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px;width:100%}
.mpb-primary-actions>button{width:100%;min-width:0;white-space:normal;min-height:40px;padding:8px;font-size:13px}
.mpb-primary-actions>button:last-child:nth-child(3){grid-column:1/-1}
.mpb-setup button.primary,.mpb-editor{background:#006DB5;color:white;border:1px solid #006DB5;border-radius:10px;font-weight:700}
.mpb-setup button.primary:hover,.mpb-editor:hover{background:#005B97;color:#fff}
.mpb-advanced{width:100%;border:1px solid #B6BDC4;border-radius:10px;padding:9px;font-size:13px;text-align:center}
.mpb-advanced summary{cursor:pointer;font-weight:700}
.mpb-advanced .config-row{margin-top:8px}
.mpb-steps{width:100%;padding:0 0 0 24px;margin:0;text-align:left;display:flex;flex-direction:column;gap:9px;font-size:13px}
.mpb-steps li{padding-left:3px;line-height:1.35}
.mpb-steps li::marker{font-weight:bold;color:#006DB5}
.mpb-steps li span{display:block;color:#626A73;margin-top:3px}
.mpb-steps button,.mpb-editor{display:block;margin:7px 0 0;width:100%;padding:8px 10px;text-align:center;min-height:38px;white-space:normal;text-decoration:none}
#modal:has(.mpb-setup){overflow:auto;max-height:calc(100dvh - 16px)}
@media (max-height:500px){.mpb-setup{gap:7px}.mpb-setup>svg.board{max-height:68px}.mpb-steps{gap:6px}}

/* Estado USB: sin modificar las dimensiones ni la posición de los botones. */
#test.usb-ready {color:var(--blue);border-color:var(--blue)}
.mpb-wizard .mpb-steps {gap:12px}
.mpb-primary-actions>button:disabled {opacity:.65;cursor:default}

/* Un único control principal, simulador debajo; configuración discreta. */
.mpb-primary-actions{grid-template-columns:1fr}.mpb-primary-actions>button{min-height:44px}.mpb-advanced .config-row{justify-content:center}.mpb-setup .notice{border-left:1px solid #B6BDC4}

/* Geometría gemela: el lienzo utiliza el espacio disponible, sin deformar las figuras. */
body.playing #stage.canvas-stage canvas { display:block; flex:none; max-width:100%; max-height:100%; }
body.playing #stage.canvas-stage { background:transparent; }
#stage .panel { width:100%; max-width:none; }
#stage .panel .sensor-grid { max-width:1000px; }
#stage .panel .reading { font-size:clamp(36px,12dvh,100px); }
#stage .panel .meter { max-width:860px; }
#stage .panel .big { height:clamp(64px,36dvh,320px); }
#stage .panel .led-grid { width:min(100%,36dvh,380px); }
#modeLabel { line-height:1.2; }
@media (orientation:portrait) {
 body.playing:not([data-activity="carrera"]) #play:has(.canvas-stage) {justify-content:center;}
 body.playing:not([data-activity="carrera"]) #stage.canvas-stage {flex:0 1 auto; aspect-ratio:var(--canvas-aspect); max-height:100%;}
}
@media (orientation:landscape) and (max-height:600px) and (min-aspect-ratio:2/1) {
 body.playing[data-activity="carrera"] #play {display:grid;grid-template-columns:minmax(0,1fr) clamp(160px,24vw,216px);grid-template-rows:minmax(0,1fr);gap:10px;}
 body.playing[data-activity="carrera"] #game-footer {display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;min-height:0;gap:8px;}
 body.playing[data-activity="carrera"] #simControls {flex-direction:column;max-height:none;align-items:center;}
 body.playing[data-activity="carrera"] #game-footer #controls button {width:100%;}
 body.playing[data-activity="carrera"] #game-footer #controls {width:100%;}
}
@media (orientation:landscape) and (max-height:500px) {#stage .panel .led-grid{width:min(130px,35dvh);}}

#game-footer {grid-template-areas:none;grid-auto-flow:row;grid-template-columns:minmax(0,1fr);}
#game-footer #command-slot:empty {display:none;}
#game-footer #controls,#game-footer #simControls,#game-footer #modeLabel {grid-area:auto;}
#game-footer #modeLabel {width:100%;}
/* Retos: misma paleta y controles originales. */
.menu-toolbar .nx-tabs {grid-template-columns: repeat(3,minmax(0,1fr));}
.menu-toolbar .nx-tabs button {padding-inline: 3px;}
.reto-panel {width:min(100%,650px);max-height:100%;overflow:auto;margin:auto;padding:12px;box-sizing:border-box;color:var(--ink);text-align:left;}
.reto-panel h2 {font-size:clamp(16px,3vw,23px);margin:0 0 10px;}
.reto-panel ol {padding-left:24px;margin:8px 0;}
.reto-panel li {margin:8px 0;}
.reto-panel p {font-size:13px;margin:8px 0;}
.reto-buttons {display:flex;flex-wrap:wrap;gap:8px;}
.reto-buttons button {flex:1;min-width:120px;padding:8px;}

.reto-panel {min-height:0;overscroll-behavior:contain;}
.reto-buttons button {min-height:44px;}

/* Retos: tarjetas dobles, con iconos grandes y sin texto explicativo en el menú. */
#activity-grid[data-category="challenges"] { --cols: 4; }
#activity-grid[data-category="challenges"] .activity-tile {
  position: relative;
  flex-basis: calc((100% - var(--tile-gap))/2);
  height: 128px;
  gap: 7px;
  padding: 10px 12px;
}
#activity-grid[data-category="challenges"] .activity-icon { width: 52px; height: 52px; }
#activity-grid[data-category="challenges"] .activity-label { font-size: 15px; min-height: 2.3em; }
.reto-numero { position: absolute; top: 8px; left: 10px; font-size: 14px; font-weight: 700; }
@media (orientation:landscape) and (max-height:600px) {
  #activity-grid[data-category="challenges"] { --cols: 8; }
  #activity-grid[data-category="challenges"] .activity-tile { flex-basis: calc((100% - 3*var(--tile-gap))/4); height: 100px; }
  #activity-grid[data-category="challenges"] .activity-icon { width: 40px; height: 40px; }
  #activity-grid[data-category="challenges"] .activity-label { font-size: 13px; }
}

/* Navegación didáctica y guía integrada */
#back-reto {width:var(--action-height);height:var(--action-height);min-width:var(--action-height);padding:0;flex:none} #back-reto svg,#teacher-guide svg {width:22px;height:22px;flex:none}
.reto-digit {font-size:clamp(28px,6vw,48px);font-weight:850;line-height:1;display:grid;place-items:center;width:100%;height:100%}
#activity-grid[data-category="challenges"] .activity-tile {height:118px} #activity-grid[data-category="challenges"] .activity-label {min-height:1.2em}
@media (orientation:landscape) and (max-height:600px) {#activity-grid[data-category="challenges"] .activity-tile {height:85px;gap:2px} .reto-digit{font-size:32px}}
@media (max-width:430px) {body.playing .heading:has(#back-reto:not([hidden])){gap:4px} body.playing .heading:has(#back-reto:not([hidden])) #name{font-size:13px} }
@media print {body:has(#guide-dialog[open]) main,body:has(#guide-dialog[open]) .guide-toolbar {display:none!important} #guide-dialog[open]{position:static;width:100%;max-width:none;max-height:none;overflow:visible;border:0;margin:0} #guide-dialog::backdrop{display:none} .guide-section{break-inside:avoid} }

.reto-panel{width:min(100%,1000px);display:grid;gap:8px;align-content:start;max-height:100%;overflow:auto;touch-action:pan-y}.reto-panel h2{margin:0;font-size:clamp(16px,2.4vw,22px)}.reto-intro,.reto-warning{font-size:13px;margin:4px 0}.reto-figure{margin:0;padding:4px;background:#F1F2F4;border-radius:12px}.reto-figure svg{width:100%;max-height:40dvh;display:block}.reto-steps{font-size:14px;margin:3px 0;padding-left:22px}.reto-steps li{margin:4px 0}.reto-buttons{display:flex;gap:8px;flex-wrap:wrap}.reto-buttons button{flex:1;min-width:120px}@media(orientation:landscape) and (max-height:600px){.reto-panel{grid-template-columns:1fr 1fr}.reto-header,.reto-warning,.reto-buttons{grid-column:1/-1}.reto-figure svg{max-height:48dvh}}

.reto-dual{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;align-items:start}.reto-dual figure{margin:0;min-width:0;text-align:center}.reto-dual figcaption,.reto-caption{font-size:12px;font-weight:700;text-align:center;margin:3px 0}.reto-dual svg{max-height:38dvh}.reto-montaje{grid-template-columns:1.55fr 1fr}.reto-caption{color:#34383E}.reto-figure svg text{font-family:system-ui,sans-serif}.reto-figure .board-contact{opacity:1}.reto-figure .help-markers{display:none} @media(max-width:480px) and (orientation:portrait){.reto-dual:not(.reto-montaje){grid-template-columns:1fr}.reto-dual:not(.reto-montaje) svg{max-height:34dvh}}

body.playing:is([data-game="21"],[data-game="32"],[data-game="33"],[data-game="34"],[data-game="35"]) header{grid-template-columns:minmax(0,1fr) auto}body.playing:is([data-game="21"],[data-game="32"],[data-game="33"],[data-game="34"],[data-game="35"]) #name{overflow-wrap:normal;word-break:normal}

/* Reto: aviso después del catálogo y ficha. Selectores con indicador deslizante. */
#reto-notice {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr) 66px;
  flex: none;
  align-items: center;
  gap: 12px;
  width: min(100%, 520px);
  margin: 7px auto 0;
  padding: 10px 14px;
  border: 3px solid var(--red);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  text-align: center;
  line-height: 1.3;
  font-size: 13px;
  font-weight: 600;
}
#reto-notice .notice-copy {display:flex;flex-direction:column;gap:8px;align-items:center;justify-content:center;min-width:0;}
#reto-notice strong {font-size:17px;font-weight:800;color:var(--red);}
#reto-notice > svg {display:block;width:100%;height:auto;}
#reto-notice .notice-alert {max-width:60px;justify-self:center;}
#reto-notice .notice-family {max-width:66px;justify-self:center;}
/* En la ficha de Retos la numeración ya aparece en el título. */
body:not(.playing)[data-menu-view="list"] #selector-panel:has(#reto-notice:not([hidden])) #preview-name {margin-top:16px;}
@media (max-width:480px) {
  #reto-notice {grid-template-columns:44px minmax(0,1fr) 44px;gap:7px;padding:9px;}
  #reto-notice strong {font-size:15px;}
  #reto-notice .notice-copy {gap:4px;}
}
.reto-digit {font-size:clamp(25px,5.5vw,39px);letter-spacing:-.05em;}
.reto-fault {margin:0;text-align:center;}
.reto-fault figcaption {font-size:13px;font-weight:700;margin:3px 0;}
.menu-toolbar :is(.nx-tabs,.menu-views) {position:relative;isolation:isolate;}
.menu-toolbar :is(.nx-tabs,.menu-views).indicator-ready::before {content:"";position:absolute;z-index:0;pointer-events:none;top:0;left:0;width:var(--indicator-w);height:var(--indicator-h);transform:translate(var(--indicator-x),var(--indicator-y));border-radius:8px;background:var(--ink);}
.menu-toolbar :is(.nx-tabs,.menu-views).indicator-animated::before {transition:transform 250ms cubic-bezier(.22,.75,.24,1),width 250ms cubic-bezier(.22,.75,.24,1),height 250ms cubic-bezier(.22,.75,.24,1);}
.menu-toolbar :is(.nx-tabs,.menu-views).indicator-ready button {position:relative;z-index:1;background:transparent;border-color:transparent;transition:color 190ms ease;}
.menu-toolbar :is(.nx-tabs,.menu-views).indicator-ready button[aria-pressed="true"] {color:white;background:transparent;border-color:transparent;}
.menu-toolbar :is(.nx-tabs,.menu-views).indicator-ready button[aria-pressed="false"] {color:var(--ink);}
.menu-toolbar :is(.nx-tabs,.menu-views).indicator-ready button:focus-visible {outline:2px solid var(--red);outline-offset:-2px;}
@media (prefers-reduced-motion:reduce) {.menu-toolbar :is(.nx-tabs,.menu-views).indicator-animated::before,.menu-toolbar :is(.nx-tabs,.menu-views).indicator-ready button {transition:none;}}
@media (orientation:landscape) and (max-height:600px), (orientation:portrait) and (max-height:580px) {
 #reto-notice {font-size:12px;padding:6px 10px;margin:3px auto 0;gap:8px;}
 #reto-notice {grid-template-columns:46px minmax(0,1fr) 46px;} #reto-notice strong {font-size:14px;} #reto-notice .notice-copy {gap:3px;}
 body:not(.playing)[data-menu-view="list"] #selector-panel:has(#reto-notice:not([hidden])) #preview-name {margin-top:4px;}
 .reto-digit {font-size:30px;}
 body:not(.playing)[data-menu-view="list"] #selector-panel:has(#reto-notice:not([hidden])) {overflow:auto;}
}

body:not(.playing)[data-menu-view="list"] #selector-panel:has(#reto-notice:not([hidden])) #start-game {margin-bottom:0;}
@media (max-width:480px) and (orientation:portrait) {.reto-dual:not(.reto-montaje) svg{max-height:24dvh;}}

/* Catálogo: centra el conjunto icono + título por su altura real, no por una
   reserva fija de dos líneas. Se respetan las dimensiones de las tarjetas. */
#activity-grid:is([data-category="games"], [data-category="experiences"]) .activity-tile {
  justify-content: center;
  gap: 3px;
  padding-block: 4px;
}
#activity-grid:is([data-category="games"], [data-category="experiences"]) .activity-label {
  min-height: 0;
  flex: none;
  line-height: 1.15;
}

/* Guía de retos: control de catálogo y diálogo accesible con contenido local. */
#teacher-guide {
  display: flex;
  flex: none;
  align-self: center;
  min-height: 44px;
  padding: 8px 18px;
  gap: 8px;
  font-size: 14px;
}
#guide-dialog {
  width: min(92vw, 680px);
  max-height: 88vh;
  max-height: 88dvh;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  box-shadow: 0 10px 40px #34383e30;
}
#guide-dialog:not([open]) { display: none; }
#guide-dialog::backdrop { background: #34383e99; }
#guide-dialog.guide-fallback {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: auto;
  display: block;
  box-shadow: 0 0 0 100vmax #34383e99;
}
.guide-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 14px;
  background: #111;
  color: #fff;
  border-bottom: 1px solid #111;
}
.guide-toolbar h2 { flex: 1; margin: 0; font-size: 19px; color: #fff; }
#guide-close { width: 44px; min-height: 44px; padding: 0; font-size: 27px; color:#fff; border-color:#fff; background:transparent; }
#guide-close:hover,#guide-close:focus-visible{background:#ffffff14;}
.guide-body { padding: 16px; font-size: 14px; line-height: 1.55; text-align: left; }
.guide-lead { margin: 0 0 14px; }
.guide-section { padding: 14px 0; border-top: 1px solid var(--line); }
.guide-section h3 { margin: 0 0 8px; font-size: 17px; }
.guide-section h3 span { color: var(--red); margin-right: 5px; }
.guide-section p { margin: 6px 0; }
.guide-safety { margin: 0; padding: 12px; background: var(--field); border-radius: 8px; border-left: 3px solid var(--red); }
@media (orientation:landscape) and (max-height:600px), (orientation:portrait) and (max-height:580px) {
  #teacher-guide { min-height: 36px; padding: 4px 12px; font-size: 13px; }
  #reto-notice { margin-top: 2px; }
}

/* Controles de navegación: realimentación común, sin afectar a los juegos.
   Los botones de acción se resaltan mientras se pulsan; los de estado
   conservan el resaltado hasta que se desactiva su función. */
:is(header button, #teacher-guide, .reto-buttons button, #helpclose):not(:disabled):is(:active, .pressed, :focus-visible),
header button[aria-pressed="true"],
body[data-game="6"] #test,
body.modal-open #helpbtn,
body:has(#guide-dialog[open]) #teacher-guide {
  background: #111;
  border-color: #111;
  color: #fff;
}
@media (hover:hover) and (pointer:fine) {
  :is(header button, #teacher-guide, .reto-buttons button, #helpclose):not(:disabled):hover {
    background: #111;
    border-color: #111;
    color: #fff;
  }
}
/* Los estados de selección de las pestañas mantienen su indicador animado. */

/* MicroPlayBit: ajustes de los retos y estados de navegación. */
body:has(#modal[open]) #test, body:has(#modal[open]).playing #helpbtn, #test.usb-ready {background:#111;border-color:#111;color:#fff;}
body:not(.playing)[data-menu-view="list"] #selector-panel:has(#reto-notice:not([hidden])) #preview-icon {display:none;}
body.playing[data-activity^="r"] #stage:has(.mpb-challenge) {overflow:auto;align-items:flex-start;}
.mpb-challenge {width:min(100%,760px);margin:auto;display:grid;gap:12px;padding:12px;overflow:auto;touch-action:pan-y;max-height:100%;text-align:left;}
.mpb-challenge h2,.mpb-challenge p {margin:0;} .mpb-challenge .reto-figure {display:flex;align-items:center;justify-content:center;gap:16px;} .mpb-challenge .reto-figure .board {max-height:22dvh;width:150px;margin:0;} .mpb-challenge .question {font-size:clamp(35px,8vw,70px);font-weight:800;color:var(--blue);} .mpb-challenge .reto-buttons button {white-space:normal;}

.menu-toolbar .nx-tabs {grid-template-columns:repeat(2,minmax(0,1fr));}

.music-keys{display:flex;gap:4px;justify-content:center;margin:12px auto;width:min(100%,520px)}.music-keys button{flex:1;min-width:0;padding:8px 0;height:clamp(48px,12vh,110px);border:1px solid #929BA4;border-radius:6px;background:white;color:#34383E;font-weight:700}.music-keys button[aria-pressed=true]{background:#006DB5;color:white}.music-keys button.sounding{background:#242424;color:white}

/* Solo se muestra una acción principal, salvo cuando hay que confirmar o cancelar. */
.mpb-primary-actions{grid-template-columns:repeat(auto-fit,minmax(120px,1fr))}
.mpb-primary-actions>button[hidden]{display:none!important}
