/* Highlight-and-comment layer (comments.js). Quiet by default; motion 150–200 ms ease-out. */
:root {
  --cm-shadow: 0 1px 2px rgba(38, 37, 30, 0.04), 0 6px 24px rgba(38, 37, 30, 0.07);
  --cm-line-strong: #cfccc2;
}

/* Highlights: each mark carries its author's colors (person-color.js) as custom properties. */
mark.cm {
  color: inherit; background: var(--hl); box-shadow: inset 0 -1.5px 0 var(--hl-line);
  border-radius: 1px; cursor: pointer;
  transition: background-color 150ms ease, box-shadow 150ms ease;
}
mark.cm.on, mark.cm.hover { background: var(--hl-on); box-shadow: inset 0 -2px 0 var(--hl-line-on); }
.editing mark.cm { all: unset; }

/* Floating Comment button above a selection */
.cm-fab {
  position: absolute; z-index: 25; display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px 0 9px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--ink); font: 500 13px var(--sans); cursor: pointer;
  box-shadow: var(--cm-shadow);
  opacity: 0; pointer-events: none; transform: scale(0.96); transform-origin: 0 50%;
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
.cm-fab.show { opacity: 1; pointer-events: auto; transform: none; }
.cm-fab svg { color: var(--muted); }
.cm-fab:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .cm-fab:hover { background: var(--bg); } }

/* Hover a block: quiet "Comment" in the rail (icon-only in the gutter when a card is beside it) */
.cm-add {
  position: absolute; z-index: 6; display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 8px 0 6px; margin-left: -6px; border: 0; border-radius: 6px; background: none;
  color: var(--muted); font: 13px var(--sans); cursor: pointer;
  opacity: 0; pointer-events: none; transition: opacity 150ms var(--ease-out), color 150ms ease, background-color 150ms ease;
}
.cm-add.show { opacity: 1; pointer-events: auto; }
.cm-add.compact { width: 26px; padding: 0; margin-left: 0; justify-content: center; }
.cm-add.compact span { display: none; }
.cm-add:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .cm-add:hover { color: var(--ink); background: var(--panel); } }
@media (max-width: 1180px) { .cm-add { display: none; } }

/* Topbar: identity, count, resolved filter */
.cm-me {
  display: inline-flex; align-items: center; gap: 7px; border: 0; background: none; padding: 4px 6px; margin-left: -6px; border-radius: 6px;
  font: 13px var(--sans); color: var(--muted); cursor: pointer; transition: color 150ms ease, background-color 150ms ease;
}
.cm-me b { font-weight: 500; color: var(--ink-2); }
.cm-me:disabled { cursor: default; }
.cm-dot { width: 8px; height: 8px; border-radius: 50%; }
@media (hover: hover) and (pointer: fine) { .cm-me:not(:disabled):hover { background: var(--panel); color: var(--ink-2); } }
.cm-count { font: 11px var(--mono); color: var(--muted); min-width: 1ch; }
.cm-count:empty { display: none; }
body.hide-notes .cm-resolved-toggle { display: none; }
@media (max-width: 1180px) { .cm-resolved-toggle, .cm-me { display: none; } }

/* Rail cards: positioned by transform so moves animate on the compositor. */
.right .cm-card {
  position: absolute; left: 0; right: 0; top: 0;
  transform: translate(var(--nx, 0px), var(--y, 0px));
  transition: transform 200ms var(--ease-out), border-color 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}
.right .cm-card.cm-instant { transition: none; }
.right .cm-card.hover:not(.cm-new), .right .cm-card.active:not(.cm-new) { --nx: -4px; }
.cm-card {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; line-height: 1.45; color: var(--ink-2); cursor: default;
}
.cm-card.hover, .cm-card.active { border-color: var(--cm-line-strong); }
.cm-card.active { box-shadow: var(--cm-shadow); z-index: 1; }
.cm-card.resolved { opacity: 0.7; }
.cm-card.resolved.active, .cm-card.resolved.hover { opacity: 1; }

/* New comment: just the pill, no card chrome */
.cm-card.cm-new { background: none; border: 0; padding: 0; box-shadow: none; }

