/* ===========================================================================
   La Plaza — estilos
   Dos pantallas: acceso (lobby) y mundo (plaza). El mundo es un canvas a pantalla
   completa; todo lo demás flota encima.
   =========================================================================== */

:root {
  --bg: #10141c;
  --bg-soft: #181e2a;
  --bg-card: #1c2331;
  --line: #2b3547;
  --text: #e8ecf4;
  --text-dim: #94a0b8;
  --accent: #4a9eff;
  --accent-soft: #8fe3ff;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body { overflow: hidden; }

.screen { position: fixed; inset: 0; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ lobby -- */

.lobby {
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
  background:
    radial-gradient(1100px 600px at 50% -10%, #23324a 0%, transparent 60%),
    var(--bg);
}

.lobby__card {
  width: min(880px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 30px;
}

.lobby__head h1 {
  margin: 0 0 6px;
  font-size: 30px;
  letter-spacing: -0.5px;
}

.lobby__head p {
  margin: 0 0 24px;
  color: var(--text-dim);
  max-width: 56ch;
}

.lobby__grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 28px;
  align-items: start;
}

@media (max-width: 720px) {
  .lobby__grid { grid-template-columns: 1fr; }
  .lobby__card { padding: 22px; }
}

.lobby__foot {
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-dim);
}

.lobby__foot a { color: var(--accent); text-decoration: none; }
.lobby__foot a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- preview -- */

.preview { display: grid; gap: 10px; }

.preview__stage {
  position: relative;
  aspect-ratio: 220 / 300;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(180deg, #6d9b5c, #c9bda6 72%);
  border: 1px solid var(--line);
}

.preview__stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.preview__idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 6px;
  background: rgba(16, 20, 28, 0.72);
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px;
}

.preview__icon { font-size: 30px; }
.preview__idle p { margin: 0; }

/* ------------------------------------------------------------------ forms -- */

.form { display: grid; gap: 16px; }

.field {
  display: grid;
  gap: 6px;
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.field__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 0;
}

.field__hint { font-size: 12px; color: var(--text-dim); }

.field__input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
}

.field__input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.colors { display: flex; flex-wrap: wrap; gap: 9px; }

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease;
}

.swatch:hover { transform: scale(1.08); }

.swatch[aria-checked="true"] {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.45);
}

.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------- voz (lobby) -- */

