/* 리더 화면(도구막대·서랍) — 본문 색은 reader.js 가 책 안에 따로 넣는다 */
:root, [data-theme="paper"] {
  --bg: #ffffff; --ink: #1f2328; --muted: #6b7079; --line: #e5e7eb; --panel: #ffffff;
  --chip: #f3efe6; --chip-ink: #333; --on: #1d6b4f; --on-ink: #fff; --hover: rgba(0,0,0,.05);
  --scrim: rgba(0,0,0,.28); --track: #e2ded4; color-scheme: light;
}
[data-theme="sepia"] {
  --bg: #f4ecd8; --ink: #4b3a28; --muted: #85725c; --line: #e2d5b8; --panel: #f7f0de;
  --chip: #eadfc4; --chip-ink: #4b3a28; --on: #8a5a2b; --on-ink: #fff; --hover: rgba(80,50,10,.07); --track: #e0d2b2;
}
[data-theme="gray"] {
  --bg: #3a3c40; --ink: #e2e2e2; --muted: #a9acb2; --line: #4c4f54; --panel: #34363a;
  --chip: #46494e; --chip-ink: #e2e2e2; --on: #7fb8a0; --on-ink: #1b1d20; --hover: rgba(255,255,255,.07); --track: #55585e; color-scheme: dark;
}
[data-theme="night"] {
  --bg: #121314; --ink: #c9cbce; --muted: #8b8f96; --line: #26282b; --panel: #18191b;
  --chip: #232528; --chip-ink: #c9cbce; --on: #6aa58c; --on-ink: #0e0f10; --hover: rgba(255,255,255,.06); --track: #2b2e32; color-scheme: dark;
}
[data-theme="contrast"] {
  --bg: #000; --ink: #fff; --muted: #e0e0e0; --line: #fff; --panel: #000;
  --chip: #000; --chip-ink: #fff; --on: #ffd400; --on-ink: #000; --hover: rgba(255,255,255,.15); --track: #fff; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: "Pretendard Variable", "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  overflow: hidden; -webkit-tap-highlight-color: transparent;
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
button { font: inherit; color: inherit; }

.app { position: fixed; inset: 0; }
.stage { position: absolute; inset: 0; }
.stage foliate-view { display: block; width: 100%; height: 100%; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; }

/* 도구막대 — 본문 위에 겹쳐 뜬다(본문은 위아래 여백을 비워 둠) */
.top, .bottom {
  position: absolute; left: 0; right: 0; z-index: 10; display: flex; align-items: center; gap: 4px;
  background: var(--bg); transition: transform .22s ease, opacity .22s ease;
}
.top { top: 0; height: calc(52px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0 16px; border-bottom: 1px solid var(--line); }
.bottom { bottom: 0; height: calc(52px + env(safe-area-inset-bottom)); padding: 0 8px env(safe-area-inset-bottom) 14px; border-top: 1px solid var(--line); }
.app[data-chrome="hidden"] .top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.app[data-chrome="hidden"] .bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.book-title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; gap: 2px; }
.ib {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; cursor: pointer; flex: none;
}
.ib:hover { background: var(--hover); }
.ib:focus-visible, .seg button:focus-visible, .drawer a:focus-visible { outline: 2px solid var(--on); outline-offset: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 34px; margin: 5px 4px 5px 0; padding: 0 11px 0 8px; flex: none;
  border: 1px solid var(--line); border-radius: 17px; background: transparent; color: inherit; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip:hover { background: var(--hover); }
.chip svg { width: 18px; height: 18px; }
#btnMark[aria-pressed="true"] svg { fill: var(--on); stroke: var(--on); }

#slider { width: min(46vw, 740px); accent-color: var(--on); margin: 0 6px 0 0; }
.pct { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.loc, .chap { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chap { overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 28vw; }
.spacer { flex: 1; }

/* 도구막대가 숨었을 때 아래 가운데 작은 쪽 번호 */
.mini {
  position: absolute; left: 50%; bottom: calc(10px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none; z-index: 5;
  opacity: 0; transition: opacity .2s;
}
.app[data-chrome="hidden"] .mini { opacity: 1; }

/* 서랍 */
.scrim { position: absolute; inset: 0; background: var(--scrim); z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(380px, 100vw); z-index: 40; background: var(--panel);
  border-left: 1px solid var(--line); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top);
  transform: translateX(102%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s;
}
.drawer.open { transform: none; visibility: visible; transition: transform .22s ease; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-head .close { background: var(--chip); }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 20px calc(28px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }

/* 설정 */
.set { padding: 16px 0 6px; border-bottom: 1px solid var(--line); }
.set:last-child { border-bottom: 0; }
.set h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 700; }
.set h4 { margin: 14px 0 8px; font-size: 13px; font-weight: 700; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  min-height: 36px; padding: 0 13px; border: 1px solid var(--line); border-radius: 8px; background: transparent;
  font-size: 14px; cursor: pointer;
}
.seg button:hover { background: var(--hover); }
.seg button[aria-pressed="true"] { background: var(--on); border-color: var(--on); color: var(--on-ink); font-weight: 700; }
.help { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.box { margin-top: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; color: var(--muted); }
.box p { margin: 4px 0; } .box b { color: var(--ink); margin-right: 8px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 52px; height: 38px; border: 1px solid var(--line); border-radius: 8px; background: transparent; cursor: pointer; font-weight: 700; }
.stepper output { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }
.fonts button[data-v="serif"], .fonts button[data-v="notoserif"], .fonts button[data-v="nanummyeongjo"], .fonts button[data-v="gowunbatang"] { font-family: "Noto Serif KR", "Batang", serif; }
.links { display: flex; flex-direction: column; gap: 8px; }
.links a { color: var(--on); font-weight: 600; font-size: 14px; }
[data-theme="contrast"] .links a { color: var(--on); }
.reset { margin-top: 14px; border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; font-size: 13px; }

/* 목차 */
.toc-list { list-style: none; margin: 0; padding: 6px 0; }
.toc-list a { display: block; padding: 10px 10px; margin: 0 -10px; border-radius: 8px; color: inherit; text-decoration: none; font-size: 14.5px; line-height: 1.45; }
.toc-list a:hover { background: var(--hover); }
.toc-list a.cur { background: var(--chip); font-weight: 700; box-shadow: inset 3px 0 0 var(--on); }
.toc-list .l1 > a { font-weight: 700; }
.toc-list .l2 > a { padding-left: 24px; color: var(--muted); }
.toc-list .l3 > a { padding-left: 38px; color: var(--muted); font-size: 13.5px; }
.toc-list .l2 > a.cur, .toc-list .l3 > a.cur { color: var(--ink); }

/* 책갈피·문구 */
.marks h3 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); }
.mark { display: flex; gap: 8px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mark .go { flex: 1; text-align: left; border: 0; background: none; padding: 0; cursor: pointer; }
.mark .t { display: block; font-size: 14px; line-height: 1.5; }
.mark .m { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.mark .del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12.5px; padding: 2px 4px; }
.mark .sw { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.empty { color: var(--muted); font-size: 13.5px; padding: 6px 0; }

/* 검색 */
.search-form { display: flex; gap: 6px; padding: 14px 0 8px; position: sticky; top: 0; background: var(--panel); }
.search-form input { flex: 1; min-width: 0; height: 40px; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; background: transparent; color: inherit; font: inherit; font-size: 15px; }
.search-form button { height: 40px; padding: 0 14px; border: 0; border-radius: 8px; background: var(--on); color: var(--on-ink); font-weight: 700; cursor: pointer; }
.search-status { color: var(--muted); font-size: 12.5px; margin: 4px 0 6px; }
.res-group { margin: 14px 0 4px; font-size: 12.5px; color: var(--muted); font-weight: 700; }
.res { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; margin: 0 -10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; line-height: 1.55; color: inherit; }
.res:hover { background: var(--hover); }
.res mark { background: #ffe58a; color: #000; border-radius: 2px; padding: 0 1px; }

/* 글자 선택 메뉴 */
.selmenu {
  position: absolute; z-index: 50; display: flex; align-items: center; gap: 2px; padding: 4px;
  background: #24272c; color: #fff; border-radius: 10px; box-shadow: 0 6px 22px rgba(0,0,0,.25);
}
.selmenu[hidden] { display: none; }
.selmenu button { border: 0; background: none; color: #fff; height: 36px; min-width: 36px; padding: 0 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.selmenu button:hover { background: rgba(255,255,255,.12); }
.selmenu .sep { width: 1px; height: 20px; background: rgba(255,255,255,.25); margin: 0 2px; }
.dot { display: inline-block; width: 16px; height: 16px; border-radius: 50%; vertical-align: middle; }
.dot.yellow, .sw.yellow { background: #f7d64a; } .dot.orange, .sw.orange { background: #f5a25d; } .dot.blue, .sw.blue { background: #84b8f0; }

.toast {
  position: absolute; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px);
  background: #24272c; color: #fff; padding: 9px 16px; border-radius: 20px; font-size: 13.5px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 60; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 640px) {
  .top { padding-left: 12px; }
  .ib { width: 40px; height: 40px; }
  .bottom { flex-wrap: wrap; height: auto; padding: 8px 8px calc(6px + env(safe-area-inset-bottom)) 14px; row-gap: 0; }
  #slider { order: 0; width: 100%; flex: 1 1 100%; margin: 4px 6px 4px 0; }
  .chap { display: none; }
}

/* 좁은 폰(갤럭시 S 등 360px)에서는 제목이 한 글자만 잘려 보여 숨긴다 — 버튼이 우선 */
@media (max-width: 380px) { .book-title { visibility: hidden; } }
