:root {
  --amber: #D4871C;
  --teal: #1A5C6B;
  --teal-light: #2E8CA3;
  --orange: #E8611A;
  --night: #16161a;
  --panel: #1f1f24;
  --panel-2: #26262c;
  --cream: #FFF8EE;
  --muted: #9a948a;
  --line: #35353c;
  --green: #2D8E6F;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--night);
  color: var(--cream);
  font: 15px/1.6 -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--teal-light); }

/* ── Header ── */
header.review-bar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 18px;
  background: rgba(22,22,26,0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.review-bar .home { color: var(--muted); text-decoration: none; font-size: 13px; }
.review-bar .home:hover { color: var(--cream); }
.review-bar h1 { font-size: 15px; margin: 0; font-weight: 600; flex: 1; min-width: 200px; }
.review-bar select {
  background: var(--panel); color: var(--cream);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 13px;
}
.review-bar .viewer { font-size: 12px; color: var(--muted); }
#diff-banner {
  display: none; width: 100%; padding: 6px 10px; border-radius: 6px;
  background: rgba(212,135,28,0.12); border: 1px solid rgba(212,135,28,0.4);
  color: var(--amber); font-size: 13px;
}

/* ── Layout ── */
.review-main { display: flex; gap: 0; max-width: 1280px; margin: 0 auto; }
article#doc {
  flex: 1; min-width: 0; max-width: 780px;
  padding: 28px 34px 120px; margin: 0 auto;
}
aside#panel {
  width: 350px; flex-shrink: 0;
  border-left: 1px solid var(--line);
  padding: 18px 16px 120px;
  position: sticky; top: 49px;
  height: calc(100vh - 49px);
  overflow-y: auto;
}

/* ── Document typography ── */
#doc h1 { color: var(--cream); font-size: 26px; line-height: 1.25; margin: 1.2em 0 0.4em; }
#doc h2 {
  color: var(--amber); font-size: 20px; margin-top: 1.6em;
  border-bottom: 1px solid var(--line); padding-bottom: 6px;
}
#doc h3 { color: var(--teal-light); font-size: 16.5px; margin-top: 1.4em; }
#doc h4 { color: var(--cream); font-size: 15px; }
#doc img { max-width: 100%; border-radius: 8px; }
#doc figure { margin: 1.4em 0; text-align: center; }
#doc figcaption { font-size: 12.5px; color: var(--muted); font-style: italic; margin-top: 6px; }
#doc table { border-collapse: collapse; width: 100%; font-size: 13.5px; margin: 1em 0; display: block; overflow-x: auto; }
#doc th, #doc td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
#doc th { background: var(--panel); color: var(--amber); }
#doc blockquote { border-left: 3px solid var(--teal); margin-left: 0; padding-left: 14px; color: var(--muted); }
#doc hr { border: none; border-top: 1px solid var(--line); margin: 2em 0; }
#doc code { background: var(--panel); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* ── Anchored blocks & comment affordance ── */
#doc [data-anchor] { position: relative; border-radius: 4px; }
#doc [data-anchor].has-comments {
  border-left: 3px solid var(--amber);
  padding-left: 10px; margin-left: -13px;
  cursor: pointer;
}
#doc [data-anchor].flash { animation: flash 1.6s ease-out; }
/* Table rows can't take the border-left/margin treatment (margins don't
   apply to tr); highlight with a background tint + inset bar on the first
   cell instead. */
#doc tr[data-anchor].has-comments {
  border-left: none; padding-left: 0; margin-left: 0;
  background: rgba(212,135,28,0.08);
}
#doc tr[data-anchor].has-comments > td:first-child,
#doc tr[data-anchor].has-comments > th:first-child { box-shadow: inset 3px 0 0 var(--amber); }
@keyframes flash { 0% { background: rgba(212,135,28,0.25); } 100% { background: transparent; } }

#add-btn {
  position: absolute; z-index: 30; display: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--amber); color: #16161a; border: none;
  font-size: 17px; line-height: 1; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
#add-btn:hover { background: var(--orange); }

/* ── Comment composer popover ── */
#composer {
  display: none; position: absolute; z-index: 50;
  width: 320px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.6);
}
#composer .quote { font-size: 12px; color: var(--muted); font-style: italic; margin-bottom: 8px;
  max-height: 48px; overflow: hidden; border-left: 2px solid var(--amber); padding-left: 8px; }
#composer textarea {
  width: 100%; min-height: 70px; resize: vertical;
  background: var(--night); color: var(--cream);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px; font: inherit; font-size: 13.5px;
}
#composer .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* ── Buttons ── */
button.btn {
  background: var(--teal); color: var(--cream); border: none;
  border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
button.btn:hover { background: var(--teal-light); }
button.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
button.btn.ghost:hover { color: var(--cream); }
button.link {
  background: none; border: none; color: var(--teal-light);
  font-size: 12px; cursor: pointer; padding: 2px 4px;
}
button.link:hover { text-decoration: underline; }

/* ── Sidebar ── */
#panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 4px 0 12px; }
.comment-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 13.5px;
}
.comment-card.resolved { opacity: 0.55; }
.comment-card .meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.comment-card .meta .author { color: var(--amber); font-weight: 600; }
.comment-card .quote {
  font-size: 12px; color: var(--muted); font-style: italic;
  border-left: 2px solid var(--teal); padding-left: 8px; margin: 4px 0 6px;
  max-height: 40px; overflow: hidden; cursor: pointer;
}
.comment-card .quote:hover { color: var(--cream); }
.comment-card .body { white-space: pre-wrap; }
.comment-card .replies { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
.comment-card .reply { margin-bottom: 6px; }
.comment-card .reply .author { color: var(--teal-light); font-weight: 600; font-size: 12px; }
.comment-card .actions { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.comment-card textarea {
  width: 100%; min-height: 50px; margin-top: 6px;
  background: var(--night); color: var(--cream);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px; font: inherit; font-size: 13px;
}
.orphan-note { font-size: 11.5px; color: var(--orange); margin-bottom: 4px; }
#panel .empty { color: var(--muted); font-size: 13px; }
#resolved-toggle { margin: 14px 0 8px; }

/* ── Diff rendering ── */
.diff-added { background: rgba(45,142,111,0.14); border-left: 3px solid var(--green); padding-left: 10px; margin-left: -13px; }
.diff-removed { background: rgba(232,97,26,0.10); border-left: 3px solid var(--orange); padding-left: 10px; margin-left: -13px; opacity: 0.75; }
.diff-removed * { text-decoration: line-through; text-decoration-color: rgba(232,97,26,0.7); }
ins { background: rgba(45,142,111,0.3); text-decoration: none; border-radius: 3px; padding: 0 2px; }
del { background: rgba(232,97,26,0.25); text-decoration: line-through; border-radius: 3px; padding: 0 2px; }

/* ── Mobile ── */
#panel-toggle { display: none; }
@media (max-width: 980px) {
  aside#panel {
    position: fixed; right: 0; top: 49px; bottom: 0; height: auto;
    background: var(--night); transform: translateX(100%);
    transition: transform 0.25s ease; width: min(92vw, 360px); z-index: 60;
    border-left: 1px solid var(--line);
  }
  aside#panel.open { transform: translateX(0); box-shadow: -10px 0 40px rgba(0,0,0,0.6); }
  #panel-toggle {
    display: block; position: fixed; bottom: 18px; right: 18px; z-index: 70;
    background: var(--amber); color: var(--night); border: none; border-radius: 999px;
    padding: 12px 18px; font-weight: 700; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.5); cursor: pointer;
  }
}
