:root {
  --bg: #0f1419;
  --bg-elev: #161b26;
  --bg-elev2: #1f2533;
  --bg-elev3: #2a3142;
  --border: #2d3548;
  --border-light: #3d4659;
  --text: #f3f4f6;
  --text-dim: #94a3b8;
  --text-faint: #64748b;

  --primary: #8b5cf6;
  --primary-dark: #6d28d9;
  --primary-light: #a78bfa;
  --accent: #ec4899;
  --accent-dark: #be185d;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  --gradient: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --gradient-soft: linear-gradient(135deg, rgba(139,92,246,0.15), rgba(236,72,153,0.15));

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.5);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", Consolas, "Courier New", monospace;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  font-size: 14px;
  line-height: 1.5;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: all 0.15s ease;
  font-weight: 500;
}

button:hover {
  background: var(--bg-elev3);
  border-color: var(--border-light);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0) scale(0.98);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

button.primary,
.btn-primary {
  background: var(--gradient);
  border: none;
  color: white;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(139,92,246,0.3);
}

button.primary:hover,
.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 16px rgba(139,92,246,0.4);
}

.btn-secondary {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
}

.btn-primary.big {
  padding: 12px 24px;
  font-size: 15px;
  width: 100%;
}

.btn-primary.danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 4px 12px rgba(239,68,68,0.3);
}

button.danger {
  color: var(--danger);
  border-color: rgba(239,68,68,0.3);
}

button.danger:hover {
  background: rgba(239,68,68,0.1);
  border-color: var(--danger);
}

.icon-btn {
  background: transparent;
  border: none;
  padding: 8px 10px;
  font-size: 16px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.icon-btn:hover {
  background: var(--bg-elev2);
  transform: none;
}

.icon-btn.small {
  padding: 4px 6px;
  font-size: 13px;
}

input, select, textarea {
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.2);
}

input::placeholder {
  color: var(--text-faint);
}

.hidden { display: none !important; }

/* ============ Landing ============ */
body.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: radial-gradient(ellipse at top left, #1e1b4b 0%, transparent 50%),
              radial-gradient(ellipse at bottom right, #831843 0%, transparent 50%),
              #0f1419;
  position: relative;
}

.bg-blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
  animation: float 12s ease-in-out infinite;
}

.bg-blob.b1 { background: #8b5cf6; width: 400px; height: 400px; top: -100px; left: -100px; }
.bg-blob.b2 { background: #ec4899; width: 500px; height: 500px; bottom: -150px; right: -150px; animation-delay: -4s; }
.bg-blob.b3 { background: #3b82f6; width: 300px; height: 300px; top: 50%; left: 50%; animation-delay: -8s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.05); }
  66% { transform: translate(-30px, 40px) scale(0.95); }
}

.landing-card {
  position: relative;
  z-index: 1;
  width: 420px;
  max-width: 92vw;
  padding: 40px;
  background: rgba(22, 27, 38, 0.85);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: card-in 0.4s ease;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand-icon {
  font-size: 64px;
  margin-bottom: 12px;
  display: inline-block;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.brand h1 {
  margin: 0 0 6px;
  font-size: 36px;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.btn-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  font-size: 15px;
  transition: all 0.2s ease;
}

.btn-hero:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.btn-hero.primary {
  background: var(--gradient);
  border: none;
  color: white;
  box-shadow: 0 8px 24px rgba(139,92,246,0.35);
}

.btn-hero.primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 12px 32px rgba(139,92,246,0.5);
}

.btn-icon {
  font-size: 28px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius);
}

.btn-hero.primary .btn-icon {
  background: rgba(255,255,255,0.15);
}

.btn-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.btn-title {
  font-size: 16px;
  font-weight: 700;
}

.btn-sub {
  font-size: 12px;
  opacity: 0.7;
}

.nick-bar {
  margin-bottom: 16px;
}

.nick-bar > label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.nick-input {
  display: flex;
  gap: 8px;
}

.nick-input input {
  flex: 1;
}

.tips {
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tips li {
  color: var(--text-dim);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tips li span {
  font-size: 14px;
}

.err {
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: center;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ============ Code inputs (join modal) ============ */
.code-inputs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 20px 0;
}

.code-inputs input {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  padding: 0;
}

/* ============ Modal ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  text-align: center;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-content h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
}

.modal-sub {
  margin: 0 0 16px;
  color: var(--text-dim);
  font-size: 13px;
}

.modal-foot {
  margin: 14px 0 0;
  color: var(--text-faint);
  font-size: 12px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.modal-actions button {
  min-width: 100px;
}

/* Word picker */
.word-pick-content { min-width: 380px; }

.word-options {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 20px 0 10px;
}

.word-options button {
  padding: 16px 24px;
  font-size: 18px;
  font-weight: 600;
  background: var(--bg-elev2);
  border: 2px solid var(--border);
  min-width: 100px;
  transition: all 0.2s ease;
}

.word-options button:hover {
  border-color: var(--primary);
  background: var(--bg-elev3);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(139,92,246,0.25);
}

/* Players modal */
.players-content {
  min-width: 400px;
  max-width: 480px;
  text-align: left;
}

.players-content h2 {
  text-align: center;
  margin-bottom: 20px;
}

.section {
  margin-bottom: 20px;
}

.section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section h3 .count {
  background: var(--bg-elev3);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}

.section h3 .hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-faint);
  font-size: 11px;
}

#players-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#players-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-elev2);
  border-radius: var(--radius);
  font-size: 14px;
  transition: background 0.15s;
}

#players-list li:hover {
  background: var(--bg-elev3);
}

