/* GlassBoard — original dark UI */
:root {
  --bg: #0f1117;
  --bg2: #141722;
  --panel: #1a1e2b;
  --panel2: #20253400;
  --border: #2a3040;
  --border2: #39415a;
  --text: #e8eaf2;
  --muted: #8b93a9;
  --accent: #7c5cff;
  --accent2: #22d3aa;
  --danger: #ef4466;
  --shadow: 0 8px 28px rgba(0,0,0,.45);
  --radius: 12px;
  font-size: 15px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent2); }

.logo-mark {
  width: 26px; height: 26px; position: relative; display: inline-block; flex: 0 0 26px;
}
.logo-mark::before, .logo-mark::after {
  content: ""; position: absolute; width: 17px; height: 17px; border-radius: 5px;
}
.logo-mark::before { left: 0; top: 0; background: var(--accent); }
.logo-mark::after  { right: 0; bottom: 0; background: var(--accent2); opacity: .88; }
.logo-word { font-weight: 700; letter-spacing: .2px; }
.logo-word em { font-style: normal; color: var(--accent2); }

.boot-splash {
  height: 100vh; display: flex; gap: 12px; align-items: center; justify-content: center;
  color: var(--muted);
}

/* ---------- generic controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 8px 14px; cursor: pointer; white-space: nowrap;
  transition: border-color .12s, background .12s, transform .05s;
}
.btn:hover { border-color: var(--border2); background: #202537; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #8d70ff; border-color: #8d70ff; }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 4px 10px; border-radius: 7px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 12px; outline: none; transition: border-color .12s;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.45; margin-top: 6px; }
.err-box { background: rgba(239,68,102,.1); border: 1px solid rgba(239,68,102,.4); color: #ff9fb3;
  border-radius: 9px; padding: 9px 12px; font-size: 13.5px; margin-bottom: 12px; display: none; }
.err-box.show { display: block; }

/* ---------- auth / setup ---------- */
.center-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(700px 400px at 15% 10%, rgba(124,92,255,.14), transparent 60%),
    radial-gradient(700px 400px at 85% 90%, rgba(34,211,170,.10), transparent 60%), var(--bg);
  overflow: auto;
}
.auth-card {
  width: 420px; max-width: 100%; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 30px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 21px; margin: 14px 0 4px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; line-height: 1.5; }
.auth-head { display: flex; align-items: center; gap: 10px; font-size: 19px; }
.auth-switch { margin-top: 16px; font-size: 13.5px; color: var(--muted); text-align: center; }
.auth-switch a { cursor: pointer; }
.auth-card .btn-primary { width: 100%; padding: 11px; margin-top: 4px; }

