/* ================================================
   BOSQUE DE LAS PALABRAS — Nuvecielas
   Estilos completamente rediseñados
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;800;900&family=Fredoka+One&display=swap');

:root {
  --bg1: #fdf4ff;
  --bg2: #f0f9ff;
  --card: rgba(255,255,255,.90);
  --ink: #1a1a2e;
  --muted: #6b7280;

  --violet: #7c3aed;
  --violet-light: #ede9fe;
  --cyan: #06b6d4;
  --cyan-light: #cffafe;
  --pink: #ec4899;
  --pink-light: #fce7f3;
  --amber: #f59e0b;
  --amber-light: #fef3c7;
  --lime: #84cc16;
  --lime-light: #ecfccb;

  /* colores por tipo de palabra */
  --col-sujeto: #7c3aed;
  --col-sujeto-bg: #ede9fe;
  --col-verbo: #0891b2;
  --col-verbo-bg: #cffafe;
  --col-cosa: #d97706;
  --col-cosa-bg: #fef3c7;
  --col-lugar: #16a34a;
  --col-lugar-bg: #dcfce7;
  --col-adj: #db2777;
  --col-adj-bg: #fce7f3;

  --shadow: 0 16px 50px rgba(0,0,0,.10);
  --shadow2: 0 10px 24px rgba(124,58,237,.12);
  --radius: 24px;
  --border: 1px solid rgba(0,0,0,.06);

  --font-display: 'Fredoka One', 'Nunito', cursive;
  --font-body: 'Nunito', 'Segoe UI', Roboto, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* Garantiza que [hidden] siempre oculte, sin importar otras reglas de display */
[hidden] { display: none !important; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 900px 600px at 10% 5%, rgba(167,139,250,.22) 0%, transparent 60%),
    radial-gradient(ellipse 800px 600px at 92% 10%, rgba(56,189,248,.20) 0%, transparent 55%),
    radial-gradient(ellipse 700px 500px at 15% 92%, rgba(132,204,22,.15) 0%, transparent 55%),
    radial-gradient(ellipse 750px 550px at 88% 88%, rgba(245,158,11,.15) 0%, transparent 55%),
    linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 100%);
  overflow-x: hidden;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle, rgba(124,58,237,.10) 1px, transparent 1px),
    radial-gradient(circle, rgba(6,182,212,.08) 1px, transparent 1px);
  background-size: 52px 52px, 78px 78px;
  background-position: 0 0, 26px 26px;
  animation: bgFloat 25s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}

@keyframes bgFloat {
  from { transform: translate(0, 0); opacity: .4; }
  to   { transform: translate(10px, 15px); opacity: .7; }
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 1060px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: var(--border);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.9);
  border-radius: 20px;
  padding: 10px 16px;
  position: relative;
  z-index: 10;
}

.topbar::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 21px;
  background: linear-gradient(135deg,
    rgba(124,58,237,.30),
    rgba(6,182,212,.22),
    rgba(236,72,153,.20),
    rgba(245,158,11,.18)
  );
  z-index: -1;
  pointer-events: none;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; }

.brand-img {
  width: 100%;
  max-width: 280px;
  height: auto;
  display: block;
  object-fit: contain;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,.05);
  box-shadow: 0 6px 14px rgba(0,0,0,.08);
}

/* ===== HUD ===== */
.hud {
  display: flex;
  gap: 8px 14px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  align-items: center;
  font-weight: 700;
}

.hud strong { color: var(--ink); font-weight: 900; }

/* Contenedor de la barra de tiempo (fuera del hud, en el topbar) */
.time-bar-wrap {
  width: 100%;
  height: 7px;
  background: rgba(0,0,0,.07);
  border-radius: 999px;
  overflow: hidden;
  display: none;
  margin-top: 4px;
  order: 10;
}
.time-bar-wrap.active { display: block; }

