/* =========================================================================
   서재 — 웹 EPUB 뷰어 스타일
   ========================================================================= */

:root {
  --ink: #211e19;
  --ink-2: #5c544a;
  --ink-3: #8d8274;
  --paper: #f7f3ec;
  --paper-2: #fffdf9;
  --paper-3: #f1eade;
  --line: #e6ddcf;
  --accent: #8c5a2b;
  --accent-2: #b07c3f;
  --accent-soft: #f2e5cf;
  --danger: #a63a2c;
  --shadow-sm: 0 1px 2px rgba(58, 44, 28, .06), 0 4px 14px rgba(58, 44, 28, .07);
  --shadow-md: 0 10px 30px rgba(58, 44, 28, .13);
  --radius: 16px;
  --ui-font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --serif: "Noto Serif KR", "Nanum Myeongjo", "Apple SD Gothic Neo", Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--ui-font);
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  word-break: keep-all;
  overflow-wrap: break-word;
}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }
[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, [role="button"]:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 99;
  background: var(--paper-2); color: var(--ink); padding: 8px 14px; border-radius: 10px;
  box-shadow: var(--shadow-sm);
}
.skip-link:focus { left: 12px; }

/* ---------------------------------------------------------------- library */

.library {
  background:
    radial-gradient(900px 520px at 12% -8%, #fffdf8 0%, rgba(255, 253, 248, 0) 62%),
    radial-gradient(720px 460px at 88% 4%, #f4ecde 0%, rgba(244, 236, 222, 0) 60%),
    linear-gradient(180deg, #f8f4ec 0%, #f3ede2 100%);
}

.lib-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 18px 28px;
}

.lib-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }

.brand-mark {
  width: 42px; height: 42px; flex: 0 0 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: #f7ecd9;
  background: linear-gradient(150deg, #6d4a28, #3f2b17);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 6px 16px rgba(63, 43, 23, .22);
}
.brand-mark svg { width: 24px; height: 24px; }

.brand-text { min-width: 0; }
.brand-text h1 {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: -.01em;
  margin: 0;
  line-height: 1.2;
}
.brand-text p {
  margin: 3px 0 0; font-size: 12px; color: var(--ink-3); letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw;
}

.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  padding: 5px 9px; border-radius: 999px;
  background: #e9efe2; color: #46603a; border: 1px solid #d3e0c8;
  white-space: nowrap;
}

.ghost {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .6);
  color: var(--ink-2);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  transition: background .18s, border-color .18s, transform .18s;
}
.ghost:hover { background: #fff; border-color: #d6c9b6; }
.ghost.small { padding: 6px 10px; font-size: 12px; }

/* dropzone */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 26px 20px 22px;
  border: 2px dashed #d8c9b2;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .78), rgba(255, 252, 246, .52));
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset;
  transition: border-color .2s, background .2s, transform .2s, box-shadow .2s;
  cursor: pointer;
}
.dropzone:hover { border-color: #c9b294; background: rgba(255, 255, 255, .92); }
.dropzone:active { transform: scale(.997); }
.dropzone.is-over {
  border-color: var(--accent-2);
  background: #fff8ec;
  box-shadow: 0 0 0 6px rgba(176, 124, 63, .12);
}
.dropzone.is-over .drop-art { transform: translateY(-3px) scale(1.04); }

.drop-art { color: #b08a58; width: 56px; height: 56px; margin-bottom: 2px; transition: transform .2s; }
.drop-art svg { width: 100%; height: 100%; }
.drop-art .drop-plus { color: var(--accent); }

.dropzone h2 {
  font-family: var(--serif);
  font-size: 19px;
  margin: 4px 0 2px;
  letter-spacing: -.01em;
  text-wrap: balance;
}
.drop-sub {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-3);
  max-width: 30em;
  text-wrap: balance;
}
.drop-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.drop-formats { margin: 10px 0 0; font-size: 11px; color: #a89a87; letter-spacing: .04em; }

.primary {
  display: inline-flex; align-items: center; gap: 7px;
  background: linear-gradient(180deg, #9a6633, #83511f);
  color: #fff8ee;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .01em;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .22) inset, 0 6px 16px rgba(131, 81, 31, .24);
  transition: filter .18s, transform .18s;
}
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: translateY(1px); }
.primary svg { width: 18px; height: 18px; }
.primary.small { padding: 9px 14px; font-size: 13px; border-radius: 10px; }
.primary.full { width: 100%; justify-content: center; margin: 4px 0 10px; }

.secondary {
  border: 1px solid var(--line);
  background: #fffdf9;
  color: var(--ink-2);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  transition: background .18s, border-color .18s;
}
.secondary:hover { background: #fff; border-color: #d6c9b6; }

/* shelf */
.shelf-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 26px 2px 12px;
}
.shelf-head h2 {
  font-family: var(--serif); font-size: 17px; margin: 0; letter-spacing: -.01em;
  display: flex; align-items: center; gap: 8px;
}
.count { font-size: 12px; color: var(--ink-3); font-weight: 600; }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 16px 14px;
}

.book-card { position: relative; min-width: 0; }

.book-open {
  display: block; width: 100%; text-align: left; padding: 0;
  border-radius: 12px;
}

.book-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 8px 11px 11px 8px;
  overflow: hidden;
  background: linear-gradient(145deg, #e8dcc8, #d9c9ae);
  box-shadow: var(--shadow-sm), inset 6px 0 10px -8px rgba(60, 42, 24, .55);
  transform: translateZ(0);
  transition: transform .22s cubic-bezier(.22, .61, .36, 1), box-shadow .22s;
}
.book-cover::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, .16) 0, rgba(255, 255, 255, .10) 2.5%, rgba(255, 255, 255, 0) 7%);
  pointer-events: none;
}
.book-cover img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.cover-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 14px 12px;
  text-align: center;
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.5;
  color: #584635;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, .32) 0 2px, rgba(255, 255, 255, 0) 2px 7px),
    linear-gradient(160deg, #e3d3b8, #cbb795);
  word-break: keep-all;
  overflow: hidden;
}

