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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f5;
  color: #111;
}

/* ---------- ICONS ---------- */

.icon-logo,
.icon-exit,
.icon-battery,
.icon-music {
  width: 20px;
  height: 20px;
  display: block;
}

.icon-tool {
  width: 18px;
  height: 18px;
  display: block;
}

.icon-chat,
.icon-task {
  width: 18px;
  height: 18px;
  display: block;
}

.icon-send {
  width: 18px;
  height: 18px;
  display: block;
}

/* ---------- TOPBAR ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 1px solid #e0e0e0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo-text {
  font-weight: 600;
  font-size: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.exit-btn {
  background: transparent;
  border: none;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.exit-btn.hidden {
  display: none;
}

/* ---------- LAYOUT ---------- */

.main {
  display: flex;
  padding: 12px;
  gap: 12px;
}

.sidebar {
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel {
  background: #ffffff;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
}

.panel.hidden {
  display: none;
}

.panel h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}

#statusText {
  font-size: 13px;
  color: #666;
  margin-bottom: 8px;
}

/* ---------- BUTTONS ---------- */

.primary,
.secondary,
.danger {
  width: 100%;
  padding: 9px 12px;
  border-radius: 999px;
  margin-top: 6px;
  border: 1px solid transparent;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.primary {
  background: #111;
  color: #fff;
}

.primary:hover {
  background: #000;
}

.secondary {
  background: #f2f2f2;
  color: #111;
  border-color: #d4d4d4;
}

.secondary:hover {
  background: #e6e6e6;
}

.danger {
  background: #c62828;
  color: #fff;
  border-color: #b71c1c;
}

.danger:hover {
  background: #b71c1c;
}

.clear-danger {
  color: #b71c1c;
}

/* убрать синий фокус */

.primary:focus,
.secondary:focus,
.danger:focus,
.exit-btn:focus,
.chat-btn:focus,
.task-btn:focus,
.chat-close-btn:focus,
.chat-send-btn:focus,
.chat-input:focus,
.task-close-btn:focus,
.music-btn:focus {
  outline: none;
  box-shadow: none;
}

/* лёгкий фокус для поля чата */
.chat-input:focus,
#codeInput:focus {
  border-color: #111;
}

/* ---------- TOOLS ---------- */

.tool-row {
  display: flex;
  gap: 8px;
  margin: 8px 0 10px;
}

.tool-btn {
  flex: 1;
  min-width: 0;
  background: #f2f2f2;
  border: 1px solid #d4d4d4;
  padding: 8px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.tool-btn.active {
  background: #111;
  border-color: #111;
}

.tool-btn.active .icon-tool {
  filter: invert(1);
}

/* ---------- COLORS ---------- */

.label {
  font-size: 12px;
  color: #777;
  margin-bottom: 4px;
  margin-top: 6px;
}

#colorSection {
  margin-top: 4px;
}

