* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, #fef3f8 0%, #eef4ff 50%, #f0fbf4 100%);
  color: #1f2937;
}

.screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.screen.active { display: flex; }

.card {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(31, 41, 55, 0.12);
  padding: 32px;
}

.home-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.home-card h1 { margin: 0 0 4px; font-size: 28px; }
.subtitle { color: #6b7280; margin: 0 0 24px; font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; margin-bottom: 14px; }
.field span { font-size: 13px; color: #6b7280; font-weight: 600; }
.field input, .field select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid #e5e7eb;
  font-size: 15px;
  outline: none;
  background: #fafafa;
}
.field input:focus, .field select:focus { border-color: #6366f1; background: #fff; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.field.inline span { white-space: nowrap; }

.btn {
  width: 100%;
  padding: 11px 16px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .06s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: #6366f1; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #4f46e5; }
.btn-secondary { background: #ecfdf5; color: #059669; border: 1.5px solid #a7f3d0; }
.btn-secondary:hover { background: #d1fae5; }
.btn-ghost { background: #f3f4f6; color: #374151; }
.btn-ghost:hover { background: #e5e7eb; }
.btn-ghost.active-tool { background: #c7d2fe; color: #3730a3; }
.btn.small { width: auto; padding: 7px 12px; font-size: 13px; }

.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: #9ca3af; font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: #e5e7eb; }

.error-text { color: #dc2626; font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.hint { color: #9ca3af; font-size: 13px; text-align: center; margin: 10px 0 0; }

/* Lobby */
.lobby-card { width: 100%; max-width: 460px; }
.lobby-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.lobby-header h2 { margin: 0 0 4px; font-size: 13px; color: #6b7280; font-weight: 600; }
.room-code { font-size: 34px; font-weight: 800; letter-spacing: 4px; color: #4f46e5; }

.player-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; max-height: 260px; overflow-y: auto; }
.player-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 10px; background: #f9fafb;
}
.player-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: #c7d2fe; color: #3730a3; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0;
}
.player-name { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-score { font-size: 13px; color: #6b7280; font-weight: 700; }
.player-tag { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: #fef3c7; color: #92400e; font-weight: 700; }
.player-tag.drawer { background: #dbeafe; color: #1e40af; }
.player-tag.guessed { background: #d1fae5; color: #065f46; }

.host-settings { border-top: 1px dashed #e5e7eb; padding-top: 16px; margin-top: 8px; }

/* Game layout */
#screen-game.active { align-items: stretch; padding: 12px; height: 100vh; min-height: 0; overflow: hidden; }
.game-layout { display: flex; gap: 12px; width: 100%; max-width: 1200px; height: 100%; min-height: 0; margin: 0 auto; }
.game-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.game-side { width: 280px; flex-shrink: 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; }

.game-topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-radius: 14px; padding: 10px 18px;
  box-shadow: 0 4px 16px rgba(31,41,55,.08);
}
.topbar-item { font-size: 14px; font-weight: 700; color: #374151; }
.word-hint { font-size: 22px; letter-spacing: 6px; color: #4f46e5; }
.timer { font-size: 18px; color: #dc2626; min-width: 50px; text-align: right; }
.timer.low { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.canvas-wrap {
  position: relative; background: #fff; border-radius: 14px; overflow: hidden;
  box-shadow: 0 4px 16px rgba(31,41,55,.08); flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; background: #fff; }

.overlay {
  position: absolute; inset: 0; background: rgba(255,255,255,.92);
  display: flex; align-items: center; justify-content: center; z-index: 5;
}
.overlay-card { text-align: center; padding: 20px; max-width: 90%; }
.overlay-card h3 { margin: 0 0 14px; font-size: 18px; }
.choose-words { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.choose-words button {
  padding: 14px 20px; border-radius: 12px; border: 2px solid #c7d2fe;
  background: #eef2ff; color: #3730a3; font-weight: 700; font-size: 16px; cursor: pointer;
}
.choose-words button:hover { background: #c7d2fe; }
.reveal-word { font-size: 30px; font-weight: 800; color: #059669; margin-bottom: 8px; }
.final-scores { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 220px; }
.final-scores .player-row:first-child { background: #fef3c7; }

.toolbar { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 14px; padding: 10px 14px; box-shadow: 0 4px 16px rgba(31,41,55,.08); flex-wrap: wrap; }
.colors { display: flex; gap: 6px; flex-wrap: wrap; }
.color-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color-swatch.active { border-color: #111827; transform: scale(1.1); }
#brush-size { width: 100px; }

.game-players { max-height: 220px; flex-shrink: 0; overflow-y: auto; background: #fff; border-radius: 14px; padding: 10px; box-shadow: 0 4px 16px rgba(31,41,55,.08); }
.chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #fff; border-radius: 14px; box-shadow: 0 4px 16px rgba(31,41,55,.08); overflow: hidden; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.chat-msg .from { font-weight: 700; color: #4f46e5; margin-right: 4px; }
.chat-msg.system { color: #9ca3af; font-style: italic; }
.chat-msg.correct { color: #059669; font-weight: 700; background: #ecfdf5; padding: 4px 8px; border-radius: 8px; }
.chat-msg.mine .from { color: #ea580c; }
.chat-form { flex-shrink: 0; display: flex; gap: 6px; padding: 10px; border-top: 1px solid #f3f4f6; }
.chat-form input { flex: 1; padding: 9px 10px; border-radius: 8px; border: 1.5px solid #e5e7eb; font-size: 13px; outline: none; }
.chat-form input:focus { border-color: #6366f1; }

@media (max-width: 860px) {
  #screen-game.active { height: auto; min-height: 100vh; overflow: visible; }
  .game-layout { flex-direction: column; height: auto; }
  .game-side { width: 100%; }
  .game-players { max-height: 140px; }
  .chat-panel { flex: none; min-height: 260px; max-height: 46vh; }
}