.book-open:hover .book-cover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.book-progress {
  position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: rgba(0, 0, 0, .22);
}
.book-progress i { display: block; height: 100%; background: linear-gradient(90deg, #e2b779, #f3d9a9); }

.book-meta { padding: 7px 2px 0; min-width: 0; }
.book-meta strong {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12.5px; font-weight: 700; line-height: 1.35; letter-spacing: -.01em;
}
.book-meta span {
  display: block; margin-top: 2px;
  font-size: 11px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-meta em {
  display: block; margin-top: 3px;
  font-size: 10.5px; font-style: normal; color: #a2957f; letter-spacing: .01em;
}

.book-remove {
  position: absolute; top: 5px; right: 5px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: rgba(28, 22, 16, .55);
  color: #fff;
  font-size: 15px; line-height: 1;
  opacity: 0;
  transition: opacity .18s, background .18s;
  backdrop-filter: blur(3px);
}
.book-card:hover .book-remove, .book-card:focus-within .book-remove { opacity: 1; }
.book-remove:hover { background: var(--danger); }

.empty-shelf {
  margin: 8px 2px 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .5);
  font-size: 13px;
  color: var(--ink-3);
  text-align: center;
}
.empty-shelf p { margin: 0; }

.lib-foot {
  margin: 26px 2px 0;
  padding-top: 14px;
  border-top: 1px solid rgba(0, 0, 0, .06);
  font-size: 11px;
  line-height: 1.7;
  color: #a2957f;
}

/* ---------------------------------------------------------------- reader */

.reader {
  background: var(--r-bg);
  color: var(--r-ink);
  touch-action: manipulation;
}
.reader[data-theme="light"] {
  --r-bg: #fbf9f4; --r-ink: #221f1b; --r-muted: #7d7367;
  --r-line: rgba(34, 31, 27, .10); --r-bar: rgba(251, 249, 244, .93);
  --r-hover: rgba(34, 31, 27, .06); --r-sheet: #fffdf9; --r-sheet-line: #ece3d4;
}
.reader[data-theme="sepia"] {
  --r-bg: #f2e7cf; --r-ink: #463a2a; --r-muted: #7d6c53;
  --r-line: rgba(70, 58, 42, .14); --r-bar: rgba(243, 233, 210, .94);
  --r-hover: rgba(70, 58, 42, .07); --r-sheet: #fbf3e2; --r-sheet-line: #e3d3b4;
}
.reader[data-theme="dark"] {
  --r-bg: #14161a; --r-ink: #d9d5cd; --r-muted: #8d8b86;
  --r-line: rgba(217, 213, 205, .14); --r-bar: rgba(20, 22, 26, .94);
  --r-hover: rgba(217, 213, 205, .10); --r-sheet: #1c1f24; --r-sheet-line: #2e3238;
}

.reader-bar {
  position: absolute; left: 0; right: 0; z-index: 12;
  display: flex; align-items: center; gap: 10px;
  background: var(--r-bar);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  backdrop-filter: blur(14px) saturate(1.1);
  transition: transform .26s cubic-bezier(.22, .61, .36, 1), opacity .2s;
}

.reader-bar.top {
  top: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  border-bottom: 1px solid var(--r-line);
  min-height: 54px;
}
.reader-bar.bottom {
  bottom: 0;
  padding: 8px 10px calc(env(safe-area-inset-bottom, 0px) + 8px);
  border-top: 1px solid var(--r-line);
  min-height: 64px;
}

.reader.hide-chrome .reader-bar.top { transform: translateY(-102%); opacity: 0; pointer-events: none; }
.reader.hide-chrome .reader-bar.bottom { transform: translateY(102%); opacity: 0; pointer-events: none; }

.reader-title {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px;
  padding-left: 2px;
}
.reader-title strong {
  font-family: var(--serif);
  font-size: 14px; font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-title span {
  font-size: 11px; color: var(--r-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.reader-actions { display: flex; align-items: center; gap: 2px; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  color: var(--r-ink, var(--ink));
  transition: background .16s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--r-hover, rgba(0, 0, 0, .05)); }
.icon-btn.is-on { color: var(--accent-2); background: var(--r-hover); }

.chip {
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  color: var(--r-ink, var(--ink));
  border: 1px solid var(--r-line, var(--line));
  transition: background .16s;
}
.chip:hover { background: var(--r-hover); }
.chip .aa { font-size: 10px; margin-left: 1px; vertical-align: 1px; }

.stage {
  position: absolute; inset: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 62px) 16px calc(env(safe-area-inset-bottom, 0px) + 72px);
  display: flex;
  justify-content: center;
  min-height: 0;
}

.frame-wrap {
  position: relative;
  width: 100%;
  max-width: 720px;
  height: 100%;
  min-height: 0;
}
.reader.is-spread .frame-wrap { max-width: 1060px; }

.reader.is-spread .frame-wrap::after {
  content: "";
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 40px; transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.05) 42%, rgba(0,0,0,.10) 50%, rgba(0,0,0,.05) 58%, rgba(0,0,0,0) 100%);
  pointer-events: none;
}
.reader.is-spread[data-theme="dark"] .frame-wrap::after {
  background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.30) 42%, rgba(0,0,0,.45) 50%, rgba(0,0,0,.30) 58%, rgba(0,0,0,0) 100%);
}