.colors {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.color-swatch {
  width: 26px;
  height: 26px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1px solid #d4d4d4;
  cursor: pointer;
  transition: border-color 0.18s ease;
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.color-swatch.active {
  border-color: #111;
}

/* Радужный кружочек — «размытые» волны, все цвета радуги */

.gradient {
  border: none;
  background:
    radial-gradient(circle at 0% 0%, #ff0000 0, #ff0000 25%, transparent 60%),
    radial-gradient(circle at 100% 0%, #ff7f00 0, #ff7f00 25%, transparent 60%),
    radial-gradient(circle at 0% 100%, #00ff00 0, #00ff00 25%, transparent 60%),
    radial-gradient(circle at 100% 100%, #0000ff 0, #0000ff 25%, transparent 60%),
    radial-gradient(circle at 50% 50%, #00ffff 0, #00ffff 25%, transparent 60%),
    radial-gradient(circle at 30% 70%, #8b00ff 0, #8b00ff 25%, transparent 60%);
  background-size: 200% 200%;
  animation: rainbowBlob 4s ease-in-out infinite alternate;
}

@keyframes rainbowBlob {
  0% {
    background-position: 0% 0%;
    transform: translate3d(0, 0, 0) scale(1);
  }
  25% {
    background-position: 100% 0%;
    transform: translate3d(2%, -3%, 0) scale(1.05);
  }
  50% {
    background-position: 100% 100%;
    transform: translate3d(-2%, 3%, 0) scale(0.97);
  }
  75% {
    background-position: 0% 100%;
    transform: translate3d(3%, -1%, 0) scale(1.03);
  }
  100% {
    background-position: 0% 0%;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

.custom-color {
  background: #ffffff;
}

.custom-color::before {
  content: "+";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 500;
  color: #111;
}

/* ---------- RANGE ---------- */

#sizeRange {
  width: 100%;
  margin-bottom: 8px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: #e0e0e0;
}

#sizeRange::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #111;
  border: 2px solid #ffffff;
  cursor: pointer;
}

#sizeRange::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #111;
  border: 2px solid #ffffff;
  cursor: pointer;
}

/* ---------- CANVAS AREA ---------- */

.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.canvas-header {
  background: #ffffff;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.canvas-header.hidden {
  display: none;
}

.header-left,
.header-center,
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-center {
  flex: 1;
  justify-content: center;
}

#roomLabel {
  font-size: 13px;
  color: #333;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f2f2f2;
}

/* чат, задание, музыка */

.chat-btn,
.task-btn,
.music-btn {
  position: relative;
  border-radius: 999px;
  border: 1px solid #d4d4d4;
  background: #f2f2f2;
  padding: 5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.music-btn.music-on {
  background: #111;
  border-color: #111;
}

.music-btn.music-on .icon-music {
  filter: invert(1);
}

.chat-badge,
.task-badge {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 8px;
  height: 8px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: #c62828;
}

.chat-badge-hidden,
.task-badge-hidden {
  display: none;
}

.partner {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.dot {
  width: 10px;
  height: 10px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  display: inline-block;
}

.dot.offline {
  background: #c62828;
}

.dot.online {
  background: #2e7d32;
}

.battery {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #555;
}

/* ---------- CANVAS ---------- */

.canvas-container {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
  height: 70vh;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- MODALS ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(8px);
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.22s ease;
  z-index: 100;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-box {
  background: #ffffff;
  padding: 16px 16px 14px;
  border-radius: 10px;
  min-width: 220px;
  max-width: calc(100% - 48px);
  border: 1px solid #e0e0e0;
  text-align: center;
  transform: translateY(0) scale(1);
  opacity: 1;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.modal-box.small {
  width: 230px;
}

.modal.hidden .modal-box {
  transform: translateY(8px) scale(0.98);
  opacity: 0;
}

.modal-box h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.modal-box p {
  font-size: 13px;
  color: #555;
  margin-bottom: 8px;
}

.subnote {
  font-size: 11px;
  color: #777;
  margin-top: -4px;
  margin-bottom: 10px;
}

#codeInput {
  width: 100%;
  border-radius: 999px;
  border: 1px solid #d4d4d4;
  padding: 8px 10px;
  font-size: 14px;
  margin: 8px 0 2px;
}

.error {
  font-size: 12px;
  color: #c62828;
}

/* ---- модалка своего цвета ---- */

.color-box {
  width: 260px;
}

.cp-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  justify-content: center;
}

.cp-preview-circle {
  width: 34px;
  height: 34px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1px solid #d4d4d4;
  background: #000000;
}

.cp-hex {
  font-family: monospace;
  font-size: 13px;
  color: #333;
}

.cp-row {
  margin-bottom: 10px;
  text-align: left;
}

.cp-row label {
  font-size: 12px;
  color: #777;
  display: block;
  margin-bottom: 2px;
}

.cp-row input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: #e0e0e0;
}

#hueRange {
  background: linear-gradient(
    to right,
    #ff0000,
    #ff00ff,
    #0000ff,
    #00ffff,
    #00ff00,
    #ffff00,
    #ff0000
  );
}

#satRange,
#lightRange {
  background: #e0e0e0;
}

.cp-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #111;
  border: 2px solid #ffffff;
  cursor: pointer;
}

.cp-row input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #111;
  border: 2px solid #ffffff;
  cursor: pointer;
}

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

.recent-swatch {
  width: 20px;
  height: 20px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1px solid #d4d4d4;
  cursor: pointer;
}

/* ---- модалка чата ---- */

.chat-box {
  width: 320px;
  text-align: left;
  padding-bottom: 10px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.chat-title {
  font-size: 15px;
  font-weight: 600;
}

.chat-close-btn {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
}

.chat-messages {
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  padding: 6px 6px 4px;
  height: 240px;
  overflow-y: auto;
  background: #fafafa;
  margin-bottom: 8px;
}

.chat-message {
  max-width: 80%;
  font-size: 13px;
  padding: 0;
  margin-bottom: 4px;
  word-wrap: break-word;
  animation: chat-pop 0.18s ease;
}

.chat-bubble {
  padding: 6px 9px;
  border-radius: 12px;
}

.chat-message.me {
  margin-left: auto;
}

.chat-message.me .chat-bubble {
  background: #111;
  color: #fff;
}

.chat-message.them {
  margin-right: auto;
}

.chat-message.them .chat-bubble {
  background: #eaeaea;
  color: #111;
}

.chat-text {
  white-space: pre-wrap;
}

.chat-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.chat-time {
  font-size: 11px;
  opacity: 0.75;
}

.chat-status-icon {
  width: 14px;
  height: 14px;
}

.chat-message.me .chat-status-icon {
  filter: invert(1); /* белая иконка для тёмного пузыря */
}

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

.chat-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.chat-input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid #d4d4d4;
  padding: 7px 10px;
  font-size: 14px;
}

/* маленькая кнопка отправки + белая иконка */
.chat-send-btn {
  width: auto;
  padding: 5px 6px;
  margin-top: 0;
  border-radius: 999px;
}

.chat-send-btn .icon-send {
  filter: invert(1);
}

/* ---- модалка задания ---- */

.task-box {
  width: 340px;
  text-align: left;
  padding-bottom: 12px;
}

.task-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.task-title {
  font-size: 15px;
  font-weight: 600;
}

.task-close-btn {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
}

/* картинка задания без чёрных полей */

.task-image-wrap {
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  overflow: hidden;
  background: #ffffff;
  height: 220px;
  touch-action: none; /* для pinch-zoom */
}

.task-image-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(1);
  transition: transform 0.12s ease;
  transform-origin: center center;
}

.task-image {
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
}

.task-actions-row {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

/* ---- музыка ---- */

.music-buttons-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 780px) {
  .main {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    order: 2;
  }

  .canvas-area {
    order: 1;
  }

  .canvas-container {
    height: 60vh;
  }
}
