* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

button, input, .room-badge { touch-action: manipulation; }

:root {
  --bg: #0d0f13;
  --panel: #14171d;
  --panel-2: #1b1f27;
  --border: #262b35;
  --border-soft: #1f242e;
  --text: #e9ecf2;
  --muted: #8b93a3;
  --accent: #f0b429;
  --accent-dark: #1a1503;
  --danger: #e5484d;
  --ok: #4cc38a;
  --radius: 14px;
  --font-body: "Inter", system-ui, sans-serif;
  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(240, 180, 41, .06), transparent 60%),
    radial-gradient(700px 500px at 0% 100%, rgba(76, 195, 138, .04), transparent 60%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }

.screen { display: none; height: 100vh; height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

h1, h2, h3, .brand-name, .big-letter, .basta-banner, .pane-kicker { font-family: var(--font-display); }

/* ================= inicio ================= */
#screen-home.active { align-items: center; justify-content: center; position: relative; }

/* letras flotantes de fondo */
.bg-letters {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.bg-letters span {
  position: absolute;
  bottom: -12vh;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
  animation: floatUp linear infinite;
  will-change: transform, opacity;
}
@keyframes floatUp {
  0%   { transform: translateY(0) rotate(var(--rot0, -8deg)); opacity: 0; }
  12%  { opacity: var(--op, .08); }
  85%  { opacity: var(--op, .08); }
  100% { transform: translateY(-115vh) rotate(var(--rot1, 10deg)); opacity: 0; }
}

.home-card { position: relative; z-index: 1; }

.home-card {
  background: var(--panel);
  padding: 42px 38px 30px;
  border-radius: 20px;
  width: min(420px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
  animation: rise .5s cubic-bezier(.2, .9, .3, 1) both;
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.brand-mark {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), #d18f11);
  color: var(--accent-dark);
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(240, 180, 41, .25);
}
.brand-mark { animation: markTilt 5s ease-in-out infinite; }
@keyframes markTilt {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(4deg) translateY(-3px); }
}
.brand-name {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.5px;
  background: linear-gradient(100deg, var(--text) 40%, var(--accent) 50%, var(--text) 60%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 4.5s ease-in-out infinite;
}
@keyframes shimmer {
  0%, 30% { background-position: 120% 0; }
  70%, 100% { background-position: -60% 0; }
}
.brand-sub { color: var(--muted); font-size: .85rem; }

.field-label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}

input[type="text"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 14px;
  color: var(--text);
  font-size: 16px; /* evita zoom al enfocar en iOS */
  font-family: var(--font-body);
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240, 180, 41, .12); }

#inp-code { text-transform: uppercase; letter-spacing: 8px; text-align: center; font-weight: 700; }

/* botones */
.btn {
  border: none;
  border-radius: 10px;
  padding: 13px 20px;
  font-size: .95rem;
  font-weight: 700;
  font-family: var(--font-body);
  letter-spacing: .3px;
  cursor: pointer;
  transition: transform .08s, filter .15s, box-shadow .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(145deg, var(--accent), #dd9c15);
  color: var(--accent-dark);
  box-shadow: 0 6px 20px rgba(240, 180, 41, .22);
  position: relative;
  overflow: hidden;
}
/* destello que barre el botón principal */
.btn.primary::after {
  content: "";
  position: absolute;
  top: 0; left: -80%;
  width: 45%; height: 100%;
  background: linear-gradient(105deg, transparent, rgba(255, 255, 255, .45), transparent);
  transform: skewX(-20deg);
  animation: sweep 3.2s ease-in-out infinite;
}
@keyframes sweep {
  0%, 55% { left: -80%; }
  85%, 100% { left: 130%; }
}
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 8px 26px rgba(240, 180, 41, .3); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--muted); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
.btn.small { padding: 8px 14px; font-size: .8rem; }
.btn.big { padding: 15px 34px; font-size: 1.05rem; }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }

.btn.basta {
  background: linear-gradient(145deg, var(--danger), #c22d33);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 4px;
  padding: 16px 20px;
  width: 100%;
  margin-top: 16px;
  box-shadow: 0 6px 22px rgba(229, 72, 77, .25);
}
.btn.basta:not(:disabled):hover { box-shadow: 0 8px 30px rgba(229, 72, 77, .4); }
/* cuando se habilita, el basta pide atención */
.btn.basta.ready { animation: readyPulse 1.1s ease-in-out infinite; }
@keyframes readyPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 6px 22px rgba(229, 72, 77, .25); }
  50% { transform: scale(1.025); box-shadow: 0 10px 34px rgba(229, 72, 77, .5); }
}