#bookFrame {
  width: 100%; height: 100%;
  border: 0; display: block;
  background: transparent;
  border-radius: 2px;
}

.page-edge {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px; height: 40px;
  display: none;
  place-items: center;
  border-radius: 999px;
  color: var(--r-ink);
  background: var(--r-hover);
  opacity: .55;
  transition: opacity .18s, background .18s;
  z-index: 8;
}
.page-edge svg { width: 22px; height: 22px; }
.page-edge:hover { opacity: 1; }
.page-edge.prev { left: 8px; }
.page-edge.next { right: 8px; }
.page-edge:disabled { opacity: .12; pointer-events: none; }

.reader.is-spread .page-edge { display: grid; }

/* bottom bar */
.nav-btn {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  color: var(--r-ink);
  transition: background .16s, opacity .16s;
}
.nav-btn svg { width: 20px; height: 20px; }
.nav-btn:hover { background: var(--r-hover); }
.nav-btn:disabled { opacity: .3; }

.progress-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding: 0 2px; }

#progressSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  margin: 0;
  cursor: pointer;
}
#progressSlider::-webkit-slider-runnable-track {
  height: 5px; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2) var(--fill, 0%), rgba(128, 112, 92, .22) var(--fill, 0%));
}
#progressSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px; margin-top: -5px;
  border-radius: 999px;
  background: var(--accent-2);
  border: 2px solid var(--r-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .28);
}
#progressSlider::-moz-range-track { height: 4px; border-radius: 999px; background: rgba(128, 112, 92, .22); }
#progressSlider::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--accent-2); }
#progressSlider::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 999px; background: var(--accent-2);
  border: 2px solid var(--r-bg);
}

.status-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; color: var(--r-muted);
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
}
#rPercent { font-weight: 700; color: var(--r-ink); }
.status-hint { margin-left: auto; opacity: .8; }

