/* 논문 리더. 색·글꼴은 style.css 의 변수(--bg, --card-bg, --border, --accent …)만 쓴다.
   종이(쪽)가 주인공이라 도구 막대는 얇은 한 줄, 배경은 중립색, 패널은 완전히 접힌다. */

/* ---------- 첫 화면 ---------- */
main.rd-home { max-width: 960px; }
.rd-home .rd-dropzone, .rd-home .rd-recent, .rd-home .rd-home-error { max-width: 720px; }
.rd-home h1 { margin: 0 0 6px; font-size: 1.6rem; }
.rd-home .subtitle { margin: 0 0 24px; color: var(--muted); }

.rd-dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 44px 20px;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.rd-dropzone.dragover { border-color: var(--accent); background: var(--hover-tint); }
.rd-dropzone.is-busy { opacity: 0.6; pointer-events: none; }
.rd-dropzone-text { color: var(--muted); font-size: 0.95rem; }
.rd-file-label {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 20px;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.rd-file-label:hover { background: var(--hover-tint); }
/* 파일 입력은 화면에서만 숨기고 초점은 받는다(키보드로 Tab → Enter/Space 로 열 수 있다). */
.rd-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.rd-file-input:focus-visible + .rd-file-label { outline: 2px solid var(--accent); outline-offset: 3px; background: var(--hover-tint); }
.rd-home-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--error-border);
  border-radius: 6px;
  background: var(--error-bg);
  font-size: 0.9rem;
}
.rd-home-error[hidden], .rd-recent[hidden], .rd-notice[hidden] { display: none; }