.time-bar {
  height: 100%;
  border-radius: 999px;
  width: 100%;
  background: linear-gradient(90deg, #10b981, #34d399);
  transition: width .25s linear, background .5s ease;
}
.time-bar.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.time-bar.danger {
  background: linear-gradient(90deg, #ef4444, #f87171);
  animation: timePulse .4s ease-in-out infinite alternate;
}
@keyframes timePulse {
  from { opacity: .75; }
  to   { opacity: 1; box-shadow: 0 0 8px rgba(239,68,68,.55); }
}

/* Badges de score y racha */
.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(124,58,237,.10);
  border: 1px solid rgba(124,58,237,.16);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 900;
  color: var(--violet);
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(245,158,11,.12);
  border: 1px solid rgba(245,158,11,.22);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 900;
  color: #92400e;
  transition: transform .2s;
}
.streak-badge.pop { animation: streakPop .3s ease-out; }
@keyframes streakPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ===== Cards ===== */
.card {
  margin-top: 14px;
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1.5px;
  background: linear-gradient(135deg,
    rgba(124,58,237,.25),
    rgba(6,182,212,.20),
    rgba(236,72,153,.18),
    rgba(245,158,11,.14)
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.title {
  margin: 0 0 6px 0;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  background: linear-gradient(135deg, var(--violet), var(--pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin: 0 0 16px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

/* ===== Grid personajes ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.char {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 12px 14px;
  border-radius: 20px;
  border: 2px solid rgba(0,0,0,.06);
  background: rgba(255,255,255,.94);
  cursor: pointer;
  user-select: none;
  box-shadow: 0 6px 18px rgba(0,0,0,.06);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
  position: relative;
  overflow: hidden;
  text-align: center;
}

.char::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(260px 160px at 50% -10%, rgba(124,58,237,.08), transparent 70%);
  pointer-events: none;
}

.char:hover {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 18px 36px rgba(124,58,237,.16);
  border-color: rgba(124,58,237,.22);
}

.char[aria-selected="true"] {
  border-color: var(--violet);
  border-width: 2.5px;
  box-shadow: 0 18px 36px rgba(124,58,237,.24), 0 0 0 4px rgba(124,58,237,.10);
  background: rgba(237,233,254,.55);
}

.char[aria-selected="true"]::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 12px;
  width: 22px;
  height: 22px;
  background: var(--violet);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  z-index: 2;
  line-height: 22px;
  text-align: center;
}

.avatar {
  width: 96px;
  height: 108px;
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(124,58,237,.07), rgba(6,182,212,.07));
  box-shadow: 0 6px 18px rgba(124,58,237,.10);
  flex: 0 0 auto;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .3s ease;
}

.char:hover .avatar img { transform: scale(1.07) translateY(-4px); }

.char .meta { display: flex; flex-direction: column; gap: 3px; }
.char .name  { font-family: var(--font-display); font-size: 17px; font-weight: 400; color: var(--violet); }
.char .desc  { font-size: 12px; color: var(--muted); font-weight: 700; }

.char .skill-tag {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--violet-light);
  color: var(--violet);
  margin-top: 2px;
  align-self: center;
}

/* ===== Inputs / Buttons ===== */
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
}

.label { font-size: 13px; color: var(--muted); font-weight: 700; }

.input {
  flex: 1 1 220px;
  border-radius: 16px;
  border: 1.5px solid rgba(0,0,0,.10);
  padding: 12px 16px;
  font-weight: 800;
  font-size: 16px;
  font-family: var(--font-body);
  background: rgba(255,255,255,.94);
  box-shadow: 0 4px 10px rgba(0,0,0,.04);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  color: var(--ink);
}
.input:focus {
  border-color: rgba(124,58,237,.45);
  box-shadow: 0 0 0 4px rgba(124,58,237,.09);
}

button {
  font-family: var(--font-body);
  border-radius: 16px;
  border: 1.5px solid rgba(0,0,0,.10);
  padding: 11px 16px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 4px 12px rgba(0,0,0,.05);
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease;
  position: relative;
}

button:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(0,0,0,.10); }
button:active { transform: translateY(0); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.primary {
  border: none;
  color: #fff;
  background: linear-gradient(135deg, #7c3aed 0%, #ec4899 60%, #06b6d4 100%);
  box-shadow: 0 10px 26px rgba(124,58,237,.28);
}
.primary:hover { box-shadow: 0 14px 32px rgba(124,58,237,.36); filter: brightness(1.05); }

.ghost { background: rgba(255,255,255,.76); }

.note       { margin-top: 10px; font-size: 12px; color: var(--muted); font-weight: 700; }
.note.small { font-size: 11px; opacity: .75; }

/* ===== Game card ===== */
#gameWrap { flex: 1 1 auto; min-height: 0; }

#gameWrap.card.game {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
}

#gameWrap #canvas {
  width: 100%;
  display: block;
  height: min(70vh, 700px);
  max-height: 72vh;
  border-radius: 18px;
  border: 1px solid rgba(0,0,0,.05);
  box-shadow: 0 20px 50px rgba(0,0,0,.12), 0 0 0 6px rgba(124,58,237,.07);
  touch-action: none;
}

/* Story */
.story {
  background: rgba(255,255,255,.76);
  border-radius: 18px;
  border: 1px solid rgba(0,0,0,.06);
  padding: 14px 16px;
  box-shadow: 0 4px 14px rgba(0,0,0,.05);
}

.story-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}

.story-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 400;
  color: var(--violet);
}

.story-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  margin-top: 3px;
}

.story-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.story-actions button { padding: 7px 12px; font-size: 12px; border-radius: 12px; }

#promptLine  { font-weight: 900; color: var(--violet); }
#templateLine { font-weight: 900; color: var(--cyan); }

#storyText {
  font-weight: 800;
  line-height: 1.7;
  font-size: 15px;
  margin-top: 10px;
  min-height: 2.4em;
  color: var(--ink);
}