/* Hover toolbar: resolve + more */
.cm-tools {
  position: absolute; top: 6px; right: 6px; z-index: 2; display: flex; gap: 2px; padding: 2px;
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
  opacity: 0; pointer-events: none; transition: opacity 150ms var(--ease-out);
}
.cm-card.hover .cm-tools, .cm-card.active .cm-tools, .cm-card.menu-open .cm-tools, .cm-tools:focus-within { opacity: 1; pointer-events: auto; }
@media (hover: none) { .cm-tools { opacity: 1; pointer-events: auto; } }
.cm-tool {
  width: 24px; height: 22px; display: grid; place-items: center; border: 0; border-radius: 4px; background: none;
  color: var(--muted); cursor: pointer; transition: background-color 150ms ease, color 150ms ease;
}
.cm-tool:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .cm-tool:hover { background: var(--panel); color: var(--ink); } }
.cm-card.resolved .cm-tool[data-act="resolve"] { color: var(--accent); }
.cm-menu {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 128px; padding: 4px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--cm-shadow);
  opacity: 0; pointer-events: none; transform: scale(0.96); transform-origin: top right;
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
.cm-card.menu-open .cm-menu { opacity: 1; pointer-events: auto; transform: none; }
.cm-card.menu-open { z-index: 3; }
.cm-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 8px; border-radius: 4px; font: 13px var(--sans); color: var(--ink); cursor: pointer; }
.cm-menu button.danger { color: var(--warn); }
@media (hover: hover) and (pointer: fine) { .cm-menu button:hover { background: var(--panel); } }

