/* ===========================
   처음처럼 — Premium Book Reader
   =========================== */
@import url('https://fonts.googleapis.com/css2?family=Nanum+Myeongjo:wght@400;700;800&family=Noto+Serif+KR:wght@200;300;400;500;600;700;900&family=Nanum+Pen+Script&family=Nanum+Gothic:wght@400;700;800&family=Noto+Sans+KR:wght@300;400;500;700;900&family=Gamja+Flower&family=Gowun+Batang:wght@400;700&family=Gowun+Dodum&family=IBM+Plex+Sans+KR:wght@300;400;500;600;700&display=swap');

/* --- Variables --- */
:root {
  --bg-primary: #f7f3ed;
  --bg-secondary: #efe9e0;
  --bg-paper: #fdfbf7;
  --bg-accent: #e8e0d4;
  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-muted: #a8a29e;
  --accent: #9a7b4f;
  --accent-light: rgba(154,123,79,0.1);
  --border: #e7e0d5;
  --shadow: 0 1px 8px rgba(28,25,23,0.06);
  --font-serif: 'Noto Serif KR','Nanum Myeongjo',Georgia,serif;
  --font-display: 'Nanum Myeongjo','Noto Serif KR',serif;
  --font-handwrite: 'Nanum Pen Script',cursive;
  --font-ui: 'Noto Sans KR','Nanum Gothic',sans-serif;
  --font-size-base: 18px;
  --transition: 0.25s ease;
  --bar-bg: rgba(247,243,237,0.92);
  --bar-border: rgba(231,224,213,0.7);
  --overlay-bg: rgba(15,12,10,0.94);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg-primary: #171412;
  --bg-secondary: #1f1b17;
  --bg-paper: #221e1a;
  --bg-accent: #2e2822;
  --text-primary: #e7e0d5;
  --text-secondary: #b8ad9e;
  --text-muted: #78706a;
  --accent: #c4a06a;
  --accent-light: rgba(196,160,106,0.12);
  --border: #332d26;
  --shadow: 0 1px 8px rgba(0,0,0,0.3);
  --bar-bg: rgba(23,20,18,0.92);
  --bar-border: rgba(51,45,38,0.7);
}

