/* スタンドアロン版コメント。トークンは ui.css / canvas.html のもの (--c-* / --page / --primary …) をそのまま使う = ダークにも追従 */
:root { --rv-pin: #f59e0b; --rv-pin-fg: #18181b; --rv-done: color-mix(in oklab, var(--c-muted) 70%, transparent); }

.ctl .rv-seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: 9px; background: color-mix(in oklab, var(--c-muted) 14%, transparent); }
.ctl .rv-seg button { height: 28px; border-radius: 7px; }
.ctl .rv-seg button[aria-pressed="true"] { background: var(--c-card); box-shadow: 0 1px 3px rgb(0 0 0 / .18); }
.ctl .rv-seg .rv-btn[aria-pressed="true"] { background: var(--rv-pin); color: var(--rv-pin-fg); }
.ctl .rv-btn.locked { opacity: .6; }
.ctl .rv-lbtn[aria-pressed="true"] { background: color-mix(in oklab, var(--c-muted) 18%, transparent); }

/* ピン: 左下を指す吹き出し。ワールドではなく画面座標に置き、canvas の docPoint で毎フレーム置き直す */
.rv-pins { position: fixed; inset: 0; pointer-events: none; z-index: 6; overflow: hidden; }
.rv-pinwrap { position: absolute; left: 0; top: 0; will-change: transform; }
/* 丸の中心 = アンカー点。重なる時だけ --dx だけ右へずらし、根元に点と線を出す */
.rv-pin { pointer-events: auto; position: absolute; left: -13px; top: -13px; width: 26px; height: 26px; padding: 0;
  transform: translateX(var(--dx, 0px));
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--rv-pin); color: var(--rv-pin-fg); border: 2px solid var(--c-card); box-shadow: 0 2px 8px rgb(0 0 0 / .28);
  font: 700 12px/1 ui-monospace, monospace; cursor: pointer; }
.rv-pin.wide { width: auto; min-width: 26px; padding: 0 5px; border-radius: 13px; }
/* 操作モード: 画面を邪魔しない薄さ。丸の上だけポインタが効き、ホバーで濃くする */
.rv-pin { opacity: .25; transition: opacity .15s, transform .15s; }
.rv-pin:hover, .rv-pin.cur { opacity: .8; }
/* コメントモード: 不透明・影つき */
.rv-commenting .rv-pin { opacity: 1; box-shadow: 0 3px 10px rgb(0 0 0 / .35); }
.rv-lead { display: none; position: absolute; left: 0; top: -1px; height: 2px; width: var(--dx, 0px); background: var(--rv-pin); opacity: .25; pointer-events: none; }
.rv-pinwrap.shifted .rv-lead { display: block; }
.rv-pinwrap.shifted::before { content: ""; position: absolute; left: -3px; top: -3px; width: 6px; height: 6px; border-radius: 50%; background: var(--rv-pin); opacity: .35; }
.rv-commenting .rv-lead, .rv-commenting .rv-pinwrap.shifted::before { opacity: 1; }
.rv-pin:hover { transform: translateX(var(--dx, 0px)) scale(1.08); }
.rv-pin.cur { outline: 3px solid color-mix(in oklab, var(--rv-pin) 45%, transparent); outline-offset: 1px; }
.rv-pin.done { background: var(--c-card); color: var(--c-muted); border-color: var(--rv-done); }
.rv-pin.draft { background: var(--c-fg); color: var(--page); pointer-events: none; opacity: 1; }

/* 一覧: キャンバスの右上 (ミニマップの上) */
.rv-list { position: absolute; right: 12px; top: 40px; bottom: 174px; width: min(320px, calc(100% - 24px)); z-index: 8;
  display: flex; flex-direction: column; background: var(--c-card); color: var(--c-fg); border: 1px solid var(--c-border);
  border-radius: 12px; box-shadow: var(--shadow-lg, 0 10px 30px rgb(0 0 0 / .18)); overflow: hidden; font-size: .8rem; cursor: default; user-select: text; }
