:root {
  --bg: #1f2233;
  --bg2: #2a2e45;
  --panel: #ffffff;
  --line: #3a3f5c;
  --ink: #1c1f2e;
  --paper: #ffffff;
  --accent: #ffd166;
  --accent2: #4cc9f0;
  --good: #52d681;
  --bad: #ff6b6b;
  --muted: #9aa3c0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1100px 700px at 50% -15%, #2f3550, var(--bg));
  color: #eef1ff;
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

button {
  font: inherit;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  background: #3c4265;
  color: #eef1ff;
  cursor: pointer;
  transition: transform .06s, filter .12s;
}
button:hover { filter: brightness(1.12); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--accent); color: #3a2c00; font-weight: 800; }
.secondary { background: #454b74; }
.big { width: 100%; padding: 16px; font-size: 20px; margin: 14px 0 20px; }

input, select {
  font: inherit;
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: #171a29;
  color: #eef1ff;
}
input:focus { outline: none; border-color: var(--accent2); }

/* ---------- home ---------- */
#home { display: grid; place-items: center; padding: 26px 16px; }
.home-card { width: min(880px, 100%); }
h1 { font-size: clamp(40px, 8vw, 66px); margin: 0; letter-spacing: -2px; }
h1 span { color: var(--accent); }
.tag { color: var(--muted); margin: 4px 0 22px; }

.identity { display: flex; gap: 18px; align-items: center; background: var(--bg2); border-radius: 16px; padding: 16px; }
.avatar-picker { display: flex; align-items: center; gap: 8px; }
.arrow { background: #3c4265; padding: 8px 12px; }
.identity-fields { flex: 1; display: grid; gap: 10px; }
.face-row { display: flex; gap: 8px; }
.face-row .arrow { flex: 1; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-size: 24px; flex: none;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
}
.avatar.big { width: 84px; height: 84px; font-size: 44px; }
.avatar.mini { width: 34px; height: 34px; font-size: 19px; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--bg2); border-radius: 16px; padding: 16px; }
.panel h3 { margin: 0 0 8px; font-size: 16px; }
.panel .secondary { width: 100%; }
.join-row { display: flex; gap: 8px; margin-top: 10px; }
.code { text-align: center; letter-spacing: 6px; text-transform: uppercase; font-weight: 800; }
.join-row .secondary { width: auto; }
.room-list { display: grid; gap: 8px; max-height: 190px; overflow: auto; }
.room-row { display: flex; justify-content: space-between; align-items: center; background: #171a29; border-radius: 10px; padding: 9px 12px; font-size: 14px; }
.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 20px; }

/* ---------- game ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 0 0 14px 14px;
  position: sticky; top: 0; z-index: 6;
  max-width: 1180px; margin: 0 auto;
}
.clock {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 900; font-size: 19px;
  background: #eef1ff; color: var(--ink); border: 3px solid var(--accent2);
}
.clock.low { border-color: var(--bad); color: var(--bad); }
.round-box { flex: 1; text-align: center; min-width: 0; }
.round { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: #6a7192; font-weight: 700; }
.word { font-size: clamp(16px, 2.4vw, 26px); font-weight: 800; letter-spacing: 4px; font-family: ui-monospace, "Courier New", monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.word small { letter-spacing: 0; font-family: inherit; color: #6a7192; }
.top-right { display: flex; align-items: center; gap: 8px; }
.room-code { color: #6a7192; font-size: 13px; }
.room-code b { color: var(--ink); letter-spacing: 2px; }

.layout {
  display: grid; grid-template-columns: 190px minmax(0, 1fr) 260px;
  gap: 12px; padding: 12px; align-items: start;
  max-width: 1180px; margin: 0 auto;
}

.players {
  background: var(--panel); border-radius: 12px; padding: 6px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px;
  max-height: 70vh; overflow-y: auto; overflow-x: hidden; align-content: start;
}
.player { display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 9px; color: var(--ink); font-size: 13px; min-width: 0; }
.player + .player { border-top: 1px solid #eef0f7; }
.player.me { background: #fff8e1; }
.player.guessed { background: #e8fbef; }
.player.drawing { background: #e7f6ff; }
.player .info { flex: 1; min-width: 0; }
.player .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .pts { color: #6a7192; font-size: 12px; }
.player .rank { color: #9aa3c0; font-weight: 800; font-size: 12px; width: 18px; flex: none; }
.player .badge { flex: none; }
.player .badge { font-size: 15px; }
.gain { color: var(--good); font-weight: 800; font-size: 12px; }
.countdown { color: var(--accent); font-weight: 800; }
.player.pop { animation: pop .45s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); background: #dcf7e5; } 100% { transform: scale(1); } }

.stage { display: grid; gap: 8px; justify-items: center; }
.canvas-wrap {
  position: relative; width: 100%; max-width: 640px;
  background: var(--paper); border-radius: 12px; overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,.28);
}
canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; touch-action: none; cursor: crosshair; background: #fff; }

.overlay {
  position: absolute; inset: 0; background: rgba(20,23,38,.9);
  display: flex; overflow-y: auto; overflow-x: hidden;
  padding: 14px; text-align: center;
}
.overlay-card { width: min(560px, 100%); margin: auto; }
.overlay h2 { margin: 0 0 10px; font-size: clamp(17px, 2.6vw, 24px); }
.choices { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.choices button { background: var(--accent); color: #3a2c00; font-weight: 800; font-size: 17px; padding: 12px 20px; }
.reveal { font-size: clamp(20px, 4vw, 34px); font-weight: 900; color: var(--accent); margin-bottom: 12px; }
.result-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 10px; border-radius: 8px; background: rgba(255,255,255,.07); margin-bottom: 5px; font-size: 14px; }
.podium { display: grid; gap: 6px; margin-bottom: 10px; }
.podium-row { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.09); padding: 10px 14px; border-radius: 10px; }
.podium-row .medal { font-size: 24px; }
.podium-row .nm { flex: 1; text-align: left; font-weight: 700; }
.settings { display: grid; gap: 6px; text-align: left; margin-bottom: 10px; }
.settings label { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; font-size: 13px; }
.settings input { padding: 7px 10px; }
.settings input[type=range] { padding: 0; }
.settings .val { color: var(--accent); font-weight: 800; }
.invite { display: flex; gap: 8px; margin-bottom: 8px; }
.invite input { padding: 7px 10px; font-size: 13px; }
.waiting-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 10px; }
.chip { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.09); padding: 5px 10px; border-radius: 20px; font-size: 13px; }

.tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; background: var(--panel); border-radius: 12px; padding: 8px 10px; width: 100%; max-width: 640px; }
.palette { display: grid; grid-template-columns: repeat(13, 1fr); gap: 0; border-radius: 6px; overflow: hidden; }
.swatch { width: 22px; height: 22px; border: none; padding: 0; border-radius: 0; cursor: pointer; }
.swatch.on { outline: 3px solid var(--ink); outline-offset: -3px; z-index: 1; }
.tool-group { display: flex; gap: 6px; }
.tool { background: #eef1ff; color: var(--ink); padding: 8px 11px; font-size: 17px; }
.tool.on { background: var(--accent2); }
.sizes { display: flex; gap: 6px; align-items: center; }
.size-dot { background: #eef1ff; border-radius: 50%; padding: 0; display: grid; place-items: center; }
.size-dot i { display: block; background: var(--ink); border-radius: 50%; }
.size-dot.on { background: var(--accent2); }

.chat { background: var(--panel); border-radius: 12px; display: flex; flex-direction: column; height: 70vh; max-height: 640px; }
.chat-log { flex: 1; overflow: auto; padding: 8px; display: grid; gap: 3px; align-content: start; color: var(--ink); font-size: 13.5px; }
.chat-log div { padding: 4px 7px; border-radius: 7px; word-break: break-word; }
.chat-log .even { background: #f5f6fb; }
.chat-log .system { color: #6a7192; font-style: italic; }
.chat-log .correct { background: #dcf7e5; color: #12692f; font-weight: 700; }
.chat-log .close { background: #fff3cd; color: #7a5b00; font-weight: 600; }
.chat-log .team { background: #e7f6ff; color: #08506e; }
.chat-log b { color: #2a2e45; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #eef0f7; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .players { max-height: 132px; grid-auto-flow: column; grid-auto-columns: 150px; overflow-x: auto; }
  .player + .player { border-top: none; }
  .chat { height: 40vh; }
  .split { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .palette { grid-template-columns: repeat(13, 1fr); }
}
