/* TrazoLoco — tema "cuaderno de dibujo" */
:root {
  --paper: #f7f3e9;
  --paper2: #fffdf6;
  --ink: #2b2620;
  --ink-soft: #7a7060;
  --line: #ddd3bd;
  --red: #e8503a;
  --yellow: #f6c344;
  --blue: #4a90d9;
  --green: #58a55c;
  --radius: 14px;
  /* bordes "dibujados a mano": cada esquina distinta */
  --wobble: 255px 18px 225px 18px / 18px 225px 18px 255px;
  --wobble2: 18px 225px 18px 255px / 255px 18px 225px 18px;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Patrick Hand', 'Comic Sans MS', cursive, sans-serif;
  background-color: var(--paper);
  background-image: radial-gradient(var(--line) 1.1px, transparent 1.3px);
  background-size: 24px 24px;
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ---------- logo / hero ---------- */
.hero { text-align: center; padding: 3rem 1rem 1.2rem; }

.logo {
  display: inline-block;
  font-size: 3.6rem;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--ink);
  transform: rotate(-1.5deg);
  /* subrayado de resaltador */
  background: linear-gradient(transparent 62%, rgba(246, 195, 68, .75) 62%, rgba(246, 195, 68, .75) 92%, transparent 92%);
  padding: 0 .3em;
}
.logo span { color: var(--red); }
.logo-emoji { display: inline-block; animation: wiggle 2.5s ease-in-out infinite; }
.logo-small { font-size: 1.5rem; transform: rotate(-1deg); }

@keyframes wiggle {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50% { transform: rotate(10deg) scale(1.15); }
}

.tagline { color: var(--ink-soft); font-size: 1.25rem; margin-top: .8rem; transform: rotate(-.4deg); }

/* ---------- tarjeta de entrada ---------- */
.join-card {
  max-width: 430px;
  margin: 1.5rem auto;
  padding: 2rem;
  background: var(--paper2);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble);
  box-shadow: 5px 6px 0 rgba(43, 38, 32, .18);
  transform: rotate(.4deg);
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.avatar-picker { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.avatar-display {
  font-size: 3.4rem;
  width: 92px; height: 92px;
  display: grid; place-items: center;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 50% 46% 52% 48% / 48% 52% 46% 50%;
  transition: transform .15s;
  cursor: default;
}
.avatar-display.pop { animation: pop .25s; }
@keyframes pop { 50% { transform: scale(1.25) rotate(6deg); } }

.avatar-arrow {
  background: var(--paper2);
  border: 2px solid var(--ink);
  color: var(--ink);
  font-size: 1.5rem;
  width: 44px; height: 44px;
  border-radius: 48% 52% 50% 50% / 52% 48% 52% 48%;
  cursor: pointer;
  transition: transform .1s, background .15s;
  font-family: inherit;
}
.avatar-arrow:hover { background: var(--yellow); transform: scale(1.12) rotate(-4deg); }

input[type="text"] {
  padding: .8rem 1.1rem;
  border: 2px solid var(--ink);
  border-radius: var(--wobble2);
  background: #fff;
  color: var(--ink);
  font-size: 1.15rem;
  font-family: inherit;
  outline: none;
  width: 100%;
}
input[type="text"]:focus { border-color: var(--blue); box-shadow: 2px 2px 0 rgba(74, 144, 217, .35); }
input::placeholder { color: var(--ink-soft); }

.btn {
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble);
  padding: .7rem 1.3rem;
  font-size: 1.15rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--paper2);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }

.btn-primary { background: var(--yellow); }
.btn-primary:hover { background: #f8cd5e; }
.btn-secondary { background: var(--paper2); }
.btn-secondary:hover { background: #fff; }
.btn-big { font-size: 1.45rem; padding: .9rem 1.5rem; transform: rotate(-.6deg); }
.btn-big:hover { transform: rotate(-.6deg) translate(-1px, -1px); }
.btn-big:active { transform: rotate(-.6deg) translate(3px, 3px); }

.join-row { display: flex; flex-direction: column; gap: .9rem; }
.code-join { display: flex; gap: .6rem; }
.code-join input { text-transform: uppercase; letter-spacing: .4em; text-align: center; }

.home-error { color: var(--red); text-align: center; font-size: 1.1rem; min-height: 1.2em; }

/* ---------- contenido SEO ---------- */
.seo-content {
  max-width: 720px;
  margin: 3.5rem auto;
  padding: 0 1.5rem;
  display: grid;
  gap: 2rem;
}
.seo-content article {
  background: var(--paper2);
  border: 2px solid var(--ink);
  border-radius: var(--wobble2);
  padding: 1.5rem 1.8rem;
  box-shadow: 4px 4px 0 rgba(43, 38, 32, .15);
}
.seo-content article:nth-child(odd) { transform: rotate(.35deg); }
.seo-content article:nth-child(even) { transform: rotate(-.35deg); }
.seo-content h2 {
  color: var(--ink);
  margin-bottom: .6rem;
  font-size: 1.6rem;
  display: inline-block;
  background: linear-gradient(transparent 60%, rgba(232, 80, 58, .25) 60%, rgba(232, 80, 58, .25) 92%, transparent 92%);
}
.seo-content h3 { color: var(--ink); margin: .9rem 0 .3rem; font-size: 1.2rem; }
.seo-content p, .seo-content li { color: var(--ink-soft); line-height: 1.6; font-size: 1.08rem; }
.seo-content ol { padding-left: 1.4rem; display: grid; gap: .5rem; }
.seo-content strong { color: var(--ink); }

.footer { text-align: center; color: var(--ink-soft); padding: 2rem; font-size: 1rem; }

/* ---------- pantalla de juego ---------- */
#screen-game { height: 100vh; display: none; flex-direction: column; }
#screen-game.active { display: flex; }

.game-header {
  display: grid;
  grid-template-columns: 1fr minmax(0, auto) 1fr;
  align-items: center;
  gap: 1rem;
  padding: .55rem 1.2rem;
  background: var(--paper2);
  border-bottom: 2.5px dashed var(--ink);
}

.header-side { display: flex; align-items: center; gap: .9rem; }
.header-right { justify-self: end; }

.round-info { color: var(--ink-soft); font-size: 1.1rem; white-space: nowrap; }

.word-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: .6em;
  font-size: 2.2rem;
  color: var(--ink);
  min-height: 1.2em;
  white-space: nowrap;
  overflow: hidden;
}
#word-text { letter-spacing: .35em; text-indent: .35em; }
#word-count { font-size: 1.05rem; color: var(--ink-soft); }

.btn-report:disabled { opacity: .35; cursor: default; transform: none; }

.timer { position: relative; width: 52px; height: 52px; flex-shrink: 0; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-bg { fill: var(--paper2); stroke: var(--line); stroke-width: 4; }
.timer-ring {
  fill: none; stroke: var(--green); stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 107;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke .5s;
}
.timer.low .timer-ring { stroke: var(--red); }
.timer.low #timer-num { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: translate(-50%,-50%) scale(1.3); } }
#timer-num {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  font-size: 1.05rem;
  color: var(--ink);
}

.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 290px 1fr 300px;
  gap: .9rem;
  padding: .9rem;
  min-height: 0;
}

/* ---------- jugadores ---------- */
.players-panel {
  background: var(--paper2);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble2);
  box-shadow: 4px 4px 0 rgba(43, 38, 32, .15);
  padding: .65rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.player {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .45rem .6rem;
  border: 1.5px solid transparent;
  border-radius: 10px;
  transition: background .3s, transform .3s;
}
.player.me { border-color: var(--blue); background: rgba(74, 144, 217, .08); }
.player.drawer { background: rgba(246, 195, 68, .3); border-color: var(--ink); }
.player.guessed { background: rgba(88, 165, 92, .2); }
.player.bump { animation: bump .5s; }
@keyframes bump { 30% { transform: scale(1.05) rotate(-1deg); background: rgba(88, 165, 92, .45); } }
.player.offline { opacity: .45; filter: grayscale(.8); }