/* Color themes */
[data-color="cool"]  { --bg-primary:#f0f3f8;--bg-secondary:#e4eaf2;--bg-paper:#f8fafc;--bg-accent:#d3dce8;--text-primary:#1e2a3a;--text-secondary:#4a5568;--text-muted:#a0aec0;--accent:#4a7ab5;--accent-light:rgba(74,122,181,0.08);--border:#d5dde8;--bar-bg:rgba(240,243,248,0.92);--bar-border:rgba(213,221,232,0.7); }
[data-color="green"] { --bg-primary:#f2f5f0;--bg-secondary:#e5ece2;--bg-paper:#f9fbf8;--bg-accent:#d3e2cf;--text-primary:#1e2e1a;--text-secondary:#4a5a40;--text-muted:#8a9a80;--accent:#5a8a3a;--accent-light:rgba(90,138,58,0.08);--border:#c8d8be;--bar-bg:rgba(242,245,240,0.92);--bar-border:rgba(200,216,190,0.7); }
[data-color="sepia"] { --bg-primary:#f0e8d4;--bg-secondary:#e6dcc4;--bg-paper:#f6f0e0;--bg-accent:#d4c4a0;--text-primary:#3a2e1e;--text-secondary:#5a4a34;--text-muted:#8a7a5a;--accent:#8a6a2a;--accent-light:rgba(138,106,42,0.08);--border:#c8b898;--bar-bg:rgba(240,232,212,0.92);--bar-border:rgba(200,184,152,0.7); }
[data-theme="dark"][data-color="cool"]  { --bg-primary:#10141a;--bg-secondary:#181e28;--bg-paper:#1c222e;--accent:#6aabe8;--accent-light:rgba(106,171,232,0.1);--border:#283040;--bar-bg:rgba(16,20,26,0.92);--bar-border:rgba(40,48,64,0.7); }
[data-theme="dark"][data-color="green"] { --bg-primary:#101810;--bg-secondary:#182018;--bg-paper:#1c261c;--accent:#6aaa4a;--accent-light:rgba(106,170,74,0.1);--border:#283828;--bar-bg:rgba(16,24,16,0.92);--bar-border:rgba(40,56,40,0.7); }
[data-theme="dark"][data-color="sepia"] { --bg-primary:#181410;--bg-secondary:#201a12;--bg-paper:#261e16;--accent:#c09030;--accent-light:rgba(192,144,48,0.1);--border:#382c1c;--bar-bg:rgba(24,20,16,0.92);--bar-border:rgba(56,44,28,0.7); }

/* Font families */
[data-font="myeongjo"]     { --font-serif:'Nanum Myeongjo',serif; --font-display:'Nanum Myeongjo',serif; }
[data-font="noto-serif"]   { --font-serif:'Noto Serif KR',serif; --font-display:'Noto Serif KR',serif; }
[data-font="gowun-batang"] { --font-serif:'Gowun Batang',serif; --font-display:'Gowun Batang',serif; }
[data-font="gothic"]       { --font-serif:'Nanum Gothic',sans-serif; --font-display:'Nanum Gothic',sans-serif; }
[data-font="noto-sans"]    { --font-serif:'Noto Sans KR',sans-serif; --font-display:'Noto Sans KR',sans-serif; }
[data-font="gowun-dodum"]  { --font-serif:'Gowun Dodum',sans-serif; --font-display:'Gowun Dodum',sans-serif; }
[data-font="gamja"]        { --font-serif:'Gamja Flower',cursive; --font-display:'Gamja Flower',cursive; }

/* --- Reset --- */
*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }
html { -webkit-text-size-adjust:none; text-size-adjust:none; }
body {
  font-family: var(--font-serif);
  font-size: var(--font-size-base);
  line-height: 1.85;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  height: 100vh; height: 100dvh;
  word-break: keep-all;
  overflow-wrap: break-word;
  transition: background var(--transition), color var(--transition);
}

/* ============================
   Book Container
   ============================ */
.book {
  position: fixed;
  inset: 0;
  background: var(--bg-paper);
  overflow: hidden;
}
.book-page-layer {
  position: absolute;
  inset: 0;
  padding: 56px 28px 72px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
  backface-visibility: hidden;
}
.book-page-layer.active { opacity: 1; pointer-events: auto; }

/* Touch zones */
.tap-left, .tap-center, .tap-right {
  position: absolute; top: 0; bottom: 0; z-index: 5;
  -webkit-tap-highlight-color: transparent;
}
.tap-left   { left: 0; width: 30%; pointer-events: none; }
.tap-center { left: 30%; width: 40%; pointer-events: none; }
.tap-right  { right: 0; width: 30%; pointer-events: none; }

/* Page shadow */
.page-shadow {
  position: absolute; inset: 0; pointer-events: none; z-index: 10;
  opacity: 0; transition: opacity 0.3s ease;
}
.page-shadow.show-fwd { opacity: 1; background: linear-gradient(to left, transparent 65%, rgba(0,0,0,0.04) 100%); }
.page-shadow.show-bwd { opacity: 1; background: linear-gradient(to right, transparent 65%, rgba(0,0,0,0.04) 100%); }

/* ============================
   Page Flip Animations
   ============================ */
@keyframes flip3dOutFwd  { 0%{transform:perspective(1800px) rotateY(0);opacity:1} 100%{transform:perspective(1800px) rotateY(-105deg);opacity:0} }
@keyframes flip3dInFwd   { 0%{transform:perspective(1800px) rotateY(75deg);opacity:0} 50%{opacity:1} 100%{transform:perspective(1800px) rotateY(0);opacity:1} }
@keyframes flip3dOutBwd  { 0%{transform:perspective(1800px) rotateY(0);opacity:1} 100%{transform:perspective(1800px) rotateY(105deg);opacity:0} }
@keyframes flip3dInBwd   { 0%{transform:perspective(1800px) rotateY(-75deg);opacity:0} 50%{opacity:1} 100%{transform:perspective(1800px) rotateY(0);opacity:1} }
@keyframes slideOutFwd   { 0%{transform:translateX(0);opacity:1} 100%{transform:translateX(-100%);opacity:.3} }
@keyframes slideInFwd    { 0%{transform:translateX(100%);opacity:.3} 100%{transform:translateX(0);opacity:1} }
@keyframes slideOutBwd   { 0%{transform:translateX(0);opacity:1} 100%{transform:translateX(100%);opacity:.3} }
@keyframes slideInBwd    { 0%{transform:translateX(-100%);opacity:.3} 100%{transform:translateX(0);opacity:1} }
@keyframes fadeOut       { 0%{opacity:1} 100%{opacity:0} }
@keyframes fadeIn        { 0%{opacity:0} 100%{opacity:1} }

.book-page-layer.flip3d-out-fwd  { animation:flip3dOutFwd .5s cubic-bezier(.4,.0,.2,1) forwards; transform-origin:left center; pointer-events:none; }
.book-page-layer.flip3d-in-fwd   { animation:flip3dInFwd  .5s cubic-bezier(.4,.0,.2,1) forwards; transform-origin:right center; }
.book-page-layer.flip3d-out-bwd  { animation:flip3dOutBwd .5s cubic-bezier(.4,.0,.2,1) forwards; transform-origin:right center; pointer-events:none; }
.book-page-layer.flip3d-in-bwd   { animation:flip3dInBwd  .5s cubic-bezier(.4,.0,.2,1) forwards; transform-origin:left center; }
.book-page-layer.slide-out-fwd   { animation:slideOutFwd .3s ease-in-out forwards; pointer-events:none; }
.book-page-layer.slide-in-fwd    { animation:slideInFwd  .3s ease-in-out forwards; }
.book-page-layer.slide-out-bwd   { animation:slideOutBwd .3s ease-in-out forwards; pointer-events:none; }
.book-page-layer.slide-in-bwd    { animation:slideInBwd  .3s ease-in-out forwards; }
.book-page-layer.fade-out-fwd,
.book-page-layer.fade-out-bwd    { animation:fadeOut .25s ease forwards; pointer-events:none; }
.book-page-layer.fade-in-fwd,
.book-page-layer.fade-in-bwd     { animation:fadeIn .25s ease forwards; }

/* ============================
   Top Bar
   ============================ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 50; height: 48px;
  background: var(--bar-bg);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--bar-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px;
  padding-top: env(safe-area-inset-top, 0px);
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.topbar.hidden { transform: translateY(-100%); opacity: 0; pointer-events: none; }

.tb-left, .tb-right { display: flex; align-items: center; gap: 2px; }

.tb-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}
.tb-btn:hover { background: var(--accent-light); color: var(--text-primary); }
.tb-btn:active { background: var(--accent-light); transform: scale(0.95); }
.tb-btn svg { flex-shrink: 0; }

/* ============================
   Bottom Bar
   ============================ */
.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 50; height: 56px;
  background: var(--bar-bg);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--bar-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.bottombar.hidden { transform: translateY(100%); opacity: 0; pointer-events: none; }

.bb-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.bb-btn:hover { background: var(--accent-light); color: var(--text-primary); }
.bb-btn:active { transform: scale(0.97); }
.bb-btn:disabled { opacity: 0.25; pointer-events: none; }
.bb-btn svg { flex-shrink: 0; }

.bb-page {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.5px;
}

/* ============================
   Cover Page
   ============================ */
.cover-page {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  min-height: 100%; padding: 40px 24px;
}
.cover-ornament {
  color: var(--accent);
  font-size: 14px; letter-spacing: 16px;
  margin-bottom: 32px; opacity: 0.4;
}
.cover-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.4em;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 8px;
  letter-spacing: 8px;
}
.cover-subtitle {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 40px;
  letter-spacing: 8px;
  font-weight: 400;
}
.cover-author {
  font-family: var(--font-handwrite);
  font-size: 1.6em;
  color: var(--accent);
  margin-bottom: 4px;
}
.cover-role {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 3px;
  margin-bottom: 40px;
  font-weight: 400;
}
.cover-stats {
  display: flex; justify-content: center; gap: 40px;
  margin-bottom: 40px; flex-wrap: wrap;
}
.cover-stat { text-align: center; }
.cover-stat-number {
  font-family: var(--font-display);
  font-size: 1.1em; font-weight: 700;
  color: var(--accent);
  display: block; margin-bottom: 4px;
}
.cover-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 1px;
}
.cover-hint {
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-muted);
  opacity: 0.5;
  animation: hintPulse 3s ease-in-out infinite;
}
@keyframes hintPulse { 0%,100%{opacity:.3} 50%{opacity:.7} }
.cover-version {
  font-size: 10px; color: var(--text-muted);
  margin-top: 20px; opacity: 0.3;
}
.cover-page::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 30% 40%, rgba(154,123,79,0.04) 0%, transparent 60%);
}