.rd-recent { margin-top: 28px; }
.rd-recent-title { margin: 0 0 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.rd-recent-list { list-style: none; margin: 0; padding: 0; }
.rd-recent-item { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--border); }
.rd-recent-item button {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 10px 4px;
}
.rd-recent-open { flex: 1; display: flex; justify-content: space-between; gap: 12px; text-align: left; }
.rd-recent-open:hover { color: var(--accent); }
.rd-recent-size { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.rd-recent-delete { color: var(--muted); font-size: 0.8rem !important; }
.rd-recent-delete:hover { color: var(--accent); }

/* ---------- 첫 화면: 글 붙여넣기 ---------- */
.rd-paste { margin-top: 36px; }
.rd-paste-title { margin: 0 0 8px; font-size: 1.05rem; }
.rd-paste-text {
  width: 100%;
  min-height: 150px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  box-sizing: border-box;
}
.rd-paste-text[hidden], .rd-paste-rendered[hidden], .rd-paste-result[hidden], .rd-paste-status[hidden] { display: none; }
.rd-paste-rendered {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  font-size: 0.95rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-height: 0;
  max-height: 60vh;
  overflow-y: auto;
}
.rd-paste-actions { display: flex; gap: 8px; margin-top: 10px; }
.rd-paste-btn {
  height: 40px;
  padding: 0 18px;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.rd-paste-btn:disabled { opacity: 0.5; cursor: default; }
.rd-paste-btn-plain { background: transparent; color: var(--accent); }
.rd-paste-btn-plain:hover { background: var(--hover-tint); }
.rd-paste-btn[hidden] { display: none; }
.rd-paste-status { margin: 8px 0 0; font-size: 0.85rem; color: var(--muted); }
.rd-paste-result { margin-top: 18px; }
.rd-paste-terms { position: static; max-height: none; overflow: visible; }
.rd-paste-count { margin: 0 0 10px; font-size: 1rem; }
@media (max-width: 640px) {
  .rd-paste-btn { height: 44px; }
}

/* ---------- 전체 화면 ---------- */
body.rd-open { overflow: hidden; }
body.rd-open .site-header,
body.rd-open .site-footer { display: none; }

.rd {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  --rd-left-w: 260px;
  --rd-right-w: 340px;
  --rd-desk: color-mix(in srgb, var(--text) 6%, var(--bg));
  --rd-danger: #c0392b;
  --rd-hl-ink: #1f2328; /* 형광펜 색 위의 표시: 형광펜 색은 다크 모드에서도 같은 연한 색이라 글자색도 고정 */
}
:root[data-theme="dark"] .rd { --rd-danger: #ff8f84; }
.rd[hidden] { display: none; }
.rd button, .rd input { font-family: inherit; }
.rd :focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- 도구 막대 ---------- */
.rd-toolbar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 10px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.rd-group { display: flex; align-items: center; gap: 2px; }
.rd-spacer { flex: 1 1 0; }
.rd-title {
  flex: 0 1 260px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.rd-btn {
  height: 30px;
  min-width: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.rd-btn:hover:not(:disabled) { background: var(--hover-tint); }
.rd-btn:disabled { color: var(--muted); opacity: 0.55; cursor: default; }
.rd-btn.is-on,
.rd-btn[aria-pressed="true"]:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.rd-icon-btn { padding: 0 6px; font-size: 1.05rem; }
#rd-left-toggle { gap: 5px; }
#rd-left-toggle .rd-btn-label { font-size: 0.85rem; white-space: nowrap; }
@media (max-width: 767px) { #rd-left-toggle .rd-btn-label { display: none; } }

.rd-page-input {
  width: 3.4em;
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  text-align: right;
  appearance: textfield;
  -moz-appearance: textfield;
}
.rd-page-input::-webkit-outer-spin-button,
.rd-page-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.rd-page-total { color: var(--muted); margin-left: 4px; white-space: nowrap; }

.rd-search-input {
  width: 150px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}
.rd-search-input:disabled { opacity: 0.55; }
.rd-search-count { color: var(--muted); min-width: 2.5em; margin-left: 4px; font-size: 0.8rem; white-space: nowrap; }

.rd-extra { display: flex; align-items: center; gap: 10px; }
.rd-zoom-label { min-width: 3.2em; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.rd-more { display: none; font-size: 1.2rem; }
.rd-panelbtns { padding-left: 8px; border-left: 1px solid var(--border); }

.rd-search-close { display: none; }

/* ---------- 안내 ---------- */
.rd-notice {
  flex: none;
  padding: 7px 16px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.rd-notice { display: flex; align-items: flex-start; gap: 8px; }
.rd-notice[hidden] { display: none; }
.rd-notice-lines { flex: 1 1 auto; min-width: 0; }
.rd-notice-close { flex: none; border: 0; background: none; color: inherit; font-size: 1.1rem; line-height: 1; padding: 0 4px; cursor: pointer; }
.rd-notice p { margin: 0; }
.rd-notice p + p { margin-top: 2px; }

/* ---------- 본문 + 패널 ---------- */
.rd-body {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 0 minmax(0, 1fr) 0;
}
.rd-body.rd-left-open { grid-template-columns: var(--rd-left-w) minmax(0, 1fr) 0; }
.rd-body.rd-right-open { grid-template-columns: 0 minmax(0, 1fr) var(--rd-right-w); }
.rd-body.rd-left-open.rd-right-open { grid-template-columns: var(--rd-left-w) minmax(0, 1fr) var(--rd-right-w); }

.rd-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card-bg);
  visibility: hidden;
}
.rd-panel-left { border-right: 1px solid var(--border); }
.rd-panel-right { border-left: 1px solid var(--border); }
.rd-left-open .rd-panel-left,
.rd-right-open .rd-panel-right { visibility: visible; }
.rd-body:not(.rd-left-open) .rd-panel-left,
.rd-body:not(.rd-right-open) .rd-panel-right { border-width: 0; }

.rd-tabs {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--border);
}
.rd-tab {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 0.88rem;
  cursor: pointer;
}
.rd-tab:hover { color: var(--text); }
.rd-tab[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.rd-panel-close { display: none; margin-left: auto; margin-bottom: 4px; }
.rd-pane { flex: 1 1 0; min-height: 0; overflow: auto; padding: 12px; font-size: 0.88rem; }
.rd-pane[hidden] { display: none; }
.rd-pane:empty::before { content: "표시할 내용이 없습니다."; color: var(--muted); }

/* ---------- 쪽 ---------- */
.rd-scroll {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
  background: var(--rd-desk);
  outline: none;
}
.rd .rd-scroll:focus,
.rd .rd-scroll:focus-visible { outline: none; }
/* 읽기 영역 테두리는 키보드로 움직일 때만(스크립트 초점·마우스 클릭엔 없음) */
.rd.rd-kbd .rd-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rd-pages {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: max-content;
  min-width: 100%;
  padding: 16px;
}
.rd-page {
  position: relative;
  flex: none;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.rd-canvas { position: absolute; left: 0; top: 0; display: block; }
.rd-page .textLayer { z-index: 2; }
.rd-overlay { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

/* ---------- 돌아가기 ---------- */
.rd-back {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 5;
  height: 36px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}
.rd-back[hidden] { display: none; }
.rd-scrim { display: none; }

/* ===== 작업 4: 선택 도구·형광펜·메모 패널 (시작) ===== */
.rd-hl-yellow { --hl-rgb: 255, 224, 102; --hl-solid: #ffe066; }
.rd-hl-green { --hl-rgb: 140, 233, 154; --hl-solid: #8ce99a; }
.rd-hl-pink { --hl-rgb: 255, 201, 222; --hl-solid: #ffc9de; }
.rd-hl-blue { --hl-rgb: 165, 216, 255; --hl-solid: #a5d8ff; }
.rd-rect.rd-highlight.rd-hl-yellow,
.rd-rect.rd-highlight.rd-hl-green,
.rd-rect.rd-highlight.rd-hl-pink,
.rd-rect.rd-highlight.rd-hl-blue { background: rgba(var(--hl-rgb), 0.6); }
.rd-rect.rd-highlight.rd-memo-mark {
  background: var(--hl-solid);
  border: calc(1px / var(--rd-scale, 1)) solid rgba(0, 0, 0, 0.55);
  border-radius: 50%;
}
.rd-rect.rd-selpreview {
  background: var(--accent-soft);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  outline: calc(1px / var(--rd-scale, 1)) solid var(--accent);
  outline: calc(1px / var(--rd-scale, 1)) solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: 2px;
}

.rd-seltool {
  position: fixed;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  max-width: calc(100vw - 16px);
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
}
.rd-seltool[hidden] { display: none; }
.rd-hlbtn {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid var(--card-bg);
  border-radius: 50%;
  background: var(--hl-solid);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.rd-hlbtn:hover { box-shadow: 0 0 0 2px var(--accent); }
.rd-seltool-sep { width: 1px; height: 18px; background: var(--border); margin: 0 2px; }
.rd-seltool-btn {
  height: 28px;
  padding: 0 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
}
.rd-seltool-btn:hover { background: var(--hover-tint); }

.rd-annopop {
  position: fixed;
  z-index: 41;
  box-sizing: border-box;
  width: min(280px, calc(100vw - 16px));
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.25);
}
.rd-annopop[hidden] { display: none; }
.rd-annopop-colors { display: flex; gap: 8px; margin-bottom: 8px; }
.rd-annopop-color {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 2px solid var(--card-bg);
  border-radius: 50%;
  background: var(--hl-solid);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.rd-annopop-color[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.rd-annopop-note {
  box-sizing: border-box;
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  resize: vertical;
}
.rd-annopop-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.rd-annopop-btn {
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.rd-annopop-btn:hover { background: var(--hover-tint); }
.rd-annopop-btn.is-primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.rd-annopop-btn.is-danger { margin-right: auto; color: var(--rd-danger); }
.rd-annopop-btn.is-term { color: var(--accent); border-color: var(--accent); }
.rd-annopop-btn[hidden] { display: none; }
/* 겹친 기록이 없으면 숨긴다: 이 칸의 인라인 display:flex 가 hidden 을 이기므로 !important */
#rd-annopop-switch[hidden] { display: none !important; }
.rd-annopop-actions { flex-wrap: wrap; }
/* 색만으로 구분하지 않게: 고른 색에는 표시를 붙인다 */
.rd-annopop-color[aria-pressed="true"]::after { content: "✓"; display: block; color: var(--rd-hl-ink); font-size: 0.8rem; font-weight: 700; line-height: 20px; text-align: center; }

.rd-tab-count {
  display: inline-block;
  min-width: 1.4em;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  line-height: 1.5;
  text-align: center;
}
.rd-pane-empty { margin: 16px 12px; color: var(--muted); font-size: 0.88rem; line-height: 1.5; }
.rd-note-list { margin: 0; padding: 0; list-style: none; }
.rd-note-item { border-bottom: 1px solid var(--border); }
.rd-note {
  display: flex;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.rd-note:hover { background: var(--hover-tint); }
.rd-note-dot {
  flex: none;
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--hl-solid);
  box-shadow: 0 0 0 1px var(--border);
}
.rd-note-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.rd-note-page { color: var(--muted); font-size: 0.75rem; }
.rd-note-quote { font-size: 0.85rem; line-height: 1.45; overflow-wrap: anywhere; }
.rd-note-memo { font-size: 0.85rem; line-height: 1.45; color: var(--accent); white-space: pre-wrap; overflow-wrap: anywhere; }
.rd-note.is-lost .rd-note-quote { color: var(--muted); }
.rd-note-losthead { margin: 14px 12px 2px; font-size: 0.85rem; color: var(--muted); }
.rd-note-losthint { margin: 0 12px 6px; color: var(--muted); font-size: 0.78rem; line-height: 1.4; }
/* ===== 작업 4 (끝) ===== */

/* ===== 작업 5: 용어 밑줄·카드·용어 패널 (시작) ===== */
/* 용어 표시: 눈에 띄되 쪽이 지저분해지지 않게. 약 1.75px 실선 밑줄(강조색 75%)과 아주 옅은 배경(9%).
   마우스를 올린 용어는 밑줄이 진해지고 배경도 짙어진다. 형광펜(불투명도 0.6 안팎의 채움)이 겹치면 형광펜이 우세하다.
   사각형은 겹침층 요소일 뿐, pdf.js 글자층 요소는 건드리지 않는다.
   파일 끝 겹침층 규칙(.rd-rect.rd-term)보다 뒤에 오지 않으므로 .rd-layer 를 붙여 우선하게 한다. */
.rd-layer .rd-rect.rd-term {
  /* 테두리는 레이아웃에서 정수 화소로 내림되어 배율 1에서 1px 로 줄어드므로, 내림이 없는 안쪽 그림자로 긋는다. */
  border-bottom: 0;
  box-shadow: inset 0 calc(-1.75px / var(--rd-scale, 1)) 0 var(--accent);
  box-shadow: inset 0 calc(-1.75px / var(--rd-scale, 1)) 0 color-mix(in srgb, var(--accent) 75%, transparent);
  background: var(--accent-soft);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
}
.rd-layer .rd-rect.rd-term.is-hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: inset 0 calc(-1.75px / var(--rd-scale, 1)) 0 var(--accent);
}
.rd-scroll.is-term-hover .textLayer,
.rd-scroll.is-term-hover .textLayer * { cursor: pointer; }

.rd-term-card { z-index: 45; }
.rd-term-card[hidden] { display: none; }
.rd-term-hide {
  margin-top: 8px;
  margin-left: 10px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
}
.rd-term-hide:hover { color: var(--text); }
.rd-term-report {
  margin-top: 8px;
  margin-left: 10px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
}
.rd-term-report:hover { color: var(--text); }
.rd-term-report:disabled { cursor: default; opacity: 0.6; }
.rd-term-report.is-done { text-decoration: none; cursor: default; display: inline-block; }
.rd-term-card .dict-popover-detail { display: inline-block; }

.rd-term-block {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--card-bg);
}
.rd-term-block[hidden] { display: none; }
.rd-term-sectionhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.rd-term-sectionhead .current-page-terms-title { margin: 0; }
.rd-lookup-none { margin: 0 0 6px; color: var(--text); }
#rd-lookup a { color: var(--accent); }
.rd-term-hint { margin: 6px 0 0; color: var(--muted); font-size: 0.8rem; }
.rd-term-status { margin: 0 0 10px; color: var(--muted); }
.rd-term-status[hidden] { display: none; }
.rd-term-filter {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
}
.rd-term-filter:disabled { opacity: 0.55; }
#rd-term-category {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}
#rd-paste-category {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}
.rd-term-count { margin: 12px 0 6px; font-size: 0.9rem; }
#rd-pane-terms .term-list { gap: 0; }
#rd-pane-terms .term-card {
  position: relative;
  display: block;
  padding: 10px 34px 10px 12px;
  margin-bottom: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
#rd-pane-terms .term-card:hover { border-color: var(--accent); }
#rd-pane-terms .term-card-name { display: block; font-weight: 600; }
#rd-pane-terms .term-card-definition {
  margin: 4px 0 6px;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#rd-pane-terms .rd-focus-card .term-card-definition,
#rd-pane-terms .rd-lookup-list .term-card-definition { display: block; overflow: visible; }
#rd-pane-terms .term-list li a.term-card-detail {
  display: inline-flex;
  margin-top: 4px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  text-decoration: none;
}
#rd-pane-terms .term-card-hide-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
#rd-pane-terms .term-card-hide-btn:hover { background: var(--hover-tint); color: var(--text); }
#rd-pane-terms .term-card-basics { margin-top: 6px; font-size: 0.82rem; }
#rd-pane-terms .term-card-basics-list { list-style: none; margin: 6px 0 0; padding: 0; }
/* 카드 이름 단추: 키보드로 카드를 누를 수 있게 한다. 모양은 글자 그대로. */
.rd-card-go {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.rd-card-go[aria-expanded]::after { content: " ▾"; color: var(--muted); }
.rd-card-go[aria-expanded="true"]::after { content: " ▴"; }
/* 사전 찾기 결과에서 펼친 카드: 뜻 전체를 보여 준다 */
#rd-pane-terms .term-card.is-expanded { border-color: var(--accent); }
#rd-pane-terms .term-card.is-expanded > .term-card-definition {
  display: block;
  overflow: visible;
  -webkit-line-clamp: unset;
}
/* 뜻을 받지 못한 카드의 안내 */
.rd-def-failed { margin: 4px 0 6px; color: var(--muted); font-size: 0.82rem; line-height: 1.5; }
.rd-def-failed .rd-def-retry { color: var(--accent); text-decoration: underline; }
@media (max-width: 767px) {
  .rd-term-card.is-sheet {
    left: 8px !important;
    right: 8px;
    top: auto !important;
    bottom: 8px;
    width: auto;
    z-index: 50;
    max-height: 60vh;
    overflow: auto;
  }
}
/* ===== 작업 5 (끝) ===== */

/* ---------- 좁은 화면: 패널은 아래 서랍 ---------- */
@media (max-width: 767px) {
  .rd-toolbar { gap: 4px; padding: 0 6px; }
  .rd-title { display: none; }
  .rd-search-input { width: 100%; min-width: 0; }
  .rd-search { flex: 1 1 0; min-width: 0; }
  .rd-search-count,
  .rd-search .rd-icon-btn,
  /* 검색 칸에 초점이 있거나 검색어가 있으면(reader.js 가 .rd-searching 을 붙인다) 도구 막대를 검색에 내준다:
     입력 칸은 남는 폭을 다 쓰고, 이전·다음·건수·검색 닫기가 보인다. */
  .rd-toolbar.rd-searching #rd-close,
  .rd-toolbar.rd-searching .rd-pagebox,
  .rd-toolbar.rd-searching .rd-more,
  .rd-toolbar.rd-searching .rd-panelbtns { display: none; }
  .rd-toolbar.rd-searching .rd-search { flex: 1 1 auto; gap: 4px; }
  .rd-toolbar.rd-searching .rd-search-input { flex: 1 1 4em; width: auto; }
  .rd-toolbar.rd-searching .rd-search-count { display: inline-block; flex: 0 0 auto; min-width: 3em; text-align: center; margin: 0; }
  .rd-toolbar.rd-searching .rd-search .rd-icon-btn,
  .rd-toolbar.rd-searching .rd-search-close { display: inline-flex; flex: 0 0 auto; }
  .rd-spacer { display: none; }
  .rd-panelbtns { padding-left: 4px; }
  .rd-more { display: inline-flex; }
  .rd-extra {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 6px;
    z-index: 20;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  }
  .rd-toolbar.more-open .rd-extra { display: flex; }

  .rd-body,
  .rd-body.rd-left-open,
  .rd-body.rd-right-open,
  .rd-body.rd-left-open.rd-right-open { grid-template-columns: minmax(0, 1fr); }
  .rd-scroll { grid-column: 1; grid-row: 1; }
  .rd-panel,
  .rd-panel-left,
  .rd-panel-right {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: 70vh;
    border-width: 1px 0 0;
    border-style: solid;
    border-color: var(--border);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .rd-left-open .rd-panel-left,
  .rd-right-open .rd-panel-right {
    transform: translateY(0);
    visibility: visible;
    transition: transform 0.2s ease, visibility 0s;
  }
  .rd-body:not(.rd-left-open) .rd-panel-left,
  .rd-body:not(.rd-right-open) .rd-panel-right { border-width: 1px 0 0; }
  .rd-panel-close { display: inline-flex; }
  .rd-drawer-open ~ .rd-scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.35); }
}

/* ---------- 좁은 화면: 터치 대상 40px, 배경 스크롤 잠금 ---------- */
@media (max-width: 767px) {
  .rd-toolbar { height: 48px; }
  .rd-btn { min-height: 40px; min-width: 40px; }
  .rd-page-input { width: 2.8em; height: 40px; font-size: 1rem; }
  .rd-search-input { height: 40px; font-size: 1rem; } /* 16px 이상이어야 iOS 가 입력할 때 확대하지 않는다 */
  .rd-tab { height: 40px; min-width: 40px; }
  #rd-annopop-switch button { min-width: 40px; min-height: 40px; }
  .rd-hlbtn { width: 40px; height: 40px; }
  .rd-seltool { gap: 2px; }
  .rd-seltool-btn { height: 40px; padding: 0 12px; }
  .rd-annopop-color { width: 40px; height: 40px; }
  .rd-annopop-color[aria-pressed="true"]::after { line-height: 36px; font-size: 1rem; }
  .rd-annopop-colors { gap: 12px; }
  .rd-annopop-btn { height: 40px; padding: 0 14px; }
  .rd-annopop-note { font-size: 1rem; }
  .rd-note { min-height: 40px; }
  .rd-card-go { min-height: 40px; display: flex; align-items: center; }
  #rd-pane-terms .term-card { padding-right: 46px; }
  #rd-pane-terms .term-card-hide-btn { top: 0; right: 0; width: 40px; height: 40px; }
  #rd-pane-terms .term-list li a.term-card-detail { min-height: 40px; padding: 0 14px; align-items: center; }
  .term-filter-link, .rd-focus-close, .rd-lookup-close, #rd-term-more, .rd-term-hide, .rd-term-report { min-height: 40px; }
  #rd-term-category, #rd-paste-category, .rd-term-filter { min-height: 40px; font-size: 1rem; }
  .term-filter-checkbox { min-height: 40px; display: inline-flex; align-items: center; gap: 6px; }
  .term-filter-checkbox[hidden] { display: none; }
  .ro-item { min-height: 40px; align-items: center; }
  .rd-term-card .dict-popover-close, .rd-term-card .dict-popover-detail { min-width: 40px; min-height: 40px; }
  .rd-ref-go, .rd-ref-more, .rd-ref-prev-go { min-height: 40px; min-width: 40px; }
  .rd-back { height: 40px; }
  .rd-recent-item button { min-height: 40px; }
  .rd-file-label { height: 44px; }
  /* 서랍이 열려 있으면 뒤의 본문은 스크롤하지 않는다(뒤 본문은 inert 이기도 하다). 두 손가락 확대는 막지 않는다. */
  .rd-body.rd-drawer-open .rd-scroll { overflow: hidden; }
  .rd-pane { overscroll-behavior: contain; }
}

@media (prefers-reduced-motion: reduce) {
  .rd-panel { transition: none !important; }
  .rd *, .rd *::before, .rd *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- 겹침층(작업 3) ---------- */
/* 쪽을 격리해 형광펜의 multiply 가 캔버스와 섞이게 한다. 겹침층 자체는 쌓임 맥락을 만들지 않는다(텍스트 레이어 아래). */
.rd-page { isolation: isolate; }
.rd-page .rd-overlay { z-index: auto; }
.rd-layer {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  transform: scale(var(--rd-scale, 1));
  pointer-events: none;
}
.rd-layer-highlight { mix-blend-mode: multiply; }
.rd-rect { position: absolute; box-sizing: border-box; pointer-events: none; }
.rd-rect.rd-highlight { background: rgba(255, 224, 51, 0.5); border-radius: 1px; }
.rd-rect.rd-term { border-bottom: calc(1px / var(--rd-scale, 1)) dotted var(--accent); }
.rd-rect.rd-ref { border-bottom: calc(1px / var(--rd-scale, 1)) solid var(--accent); }
.rd-rect.rd-search {
  background: rgba(255, 190, 40, 0.28);
  border: calc(1px / var(--rd-scale, 1)) solid rgba(210, 130, 0, 0.7);
  border-radius: 2px;
}
.rd-rect.rd-search.rd-current {
  background: rgba(255, 140, 0, 0.5);
  border-color: rgba(190, 80, 0, 0.95);
  box-shadow: 0 0 0 calc(1px / var(--rd-scale, 1)) rgba(190, 80, 0, 0.5);
}
.rd-flash-rect {
  background: var(--rd-flash, color-mix(in srgb, var(--accent) 35%, transparent));
  border-radius: 2px;
  animation: rd-flash-fade 1.2s ease-out forwards;
}
@keyframes rd-flash-fade { 0% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .rd-flash-rect { animation: none; }
}

/* 문서를 여는 동안 전체 화면 리더 뒤로 자동 광고가 비치지 않게 한다(애드센스 로더는 그대로 둔다). */
body.rd-open > ins.adsbygoogle,
body.rd-open > .google-auto-placed,
body.rd-open > .adsbygoogle { display: none !important; }

/* 단축키 안내 */
.rd-keys {
  position: fixed; z-index: 60; left: 50%; top: 50%; transform: translate(-50%, -50%);
  box-sizing: border-box; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  padding: 16px 18px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--card-bg); color: var(--text); box-shadow: 0 10px 34px rgba(0, 0, 0, 0.3);
}
.rd-keys[hidden] { display: none; }
.rd-keys-title { margin: 0 0 10px; font-size: 1.05rem; }
.rd-keys-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0 0 12px; font-size: 0.88rem; }
.rd-keys-list dt { font-weight: 600; font-family: inherit; }
.rd-keys-list dd { margin: 0; }
.rd-keys-close { border: 1px solid var(--border); }

/* DOI·arXiv로 열기, 핵심 선행논문 (oa.js) */
.rd-oa-form { display: flex; gap: 8px; margin: 12px 0 4px; flex-wrap: wrap; }
.rd-oa-input { flex: 1 1 240px; min-width: 0; padding: 8px 10px; border: 1px solid var(--border, #ccc); border-radius: 6px; background: var(--card-bg); color: var(--text); font: inherit; }
.rd-oa-form button { cursor: pointer; font: inherit; }
.rd-oa-form button:disabled { opacity: 0.6; cursor: default; }
.rd-oa-msg { margin: 4px 0 0; color: var(--text); }
.rd-oa-msg[hidden] { display: none; }
.rd-oa-msg a, #rd-prior a { color: var(--accent); }
.rd-prior-list { margin: 0; padding-left: 1.2em; }
.rd-prior-list li { margin: 0 0 6px; }
.rd-prior-meta { font-size: 0.85em; opacity: 0.8; }
