/* ============ base ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a1c20;
  color: #eaeaea;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
}

/* ============ sidebar ============ */
#sidebar {
  position: fixed;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  background: rgba(20,22,28,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 200;
  box-shadow: 0 10px 32px rgba(0,0,0,0.4);
}
.tool {
  width: 40px;
  height: 40px;
  background: transparent;
  border: 0;
  color: #aaa;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.tool:hover { background: rgba(255,255,255,0.06); color: #eaeaea; }
.tool.active {
  background: #4a9eff;
  color: white;
}

/* ============ auth modal ============ */
#auth-modal {
  position: fixed; inset: 0; z-index: 4000;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
}
#auth-modal[hidden] { display: none; }
.auth-box {
  position: relative;
  width: 340px; max-width: 92vw;
  background: #1f2127;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  display: flex; flex-direction: column; gap: 10px;
}
.auth-x { position: absolute; top: 12px; right: 14px; background: none; border: 0; color: #888; font-size: 16px; cursor: pointer; }
.auth-title { font-size: 16px; font-weight: 700; color: #eaeaea; margin-bottom: 4px; }
.auth-discord {
  background: #5865F2; color: #fff; border: 0; border-radius: 9px;
  padding: 11px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.auth-discord:hover { filter: brightness(1.08); }
.auth-or { display: flex; align-items: center; gap: 8px; color: #777; font-size: 12px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: rgba(255,255,255,0.1); }
#auth-modal input {
  background: #15161a; border: 1px solid rgba(255,255,255,0.12); color: #eaeaea;
  border-radius: 8px; padding: 10px 12px; font-size: 14px; outline: none;
}
#auth-modal input:focus { border-color: #4a9eff; }
.auth-row { display: flex; gap: 8px; }
.auth-row button {
  flex: 1; border-radius: 8px; padding: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.12); background: #2a2c34; color: #eaeaea;
}
.auth-row button.primary { background: #4a9eff; border-color: #4a9eff; color: #fff; }
.auth-row button:hover { filter: brightness(1.1); }
.auth-msg { font-size: 12px; color: #ff8a8a; min-height: 16px; }
.auth-msg.ok { color: #6fcc4f; }
#btn-account { font-weight: 700; }
/* accent the Sign in button so it draws attention */
#btn-account.accent {
  background: linear-gradient(180deg, #4ea1ff, #2f6dff) !important;
  color: #fff !important;
  border-color: #2f6dff !important;
  box-shadow: 0 0 0 3px rgba(74,158,255,0.25), 0 6px 18px rgba(47,109,255,0.4);
  animation: acc-pulse 2.2s ease-in-out infinite;
}
@keyframes acc-pulse {
  0%,100% { box-shadow: 0 0 0 3px rgba(74,158,255,0.25), 0 6px 18px rgba(47,109,255,0.35); }
  50%     { box-shadow: 0 0 0 5px rgba(74,158,255,0.10), 0 6px 22px rgba(47,109,255,0.55); }
}

/* chat avatar (Discord) */
.chat-av {
  width: 16px; height: 16px; border-radius: 50%;
  object-fit: cover; vertical-align: -3px; margin-right: 5px;
}

/* ============ version history ============ */
#history-panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 290px; max-height: 70vh; overflow-y: auto;
  background: rgba(20,22,28,0.97); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 12px;
  box-shadow: 0 16px 44px rgba(0,0,0,0.5); padding: 10px; z-index: 300;
}
#history-panel[hidden] { display: none; }
.hist-save {
  width: 100%; margin-bottom: 8px; padding: 8px 10px;
  background: #2563eb; color: #fff; border: none; border-radius: 8px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.hist-save:hover { background: #1d4ed8; }
.hist-save:disabled { opacity: 0.6; cursor: default; }
.hist-sect {
  font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  color: #7db7ff; margin: 12px 2px 4px; opacity: 0.85;
}
.hist-sect:first-child { margin-top: 2px; }
.hist-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 4px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.hist-item:last-child { border-bottom: none; }
.hist-meta { min-width: 0; flex: 1; }
.hist-lbl { font-size: 12px; color: #e7e9ee; line-height: 1.3; word-break: break-word; }
.hist-when { font-size: 10px; color: #7a7f8a; margin-top: 2px; }
.hist-actions { flex: none; display: flex; align-items: center; gap: 4px; }
.hist-restore {
  flex: none; background: #2a2c34; color: #eaeaea; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 7px; padding: 5px 10px; font-size: 11px; cursor: pointer;
}
.hist-restore:hover { background: #4a9eff; color: #fff; border-color: #4a9eff; }
.hist-del {
  flex: none; background: transparent; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 7px; padding: 4px 7px; font-size: 11px; cursor: pointer; line-height: 1;
}
.hist-del:hover { background: #e0533f; border-color: #e0533f; }

/* ============ backup menu ============ */
#backup-menu {
  position: absolute; top: calc(100% + 8px); right: 0; width: 240px;
  background: rgba(20,22,28,0.97); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 12px;
  box-shadow: 0 16px 44px rgba(0,0,0,0.5); padding: 10px; z-index: 300;
}
#backup-menu[hidden] { display: none; }
.bk-btn {
  width: 100%; margin-top: 6px; padding: 9px 10px; text-align: left; cursor: pointer;
  background: #2a2c34; color: #eaeaea; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; font-size: 12px; font-weight: 600;
}
.bk-btn:hover { background: #3a3c44; }
.bk-note { font-size: 10px; color: #7a7f8a; margin-top: 8px; line-height: 1.4; }

/* ============ announcements ============ */
#btn-notif { position: relative; }
#notif-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: #e0533f; color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
}
#notif-badge[hidden] { display: none; }
#notif-panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 300px; max-height: 70vh; overflow-y: auto;
  background: rgba(20,22,28,0.97); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 12px;
  box-shadow: 0 16px 44px rgba(0,0,0,0.5); padding: 10px; z-index: 300;
}
#notif-panel[hidden] { display: none; }
.nt-head { font-size: 13px; font-weight: 700; color: #7db7ff; margin-bottom: 8px; }
.nt-compose { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.nt-compose textarea {
  background: #0e0f12; border: 1px solid rgba(255,255,255,0.1); color: #eaeaea;
  border-radius: 8px; padding: 8px; font-size: 12px; resize: vertical; min-height: 56px; outline: none;
  font-family: inherit;
}
.nt-compose textarea:focus { border-color: #4a9eff; }
#nt-send {
  align-self: flex-end; background: #4a9eff; color: #fff; border: 0;
  border-radius: 7px; padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.nt-item { padding: 8px 4px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.nt-item:last-child { border-bottom: none; }
.nt-text { font-size: 13px; color: #e7e9ee; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.nt-date { font-size: 10px; color: #777; margin-top: 4px; }
.nt-empty { color: #666; font-size: 12px; padding: 10px; text-align: center; }

/* ============ live presence cursors ============ */
#presence { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 9000; }
.pcursor {
  position: absolute;
  transform: translate(-50%, -50%) scale(var(--pinv, 1));
  display: flex; align-items: center; gap: 6px;
  pointer-events: none; white-space: nowrap;
  transition: left 0.09s linear, top 0.09s linear;   /* smooth glide between updates */
}
.pc-av {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #4a9eff; object-fit: cover;
  box-shadow: 0 0 12px rgba(74,158,255,0.7);
}
.pc-name {
  background: rgba(20,22,28,0.9); color: #fff;
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px;
}
#btn-eye.off { opacity: 0.65; }
#btn-signout { background: #c0392b !important; color: #fff !important; border-color: #c0392b !important; }
#btn-signout:hover { background: #e74c3c !important; }

/* ============ global chat (pinned right, collapsible) ============ */
#global-chat {
  position: fixed; right: 14px; bottom: 14px;
  width: 280px; height: 380px;
  background: rgba(20,22,28,0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
  z-index: 150; box-shadow: 0 16px 40px rgba(0,0,0,0.5);
}
body.gc-hidden #global-chat { display: none; }
#gc-head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; font-size: 12px; font-weight: 700; color: #7db7ff;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.gc-right { display: flex; align-items: center; gap: 10px; }
.gc-online { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; color: #cfd3da; }
.gc-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
  background: #35c759; box-shadow: 0 0 0 0 rgba(53,199,89,0.6);
  animation: gc-pulse 2s infinite;
}
@keyframes gc-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(53,199,89,0.55); }
  70%  { box-shadow: 0 0 0 6px rgba(53,199,89,0); }
  100% { box-shadow: 0 0 0 0 rgba(53,199,89,0); }
}
#gc-collapse { background: none; border: 0; color: #888; font-size: 18px; cursor: pointer; line-height: 1; }
#gc-collapse:hover { color: #fff; }
#gc-msgs { flex: 1; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
#gc-msgs > .chat-msg:first-child { margin-top: auto; }
#gc-msgs::-webkit-scrollbar { width: 6px; }
#gc-msgs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
#gc-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid rgba(255,255,255,0.07); }
#gc-text {
  flex: 1; min-width: 0; background: #0e0f12; border: 1px solid rgba(255,255,255,0.1);
  color: #eaeaea; border-radius: 8px; padding: 7px 10px; font-size: 12px; outline: none;
}
#gc-text:focus { border-color: #4a9eff; }
#gc-send {
  width: 34px; flex: none; background: linear-gradient(180deg, #4ea1ff, #2f6dff);
  color: #fff; border: 0; border-radius: 8px; cursor: pointer; font-size: 13px;
}
#gc-send:hover { filter: brightness(1.1); }
#gc-open {
  position: fixed; right: 14px; bottom: 14px; z-index: 150;
  width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(180deg, #4ea1ff, #2f6dff);
  color: #fff; border: 0; font-size: 20px; cursor: pointer;
  box-shadow: 0 8px 22px rgba(47,109,255,0.5);
  display: none; align-items: center; justify-content: center;
}
body.gc-hidden #gc-open { display: flex; }

/* ============ visitor (read-only) mode ============ */
body.readonly #sidebar,
body.readonly #hud,
body.readonly .edit-only { display: none !important; }

/* ============ personal progress ============ */
.signed-only { display: none !important; }
body.signed-in .signed-only { display: inline-flex !important; }
#progress-chip { font-size: 12px; color: #ffce4a; font-weight: 700; padding: 0 6px; align-items: center; }

/* progress glow (::before, won't clash with selection/glass/glow) */
.el.studied::before {
  content: "";
  position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  box-shadow: 0 0 0 2px rgba(70,196,106,0.85), 0 0 22px 2px rgba(70,196,106,0.5);
}
.el.studying::before {
  content: "";
  position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  box-shadow: 0 0 0 2px rgba(255,176,32,0.9), 0 0 22px 2px rgba(255,176,32,0.5);
}
.studied-btn {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);   /* fully above the block, with a gap */
  left: 50%; transform: translateX(-50%);
  background: rgba(20,22,28,0.92); color: #aab0ba;
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 11px; font-weight: 600;
  padding: 4px 12px; border-radius: 20px;
  cursor: pointer; white-space: nowrap; z-index: 14;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
body.signed-in .studied-btn { display: flex; align-items: center; }
.studied-btn:hover { background: #2a2c34; color: #fff; }
.studied-btn.studying { background: #f5a623; color: #1a1a1a; border-color: #f5a623; }
.studied-btn.done     { background: #46c46a; color: #fff;     border-color: #46c46a; }

/* ============ viewport / canvas ============ */
#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at center, #25272d 0%, #16171a 100%),
    #1a1c20;
  cursor: grab;
  touch-action: none;           /* we handle pan/pinch ourselves on touch */
}
/* but let scrollable inner areas scroll natively on touch */
.article-body, .chat-msgs, .faq-body, .gm-grid { touch-action: pan-y; }
body.tool-rect #viewport,
body.tool-text #viewport {
  cursor: crosshair;
}
#viewport.dragging { cursor: grabbing; }

/* moving grid — panned & zoomed via JS so you can feel movement over empty space */
#grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,0.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.10) 1px, transparent 1px);
  background-size: 40px 40px, 40px 40px, 200px 200px, 200px 200px;
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  /* no will-change: transform — keeping a cached GPU layer makes text blurry
     when zoomed in; without it Chrome re-rasterizes text crisply after zoom */
}

/* smart alignment guides (screen space) */
#guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: visible;
}
.guide-line {
  position: absolute;
  background: #ff3b9a;
  box-shadow: 0 0 4px rgba(255,59,154,0.6);
}
.guide-line.v { width: 1px; }
.guide-line.h { height: 1px; }

/* ghost rectangle shown while drawing a new element */
#marquee {
  position: absolute;
  border: 1.5px dashed #4a9eff;
  background: rgba(74,158,255,0.08);
  border-radius: 12px;
  pointer-events: none;
  z-index: 50;
}

/* ============ elements ============ */
.el {
  position: absolute;
  outline: none;
}
.el.rect {
  background: #2a2c34;
  border: 1px solid rgba(255,255,255,0.06);
}
/* frosted glass block (toggle) — translucent fill set inline by JS */
.el.rect.glass {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.10);
  box-shadow:
    0 18px 50px rgba(0,0,0,0.45),
    inset 0 1px 0 rgba(255,255,255,0.05);
}
/* soft edge glow (toggle) — via ::after so it won't clash with selection/glass shadows */
.el.rect.glow::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: -1;
  box-shadow:
    0 0 24px 2px var(--glow-color, rgba(74,158,255,0.6)),
    0 0 9px 0   var(--glow-color, rgba(74,158,255,0.6));
}
.el.text {
  background: transparent;
  color: #eaeaea;
  padding: 8px 10px;
  overflow: hidden;
  font-size: 18px;
  line-height: 1.12;       /* tight, display-style spacing for multi-line text */
  word-wrap: break-word;
  white-space: pre-wrap;
}
/* contenteditable can wrap each line in a <div>/<p>; kill their default margins */
.el.text div, .el.text p { margin: 0; }
.el.text.empty::before {
  content: "Type something…";
  color: rgba(255,255,255,0.25);
  font-style: italic;
}

.el.selected {
  box-shadow: 0 0 0 2px #4a9eff, 0 8px 32px rgba(0,0,0,0.4);
}
/* lighter outline when part of a multi-selection */
.el.multi {
  box-shadow: 0 0 0 1.5px rgba(74,158,255,0.7);
}

/* ============ rectangle live chat panel — dark glass HUD ============ */
.chat-panel {
  position: absolute;        /* positioned in canvas/world coords via JS */
  background: rgba(15, 17, 23, 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-head {
  height: 30px;
  flex: none;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #7db7ff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.chat-head::before {           /* online dot */
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #36e28a;
  box-shadow: 0 0 10px #36e28a;
}
.chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
/* anchor messages to the bottom: few messages sit just above the input and
   grow upward; newest is always at the bottom (YouTube/Twitch style) */
.chat-msgs > .chat-msg:first-child { margin-top: auto; }
.chat-msg {
  position: relative;
  padding: 3px 8px;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.82);
  word-break: break-word;
  border-radius: 5px;
}
.chat-msg:hover { background: rgba(255, 255, 255, 0.04); }
.chat-del {
  position: absolute; top: 2px; right: 4px;
  background: none; border: 0; color: #888; font-size: 14px; line-height: 1;
  cursor: pointer; opacity: 0; padding: 0 3px; border-radius: 4px;
}
.chat-msg:hover .chat-del { opacity: 1; }
.chat-del:hover { color: #fff; background: #e0533f; }
.chat-author {
  color: #ffb35c;            /* default; per-user color set inline overrides this */
  font-weight: 600;
  margin-right: 5px;
}
.chat-empty {
  color: #5a5d66;
  font-size: 11px;
  font-style: italic;
  margin: auto 0;
  text-align: center;
}
.chat-input {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.chat-input input {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 10px;
  border: none;
  border-radius: 8px;
  outline: none;
  background: rgba(255, 255, 255, 0.07);
  color: white;
  font-size: 12px;
}
.chat-input input:focus { background: rgba(255, 255, 255, 0.11); }
.chat-send {
  flex: none;
  width: 32px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(180deg, #4ea1ff, #2f6dff);
  color: white;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-send:hover { filter: brightness(1.1); }
.chat-msgs::-webkit-scrollbar { width: 5px; }
.chat-msgs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 10px; }
.chat-msgs::-webkit-scrollbar-track { background: transparent; }
/* ============ article / document block (native text → crisp + translatable) ============ */
.el.article {
  background: #23252b;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
}
.article-bar {
  flex: none;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: #1b1d22;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: move;
}
.article-grip { font-size: 11px; font-weight: 700; color: #888; letter-spacing: 0.04em; user-select: none; }
.article-ext { font-size: 12px; font-weight: 600; color: #7db7ff; text-decoration: none; }
.article-ext:hover { text-decoration: underline; }
.article-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  color: #e7e9ee;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
}
.article-body * { max-width: 100%; }
.article-body img { height: auto; border-radius: 6px; }
.article-body h1 { font-size: 24px; margin: 8px 0; color: #fff; }
.article-body h2 { font-size: 20px; margin: 8px 0; color: #fff; }
.article-body p  { margin: 0 0 10px; }
.article-body a  { color: #7db7ff; }
.article-body::-webkit-scrollbar { width: 8px; }
.article-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 4px; }
body.tool-article #viewport { cursor: crosshair; }
/* while dragging/resizing, iframes must not swallow the mouseup (prevents stuck resize) */
body.is-dragging iframe { pointer-events: none !important; }

/* ============ link preview card (pasted website links) ============ */
.el.link {
  background: #23252b;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
}
.el.link .link-card { display: flex; flex-direction: column; height: 100%; }
.link-thumb {
  flex: 1 1 auto; min-height: 0;
  background: #15171c center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  color: #4a4d55; font-size: 34px;
}
.link-thumb.has-img .link-thumb-ph { display: none; }
.link-info {
  flex: none; padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 4px;
  background: #1b1d22; border-top: 1px solid rgba(255,255,255,0.06);
}
.link-site { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #9aa0aa; }
.link-fav { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.link-domain { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-title {
  font-size: 14px; font-weight: 700; color: #fff; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.link-desc {
  font-size: 12px; color: #aab0ba; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.link-open { margin-top: 4px; align-self: flex-start; font-size: 12px; font-weight: 600; color: #7db7ff; text-decoration: none; }
.link-open:hover { text-decoration: underline; }

/* ============ gallery ============ */
.el.gallery {
  background: #1a1a1f;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.gal-bar {
  flex: none; height: 26px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px; background: #23242b; cursor: move;
}
.gal-grip { font-size: 10px; font-weight: 700; color: #888; letter-spacing: 0.05em; user-select: none; }
.gal-add { display: none; background: #4a9eff; color: #fff; border: 0; border-radius: 6px; font-size: 11px; padding: 3px 8px; cursor: pointer; }
body.view-admin .gal-add { display: inline-block; }     /* only admin adds works */
.gal-stage { flex: 1; position: relative; background: #0e0f12; cursor: pointer; overflow: hidden; }
.gal-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity 3s ease;
}
.gal-img.show { opacity: 1; }
.gal-cap { flex: none; padding: 6px 8px; font-size: 11px; color: #aab0ba; text-align: center; background: #23242b; border-top: 1px solid rgba(255,255,255,0.05); cursor: pointer; }
body.tool-gallery #viewport { cursor: crosshair; }

/* gallery modal — all works */
#gal-modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.8);
  display: flex; align-items: center; justify-content: center;
}
.gm-box {
  width: 90vw; max-width: 1100px; height: 85vh;
  background: #1b1d22; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.gm-head {
  flex: none; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  color: #eaeaea; font-size: 14px; font-weight: 600;
}
.gm-head button {
  background: #2a2c34; color: #eaeaea; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 7px; padding: 6px 12px; font-size: 12px; cursor: pointer; margin-left: 6px;
}
.gm-add { background: #4a9eff !important; color: #fff; border-color: #4a9eff !important; }
.gm-head button:hover { filter: brightness(1.1); }
.gm-grid {
  flex: 1; overflow-y: auto; padding: 14px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px;
  align-content: start;
}
.gm-cell { position: relative; aspect-ratio: 1; background: #0e0f12; border-radius: 8px; overflow: hidden; cursor: zoom-in; }
.gm-cell img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s; }
.gm-cell:hover img { transform: scale(1.05); }

/* lightbox */
#gal-light {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
}
#gal-light .lb-img {
  max-width: 90vw; max-height: 86vh;
  object-fit: contain; border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#gal-light .lb-close, #gal-light .lb-prev, #gal-light .lb-next {
  position: absolute;
  background: rgba(255,255,255,0.1);
  color: #fff; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#gal-light .lb-close { top: 18px; right: 22px; width: 40px; height: 40px; border-radius: 50%; font-size: 18px; }
#gal-light .lb-prev, #gal-light .lb-next { top: 50%; transform: translateY(-50%); width: 52px; height: 80px; border-radius: 10px; font-size: 40px; }
#gal-light .lb-prev { left: 20px; }
#gal-light .lb-next { right: 20px; }
#gal-light .lb-close:hover, #gal-light .lb-prev:hover, #gal-light .lb-next:hover { background: rgba(255,255,255,0.22); }
#gal-light .lb-count {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  color: #ccc; font-size: 13px; background: rgba(0,0,0,0.5); padding: 5px 12px; border-radius: 20px;
}
.gm-del {
  position: absolute; top: 5px; right: 5px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,0.65); color: #fff; border: 0; cursor: pointer; font-size: 14px;
}
.gm-del:hover { background: #c0392b; }
.gm-empty { grid-column: 1 / -1; text-align: center; color: #666; padding: 50px; }

/* ============ vote bar (for / against) ============ */
.el.vote {
  background: #23252b;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.vote-label {
  font-size: 14px;
  font-weight: 600;
  color: #eaeaea;
  text-align: center;
  outline: none;
}
.vote-bar {
  display: flex;
  height: 10px;
  border-radius: 6px;
  overflow: hidden;
  background: #15161a;
}
.vote-fill-down { background: linear-gradient(90deg,#e0533f,#ff7a5f); transition: width 0.4s ease; }
.vote-fill-up   { background: linear-gradient(90deg,#46c46a,#7ee29a); transition: width 0.4s ease; margin-left: auto; }
.vote-row { display: flex; gap: 8px; }
.vote-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: #2a2c34;
  color: #eaeaea;
  font-size: 14px;
  cursor: pointer;
}
.vote-btn b { font-weight: 700; }
.vote-arrow { font-size: 18px; font-weight: 900; line-height: 1; }
.vote-down .vote-arrow { color: #e0533f; }
.vote-up   .vote-arrow { color: #46c46a; }
.vote-btn .vote-pct-up, .vote-btn .vote-pct-down { font-size: 12px; color: #9aa0aa; }
.vote-down:hover { border-color: #e0533f; }
.vote-up:hover   { border-color: #46c46a; }
.vote-down.mine { background: rgba(224,83,63,0.25); border-color: #e0533f; }
.vote-up.mine   { background: rgba(70,196,106,0.25); border-color: #46c46a; }

/* ============ premium zone cover ============ */
.el.premium {
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  background: transparent;
  border: 2px solid rgba(255,196,0,0.7);     /* gold frame so premium is noticeable */
  box-shadow: 0 0 18px rgba(255,196,0,0.25);
}
.prem-bar {
  flex: none;
  height: 26px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: rgba(255,196,0,0.12);
  border: 1px solid rgba(255,196,0,0.4);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  cursor: move;
}
.prem-grip { font-size: 10px; font-weight: 800; letter-spacing: 0.08em; color: #ffce4a; user-select: none; }
.prem-cover {
  flex: 1;
  border-radius: 0 0 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.prem-teaser {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 20px;
  max-width: 80%;
}
.prem-lock { font-size: 34px; }
.prem-title {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  outline: none;
}
.prem-desc {
  font-size: 13px;
  color: #cfd3da;
  line-height: 1.45;
  outline: none;
}
.prem-btn {
  margin-top: 6px;
  background: linear-gradient(180deg, #ff7a3d, #f0591f);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 10px;
  text-decoration: none;
  box-shadow: 0 8px 22px rgba(240,89,31,0.4);
}
.prem-btn:hover { filter: brightness(1.08); }
.prem-hint {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: #ffe08a;
  background: rgba(255,196,0,0.08);
  border: 1px solid rgba(255,196,0,0.35);
  border-radius: 20px;
  padding: 6px 14px;
  text-shadow: 0 0 10px rgba(255,196,0,0.5);
  box-shadow: 0 0 16px rgba(255,196,0,0.18);
  animation: prem-hint-glow 2.6s ease-in-out infinite;
}
.prem-crown { font-size: 14px; filter: drop-shadow(0 0 6px rgba(255,196,0,0.8)); }
@keyframes prem-hint-glow {
  0%,100% { box-shadow: 0 0 14px rgba(255,196,0,0.15); border-color: rgba(255,196,0,0.30); }
  50%     { box-shadow: 0 0 26px rgba(255,196,0,0.40); border-color: rgba(255,196,0,0.6); }
}

/* --- per-element access state (set by JS from tier / admin preview) --- */
/* ADMIN edit: translucent, teaser editable, content beneath clickable, bar to grab */
.el.premium.prem-admin .prem-bar    { display: flex; }
.el.premium.prem-admin .prem-cover  {
  background: rgba(20,16,8,0.45);
  border: 1px dashed rgba(255,196,0,0.5);
  pointer-events: none;                 /* clicks pass to content beneath for editing */
}
.el.premium.prem-admin .prem-teaser { opacity: 0.85; pointer-events: auto; }

/* LOCK: opaque frosted cover + teaser, blocks beneath, on top */
.el.premium.prem-lock { z-index: 100000 !important; }
.el.premium.prem-lock .prem-bar   { display: none; }
.el.premium.prem-lock .prem-cover {
  background: rgba(18,20,26,0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  pointer-events: auto;
}
.el.premium.prem-lock .prem-teaser { pointer-events: auto; }

/* OPEN: transparent glowing gold frame, content visible */
.el.premium.prem-open {
  pointer-events: none;
  border: 2px solid rgba(255,196,0,0.85);
  box-shadow: 0 0 26px rgba(255,196,0,0.5), inset 0 0 22px rgba(255,196,0,0.08);
  background: transparent;
}
.el.premium.prem-open .prem-bar    { display: none; }
.el.premium.prem-open .prem-teaser { display: none; }
.el.premium.prem-open .prem-cover  {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: none;
  pointer-events: none;
}

/* ============ view-as switch in top bar ============ */
.tb-label { font-size: 11px; color: #888; }
#view-as { display: flex; gap: 2px; background: #1a1a1f; border-radius: 8px; padding: 2px; }
#view-as button {
  background: transparent;
  border: 0;
  color: #aaa;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
#view-as button:hover { color: #eaeaea; }
#view-as button.active { background: #4a9eff; color: #fff; }

/* ============ google docs/slides/sheets embed ============ */
.el.embed {
  background: #1a1a1f;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.embed-bar {
  flex: none;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: #23242b;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 12px;
  color: #eaeaea;
}
.embed-ext {
  color: #7db7ff;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}
.embed-ext:hover { text-decoration: underline; }
.embed-inner {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.embed-open {
  background: #4a9eff;
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.embed-open:hover { background: #5aa8ff; }
.el.embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ============ block FAQ (collapsible, under the block) ============ */
.faq-wrap {
  position: absolute;        /* world coords via JS */
  text-align: center;
}
.faq-tab {
  background: rgba(15,17,23,0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.10);
  color: #7db7ff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 7px 16px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.faq-tab:hover { background: rgba(30,34,44,0.92); }
.faq-caret { font-size: 10px; margin-left: 4px; }
.faq-body {
  display: none;
  margin-top: 6px;
  text-align: left;
  background: rgba(15,17,23,0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.5);
  padding: 8px;
  overflow: hidden;
}
.faq-wrap.open .faq-body { display: block; }
.faq-item {
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding: 2px 0;
}
.faq-item:last-of-type { border-bottom: none; }
.faq-q-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
}
.faq-chev {
  color: #7db7ff;
  font-size: 11px;
  cursor: pointer;
  transition: transform 0.12s;
  flex: none;
}
.faq-item.open .faq-chev { transform: rotate(90deg); }
.faq-q {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: #eaeaea;
  outline: none;
  word-break: break-word;
}
.faq-q:focus { background: rgba(255,255,255,0.05); border-radius: 5px; }
.faq-del {
  width: 22px; height: 22px;
  background: transparent;
  border: 0;
  color: #777;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  flex: none;
}
.faq-del:hover { background: #c0392b; color: white; }
.faq-a {
  display: none;
  font-size: 12px;
  line-height: 1.4;
  color: rgba(255,255,255,0.78);
  padding: 2px 8px 8px 27px;
  outline: none;
  word-break: break-word;
}
.faq-item.open .faq-a { display: block; }
.faq-a:focus { background: rgba(255,255,255,0.05); border-radius: 5px; }
.faq-empty { color: #666; font-size: 12px; padding: 8px; text-align: center; }
.faq-add {
  width: 100%;
  margin-top: 6px;
  background: rgba(74,158,255,0.14);
  border: 1px dashed rgba(74,158,255,0.45);
  color: #7db7ff;
  border-radius: 8px;
  padding: 7px;
  font-size: 12px;
  cursor: pointer;
}
.faq-add:hover { background: rgba(74,158,255,0.26); }

/* manual resize grip (bottom-right of the chat) */
.chat-resize {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.12s;
  background:
    linear-gradient(135deg, transparent 45%, rgba(255,255,255,0.5) 45%, rgba(255,255,255,0.5) 55%, transparent 55%),
    linear-gradient(135deg, transparent 65%, rgba(255,255,255,0.5) 65%, rgba(255,255,255,0.5) 75%, transparent 75%);
}
.chat-panel:hover .chat-resize { opacity: 0.8; }
.chat-resize:hover { opacity: 1; }

/* popover toggle button active state */
#popover button.active { background: #4a9eff; color: white; border-color: #4a9eff; }

/* lock badge */
.lock-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  z-index: 6;
  pointer-events: auto;
  user-select: none;
  opacity: 0.55;
  transition: opacity 0.12s, background 0.12s;
}
.el.locked:hover .lock-badge { opacity: 1; }
.lock-badge:hover { background: #4a9eff; opacity: 1; }
/* faint outline so locked items are recognizable at a glance */
.el.locked { outline: 1px dashed rgba(255,255,255,0.12); }

/* group selection box (multi-select) — kept on top so its handles stay grabbable */
#selbox {
  position: absolute;
  border: 1.5px solid #4a9eff;
  background: rgba(74,158,255,0.04);
  z-index: 9999;
  cursor: move;
}
#selbox[hidden] { display: none; }

/* let text inside be selectable for typing + chrome translator */
.el.text, .el.text * { user-select: text; }

/* ============ image element (PNG / transparent) ============ */
.el.image {
  background: transparent;
  border: none;
}
.el.image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;   /* block native browser drag/copy of img */
  user-select: none;
}

/* drop indicator on viewport */
#viewport.drop-active {
  box-shadow: inset 0 0 0 3px #4a9eff;
}
#viewport.drop-active::after {
  content: "Drop image to add";
  position: absolute;
  top: 24px; left: 50%;
  transform: translateX(-50%);
  background: rgba(74,158,255,0.9);
  color: white;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  z-index: 300;
  pointer-events: none;
}

/* ============ video element (YouTube) ============ */
.el.video {
  background: #0a0a0c;
  border-radius: 10px;
  overflow: hidden;
}
.el.video .yt-thumb {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-color: #0a0a0c;
}
.el.video .yt-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(0,0,0,0.25), rgba(0,0,0,0) 50%);
  pointer-events: none;
}
.el.video .yt-play {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(0,0,0,0.78);
  border: 0;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  padding-left: 6px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  z-index: 3;
}
.el.video .yt-play:hover {
  background: #cc0000;
  transform: translate(-50%, -50%) scale(1.1);
}
.el.video .yt-stop {
  display: none;
  position: absolute;
  top: 6px; right: 6px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.75);
  border: 0;
  color: white;
  font-size: 14px;
  cursor: pointer;
  z-index: 6;
}
/* drag bar over the top edge of playing video — lets you move it without stopping */
.el.video .yt-dragbar {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 40px;
  height: 26px;
  background: linear-gradient(rgba(0,0,0,0.75), rgba(0,0,0,0));
  cursor: move;
  z-index: 5;
  color: #bbb;
  font-size: 11px;
  padding: 5px 10px;
  letter-spacing: 1px;
  user-select: none;
}
.el.video.playing .yt-dragbar { display: block; }
.el.video .yt-dragbar::before { content: "⋮⋮  drag"; }
.el.video.playing .yt-stop {
  display: flex;
  align-items: center;
  justify-content: center;
}
.el.video.playing .yt-thumb,
.el.video.playing .yt-play { display: none; }
.el.video iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ============ resize handles ============ */
.handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #ffffff;
  border: 2px solid #4a9eff;
  border-radius: 50%;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.handle.nw { top: -6px;  left: -6px;  cursor: nwse-resize; }
.handle.n  { top: -6px;  left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.handle.ne { top: -6px;  right: -6px; cursor: nesw-resize; }
.handle.e  { top: 50%;   right: -6px; transform: translateY(-50%); cursor: ew-resize; }
.handle.se { bottom: -6px;right: -6px; cursor: nwse-resize; }
.handle.s  { bottom: -6px;left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.handle.sw { bottom: -6px;left: -6px; cursor: nesw-resize; }
.handle.w  { top: 50%;   left: -6px; transform: translateY(-50%); cursor: ew-resize; }

/* ============ HUD ============ */
#hud {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,22,28,0.85);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.6;
  z-index: 100;
  text-align: center;
}
#hud b { color: #4a9eff; }

/* ============ popover ============ */
#popover {
  position: fixed;
  background: rgba(20,22,28,0.96);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;                      /* wrap to a 2nd row instead of overflowing */
  gap: 8px 10px;
  align-items: center;
  max-width: calc(100vw - 24px);        /* never run off-screen */
  z-index: 400;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  font-size: 12px;
  color: #ccc;
}
#popover label { white-space: nowrap; }
#popover[hidden] { display: none; }
#popover label { display: flex; gap: 6px; align-items: center; }
#popover input[type=range] {
  width: 100px;
  cursor: pointer;
}
#popover input[type=number] {
  background: #1a1a1f;
  border: 1px solid rgba(255,255,255,0.1);
  color: #eaeaea;
  padding: 4px 4px 4px 8px;   /* left-aligned value, spinner gets the right side */
  border-radius: 6px;
  width: 62px;                /* wide enough that the spinner never covers digits */
  font-size: 12px;
  text-align: left;
  flex: none;
}
#popover input[type=color] {
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
}
#popover .sep { width: 1px; height: 20px; background: rgba(255,255,255,0.1); }
#popover button {
  background: #2a2c34;
  color: #eaeaea;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}
#popover button:hover { background: #3a3c44; }
#popover button.danger { background: #c0392b; border-color: #c0392b; }
#popover button.danger:hover { background: #e74c3c; }

#popover .align-group {
  display: flex;
  gap: 2px;
  background: #1a1a1f;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 2px;
}
#popover .align-btn {
  background: transparent;
  border: 0;
  color: #aaa;
  padding: 4px 7px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#popover .align-btn:hover { background: rgba(255,255,255,0.06); color: #eaeaea; }
#popover .align-btn.active { background: #4a9eff; color: white; }

#popover .z-group {
  display: flex;
  gap: 2px;
  background: #1a1a1f;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 2px;
}
#popover .z-group button {
  background: transparent;
  border: 0;
  color: #aaa;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
}
#popover .z-group button:hover { background: rgba(255,255,255,0.06); color: #eaeaea; }

#popover .font-select {
  background: #1a1a1f;
  color: #eaeaea;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  max-width: 160px;
}
#popover .font-select option { background: #25272d; color: #eaeaea; }

/* ============ connectors (links between blocks) ============ */
#links {
  position: absolute;
  left: -50000px;
  top: -50000px;
  width: 100000px;
  height: 100000px;
  overflow: visible;
  pointer-events: none;     /* empty areas pass clicks through; only paths below opt in */
}
#links path.link      { fill: none; pointer-events: none; stroke-linecap: round; }
#links path.link-hit  { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
#links path.link-temp { fill: none; pointer-events: none; }
#links path.link-sel  { fill: none; pointer-events: none; }
#links circle.wp {
  fill: #ffffff;
  stroke: #4a9eff;
  stroke-width: 2;
  pointer-events: auto;
  cursor: grab;
}
#links circle.wp:hover { fill: #4a9eff; }
/* flowing pulse toward the target */
@keyframes link-flow { to { stroke-dashoffset: -36; } }
#links path.link.flow {
  stroke-dasharray: 10 8;
  animation: link-flow 0.6s linear infinite;
}
body.tool-connect #viewport { cursor: crosshair; }

/* ============ top bar (start view + bookmarks) ============ */
#topbar {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20,22,28,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 6px 8px;
  z-index: 200;
  box-shadow: 0 10px 32px rgba(0,0,0,0.4);
}
#topbar button {
  background: #2a2c34;
  color: #eaeaea;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
#topbar button:hover { background: #3a3c44; }
#topbar .tb-divider { width: 1px; height: 20px; background: rgba(255,255,255,0.1); }

#bookmark-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: rgba(20,22,28,0.97);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
#bookmark-menu[hidden] { display: none; }
.bm-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 8px;
  margin: 1px 0;
}
.bm-row:hover { background: rgba(255,255,255,0.04); }
.bm-drag {
  flex: none;
  color: #555;
  cursor: grab;
  font-size: 13px;
  padding: 0 2px;
  user-select: none;
}
.bm-row:hover .bm-drag { color: #888; }
.bm-name {
  flex: 1;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 13px;
  color: #eaeaea;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bm-name:hover { background: rgba(74,158,255,0.18); }
.bm-del, .bm-child {
  width: 26px;
  height: 26px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: #aab0ba;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
}
.bm-child:hover { background: #4a9eff; color: white; border-color: #4a9eff; }
.bm-del:hover   { background: #c0392b; color: white; border-color: #c0392b; }
/* depth styling for the 3-level tree */
.bm-d0 .bm-name { font-weight: 700; color: #eaeaea; }
.bm-d1 .bm-name { font-weight: 600; color: #cfd3da; font-size: 12px; }
.bm-d2 .bm-name { font-weight: 400; color: #aab0ba; font-size: 12px; }
.bm-d1 .bm-name::before { content: "› "; color: #555; }
.bm-d2 .bm-name::before { content: "· "; color: #555; }
#bookmark-menu { min-width: 240px; max-height: 60vh; overflow-y: auto; }
.bm-empty { color: #666; font-size: 12px; padding: 8px; text-align: center; }
.bm-add {
  width: 100%;
  margin-top: 6px;
  background: rgba(74,158,255,0.15);
  border: 1px dashed rgba(74,158,255,0.5);
  color: #7db7ff;
  border-radius: 8px;
  padding: 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.bm-add:hover { background: rgba(74,158,255,0.28); }

/* ============ toast ============ */
#toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(20,22,28,0.95);
  border: 1px solid rgba(255,255,255,0.1);
  color: #eaeaea;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ brand (top-left) ============ */
#brand {
  position: fixed; top: 14px; left: 16px; z-index: 200;
  display: flex; align-items: center; gap: 10px;
  pointer-events: none;          /* never blocks the canvas */
  user-select: none;
}
#brand-eye {
  position: relative; width: 42px; height: 42px; flex: none;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
  pointer-events: auto; cursor: pointer;   /* only the eye is clickable (easter egg) */
  transition: width 0.25s ease, height 0.25s ease, filter 0.3s ease;
}
#brand-eye img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.be-pupil { transition: transform 0.08s ease-out; will-change: transform; }
.brand-text {
  font-family: 'Russo One', sans-serif;
  font-size: 15px; letter-spacing: 0.3px; color: #eef1f5;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  display: flex; align-items: baseline; gap: 6px;
}
.brand-alpha {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 8px; font-weight: 600; letter-spacing: 0.5px; text-transform: lowercase;
  color: rgba(255,255,255,0.35);
}

/* easter-egg states (reset on page refresh) */
#brand.be-grown #brand-eye { width: 58px; height: 58px; }
@keyframes be-shake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  15% { transform: translateX(-3px) rotate(-7deg); }
  30% { transform: translateX(3px)  rotate(7deg); }
  45% { transform: translateX(-2px) rotate(-5deg); }
  60% { transform: translateX(2px)  rotate(5deg); }
  75% { transform: translateX(-1px) rotate(-2deg); }
}
#brand-eye.be-shake { animation: be-shake 0.5s ease; }
#egg-bubble {
  position: absolute; top: 52px; left: 0;
  font-family: 'Russo One', sans-serif; font-size: 12px; color: #eef1f5;
  background: rgba(20,22,28,0.96); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; padding: 6px 11px; white-space: nowrap;
  box-shadow: 0 8px 22px rgba(0,0,0,0.5);
  opacity: 0; transform: translateY(-5px); pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#egg-bubble.show { opacity: 1; transform: translateY(0); }

/* ---- Evil mode: after the 4th eye click (resets on refresh) ---- */
body.evil #viewport { background: radial-gradient(circle at center, #2a1416 0%, #1a0d0e 100%), #1a0d0e; }
body.evil #brand-eye { filter: drop-shadow(0 2px 10px rgba(255,55,55,0.6)); }
body.evil .brand-alpha { color: rgba(255,120,120,0.5); }
body.evil #egg-bubble { border-color: rgba(255,90,90,0.4); }
body.evil #topbar,
body.evil #sidebar,
body.evil #global-chat,
body.evil #minimap,
body.evil #history-panel,
body.evil #notif-panel,
body.evil #bookmark-menu,
body.evil #popover {
  background: rgba(42,18,20,0.94);
  border-color: rgba(255,90,90,0.20);
}

/* ============ minimap ============ */
#minimap {
  position: fixed; left: 14px; bottom: 14px; z-index: 140;
  width: 210px; height: 140px;
  background: rgba(20,22,28,0.92); backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 10px;
  box-shadow: 0 10px 32px rgba(0,0,0,0.45);
  padding: 5px; overflow: hidden;
}
#minimap[hidden] { display: none; }
#mm-canvas { width: 100%; height: 100%; display: block; cursor: pointer; border-radius: 6px; }

/* ============ reactions (emoji on blocks) ============ */
.react-bar { position: absolute; bottom: 8px; left: 8px; display: flex; gap: 5px; z-index: 13; }
.react-pill {
  display: inline-flex; align-items: center; gap: 3px;
  background: rgba(18,20,26,0.82); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px; padding: 2px 7px; font-size: 13px; line-height: 1; cursor: pointer;
  color: #d6d9df; backdrop-filter: blur(6px);
}
.react-pill:hover { background: rgba(40,43,52,0.92); }
.react-pill.mine { border-color: #4a9eff; background: rgba(74,158,255,0.22); }
.re-n { font-size: 11px; font-weight: 700; }
.react-pill:not(.has) .re-n { display: none; }

/* ============ my progress / badges ============ */
#progress-chip { cursor: pointer; }
#progress-chip:hover { color: #fff; }
#progress-panel {
  position: fixed; top: 58px; left: 50%; transform: translateX(-50%);
  width: 300px; max-width: 92vw;
  background: rgba(20,22,28,0.98); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 12px;
  box-shadow: 0 16px 44px rgba(0,0,0,0.5); padding: 14px; z-index: 300;
}
#progress-panel[hidden] { display: none; }
.pp-lvl { font-size: 13px; font-weight: 700; color: #eef1f5; margin-bottom: 8px; }
.pp-bar { height: 7px; background: rgba(255,255,255,0.1); border-radius: 5px; overflow: hidden; }
.pp-fill { height: 100%; background: linear-gradient(90deg,#4ea1ff,#8a6bff); border-radius: 5px; transition: width 0.3s; }
.pp-sub { font-size: 10px; color: #7a7f8a; margin: 5px 0 12px; }
.pp-badges-title { font-size: 11px; font-weight: 700; color: #9aa0aa; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 8px; }
.pp-badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pp-badge { text-align: center; padding: 8px 4px; border-radius: 9px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.06); }
.pp-badge-ic { font-size: 22px; line-height: 1; }
.pp-badge-name { font-size: 9px; color: #aab0ba; margin-top: 4px; line-height: 1.2; }
.pp-badge.off { opacity: 0.32; filter: grayscale(1); }
.pp-badge.on { background: rgba(74,158,255,0.12); border-color: rgba(74,158,255,0.3); }
.pp-badge.on .pp-badge-name { color: #eef1f5; }

/* ============ onboarding ============ */
#onboard {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(10,11,14,0.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#onboard[hidden] { display: none; }
.ob-arrow {
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%);
  font-size: 13px; font-weight: 700; color: #7fdfff; white-space: nowrap;
  background: rgba(20,22,28,0.96); border: 1px solid rgba(127,223,255,0.5);
  padding: 8px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.55);
  animation: ob-bounce 1.2s ease-in-out infinite;
}
@keyframes ob-bounce { 0%,100% { transform: translate(-50%,0); } 50% { transform: translate(-50%,-7px); } }
.ob-card {
  width: min(92vw, 470px); max-height: 86vh; overflow-y: auto;
  background: #1b1d22; border: 1px solid rgba(255,255,255,0.1); border-radius: 16px;
  padding: 26px 24px; box-shadow: 0 24px 70px rgba(0,0,0,0.6);
}
.ob-card h2 {
  font-family: 'Russo One', sans-serif; font-size: 22px; color: #fff;
  margin-bottom: 16px; text-align: center;
}
.ob-steps { list-style: none; display: flex; flex-direction: column; gap: 13px; margin: 0 0 22px; }
.ob-steps li { font-size: 14px; line-height: 1.5; color: #d6d9df; }
.ob-steps b { color: #fff; }
.ob-btn {
  width: 100%; padding: 12px; cursor: pointer;
  background: linear-gradient(180deg,#4ea1ff,#2f6dff); color: #fff; border: 0;
  border-radius: 10px; font-size: 15px; font-family: 'Russo One', sans-serif;
}
.ob-btn:hover { filter: brightness(1.08); }
@media (max-width: 760px) { .ob-arrow { white-space: normal; max-width: 92vw; text-align: center; } }

/* ============ touch / mobile ============ */
html, body { overscroll-behavior: none; }      /* no pull-to-refresh / bounce while panning */
.el { -webkit-touch-callout: none; }            /* no long-press menu on blocks */

@media (max-width: 760px) {
  /* keyboard hints are desktop-only */
  #hud { display: none !important; }

  /* minimap takes too much room on phones */
  #minimap { display: none; }

  /* brand would overlap the full-width top bar on phones */
  #brand { display: none; }

  /* top bar: fit the screen — swipe it horizontally to reach every button */
  #topbar {
    left: 6px; right: 6px; transform: none; width: auto; max-width: none;
    justify-content: flex-start; flex-wrap: nowrap;
    overflow-x: auto; overflow-y: visible;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    padding: 5px 6px; gap: 5px;
  }
  #topbar::-webkit-scrollbar { display: none; }
  #topbar button { padding: 8px 11px; font-size: 12px; white-space: nowrap; flex: 0 0 auto; }
  #topbar .tb-divider { flex: 0 0 auto; }

  /* dropdown panels: pin to the screen so the top-bar's scroll can't clip them */
  #history-panel, #notif-panel, #bookmark-menu, #backup-menu {
    position: fixed; top: 60px; left: 6px; right: 6px;
    width: auto; min-width: 0; max-width: none; max-height: 70vh;
  }

  /* global chat: smaller, doesn't swallow the whole screen */
  #global-chat { right: 8px; bottom: 8px; width: min(82vw, 300px); height: min(52vh, 380px); }

  /* roomier tap targets in the element toolbar (admin editing on a tablet) */
  #popover button, #popover .align-btn { min-height: 32px; }
}

/* coarse pointers (phones / tablets): bigger tap targets on in-board controls */
@media (pointer: coarse) {
  .yt-play { transform: scale(1.15); }
  .studied-btn { padding: 7px 11px; }
  .gal-add, .vote-btn { min-height: 34px; }
}