@media (max-height: 700px) {
  .cover-page { justify-content: flex-start; padding-top: 16px; }
  .cover-ornament { margin-bottom: 16px; }
  .cover-title { font-size: 1.8em; }
  .cover-subtitle { margin-bottom: 24px; }
  .cover-stats { gap: 20px; margin-bottom: 24px; }
  .cover-role { margin-bottom: 24px; }
}

/* ============================
   Author Page
   ============================ */
.author-page {
  max-width: 600px; margin: 0 auto; padding: 32px 0;
}
.author-page h2 {
  font-family: var(--font-display);
  font-size: 1.2em; font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 28px;
  letter-spacing: 4px;
}
.author-bio {
  color: var(--text-secondary);
  line-height: 2;
  font-size: 0.95em;
}
.author-bio p { margin-bottom: 12px; text-indent: 1em; }
.author-highlights {
  display: grid; grid-template-columns: repeat(2,1fr);
  gap: 12px; margin-top: 28px;
}
.highlight-item {
  text-align: center; padding: 16px 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.highlight-icon { font-size: 1.2em; margin-bottom: 4px; opacity: 0.7; }
.highlight-text { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.highlight-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ============================
   TOC Page (Inline)
   ============================ */
.toc-page { max-width: 600px; margin: 0 auto; padding: 12px 0; }
.toc-page-title {
  font-family: var(--font-display);
  font-size: 1.2em; font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: 8px;
}
.toc-page-hint {
  text-align: center; font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.toc-back-btn {
  display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 12px; padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: var(--font-ui); font-size: 13px; font-weight: 500;
  cursor: pointer; position: relative; z-index: 20;
  transition: all var(--transition);
}
.toc-back-btn:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }

.toc-year-row {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  position: relative; z-index: 15;
  transition: background var(--transition);
}
.toc-year-row:hover { background: var(--accent-light); }
.toc-year-row:active { background: var(--bg-accent); }
.toc-year-name {
  font-family: var(--font-display);
  font-size: 15px; font-weight: 700;
  color: var(--text-primary);
}
.toc-year-dots {
  flex: 1;
  border-bottom: 1px dotted var(--border);
  margin: 0 8px; min-width: 20px;
}
.toc-year-info {
  font-size: 13px; color: var(--accent);
  font-weight: 500; white-space: nowrap;
}
.toc-year-arrow {
  font-size: 11px; color: var(--text-muted);
  margin-left: 4px; transition: transform 0.2s;
}

.toc-year-detail .toc-year-list { margin-top: 8px; }
.toc-page-summary { padding: 0 8px; }

.toc-acc-list { padding: 0 4px 8px 12px; }
.toc-acc-item {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 8px;
  cursor: pointer; border-radius: var(--radius-sm);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 15;
  transition: background var(--transition);
}
.toc-acc-item:last-child { border-bottom: none; }
.toc-acc-item:hover { background: var(--accent-light); }
.toc-acc-date { font-size: 12px; color: var(--text-muted); min-width: 36px; flex-shrink: 0; }
.toc-acc-title { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.toc-page-total {
  text-align: center; margin-top: 24px;
  font-size: 12px; color: var(--text-muted);
  letter-spacing: 1px;
}

/* ============================
   Post Content
   ============================ */
.post-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.post-date {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}
.post-title {
  font-family: var(--font-display);
  font-size: 1.3em;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.5;
}

.post-text-page {
  max-width: 640px; margin: 0 auto;
  color: var(--text-secondary);
  line-height: 2;
  padding: 8px 0;
}
.post-text-page p { margin-bottom: 1.2em; }

.post-image-page {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 80vh; padding: 12px 0; gap: 8px;
}
.post-image-page img {
  max-width: 100%; max-height: calc(100vh - 120px);
  object-fit: contain; border-radius: var(--radius-sm);
  box-shadow: 0 2px 16px rgba(0,0,0,0.08);
}
[data-img-size="large"] .post-image-page img { max-height: calc(100vh - 80px); }
[data-img-size="small"] .post-image-page img { max-width: 60%; }
[data-img-size="off"]   .post-image-page { display: none !important; }

/* End page */
.post-end-page {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 100%;
}
.end-flowers { display: flex; gap: 16px; }
.end-flower { width: 24px; height: 24px; opacity: 0.3; }
.end-flower svg { width: 100%; height: 100%; fill: var(--accent); }

/* ============================
   Overlay Base
   ============================ */
.toc-overlay, .search-overlay, .timeline-overlay, .category-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--overlay-bg);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
  display: flex; flex-direction: column;
}
.toc-overlay.open, .search-overlay.open,
.timeline-overlay.open, .category-overlay.open {
  opacity: 1; pointer-events: auto;
}

/* Overlay panels */
.toc-panel, .search-panel, .timeline-panel, .category-panel {
  width: 100%; max-width: 480px; margin: 0 auto;
  display: flex; flex-direction: column; height: 100%;
  color: rgba(255,255,255,0.9);
}

/* Overlay headers */
.toc-header, .search-header, .timeline-header, .category-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; flex-shrink: 0;
}
.toc-header h3, .timeline-header h3, .category-header h3 {
  font-family: var(--font-ui);
  font-size: 15px; font-weight: 600;
  letter-spacing: 1px;
}

