/* Comments stay outside the editable page and use the editor's UI palette. */
[data-ud-comment-id][data-ud-comment-edge] { display: none !important; }
::highlight(ud-comments) { background-color: var(--ud-comment-highlight, #fff0ba); }
::highlight(ud-comment-active) { background-color: var(--ud-comment-active-highlight, #ffdf80); }
body { --comments-width: 328px; }
#ud-comments-panel {
  position: fixed; z-index: 10070; top: var(--comments-top, 122px); right: 12px;
  bottom: var(--comments-bottom, 40px); width: var(--comments-width);
  display: flex; flex-direction: column; box-sizing: border-box; overflow: hidden;
  background: #f8fafd; border: 1px solid #e0e5ed; border-radius: 12px;
  box-shadow: 0 2px 8px #25334b08; color: var(--ink, #1f1f1f);
  font: 13px/1.6 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}
#ud-comments-panel *, #ud-comments-panel *::before, #ud-comments-panel *::after { box-sizing: border-box; }
#ud-comments-panel[hidden], #ud-comments-panel [hidden] { display: none !important; }
#ud-comments-panel button, #ud-comments-panel input, #ud-comments-panel textarea { font: inherit; }
#ud-comments-panel button { cursor: pointer; border: 0; color: inherit; background: transparent; }
#ud-comments-panel button:disabled { opacity: .45; cursor: default; }
#ud-comments-panel :is(button, summary, input, textarea):focus-visible { outline: 2px solid var(--accent, #0b57d0); outline-offset: 2px; }
#ud-comments-panel svg { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ud-comments-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; flex: 0 0 auto; }
.ud-comments-heading, .ud-comments-header-actions { display: flex; align-items: center; gap: 8px; }
.ud-comments-heading h2 { margin: 0; font-family: inherit; font-weight: 600; font-size: 16px; line-height: 24px; }
.ud-comments-count { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 7px; text-align: center; background: #e9edf3; color: #667080; font-size: 11px; line-height: 22px; }
#ud-comments-panel .ud-comments-icon { display: grid; place-items: center; width: 28px; height: 28px; padding: 5px; border-radius: 6px; color: #6c7480; cursor: pointer; }
#ud-comments-panel .ud-comments-icon:hover { background: #e8edf5; color: #263346; }
#ud-comments-panel .ud-comments-new { display: flex; align-items: center; gap: 3px; padding: 4px 7px; border-radius: 6px; color: var(--accent, #0b57d0); font-size: 12px; font-weight: 600; }
#ud-comments-panel .ud-comments-new:hover { background: #e7effd; }
.ud-comments-scroll { padding: 0 12px 16px; flex: 1; min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: #c9d0da transparent; }
.ud-comments-list { display: flex; flex-direction: column; gap: 12px; }
.ud-comment-card { padding: 15px; border: 1px solid #e2e7ee; border-radius: 10px; background: #fff; transition: border-color .15s; }
.ud-comment-card[data-active="true"] { border-color: #a5bee9; box-shadow: 0 0 0 1px #d9e5fa; }
.ud-comment-head { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.ud-comment-avatar { flex: 0 0 30px; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: #e8eefb; color: #4268a8; font-size: 10px; font-weight: 600; }
.ud-comment-who { flex: 1; min-width: 0; line-height: 1.45; }
.ud-comment-who strong { display: block; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ud-comment-who time { display: block; color: #858d99; font-size: 10px; margin-top: 2px; }
.ud-comment-menu { position: relative; align-self: flex-start; }
.ud-comment-menu summary { list-style: none; }
.ud-comment-menu summary::-webkit-details-marker { display: none; }
.ud-comment-menu-items { position: absolute; z-index: 2; right: 0; top: 30px; width: 120px; padding: 5px; border: 1px solid #e0e5ed; background: white; border-radius: 8px; box-shadow: 0 4px 16px #26334618; }
#ud-comments-panel .ud-comment-menu-items button { display: flex; align-items: center; gap: 8px; width: 100%; border-radius: 5px; padding: 6px 9px; font-size: 12px; text-align: left; }
#ud-comments-panel .ud-comment-menu-items button:hover { background: #f0f4fa; }
#ud-comments-panel .ud-comment-menu-items button:last-child { color: #b13e3e; }
#ud-comments-panel .ud-comment-quote { display: flex; align-items: center; gap: 8px; text-align: left; width: 100%; margin: 0 0 10px; padding: 7px 9px; border-left: 2px solid #e6c56a; border-radius: 0 4px 4px 0; background: #faf8f1; color: #827450; font-size: 11px; line-height: 1.6; }
.ud-comment-quote span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; flex: 1; }
#ud-comments-panel .ud-comment-quote svg { width: 13px; height: 13px; opacity: .65; }
#ud-comments-panel .ud-comment-quote:hover { background: #f6f0dd; }
.ud-comment-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: #384150; line-height: 1.8; font-size: 13px; }
.ud-comment-compose { padding: 14px; border: 1px solid #adc4e8; border-radius: 10px; background: #fff; margin-bottom: 14px; box-shadow: 0 2px 6px #273b5c08; }
.ud-compose-title { font-size: 12px; font-weight: 600; margin-bottom: 9px; }
.ud-compose-quote { padding: 0 0 0 8px; margin-bottom: 14px; border-left: 2px solid #e6c56a; color: #8b7b50; font-size: 11px; max-height: 36px; overflow: hidden; overflow-wrap: anywhere; }
.ud-compose-author { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
#ud-comments-panel .ud-compose-author input { min-width: 0; width: 100%; border: 1px solid transparent; border-radius: 4px; color: #525e70; background: transparent; padding: 3px 5px; font-size: 12px; }
#ud-comments-panel .ud-compose-author input:hover { border-color: #dfe5ef; }
#ud-comments-panel textarea { display: block; width: 100%; min-height: 100px; max-height: 260px; padding: 10px; margin: 0; border: 1px solid #e1e6ef; border-radius: 6px; background: #fcfdff; color: #354153; resize: vertical; line-height: 1.7; }
#ud-comments-panel textarea::placeholder { color: #9ba3ae; }
.ud-compose-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 12px; }
#ud-comments-panel .ud-comments-text-button { border-radius: 6px; padding: 6px 10px; color: #717c8a; font-size: 12px; }
#ud-comments-panel .ud-comments-text-button:hover { background: #f0f3f8; }
#ud-comments-panel .ud-comments-primary { padding: 6px 12px; border-radius: 6px; background: var(--accent, #0b57d0); color: white; font-size: 12px; font-weight: 500; }
#ud-comments-panel .ud-comments-primary:hover { background: var(--accent-dark, #0842a0); }
.ud-comments-empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 70px 22px 30px; color: #959fad; }
#ud-comments-panel .ud-comments-empty svg { width: 34px; height: 34px; margin-bottom: 20px; color: #a9b9d2; stroke-width: 1.15; }
.ud-comments-empty strong { font-size: 13px; font-weight: 500; color: #687487; }
.ud-comments-empty p { font-size: 12px; line-height: 1.8; margin: 8px 0 0; max-width: 190px; }
.ud-comments-footer { display: flex; flex-direction: column; flex: 0 0 auto; gap: 6px; padding: 10px 16px; border-top: 1px solid #e8edf4; color: #919bab; font-size: 10px; }
.ud-comments-footer [role="status"] { color: #98723f; font-size: 11px; }
.ud-comments-footer [role="status"]:empty { display: none; }
.ud-comments-hint { display: flex; align-items: center; gap: 4px; }
.ud-comments-hint kbd { border: 1px solid #dce3ed; border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; line-height: 16px; font: inherit; }
#ribbon #btn-comments[aria-expanded="true"] { color: var(--accent, #0b57d0); background: var(--accent-weak, #d3e3fd); }

/* iOS-style rail: quiet chrome, generous touch targets, and one clear action. */
#ud-comments-panel { --ios-blue:#007aff; --ios-ink:#1c1c1e; --ios-secondary:#8e8e93; right:16px; width:min(352px,calc(100vw - 32px)); border:1px solid rgba(60,60,67,.13); border-radius:18px; background:rgba(248,248,250,.94); box-shadow:0 18px 46px rgba(0,0,0,.14),0 2px 8px rgba(0,0,0,.06); color:var(--ios-ink); backdrop-filter:saturate(180%) blur(18px); -webkit-backdrop-filter:saturate(180%) blur(18px); font-size:14px; }
@media (min-width:1100px) { body.ud-comments-open { --comments-width:352px; } }
/* The comments rail is an overlay. Opening it must never resize or reflow the
   editable canvas; this matches the reference editor's inspector behavior. */
@media (min-width:1100px) { body.ud-comments-open #canvas { margin-right:0 !important; } }
#ud-comments-panel .ud-comments-header { padding:17px 18px 13px; border-bottom:1px solid rgba(60,60,67,.10); }
#ud-comments-panel .ud-comments-heading { gap:9px; }
#ud-comments-panel .ud-comments-heading h2 { font-size:17px; font-weight:700; letter-spacing:-.2px; }
#ud-comments-panel .ud-comments-count { min-width:21px; height:21px; border-radius:999px; background:#e5e5ea; color:#6e6e73; line-height:21px; font-size:11px; }
#ud-comments-panel .ud-comments-icon { width:34px; height:34px; border-radius:999px; color:#636366; }
#ud-comments-panel .ud-comments-icon:hover { background:rgba(118,118,128,.12); color:#1c1c1e; }
#ud-comments-panel .ud-comments-new { min-height:34px; padding:6px 12px 6px 10px; border-radius:999px; background:var(--ios-blue); color:#fff; font-size:13px; font-weight:650; box-shadow:0 1px 2px rgba(0,122,255,.2); }
#ud-comments-panel .ud-comments-new:hover { background:#006ee6; }
#ud-comments-panel .ud-comments-scroll { padding:14px 12px 16px; }
#ud-comments-panel .ud-comments-list { gap:10px; }
#ud-comments-panel .ud-comment-card { padding:14px; border:0; border-radius:14px; background:#fff; box-shadow:0 1px 3px rgba(0,0,0,.08); }
#ud-comments-panel .ud-comment-card[data-active="true"] { border:0; box-shadow:0 0 0 2px rgba(0,122,255,.32),0 2px 7px rgba(0,0,0,.10); }
#ud-comments-panel .ud-comment-head { gap:10px; margin-bottom:10px; }
#ud-comments-panel .ud-comment-avatar { width:32px; height:32px; flex-basis:32px; background:linear-gradient(145deg,#dcecff,#b8d4ff); color:#075db5; font-size:10px; }
#ud-comments-panel .ud-comment-who strong { color:var(--ios-ink); font-size:13px; }
#ud-comments-panel .ud-comment-who time { color:var(--ios-secondary); font-size:11px; }
#ud-comments-panel .ud-comment-quote { margin-bottom:9px; padding:8px 10px; border:0; border-left:3px solid #ffcc00; border-radius:8px; background:#fff9df; color:#75652d; line-height:1.5; }
#ud-comments-panel .ud-comment-quote:hover { background:#fff4c5; }
#ud-comments-panel .ud-comment-text { color:#3a3a3c; line-height:1.65; font-size:14px; }
#ud-comments-panel .ud-comment-compose { padding:15px; margin-bottom:12px; border:0; border-radius:14px; background:#fff; box-shadow:0 1px 3px rgba(0,0,0,.08); }
#ud-comments-panel .ud-compose-title { margin-bottom:10px; font-size:15px; font-weight:700; }
#ud-comments-panel textarea { min-height:88px; padding:11px 12px; border:1px solid #d1d1d6; border-radius:11px; background:#f8f8fa; color:var(--ios-ink); font-size:14px; }
#ud-comments-panel textarea:focus { border-color:var(--ios-blue); box-shadow:0 0 0 3px rgba(0,122,255,.16); outline:0; }
#ud-comments-panel .ud-compose-actions { margin-top:13px; gap:8px; }
#ud-comments-panel .ud-comments-text-button { min-height:34px; padding:7px 12px; border-radius:999px; color:var(--ios-blue); font-size:13px; font-weight:600; }
#ud-comments-panel .ud-comments-text-button:hover { background:rgba(0,122,255,.10); }
#ud-comments-panel .ud-comments-primary { min-height:34px; padding:7px 14px; border-radius:999px; background:var(--ios-blue); font-size:13px; font-weight:650; }
#ud-comments-panel .ud-comments-primary:hover { background:#006ee6; }
#ud-comments-panel .ud-comments-footer { padding:9px 17px 11px; border-top-color:rgba(60,60,67,.10); color:var(--ios-secondary); }
#ud-comments-panel .ud-comments-hint kbd { border-color:#d1d1d6; border-radius:5px; background:#f2f2f7; }
.ud-comments-settings { display:flex; align-items:center; gap:10px; color:var(--ios-secondary); font-size:11px; }
.ud-comments-highlight-toggle, .ud-comments-highlight-color { display:inline-flex; align-items:center; gap:4px; cursor:pointer; }
.ud-comments-highlight-toggle input { position:absolute; opacity:0; pointer-events:none; }
.ud-comments-highlight-toggle span { display:inline-flex; align-items:center; gap:3px; min-height:25px; padding:3px 8px 3px 6px; border-radius:999px; background:#f2f2f7; color:#636366; }
.ud-comments-highlight-toggle span svg { width:14px; height:14px; }
.ud-comments-highlight-toggle input:checked + span { background:rgba(0,122,255,.12); color:#007aff; }
.ud-comments-highlight-color input { width:24px; height:22px; padding:0; border:1px solid #d1d1d6; border-radius:6px; background:transparent; cursor:pointer; }
@media (max-width:700px) { #ud-comments-panel { right:8px; left:8px; width:auto; max-height:72dvh; border-radius:20px; box-shadow:0 -10px 34px rgba(0,0,0,.16); } #ud-comments-panel .ud-comments-header { padding:13px 17px 10px; } #ud-comments-panel .ud-comments-scroll { padding-top:11px; } #ud-comments-panel .ud-comments-footer { padding-bottom:7px; } }

/* iOS-style comment rail: quiet chrome, generous touch targets, and one clear
   blue action.  Content remains native comments; this only changes presentation. */
#ud-comments-panel {
  --ios-blue: #007aff;
  --ios-ink: #1c1c1e;
  --ios-secondary: #8e8e93;
  top: var(--comments-top, 104px);
  right: 16px;
  bottom: var(--comments-bottom, 32px);
  width: min(352px, calc(100vw - 32px));
  border: 1px solid rgba(60,60,67,.13);
  border-radius: 18px;
  background: rgba(248,248,250,.94);
  box-shadow: 0 18px 46px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.06);
  color: var(--ios-ink);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  font-size: 14px;
}
#ud-comments-panel .ud-comments-header { padding: 17px 18px 13px; border-bottom: 1px solid rgba(60,60,67,.10); }
#ud-comments-panel .ud-comments-heading { gap: 9px; }
#ud-comments-panel .ud-comments-heading h2 { font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
#ud-comments-panel .ud-comments-count { min-width: 21px; height: 21px; border-radius: 999px; background: #e5e5ea; color: #6e6e73; line-height: 21px; font-size: 11px; }
#ud-comments-panel .ud-comments-icon { width: 34px; height: 34px; border-radius: 999px; color: #636366; }
#ud-comments-panel .ud-comments-icon:hover { background: rgba(118,118,128,.12); color: #1c1c1e; }
#ud-comments-panel .ud-comments-new { min-height: 34px; padding: 6px 12px 6px 10px; border-radius: 999px; background: var(--ios-blue); color: #fff; font-size: 13px; font-weight: 650; box-shadow: 0 1px 2px rgba(0,122,255,.2); }
#ud-comments-panel .ud-comments-new:hover { background: #006ee6; }
#ud-comments-panel .ud-comments-scroll { padding: 14px 12px 16px; scrollbar-color: #c7c7cc transparent; }
#ud-comments-panel .ud-comments-list { gap: 10px; }
#ud-comments-panel .ud-comment-card { padding: 14px; border: 0; border-radius: 14px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
#ud-comments-panel .ud-comment-card[data-active="true"] { border: 0; box-shadow: 0 0 0 2px rgba(0,122,255,.32), 0 2px 7px rgba(0,0,0,.10); }
#ud-comments-panel .ud-comment-head { gap: 10px; margin-bottom: 10px; }
#ud-comments-panel .ud-comment-avatar { width: 32px; height: 32px; flex-basis: 32px; border-radius: 50%; background: linear-gradient(145deg,#dcecff,#b8d4ff); color: #075db5; font-size: 10px; }
#ud-comments-panel .ud-comment-who strong { color: var(--ios-ink); font-size: 13px; }
#ud-comments-panel .ud-comment-who time { color: var(--ios-secondary); font-size: 11px; }
#ud-comments-panel .ud-comment-quote { margin-bottom: 9px; padding: 8px 10px; border: 0; border-left: 3px solid #ffcc00; border-radius: 8px; background: #fff9df; color: #75652d; line-height: 1.5; }
#ud-comments-panel .ud-comment-quote:hover { background: #fff4c5; }
#ud-comments-panel .ud-comment-text { color: #3a3a3c; line-height: 1.65; font-size: 14px; }
#ud-comments-panel .ud-comment-compose { padding: 15px; margin-bottom: 12px; border: 0; border-radius: 14px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
#ud-comments-panel .ud-compose-title { margin-bottom: 10px; font-size: 15px; font-weight: 700; }
#ud-comments-panel .ud-compose-quote { border-left-color: #ffcc00; color: #75652d; }
#ud-comments-panel .ud-compose-author input { font-size: 13px; }
#ud-comments-panel textarea { min-height: 88px; padding: 11px 12px; border: 1px solid #d1d1d6; border-radius: 11px; background: #f8f8fa; color: var(--ios-ink); font-size: 14px; }
#ud-comments-panel textarea:focus { border-color: var(--ios-blue); box-shadow: 0 0 0 3px rgba(0,122,255,.16); outline: 0; }
#ud-comments-panel .ud-compose-actions { margin-top: 13px; gap: 8px; }
#ud-comments-panel .ud-comments-text-button { min-height: 34px; padding: 7px 12px; border-radius: 999px; color: var(--ios-blue); font-size: 13px; font-weight: 600; }
#ud-comments-panel .ud-comments-text-button:hover { background: rgba(0,122,255,.10); }
#ud-comments-panel .ud-comments-primary { min-height: 34px; padding: 7px 14px; border-radius: 999px; background: var(--ios-blue); font-size: 13px; font-weight: 650; }
#ud-comments-panel .ud-comments-primary:hover { background: #006ee6; }
#ud-comments-panel .ud-comments-footer { padding: 9px 17px 11px; border-top-color: rgba(60,60,67,.10); color: var(--ios-secondary); }
#ud-comments-panel .ud-comments-hint kbd { border-color: #d1d1d6; border-radius: 5px; background: #f2f2f7; }
@media (max-width: 700px) {
  #ud-comments-panel { right: 8px; left: 8px; bottom: var(--comments-bottom, 42px); width: auto; max-height: 72dvh; border-radius: 20px; box-shadow: 0 -10px 34px rgba(0,0,0,.16); }
  #ud-comments-panel .ud-comments-header { padding: 13px 17px 10px; }
  #ud-comments-panel .ud-comments-scroll { padding-top: 11px; }
  #ud-comments-panel .ud-comments-footer { padding-bottom: 7px; }
}
@media (min-width: 1100px) {
  body.ud-comments-open:not(.presenting):not(.udoc-html-immersive) #canvas { margin-right: calc(var(--comments-width) + 24px); }
}
@media (max-width: 700px) {
  #ud-comments-panel { top: auto; right: 8px; left: 8px; bottom: var(--comments-bottom, 42px); width: auto; max-height: 68dvh; border-radius: 14px; box-shadow: 0 -3px 24px #27354c16; }
  .ud-comments-scroll { min-height: 140px; }
  .ud-comments-header { padding: 12px 16px; }
  #ud-comments-panel .ud-comments-icon { width: 32px; height: 32px; }
  .ud-comments-hint { display: none; }
  .ud-comments-footer { padding: 4px 16px; }
  .ud-comments-empty { padding-top: 26px; padding-bottom: 26px; }
}
@media (prefers-reduced-motion: reduce) { .ud-comment-card { transition: none; } }
.ud-comment-reply { display:block; margin:10px 0 0 auto; border:0; background:transparent; color:#007aff; font-size:12px; font-weight:600; cursor:pointer; }
.ud-comment-reply-card { margin:10px 0 0 40px; padding:9px 10px; border-left:2px solid #d1d1d6; background:#f8f8fa; border-radius:8px; }
.ud-comment-reply-head { display:flex; align-items:center; gap:7px; color:#6e6e73; font-size:11px; }
.ud-comment-reply-card .ud-comment-text { margin:4px 0 0; font-size:13px; line-height:1.5; }
@media print {
  #ud-comments-panel { display: none !important; }
  body.ud-comments-open #canvas { margin-right: 0 !important; }
}

/* Final compact iOS card pass: a quiet accent rail keeps the active thread
 * obvious without the heavy blue outline used by the earlier prototype. */
#ud-comments-panel .ud-comment-card {
  position: relative;
  border-left: 3px solid transparent;
  transition: border-color .16s, box-shadow .16s, transform .16s;
}
#ud-comments-panel .ud-comment-card:hover { transform: translateY(-1px); }
#ud-comments-panel .ud-comment-card[data-active="true"] {
  border-left-color: #007aff;
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 0 0 1px rgba(0,122,255,.14);
}
#ud-comments-panel .ud-comment-menu summary { opacity: .45; transition: opacity .14s, background .14s; }
#ud-comments-panel .ud-comment-card:hover .ud-comment-menu summary,
#ud-comments-panel .ud-comment-menu[open] summary { opacity: 1; }
#ud-comments-panel .ud-comment-reply {
  min-height: 30px;
  margin-top: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  color: #007aff;
  background: rgba(0,122,255,.08);
}
#ud-comments-panel .ud-comment-reply:hover { background: rgba(0,122,255,.15); }
#ud-comments-panel .ud-comment-reply-card {
  margin: 10px 0 0 34px;
  padding: 10px 11px;
  border: 0;
  border-left: 3px solid #d7d7dc;
  border-radius: 10px;
  background: #f2f2f7;
}