.player-avatar { font-size: 1.7rem; }
.player-info { flex: 1; min-width: 0; }
.player-name {
  display: block;
  font-size: 1.05rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-score { display: block; font-size: .95rem; color: var(--ink-soft); }
.player-rank { color: var(--ink-soft); font-size: 1rem; width: 1.6em; flex-shrink: 0; }
.player-badge { font-size: 1.05rem; flex-shrink: 0; }

/* ---------- lienzo ---------- */
.canvas-area { display: flex; flex-direction: column; gap: .9rem; min-width: 0; min-height: 0; }

.canvas-wrap {
  position: relative;
  flex: 1;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 5px 6px 0 rgba(43, 38, 32, .18);
  min-height: 0;
}
#board, #fx {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
}
#fx { pointer-events: none; }
#board.drawing-pen { cursor: crosshair; }
#board.drawing-fill { cursor: cell; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0;
  background: rgba(247, 243, 233, .95);
  background-image: radial-gradient(var(--line) 1.1px, transparent 1.3px);
  background-size: 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 1.5rem;
  text-align: center;
  z-index: 5;
  animation: fadein .3s;
}
@keyframes fadein { from { opacity: 0; } }
.overlay h2 { font-size: 2rem; font-weight: 400; transform: rotate(-.5deg); }
.overlay-sub { color: var(--ink-soft); font-size: 1.15rem; }

.room-code {
  display: inline-block;
  background: var(--yellow);
  border: 2px solid var(--ink);
  padding: .05em .45em;
  border-radius: 8px;
  letter-spacing: .25em;
  transform: rotate(-1.5deg);
  box-shadow: 2px 2px 0 var(--ink);
}

.word-options { display: flex; gap: 1.1rem; flex-wrap: wrap; justify-content: center; }
.word-option {
  background: var(--paper2);
  border: 2.5px solid var(--ink);
  color: var(--ink);
  font-size: 1.3rem;
  font-family: inherit;
  padding: .9rem 1.5rem;
  border-radius: var(--wobble);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s, background .15s;
  animation: cardin .4s backwards;
}
.word-option:nth-child(1) { background: rgba(246, 195, 68, .5); transform: rotate(-2deg); }
.word-option:nth-child(2) { background: rgba(74, 144, 217, .25); transform: rotate(1.2deg); animation-delay: .1s; }
.word-option:nth-child(3) { background: rgba(232, 80, 58, .22); transform: rotate(-1deg); animation-delay: .2s; }
@keyframes cardin { from { opacity: 0; transform: translateY(20px) scale(.8); } }
.word-option:hover { transform: scale(1.1) rotate(0deg) !important; background: var(--yellow); }

.revealed-word {
  color: var(--ink);
  font-size: 1.5em;
  letter-spacing: .1em;
  background: linear-gradient(transparent 60%, rgba(246, 195, 68, .8) 60%, rgba(246, 195, 68, .8) 92%, transparent 92%);
  padding: 0 .25em;
}

