:root {
  color-scheme: light dark;
  --bg: #16181d;
  --panel: #1f2229;
  --border: #2e323b;
  --text: #e8e8ea;
  --muted: #9a9ea7;
  --accent: #5b8cff;
  --danger: #e05a5a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#app { min-height: 100vh; }

.screen {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 16px;
}

.screen-home, .screen-join {
  max-width: 420px;
  text-align: center;
  padding-top: 15vh;
}

h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 0.95rem; color: var(--muted); margin: 20px 0 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 1rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; width: 100%; margin-top: 12px; }
.btn-active { border-color: var(--accent); background: rgba(91, 140, 255, 0.18); color: var(--accent); }

.icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-dot { fill: currentColor; stroke: none; }

.text-input {
  display: block;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  margin-top: 10px;
}

.avatar-preview {
  width: 56px;
  height: 56px;
  margin: 12px auto;
  border-radius: 50%;
  overflow: hidden;
  background: var(--panel);
}
.avatar-preview img { width: 100%; height: 100%; display: block; }
.join-hint { margin: 16px 0 8px; color: var(--muted); font-size: 0.85rem; }
.join-form .avatar-picker {
  max-height: 260px;
  overflow-y: auto;
  padding: 4px;
  margin-bottom: 16px;
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.lobby-body {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 1000px) {
  .lobby-body { grid-template-columns: 1fr; }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
/* Group separators (tools | colors | widths | clear) so the single row
   reads as grouped controls rather than one flat list of buttons. */
.toolbar > * + * {
  padding-left: 8px;
  border-left: 1px solid var(--border);
}
.toolbar-tools, .toolbar-colors, .toolbar-widths {
  display: flex;
  gap: 4px;
}
.tool-btn {
  width: 32px;
  height: 32px;
  padding: 0;
}
.brush-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brush-color);
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
}
.swatch-active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.width-btn {
  width: 32px;
  height: 32px;
  padding: 0;
}
.width-btn-active { border-color: var(--accent); background: rgba(91, 140, 255, 0.18); }

.board-wrap {
  width: 100%;
  aspect-ratio: 1000 / 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.board {
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}
.tool-cursor {
  position: absolute;
  display: none;
  pointer-events: none;
}
.tool-cursor-brush {
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8);
}
.tool-cursor-eraser {
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.7);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9);
  background: transparent;
}

.player-list { list-style: none; padding: 0; margin: 0; }
.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
}
.player-row-you { background: var(--panel); }
.player-name { flex: 1; }
.player-score { color: var(--muted); font-variant-numeric: tabular-nums; }
.badge-host, .badge-offline {
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 6px;
  margin-left: 6px;
}
.badge-host { background: #4a3d1f; color: #ffd479; }
.badge-offline { background: #3a2323; color: #ff9a9a; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--panel);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; display: block; }

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
}
.avatar-cell {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 50%;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}
.avatar-cell img { width: 100%; height: 100%; display: block; }
.avatar-cell-mine { border-color: var(--accent); }
.avatar-cell-taken { opacity: 0.25; cursor: not-allowed; }

.chat {
  display: flex;
  flex-direction: column;
  height: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  font-size: 0.9rem;
}
.chat-line { margin-bottom: 4px; word-break: break-word; }
.chat-system { color: var(--muted); font-style: italic; }
.chat-form {
  display: flex;
  border-top: 1px solid var(--border);
}
.chat-form .text-input { margin: 0; border: none; border-radius: 0; flex: 1; }
.chat-form .btn { border: none; border-radius: 0; }

.error-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  z-index: 100;
}

.phase-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.phase-timer {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}

.word-choices-slot:empty { display: none; }
.word-choices {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}
.word-choices-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-word { font-size: 1rem; }
.word-badge {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-left: 4px;
}

.start-game-slot:empty { display: none; }
.start-game-slot { margin: 12px 0; }

.toolbar-slot:empty { display: none; }

.scoreboard-slot:empty { display: none; }
.scoreboard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.scoreboard-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 32px;
  min-width: 280px;
  text-align: center;
}
.scoreboard-list {
  text-align: left;
  padding-left: 20px;
  margin: 12px 0;
}

.btn-small { font-size: 0.75rem; padding: 3px 8px; margin-left: 8px; }

.settings-slot:empty { display: none; }
.settings-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0;
}
.settings-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.settings-form label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.9rem; }
.settings-form .text-input { margin: 0; width: 140px; }
.settings-form textarea.text-input { width: 100%; }

.chat-team { color: var(--accent); }
.chat-spectators { color: var(--muted); }

.word-mask {
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  text-align: center;
  padding: 6px 0;
  min-height: 1.8rem;
}

.scoreboard-teams { list-style: none; padding: 0; margin: 8px 0; font-weight: 600; }

@media (max-width: 560px) {
  .screen { padding: 12px 8px; }
  .lobby-header { flex-wrap: wrap; gap: 8px; }
  .chat { height: 260px; }
  .toolbar { gap: 4px; }
  .swatch { width: 22px; height: 22px; }
  .width-btn, .tool-btn { width: 28px; height: 28px; }
  .word-choices-row { flex-direction: column; }
  .btn-word { width: 100%; }
  .scoreboard-card { padding: 16px 20px; width: 90vw; }
  .phase-bar { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* Drawing needs a pointer with hover + fine precision; touch devices get a
   clear explanation instead of a half-working canvas when it's their turn
   to draw (docs/spec.md §7: "рисование на мобильных не поддерживается" is
   an explicit MVP boundary, not an oversight). is-drawer-turn is toggled
   by ui.js alongside the toolbar's own visibility. */
.board-wrap { position: relative; }
@media (pointer: coarse) {
  .board-wrap.is-drawer-turn::after {
    content: "Рисование недоступно с сенсорного экрана в этой версии";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    font-size: 0.95rem;
  }
}
