:root {
  --paper: #F4F2EC;
  --dot: #D3CFC4;
  --ink: #171614;
  --muted: #8A867C;
  --line: rgba(23, 22, 20, 0.09);
  --panel: #FFFFFF;
  --accent: #FF5A1F;
  --shadow: 0 1px 2px rgba(23, 22, 20, 0.06), 0 8px 28px -10px rgba(23, 22, 20, 0.18);
  --s: 1;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font: 400 14px/1.4 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
kbd { font: inherit; }

/* ---------- canvas ---------- */
#stage {
  position: fixed; inset: 0; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
  background-color: var(--paper);
  background-image: radial-gradient(circle, var(--dot) 1.1px, transparent 1.3px);
  background-size: 24px 24px;
}
#stage.tool-pen { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Ccircle cx='8' cy='8' r='3' fill='%23171614' stroke='white' stroke-width='1.5'/%3E%3C/svg%3E") 8 8, crosshair; }
#stage.tool-eraser { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='12' cy='12' r='9' fill='white' fill-opacity='.6' stroke='%23171614' stroke-width='1.5'/%3E%3C/svg%3E") 12 12, cell; }
#stage.tool-note, #stage.tool-text { cursor: crosshair; }
#stage.panning, #stage.space { cursor: grab; }
#stage.panning { cursor: grabbing; }

#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }

.item { position: absolute; left: 0; top: 0; pointer-events: none; }
.item.editing { pointer-events: auto; }
.item.sel { outline: calc(1.5px / var(--s)) solid var(--accent); outline-offset: calc(5px / var(--s)); }
.item .h {
  display: none; position: absolute;
  width: calc(12px / var(--s)); height: calc(12px / var(--s));
  right: calc(-11px / var(--s)); bottom: calc(-11px / var(--s));
  background: #fff; border: calc(1.5px / var(--s)) solid var(--accent); border-radius: 50%;
}
.item.sel.solo .h { display: block; }

.item.stroke svg { display: block; overflow: visible; }
.item.stroke path { fill: none; stroke-linecap: round; stroke-linejoin: round; }

.item.note {
  padding: 18px 18px 22px;
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(23,22,20,.05), 0 14px 26px -18px rgba(23,22,20,.45);
  transform: rotate(var(--rot, 0deg));
}
.item.note.white { box-shadow: 0 0 0 1px var(--line), 0 14px 26px -18px rgba(23,22,20,.45); }
.item.note .tx {
  width: 100%; height: 100%; overflow: hidden;
  font-size: 19px; line-height: 1.32; font-weight: 500; letter-spacing: -0.01em;
  white-space: pre-wrap; overflow-wrap: anywhere; outline: none;
}
.item.text .tx {
  display: inline-block; min-width: 0.6em; white-space: pre;
  font-size: var(--fs, 28px); line-height: 1.18; font-weight: 600; letter-spacing: -0.02em;
  outline: none; padding: 0 1px;
}
.item.text.editing .tx:empty::before { content: "type"; color: var(--muted); font-weight: 500; }
.item.image img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  border-radius: 4px; background: #e9e6dd;
  box-shadow: 0 1px 0 rgba(23,22,20,.05), 0 16px 30px -20px rgba(23,22,20,.5);
  -webkit-user-drag: none;
}
.item.image.pending img { opacity: .55; }
.item.link {
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 0 18px 0 52px; background: var(--panel); border-radius: 12px;
  box-shadow: 0 0 0 1px var(--line), 0 14px 26px -20px rgba(23,22,20,.45);
}
.item.link::before {
  content: ""; position: absolute; left: 16px; top: 50%; width: 22px; height: 22px; margin-top: -11px;
  border-radius: 6px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M8 16L16 8M10 8h6v6'/%3E%3C/svg%3E") center/16px no-repeat;
}
.item.link .host { font-weight: 600; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.link .url { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@keyframes plonk {
  0% { transform: translateY(-10px) scale(1.06) rotate(var(--rot, 0deg)); filter: drop-shadow(0 18px 14px rgba(23,22,20,.12)); }
  60% { transform: translateY(1px) scale(.985) rotate(var(--rot, 0deg)); }
  100% { transform: translateY(0) scale(1) rotate(var(--rot, 0deg)); }
}
.item.drop { animation: plonk .34s cubic-bezier(.3,.7,.3,1) both; }

#marquee { position: absolute; border: 1px solid var(--accent); background: rgba(255, 90, 31, .06); border-radius: 2px; pointer-events: none; }

#cursors { position: absolute; inset: 0; pointer-events: none; }
.cursor { position: absolute; left: 0; top: 0; transition: transform 90ms linear; will-change: transform; }
.cursor svg { display: block; width: 18px; height: 18px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.2)); }
.cursor span {
  position: absolute; left: 14px; top: 16px; padding: 2px 7px 3px; border-radius: 7px;
  color: #fff; font-size: 12px; font-weight: 500; white-space: nowrap;
}