#players-list li .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

#players-list li .info {
  flex: 1;
  min-width: 0;
}

#players-list li .name {
  font-weight: 600;
  word-break: break-all;
}

#players-list li .badges {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

#players-list li .badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  letter-spacing: 0.5px;
}

#players-list li .badge.owner { background: var(--warning); color: black; }
#players-list li .badge.draw { background: var(--accent); }
#players-list li .badge.correct { background: var(--success); }
#players-list li .badge.disconnected { background: var(--text-faint); }

#players-list li .score {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--success);
  min-width: 40px;
  text-align: right;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.setting-row > label {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-row > label .hint {
  color: var(--text-faint);
  font-size: 11px;
}

.seg {
  display: flex;
  gap: 4px;
  background: var(--bg-elev2);
  padding: 4px;
  border-radius: var(--radius);
}

.seg button {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
}

.seg button:hover {
  background: var(--bg-elev3);
  color: var(--text);
  transform: none;
}

.seg button.active {
  background: var(--gradient);
  color: white;
  box-shadow: 0 2px 6px rgba(139,92,246,0.3);
}

.categories {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.categories label {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-elev2);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.categories label:hover {
  background: var(--bg-elev3);
}

.categories input {
  width: auto;
  margin: 0;
  accent-color: var(--primary);
}

.custom-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.custom-words .chip {
  background: var(--gradient);
  color: white;
  padding: 4px 8px 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

.custom-words .chip button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  cursor: pointer;
  padding: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
}

.custom-words .chip button:hover {
  background: rgba(255,255,255,0.35);
}

.custom-add {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.custom-add input { flex: 1; padding: 6px 10px; font-size: 12px; }
.custom-add button { padding: 6px 14px; font-size: 12px; }

/* ============ Room layout ============ */
body.room {
  display: grid;
  grid-template-areas:
    "topbar topbar topbar"
    "canvas canvas chat";
  grid-template-columns: 1fr 1fr 340px;
  grid-template-rows: 64px 1fr;
  height: 100vh;
  width: 100vw;
}

body.room.no-chat {
  grid-template-columns: 1fr 1fr 0;
}

/* Topbar */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  z-index: 1100;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-info .label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-right: 2px;
}

.room-info .code {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 3px;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.phase-info {
  flex: 0 0 auto;
}

.phase-label {
  display: inline-block;
  padding: 6px 14px;
  background: var(--bg-elev2);
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.phase-label.drawing { background: rgba(139,92,246,0.15); color: var(--primary-light); border-color: rgba(139,92,246,0.3); }
.phase-label.guessing { background: rgba(236,72,153,0.15); color: var(--accent); border-color: rgba(236,72,153,0.3); }
.phase-label.reveal { background: rgba(245,158,11,0.15); color: var(--warning); border-color: rgba(245,158,11,0.3); }
.phase-label.ended { background: rgba(16,185,129,0.15); color: var(--success); border-color: rgba(16,185,129,0.3); }

.word-display {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 4px;
  font-family: var(--font-mono);
  min-width: 120px;
  text-align: center;
  padding: 6px 12px;
  background: var(--bg-elev2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.word-display.drawer { background: rgba(139,92,246,0.15); border-color: rgba(139,92,246,0.3); color: var(--primary-light); }
.word-display.reveal { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.3); color: var(--success); }

.timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}

.timer-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--success);
}

.timer.warn .timer-num {
  color: var(--danger);
  animation: pulse 0.6s infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0.7; transform: scale(1.1); }
}

.timer-bar {
  width: 60px;
  height: 3px;
  background: var(--bg-elev3);
  border-radius: 2px;
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  background: var(--gradient);
  width: 100%;
  transition: width 0.3s ease;
  border-radius: 2px;
}

.timer.warn .timer-bar-fill { background: var(--danger); }

.topbar-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: auto;
}