/* Close buttons */
.toc-close, .search-close, .timeline-close, .category-close {
  background: none; border: none;
  color: rgba(255,255,255,0.5);
  font-size: 13px; cursor: pointer;
  font-family: var(--font-ui);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
}
.toc-close:hover, .search-close:hover,
.timeline-close:hover, .category-close:hover {
  color: rgba(255,255,255,0.9);
}

/* ============================
   TOC Overlay
   ============================ */
.toc-book-info { text-align: center; padding: 12px 20px 12px; }
.toc-book-title {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 700; margin-bottom: 2px;
}
.toc-book-author {
  font-size: 13px; color: rgba(255,255,255,0.45);
}

.toc-category-btn-wrap { padding: 0 20px 10px; }
.toc-category-btn {
  width: 100%; padding: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.6);
  font-family: var(--font-ui); font-size: 13px;
  cursor: pointer; transition: all var(--transition);
}
.toc-category-btn:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.8); }

.toc-search-wrap { padding: 0 20px 10px; }
.toc-search-input {
  width: 100%; padding: 8px 14px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05);
  color: #fff;
  font-family: var(--font-ui); font-size: 14px; outline: none;
  transition: border-color var(--transition);
}
.toc-search-input::placeholder { color: rgba(255,255,255,0.3); }
.toc-search-input:focus { border-color: rgba(255,255,255,0.3); }

