:root {
  --paper: #f6f3ee;
  --card: #ffffff;
  --ink: #26221f;
  --ink-2: #5d5750;
  --line: #e4ddd3;
  --brand: #5b21d6;
  --brand-2: #7c4dff;
  --brand-soft: #efe8ff;
  --story: #fbe9a8;
  --story-ink: #6b5200;
  --act: #cfe6ee;
  --act-ink: #1e5566;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 6px 18px rgba(40, 30, 20, .08);
  --r: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Sans KR", system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.view { max-width: 980px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }

/* ── 홈 ── */
.top { padding: calc(20px + env(safe-area-inset-top)) 0 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 34px; line-height: 1; }
.brand h1 { font-family: "Jua", sans-serif; font-weight: 400; font-size: 28px; margin: 0; color: var(--brand); letter-spacing: -.5px; }
.brand p { margin: 0; color: var(--ink-2); font-size: 14px; }

.scan-card {
  width: 100%; display: flex; align-items: center; gap: 18px;
  border: 0; border-radius: 24px; padding: 22px 22px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff; text-align: left; box-shadow: 0 10px 28px rgba(91, 33, 214, .32);
  transition: transform .12s ease;
}
.scan-card:active { transform: scale(.98); }
.scan-icon { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 20px; background: rgba(255,255,255,.18); flex: none; }
.scan-text strong { display: block; font-family: "Jua", sans-serif; font-weight: 400; font-size: 30px; line-height: 1.15; }
.scan-text small { display: block; opacity: .9; font-size: 15px; margin-top: 2px; }

.search-row { margin: 18px 0 10px; }
.search { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 0 14px; color: var(--ink-2); }
.search:focus-within { border-color: var(--brand); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font: inherit; font-size: 17px; padding: 13px 0; color: var(--ink); }

.levels { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 6px; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 16px; font-weight: 700; font-size: 15px; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip small { font-weight: 500; opacity: .8; margin-left: 4px; }
.count { color: var(--ink-2); font-size: 14px; margin: 6px 2px 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; } }
.tile { display: flex; flex-direction: column; text-align: left; border: 0; padding: 0; background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); transition: transform .12s ease; }
.tile:active { transform: scale(.97); }
.tile-img { position: relative; aspect-ratio: 1; background: #eee center/cover no-repeat; }
.tile-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-no { position: absolute; left: 8px; top: 8px; background: rgba(38, 34, 31, .78); color: #fff; font-weight: 700; font-size: 13px; padding: 2px 9px; border-radius: 999px; }
.tile-body { padding: 9px 11px 12px; }
.tile-title { font-weight: 700; font-size: 15px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.noimg { display: grid; place-items: center; width: 100%; height: 100%; background: var(--brand-soft); color: var(--brand); font-family: "Jua", sans-serif; font-size: 20px; padding: 12px; text-align: center; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--ink-2); padding: 40px 0; }
.foot { text-align: center; margin-top: 28px; }
.foot a { color: var(--brand); font-weight: 700; text-decoration: none; }

/* ── 책 상세 ── */
.book-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; background: var(--paper); }
.icon-btn { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; border: 0; background: var(--card); box-shadow: var(--shadow); color: var(--ink); }
.icon-btn.light { background: rgba(0,0,0,.45); color: #fff; box-shadow: none; }
.book-id { display: flex; align-items: center; gap: 8px; font-family: "Jua", sans-serif; font-size: 26px; color: var(--brand); }
.pill { font-family: "Noto Sans KR", sans-serif; font-weight: 700; font-size: 14px; background: var(--brand); color: #fff; border-radius: 8px; padding: 2px 9px; }

.book-head { display: flex; gap: 16px; align-items: center; background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); margin-top: 4px; }
.book-cover { width: 108px; height: 108px; object-fit: cover; border-radius: 12px; flex: none; background: #eee; }
.book-head h2 { margin: 0 0 8px; font-size: 21px; line-height: 1.3; }
.kicker { margin: 0; font-size: 12.5px; font-weight: 700; color: var(--brand); letter-spacing: .5px; }
.pairs { list-style: none; margin: 2px 0 0; padding: 0; font-size: 15px; color: var(--ink-2); }
.pairs li::before { content: "· "; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 16px 0 12px; background: #ebe5dc; padding: 5px; border-radius: 16px; position: sticky; top: calc(66px + env(safe-area-inset-top)); z-index: 4; }
.tab { border: 0; background: none; border-radius: 12px; padding: 11px 4px; font-weight: 700; font-size: 16px; color: var(--ink-2); }
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.pages { display: grid; gap: 16px; }
@media (min-width: 760px) { .pages { grid-template-columns: 1fr 1fr; } }
.page { margin: 0; background: var(--card); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
/* 왼쪽 세로 띠("4A 1 줄거리")는 위에 이미 나오므로 가리고 글씨를 크게 */
.crop { position: relative; aspect-ratio: 1200 / 1764; overflow: hidden; background: #f1eee9; cursor: zoom-in; }
.crop img { position: absolute; top: 0; right: 0; width: 113.75%; height: 100%; display: block; }
@media (max-width: 759px) { .pages { margin: 0 -16px; gap: 12px; } .page { border-radius: 0; } }
.save1 { margin-left: auto; border: 0; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 13.5px; padding: 6px 12px; border-radius: 999px; flex: none; }
.page figcaption .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.wide { display: block; width: 100%; margin-top: 16px; font-size: 17px; padding: 16px 10px; }
.page figcaption { display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--line); }
.tag { font-size: 12.5px; padding: 2px 9px; border-radius: 999px; font-weight: 700; }
.tag.story { background: var(--story); color: var(--story-ink); }
.tag.act { background: var(--act); color: var(--act-ink); }
.tag.info { background: var(--brand-soft); color: var(--brand); }

.actions, .prevnext { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.btn { border: 0; border-radius: 14px; padding: 14px 10px; font-weight: 700; font-size: 16px; background: var(--brand); color: #fff; }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.btn:disabled { opacity: .4; }

/* ── 촬영 ── */
.scan { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; }
.scan video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-shade { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.frame { position: relative; width: min(78vw, 62vh, 460px); aspect-ratio: 1; border-radius: 18px; box-shadow: 0 0 0 200vmax rgba(0,0,0,.5); transition: box-shadow .2s; }
.frame i { position: absolute; width: 38px; height: 38px; border: 5px solid #fff; }
.frame i:nth-child(1) { left: -3px; top: -3px; border-right: 0; border-bottom: 0; border-radius: 16px 0 0 0; }
.frame i:nth-child(2) { right: -3px; top: -3px; border-left: 0; border-bottom: 0; border-radius: 0 16px 0 0; }
.frame i:nth-child(3) { left: -3px; bottom: -3px; border-right: 0; border-top: 0; border-radius: 0 0 0 16px; }
.frame i:nth-child(4) { right: -3px; bottom: -3px; border-left: 0; border-top: 0; border-radius: 0 0 16px 0; }
.frame.hit i { border-color: #7dffb0; }
.scan-hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(12px + env(safe-area-inset-top)) 16px 0; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.scan-msg { align-self: center; margin: 0; background: rgba(0,0,0,.55); padding: 9px 16px; border-radius: 999px; font-weight: 700; font-size: 16px; text-align: center; max-width: 92vw; }
.scan-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 28px calc(28px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.35); }
.shutter:active { background: #fff; }
.round-btn { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 50%; background: rgba(0,0,0,.5); color: #fff; cursor: pointer; }
.ghost-slot { visibility: hidden; }

.picks { position: absolute; left: 0; right: 0; bottom: 0; background: var(--paper); color: var(--ink); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 78vh; overflow: auto; }
.picks-title { font-family: "Jua", sans-serif; font-size: 22px; margin: 0 0 12px; }
.pick-list { display: grid; gap: 10px; margin-bottom: 12px; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: var(--card); border-radius: 14px; padding: 10px; box-shadow: var(--shadow); }
.pick img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; }
.pick b { display: block; font-size: 16px; }
.pick small { color: var(--ink-2); font-size: 13.5px; }
.picks .btn { width: 100%; }

.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: rgba(0,0,0,.6); font-weight: 700; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 크게 보기 ── */
.zoom { position: fixed; inset: 0; z-index: 30; background: rgba(20,18,16,.96); overflow: auto; touch-action: pan-x pan-y pinch-zoom; }
.zoom img { display: block; width: 100%; max-width: 1100px; margin: 0 auto; }
@media (max-width: 759px) { .zoom img { width: 200%; max-width: none; } }
.zoom-close { position: fixed; right: 14px; top: calc(14px + env(safe-area-inset-top)); z-index: 1; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 700; z-index: 40; max-width: 90vw; text-align: center; }

/* ── 인쇄: 선택한 탭의 페이지만 A4 한 장씩 ── */
@media print {
  @page { size: A4; margin: 8mm; }
  body { background: #fff; }
  #home, .book-top, .book-head, .tabs, .actions, .prevnext, .toast, .scan, .zoom, .btn.wide { display: none !important; }
  .crop { aspect-ratio: auto; overflow: visible; }
  .crop img { position: static !important; width: 100% !important; height: auto !important; }
  #book { display: block !important; max-width: none; padding: 0; }
  .pages { display: block; }
  .page { box-shadow: none; border-radius: 0; break-after: page; page-break-after: always; }
  .page figcaption { display: none; }
  .page img { max-height: 277mm; width: auto; margin: 0 auto; }
}