.players-btn {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.players-btn:hover {
  background: var(--bg-elev3);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.pv-owner, .pv-self {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pv-icon { font-size: 16px; }

.pv-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: white;
  flex-shrink: 0;
}

.pv-name {
  font-size: 13px;
  font-weight: 600;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 4px;
  min-width: 18px;
  height: 16px;
}

/* Canvas */
.canvas-area {
  grid-area: canvas;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
  min-height: 0;
  position: relative;
}

.canvas-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  min-height: 0;
}

#canvas {
  background: white;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  cursor: crosshair;
  touch-action: none;
}

#canvas.locked { cursor: not-allowed; }

.canvas-overlay {
  position: absolute;
  top: 28px;
  left: 28px;
  background: rgba(15,20,25,0.85);
  color: white;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  z-index: 5;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.canvas-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  align-items: center;
}

body.viewer .toolbar { display: none; }

.tool-group {
  display: flex;
  gap: 4px;
  align-items: center;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}

.tool-group:last-child { border-right: none; padding-right: 0; }

.tool, .actions button, .sizes .size {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
}

.tool:hover, .actions button:hover, .sizes .size:hover {
  border-color: var(--primary);
}

.tool.active {
  background: var(--gradient);
  border-color: transparent;
  color: white;
  box-shadow: 0 2px 8px rgba(139,92,246,0.4);
}

.sizes .size {
  border-radius: 50%;
  position: relative;
}

.sizes .size::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 50%;
}

.sizes .size[data-size="2"]::after { width: 2px; height: 2px; }
.sizes .size[data-size="4"]::after { width: 4px; height: 4px; }
.sizes .size[data-size="8"]::after { width: 8px; height: 8px; }
.sizes .size[data-size="16"]::after { width: 14px; height: 14px; }
.sizes .size[data-size="32"]::after { width: 20px; height: 20px; }
.sizes .size[data-size="48"]::after { width: 26px; height: 26px; }
.sizes .size[data-size="64"]::after { width: 30px; height: 30px; }

.sizes .size.active {
  background: var(--gradient);
  border-color: transparent;
  color: white;
}

.colors { flex-wrap: nowrap; }

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
}

.palette .swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  transition: transform 0.1s;
}

.palette .swatch:hover {
  transform: scale(1.15);
}

.palette .swatch.active {
  border: 2px solid white;
  transform: scale(1.2);
  box-shadow: 0 0 0 2px var(--primary);
}

.picker {
  position: relative;
  cursor: pointer;
}