.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: .75rem;
  text-transform: uppercase; letter-spacing: 1px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; }

.error { color: var(--danger); text-align: center; font-size: .9rem; }

.byline {
  text-align: center;
  color: var(--muted);
  font-size: .72rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 10px;
  opacity: .7;
}

/* ================= barra superior ================= */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border-soft);
  gap: 10px;
}
.top-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.top-right { display: flex; align-items: center; gap: 14px; justify-content: flex-end; }

.logo-mini {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.3px;
  white-space: nowrap;
}

.room-badge {
  white-space: nowrap;
  background: var(--panel-2);
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 600;
  letter-spacing: 2px;
  cursor: pointer;
  border: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text);
  font-family: var(--font-body);
  transition: border-color .15s;
}
.room-badge:hover { border-color: var(--accent); }

.letter-display { display: flex; align-items: center; gap: 12px; }
.letter-label {
  color: var(--muted);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.big-letter {
  background: linear-gradient(145deg, var(--accent), #d18f11);
  color: var(--accent-dark);
  font-size: 1.5rem;
  font-weight: 700;
  width: 46px; height: 46px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(240, 180, 41, .25);
}
.big-letter.pop { animation: letterPop .5s cubic-bezier(.2, 1.4, .4, 1); }

.round-display {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  white-space: nowrap;
}

/* timer con anillo de progreso */
.timer { position: relative; width: 48px; height: 48px; }
.timer svg { width: 48px; height: 48px; transform: rotate(-90deg); }
.timer .ring-bg { fill: none; stroke: var(--border); stroke-width: 4; }
.timer .ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 125.7;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset .25s linear, stroke .3s;
}
.timer.low .ring { stroke: var(--danger); }
.timer.low #timer-num { color: var(--danger); animation: pulse 1s infinite; }
#timer-num {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: .95rem;
  font-variant-numeric: tabular-nums;
}

/* barra de tiempo bajo el topbar */
.timebar { height: 3px; background: var(--border-soft); }
#timebar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #d18f11);
  transition: width .25s linear;
}
.timebar.low #timebar-fill { background: var(--danger); }

/* ================= layout ================= */
.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 250px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}
.content-panel, .players-panel { min-width: 0; }

.content-panel {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  padding: 26px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.players-panel {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.players-panel h3 {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 12px;
}

#player-list { list-style: none; overflow-y: auto; }
#player-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  font-size: .9rem;
  animation: fadeIn .25s both;
}
#player-list li.disconnected { opacity: .35; }
#player-list li .score {
  margin-left: auto;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
#player-list li.me .name { color: var(--ok); }

.avatar {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  color: #0d0f13;
  flex-shrink: 0;
}
.host-tag {
  font-size: .58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  border: 1px solid rgba(240, 180, 41, .4);
  border-radius: 5px;
  padding: 2px 5px;
}

/* ================= paneles ================= */
.pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 660px;
  margin: 0 auto;
  animation: rise .35s cubic-bezier(.2, .9, .3, 1) both;
}
.pane h2 { text-align: center; font-size: 1.5rem; letter-spacing: -.3px; }
.pane-kicker {
  text-align: center;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2.5px;
}

#pane-lobby { text-align: center; align-items: center; }

.code-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 40px;
}
.code-label { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: 1.5px; }
#lobby-code {
  color: var(--accent);
  letter-spacing: 12px;
  font-size: 2.2rem;
  font-family: var(--font-display);
  text-indent: 12px;
}

.rules { display: flex; flex-direction: column; gap: 10px; width: 100%; text-align: left; }
.rule {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: .88rem;
}
.rule-n {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent);
  font-size: .95rem;
}

/* formulario */
.answer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.answer-row { display: flex; flex-direction: column; gap: 6px; }
.answer-row label {
  font-size: .68rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.answer-row input.filled { border-color: rgba(76, 195, 138, .5); }
.answer-row input:disabled { opacity: .55; }

/* banner basta */
.basta-banner {
  position: sticky;
  bottom: 0;
  margin: 10px auto 0;
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(145deg, var(--danger), #c22d33);
  color: #fff;
  border-radius: 12px;
  padding: 12px 26px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 1px;
  width: fit-content;
  max-width: 100%;
  box-shadow: 0 10px 30px rgba(229, 72, 77, .35);
  animation: slideUp .3s cubic-bezier(.2, .9, .3, 1) both;
}
.basta-count {
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  min-width: 1.2em;
  text-align: center;
  animation: pulse 1s infinite;
}

/* presentación de ronda */
.round-intro {
  position: absolute;
  inset: 0;
  background: rgba(13, 15, 19, .92);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 8;
  pointer-events: none;
  animation: fadeIn .25s both;
}
.round-intro.leaving { animation: fadeOut .35s both; }
#ov-round-label {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 3px;
}
#ov-round-letter {
  font-family: var(--font-display);
  font-size: 7rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  animation: letterPop .55s cubic-bezier(.2, 1.4, .4, 1) both .1s;
}
.round-intro-hint { color: var(--muted); font-size: .9rem; }

