:root {
  color-scheme: light;
  --bg: #fafafa;
  --panel: #ffffff;
  --hover: #f1f3f5;
  --border: #dee2e6;
  --text: #212529;
  --muted: #868e96;
  --accent: #4263eb;
  --accent-soft: #edf2ff;
  --primary: #4263eb;
  --primary-hover: #3b5bdb;
  --success: #2f9e44;
  --warning: #f08c00;
  --toast-bg: #212529;
  --toast-text: #ffffff;
  --overlay: rgba(250, 250, 250, 0.85);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #161719;
    --panel: #25262b;
    --hover: #2c2e33;
    --border: #373a40;
    --text: #e9ecef;
    --muted: #909296;
    --accent: #748ffc;
    --accent-soft: rgba(116, 143, 252, 0.16);
    --primary: #4c6ef5;
    --primary-hover: #5c7cfa;
    --success: #51cf66;
    --warning: #ffa94d;
    --toast-bg: #e9ecef;
    --toast-text: #212529;
    --overlay: rgba(22, 23, 25, 0.85);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #161719;
  --panel: #25262b;
  --hover: #2c2e33;
  --border: #373a40;
  --text: #e9ecef;
  --muted: #909296;
  --accent: #748ffc;
  --accent-soft: rgba(116, 143, 252, 0.16);
  --primary: #4c6ef5;
  --primary-hover: #5c7cfa;
  --success: #51cf66;
  --warning: #ffa94d;
  --toast-bg: #e9ecef;
  --toast-text: #212529;
  --overlay: rgba(22, 23, 25, 0.85);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  overscroll-behavior: none;
}

#board {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

body[data-tool='select'] #board {
  cursor: default;
}
body[data-tool='pan'] #board,
body.panning #board {
  cursor: grab;
}
body.dragging #board {
  cursor: grabbing;
}
body[data-tool='text'] #board {
  cursor: text;
}
body[data-tool='eraser'] #board {
  cursor: none;
}

#text-editor {
  position: fixed;
  margin: 0;
  padding: 0;
  border: none;
  outline: 1px dashed var(--accent);
  outline-offset: 4px;
  background: transparent;
  resize: none;
  overflow: hidden;
  white-space: pre;
  line-height: 1.25;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-width: 4px;
}

.panel {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  user-select: none;
}

#toolbar {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  overflow-x: auto;
}

#zoombar {
  top: 16px;
  left: 16px;
}

#topbar {
  top: 16px;
  right: 16px;
  gap: 10px;
  padding: 6px 10px;
}

.group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.sep {
  width: 1px;
  align-self: stretch;
  margin: 2px 4px;
  background: var(--border);
}

button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  flex: none;
}

button:hover {
  background: var(--hover);
}

button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

button:disabled {
  opacity: 0.35;
  cursor: default;
  background: transparent;
}

button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 2px var(--panel);
  background: var(--c);
}

.swatch:hover {
  background: var(--c);
  filter: brightness(1.1);
}

.swatch.active {
  border-color: var(--accent);
  background: var(--c);
}

.swatch.custom {
  position: relative;
  display: block;
  overflow: hidden;
  cursor: pointer;
  background: conic-gradient(#e03131, #f08c00, #fab005, #2f9e44, #1971c2, #9c36b5, #e03131);
}

.swatch.custom input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dot {
  width: var(--d);
  height: var(--d);
  border-radius: 50%;
  background: currentColor;
}

#zoom-label {
  min-width: 72px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

#status {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

#status::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--success);
}

#status.offline::before {
  background: var(--warning);
}

#users {
  display: flex;
  gap: 4px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  background: var(--c);
}

.avatar:hover {
  background: var(--c);
  filter: brightness(1.1);
}

.avatar.me {
  outline: 2px solid var(--c);
  outline-offset: 2px;
}

#toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--toast-bg);
  color: var(--toast-text);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.15s,
    transform 0.15s;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 640px) {
  #status {
    display: none;
  }
}

.icon-link {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text);
}

.icon-link:hover {
  background: var(--hover);
}

.icon-link svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#board-name {
  width: auto;
  max-width: 220px;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: inherit;
  font-weight: 600;
}

#fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--overlay);
}

#fatal[hidden] {
  display: none;
}

#fatal .panel {
  position: static;
  flex-direction: column;
  gap: 12px;
  padding: 24px 32px;
}

#fatal p {
  margin: 0;
}

#fatal a {
  color: var(--accent);
}

@media (max-width: 640px) {
  #board-name {
    max-width: 110px;
  }
}