.cm-tags { margin-bottom: 6px; }
.cm-tag { font: 11px var(--mono); color: var(--muted); }
.cm-tag.warn { color: var(--warn); }
.cm-quote { font-size: 12.5px; color: var(--muted); text-decoration: line-through; text-decoration-color: #b9b6ab; border-left: 2px solid var(--line); padding-left: 8px; margin: 0 0 8px; overflow-wrap: anywhere; }

.cm-c + .cm-c { margin-top: 12px; }
.cm-who { display: flex; align-items: center; gap: 7px; min-width: 0; }
.cm-av { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font: 600 10.5px var(--sans); }
.cm-name { font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cm-body { margin: 3px 0 0 27px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-2); }
.cm-body.clamp { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.cm-more-text { border: 0; background: none; padding: 0; margin: 2px 0 0 27px; font: 13px var(--sans); color: var(--muted); cursor: pointer; transition: color 150ms ease; }
@media (hover: hover) and (pointer: fine) { .cm-more-text:hover { color: var(--ink); } }
.cm-nreplies { margin: 8px 0 0 27px; font-size: 12.5px; color: var(--muted); }

/* Pill input: new comment and reply */
.cm-reply { display: flex; align-items: flex-start; gap: 7px; margin-top: 12px; }
.cm-reply .cm-av { margin-top: 5px; }
.cm-pill {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 6px; padding: 4px 4px 4px 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.cm-new .cm-pill { box-shadow: var(--cm-shadow); }
.cm-pill:focus-within { border-color: var(--cm-line-strong); }
.cm-pill textarea {
  flex: 1; min-width: 0; display: block; resize: none; overflow: hidden; height: 22px; min-height: 22px; margin: 1px 0;
  border: 0; padding: 1px 0; background: none; font: 13px/1.5 var(--sans); color: var(--ink); outline: none;
}
.cm-pill textarea::placeholder { color: var(--muted); }
.cm-send {
  flex: none; width: 24px; height: 24px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--ink); color: var(--bg); cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, transform 160ms var(--ease-out);
}
.cm-send:disabled { background: var(--panel); color: var(--muted); cursor: default; }
.cm-send:active:not(:disabled) { transform: scale(0.97); }

.cm-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.cm-btn { height: 28px; padding: 0 11px; border-radius: 6px; font: 500 13px var(--sans); cursor: pointer; border: 1px solid transparent; transition: transform 160ms var(--ease-out), background-color 150ms ease, opacity 150ms ease; }
.cm-btn:active:not([disabled]) { transform: scale(0.97); }
.cm-btn.primary { background: var(--ink); color: var(--bg); }
.cm-btn.primary[disabled] { opacity: 0.35; cursor: default; }
.cm-btn.ghost { background: none; color: var(--ink-2); }
@media (hover: hover) and (pointer: fine) { .cm-btn.ghost:hover { background: var(--panel); } .cm-btn.primary:not([disabled]):hover { background: #3a392f; } }

/* Minimap: thread ticks on the right edge */
.cm-map { position: fixed; top: 64px; bottom: 16px; right: 6px; width: 14px; z-index: 9; pointer-events: none; }
.cm-tick {
  position: absolute; right: 0; width: 10px; height: 3px; padding: 0; border: 0; border-radius: 2px;
  background: var(--c); opacity: 0.55; cursor: pointer; pointer-events: auto;
  transition: opacity 150ms ease, width 150ms var(--ease-out);
}
.cm-tick::before { content: ""; position: absolute; inset: -4px -2px; }
.cm-tick.on { opacity: 1; width: 14px; }
@media (hover: hover) and (pointer: fine) { .cm-tick:hover { opacity: 1; width: 14px; } }
body.hide-notes .cm-map { display: none; }

/* Narrow screens: chip under a block, bottom sheet for its threads */
.cm-chip { display: none; }
.cm-scrim, .cm-sheet { display: none; }
@media (max-width: 1180px) {
  .blkwrap { position: relative; }
  .cm-chip {
    display: inline-flex; align-items: center; gap: 4px; float: right; margin: -16px 0 4px 8px; position: relative;
    height: 22px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
    color: var(--ink-2); font: 500 12px var(--sans); cursor: pointer;
  }
  h1#title .cm-chip { float: none; margin: 0 0 0 8px; vertical-align: middle; }
  .cm-chip:active { transform: scale(0.97); }
  .blkwrap::after { content: ""; display: block; clear: both; }
  .cm-scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(38, 37, 30, 0.18); opacity: 0; pointer-events: none; transition: opacity 200ms ease; }
  .cm-scrim.show { opacity: 1; pointer-events: auto; }
  .cm-sheet {
    display: flex; flex-direction: column; position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 72vh;
    background: var(--bg); border-top: 1px solid var(--line); border-radius: 8px 8px 0 0; box-shadow: 0 -8px 30px rgba(38, 37, 30, 0.08);
    transform: translateY(100%); transition: transform 200ms var(--ease-out); visibility: hidden;
  }
  .cm-sheet.show { transform: none; visibility: visible; }
  .cm-sheet-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; font-weight: 500; font-size: 14px; border-bottom: 1px solid var(--line); }
  .cm-sheet-body { overflow-y: auto; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 10px; }
  .cm-sheet .cm-card { position: relative; }
  .cm-empty { color: var(--muted); font-size: 13px; margin: 4px 0; }
  .cm-map { display: none; }
}

/* First-visit name modal */
.cm-modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(38, 37, 30, 0.22); opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 150ms ease, visibility 0s linear 150ms;
}
.cm-modal.show { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 200ms ease, visibility 0s; }
.cm-modal-card {
  width: min(360px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 20px;
  box-shadow: var(--cm-shadow); transform: scale(0.96); opacity: 0; transform-origin: center;
  transition: transform 150ms var(--ease-out), opacity 150ms var(--ease-out);
}
.cm-modal.show .cm-modal-card { transform: none; opacity: 1; transition-duration: 200ms; }
.cm-modal h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
.cm-modal p { margin: 4px 0 14px; font-size: 13.5px; color: var(--muted); }
.cm-modal input {
  display: block; width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); font: 14px var(--sans); color: var(--ink); outline: none; transition: border-color 150ms ease, background-color 150ms ease;
}
.cm-modal input:focus { border-color: #b9b6ab; background: #fff; }
.cm-modal .cm-actions { margin-top: 14px; }
.cm-modal .cm-btn { height: 32px; }

@media (prefers-reduced-motion: reduce) {
  .cm-fab, .cm-fab.show, .cm-fab:active { transform: none; }
  .cm-menu, .cm-modal-card { transform: none; }
  .right .cm-card { transition: border-color 150ms ease, box-shadow 150ms ease, opacity 150ms ease; }
  .right .cm-card.hover:not(.cm-new), .right .cm-card.active:not(.cm-new) { --nx: 0px; }
  .cm-sheet { transition: opacity 200ms ease; transform: none; opacity: 0; }
  .cm-sheet.show { opacity: 1; }
  .cm-btn:active:not([disabled]), .cm-chip:active, .cm-add:active, .cm-send:active:not(:disabled), .cm-tool:active { transform: none; }
}
