:root {
  --paper: #faf8f3;
  --ink: #1f2937;
  --muted: #6b7280;
  --surface: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.12), 0 1px 3px rgba(15, 23, 42, 0.08);
  --accent: #0d9488;
  --accent-soft: #ccfbf1;
  --danger: #dc2626;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 500 14px/1.2 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
body[data-tool="hand"] canvas, body.panning canvas { cursor: grab; }
body.panning.dragging canvas { cursor: grabbing; }
body[data-tool="eraser"] canvas { cursor: cell; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

/* top bar */
.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.spacer { flex: 1; pointer-events: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.chip svg { width: 18px; height: 18px; color: var(--muted); }
#room-name { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: none; }
.dot.offline { background: #f59e0b; animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: 0.3; } }

.zoom { padding: 0 4px; gap: 0; }
.zoom button { height: 38px; min-width: 36px; padding: 0 6px; font-size: 18px; color: var(--muted); }
.zoom #zoom-reset { font-size: 13px; min-width: 52px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* bottom toolbar */
.toolbar {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 16px);
}
.tool {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--ink);
  transition: background 0.12s, color 0.12s;
}
.tool:active { background: rgba(15, 23, 42, 0.06); }
.tool.active { background: var(--accent-soft); color: var(--accent); }
#clear { color: var(--danger); }
.sep { width: 1px; height: 28px; background: var(--border); margin: 0 4px; }

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1.5px var(--border), 0 0 0 1px rgba(0,0,0,.15) inset;
}

@media (max-width: 420px) {
  .tool { width: 42px; height: 46px; }
  .sep { margin: 0 2px; }
  .users svg { display: none; }
}

/* color / size popover */
.palette {
  position: fixed;
  left: 50%;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 76px);
  transform: translateX(-50%);
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.palette[hidden] { display: none; }
.palette .row { display: flex; gap: 8px; justify-content: center; }
.palette .colors button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1.5px var(--border);
}
.palette .colors button.active { box-shadow: 0 0 0 2.5px var(--accent); }
.palette .sizes button {
  width: 48px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}
.palette .sizes button.active { background: var(--accent-soft); }
.palette .sizes span { display: block; border-radius: 50%; background: var(--ink); }

.toast {
  position: fixed;
  left: 50%;
  top: calc(max(12px, env(safe-area-inset-top)) + 52px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.toast[hidden] { display: none; }