/* ===== End overlay ===== */
#endOverlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 5, 30, .60);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 20px;
  animation: overlayIn .3s ease-out;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.end-card {
  background: rgba(255,255,255,.97);
  border-radius: 28px;
  padding: 32px 34px;
  max-width: 540px;
  width: 100%;
  box-shadow: 0 40px 80px rgba(0,0,0,.28), 0 0 0 1.5px rgba(124,58,237,.15);
  position: relative;
  overflow: hidden;
  animation: cardIn .42s cubic-bezier(.175,.885,.32,1.275);
}

@keyframes cardIn {
  from { opacity: 0; transform: scale(.86) translateY(28px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.end-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, rgba(124,58,237,.05) 0%, rgba(236,72,153,.04) 50%, rgba(6,182,212,.04) 100%);
  pointer-events: none;
}

.end-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 400;
  background: linear-gradient(135deg, var(--violet), var(--pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0 0 6px 0;
  line-height: 1.2;
}

.end-sub {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  margin: 0 0 16px 0;
}

.end-score {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.end-score-item {
  flex: 1;
  min-width: 90px;
  background: linear-gradient(135deg, rgba(124,58,237,.07), rgba(236,72,153,.04));
  border: 1px solid rgba(124,58,237,.13);
  border-radius: 16px;
  padding: 12px 12px;
  text-align: center;
}

.end-score-item .score-val {
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--violet);
  line-height: 1;
}

.end-score-item .score-lbl {
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.end-record {
  font-size: 12px;
  color: var(--amber);
  font-weight: 900;
  margin-top: 3px;
}

.end-story {
  font-weight: 800;
  line-height: 1.7;
  font-size: 14px;
  color: var(--ink);
  background: rgba(124,58,237,.04);
  border-radius: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(124,58,237,.09);
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.end-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.end-actions button { flex: 1; min-width: 100px; }

/* ===== Confetti canvas ===== */
#confettiCanvas {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* ===== Dialog ===== */
.dialog {
  border: none;
  border-radius: 24px;
  padding: 24px 28px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(0,0,0,.06);
  max-width: 520px;
  font-family: var(--font-body);
}
.dialog::backdrop { background: rgba(0,0,0,.40); backdrop-filter: blur(4px); }
.dialog h2 { font-family: var(--font-display); font-weight: 400; font-size: 22px; margin: 0 0 14px; color: var(--violet); }
.dialog ul { margin: 8px 0 16px 18px; color: var(--muted); font-weight: 700; line-height: 1.8; }
.dialog li { margin-bottom: 4px; }

/* ===== Toast record ===== */
.record-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #78350f;
  font-weight: 900;
  font-size: 15px;
  font-family: var(--font-body);
  padding: 10px 24px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(245,158,11,.35);
  z-index: 2000;
  transition: transform .4s cubic-bezier(.175,.885,.32,1.275), opacity .3s;
  opacity: 0;
  pointer-events: none;
}
.record-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ===== Footer ===== */
.footer {
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  opacity: .65;
  font-weight: 700;
}

/* ===== Mobile ===== */
@media (max-width: 640px) {
  .wrap { padding: 10px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .brand { justify-content: space-between; }
  .brand-img { max-width: 100%; max-height: 120px; }
  .hud { width: 100%; justify-content: space-between; font-size: 12px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .avatar { width: 76px; height: 86px; }
  .char .name { font-size: 15px; }
  #gameWrap #canvas { height: 55vh; max-height: 58vh; }
  .end-card { padding: 22px 18px; }
  .end-title { font-size: 26px; }
  .footer { display: none; }
}
