/* =========================================================
   Componentes compartidos por laboratorio y taller:
   tablero, entidades, editor de código y mensajes.
   ========================================================= */

/* ---------- tablero (--w y --h se fijan desde JS) ---------- */
.board {
  display: grid;
  grid-template-columns: 1.6em minmax(0, 1fr);
  gap: 4px 6px;
  font: 600 .78rem var(--font-head);
  color: var(--muted);
}
.field {
  position: relative;
  aspect-ratio: var(--w) / var(--h);
  border: var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  background: #9BDD5E;
  container-type: inline-size;
}
.cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--w), 1fr);
  grid-template-rows: repeat(var(--h), 1fr);
}
.cell { position: relative; box-shadow: inset 0 -3px 0 rgba(26, 26, 26, .06); }
.cell.alt { background: #8DD24F; }
.cell.wall {
  background:
    linear-gradient(var(--ink), var(--ink)) 50% 50% / 100% 2.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 30% 0 / 2.5px 50% no-repeat,
    linear-gradient(var(--ink), var(--ink)) 70% 100% / 2.5px 50% no-repeat,
    #B8C2D1;
  box-shadow: inset 0 0 0 2.5px var(--ink), inset 0 -8px 0 #8592A6;
}
.cell.mark::after {
  content: "✖";
  position: absolute;
  inset: 12%;
  display: grid;
  place-items: center;
  color: var(--red);
  border: 3px dashed var(--red);
  border-radius: 10px;
  font-size: calc(100cqw / var(--w) * .38);
  font-weight: 900;
}
.ylabels { display: grid; grid-template-rows: repeat(var(--h), 1fr); align-items: center; text-align: right; }
.xlabels { display: grid; grid-template-columns: repeat(var(--w), 1fr); text-align: center; padding-top: 4px; }
.axis-note { grid-column: 2; font-weight: 600; }

/* ---------- entidades ---------- */
.ents { position: absolute; inset: 0; pointer-events: none; }
.ent { position: absolute; display: flex; align-items: center; justify-content: center; transition: left .22s ease, top .22s ease; z-index: 2; }
.ent .extra { position: absolute; inset: 0; }
.ent.hero { z-index: 4; }
.ent.flag, .ent.item { z-index: 1; }
.ent::before {
  content: "";
  position: absolute;
  bottom: 8%;
  left: 22%;
  right: 22%;
  height: 12%;
  border-radius: 50%;
  background: rgba(26, 26, 26, .2);
}
.ent .sp { position: relative; width: 76%; height: 76%; display: flex; align-items: center; justify-content: center; }
.ent .sp .ico { width: 100%; height: 100%; }
.ent.item .sp { animation: float 2.2s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6%); } }
/* La mascota es más grande que la casilla y apoya los pies abajo. */
.ent .sp .mascot {
  position: absolute;
  width: 170%;
  bottom: -4%;
  left: -35%;
}
.ent .badge {
  position: absolute;
  right: 2%;
  top: 2%;
  width: 34%;
  height: 34%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.ent .badge .ico { width: 78%; height: 78%; }
.ent .tag {
  position: absolute;
  bottom: -2%;
  left: 50%;
  transform: translateX(-50%);
  font: 600 calc(100cqw / var(--w) * .17) var(--font-head);
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0 6px;
  white-space: nowrap;
}
.ent .hp {
  position: absolute;
  top: 0;
  left: 16%;
  right: 16%;
  height: 9%;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}
.ent .hp i { display: block; height: 100%; background: var(--green); transition: width .2s; }
.ent .bubble {
  position: absolute;
  bottom: 118%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper);
  color: var(--ink);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 2px 10px;
  font: 600 .85rem var(--font-head);
  white-space: nowrap;
  box-shadow: 0 3px 0 var(--ink);
  z-index: 6;
  max-width: 60cqw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ent.hit .sp { animation: hit .3s; }
.ent.bump .sp { animation: bump .3s; }
@keyframes hit {
  25% { transform: translateX(-14%) rotate(-10deg); }
  75% { transform: translateX(14%) rotate(10deg); }
}
@keyframes bump { 50% { transform: scale(.85); } }
.field.win { animation: win 1s; }
@keyframes win { 30% { box-shadow: 0 0 0 10px var(--yellow), var(--shadow); } }

/* ---------- editor ---------- */
.editor-card { background: var(--code-bg); }
.editor-card .card-head { padding: 10px 14px; gap: 10px; }
.editor-card .dots { display: flex; gap: 6px; }
.editor-card .dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.editor-card .dots i:nth-child(1) { background: var(--red); }
.editor-card .dots i:nth-child(2) { background: var(--yellow); }
.editor-card .dots i:nth-child(3) { background: var(--green); }
.editor-card .file { margin-left: auto; }
.editor {
  --editor-h: 300px; /* el gutter y el textarea comparten altura */
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  background: var(--code-bg);
}
.editor:focus-within { box-shadow: inset 0 0 0 3px var(--yellow); }
.gutter {
  height: var(--editor-h);
  padding: 12px 4px 12px 8px;
  color: #64748B;
  text-align: right;
  font: 500 .9rem/1.6 var(--font-code);
  user-select: none;
  overflow: hidden;
  border-right: 2px solid #334155;
}
.gutter span { display: block; padding: 0 6px; border-radius: 6px; }
.gutter .on { background: var(--yellow); color: var(--ink); }
.gutter .err { background: var(--red); color: #fff; }
.editor textarea {
  height: var(--editor-h);
  padding: 12px 14px;
  background: transparent;
  color: var(--code-ink);
  border: 0;
  resize: none;
  font: 500 .9rem/1.6 var(--font-code);
  outline: none;
  white-space: pre;
  overflow: auto;
  tab-size: 4;
  caret-color: var(--yellow);
}

/* ---------- controles y mensajes ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.msg {
  position: relative;
  margin-top: 16px;
  padding: 12px 16px;
  min-height: 3.2em;
  background: var(--paper);
  border: var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}
.msg.err { background: var(--red-soft); }
.msg.win { background: var(--green-soft); }
.msg.info { background: var(--yellow-soft); }
.msg .btn { margin-top: 10px; margin-right: 8px; }
.hintline { font-size: .9rem; color: var(--muted); margin: 10px 2px 0; }

/* Mascota que comenta (globo con pico) */
.talk { display: flex; gap: 6px; align-items: flex-end; margin-top: 16px; }
.talk .mascot { width: 96px; margin-bottom: -4px; }
.talk .msg { flex: 1; margin-top: 0; }
.talk .msg::before {
  content: "";
  position: absolute;
  left: -12px;
  bottom: 22px;
  width: 18px;
  height: 18px;
  background: inherit;
  border-left: var(--border);
  border-bottom: var(--border);
  transform: rotate(45deg);
}