.voice-setup {
  grid-column: 1 / -1;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.check {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.check b { display: block; font-size: 14px; }
.check small { display: block; color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }

.voice-setup__warn {
  margin: 0;
  padding: 9px 12px;
  border-radius: 9px;
  background: #43350f;
  color: #fde68a;
  font-size: 12.5px;
  line-height: 1.5;
}

/* ---------------------------------------------------------------- botones -- */

.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, opacity 0.15s ease;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.btn--primary { background: var(--accent); color: #08131f; }

.btn--ghost {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--line);
}

.msg { margin: 0; font-size: 13px; min-height: 1.2em; color: var(--text-dim); }
.msg--bad { color: var(--bad); }
.msg--ok { color: var(--ok); }
.msg--warn { color: var(--warn); }

/* ------------------------------------------------------------------ plaza -- */

.plaza { background: #10141c; }

.plaza__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* -------------------------------------------------------------------- hud -- */

.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  pointer-events: none;
}

.hud__left, .hud__right { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  pointer-events: auto;
  background: rgba(16, 20, 28, 0.78);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.chip--action { cursor: pointer; font: inherit; font-size: 13px; }
.chip--action:hover { background: rgba(40, 52, 72, 0.9); }
.chip--action:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.chip--ok { color: var(--ok); }
.chip--warn { color: var(--warn); }
.chip--bad { color: var(--bad); }

/* El micrófono abierto tiene que ser inconfundible: transmitir sin darse cuenta
   es el peor error posible en una herramienta así. */
.chip--mic[aria-pressed="true"] {
  background: #1d4d33;
  border-color: #2f7f52;
  color: #86efac;
}

.chip--mic[aria-pressed="true"]::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #4ade80;
  animation: pulse 1.6s ease-in-out infinite;
  vertical-align: middle;
}

.chip[aria-pressed="true"]:not(.chip--mic) {
  background: #4a3a12;
  border-color: #78591a;
  color: #fde68a;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .chip--mic[aria-pressed="true"]::before { animation: none; }
}

/* --------------------------------------------------------------- acciones -- */

.actions {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.actions__group {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.act {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(16, 20, 28, 0.82);
  backdrop-filter: blur(8px);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.act:hover { background: rgba(44, 58, 80, 0.92); }
.act:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.act__icon { font-size: 16px; line-height: 1; }

.act[aria-pressed="true"] {
  background: #1d3a5c;
  border-color: var(--accent);
  color: var(--accent-soft);
}

/* Las contextuales se distinguen: aparecen y desaparecen según dónde estés, y
   conviene que se lean como algo distinto de las acciones siempre disponibles. */
.act--context {
  background: rgba(30, 44, 26, 0.88);
  border-color: rgba(140, 220, 120, 0.35);
}

.act--context:hover { background: rgba(44, 66, 38, 0.94); }

.act--waiting {
  background: rgba(74, 58, 18, 0.9);
  border-color: #a8801e;
  color: #fde68a;
}

@media (max-width: 620px) {
  /* En pantalla angosta las etiquetas no caben junto al chat: quedan los íconos,
     que con el title siguen siendo descubribles. */
  .act__label { display: none; }
  .act { padding: 10px 12px; }
}

/* ------------------------------------------------------------------ stats -- */

.stats {
  position: absolute;
  top: 58px;
  right: 14px;
  width: 260px;
  background: rgba(16, 20, 28, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 13px;
}

.stats h2 { margin: 0 0 10px; font-size: 14px; }

.stats dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
}

.stats dt { color: var(--text-dim); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.stats__note {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 12px;
}

/* ------------------------------------------------------------------- chat -- */

.badge {
  display: inline-block;
  min-width: 17px;
  padding: 0 5px;
  margin-left: 3px;
  border-radius: 9px;
  background: var(--accent);
  color: #08131f;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  line-height: 17px;
}

.chat {
  position: absolute;
  bottom: 14px;
  left: 14px;
  width: min(330px, calc(100% - 28px));
  max-height: min(58vh, 460px);
  display: flex;
  flex-direction: column;
  background: rgba(16, 20, 28, 0.93);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat__title {
  margin: 0;
  padding: 11px 14px 8px;
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
}

.chat__log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 80px;
}

.chat__row { display: grid; gap: 2px; }

.chat__meta {
  display: flex;
  gap: 7px;
  align-items: baseline;
  font-size: 11.5px;
}

.chat__who { font-weight: 600; color: var(--accent-soft); }
.chat__row--self .chat__who { color: var(--ok); }
.chat__when { color: #6b7689; font-size: 10.5px; }

.chat__text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
  /* Un mensaje con una palabra larguísima no debe ensanchar el panel. */
  overflow-wrap: anywhere;
}

/* Mensaje propio aún sin confirmar por el servidor. */
.chat__row--pending { opacity: 0.55; }

.chat__form {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 10px;
  border-top: 1px solid var(--line);
}

.chat__input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}

.chat__input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chat__counter {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 18px;
  text-align: right;
}

.chat__counter--low { color: var(--warn); font-weight: 600; }

.chat__send {
  border: 0;
  border-radius: 9px;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: var(--accent);
  color: #08131f;
  font-size: 14px;
  cursor: pointer;
}

.chat__send:hover { filter: brightness(1.12); }
.chat__send:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

/* En pantallas bajas el chat competiría con la vista propia de la cámara. */
@media (max-height: 560px) {
  .chat { max-height: 46vh; }
}

/* ------------------------------------------------------------------- mapa -- */

.map {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 11, 16, 0.82);
  backdrop-filter: blur(6px);
}

.map__box {
  width: min(1000px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.map__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}

.map__head h2 { margin: 0; font-size: 16px; }

.map__close {
  border: 0;
  background: var(--bg-soft);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.map__close:hover { background: #2c3648; }
.map__close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.map__canvas {
  width: 100%;
  /* La plaza mide 2400×1400: la misma proporción evita deformar el plano. */
  aspect-ratio: 12 / 7;
  display: block;
  background: #2a3a28;
  cursor: crosshair;
  min-height: 0;
}

.map__legend {
  margin: 0;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 12.5px;
}

/* ------------------------------------------------------- hint y banner ---- */

.hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(16, 20, 28, 0.75);
  color: var(--text-dim);
  font-size: 13px;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

.hint--gone { opacity: 0; }

.banner {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 28px));
  padding: 12px 18px;
  border-radius: var(--radius);
  background: #4c1d1d;
  color: #fecaca;
  border: 1px solid #7f2d2d;
  box-shadow: var(--shadow);
  font-size: 14px;
  text-align: center;
}

.banner--warn { background: #43350f; color: #fde68a; border-color: #78591a; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
