:root {
  --bg: #16161f;
  --panel: #21212e;
  --text: #f4f4f8;
  --muted: #9494a6;
  --accent: #6c5ce7;
  --red: #e21b3c;
  --blue: #1368ce;
  --yellow: #d89e00;
  --green: #26890c;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.wrap {
  width: 100%;
  max-width: 720px;
  padding: 24px 16px 60px;
}

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; color: var(--muted); font-weight: 600; }
p.muted { color: var(--muted); }

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #3a3a4d;
  background: #14141c;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 8px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
  transition: transform .08s ease;
}
button:hover { filter: brightness(1.1); }
button:active { transform: scale(0.97); }
button.secondary { background: #3a3a4d; }
button.ghost { background: transparent; border: 1px solid #3a3a4d; }
button:disabled { opacity: .4; cursor: not-allowed; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }

.code-display {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-align: center;
  padding: 20px;
  color: var(--accent);
}

.question-editor {
  border: 1px solid #33334a;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.option-row { display: flex; align-items: center; gap: 6px; }
.option-row input[type="text"] { margin-bottom: 0; }

.player-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.player-list li { background: #14141c; padding: 6px 12px; border-radius: 20px; font-size: .9rem; }

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.answer-btn {
  aspect-ratio: 1.6;
  border-radius: var(--radius);
  color: white;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
}
.answer-btn.a { background: var(--red); }
.answer-btn.b { background: var(--blue); }
.answer-btn.c { background: var(--yellow); }
.answer-btn.d { background: var(--green); }
.answer-btn.correct { outline: 4px solid white; }
.answer-btn.wrong { opacity: .35; }

.timer-bar {
  height: 8px;
  border-radius: 4px;
  background: #33334a;
  overflow: hidden;
  margin: 10px 0;
}
.timer-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width .2s linear;
}

.leaderboard { list-style: none; padding: 0; margin: 0; }
.leaderboard li {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: #14141c;
  border-radius: 8px;
  margin-bottom: 6px;
}
.leaderboard li:first-child { border: 1px solid var(--accent); }

.center { text-align: center; }
.hidden { display: none !important; }

#qrcode { display: flex; justify-content: center; margin: 12px 0; }
#qrcode img { border-radius: 8px; }

footer { color: var(--muted); font-size: .8rem; text-align: center; margin-top: 24px; }
a { color: var(--accent); }

/* ---------- Palabra oculta ---------- */
.word-pattern { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 16px 0; }
.word-tile {
  min-width: 34px;
  height: 44px;
  border-radius: 8px;
  background: #14141c;
  border: 2px solid #3a3a4d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 800;
  padding: 0 4px;
}
.word-tile.filled { border-color: var(--accent); color: var(--accent); }
.word-tile.gap { border: none; background: transparent; min-width: 14px; }

.letter-keyboard { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 16px; }
.letter-key {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #3a3a4d;
  color: white;
  font-weight: 700;
  padding: 0;
  font-size: .95rem;
}
.letter-key.hit { background: var(--green); }
.letter-key.miss { background: var(--red); opacity: .6; }

.reveal-tiles { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 12px 0; }
.reveal-tile {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.05rem;
}

.type-select { margin-bottom: 8px; }

/* ---------- Relacionar termino-definicion (piezas de puzzle) ---------- */
.match-board { display: flex; gap: 16px; margin: 14px 0; }
.match-column { flex: 1; display: flex; flex-direction: column; gap: 8px; }

.puzzle-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(145deg, #1c1c28, #14141c);
  border: 2px solid #3a3a4d;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease;
  font-size: .92rem;
}
.puzzle-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.puzzle-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,92,231,.35); }
.puzzle-card.matched { border-color: var(--green); opacity: .4; cursor: default; pointer-events: none; }
.puzzle-card.wrong-flash { animation: puzzleWrongFlash .4s ease; }
@keyframes puzzleWrongFlash {
  0%, 100% { border-color: #3a3a4d; }
  50% { border-color: var(--red); }
}

.puzzle-tab {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
}
.def-card .puzzle-tab { box-shadow: inset 0 0 0 2px rgba(0,0,0,.45); background-color: transparent !important; border: 2px solid; }
.puzzle-card-text { flex: 1; }

.shape-triangle { clip-path: polygon(50% 0%, 0% 100%, 100% 100%); background: var(--accent); border-color: var(--accent); }
.shape-circle { border-radius: 50%; background: var(--yellow); border-color: var(--yellow); }
.shape-square { border-radius: 4px; background: var(--blue); border-color: var(--blue); }

.match-solved { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.puzzle-solved-pair {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #14141c;
  border: 2px solid var(--green);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .92rem;
}
.puzzle-solved-pair .puzzle-tab { flex: 0 0 18px; width: 18px; height: 18px; }

.match-preview-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #14141c;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: .9rem;
}

/* ---------- Puzzle de imagen (piezas arrastrables) ---------- */
.jigsaw-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1;
  margin: 14px auto;
  background: #0c0c12;
  border-radius: 10px;
  overflow: hidden;
  padding: 3px;
  box-sizing: border-box;
}
.puzzle-slot {
  background: #1c1c28;
  border: 2px dashed #3a3a4d;
  border-radius: 6px;
  position: relative;
  min-width: 0;
  min-height: 0;
}
.puzzle-slot.filled { border-style: solid; }
.puzzle-slot.correct { border-color: var(--green); }

.jigsaw-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 10px 0;
  min-height: 66px;
  padding: 8px;
  background: #14141c;
  border-radius: 10px;
}

