* { box-sizing: border-box; }

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

canvas { display: block; width: 100vw; height: 100vh; }

/* ---------- Ajustes ---------- */
#gear {
  position: fixed; top: 8px; left: 8px; z-index: 10;
  width: 18px; height: 18px; padding: 0; border-radius: 50%;
  border: 0; background: none; color: #e8e8ee;
  font-size: 13px; line-height: 1; cursor: pointer; opacity: .6;
  display: flex; align-items: center; justify-content: center;
}
#gear:hover { opacity: 1; }
/* área táctil más grande que el ícono */
#gear::after { content: ''; position: absolute; inset: -8px; }

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

/* pestañas */
.tabs { display: flex; gap: 4px; margin: -4px 0 12px; border-bottom: 1px solid #ffffff1a; }
.tab {
  flex: 1; padding: 8px 4px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: #e8e8ee; font: inherit; font-size: 14px; opacity: .6; cursor: pointer;
}
.tab.active { opacity: 1; border-bottom-color: #8fd0ff; }
.pane { display: none; }
.pane.active { display: block; }

#padStatus { margin: 4px 0 8px; font-size: 14px; font-weight: 600; color: #6fd38a; }
#padStatus.off { color: #ff8a7a; }

/* ---------- Joystick táctil ---------- */
#joy {
  position: fixed; left: 32px; bottom: 32px; z-index: 5;
  display: none;
  width: 140px; height: 140px; border-radius: 50%;
  background: #ffffff10; border: 2px solid #ffffff30;
  touch-action: none;
}
#joy.on { display: block; }
#knob {
  position: absolute; left: 50%; top: 50%;
  width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%;
  background: #ffffff40; border: 2px solid #ffffff60;
  pointer-events: none;
}

/* ---------- Menú de stages y stage completo ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 8;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 16px;
  background: radial-gradient(ellipse at center, #0b0d14aa, #0b0d14ee);
}
.overlay[hidden] { display: none; }
.overlay h1 { margin: 0; font-size: 44px; letter-spacing: .3em; color: #ffd24a; }
.overlay .sub { margin: 0 0 8px; opacity: .7; }
.overlay .hint { margin: 8px 0 0; font-size: 12px; opacity: .5; }

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

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

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

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

/* selección (mando / teclado / mouse) */
.tile:focus { outline: none; }
.tile.selected {
  border-color: #ffd24a;
  background: linear-gradient(160deg, #3a4670, #20263a);
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 6px 0 #0a0c14, 0 0 0 3px #ffd24a, 0 0 24px #ffd24a88;
  animation: tileGlow 1.2s ease-in-out infinite;
}
@keyframes tileGlow {
  50% { box-shadow: 0 6px 0 #0a0c14, 0 0 0 3px #ffd24a, 0 0 36px #ffd24acc; }
}
.buttons button.selected, .overlay .back.selected, #panel button.wide:focus {
  outline: 3px solid #ffd24a; outline-offset: 2px;
}
/* flechita que apunta al casillero seleccionado */
.tile.selected::before {
  content: '▼'; position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
  color: #ffd24a; font-size: 14px; text-shadow: 0 0 8px #ffd24a;
  animation: tileArrow .8s ease-in-out infinite alternate;
}
@keyframes tileArrow { to { top: -16px; } }