/* revisión */
#review-table { display: flex; flex-direction: column; gap: 14px; }
.review-cat {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 14px 16px;
  animation: rise .35s both;
}
.review-cat h4 {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 10px;
}
.review-answers { display: flex; flex-direction: column; gap: 6px; }

.answer-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .9rem;
  cursor: default;
  animation: fadeIn .3s both;
  transition: border-color .15s, background .15s;
}
.answer-chip.votable { cursor: pointer; }
.answer-chip.votable:hover { border-color: var(--danger); transform: translateX(3px); }
.answer-chip { transition: border-color .15s, background .15s, transform .15s; }
.answer-chip .who { color: var(--muted); font-size: .75rem; min-width: 74px; font-weight: 600; }
.answer-chip .word { font-weight: 600; flex: 1; word-break: break-word; }
.answer-chip .pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.answer-chip.s-unique .pts { color: var(--ok); }
.answer-chip.s-dup .pts { color: var(--accent); }
.answer-chip.s-empty .word, .answer-chip.s-wrongLetter .word { color: var(--muted); font-style: italic; font-weight: 400; }
.answer-chip.s-rejected .word { text-decoration: line-through; color: var(--danger); }
.answer-chip .flag {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--danger);
  border: 1px solid rgba(229, 72, 77, .35);
  border-radius: 5px;
  padding: 2px 6px;
  white-space: nowrap;
}
.answer-chip.voted { border-color: var(--danger); background: rgba(229, 72, 77, .07); }

.round-totals { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.round-totals span {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: .85rem;
}
.round-totals strong { color: var(--accent); font-variant-numeric: tabular-nums; }

/* podio */
#podium { list-style: none; display: flex; flex-direction: column; gap: 10px; align-self: center; width: min(420px, 100%); }
#podium li {
  background: var(--panel-2);
  padding: 14px 20px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border-soft);
  animation: rise .4s both;
}
#podium li:first-child {
  border-color: rgba(240, 180, 41, .5);
  background: linear-gradient(145deg, rgba(240, 180, 41, .1), var(--panel-2) 60%);
}
.rank {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--muted);
  font-size: 1rem;
  width: 28px;
}
#podium li:first-child .rank { color: var(--accent); }
#podium .p-name { flex: 1; font-weight: 600; }
#podium .p-score { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }
.winner-tag {
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent-dark);
  background: var(--accent);
  border-radius: 5px;
  padding: 3px 8px;
}

/* ================= marca de agua ================= */
.watermark {
  position: sticky;
  top: 100%;
  float: right;
  margin-top: 12px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(240, 180, 41, .45);
  pointer-events: none;
  user-select: none;
}

/* vibración de urgencia en los últimos segundos de escritura */
body.urgent::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  box-shadow: inset 0 0 120px rgba(229, 72, 77, .18);
  animation: urgentGlow 1s ease-in-out infinite;
}
@keyframes urgentGlow {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

/* confeti del podio */
.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 45;
  width: 100vw;
  height: 100vh;
}

/* ================= toast ================= */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: .88rem;
  padding: 11px 22px;
  border-radius: 10px;
  z-index: 50;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
  max-width: 92vw;
  text-align: center;
  animation: slideUp .25s both;
}

/* ================= animaciones ================= */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.basta-banner { animation-name: bannerUp; }
@keyframes bannerUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes letterPop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ================= responsive ================= */
@media (max-width: 900px) {
  body { overflow-y: auto; overflow-x: hidden; }
  .screen.active { height: auto; min-height: 100vh; min-height: 100dvh; }
  .game-layout { grid-template-columns: 1fr; }
  .players-panel { order: 2; }
  .content-panel { order: 1; overflow: visible; padding: 18px; }
  #player-list { display: flex; flex-wrap: wrap; gap: 6px; }
  #player-list li { margin-bottom: 0; }
  .answer-grid { grid-template-columns: 1fr; }
  .big-letter { width: 40px; height: 40px; font-size: 1.25rem; }
  .letter-label { display: none; }
  .logo-mini { display: none; }
  .topbar { grid-template-columns: auto auto 1fr; }
  #ov-round-letter { font-size: 5rem; }
  .round-intro { position: fixed; border-radius: 0; }
  .watermark { font-size: .6rem; }
}
