:root {
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f8fafc;
  --card: #ffffff;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .10), 0 2px 6px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
  user-select: none; white-space: nowrap;
}
.btn:hover { background: #f1f5f9; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef2f7; color: var(--ink); }
.btn.big { padding: 12px 20px; font-size: 15px; border-radius: 12px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  border: none; background: transparent; font-size: 18px; cursor: pointer; color: var(--ink);
  padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: #eef2f7; }
.close-x { border: none; background: transparent; font-size: 15px; cursor: pointer; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.close-x:hover { background: #eef2f7; color: var(--ink); }

/* ---------- home ---------- */
#home-view { height: 100%; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.home-card {
  width: min(560px, 100%); background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 36px 36px 28px; border: 1px solid var(--line);
}
.logo { font-weight: 700; font-size: 15px; letter-spacing: .02em; color: var(--accent); margin-bottom: 18px; }
.logo-mark { font-size: 18px; }
.home-card h1 { font-size: 30px; line-height: 1.15; margin: 0 0 10px; letter-spacing: -.02em; }
.home-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 15px; }
.home-actions { display: flex; flex-direction: column; gap: 10px; }
.join-row { display: flex; gap: 8px; }
#join-code {
  flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; font-size: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; text-transform: lowercase; text-align: center;
}
#join-code:focus { outline: 2px solid var(--accent); border-color: transparent; }
#recent-section { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 18px; }
#recent-section h2 { font-size: 14px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#recent-list { list-style: none; margin: 0; padding: 0; }
#recent-list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: 10px; cursor: pointer;
}
#recent-list li:hover { background: #f1f5f9; }
.recent-name { font-weight: 600; font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; letter-spacing: .08em;
  background: #eff6ff; color: var(--accent); border-radius: 6px; padding: 3px 8px;
}
.recent-role { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.recent-remove { border: none; background: transparent; color: #9ca3af; cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.recent-remove:hover { color: var(--danger); background: #fef2f2; }
.hint { font-size: 12px; color: #94a3b8; margin-top: 22px; }

/* ---------- board chrome ---------- */
#board-view { height: 100%; display: flex; flex-direction: column; }
#topbar {
  position: relative; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
#board-name { font-weight: 700; font-size: 15px; padding: 4px 8px; border-radius: 8px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board-name.admin-editable:hover { background: #eef2f7; cursor: text; }
.badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: 3px 8px; border-radius: 99px; background: #e5e7eb; color: #374151;
}
.badge.role-admin { background: #fef3c7; color: #92400e; }
.badge.role-editor { background: #dbeafe; color: #1e40af; }
.badge.role-commenter { background: #ede9fe; color: #5b21b6; }
.badge.role-viewer { background: #e5e7eb; color: #4b5563; }
.badge.role-banned { background: #fee2e2; color: #991b1b; }
.conn { width: 9px; height: 9px; border-radius: 99px; display: inline-block; }
.conn.connecting { background: #f59e0b; }
.conn.open { background: #16a34a; }
.conn.closed { background: var(--danger); }
#online-count { font-size: 12px; }
#restrict-banner {
  z-index: 29; background: #fef2f2; color: #991b1b; border-bottom: 1px solid #fecaca;
  padding: 8px 16px; font-size: 13px; text-align: center;
}
#restrict-banner.readonly { background: #f8fafc; color: var(--muted); border-bottom-color: var(--line); }

/* ---------- canvas ---------- */
#viewport { position: relative; flex: 1; overflow: hidden; background: #fff; cursor: grab; touch-action: none; }
#viewport.panning { cursor: grabbing; }
#world { position: absolute; top: 0; left: 0; will-change: transform; transform-origin: 0 0; }
#world::before {
  content: ""; position: absolute; inset: -20000px; pointer-events: none;
  background-image: radial-gradient(circle, #d4d9e2 1.2px, transparent 1.3px);
  background-size: 24px 24px;
  opacity: .7;
}
#elements-layer { position: absolute; top: 0; left: 0; }
#empty-hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: #94a3b8; background: rgba(255,255,255,.85); border: 1px solid var(--line);
  padding: 6px 14px; border-radius: 99px; pointer-events: none; white-space: nowrap;
}
#cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.cursor-tag { position: absolute; transition: left .06s linear, top .06s linear; }
.cursor-tag .arrow { width: 14px; height: 14px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.cursor-tag .label {
  margin-left: 10px; margin-top: 8px; font-size: 11px; font-weight: 600; color: #fff;
  padding: 2px 8px; border-radius: 99px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.cursor-tag.stale { opacity: 0; transition: opacity .6s ease; }

/* ---------- elements ---------- */
.element { position: absolute; cursor: move; }
.element.selected { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 10px; }
.el-text {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 10px 14px;
  width: 260px; box-shadow: 0 2px 10px rgba(0,0,0,.07); font-size: 15px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}
.el-text.wide { width: 420px; }
.el-text .text-body.empty { color: #b6b1a3; font-style: italic; }
.el-text textarea {
  display: block; border: none; background: transparent; resize: none; outline: none;
  font: inherit; line-height: inherit; padding: 0; margin: 0; min-width: 240px; color: inherit;
}
.el-image { background: #fff; padding: 6px; border-radius: 12px; box-shadow: 0 2px 14px rgba(0,0,0,.12); border: 1px solid var(--line); }
.el-image img { display: block; max-width: 520px; border-radius: 8px; user-select: none; -webkit-user-drag: none; }
.el-link {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 280px;
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
}
.el-link .lk-title { font-weight: 600; font-size: 14px; line-height: 1.3; margin-bottom: 4px; word-break: break-word; }
.el-link .lk-domain { font-size: 12px; color: var(--accent); display: flex; align-items: center; gap: 6px; }
.el-link .lk-url { font-size: 11px; color: var(--muted); margin-top: 3px; word-break: break-all; }
.el-link img.fav { width: 16px; height: 16px; border-radius: 4px; }

/* per-element hover actions (counter-scaled so they stay readable at any zoom) */
.el-actions {
  position: absolute; top: -14px; right: -10px; display: none; gap: 4px;
  transform: scale(calc(1 / var(--z, 1))); transform-origin: top right;
}
.element:hover .el-actions, .element.selected .el-actions { display: flex; }
.el-actions button {
  width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; font-size: 13px; line-height: 1; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.12); padding: 0;
}
.el-actions button:hover { background: #f1f5f9; }
.el-actions button.act-del:hover { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.comment-chip {
  position: absolute; bottom: -10px; left: 8px; font-size: 11px; font-weight: 700; color: #fff;
  background: #7c3aed; border-radius: 99px; padding: 2px 8px; box-shadow: 0 2px 6px rgba(0,0,0,.2);
  transform: scale(calc(1 / var(--z, 1))); transform-origin: bottom left; pointer-events: none;
}
.comment-chip::before { content: "💬 "; font-size: 10px; }

/* ---------- floating panels & modals ---------- */
.floating {
  position: fixed; z-index: 40; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 14px;
}
.fp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 14px; }
.fp-row { display: flex; gap: 8px; margin-top: 10px; }
.fp-row.center { justify-content: center; }
.fp-hint { font-size: 12px; margin-top: 10px; }
#paste-panel { top: 64px; right: 16px; width: min(420px, calc(100vw - 32px)); }
#paste-text {
  width: 100%; height: 130px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font: inherit; font-size: 14px; resize: vertical;
}
#paste-text:focus { outline: 2px solid var(--accent); border-color: transparent; }
#comments-panel { top: 64px; right: 16px; width: min(360px, calc(100vw - 32px)); max-height: min(560px, calc(100vh - 120px)); display: flex; flex-direction: column; }
.comment-preview {
  font-size: 12px; border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px;
  max-height: 60px; overflow: hidden;
}
#comment-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#comment-list li { padding: 8px 6px; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.comment-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; display: flex; justify-content: space-between; gap: 6px; }
.comment-del { border: none; background: none; color: #9ca3af; cursor: pointer; font-size: 11px; padding: 0 4px; border-radius: 4px; }
.comment-del:hover { color: var(--danger); }
.comment-text { white-space: pre-wrap; word-break: break-word; }
#comment-composer { margin-top: 8px; }
#comment-input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; font-size: 13px; }
#comment-input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.35); display: flex;
  align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  width: min(440px, 100%); background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  padding: 20px; max-height: 80vh; overflow: auto;
}
.share-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 34px; letter-spacing: .25em;
  text-align: center; background: #eff6ff; color: var(--accent-dark); border-radius: 12px; padding: 18px 10px; margin-bottom: 12px;
  text-transform: lowercase; user-select: all;
}
#name-modal input, .modal-card input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 15px;
}
#name-modal input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* people list */
#users-list { list-style: none; margin: 0; padding: 0; }
#users-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.user-dot { width: 12px; height: 12px; border-radius: 99px; flex-shrink: 0; }
.user-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-you { font-size: 10px; color: var(--muted); font-weight: 500; border: 1px solid var(--line); padding: 1px 6px; border-radius: 99px; }
.user-online { width: 8px; height: 8px; border-radius: 99px; background: #16a34a; }
.user-offline { width: 8px; height: 8px; border-radius: 99px; background: #d1d5db; }
.user-role {
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font-size: 12px; background: #fff; font: inherit;
}
.user-role:disabled { border: none; background: none; color: var(--muted); }
.user-kick { border: 1px solid #fecaca; background: #fff; color: var(--danger); border-radius: 8px; font-size: 12px; padding: 4px 10px; cursor: pointer; }
.user-kick:hover { background: #fef2f2; }

/* ---------- toolbar & zoom ---------- */
#toolbar {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 35;
  display: flex; gap: 6px; background: rgba(255,255,255,.95); border: 1px solid var(--line);
  border-radius: 14px; padding: 6px; box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.tb-btn {
  border: none; background: transparent; font-size: 13px; font-weight: 500; padding: 8px 12px;
  border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.tb-btn:hover { background: #f1f5f9; }
.tb-btn.danger:hover { background: #fef2f2; color: var(--danger); }
.chip { background: #ede9fe; color: #5b21b6; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
#zoom-controls {
  position: fixed; right: 16px; bottom: 18px; z-index: 35; display: flex; align-items: center; gap: 2px;
  background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 12px; padding: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,.1);
}
#zoom-controls button { border: none; background: transparent; font-size: 14px; padding: 6px 10px; cursor: pointer; border-radius: 8px; min-width: 34px; }
#zoom-controls button:hover { background: #f1f5f9; }
#zoom-label { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #111827; color: #fff; font-size: 13px; padding: 10px 18px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: toast-in .18s ease; max-width: 80vw;
}
.toast.error { background: var(--danger); }
.toast.ok { background: #15803d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

@media (max-width: 640px) {
  .tb-right .btn.ghost { display: none; }
  #board-name { max-width: 30vw; }
  .home-card { padding: 26px 20px 20px; }
}
