:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1c1b19;
  --ink-soft: #5c574e;
  --line: #e6e2d8;
  --accent: #b4541a;
  --accent-soft: #f3e6d8;
  --shadow: 0 1px 2px rgba(28, 27, 25, 0.06), 0 8px 24px rgba(28, 27, 25, 0.08);
  --radius: 14px;
  --maxw: 1180px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"],
body.dark {
  --bg: #14131a;
  --surface: #1d1c25;
  --surface-2: #232230;
  --ink: #ece9f1;
  --ink-soft: #a8a3b8;
  --line: #322f3d;
  --accent: #f3a857;
  --accent-soft: #2a2233;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(16px, 4vw, 32px); }
.hidden { display: none !important; }

/* ----------------------------------------------------------------- header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; }
.brand-mark { font-size: 22px; }
.brand-text { font-size: 18px; letter-spacing: -0.01em; }
.header-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
  min-width: min(46vw, 320px);
}
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--ink-soft); stroke-width: 2; stroke-linecap: round; }
.search input { border: 0; background: transparent; outline: none; color: var(--ink); font-size: 15px; width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}
.icon-btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.icon-btn:active { transform: translateY(0); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ----------------------------------------------------------------- hero */
.hero { padding: clamp(28px, 6vw, 56px) 0 18px; max-width: 640px; }
.hero h1 { font-family: var(--serif); font-size: clamp(30px, 6vw, 46px); line-height: 1.05; margin: 0 0 10px; letter-spacing: -0.02em; }
.hero p { margin: 0; color: var(--ink-soft); font-size: clamp(15px, 2.4vw, 18px); }

/* ----------------------------------------------------------------- rows / grid */
.row-title { font-family: var(--serif); font-size: 22px; margin: 30px 0 14px; letter-spacing: -0.01em; }
.resume { margin-top: 18px; }
.cover-row { display: flex; gap: 18px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; }
.cover-row > * { scroll-snap-align: start; flex: 0 0 auto; width: 150px; }

.collection { margin-top: 30px; }
.collection-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.collection-head h2 { font-family: var(--serif); font-size: clamp(20px, 3.2vw, 26px); margin: 0; letter-spacing: -0.01em; }
.collection-head .count { color: var(--ink-soft); font-size: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: clamp(16px, 3vw, 26px);
}

/* ----------------------------------------------------------------- book card */
.book { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; }
.book .cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.book .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book:hover .cover { transform: translateY(-4px); box-shadow: 0 14px 34px rgba(28,27,25,0.18); }
.book .cover::after {
  content: "Read";
  position: absolute;
  inset: auto 0 0 0;
  padding: 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  opacity: 0;
  transition: opacity 0.18s ease;
}
.book:hover .cover::after { opacity: 1; }
.book .meta { display: flex; flex-direction: column; gap: 2px; }
.book .title { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .author { color: var(--ink-soft); font-size: 12.5px; }
.book .pill { align-self: flex-start; margin-top: 2px; font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; }

.loading, .empty { color: var(--ink-soft); padding: 40px 0; text-align: center; }

/* ----------------------------------------------------------------- footer */
.site-footer { margin-top: 56px; border-top: 1px solid var(--line); padding: 22px 0; color: var(--ink-soft); font-size: 14px; }

/* =================================================================== READER */
.reader-page { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; background: var(--bg); }

.reader-page[data-theme="light"] { --bg: #f6f5f1; --ink: #1c1b19; --surface: #fff; --line: #e6e2d8; }
.reader-page[data-theme="sepia"] { --bg: #f3e9d6; --ink: #4a3c28; --surface: #f7efe0; --line: #e1d4ba; }
.reader-page[data-theme="dark"] { --bg: #14131a; --ink: #ece9f1; --surface: #1d1c25; --line: #322f3d; }

.reader-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px clamp(10px, 3vw, 18px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  z-index: 30;
}
.reader-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-family: var(--serif);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}

.viewer-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: stretch; }
.viewer { flex: 1; min-width: 0; height: 100%; }

.page-arrow {
  flex: 0 0 auto;
  width: clamp(40px, 7vw, 72px);
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.15s ease, background 0.15s ease;
}
.page-arrow:hover { color: var(--accent); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.page-arrow svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#progress-bar { height: 4px; background: var(--line); }
#progress-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s ease; }

.reader-loading {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); color: var(--ink-soft); font-size: 16px; z-index: 40;
}
.reader-loading.hidden { display: none; }

/* TOC drawer */
.toc {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(86vw, 340px);
  background: var(--surface); border-right: 1px solid var(--line);
  transform: translateX(-100%); transition: transform 0.25s ease; z-index: 60;
  display: flex; flex-direction: column;
}
.toc.open { transform: translateX(0); }
.toc-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); font-family: var(--serif); font-size: 17px; }
.toc-list { overflow-y: auto; padding: 8px; }
.toc-list a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 14px; line-height: 1.35; }
.toc-list a:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.toc-list a.depth-1 { padding-left: 26px; color: var(--ink-soft); font-size: 13px; }
.toc-list a.active { color: var(--accent); font-weight: 700; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50; }

@media (max-width: 640px) {
  .search { min-width: 0; flex: 1; }
  .brand-text { display: none; }
  .page-arrow { position: absolute; top: 0; bottom: 0; z-index: 10; background: transparent; }
  .page-arrow.left { left: 0; } .page-arrow.right { right: 0; }
}