.picker input[type="color"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.picker .swatch.rgb {
  width: 36px;
  height: 36px;
  background: conic-gradient(from 0deg, #ff006e, #fb560f, #ffbe0b, #8338ec, #3a86ff, #ff006e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.recent { display: flex; gap: 3px; }

.recent .swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  cursor: pointer;
}

/* Chat */
.chat {
  grid-area: chat;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.chat-progress {
  font-size: 11px;
  background: var(--bg-elev2);
  padding: 3px 8px;
  border-radius: 10px;
  color: var(--success);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--bg-elev3); border-radius: 3px; }

.chat-msg {
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev2);
  animation: msg-in 0.2s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg .nick {
  font-weight: 700;
  color: var(--primary-light);
  margin-right: 6px;
}

.chat-msg .time {
  color: var(--text-faint);
  font-size: 10px;
  margin-left: 6px;
}

.chat-msg.system {
  background: rgba(139,92,246,0.1);
  border: 1px solid rgba(139,92,246,0.2);
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  font-size: 12px;
}

.chat-msg.correct {
  background: rgba(16,185,129,0.15);
  border: 1px solid rgba(16,185,129,0.3);
  color: var(--success);
  font-weight: 600;
}

.chat-msg.masked {
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.2);
  color: var(--warning);
}

.chat-msg.close {
  background: rgba(245,158,11,0.05);
  color: var(--warning);
  font-style: italic;
}

.chat-msg.self {
  background: rgba(236,72,153,0.1);
}

.chat-msg.self .nick { color: var(--accent); }

.chat-form {
  display: flex;
  padding: 12px;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}

.chat-form input {
  flex: 1;
}

.chat-form button {
  padding: 10px 18px;
}

/* Game end */
.end-game-content { min-width: 380px; }

#final-scores {
  text-align: left;
  padding-left: 0;
  margin: 20px 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#final-scores li {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--bg-elev2);
  border-radius: var(--radius);
  font-size: 15px;
}

#final-scores li:nth-child(1) {
  background: linear-gradient(135deg, rgba(245,158,11,0.2), rgba(245,158,11,0.05));
  border: 1px solid rgba(245,158,11,0.4);
}

#final-scores li .rank {
  font-weight: 700;
  font-size: 18px;
  width: 28px;
  text-align: center;
}

#final-scores li .name { flex: 1; }
#final-scores li .score {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--success);
  font-size: 18px;
}

.vote-section {
  margin: 16px 0;
  padding: 16px;
  background: var(--bg-elev2);
  border-radius: var(--radius);
  text-align: left;
}

.vote-status {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.vote-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.vote-count {
  font-size: 20px;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.vote-progress {
  height: 6px;
  background: var(--bg-elev3);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.vote-progress-fill {
  height: 100%;
  background: var(--gradient);
  width: 0%;
  transition: width 0.4s ease;
  border-radius: 3px;
}

.vote-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 24px;
  margin-bottom: 8px;
}

.vote-chip {
  background: rgba(16,185,129,0.15);
  color: var(--success);
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.vote-timeout-wrap {
  font-size: 12px;
  color: var(--warning);
  text-align: center;
}

.vote-timeout {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
}

.restarting-section {
  margin: 20px 0;
  padding: 24px;
  text-align: center;
}

.restarting-anim {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  color: var(--text-dim);
}

.restarting-num {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
  min-width: 24px;
}

.restarting-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--bg-elev3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

button.voted {
  background: var(--success) !important;
  box-shadow: none !important;
  cursor: default;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: var(--radius);
  z-index: 2000;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
  body.room {
    grid-template-areas:
      "topbar"
      "canvas"
      "chat";
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr 320px;
  }

  .topbar { padding: 0 12px; gap: 8px; }
  .room-info .label { display: none; }
  .word-display { display: none; }
  .timer-bar { display: none; }

  /* 手机端猜词阶段: word-display 浮动在 topbar 下方 */
  body.room:not(.mobile-draw) .topbar .word-display {
    display: flex;
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: transparent !important;
    border: none !important;
    padding: 2px 8px;
    color: #fff;
    font-weight: 800;
    letter-spacing: 2px;
    text-shadow:
      -1px -1px 0 #000,
       1px -1px 0 #000,
      -1px  1px 0 #000,
       1px  1px 0 #000,
       0 0 8px rgba(0,0,0,1),
       0 2px 4px rgba(0,0,0,0.9);
    max-width: 94vw;
    white-space: nowrap;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    font-size: 16px;
  }

  .toolbar {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 8px 12px;
  }

  .chat { border-left: none; border-top: 1px solid var(--border); }

  .modal-content { padding: 20px; }
  .word-pick-content { min-width: auto; }
  .players-content { min-width: auto; }

  .code-inputs input { width: 40px; height: 48px; font-size: 20px; }
}

/* ============ Emoji Picker ============ */
.emoji-picker {
  position: absolute;
  bottom: 60px;
  right: 2px;
  width: 340px;
  max-height: 320px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 900px) {
  .emoji-picker {
    right: auto;
    left: calc(50% - 4px);
    transform: translateX(-50%);
    width: min(340px, 94vw);
    bottom: 68px;
  }
}

.ep-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev2);
}

.ep-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 0;
  cursor: pointer;
}