.toc-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 0 20px;
}
.toc-year-group { margin-bottom: 2px; }
.toc-year-header {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; padding: 10px 20px;
  transition: background 0.2s;
}
.toc-year-header:hover { background: rgba(255,255,255,0.04); }
.toc-year-label {
  font-family: var(--font-ui);
  font-weight: 600; font-size: 14px;
  color: var(--accent); min-width: 50px;
}
.toc-year-count {
  font-size: 11px; color: rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.06);
  padding: 2px 7px; border-radius: 10px;
}
.toc-year-toggle {
  margin-left: auto; color: rgba(255,255,255,0.3);
  font-size: 10px; transition: transform var(--transition);
}
.toc-year-group.open .toc-year-toggle { transform: rotate(180deg); }
.toc-post-list { list-style: none; display: none; padding: 0 8px; }
.toc-year-group.open .toc-post-list { display: block; }
.toc-post-item {
  padding: 9px 20px; cursor: pointer;
  display: flex; align-items: baseline; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background 0.15s;
}
.toc-post-item:hover { background: rgba(255,255,255,0.05); }
.toc-post-item.current { background: rgba(154,123,79,0.15); border-left: 2px solid var(--accent); }
.toc-post-date { font-size: 12px; color: rgba(255,255,255,0.3); min-width: 38px; flex-shrink: 0; }
.toc-post-title { color: rgba(255,255,255,0.75); font-size: 14px; line-height: 1.5; }
.toc-post-item:hover .toc-post-title { color: rgba(255,255,255,0.95); }

/* ============================
   Search Overlay
   ============================ */
.search-header { gap: 10px; }
.search-input {
  flex: 1; padding: 8px 14px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05);
  color: #fff;
  font-family: var(--font-ui); font-size: 14px; outline: none;
  transition: border-color var(--transition);
}
.search-input::placeholder { color: rgba(255,255,255,0.3); }
.search-input:focus { border-color: rgba(255,255,255,0.3); }

