:root {
  --board-bg: #6b4f2a;
  --board-bg2: #5a4222;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  user-select: none;
}

/* The viewport clips the infinite world */
#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: default;
  background:
    radial-gradient(rgba(0,0,0,0.18) 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(135deg, var(--board-bg), var(--board-bg2));
  background-blend-mode: multiply;
}

#viewport.panning { cursor: grabbing; }

/* The world holds notes + connections in world coordinates.
   Pan/zoom applied via CSS transform (transform-origin 0 0). */
#world {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  /* children positioned absolutely with any (incl. negative) coords */
}

/* ---------- Notes ---------- */
.note {
  position: absolute;
  z-index: 1;
  /* left/top/width/height set inline in world units */
}

.note-inner {
  position: absolute;
  inset: 0;
  background: #ffe66b;
  box-shadow: 2px 3px 6px rgba(0,0,0,0.35);
  transform-origin: center;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  border-radius: 2px;
  padding: 8px;
  overflow: hidden;
}

.note.dragging .note-inner {
  transform: scale(1.06);
  box-shadow: 6px 10px 16px rgba(0,0,0,0.45);
}

.note.selected .note-inner {
  outline: 3px solid #ffffff;
  outline-offset: -1px;
}

.note-text {
  position: absolute;
  inset: 0;
  padding: 8px;
  font-family: "Comic Sans MS", "Segoe Print", cursive, sans-serif;
  font-size: 16px;
  line-height: 1.25;
  color: #222;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  outline: none;
}

/* When not editable, the text is not a text target */
.note-text[contenteditable="false"] {
  cursor: default;
}

/* Photo notes */
.note.photo .note-inner {
  background: #fff;
  padding: 0;
}
.note.photo .note-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.note.photo .note-text { display: none; }

/* Resizer handle */
.note .resizer {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.35) 50%);
  z-index: 2;
}
.note.photo .resizer { background: rgba(0,0,0,0.5); }

/* ---------- Connections (SVG) ---------- */
#conn-svg {
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
  overflow: visible;
  pointer-events: none; /* children opt back in */
  z-index: 2; /* above notes (z-index 1) so pins sit on top */
}
.connection { pointer-events: auto; }
.connection .conn-line { }
.connection.preview, .connection.preview * {
  pointer-events: none !important; /* a dragged preview must not capture clicks */
}
.connection .conn-pin {
  fill: #c0392b;
  stroke: #2b0000;
  stroke-width: 2;
  filter: drop-shadow(1px 1px 1px rgba(0,0,0,0.5));
}
.connection.preview .conn-line {
  opacity: 0.75;
  stroke-dasharray: 6 6;
}
.connection.preview .conn-pin { opacity: 0.75; }
.connection:hover .conn-line { filter: brightness(1.4); }

/* ---------- Toolbar ---------- */
#toolbar {
  position: fixed;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
  background: rgba(20,20,20,0.55);
  padding: 6px;
  border-radius: 6px;
  z-index: 1000;
}
#toolbar button {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}
#toolbar button:hover { background: rgba(255,255,255,0.25); }

#hint {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.35);
  padding: 3px 10px;
  border-radius: 10px;
  pointer-events: none;
  z-index: 1000;
}

/* ---------- Marquee (rectangle selection) ---------- */
#marquee {
  position: fixed;
  z-index: 500;
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: rgba(80, 140, 255, 0.18);
  pointer-events: none;
  border-radius: 2px;
}

/* ---------- Context menu ---------- */
.context-menu {
  position: fixed;
  z-index: 2000;
  background: #2b2b2b;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.4);
  padding: 4px 0;
  min-width: 160px;
  font-size: 13px;
}
.context-menu .item {
  padding: 6px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.context-menu .item:hover { background: #3a6ea5; }
.context-menu .sep { height: 1px; background: rgba(255,255,255,0.15); margin: 4px 0; }
.context-menu .swatch {
  width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.4);
}
.context-menu .label { flex: 1; }
.context-menu .thickness-bar {
  height: 6px; background: #ddd; border-radius: 3px; align-self: center;
}