.ep-tab:hover {
  background: var(--bg-elev3);
  color: var(--text);
  transform: none;
}

.ep-tab.active {
  color: var(--primary-light);
  border-bottom: 2px solid var(--primary);
}

.ep-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
}

.ep-content::-webkit-scrollbar { width: 6px; }
.ep-content::-webkit-scrollbar-thumb { background: var(--bg-elev3); border-radius: 3px; }

.ep-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 2px;
}

.ep-item {
  background: transparent;
  border: none;
  padding: 4px;
  font-size: 20px;
  cursor: pointer;
  border-radius: 4px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  min-width: 0;
}

.ep-item:hover {
  background: var(--bg-elev3);
  transform: none;
}

.ep-item.ep-face img {
  width: 32px;
  height: 32px;
}

.ep-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 24px 8px;
  font-size: 12px;
}

/* Chat face img */
.chat-msg .text .face-img,
.face-img {
  width: 32px;
  height: 32px;
  vertical-align: middle;
  margin: 0 1px;
  display: inline-block;
}

/* emoji-btn: 缩小 30% */
#emoji-btn {
  padding: 4px 7px;
  font-size: 14px;
  flex-shrink: 0;
}

/* ============ Canvas tools overlay (save buttons) ============ */
.canvas-tools-overlay {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}

.canvas-tool-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: rgba(15, 20, 25, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  border-radius: var(--radius);
  font-size: 18px;
  cursor: pointer;
  z-index: 2000;
  position: relative;
  pointer-events: all;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: all 0.15s;
}

.canvas-tool-btn:hover {
  background: rgba(15, 20, 25, 0.95);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.canvas-tool-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* 窄屏(手机)优化:不显示房间号腾出空间 */
@media (max-width: 540px) {
  body.room .room-info {
    display: none;
  }
}

/* ============ 手机画师横屏旋转 ============ */
.rotate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 5000;
  pointer-events: none;
  animation: overlay-fade-in 0.25s ease;
}

.rotate-overlay.fade-out {
  animation: overlay-fade-out 0.45s ease forwards;
}

@keyframes overlay-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes overlay-fade-out {
  to { opacity: 0; visibility: hidden; }
}

.rotate-overlay-icon {
  font-size: 80px;
  display: inline-block;
  animation: rotate-icon 1.4s cubic-bezier(0.65, 0, 0.35, 1);
}

@keyframes rotate-icon {
  0% { transform: rotate(0); }
  100% { transform: rotate(90deg); }
}

.rotate-overlay-text {
  margin-top: 16px;
  color: white;
  font-size: 14px;
  letter-spacing: 1px;
}