.search-tabs {
  display: flex; gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.search-tab {
  flex: 1; padding: 8px 0;
  background: none; border: none;
  color: rgba(255,255,255,0.35);
  font-family: var(--font-ui); font-size: 13px;
  cursor: pointer; transition: all 0.2s;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.search-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.search-ai-hint {
  padding: 6px 20px;
  font-size: 12px; color: rgba(255,255,255,0.3);
  line-height: 1.5; flex-shrink: 0;
}

.search-results {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 20px 20px;
}
.search-result-item {
  padding: 12px 0; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  transition: background 0.15s;
}
.search-result-item:hover { background: rgba(255,255,255,0.04); }
.search-result-date { font-size: 11px; color: rgba(255,255,255,0.3); margin-bottom: 3px; }
.search-result-title { font-size: 14px; color: rgba(255,255,255,0.8); line-height: 1.5; }
.search-result-snippet { font-size: 12px; color: rgba(255,255,255,0.4); margin-top: 3px; line-height: 1.4; }
.search-result-snippet mark { color: var(--accent); background: none; font-weight: 600; }

/* ============================
   Settings Sheet
   ============================ */
.settings-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.25);
  z-index: 300; opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.settings-backdrop.open { opacity: 1; pointer-events: auto; }

.settings-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 310;
  background: var(--bg-paper);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -2px 24px rgba(0,0,0,0.12);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  padding: 0 20px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 65vh;
  overflow-y: auto;
}
.settings-sheet.open { transform: translateY(0); }

.settings-handle {
  display: flex; justify-content: center; padding: 10px 0 6px;
  cursor: pointer;
}
.handle-bar {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--border);
}

.ss-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.ss-row:last-of-type { border-bottom: none; }
.ss-label {
  font-family: var(--font-ui);
  font-size: 14px; font-weight: 500;
  color: var(--text-secondary);
  min-width: 60px;
}
.ss-value {
  font-family: var(--font-ui);
  font-size: 15px; font-weight: 600;
  color: var(--accent);
  min-width: 28px; text-align: center;
}
.ss-icon { font-size: 18px; }

