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

button, input, .room-badge { touch-action: manipulation; } /* evita el retraso/zoom del doble-tap en iOS */

:root {
  --bg: #12141f;
  --panel: #1c1f2e;
  --panel-2: #252940;
  --text: #eef0f8;
  --muted: #8b90a8;
  --accent: #7c5cff;
  --accent-2: #ff5c8a;
  --ok: #3ddc84;
  --radius: 14px;
}

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 20% -10%, #232748 0%, var(--bg) 55%);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none; /* sin rebote elástico en iOS */
}

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

.screen { display: none; height: 100vh; height: 100dvh; } /* dvh: altura real visible en Safari iOS */
.screen.active { display: flex; flex-direction: column; }

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

.home-card {
  background: var(--panel);
  padding: 40px 36px;
  border-radius: 20px;
  width: min(400px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  border: 1px solid #2e3350;
}

.logo { font-size: 2.6rem; text-align: center; }
.logo-mini { font-weight: 700; }
.tagline { text-align: center; color: var(--muted); margin-bottom: 8px; }

input[type="text"] {
  background: var(--panel-2);
  border: 1px solid #343a5c;
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px; /* mínimo 16px: evita que iOS haga zoom al enfocar el input */
  outline: none;
  width: 100%;
}
input[type="text"]:focus { border-color: var(--accent); }

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

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5c8aff); color: #fff; }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid #343a5c; }
.btn:hover { filter: brightness(1.12); }

.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: .8rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #343a5c; }

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

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

/* ---------------- barra superior ---------------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid #2e3350;
  gap: 10px;
}
.top-left { display: flex; align-items: center; gap: 12px; }
.top-right { display: flex; align-items: center; gap: 12px; justify-content: flex-end; }

.room-badge {
  white-space: nowrap;
  background: var(--panel-2);
  padding: 5px 12px;
  border-radius: 8px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  border: 1px solid #343a5c;
  font-size: .85rem;
}
.room-badge:hover { border-color: var(--accent); }

.word-display {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 5px;
  min-height: 1.8rem;
  text-align: center;
}

.round-display { color: var(--muted); font-size: .9rem; }

.timer {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.timer.low { background: var(--accent-2); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* ---------------- layout juego ---------------- */
.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 200px 1fr 280px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.players-panel, .chat-panel, .canvas-wrap { min-width: 0; } /* evita que el canvas de 800px desborde el grid */

.players-panel, .chat-panel {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid #2e3350;
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.players-panel h3, .chat-panel h3 { font-size: .8rem; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }

#player-list { list-style: none; overflow-y: auto; }
#player-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: var(--panel-2);
  font-size: .92rem;
}
#player-list li.disconnected { opacity: .4; }
#player-list li.guessed { outline: 1px solid var(--ok); }
#player-list li .score { margin-left: auto; font-weight: 700; color: var(--accent); }
#player-list li.me .name { color: #5c8aff; }

/* ---------------- canvas ---------------- */
.canvas-wrap {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid #2e3350;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}

#board {
  background: #fff;
  border-radius: 10px;
  max-width: 100%;
  max-height: calc(100% - 60px);
  aspect-ratio: 4 / 3;
  touch-action: none;
  cursor: crosshair;
}
#board.drawing-disabled { cursor: default; }

/* ---------------- overlays ---------------- */
.overlay {
  position: absolute;
  inset: 12px;
  background: rgba(18, 20, 31, .88);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 20px;
  z-index: 5;
}
.overlay h2 { font-size: 1.5rem; }

#lobby-code { color: var(--accent); letter-spacing: 6px; font-size: 1.4rem; }

.word-options { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.word-options button {
  background: var(--panel-2);
  border: 2px solid var(--accent);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 22px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}
.word-options button:hover { background: var(--accent); }

.revealed-word { font-size: 2rem; font-weight: 800; color: var(--ok); letter-spacing: 3px; }

#podium { list-style: none; font-size: 1.15rem; display: flex; flex-direction: column; gap: 8px; }
#podium li { background: var(--panel-2); padding: 10px 26px; border-radius: 10px; min-width: 240px; display: flex; justify-content: space-between; gap: 20px; }
#podium li:first-child { border: 1px solid gold; }

/* ---------------- toolbar ---------------- */
.toolbar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid #343a5c;
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 24px);
  z-index: 6;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.colors { display: flex; gap: 5px; flex-wrap: wrap; max-width: 260px; }
.color-btn {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.color-btn.active { border-color: #fff; transform: scale(1.15); }

.sizes { display: flex; gap: 4px; }
.size-btn {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--panel);
  border: 2px solid transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.size-btn span { background: #fff; border-radius: 50%; display: block; }
.size-btn.active { border-color: var(--accent); }

.tool-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--panel);
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 1rem;
}
.tool-btn.active { border-color: var(--accent); }

/* ---------------- chat ---------------- */
#chat-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: .88rem;
  scrollbar-width: thin;
}
#chat-list li { padding: 5px 9px; border-radius: 7px; background: var(--panel-2); word-wrap: break-word; }
#chat-list li.system { background: transparent; color: var(--muted); font-style: italic; }
#chat-list li.correct { background: rgba(61, 220, 132, .15); color: var(--ok); font-weight: 700; }
#chat-list li.close { background: rgba(255, 200, 60, .12); color: #ffc83c; }
#chat-list li.whisper { background: rgba(124, 92, 255, .12); color: #b8a6ff; font-style: italic; }
#chat-list li .from { font-weight: 700; }

#chat-form input { width: 100%; }

/* ---------------- marca de agua ---------------- */
.watermark {
  position: absolute;
  right: 22px;
  bottom: 20px;
  font-size: .8rem;
  font-weight: 700;
  font-style: italic;
  color: rgba(124, 92, 255, .55);
  pointer-events: none;
  user-select: none;
  z-index: 10;
  text-shadow: 0 1px 3px rgba(0,0,0,.25);
}

.byline {
  text-align: center;
  color: var(--muted);
  font-size: .78rem;
  font-style: italic;
  margin-top: 4px;
}

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 10px 22px;
  border-radius: 10px;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  body { overflow-y: auto; overflow-x: hidden; }
  .screen.active { height: auto; min-height: 100vh; }
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 300px;
  }
  .players-panel { order: 2; }
  .canvas-wrap { order: 1; min-height: 320px; }
  .chat-panel { order: 3; }
  #player-list { display: flex; flex-wrap: wrap; gap: 6px; }
  #player-list li { margin-bottom: 0; }
  .word-display { font-size: 1.1rem; letter-spacing: 3px; }
  .colors { max-width: 160px; }
  /* que la barra de herramientas no tape el dibujo cuando te toca dibujar */
  .canvas-wrap.with-toolbar { padding-bottom: 110px; }
  .canvas-wrap.with-toolbar #board { max-height: 100%; }
  .watermark { right: 16px; bottom: 14px; font-size: .7rem; }
}