/* 触发横屏：portrait + 窄屏 + mobile-draw class */
@media (orientation: portrait) and (max-width: 600px) {
  body.room.mobile-draw {
    transform: rotate(90deg);
    transform-origin: top left;
    position: fixed;
    top: 0;
    left: 100vw;
    width: 100vh;
    height: 100vw;
    overflow: hidden;
  }
}

/* topbar 浮右上,2 行 grid:第一行 [timer][actions], 第二行 [word 跨两列] */
body.room.mobile-draw .topbar {
  position: absolute;
  top: 8px;
  right: 8px;
  left: auto;
  background: transparent !important;
  border: none !important;
  padding: 0;
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: 6px;
  z-index: 20;
  width: auto;
  max-width: calc(100vw - 200px);
}

body.room.mobile-draw .topbar .room-info,
body.room.mobile-draw .topbar .phase-info {
  display: none;
}

body.room.mobile-draw .topbar .word-display,
body.room.mobile-draw .topbar .timer,
body.room.mobile-draw .topbar .topbar-actions {
  background: rgba(15, 20, 25, 0.88);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  backdrop-filter: blur(8px);
}

body.room.mobile-draw .topbar .timer {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: auto;
  justify-self: end;
}

body.room.mobile-draw .topbar .topbar-actions {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  gap: 4px;
}

body.room.mobile-draw .topbar .word-display {
  grid-column: 1 / 3;
  grid-row: 2;
  font-size: 13px;
  letter-spacing: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

body.room.mobile-draw .topbar .timer .timer-bar {
  display: none;
}

body.room.mobile-draw .topbar .timer .timer-num {
  font-size: 18px;
}

body.room.mobile-draw .topbar .players-btn {
  padding: 4px 8px;
  font-size: 13px;
}

body.room.mobile-draw .topbar .pv-avatar {
  width: 20px;
  height: 20px;
  font-size: 11px;
}

body.room.mobile-draw .topbar .pv-name {
  max-width: 60px;
  font-size: 12px;
}

/* chat 隐藏 */
body.room.mobile-draw .chat {
  display: none;
}

/* canvas 占满 */
body.room.mobile-draw {
  grid-template-areas: "canvas";
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

body.room.mobile-draw .canvas-area {
  grid-area: canvas;
}

body.room.mobile-draw .canvas-wrap {
  padding: 0;
}

body.room.mobile-draw #canvas {
  border-radius: 0;
  box-shadow: none;
  max-width: calc(100% - 130px - 150px);
  max-height: 100%;
  margin-left: calc(-6% - 20px);
}

/* 工具栏左两列 */
body.room.mobile-draw .toolbar {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  flex-direction: column;
  flex-wrap: wrap;
  max-height: 92%;
  width: auto;
  max-width: 180px;
  background: rgba(15, 20, 25, 0.9);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 6px;
  z-index: 15;
  border: 1px solid var(--border);
  overflow: visible;
  gap: 4px;
}

body.room.mobile-draw .tool-group {
  flex-direction: column;
  border-right: none;
  border-bottom: none;
  padding-right: 0;
  padding-bottom: 0;
  margin-bottom: 0;
  gap: 3px;
}

body.room.mobile-draw .tool-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

body.room.mobile-draw .tool,
body.room.mobile-draw .sizes .size {
  width: 32px;
  height: 32px;
  font-size: 14px;
}

body.room.mobile-draw .sizes {
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  align-items: center;
  max-width: 40px;
  gap: 2px;
  margin-left: 1px;
}

/* 右下底部条:水平排列 [actions][palette(2列)][colors] */
.mobile-bottom-bar {
  position: absolute;
  right: 14px;
  bottom: 8px;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
  z-index: 15;
}

.mobile-floating-palette {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 5px;
  background: rgba(15, 20, 25, 0.92);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  overflow: visible;
}

.mobile-floating-palette .swatch {
  width: 24px;
  height: 24px;
}

.rgb-slot {
  display: none;
}

.mobile-floating-palette .rgb-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
}