/* ---------- ui ---------- */
.bar {
  position: fixed; z-index: 10; display: flex; align-items: center; gap: 8px;
  top: max(14px, env(safe-area-inset-top));
}
.bar.left { left: 14px; }
.bar.right { right: 14px; }
.brand {
  display: flex; align-items: center; height: 40px; padding: 0 14px 0 13px;
  background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
}
.wm { font-weight: 800; font-size: 21px; letter-spacing: -0.055em; line-height: 1; display: inline-flex; align-items: baseline; }
.wm i {
  display: inline-block; width: .5em; height: .5em; margin: 0 .045em 0 .06em;
  background: var(--accent); border-radius: .07em; transform: rotate(-12deg) translateY(-.02em);
}
.board-name { color: var(--muted); font-size: 13px; padding-left: 4px; white-space: nowrap; }
.status { font-size: 12px; color: var(--muted); padding: 0 10px; height: 28px; display: inline-flex; align-items: center; background: var(--panel); border-radius: 99px; box-shadow: var(--shadow); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 7px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.peers { display: flex; align-items: center; }
.peer {
  width: 30px; height: 30px; border-radius: 50%; margin-left: -7px;
  display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 600;
  border: 2px solid var(--paper); text-transform: uppercase;
}
.peer.more { background: var(--panel) !important; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); font-size: 11px; }
.share {
  height: 40px; padding: 0 18px; border-radius: 12px; margin-left: 6px;
  background: var(--ink); color: #fff; font-weight: 500; box-shadow: var(--shadow);
}
.share:active { transform: translateY(1px); }

.menu {
  position: fixed; z-index: 20; left: 14px; top: calc(max(14px, env(safe-area-inset-top)) + 48px);
  width: 260px; max-height: calc(100vh - 140px); overflow: auto;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow), 0 0 0 1px var(--line);
  padding: 6px;
}
.menu button { display: flex; width: 100%; align-items: center; justify-content: space-between; padding: 9px 10px; border-radius: 8px; text-align: left; }
.menu button:hover { background: #F2F0EA; }
.menu button.here { color: var(--accent); }
.menu-new { font-weight: 600; }
.menu kbd, .menu .when { color: var(--muted); font-size: 12px; font-weight: 400; }
.menu-label { color: var(--muted); font-size: 11.5px; padding: 12px 10px 4px; letter-spacing: .02em; }
.keys { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 5px 10px; margin: 4px 10px 6px; font-size: 12.5px; }
.keys dt { font-weight: 600; } .keys dd { margin: 0; color: var(--muted); }
.menu-foot { margin: 8px 10px 6px; color: var(--muted); font-size: 12px; }

.dock {
  position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 2px; padding: 5px;
  background: var(--panel); border-radius: 15px; box-shadow: var(--shadow), 0 0 0 1px var(--line);
}
.dock button { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; transition: background .12s; }
.dock button:hover { background: #F2F0EA; }
.dock button.on { background: var(--ink); color: #fff; }
.dock svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.dock button[data-tool="select"] svg path { fill: currentColor; stroke-width: 1.4; }
.dock .sep { width: 1px; height: 22px; background: var(--line); margin: 0 5px; }
.swatch { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(0,0,0,.12); }

.palette {
  position: fixed; z-index: 11; left: 50%; transform: translateX(-50%);
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 62px);
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow), 0 0 0 1px var(--line);
}
.colors, .sizes { display: flex; gap: 4px; }
.sizes { padding-left: 10px; border-left: 1px solid var(--line); }
.colors button, .sizes button { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; }
.colors button:hover, .sizes button:hover { background: #F2F0EA; }
.colors button span { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(0,0,0,.12); }
.colors button.on span { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--ink); }
.sizes button span { border-radius: 50%; background: var(--ink); }
.sizes button.on { background: #ECE9E1; }

.zoom { top: auto; bottom: max(16px, env(safe-area-inset-bottom)); left: 14px; gap: 0; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 3px; }
.zoom button { height: 34px; min-width: 34px; border-radius: 9px; font-size: 13px; color: var(--muted); }
.zoom button:hover { background: #F2F0EA; color: var(--ink); }
#zoomPct { min-width: 50px; font-variant-numeric: tabular-nums; }
#zoomIn, #zoomOut { font-size: 17px; }

#hint {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  text-align: center; pointer-events: none; z-index: 1;
}
.hint-title { font-weight: 800; font-size: clamp(34px, 6vw, 56px); letter-spacing: -0.05em; color: #C9C4B7; line-height: 1; }
.hint-sub { margin-top: 12px; color: var(--muted); font-size: 14px; }

.toast {
  position: fixed; z-index: 30; left: 50%; top: calc(max(14px, env(safe-area-inset-top)) + 4px);
  transform: translateX(-50%); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: #fff; font-weight: 500; box-shadow: var(--shadow);
  animation: toastIn .22s cubic-bezier(.3,.7,.3,1);
  max-width: calc(100vw - 32px); text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -6px); } }

@media (max-width: 640px) {
  .board-name, .zoom { display: none; }
  .dock button { width: 39px; height: 40px; }
  .dock .sep { margin: 0 2px; }
  .peer:nth-child(n+4) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .item.drop { animation: none; }
  .cursor { transition: none; }
}