.jigsaw-piece {
  width: 58px;
  height: 58px;
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
  border: 2px solid #3a3a4d;
  background-repeat: no-repeat;
  background-color: #0c0c12;
}
.jigsaw-piece.in-slot { width: 100%; height: 100%; border: none; border-radius: 4px; }
.jigsaw-piece.locked { cursor: default; }
.jigsaw-piece.dragging { opacity: .9; box-shadow: 0 10px 24px rgba(0,0,0,.55); border-color: var(--accent); }

.jigsaw-answer-area { margin-top: 10px; }
.jigsaw-answer-area.hidden { display: none; }

.jigsaw-mystery { text-align: center; padding: 20px 0; }
.jigsaw-mystery .big-emoji { font-size: 3rem; display: block; margin-bottom: 8px; }

/* ---------- Pizarra compartida (dibujar y adivinar) ---------- */
.drawer-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}
.drawer-picker-btn {
  background: linear-gradient(145deg, #1c1c28, #14141c);
  border: 2px solid #3a3a4d;
  color: var(--text);
  font-size: 1rem;
  padding: 14px 20px;
  border-radius: 12px;
}
.drawer-picker-btn:hover { border-color: var(--accent); filter: none; }

#draw-canvas, #draw-view-canvas, #host-draw-canvas, #draw-reveal-canvas, #feedback-draw-canvas {
  border: 2px solid #3a3a4d;
  cursor: crosshair;
}

/* ---------- Hit Bit (whack-a-mole de senales de atencion) ---------- */
.hitbit-thumb-row { display: inline-flex; flex-wrap: wrap; gap: 6px; vertical-align: middle; }
.hitbit-thumb {
  position: relative;
  display: inline-block;
}
.hitbit-thumb img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid #3a3a4d;
  display: block;
}
.hitbit-thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  padding: 0;
  line-height: 1;
  font-size: .65rem;
  border-radius: 50%;
  background: var(--red);
}

.hitbit-preview-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid #3a3a4d;
  margin-right: 4px;
}

.hitbit-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
  font-size: .9rem;
}

.hitbit-scenario-preview {
  width: 100%;
  height: 140px;
  border-radius: 10px;
  background-color: #14141c;
  background-repeat: no-repeat;
  margin-bottom: 10px;
}

/* Area de juego real (jugador): contenedor relativo donde "aparecen" los
   topos en posiciones absolutas aleatorias, calculadas en JS. */
.hitbit-scenario {
  position: relative;
  width: 100%;
  height: 320px;
  border-radius: var(--radius);
  background-color: #14141c;
  background-repeat: no-repeat;
  overflow: hidden;
  touch-action: none;
  margin-top: 12px;
}

.hitbit-hud {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  background: rgba(20,20,28,.75);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 1.05rem;
  z-index: 5;
}
.hitbit-hud > span { border-radius: 6px; padding: 2px 6px; transition: background-color .2s ease; }
.hitbit-flash-good { background: rgba(38,137,12,.75); }
.hitbit-flash-bad { background: rgba(226,27,60,.75); }

.hitbit-mole {
  position: absolute;
  border-radius: 10px;
  border: 3px solid white;
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
  cursor: pointer;
  object-fit: cover;
  animation: hitbitPop .15s ease;
  touch-action: none;
}
@keyframes hitbitPop {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
