:root {
  color: #202124;
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --paper: #f7f5f0;
  --ink: #202124;
  --panel: rgba(255, 255, 255, 0.88);
  --border: rgba(32, 33, 36, 0.1);
  --shadow: 0 18px 50px rgba(32, 33, 36, 0.16), 0 2px 8px rgba(32, 33, 36, 0.08);
}

* { box-sizing: border-box; }

html, body, #app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--paper);
  -webkit-user-select: none;
  user-select: none;
}

button, input { font: inherit; }

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

#canvas.is-panning { cursor: grabbing; }

.topbar {
  position: fixed;
  z-index: 10;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand, .actions {
  display: flex;
  align-items: center;
  height: 48px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 4px 18px rgba(32, 33, 36, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  pointer-events: auto;
}

.brand {
  gap: 10px;
  padding: 0 17px;
  border-radius: 18px;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border: 3px solid var(--ink);
  border-radius: 50% 48% 52% 45%;
  transform: rotate(-13deg);
}

.brand-name {
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.actions {
  gap: 2px;
  padding: 4px;
  border-radius: 18px;
}

.presence {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 8px 0 10px;
  color: rgba(32, 33, 36, 0.64);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d39a35;
  box-shadow: 0 0 0 3px rgba(211, 154, 53, 0.14);
}

.connection-dot.is-online {
  background: #3a9b61;
  box-shadow: 0 0 0 3px rgba(58, 155, 97, 0.14);
}

.icon-button, .brush-button {
  height: 40px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.icon-button {
  width: 40px;
  display: grid;
  place-items: center;
}

.icon-button svg {
  width: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-button:disabled { opacity: 0.26; cursor: default; }
.icon-button:not(:disabled):active, .brush-button:active { background: rgba(32, 33, 36, 0.08); }

.brush-button {
  min-width: 61px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 11px;
}

.brush-preview {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

#brush-size-label { min-width: 15px; font-size: 13px; font-weight: 700; }

.hint, .zoom-indicator {
  position: fixed;
  z-index: 8;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.78);
  color: rgba(32, 33, 36, 0.67);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: none;
}

.hint {
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
  transition: opacity 300ms ease, transform 300ms ease;
}

.hint.is-hidden { opacity: 0; transform: translate(-50%, 8px); }

.zoom-indicator {
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  min-width: 52px;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  opacity: 0;
  transition: opacity 180ms ease;
}

.zoom-indicator.is-visible { opacity: 1; }

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  top: max(76px, calc(env(safe-area-inset-top) + 66px));
  max-width: calc(100% - 32px);
  padding: 10px 15px;
  border-radius: 13px;
  background: rgba(32, 33, 36, 0.9);
  color: white;
  box-shadow: 0 8px 25px rgba(32, 33, 36, 0.2);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -6px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.brush-menu {
  position: fixed;
  z-index: 30;
  width: min(310px, calc(100vw - 24px));
  padding: 10px 18px 18px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  transform-origin: top center;
  animation: menu-in 140ms ease-out;
  touch-action: manipulation;
}

.brush-menu[hidden] { display: none; }

@keyframes menu-in {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
}

.menu-handle {
  width: 34px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 99px;
  background: rgba(32, 33, 36, 0.16);
}

.control { display: block; margin: 10px 0 17px; }
.control > span, .color-row > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 650;
}

output { color: rgba(32, 33, 36, 0.58); font-variant-numeric: tabular-nums; }

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--ink);
}

.color-row { margin-top: 3px; }
.swatches { display: flex; gap: 9px; }

.swatch, .custom-color {
  position: relative;
  width: 31px;
  height: 31px;
  flex: 0 0 31px;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(32, 33, 36, 0.14);
  cursor: pointer;
}

.swatch.is-selected { box-shadow: 0 0 0 2px var(--ink); }

.custom-color {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: conic-gradient(#e63b3b, #f0c43c, #4ab76e, #36a8d8, #735bd6, #e63b3b);
  color: white;
  font-size: 20px;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.custom-color input { position: absolute; width: 1px; height: 1px; opacity: 0; }

@media (max-width: 520px) {
  .topbar { top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; }
  .brand { width: 48px; padding: 0; justify-content: center; }
  .brand-name { display: none; }
  .hint { bottom: max(12px, env(safe-area-inset-bottom)); font-size: 11px; }
  .zoom-indicator { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
  .presence { padding-left: 7px; padding-right: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