/* ---------- boards home ---------- */
.home { height: 100vh; overflow: auto; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 22px;
  border-bottom: 1px solid var(--border); background: rgba(15,17,23,.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.topbar .spacer { flex: 1; }
.home-inner { max-width: 1060px; margin: 0 auto; padding: 30px 22px 60px; }
.home-inner h2 { font-size: 17px; color: var(--muted); font-weight: 600; margin-bottom: 16px; }
.boards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.board-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; position: relative; min-height: 118px;
  display: flex; flex-direction: column; transition: border-color .12s, transform .12s;
}
.board-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.board-card h3 { font-size: 15.5px; margin-bottom: 6px; word-break: break-word; }
.board-card .meta { font-size: 12.5px; color: var(--muted); margin-top: auto; line-height: 1.5; }
.board-card .card-menu {
  position: absolute; top: 10px; right: 10px; border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 17px; padding: 2px 7px; border-radius: 6px; line-height: 1;
}
.board-card .card-menu:hover { background: var(--bg2); color: var(--text); }
.board-card.new {
  border-style: dashed; align-items: center; justify-content: center; color: var(--muted);
  flex-direction: row; gap: 8px; font-size: 15px;
}
.board-card.new:hover { color: var(--accent); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; flex: 0 0 30px; user-select: none;
}

/* ---------- canvas ---------- */
#canvas {
  position: fixed; inset: 0; overflow: hidden; touch-action: none;
  background-color: var(--bg);
  background-image: radial-gradient(circle, #262c3d 1.1px, transparent 1.1px);
  background-size: 26px 26px; cursor: default;
}
#canvas.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#edgeSvg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#edgeSvg .edge { stroke: #4a5470; stroke-width: 2.2; fill: none; pointer-events: stroke; cursor: pointer; }
#edgeSvg .edge:hover { stroke: var(--danger); }
#edgeSvg .edge-hit { stroke: transparent; stroke-width: 14; fill: none; pointer-events: stroke; cursor: pointer; }
#edgeSvg .edge-temp { stroke: var(--accent); stroke-width: 2.2; stroke-dasharray: 6 5; fill: none; }

.board-topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; pointer-events: none;
}
.board-topbar > * { pointer-events: auto; }
.board-title-input {
  background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 6px 10px;
  font-weight: 600; font-size: 15px; width: 230px; outline: none;
}
.board-title-input:hover, .board-title-input:focus { border-color: var(--border); background: var(--panel); }
.presence-strip { display: flex; align-items: center; margin-left: auto; }
.presence-strip .avatar { width: 28px; height: 28px; font-size: 12px; margin-left: -7px; border: 2px solid var(--bg); }