.rv-list[hidden] { display: none; }
.rv-lhead { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; }
.rv-lhead b { font-size: .88rem; }
.rv-you { margin-left: auto; font-size: .74rem; color: var(--c-muted); max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-you b { color: var(--c-fg); font-size: .76rem; }
.rv-dim { color: var(--c-muted); }
.rv-link { border: 0; background: transparent; color: var(--out, #2563eb); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; text-underline-offset: 2px; }
.rv-acct { padding: 0 12px 6px; font-size: .66rem; color: var(--c-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-x { border: 0; background: transparent; color: var(--c-muted); cursor: pointer; border-radius: 6px; width: 26px; height: 26px; font-size: .8rem; flex-shrink: 0; }
.rv-lhead .rv-x:only-of-type { margin-left: auto; }
.rv-you + .rv-x { margin-left: 0; }
.rv-x:hover { background: color-mix(in oklab, var(--c-muted) 15%, transparent); color: var(--c-fg); }
.rv-tabs { display: flex; gap: 4px; padding: 0 12px 8px; border-bottom: 1px solid var(--c-border); }
.rv-tabs button { flex: 1; height: 28px; border: 1px solid var(--c-border); background: transparent; color: var(--c-fg); border-radius: 8px; font: 600 .74rem var(--font-sans); cursor: pointer; }
.rv-tabs button[aria-selected="true"] { background: var(--c-fg); color: var(--page); border-color: var(--c-fg); }
.rv-items { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.rv-items:first-of-type { flex: 1; }
.rv-item { width: 100%; text-align: left; display: flex; gap: 8px; align-items: flex-start; border: 1px solid transparent; background: transparent; color: var(--c-fg);
  border-radius: 8px; padding: 7px 8px; cursor: pointer; font: .78rem/1.45 var(--font-sans); }
.rv-item:hover { border-color: var(--c-border); background: color-mix(in oklab, var(--c-muted) 7%, transparent); }
.rv-item.cur { border-color: var(--rv-pin); }
.rv-n { flex-shrink: 0; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px 11px 11px 3px; background: var(--rv-pin); color: var(--rv-pin-fg);
  display: inline-flex; align-items: center; justify-content: center; font: 700 11px/1 ui-monospace, monospace; }
.rv-n.done { background: transparent; color: var(--c-muted); border: 1.5px solid var(--rv-done); }
.rv-body { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.rv-lbl { font: 600 .72rem ui-monospace, monospace; color: var(--c-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-snip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; word-break: break-word; }
.rv-meta { font-size: .68rem; color: var(--c-muted); }
.rv-orph { display: inline-block; font: 600 .62rem var(--font-sans); color: var(--warning, #d97706); border: 1px solid currentColor; border-radius: 999px; padding: 0 5px; margin-left: 4px; }
.rv-sec { padding: 8px 12px 2px; border-top: 1px solid var(--c-border); color: var(--warning, #d97706); font-size: .7rem; font-weight: 600; line-height: 1.5; }
.rv-note { color: var(--c-muted); padding: 10px 12px; margin: 0; line-height: 1.6; }
.rv-err { color: var(--destructive, #dc2626); }

/* ポップオーバー (新規 / スレッド) */
.rv-pop { position: fixed; left: 0; top: 0; z-index: 30; width: min(340px, calc(100vw - 16px)); max-height: min(70vh, 520px); display: flex; flex-direction: column;
  background: var(--c-card); color: var(--c-fg); border: 1px solid var(--c-border); border-radius: 12px; box-shadow: var(--shadow-lg, 0 10px 30px rgb(0 0 0 / .22)); font-size: .82rem; }
.rv-pop[hidden] { display: none; }
.rv-ph { display: flex; align-items: center; gap: 8px; padding: 10px 10px 8px 12px; border-bottom: 1px solid var(--c-border); }
.rv-ph .rv-lbl { flex: 1; }
.rv-ph .btn.sm { height: 26px; padding: 0 9px; font-size: .72rem; }
.rv-orphnote { padding: 8px 12px 0; color: var(--warning, #d97706); font-size: .72rem; line-height: 1.5; }
.rv-orphnote[hidden] { display: none; }
.rv-msgs { overflow: auto; padding: 4px 12px; min-height: 0; flex: 1; }
.rv-msg { padding: 8px 0; border-bottom: 1px dashed var(--c-border); }
.rv-msg:last-child { border-bottom: 0; }
.rv-mh { display: flex; gap: 8px; align-items: baseline; font-size: .74rem; }
.rv-mh span { color: var(--c-muted); font-size: .68rem; }
.rv-mb { white-space: pre-wrap; word-break: break-word; line-height: 1.55; margin-top: 2px; }
.rv-ta { margin: 8px 12px 0; resize: vertical; min-height: 56px; border: 1px solid var(--c-border); border-radius: 8px; padding: 7px 9px; background: var(--page); color: var(--c-fg); font: .82rem/1.5 var(--font-sans); }
.rv-ta:focus { outline: 2px solid color-mix(in oklab, var(--rv-pin) 60%, transparent); outline-offset: 0; border-color: var(--rv-pin); }
.rv-pf { display: flex; align-items: center; gap: 6px; justify-content: flex-end; padding: 8px 12px 10px; }
.rv-cnt { margin-right: auto; font: .68rem ui-monospace, monospace; color: var(--c-muted); }
.rv-cnt.over { color: var(--destructive, #dc2626); }
.rv-pop .btn.ghost { color: var(--c-fg); }

.rv-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; background: var(--c-fg); color: var(--page); padding: 8px 14px; border-radius: 10px; font-size: .8rem; box-shadow: var(--shadow-lg, 0 6px 20px rgb(0 0 0 / .25)); }
.rv-toast[hidden] { display: none; }

@media (max-width: 899px) {
  .rv-list { top: 8px; bottom: 120px; }
}

/* 表示名ダイアログ (alert / prompt は使わない) */
.rv-dlg { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgb(0 0 0 / .35); padding: 16px; }
.rv-dlg[hidden] { display: none; }
.rv-dlgcard { width: min(380px, 100%); background: var(--c-card); color: var(--c-fg); border: 1px solid var(--c-border); border-radius: 14px; box-shadow: var(--shadow-lg, 0 20px 50px rgb(0 0 0 / .3)); padding: 18px 18px 6px; }
.rv-dlgcard h2 { margin: 0 0 6px; font-size: 1rem; }
.rv-note0 { margin: 0 0 12px; color: var(--c-muted); font-size: .78rem; line-height: 1.6; }
.rv-inp { width: 100%; box-sizing: border-box; height: 38px; border: 1px solid var(--c-border); border-radius: 8px; padding: 0 10px; background: var(--page); color: var(--c-fg); font: .9rem var(--font-sans); }
.rv-inp:focus { outline: 2px solid color-mix(in oklab, var(--rv-pin) 60%, transparent); border-color: var(--rv-pin); }
.rv-nerr { min-height: 1.2em; margin: 4px 0 0; color: var(--destructive, #dc2626); font-size: .74rem; }
.rv-dlgcard .rv-pf { padding: 6px 0 12px; }

/* ボタンはページ側トークンで塗る (ui.css の --primary は端末用 = 常にライトなので、ダークのカード上で消える) */
.rv-pop .btn:not(.ghost):not(.outline), .rv-dlgcard .btn[type="submit"] { background: var(--c-fg); color: var(--page); border-color: var(--c-fg); }
.rv-pop .btn.outline { background: var(--c-card); color: var(--c-fg); border-color: var(--c-border); }
.rv-dlgcard .btn.ghost { color: var(--c-fg); }
