*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  height: 100vh;
  overflow: hidden;
}

/* ── Screens ── */
.screen { display: none; width: 100%; height: 100vh; align-items: center; justify-content: center; }
.screen.active { display: flex; }

/* ── Hero ── */
.hero {
  position: relative; width: 100%; height: 100vh;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
}
.hero-bg { position: absolute; inset: 0; pointer-events: none; }
.blob {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.15;
  animation: drift 8s ease-in-out infinite alternate;
}
.blob1 { width: 600px; height: 600px; background: #6366f1; top: -200px; left: -150px; animation-delay: 0s; }
.blob2 { width: 500px; height: 500px; background: #ec4899; bottom: -150px; right: -100px; animation-delay: 2s; }
.blob3 { width: 400px; height: 400px; background: #06b6d4; top: 40%; left: 40%; animation-delay: 4s; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(30px, 20px) scale(1.05); }
}
.hero-content {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2rem;
  text-align: center;
}
.logo-block { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.logo-icon { font-size: 4rem; }
.logo-block h1 {
  font-size: 4.5rem; font-weight: 900; letter-spacing: -.03em;
  background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tagline { font-size: 1.25rem; color: #94a3b8; margin: 0; }

/* ── Quick Start ── */
.quick-start {
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
  width: 360px;
}
.quick-start input {
  width: 100%; padding: 1rem 1.25rem; font-size: 1.1rem;
  border-radius: .75rem; border: 2px solid #334155;
  background: rgba(255,255,255,0.05); color: #e2e8f0;
  text-align: center; outline: none; transition: border-color .2s;
}
.quick-start input:focus { border-color: #6366f1; }
.btn-play {
  width: 100%; padding: 1rem; font-size: 1.15rem; font-weight: 700;
  border: none; border-radius: .75rem; cursor: pointer;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; letter-spacing: .02em;
  box-shadow: 0 4px 24px rgba(99,102,241,0.4);
  transition: transform .15s, box-shadow .15s;
}
.btn-play:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(99,102,241,0.5); }
.btn-play:active { transform: translateY(0); }
.login-hint { color: #64748b; font-size: .9rem; }
.login-hint a { color: #818cf8; text-decoration: none; }
.login-hint a:hover { text-decoration: underline; }

/* ── Auth forms (hidden by default) ── */
.auth-forms { width: 360px; }
.auth-forms.hidden { display: none; }
.tab-row { display: flex; gap: .5rem; margin-bottom: 1.25rem; }
.tab {
  flex: 1; padding: .5rem; border: none; border-radius: .5rem;
  background: #334155; color: #94a3b8; cursor: pointer; font-size: .85rem;
}
.tab.active { background: #6366f1; color: #fff; }
.tab-content { display: none; flex-direction: column; gap: .75rem; }
.tab-content.active { display: flex; }
.tab-content input {
  padding: .7rem 1rem; border-radius: .5rem; border: 1px solid #334155;
  background: rgba(255,255,255,0.05); color: #e2e8f0; font-size: 1rem;
}
.form-error { color: #f87171; font-size: .85rem; min-height: 1.2em; }

/* ── Features ── */
.features {
  display: flex; gap: 1.5rem; flex-wrap: wrap; justify-content: center;
}
.feature {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08);
  padding: .5rem 1rem; border-radius: 2rem; font-size: .9rem; color: #94a3b8;
}

/* ── Lobby ── */
.lobby-wrap {
  width: 100%; height: 100vh; display: flex; flex-direction: column;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
}
.lobby-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.25rem 2rem; border-bottom: 1px solid #1e293b;
}
.logo-sm { font-size: 1.25rem; font-weight: 800; color: #a5b4fc; }
.lobby-user { display: flex; align-items: center; gap: .75rem; font-size: .95rem; }
.rating-badge {
  background: #6366f1; padding: .2rem .6rem; border-radius: 1rem; font-size: .8rem;
}
.btn-sm {
  padding: .4rem .9rem; border-radius: .5rem; border: 1px solid #334155;
  background: transparent; color: #94a3b8; cursor: pointer; font-size: .85rem;
}
.btn-sm:hover { background: #1e293b; color: #e2e8f0; }
.lobby-center {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
.lobby-card {
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 1.25rem; padding: 2.5rem; width: 380px; text-align: center;
  display: flex; flex-direction: column; gap: 1rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.lobby-card h2 { font-size: 1.75rem; font-weight: 800; margin-bottom: .25rem; }
.divider {
  color: #475569; font-size: .85rem; position: relative;
  display: flex; align-items: center; gap: .75rem;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: #1e293b;
}
.join-row { display: flex; gap: .5rem; }
.join-row input {
  flex: 1; padding: .75rem 1rem; border-radius: .6rem; border: 1px solid #334155;
  background: rgba(255,255,255,0.05); color: #e2e8f0; font-size: 1rem;
  text-transform: uppercase; letter-spacing: .1em;
}
.btn-secondary {
  padding: .75rem 1.25rem; border-radius: .6rem; border: 1px solid #6366f1;
  background: transparent; color: #818cf8; cursor: pointer; font-weight: 600;
}
.btn-secondary:hover { background: #6366f1; color: #fff; }

/* ── Game Layout ── */
.game-layout {
  display: grid;
  grid-template-columns: 180px 1fr 260px;
  grid-template-rows: 1fr;
  width: 100vw;
  height: 100vh;
  background: #0a0f1e;
}

/* ── Sidebar ── */
.sidebar {
  background: #111827;
  border-right: 1px solid #1e293b;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-logo {
  font-size: 1rem; font-weight: 800; color: #a5b4fc;
  padding: 1rem; border-bottom: 1px solid #1e293b;
}
.sidebar h3 {
  padding: .75rem 1rem .4rem;
  color: #475569; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
}
#player-list {
  list-style: none; flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: .25rem; padding: .5rem;
}
#player-list li {
  background: #1e293b; border-radius: .6rem; padding: .6rem .75rem;
  display: flex; justify-content: space-between; align-items: center;
  font-size: .9rem; transition: border-left .2s;
  border-left: 3px solid transparent;
}
#player-list li.drawing { border-left-color: #6366f1; background: #1e1b4b; }
#player-list li.guessed { border-left-color: #22c55e; background: #052e16; }
.player-score { color: #a5b4fc; font-weight: 700; font-size: .85rem; }

/* ── Canvas Area ── */
.canvas-area {
  display: flex; flex-direction: column;
  background: #0a0f1e; position: relative; overflow: hidden;
}

/* Top bar */
.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: .75rem 1.25rem;
  background: #111827;
  border-bottom: 1px solid #1e293b;
  min-height: 64px;
}
#room-code-display {
  font-size: .75rem; color: #475569; font-family: monospace;
}
#word-display {
  font-size: 2rem; font-weight: 900; letter-spacing: .35em;
  text-transform: uppercase; color: #e2e8f0;
  text-align: center;
  text-shadow: 0 0 30px rgba(99,102,241,0.4);
}
#timer-display {
  font-size: 2rem; font-weight: 900; color: #6366f1;
  text-align: right; font-variant-numeric: tabular-nums;
  min-width: 3rem;
}

/* Canvas wrapper — fills remaining space */
.canvas-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: .75rem; overflow: hidden;
}
#canvas {
  background: #fff; border-radius: .75rem; cursor: crosshair;
  max-width: 100%; max-height: 100%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  display: block;
}
#canvas.no-draw { cursor: default; }

/* ── Toolbar ── */
.toolbar {
  background: #111827; border-top: 1px solid #1e293b;
  padding: .6rem 1rem; display: flex; flex-direction: column; gap: .5rem;
}
.toolbar.hidden { display: none; }
.color-row { display: flex; gap: .35rem; flex-wrap: wrap; }
.color-btn {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; transition: transform .1s;
}
.color-btn.active { border-color: #fff; transform: scale(1.25); }
.tool-row { display: flex; gap: 1rem; align-items: center; }
.tool-row label { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: #64748b; }
.tool-row input[type=range] { width: 90px; accent-color: #6366f1; }
.tool-row button {
  padding: .35rem .8rem; border-radius: .4rem; border: none;
  background: #1e293b; color: #94a3b8; cursor: pointer; font-size: .82rem;
  transition: background .15s;
}
.tool-row button:hover { background: #334155; color: #e2e8f0; }

/* ── Chat ── */
.chat-panel {
  background: #111827;
  border-left: 1px solid #1e293b;
  display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}
.chat-header {
  padding: .75rem 1rem;
  border-bottom: 1px solid #1e293b;
  font-size: .7rem; font-weight: 700; color: #475569;
  text-transform: uppercase; letter-spacing: .08em;
}
#chat-messages {
  flex: 1; overflow-y: auto; padding: .75rem;
  display: flex; flex-direction: column; gap: .35rem;
  scroll-behavior: smooth;
}
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }
.chat-msg { font-size: .875rem; line-height: 1.5; word-break: break-word; }
.chat-msg .name { font-weight: 700; color: #818cf8; }
.chat-msg.correct { background: rgba(34,197,94,0.08); border-radius: .4rem; padding: .2rem .4rem; }
.chat-msg.correct .name { color: #22c55e; }
.chat-msg.system { color: #475569; font-style: italic; font-size: .8rem; }
#chat-form {
  display: flex; border-top: 1px solid #1e293b; background: #0f172a;
}
#chat-input {
  flex: 1; padding: .75rem 1rem; background: transparent; border: none;
  color: #e2e8f0; font-size: .9rem; outline: none; min-width: 0;
}
#chat-input::placeholder { color: #475569; }
#chat-form button {
  padding: .75rem 1rem; background: #6366f1; border: none;
  color: #fff; cursor: pointer; font-weight: 700; font-size: .85rem;
  white-space: nowrap; transition: background .15s;
}
#chat-form button:hover { background: #4f46e5; }

/* ── Overlays ── */
.overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.overlay.hidden { display: none; }
.overlay-box {
  background: #1e293b; padding: 2rem; border-radius: 1rem;
  text-align: center; min-width: 320px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.overlay-box h3 { font-size: 1.4rem; margin-bottom: 1rem; }
.word-choices { display: flex; gap: 1rem; justify-content: center; margin-top: .5rem; }
.word-choice-btn {
  padding: .75rem 1.5rem; background: #6366f1; border: none; border-radius: .5rem;
  color: #fff; font-size: 1.1rem; cursor: pointer; font-weight: 700;
}
.word-choice-btn:hover { background: #4f46e5; }
#reveal-word { color: #6366f1; font-weight: 700; }
#waiting-overlay { z-index: 20; }
#waiting-players { margin: 1rem 0; display: flex; flex-direction: column; gap: .4rem; }
.waiting-player { background: #0f172a; padding: .5rem 1rem; border-radius: .5rem; }
.round-select {
  margin: .5rem 0;
  color: #94a3b8; font-size: .95rem;
}
.round-select select {
  margin-left: .5rem; padding: .3rem .6rem;
  background: #1e293b; border: 1px solid #334155;
  color: #e2e8f0; border-radius: .4rem; font-size: .95rem; cursor: pointer;
}
#btn-start-game {
  padding: .75rem 2rem; background: #22c55e; border: none; border-radius: .5rem;
  color: #fff; font-size: 1.1rem; cursor: pointer; font-weight: 700; margin-top: .5rem;
}
#btn-start-game:hover { background: #16a34a; }
#final-scores { margin: 1rem 0; }
.final-score-row { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px solid #334155; }
.btn-invite {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1.1rem; background: rgba(99,102,241,0.12); border: 1px solid #4f46e5;
  color: #818cf8; font-size: .88rem; cursor: pointer; font-weight: 600;
  border-radius: 2rem; margin-top: .5rem; transition: all .15s;
  white-space: nowrap;
}
.btn-invite:hover { background: rgba(99,102,241,0.25); color: #c7d2fe; border-color: #818cf8; }
.invite-row { display: flex; align-items: center; gap: .75rem; justify-content: center; flex-wrap: wrap; margin-top: .25rem; }
.invite-feedback { color: #22c55e; font-size: .82rem; }
#btn-play-again {
  padding: .75rem 2rem; background: #6366f1; border: none; border-radius: .5rem;
  color: #fff; font-size: 1.1rem; cursor: pointer; font-weight: 700; margin-top: .75rem;
}

/* ── Profile ── */
.profile-box {
  background: #1e293b; padding: 2rem; border-radius: 1rem;
  width: 480px; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
#btn-back-from-profile {
  background: none; border: none; color: #6366f1; cursor: pointer; font-size: .95rem; margin-bottom: 1.5rem;
  display: block;
}
.profile-header {
  display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1.5rem;
}
.profile-avatar { font-size: 3.5rem; line-height: 1; }
.profile-header h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: .25rem; }
.profile-rank { color: #94a3b8; font-size: .95rem; }
.profile-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: 1.5rem;
}
.stat-card {
  background: #0f172a; border-radius: .75rem; padding: 1rem;
  text-align: center;
}
.stat-val { font-size: 1.75rem; font-weight: 800; color: #e2e8f0; }
.stat-label { font-size: .75rem; color: #64748b; text-transform: uppercase; letter-spacing: .05em; margin-top: .2rem; }
.rank-breakdown { background: #0f172a; border-radius: .75rem; padding: 1rem; }
.rank-breakdown h3 { font-size: .8rem; color: #64748b; text-transform: uppercase; letter-spacing: .08em; margin-bottom: .75rem; }
.rank-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: .5rem 0; border-bottom: 1px solid #1e293b; font-size: .9rem;
}
.rank-row:last-child { border-bottom: none; }
.rank-row.overall { font-weight: 700; color: #e2e8f0; }
.rank-pts { color: #6366f1; font-weight: 600; font-size: .85rem; }
.rank-badge { font-size: .85rem; margin-right: .2rem; }

/* ── Leaderboard ── */
.leaderboard-box {
  background: #1e293b; padding: 2rem; border-radius: 1rem;
  width: 520px; max-height: 80vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.leaderboard-box h2 { margin: .75rem 0 1rem; text-align: center; }
#btn-back-lobby {
  background: none; border: none; color: #6366f1; cursor: pointer; font-size: .95rem;
}
#leaderboard-table { width: 100%; border-collapse: collapse; }
#leaderboard-table th, #leaderboard-table td {
  padding: .6rem .75rem; text-align: left; border-bottom: 1px solid #334155;
}
#leaderboard-table th { color: #64748b; font-size: .8rem; text-transform: uppercase; }
#leaderboard-table tr:first-child td { color: #fbbf24; font-weight: 700; }

/* ── Timer colors ── */
.timer-warn { color: #f97316 !important; }
.timer-danger { color: #ef4444 !important; }

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Hero */
  .logo-block h1 { font-size: 3rem; }
  .quick-start { width: 90vw; }
  .features { gap: .75rem; }
  .feature { font-size: .8rem; padding: .4rem .75rem; }

  /* Lobby */
  .lobby-card { width: 90vw; padding: 1.75rem; }

  /* Game — full vertical stack */
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
    height: 100dvh;
  }

  /* Players — ultra-slim strip at top */
  .sidebar {
    border-right: none;
    border-bottom: 1px solid #1e293b;
    padding: .3rem .5rem;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
  }
  .sidebar-logo { display: none; }
  .sidebar h3 { display: none; }
  #player-list {
    flex-direction: row;
    gap: .4rem;
    padding: 0;
    overflow: visible;
    flex-wrap: nowrap;
  }
  #player-list li {
    flex-direction: row;
    align-items: center;
    gap: .3rem;
    padding: .3rem .5rem;
    white-space: nowrap;
    font-size: .72rem;
    min-width: unset;
    border-radius: 2rem;
  }
  .player-score { font-size: .68rem; color: #6366f1; }

  /* Game header — compact */
  .game-header {
    padding: .35rem .75rem;
    min-height: 44px;
  }
  #word-display { font-size: 1.25rem; letter-spacing: .18em; }
  #timer-display { font-size: 1.25rem; min-width: 2.2rem; }
  #room-code-display { display: none; }

  /* Canvas — max space */
  .canvas-area { overflow: hidden; }
  .canvas-wrap { padding: .3rem; flex: 1; }
  #canvas { border-radius: .4rem; }

  /* Toolbar — single row, compact */
  .toolbar { padding: .4rem .5rem; gap: .35rem; }
  .color-row { gap: .3rem; }
  .color-btn { width: 30px; height: 30px; }
  .tool-row { gap: .4rem; }
  .tool-row label { font-size: .75rem; }
  .tool-row button { padding: .35rem .65rem; font-size: .78rem; }
  .tool-row input[type=range] { width: 70px; }

  /* Chat — collapsed by default on mobile, tap to expand */
  .chat-panel {
    border-left: none;
    border-top: 1px solid #1e293b;
    height: 44px;
    min-height: 44px;
    flex-shrink: 0;
    transition: height .2s ease;
  }
  .chat-panel.open {
    height: 200px;
    min-height: 200px;
  }
  .chat-header {
    padding: .5rem .75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    font-size: .75rem;
  }
  .chat-header::after {
    content: '▲ Tap to guess';
    font-size: .7rem;
    color: #6366f1;
  }
  .chat-panel.open .chat-header::after { content: '▼ Close'; }
  .chat-panel:not(.open) #chat-messages,
  .chat-panel:not(.open) #chat-form { display: none; }
  #chat-messages { padding: .4rem .6rem; }
  .chat-msg { font-size: .8rem; }
  #chat-input { padding: .55rem .65rem; font-size: .88rem; }

  /* Overlays */
  .overlay-box { min-width: 280px; margin: 1rem; padding: 1.5rem; }
  .word-choices { flex-direction: column; align-items: center; gap: .6rem; }
  .word-choice-btn { width: 100%; }
}

@media (max-width: 400px) {
  .logo-block h1 { font-size: 2.5rem; }
  #word-display { font-size: 1.1rem; letter-spacing: .15em; }
  #timer-display { font-size: 1.1rem; }
}
