:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --danger: #dc2626;

  --support: #16a34a;
  --rebut: #dc2626;
  --neutral: #64748b;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- home --- */

.home { max-width: 720px; margin: 0 auto; padding: 64px 24px 96px; }
.home-head h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.02em; }
.home-head p { margin: 0 0 28px; }
.home code { background: #eef2f7; padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.new-map { display: flex; gap: 8px; margin-bottom: 28px; }
.new-map input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel);
}
.new-map input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.new-map button {
  padding: 10px 16px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}

.map-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.map-list li {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.map-link {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  padding: 12px 14px; text-decoration: none; color: inherit;
}
.map-title { font-weight: 600; }
.map-list form { margin: 0; padding-right: 10px; }
.danger-link {
  background: none; border: 0; color: var(--muted);
  cursor: pointer; padding: 6px 8px; border-radius: 6px; font-size: 13px;
}
.danger-link:hover { color: var(--danger); background: #fee2e2; }
.empty { color: var(--muted); }

/* -------------------------------------------------------------- editor --- */

.page-editor { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: none;
}
.back {
  text-decoration: none; color: var(--muted); font-size: 18px;
  padding: 2px 8px; border-radius: 6px;
}
.back:hover { background: #eef2f7; color: var(--ink); }
.title-input {
  border: 1px solid transparent; background: transparent;
  padding: 5px 8px; border-radius: 6px; font-weight: 600; font-size: 15px; min-width: 180px;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--accent); background: #fff; }
.save-status { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }

.btn {
  padding: 6px 10px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 7px; cursor: pointer; color: var(--ink);
}
.btn:hover { background: #eef2f7; }
.btn:disabled { opacity: .4; cursor: default; background: var(--panel); }
.zoom-group { display: flex; gap: 4px; margin-left: 4px; }
.zoom-level { min-width: 54px; font-variant-numeric: tabular-nums; }

.workspace { flex: 1; display: flex; min-height: 0; }

.viewport {
  position: relative; flex: 1; overflow: hidden; cursor: default;
  background-color: #f6f7f9;
  background-image: radial-gradient(circle, #d3d9e2 1px, transparent 1px);
  background-size: 24px 24px;
  touch-action: none;
}
.viewport.panning { cursor: grabbing; }
.world { position: absolute; inset: 0; transform-origin: 0 0; }

.edge-layer {
  position: absolute; left: -50000px; top: -50000px;
  width: 100000px; height: 100000px; overflow: visible;
}
/* The layers span the whole canvas, so they must not swallow clicks meant for
   the edges underneath — only the boxes themselves are hit targets. */
.node-layer, .label-layer { position: absolute; inset: 0; pointer-events: none; }
.node { pointer-events: auto; }

.hint {
  position: absolute; left: 12px; bottom: 10px; margin: 0;
  color: var(--muted); font-size: 12px; pointer-events: none; user-select: none;
}

/* ---------------------------------------------------------------- node --- */

.node {
  position: absolute; border: 1.5px solid; border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; padding: 2px;
  cursor: grab; user-select: none;
}
.node.dragging { cursor: grabbing; }
.node.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.node.link-target { outline: 2px dashed var(--accent); outline-offset: 2px; }

.node-text {
  flex: 1; padding: 8px 10px; overflow: auto; white-space: pre-wrap;
  word-break: break-word; outline: none; cursor: inherit;
}
.node-text b, .node-text strong { font-weight: 700; }
.node-text:focus { cursor: text; user-select: text; }
.node-text.placeholder::before {
  content: "Claim…"; color: var(--muted); opacity: .7;
}

.port {
  position: absolute; width: 11px; height: 11px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent);
  opacity: 0; transition: opacity .12s; cursor: crosshair;
}
.node:hover .port, .node.selected .port { opacity: 1; }
.port[data-side="top"]    { top: -6px;  left: 50%; margin-left: -5.5px; }
.port[data-side="bottom"] { bottom: -6px; left: 50%; margin-left: -5.5px; }
.port[data-side="left"]   { left: -6px; top: 50%; margin-top: -5.5px; }
.port[data-side="right"]  { right: -6px; top: 50%; margin-top: -5.5px; }

.resize-handle {
  position: absolute; right: -4px; bottom: -4px; width: 12px; height: 12px;
  border-radius: 3px; background: #fff; border: 2px solid var(--accent);
  opacity: 0; cursor: nwse-resize;
}
.node:hover .resize-handle, .node.selected .resize-handle { opacity: 1; }

/* ---------------------------------------------------------------- edge --- */

.edge-line { fill: none; stroke-width: 2; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 16; cursor: pointer; }
.edge.selected .edge-line { stroke-width: 4; }
.temp-edge { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; }

.edge-label {
  position: absolute; transform: translate(-50%, -50%);
  padding: 1px 6px; border-radius: 6px; background: rgba(255,255,255,.92);
  border: 1px solid var(--line); font-size: 12px; color: var(--muted);
  max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ----------------------------------------------------------- inspector --- */

.inspector {
  width: 268px; flex: none; padding: 16px; overflow-y: auto;
  background: var(--panel); border-left: 1px solid var(--line);
}
.insp-title { font-weight: 600; margin: 0 0 12px; }
.insp-section { margin-bottom: 18px; }
.insp-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: 7px;
}
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch {
  width: 26px; height: 26px; border-radius: 7px; cursor: pointer;
  border: 1.5px solid; padding: 0;
}
.swatch.active { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-text { display: flex; align-items: center; justify-content: center; font-weight: 700; }

.type-buttons { display: flex; flex-direction: column; gap: 6px; }
.type-btn {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 7px; cursor: pointer; text-align: left;
}
.type-btn:hover { background: #eef2f7; }
.type-btn.active { border-color: var(--accent); background: #eff6ff; }
.type-dot { width: 24px; height: 0; border-top-width: 2.5px; border-top-style: solid; flex: none; }
.type-row { display: flex; gap: 6px; }
.type-row .type-btn { flex: 1; justify-content: center; padding: 7px 4px; }

.insp-input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--panel);
}
.insp-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.delete-btn {
  width: 100%; padding: 8px; border: 1px solid #fecaca; background: #fef2f2;
  color: var(--danger); border-radius: 7px; cursor: pointer; font-weight: 500;
}
.delete-btn:hover { background: #fee2e2; }

.keys { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.keys li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.keys kbd {
  background: #f1f5f9; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 0 5px; font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* text formatting + size controls */

.format-row { display: flex; gap: 6px; margin-top: 8px; }
.fmt-btn {
  flex: 1; padding: 6px 0; border: 1px solid var(--line); background: var(--panel);
  border-radius: 7px; cursor: pointer; font-size: 15px; line-height: 1.2;
}
.fmt-btn:hover { background: #eef2f7; }
.fmt-btn.b { font-weight: 700; }
.fmt-btn.i { font-style: italic; font-family: Georgia, serif; }
.fmt-btn.u { text-decoration: underline; }
.fmt-btn.s { text-decoration: line-through; }

.size-row { display: flex; align-items: center; gap: 6px; }
.size-row select {
  flex: 1; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--panel);
}

.line-preview { flex: 1; height: 0; border-top-width: 2.5px; }

/* ------------------------------------------------------------ accounts --- */

a { color: var(--accent); }
a.plain { color: inherit; text-decoration: none; }
.home-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.account { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.account form { margin: 0; }
.link-btn {
  background: none; border: 0; padding: 0; color: var(--accent);
  cursor: pointer; text-decoration: underline;
}
.btn-primary {
  display: inline-block; padding: 10px 16px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-primary:hover { background: #1d4ed8; }
.small-btn { padding: 6px 12px; border-radius: 7px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.message h2 { margin: 0 0 6px; font-size: 18px; }
.message p:last-child { margin-bottom: 0; }
.actions { display: flex; align-items: center; gap: 16px; }

.auth { max-width: 420px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; }
.auth-form input {
  padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel); font-weight: 400;
}
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.auth-form p { margin: 0; }
.auth-switch { margin-top: 16px; }
.form-error {
  margin: 0; padding: 8px 10px; border-radius: 7px;
  background: #fef2f2; border: 1px solid #fecaca; color: var(--danger);
}

.list-head {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 28px 0 10px; font-weight: 600;
}

/* ------------------------------------------------------- collaboration --- */

.presence { display: flex; align-items: center; margin-right: 6px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; border: 2px solid var(--panel);
  margin-left: -6px; cursor: default; user-select: none;
}
.avatar:first-child { margin-left: 0; }
.avatar.me { box-shadow: 0 0 0 1.5px var(--accent); }

.role-badge {
  font-size: 12px; color: var(--muted); background: #eef2f7;
  padding: 2px 8px; border-radius: 999px;
}
.btn-share { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-share:hover { background: #1d4ed8; }

.readonly .port, .readonly .resize-handle { display: none; }
.readonly .node { cursor: default; }
.readonly .title-input:hover { border-color: transparent; }

.toasts {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; z-index: 10; max-width: min(520px, calc(100% - 32px));
}
.toast {
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px;
  box-shadow: var(--shadow); font-size: 13px; transition: opacity .4s;
}
.toast-warn { background: #92400e; }
.toast-error { background: var(--danger); }
.toast.gone { opacity: 0; }

.share-dialog {
  width: min(480px, calc(100% - 32px)); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px; box-shadow: 0 20px 60px rgba(15, 23, 42, .25);
  color: var(--ink);
}
.share-dialog::backdrop { background: rgba(15, 23, 42, .35); }
.share-dialog h2 { margin: 0 0 16px; font-size: 17px; padding-right: 24px; overflow-wrap: anywhere; }
.share-close { position: absolute; right: 12px; top: 10px; margin: 0; }
.icon-btn {
  background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted);
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: #eef2f7; color: var(--ink); }
.share-add { display: flex; gap: 6px; margin-bottom: 8px; }
.share-add .insp-input:first-child { flex: 1; }
.share-add select { width: auto; }
.share-dialog .form-error { margin-bottom: 10px; }
.share-people { list-style: none; margin: 0 0 18px; padding: 0; }
.share-people li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.share-people li:last-child { border-bottom: 0; }
.share-name { font-weight: 500; overflow-wrap: anywhere; }
.share-member-role { width: auto; }
.share-general p { margin: 6px 0 10px; }
.share-link-row { display: flex; gap: 6px; margin-bottom: 8px; }
.share-link-row .insp-input { flex: 1; font-size: 12px; color: var(--muted); }
.link-off .share-link-row, .link-off #share-reset { display: none; }

@media (max-width: 720px) {
  .zoom-group, .hint { display: none; }
  .inspector { display: none; }
  .title-input { min-width: 0; flex: 1; }
}