/* loading */
.loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: var(--r-bg);
  z-index: 10;
  font-size: 12.5px; color: var(--r-muted);
}
.spinner {
  width: 26px; height: 26px;
  border-radius: 999px;
  border: 2px solid rgba(140, 90, 43, .2);
  border-top-color: var(--accent-2);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* selection menu */
.sel-menu {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex; gap: 2px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(32, 26, 20, .94);
  box-shadow: var(--shadow-md);
  z-index: 14;
}
.sel-menu button {
  color: #f5ebdc;
  font-size: 12px; font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
}
.sel-menu button:hover { background: rgba(255, 255, 255, .14); }

/* panels */
.scrim {
  position: absolute; inset: 0; z-index: 15;
  background: rgba(24, 18, 12, .30);
  opacity: 0; transition: opacity .24s;
}
.scrim.is-open { opacity: 1; }

.panel {
  position: absolute; z-index: 16;
  background: var(--r-sheet, var(--paper-2));
  color: var(--r-ink);
  box-shadow: 0 -12px 40px rgba(40, 28, 16, .18);
  display: flex; flex-direction: column;
  transition: transform .28s cubic-bezier(.22, .61, .36, 1), visibility 0s linear .28s;
  overscroll-behavior: contain;
  visibility: hidden;
}
.panel.is-open { visibility: visible; transition: transform .28s cubic-bezier(.22, .61, .36, 1), visibility 0s; }
.panel-left {
  top: 0; bottom: 0; left: 0;
  width: min(86vw, 330px);
  transform: translateX(-102%);
  border-right: 1px solid var(--r-sheet-line);
  padding-top: env(safe-area-inset-top, 0px);
}
.panel-left.is-open { transform: none; }.panel-bottom {
  left: 0; right: 0; bottom: 0;
  max-height: 78%;
  transform: translateY(103%);
  border-radius: 18px 18px 0 0;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  overflow: hidden;
}
.panel-bottom.is-open { transform: none; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px;
  flex: 0 0 auto;
}
.panel-head h2 {
  font-family: var(--serif);
  font-size: 15px; margin: 0; letter-spacing: -.01em;
}
.panel-head .icon-btn { width: 32px; height: 32px; }

.toc-list {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 4px 8px 24px;
}
.toc-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--r-ink);
  word-break: keep-all;
}
.toc-item:hover { background: var(--r-hover); }
.toc-item.is-current { background: var(--r-hover); font-weight: 700; color: var(--accent-2); }
.toc-item[data-level="2"] { font-size: 12.5px; color: var(--r-muted); }
.toc-item[data-level="3"] { font-size: 12px; color: var(--r-muted); }
.toc-empty { padding: 16px; font-size: 12.5px; color: var(--r-muted); }

.search-box { display: flex; gap: 8px; padding: 4px 16px 6px; flex: 0 0 auto; }
.search-box input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--r-sheet-line);
  background: rgba(255, 255, 255, .55);
  color: var(--r-ink);
}
.reader[data-theme="dark"] .search-box input { background: rgba(255, 255, 255, .06); }

.hint { margin: 6px 16px 10px; font-size: 11.5px; color: var(--r-muted); line-height: 1.5; }

.result-list, .mark-list {
  list-style: none; margin: 0; padding: 0 8px 16px;
  overflow-y: auto; flex: 1; min-height: 0;
}
.result-list li { margin-bottom: 2px; }
.result-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: 10px;
  font-size: 12.5px; line-height: 1.55;
  color: var(--r-ink);
  word-break: keep-all;
}
.result-item:hover { background: var(--r-hover); }
.result-item .result-title {
  display: block; font-weight: 700; font-size: 11.5px; color: var(--accent-2);
  margin-bottom: 2px;
}
.result-item mark { background: rgba(232, 185, 106, .55); color: inherit; border-radius: 2px; }
.result-empty { padding: 10px 12px; font-size: 12.5px; color: var(--r-muted); }

.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
}
.setting + .setting { border-top: 1px solid var(--r-sheet-line); }
.setting-label { font-size: 13px; font-weight: 600; }
.setting-label em { font-style: normal; font-weight: 400; font-size: 11px; color: var(--r-muted); margin-left: 4px; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  border-radius: 10px;
  background: var(--r-hover);
}
.segmented button {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--r-muted);
  transition: background .16s, color .16s, box-shadow .16s;
}
.segmented button:disabled { cursor: not-allowed; }
.segmented button.is-active {
  background: var(--r-sheet);
  color: var(--r-ink);
  box-shadow: 0 1px 3px rgba(40, 28, 16, .14);
}

.stepper {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--r-hover);
}
.stepper button {
  width: 34px; height: 28px;
  border-radius: 8px;
  font-size: 12px; font-weight: 700;
  color: var(--r-ink);
}
.stepper button:hover { background: var(--r-sheet); }
.stepper span {
  min-width: 30px; text-align: center;
  font-size: 12px; font-variant-numeric: tabular-nums;
}

