/* ============================================================
   EASTAR e-Book — 공통 스타일
   ============================================================ */
:root {
  --eastar-red: #e3002b;
  --eastar-red-dark: #b3001f;
  --bg: #0f1420;
  --bg-soft: #161d2b;
  --panel: #1c2434;
  --line: rgba(255, 255, 255, .08);
  --text: #eef1f6;
  --muted: #9aa6b8;
  --shadow: 0 24px 60px rgba(0, 0, 0, .55);
  --radius: 14px;
  --font: "Pretendard", -apple-system, "맑은 고딕", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(227, 0, 43, .14), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(40, 90, 200, .12), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { display: block; }

/* ---------- 상단 브랜드 바 (공통) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  height: 60px; padding: 0 20px;
  background: rgba(15, 20, 32, .78);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: .2px; }
.brand .logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--eastar-red); color: #fff; font-weight: 900; font-size: 15px;
}
.brand .sub { color: var(--muted); font-weight: 600; font-size: 13px; }
.topbar .spacer { flex: 1; }

/* 버튼 공통 */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(255, 255, 255, .07); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 13px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .1s, border-color .15s;
  font-family: var(--font);
}
.btn:hover { background: rgba(255, 255, 255, .14); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--eastar-red); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--eastar-red-dark); }

/* ============================================================
   서재(라이브러리) 메인
   ============================================================ */
.hero {
  max-width: 1100px; margin: 0 auto; padding: 46px 20px 18px;
}
.hero h1 { font-size: 34px; margin: 0 0 8px; font-weight: 800; letter-spacing: -.5px; }
.hero p { color: var(--muted); margin: 0; font-size: 15px; line-height: 1.6; }

.toolbar {
  max-width: 1100px; margin: 22px auto 0; padding: 0 20px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
}
.search {
  flex: 1; min-width: 220px;
  display: flex; align-items: center; gap: 9px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 14px;
}
.search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 15px; font-family: var(--font);
}
.search input::placeholder { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  background: rgba(255, 255, 255, .06); border: 1px solid var(--line);
  color: var(--muted); font-size: 13px; font-weight: 600; transition: .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--eastar-red); color: #fff; border-color: transparent; }

/* 책장 그리드 */
.shelf {
  max-width: 1100px; margin: 26px auto 70px; padding: 0 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 26px 22px;
}
.book-card { cursor: pointer; transition: transform .18s; }
.book-card:hover { transform: translateY(-6px); }
.book-card .cover-wrap {
  position: relative; aspect-ratio: 1 / 1.414; border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow); background: var(--panel);
  border: 1px solid var(--line);
}
.book-card .cover-wrap img { width: 100%; height: 100%; object-fit: cover; }
.book-card .cover-wrap::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px;
  background: linear-gradient(90deg, rgba(0, 0, 0, .35), transparent);
}
.book-card .badge {
  position: absolute; top: 10px; left: 10px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; font-weight: 700;
  padding: 4px 9px; border-radius: 6px; backdrop-filter: blur(4px);
}
.book-card .badge-type {
  left: auto; right: 10px;
  background: var(--eastar-red); color: #fff; letter-spacing: .5px;
}
.book-card h3 { margin: 12px 2px 3px; font-size: 15px; font-weight: 700; line-height: 1.35; }
.book-card .meta { margin: 0 2px; color: var(--muted); font-size: 12.5px; }

.empty-state {
  max-width: 560px; margin: 60px auto; text-align: center; color: var(--muted);
  line-height: 1.8; font-size: 15px;
}
.empty-state h2 { color: var(--text); }
.empty-state code { color: var(--text); background: rgba(255, 255, 255, .08); padding: 2px 7px; border-radius: 5px; }

footer.site {
  max-width: 1100px; margin: 0 auto; padding: 26px 20px 50px;
  color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line);
}

/* ============================================================
   뷰어 (viewer.html)
   ============================================================ */
body.viewer { overflow: hidden; height: 100vh; }
.viewer-wrap { display: flex; flex-direction: column; height: 100vh; }

.v-top { gap: 12px; }
.v-top .title { font-weight: 700; font-size: 15px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 40px; height: 40px; padding: 0; justify-content: center; font-size: 17px;
}

#stage {
  flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  padding: 18px; overflow: hidden;
}
#book { box-shadow: var(--shadow); }
#book .page { background: #fff; overflow: hidden; }
#book .page img { width: 100%; height: 100%; object-fit: cover; }

/* 하단 컨트롤 */
.v-bottom {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  height: 66px; padding: 0 16px;
  background: rgba(15, 20, 32, .82); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.v-bottom input[type=range] { width: min(40vw, 320px); accent-color: var(--eastar-red); }
#pageInfo { min-width: 78px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* 사이드 패널 (썸네일/목차) */
.side {
  position: fixed; top: 0; right: 0; bottom: 0; width: 320px; max-width: 86vw; z-index: 80;
  background: var(--bg-soft); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .25s ease;
  display: flex; flex-direction: column;
}
.side.open { transform: translateX(0); }
.side .side-head { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--line); }
.side .tabs { display: flex; gap: 6px; }
.side .tab { padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.side .tab.active { background: var(--eastar-red); color: #fff; }
.side .side-body { flex: 1; overflow-y: auto; padding: 14px; }
.thumbs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.thumb { cursor: pointer; border-radius: 6px; overflow: hidden; border: 2px solid transparent; }
.thumb.active { border-color: var(--eastar-red); }
.thumb img { width: 100%; aspect-ratio: 1/1.414; object-fit: cover; }
.thumb span { display: block; text-align: center; font-size: 11px; color: var(--muted); padding: 3px 0; }
.toc-item { padding: 11px 12px; border-radius: 9px; cursor: pointer; font-size: 14px; display: flex; justify-content: space-between; gap: 10px; }
.toc-item:hover { background: rgba(255, 255, 255, .06); }
.toc-item .pg { color: var(--muted); font-size: 12.5px; }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 70; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim.show { opacity: 1; pointer-events: auto; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: #000; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 모바일 최적화 ---------- */
@media (max-width: 640px) {
  .hero { padding: 30px 16px 12px; }
  .hero h1 { font-size: 26px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 20px 14px; }
  .v-top .title { max-width: 38vw; }
  .v-bottom { gap: 8px; }
  .v-bottom input[type=range] { width: 42vw; }
  #stage { padding: 8px; }
  .brand .sub { display: none; }
}