/* ---------- podio ---------- */
.podium { display: flex; align-items: flex-end; gap: 1rem; }
.podium-spot { display: flex; flex-direction: column; align-items: center; gap: .4rem; animation: cardin .5s backwards; }
.podium-spot:nth-child(1) { animation-delay: .4s; }
.podium-spot:nth-child(2) { animation-delay: .2s; }
.podium-spot:nth-child(3) { animation-delay: .6s; }
.podium-avatar { font-size: 2.6rem; }
.podium-name { font-size: 1.15rem; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-score { color: var(--ink-soft); }
.podium-base {
  width: 92px;
  border: 2.5px solid var(--ink);
  border-radius: 8px 8px 0 0;
  display: grid; place-items: center;
  font-size: 1.8rem;
  box-shadow: 3px 0 0 rgba(43, 38, 32, .15);
}
.podium-1 .podium-base { height: 110px; background: var(--yellow); }
.podium-2 .podium-base { height: 80px; background: #e4e0d4; }
.podium-3 .podium-base { height: 60px; background: #e0a96d; }
.podium-actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; justify-content: center; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: .9rem;
  flex-wrap: wrap;
  background: var(--paper2);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble2);
  box-shadow: 4px 4px 0 rgba(43, 38, 32, .15);
  padding: .55rem .8rem;
}

.colors { display: grid; grid-template-columns: repeat(9, 26px); gap: 5px; }
.color {
  width: 26px; height: 26px;
  border-radius: 7px 9px 6px 8px;
  border: 2px solid var(--ink);
  cursor: pointer;
  transition: transform .1s;
}
.color:hover { transform: scale(1.2) rotate(4deg); }
.color.active { outline: 2.5px solid var(--blue); outline-offset: 1px; transform: scale(1.12); }

.tool-group { display: flex; gap: .4rem; }
.tool {
  background: var(--paper2);
  border: 2px solid var(--ink);
  border-radius: 10px 12px 9px 11px;
  font-size: 1.15rem;
  font-family: inherit;
  width: 42px; height: 42px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, transform .1s;
  color: var(--ink);
  box-shadow: 2px 2px 0 rgba(43, 38, 32, .25);
}
.tool:hover { background: var(--yellow); transform: scale(1.08) rotate(-3deg); }
.tool.active { background: var(--yellow); outline: 2px solid var(--ink); }

.size-dot { border-radius: 50%; background: var(--ink); display: block; margin: auto; }

/* ---------- chat ---------- */
.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--paper2);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble);
  box-shadow: 4px 4px 0 rgba(43, 38, 32, .15);
  overflow: hidden;
  min-height: 0;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: .7rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  scroll-behavior: smooth;
}

.msg {
  font-size: 1.05rem;
  line-height: 1.35;
  padding: .3rem .6rem;
  border: 1.5px solid var(--line);
  border-radius: 4px 12px 10px 6px;
  background: #fff;
  word-wrap: break-word;
  animation: msgin .2s;
}
@keyframes msgin { from { opacity: 0; transform: translateY(6px); } }
.msg b { color: var(--blue); }
.msg.sys { background: none; border: none; color: var(--ink-soft); font-style: italic; font-size: .98rem; }
.msg.sys.join { color: var(--green); }
.msg.sys.leave { color: var(--red); }
.msg.correct { background: rgba(88, 165, 92, .18); border-color: var(--green); color: #2e6b32; }
.msg.almost { background: rgba(246, 195, 68, .25); border-color: var(--yellow); color: #8a6d1a; }
.msg.whisper { opacity: .8; border-left: 3px solid var(--green); }

.chat-form { display: flex; gap: .4rem; padding: .55rem; border-top: 2px dashed var(--line); }
.chat-form input { flex: 1; padding: .55rem .8rem; font-size: 1.05rem; }
.btn-send { padding: .45rem .9rem; box-shadow: 2px 2px 0 var(--ink); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%) rotate(-.8deg);
  background: var(--ink);
  color: var(--paper);
  font-size: 1.1rem;
  padding: .7rem 1.4rem;
  border-radius: var(--wobble);
  box-shadow: 4px 4px 0 rgba(43, 38, 32, .3);
  z-index: 50;
  animation: toastin .25s;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 16px) rotate(-.8deg); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow-y: auto;
  }
  .players-panel {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 80px;
  }
  .player { flex-shrink: 0; }
  .player-rank { display: none; }
  .canvas-wrap { min-height: 46vh; }
  .chat-panel { min-height: 200px; }
  .word-display { font-size: 1.4rem; }
  #word-text { letter-spacing: .25em; text-indent: .25em; }
  .game-header { gap: .5rem; padding: .5rem .7rem; }
  .header-side .logo-small { display: none; }
  .logo { font-size: 2.5rem; }
  .colors { grid-template-columns: repeat(9, 24px); }
  .color { width: 24px; height: 24px; }
}