.mobile-floating-palette .rgb-slot.empty {
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px dashed rgba(255, 255, 255, 0.35);
}

.mobile-floating-palette .rgb-slot.empty::after {
  content: "+";
  color: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  font-weight: 700;
}

.mobile-floating-colors {
  background: rgba(15, 20, 25, 0.92);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 6px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.mobile-floating-colors .picker .swatch.rgb {
  width: 38px;
  height: 38px;
  font-size: 11px;
}

.mobile-floating-colors .recent {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: calc(6 * 22px + 5 * 3px);
  overflow: hidden;
}

.mobile-floating-colors .recent .swatch {
  width: 28px;
  height: 28px;
}

body.room.mobile-draw .mobile-floating-actions,
body.room.mobile-draw .mobile-floating-actions:last-child {
  background: rgba(15, 20, 25, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 48px;
  box-sizing: border-box;
}

body.room.mobile-draw .mobile-floating-actions button {
  width: 38px;
  height: 38px;
  font-size: 14px;
}

/* 隐藏 eyedropper(手机端不要取色) */
body.room.mobile-draw .tool[data-tool="eyedropper"] {
  display: none !important;
}

/* word-display 单独 floating 屏幕顶部中央 */
.mobile-floating-word {
  position: absolute !important;
  top: 8px !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  margin-left: calc(-3% - 10px) !important;
  background: red !important;
  border: 3px solid yellow !important;
  border-radius: 10px;
  padding: 10px 20px !important;
  z-index: 9999 !important;
  color: white !important;
  font-size: 20px !important;
  font-weight: 700;
  letter-spacing: 3px;
  text-align: center;
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.mobile-floating-word:empty::before {
  content: "(提示词加载中)";
  color: rgba(255,255,255,0.7);
}

.mobile-floating-word.drawer {
  background: rgba(139, 92, 246, 0.85) !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
}

.mobile-floating-word.reveal {
  background: rgba(16, 185, 129, 0.85) !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
}

/* 手机端不显示 colors group(只剩 recent,RGB 已移到 actions) */
body.room.mobile-draw .tool-group.colors {
  display: none !important;
}

/* 📷 emoji 视觉偏下,补偿 3px */
#save-png {
  padding-top: 0;
  padding-bottom: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ============ 手机端画师弹幕 ============ */
.danmaku-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 12;
  display: none;
}

body.room.mobile-draw .danmaku-layer {
  display: block;
  inset: auto;
  top: 50%;
  left: 50%;
  width: calc(100% - 130px - 150px);
  max-width: calc(100% - 130px - 150px);
  max-height: 100%;
  aspect-ratio: 4 / 3;
  transform: translate(-50%, -50%);
  margin-left: calc(-3% - 10px);
}

.danmaku-item {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 14px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 16px;
  color: white;
  font-size: 13px;
  white-space: nowrap;
  max-width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  animation: danmaku-float 10s linear forwards;
}

.danmaku-item.correct {
  background: rgba(16, 185, 129, 0.75);
  font-weight: 600;
}

.danmaku-item.system {
  background: rgba(139, 92, 246, 0.65);
  font-style: italic;
  font-size: 12px;
}

.danmaku-item .danmaku-nick {
  color: var(--primary-light);
  font-weight: 600;
  margin-right: 4px;
}

.danmaku-item .face-img {
  height: 18px;
  width: auto;
  vertical-align: middle;
  display: inline-block;
}

@keyframes danmaku-float {
  0% {
    margin-top: 0;
    opacity: 0;
  }
  5% {
    opacity: 1;
  }
  85% {
    opacity: 1;
  }
  100% {
    margin-top: -220px;
    opacity: 0;
  }
}

/* === 调试 === */

/* word-picker 显示时, chat 浮在幕布之上 */
.chat.above-modal {
  z-index: 1001;
}

/* 手机端选词弹窗往上 100px */
@media (max-width: 900px) {
  .word-pick-content {
    transform: translateY(-100px);
  }
}