.toolbar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 40;
  display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 6px; box-shadow: var(--shadow);
}
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 62px;
  background: transparent; border: none; border-radius: 10px; padding: 7px 8px 6px; cursor: pointer; color: var(--text);
}
.tool-btn:hover { background: #262c3f; }
.tool-btn .ico { font-size: 18px; line-height: 1; }
.tool-btn small { font-size: 10.5px; color: var(--muted); }

.zoombar {
  position: fixed; right: 16px; bottom: 18px; z-index: 40; display: flex; align-items: center; gap: 2px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 3px;
}
.zoombar button { background: transparent; border: none; color: var(--text); width: 30px; height: 28px; cursor: pointer; border-radius: 7px; font-size: 15px; }
.zoombar button:hover { background: #262c3f; }
.zoombar .zlevel { font-size: 12px; color: var(--muted); width: 46px; text-align: center; cursor: pointer; }

.help-tip {
  position: fixed; left: 16px; bottom: 18px; z-index: 40; color: var(--muted); font-size: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; line-height: 1.6;
  max-width: 260px;
}

/* ---------- nodes ---------- */
.node {
  position: absolute; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 3px 14px rgba(0,0,0,.35); display: flex; flex-direction: column; min-width: 170px; min-height: 90px;
}
.node.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(124,92,255,.35), 0 3px 14px rgba(0,0,0,.35); }
.node.drop-target { border-color: var(--accent2); box-shadow: 0 0 0 2px rgba(34,211,170,.5); }
.node-head {
  display: flex; align-items: center; gap: 7px; padding: 8px 10px; cursor: grab; user-select: none;
  border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12.5px; min-height: 34px;
}
.node-head:active { cursor: grabbing; }
.node-head .t-ico { font-size: 13px; }
.node-head .t-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.node-head .head-btn {
  background: transparent; border: none; color: var(--muted); cursor: pointer; border-radius: 5px;
  padding: 2px 6px; font-size: 13px; line-height: 1;
}
.node-head .head-btn:hover { color: var(--text); background: #262c3f; }
.node-head .head-btn.del:hover { color: var(--danger); }
.node-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; position: relative; }

.port {
  position: absolute; width: 14px; height: 14px; border-radius: 50%; background: var(--bg);
  border: 2.5px solid var(--accent); top: 50%; margin-top: -7px; cursor: crosshair; z-index: 3;
  opacity: 0; transition: opacity .12s, transform .12s;
}
.port.left { left: -8px; }
.port.right { right: -8px; }
.node:hover .port, .port.active { opacity: 1; }
.port:hover { transform: scale(1.35); background: var(--accent); }
.rs {
  position: absolute; right: -2px; bottom: -2px; width: 16px; height: 16px; cursor: nwse-resize; z-index: 3;
  border-right: 2.5px solid var(--border2); border-bottom: 2.5px solid var(--border2); border-radius: 0 0 6px 0;
}
.node:hover .rs { border-color: var(--accent); }

/* note */
.node-note .node-body textarea {
  flex: 1; width: 100%; background: transparent; border: none; resize: none; outline: none;
  padding: 10px 12px; line-height: 1.55; font-size: 14px; color: var(--text);
}
.node-note { background: #211f33; }

/* image */
.node-image .node-body { align-items: center; justify-content: center; background: #0c0e14; border-radius: 0 0 var(--radius) var(--radius); }
.node-image img { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; }

/* pdf */
.file-tile { display: flex; gap: 11px; padding: 12px; align-items: flex-start; overflow: hidden; }
.file-tile .f-ico { font-size: 26px; }
.file-tile .f-name { font-size: 13.5px; font-weight: 600; word-break: break-all; }
.file-tile .f-meta { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.file-excerpt { padding: 0 12px 10px; color: var(--muted); font-size: 12px; line-height: 1.5; overflow: hidden; flex: 1; }

/* youtube / link */
.yt-thumb { position: relative; flex: 1; background: #000; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; cursor: pointer; min-height: 90px; }
.yt-thumb img { width: 100%; height: 100%; object-fit: cover; opacity: .85; }
.yt-thumb .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 40px;
  color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,.7);
}
.yt-frame { flex: 1; width: 100%; border: none; border-radius: 0 0 var(--radius) var(--radius); }
.src-status { font-size: 11.5px; padding: 3px 8px; border-radius: 20px; display: inline-block; margin-top: 6px; }
.src-status.ok { background: rgba(34,211,170,.15); color: var(--accent2); }
.src-status.warn { background: rgba(245,158,11,.15); color: #f5b04b; }
.src-status.load { background: rgba(124,92,255,.15); color: #a891ff; }

/* chat node */
.node-chat { background: #171c2b; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.msg { max-width: 92%; border-radius: 11px; padding: 8px 12px; font-size: 13.5px; line-height: 1.55; word-wrap: break-word; overflow-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: #232940; border-bottom-left-radius: 4px; }
.msg.ai.streaming::after { content: "▍"; color: var(--accent2); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg .m-meta { font-size: 10.5px; opacity: .65; margin-top: 5px; }
.msg pre { background: #10131c; border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; overflow-x: auto; margin: 7px 0; font-size: 12.5px; }
.msg code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; background: rgba(0,0,0,.28); border-radius: 4px; padding: 1px 5px; }
.msg pre code { background: transparent; padding: 0; }
.msg p { margin: 5px 0; } .msg p:first-child { margin-top: 0; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 5px 0 5px 20px; } .msg li { margin: 3px 0; }
.msg h1, .msg h2, .msg h3 { font-size: 14.5px; margin: 9px 0 5px; }
.msg blockquote { border-left: 3px solid var(--border2); padding-left: 10px; margin: 6px 0; color: var(--muted); }
.msg.notice { align-self: center; background: transparent; color: var(--muted); font-size: 12px; text-align: center; }
.msg.error { align-self: stretch; background: rgba(239,68,102,.12); border: 1px solid rgba(239,68,102,.35); color: #ff9fb3; max-width: 100%; }
.chat-foot { border-top: 1px solid var(--border); padding: 8px; display: flex; flex-direction: column; gap: 7px; }
.chat-ctx { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); padding: 0 3px; flex-wrap: wrap; }
.chip { background: #232940; border: 1px solid var(--border); padding: 2px 9px; border-radius: 20px; font-size: 11px; white-space: nowrap; }
.chip.ctx-on { border-color: rgba(34,211,170,.5); color: var(--accent2); }
.chat-inrow { display: flex; gap: 7px; align-items: flex-end; }
.chat-inrow textarea {
  flex: 1; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; resize: none;
  padding: 9px 11px; font-size: 13.5px; outline: none; max-height: 130px; min-height: 38px; line-height: 1.45;
}
.chat-inrow textarea:focus { border-color: var(--accent); }
.chat-send {
  background: var(--accent); color: #fff; border: none; border-radius: 10px; width: 38px; height: 38px;
  cursor: pointer; font-size: 16px; flex: 0 0 38px;
}
.chat-send:hover { background: #8d70ff; }
.chat-send[disabled] { opacity: .5; cursor: not-allowed; }
.chat-model {
  background: var(--bg2); color: var(--muted); border: 1px solid var(--border); border-radius: 8px;
  font-size: 11.5px; padding: 4px 6px; outline: none; max-width: 190px;
}

/* voice notes */
.voice-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 12px; overflow: hidden; }
.voice-wrap.saved { align-items: stretch; justify-content: flex-start; gap: 8px; padding: 10px; }
.voice-wrap audio { width: 100%; height: 36px; border-radius: 9px; }
.rec-row { display: flex; align-items: center; gap: 12px; }
.rec-btn {
  width: 54px; height: 54px; border-radius: 50%; border: 2.5px solid var(--danger); background: rgba(239,68,102,.12);
  color: var(--danger); font-size: 19px; cursor: pointer; transition: transform .1s, background .15s;
}
.rec-btn:hover { background: rgba(239,68,102,.22); transform: scale(1.05); }
.rec-btn.recording { background: var(--danger); color: #fff; animation: recpulse 1.4s infinite; }
@keyframes recpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,102,.5); } 50% { box-shadow: 0 0 0 9px rgba(239,68,102,0); } }
.rec-timer { font-family: ui-monospace, Menlo, monospace; font-size: 15px; color: var(--muted); min-width: 44px; }
.rec-live {
  width: 100%; max-height: 76px; overflow-y: auto; font-size: 12.5px; color: var(--muted); line-height: 1.5;
  text-align: center; padding: 0 6px;
}
.rec-live:not(:empty) { color: var(--text); }
.voice-ta {
  flex: 1; width: 100%; background: var(--bg2); border: 1px solid var(--border); border-radius: 9px; resize: none;
  outline: none; padding: 8px 10px; font-size: 12.5px; line-height: 1.5; color: var(--text); min-height: 56px;
}
.voice-ta:focus { border-color: var(--accent); }

/* presence cursors */
.pcursor { position: absolute; z-index: 30; pointer-events: none; transition: transform .35s linear; transform-origin: 0 0; }
.pcursor svg { display: block; filter: drop-shadow(0 1px 3px rgba(0,0,0,.5)); }
.pcursor .pname {
  margin: 2px 0 0 12px; font-size: 11px; padding: 2px 8px; border-radius: 20px; color: #fff; white-space: nowrap; font-weight: 600;
}

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(5,6,10,.6); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: 460px; max-width: 100%; max-height: 86vh; overflow: auto; box-shadow: var(--shadow); }
.modal h2 { font-size: 17px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.modal .row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.modal .row:last-child { border-bottom: none; }
.modal .row .grow { flex: 1; min-width: 0; }
.modal .row .sub { color: var(--muted); font-size: 12px; }
.join-code {
  font-family: ui-monospace, Menlo, monospace; font-size: 19px; letter-spacing: 3px; background: var(--bg2);
  border: 1px dashed var(--border2); border-radius: 9px; padding: 10px 14px; text-align: center; user-select: all;
}
.modal-close { margin-left: auto; background: transparent; border: none; color: var(--muted); font-size: 19px; cursor: pointer; }

/* toasts */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent2);
  border-radius: 10px; padding: 11px 15px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 340px;
  animation: slidein .18s ease-out;
}
.toast.error { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2c3346; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