/* Color dots */
.ss-colors { justify-content: center; gap: 14px; padding: 14px 0; }
.ss-color-dot {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: all 0.2s;
}
.ss-color-dot.warm  { background: linear-gradient(135deg,#f7f3ed,#e8e0d4); }
.ss-color-dot.cool  { background: linear-gradient(135deg,#f0f3f8,#d3dce8); }
.ss-color-dot.green { background: linear-gradient(135deg,#f2f5f0,#d3e2cf); }
.ss-color-dot.sepia { background: linear-gradient(135deg,#f0e8d4,#d4c4a0); }
.ss-color-dot.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

/* Toggle group */
.ss-toggle-group { display: flex; gap: 4px; flex: 1; }
.ss-toggle {
  flex: 1; padding: 6px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 13px; cursor: pointer;
  transition: all 0.2s; text-align: center;
}
.ss-toggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* +/- buttons */
.ss-pm { display: flex; gap: 6px; margin-left: auto; }
.ss-pm-btn {
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 18px; font-weight: 500;
  cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.ss-pm-btn:hover { border-color: var(--accent); color: var(--accent); }
.ss-pm-btn:active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Select */
.ss-select {
  flex: 1; padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px; cursor: pointer; outline: none;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23a8a29e'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.ss-version {
  text-align: center; padding: 12px 0 4px;
  font-family: var(--font-ui);
  font-size: 11px; color: var(--text-muted); opacity: 0.4;
}

/* ============================
   Timeline Overlay
   ============================ */
.timeline-chart-wrap {
  padding: 0 16px 8px;
  flex-shrink: 0;
  max-height: 200px;
}
.timeline-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 20px 20px;
}
.timeline-year-title {
  font-family: var(--font-ui);
  font-size: 14px; font-weight: 600;
  color: var(--accent);
  padding: 10px 0 6px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 2px;
}
.timeline-post-item {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 4px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background 0.15s;
}
.timeline-post-item:hover { background: rgba(255,255,255,0.05); }
.timeline-post-date { font-size: 11px; color: rgba(255,255,255,0.3); min-width: 36px; flex-shrink: 0; }
.timeline-post-title { font-size: 13px; color: rgba(255,255,255,0.75); line-height: 1.5; }
.timeline-post-item:hover .timeline-post-title { color: rgba(255,255,255,0.95); }
.timeline-selected-year {
  text-align: center; padding: 4px 0;
  font-size: 12px; color: rgba(255,255,255,0.4);
  flex-shrink: 0;
}

/* ============================
   Category Overlay
   ============================ */
.category-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px 20px 14px; flex-shrink: 0;
}
.category-chip {
  padding: 6px 14px; border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.6);
  font-family: var(--font-ui); font-size: 13px;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.category-chip:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.8); }
.category-chip.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent); font-weight: 500;
}
.category-results {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 20px 20px;
}
.category-result-item {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 4px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  transition: background 0.15s;
}
.category-result-item:hover { background: rgba(255,255,255,0.05); }
.category-result-date { font-size: 11px; color: rgba(255,255,255,0.3); min-width: 38px; flex-shrink: 0; }
.category-result-title { font-size: 14px; color: rgba(255,255,255,0.75); line-height: 1.5; }
.category-result-item:hover .category-result-title { color: rgba(255,255,255,0.95); }
.category-empty {
  text-align: center; padding: 36px 0;
  color: rgba(255,255,255,0.3); font-size: 13px;
}

/* ============================
   TTS
   ============================ */
.tts-listen-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 10px;
  padding: 8px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: var(--font-ui); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.2s;
  position: relative; z-index: 20;
}
.tts-listen-btn:hover { border-color: var(--accent); color: var(--accent); }
.tts-listen-btn.playing {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

.tts-player {
  position: fixed;
  bottom: 68px; left: 50%; transform: translateX(-50%);
  z-index: 90;
  display: flex; align-items: center; gap: 10px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-family: var(--font-ui); font-size: 13px;
  box-shadow: 0 2px 16px rgba(154,123,79,0.35);
  white-space: nowrap;
}
.tts-stop-btn {
  background: rgba(255,255,255,0.2); border: none;
  color: #fff; border-radius: 12px;
  padding: 3px 10px; font-size: 12px;
  cursor: pointer; font-family: var(--font-ui);
  transition: background 0.2s;
}
.tts-stop-btn:hover { background: rgba(255,255,255,0.35); }
.tts-progress {
  font-size: 12px; opacity: 0.9;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}

/* ============================
   Misc
   ============================ */
.new-post-bell {
  position: fixed; top: 16px; right: 16px;
  z-index: 100;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-family: var(--font-ui);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(154,123,79,0.3);
  animation: bellFloat 2s ease-in-out infinite;
}
@keyframes bellFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.book-pagenum {
  position: fixed;
  bottom: 8px; left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.3;
  pointer-events: none;
  transition: opacity 0.3s;
  letter-spacing: 0.5px;
}
.bottombar:not(.hidden) ~ .book-pagenum { opacity: 0; }

.loading-spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Season background */
.season-bg {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  opacity: 0; transition: opacity 1s ease;
}
.season-bg.visible { opacity: 1; }
.season-bg.spring { background: radial-gradient(ellipse at 50% 0%, rgba(255,182,193,0.06) 0%, transparent 60%); }
.season-bg.summer { background: radial-gradient(ellipse at 50% 0%, rgba(100,180,100,0.05) 0%, transparent 60%); }
.season-bg.autumn { background: radial-gradient(ellipse at 50% 0%, rgba(210,140,50,0.06) 0%, transparent 60%); }
.season-bg.winter { background: radial-gradient(ellipse at 50% 0%, rgba(160,190,220,0.05) 0%, transparent 60%); }

/* ============================
   Mobile
   ============================ */
@media (max-width: 480px) {
  .book-page-layer { padding: 50px 20px 64px; }
  .topbar { height: 44px; padding: 0 4px; }
  .tb-btn { width: 36px; height: 36px; }
  .tb-btn svg { width: 18px; height: 18px; }
  .bottombar { height: 50px; padding: 0 8px; }
  .bb-btn { padding: 6px 10px; font-size: 13px; gap: 4px; }
  .bb-btn svg { width: 14px; height: 14px; }
  .bb-page { font-size: 12px; }
  .cover-title { font-size: 2em; letter-spacing: 4px; }
  .cover-author { font-size: 1.4em; }
  .cover-stats { gap: 24px; }
}

@media (hover: none) and (pointer: coarse) {
  .bb-btn:active { transform: scale(0.95); }
  .tb-btn:active { transform: scale(0.92); }
}

@media print {
  .topbar, .bottombar, .tts-player, .settings-sheet,
  .settings-backdrop, .toc-overlay, .search-overlay,
  .timeline-overlay, .category-overlay, .new-post-bell {
    display: none !important;
  }
  .book { position: static; }
  .book-page-layer { position: static; opacity: 1; overflow: visible; }
}