.sub-head {
  font-size: 12px; margin: 12px 16px 4px; color: var(--r-muted);
  letter-spacing: .02em; font-weight: 700;
}
.mark-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
}
.mark-item:hover { background: var(--r-hover); }
.mark-main {
  flex: 1; min-width: 0; text-align: left;
  font-size: 12.5px; line-height: 1.45; color: var(--r-ink);
  word-break: keep-all;
}
.mark-main .mark-title { display: block; font-weight: 700; font-size: 11.5px; color: var(--accent-2); }
.mark-main .mark-snippet {
  display: block; color: var(--r-muted); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mark-del {
  width: 28px; height: 28px; flex: 0 0 28px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--r-muted);
}
.mark-del:hover { background: rgba(166, 58, 44, .12); color: var(--danger); }
.mark-empty { padding: 6px 12px 12px; font-size: 12px; color: var(--r-muted); }

/* toast + dialog + drop overlay */
.busy {
  position: fixed; inset: 0; z-index: 75;
  display: grid; place-items: center;
  background: rgba(247, 243, 236, .55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  padding: 22px;
}
.busy-card {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  border-radius: 14px;
  background: var(--paper-2);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--ink-2);
  max-width: 90vw;
}
.busy-card p { margin: 0; line-height: 1.4; }
.busy-card .spinner {
  width: 20px; height: 20px; flex: 0 0 20px;
  border-radius: 999px;
  border: 2px solid rgba(140, 90, 43, .18);
  border-top-color: var(--accent-2);
  animation: spin .8s linear infinite;
}

.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translate(-50%, 14px);
  max-width: min(90vw, 420px);
  padding: 11px 16px;
  border-radius: 12px;
  background: rgba(33, 27, 21, .94);
  color: #fdf6ea;
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  pointer-events: none;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.dialog {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
  background: rgba(26, 20, 14, .38);
  padding: 22px;
}
.dialog-card {
  width: min(100%, 340px);
  background: var(--paper-2);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow-md);
}
.dialog-card h2 { font-family: var(--serif); font-size: 16px; margin: 0 0 6px; }
.dialog-card p { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--ink-3); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.dialog-actions .ghost { padding: 9px 14px; }
.danger {
  background: var(--danger); color: #fff5f1;
  padding: 9px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 700;
}
.danger:hover { filter: brightness(1.06); }

.drop-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: rgba(38, 28, 18, .55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  padding: 24px;
}
.drop-overlay-inner {
  width: min(100%, 460px);
  padding: 40px 24px;
  border: 2px dashed rgba(255, 240, 216, .8);
  border-radius: 22px;
  text-align: center;
  color: #fff6e7;
}
.drop-overlay-inner strong { display: block; font-family: var(--serif); font-size: 20px; }
.drop-overlay-inner span { display: block; margin-top: 6px; font-size: 12.5px; opacity: .8; }

/* ------------------------------------------------------------ desktop tuning */

@media (min-width: 720px) {
  .lib-scroll { padding: 34px 34px 48px; max-width: 1080px; margin: 0 auto; width: 100%; }
  .lib-head { margin-bottom: 24px; }
  .brand-text h1 { font-size: 26px; }
  .brand-mark { width: 48px; height: 48px; flex-basis: 48px; }
  .brand-mark svg { width: 27px; height: 27px; }
  .dropzone { padding: 34px 28px 30px; }
  .dropzone h2 { font-size: 22px; }
  .drop-sub { font-size: 13.5px; }
  .drop-art { width: 64px; height: 64px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 20px 18px; }
  .book-meta strong { font-size: 13.5px; }
  .stage { padding-left: 32px; padding-right: 32px; }
  .reader-title strong { font-size: 15px; }
  .panel-bottom { left: 50%; right: auto; transform: translate(-50%, 103%); width: min(560px, calc(100% - 48px)); border-radius: 18px 18px 0 0; }
  .panel-bottom.is-open { transform: translate(-50%, 0); }
  .toast { bottom: 82px; }
}

@media (min-width: 1024px) {
  .chip { font-size: 12.5px; }
  .reader-bar.top { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 380px) {
  .brand-text p { display: none; }
  .offline-pill { display: none; }
  .dropzone { padding: 22px 14px 18px; }
  .dropzone h2 { font-size: 17px; }
  .drop-actions { width: 100%; }
  .drop-actions .primary, .drop-actions .secondary { flex: 1; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
