:root {
  --paper: #f5efe4;
  --paper-2: #ece4d5;
  --card: #fbf8f2;
  --ink: #2a241f;
  --ink-2: #6b6158;
  --ink-3: #9b9086;
  --line: #ddd2c1;
  --accent: #a8472a;
  --accent-ink: #fff8f2;
  --accent-soft: #f3dfd3;
  --gold: #b88a2e;
  --silver: #8d8a85;
  --bronze: #a3683f;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .06);
  --serif: 'Gowun Batang', 'Noto Serif KR', serif;
  --sans: 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1c1915; --paper-2: #26221c; --card: #231f1a;
    --ink: #ece4d6; --ink-2: #b0a594; --ink-3: #7f7568; --line: #3a342c;
    --accent: #e0805f; --accent-ink: #1c1915; --accent-soft: #3a2a22;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1c1915; --paper-2: #26221c; --card: #231f1a;
  --ink: #ece4d6; --ink-2: #b0a594; --ink-3: #7f7568; --line: #3a342c;
  --accent: #e0805f; --accent-ink: #1c1915; --accent-soft: #3a2a22;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ── 상단바 · 하단 탭 ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 16px; padding-top: env(safe-area-inset-top, 0px);
  height: calc(56px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand-mark {
  width: 22px; height: 26px; border-radius: 2px 5px 5px 2px; background: var(--accent);
  box-shadow: inset 4px 0 0 rgba(0,0,0,.18), inset -2px 0 0 rgba(255,255,255,.15);
  position: relative;
}
.brand-mark::after { content: ''; position: absolute; left: 8px; right: 4px; top: 7px; height: 2px; background: var(--accent-ink); opacity: .8; border-radius: 1px; }
.brand-name { font-family: var(--serif); font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.topbar-right { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; text-decoration: none; font-size: 13px;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-3); font-size: 11px; font-weight: 500;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.1; }

.view {
  max-width: 600px; margin: 0 auto; outline: none;
  padding: 20px 16px calc(var(--tabbar-h) + var(--safe-b) + 32px);
  min-height: 100vh;
}

/* ── 공통 요소 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 20px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-weight: 700; text-decoration: none; transition: transform .1s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-danger { color: #c0392b; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--ink-2); }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; outline: none; transition: border-color .15s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { min-height: 50vh; resize: vertical; font-family: var(--serif); line-height: 1.85; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin: 4px 0 20px; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.social { display: grid; gap: 10px; }
.btn-naver { background: #03c75a; border-color: #03c75a; color: #fff; }
.btn-google { background: #fff; border-color: #dadce0; color: #1f1f1f; }
.s-logo { width: 22px; text-align: center; font-size: 17px; font-weight: 900; font-family: Arial, sans-serif; }
.btn-google .s-logo { color: #4285f4; }
.or { display: flex; align-items: center; gap: 12px; margin: 22px 0 18px; color: var(--ink-3); font-size: 13px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.form-error { color: #c0392b; font-size: 14px; min-height: 20px; margin: -4px 0 12px; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 0 12px; }
.section-title h2 { font-size: 19px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 6px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--card); font-size: 14px; color: var(--ink-2);
}
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 700; }

.segment { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--paper-2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.segment button { border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 500; color: var(--ink-2); }
.segment button.on { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }

.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty h3 { color: var(--ink); margin-bottom: 6px; font-size: 18px; }

/* ── 홈 ── */
.hero { padding: 8px 0 4px; }
.hero h1 { font-size: 28px; line-height: 1.35; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { margin: 10px 0 0; color: var(--ink-2); }
.search { position: relative; margin: 20px 0 14px; }
.search .input { padding-left: 42px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; stroke: var(--ink-3); fill: none; stroke-width: 2; }

/* 책 목록 */
.book-list { display: grid; gap: 12px; }
.book-row {
  display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: center;
  padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  text-decoration: none; transition: transform .12s;
}
.book-row:active { transform: scale(.99); }
.book-row h3 { font-size: 17px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-row .meta { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.book-row .sum { font-size: 13.5px; color: var(--ink-2); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

.cover {
  --c1: #a8472a; --c2: #7a2f1a;
  position: relative; aspect-ratio: 3 / 4.2; border-radius: 3px 8px 8px 3px; overflow: hidden;
  background: linear-gradient(160deg, var(--c1), var(--c2));
  box-shadow: inset 5px 0 0 rgba(0,0,0,.18), inset 6px 0 0 rgba(255,255,255,.08), 0 3px 8px rgba(40,25,10,.18);
  color: #fffaf3; display: flex; flex-direction: column; justify-content: space-between; padding: 10% 10% 10% 16%;
}
.cover .c-title { font-family: var(--serif); font-weight: 700; font-size: 10px; line-height: 1.3; word-break: keep-all; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.cover .c-rule { height: 1px; background: rgba(255,250,243,.55); margin-top: 6%; }
.cover .c-author { font-size: 8px; opacity: .85; }
.cover.lg { width: 150px; margin: 0 auto; padding: 18px 14px 16px 22px; }
.cover.lg .c-title { font-size: 19px; -webkit-line-clamp: 5; }
.cover.lg .c-author { font-size: 12px; }
.cover.lg .c-rule { margin-top: 12px; }

/* ── 책 소개 ── */
.book-detail { text-align: center; padding-top: 12px; }
.book-detail h1 { font-size: 24px; margin-top: 20px; line-height: 1.35; word-break: keep-all; }
.book-detail .by { color: var(--ink-2); margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 22px 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.stats div { padding: 12px 4px; }
.stats div + div { border-left: 1px solid var(--line); }
.stats b { display: block; font-size: 18px; font-family: var(--serif); }
.stats span { font-size: 12px; color: var(--ink-3); }
.book-detail .summary { text-align: left; background: var(--paper-2); padding: 14px 16px; border-radius: 12px; color: var(--ink-2); margin-bottom: 20px; font-family: var(--serif); }
.note { font-size: 13px; color: var(--ink-3); margin-top: 12px; }

/* ── 랭킹 ── */
.rank-list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.rank-list li { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px; padding: 12px 14px; }
.rank-list li + li { border-top: 1px solid var(--line); }
.rank-list a { text-decoration: none; }
.rank-no { font-family: var(--serif); font-weight: 700; font-size: 18px; text-align: center; color: var(--ink-3); }
.rank-list li:nth-child(1) .rank-no { color: var(--gold); font-size: 22px; }
.rank-list li:nth-child(2) .rank-no { color: var(--silver); font-size: 21px; }
.rank-list li:nth-child(3) .rank-no { color: var(--bronze); font-size: 20px; }
.rank-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-sub { font-size: 12.5px; color: var(--ink-3); }
.rank-val { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── 내 서재 ── */
.profile {
  background: var(--ink); color: var(--paper); border-radius: 18px; padding: 22px 20px;
  display: grid; gap: 14px;
}
.profile h2 { font-size: 22px; }
.profile .row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.profile .row div { background: rgba(255,255,255,.08); border-radius: 12px; padding: 10px 12px; }
.profile .row b { display: block; font-family: var(--serif); font-size: 20px; }
.profile .row span { font-size: 12px; opacity: .7; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.log li b { color: var(--accent); white-space: nowrap; }
.linkrow { display: grid; gap: 8px; margin-top: 24px; }

/* ── 쓰기 ── */
.counter { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-3); margin: -8px 0 16px; }

/* ── 약관 ── */
.doc h1 { font-size: 24px; margin-bottom: 16px; }
.doc h2 { font-size: 17px; margin: 22px 0 8px; }
.doc p, .doc li { color: var(--ink-2); font-size: 14.5px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; }
.doc td, .doc th { border: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }

.footer { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3); line-height: 1.8; }
.footer a { color: var(--ink-2); }

/* ── 토스트 ── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 500; max-width: calc(100% - 32px); box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.reading .toast { bottom: calc(var(--safe-b) + 70px); }

/* ── 읽기 화면: 휴대폰 한 화면 = 한 쪽 ── */
body.reading .topbar, body.reading .tabbar { display: none; }
body.reading { overflow: hidden; overscroll-behavior: none; }
body.reading .view { max-width: none; padding: 0; min-height: 0; }

.reader {
  --fs: 18px;
  position: fixed; inset: 0; background: var(--paper); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: var(--safe-b);
  touch-action: pan-y;
}
.reader-bar {
  height: 52px; display: flex; align-items: center; gap: 4px; padding: 0 8px;
  border-bottom: 1px solid transparent; transition: opacity .2s; flex: none;
}
.reader-bar .t { flex: 1; min-width: 0; font-family: var(--serif); font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 10px; color: var(--ink-2); font-weight: 700; font-size: 14px; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.reader.immersive .reader-bar, .reader.immersive .reader-foot { opacity: 0; pointer-events: none; }

.page-viewport { flex: 1; position: relative; overflow: hidden; margin: 0 24px; }
.page-flow {
  position: absolute; top: 0; left: 0; height: 100%;
  column-fill: auto; column-gap: 48px;
  font-family: var(--serif); font-size: var(--fs); line-height: 1.9; word-break: keep-all; overflow-wrap: anywhere;
  transition: transform .32s cubic-bezier(.2,.7,.2,1);
  will-change: transform;
}
.page-flow.no-anim { transition: none; }
.page-flow p { margin: 0 0 1em; text-indent: .6em; }
.page-flow p.first { text-indent: 0; }
.page-flow h3 { font-size: 1.12em; margin: .6em 0 1em; break-after: avoid; text-indent: 0; }
.page-flow .title-page { break-after: column; height: 100%; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.page-flow .title-page h2 { font-size: 1.6em; line-height: 1.35; margin-bottom: .6em; }
.page-flow .title-page .by { color: var(--ink-2); font-size: .85em; }
.page-flow .title-page .orn { color: var(--accent); margin: 1.2em 0; letter-spacing: .6em; font-size: .8em; }
.page-flow .end-page {
  break-before: column; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; font-family: var(--sans); font-size: 15px; gap: 12px;
}
.end-page .fin { font-family: var(--serif); font-size: 34px; color: var(--accent); }
.end-page .award { background: var(--accent-soft); color: var(--accent); padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; }
.end-page .btns { display: grid; gap: 8px; width: 100%; max-width: 280px; margin-top: 8px; }

.tap-zone { position: absolute; top: 0; bottom: 0; z-index: 2; }
.tap-prev { left: 0; width: 30%; }
.tap-mid { left: 30%; width: 40%; }
.tap-next { right: 0; width: 30%; }
.end-page .btns, .end-page .btns * { position: relative; z-index: 3; }

.reader-foot { height: 48px; display: flex; align-items: center; gap: 12px; padding: 0 24px; flex: none; transition: opacity .2s; }
.progress { flex: 1; height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.page-no { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }

.reader-menu {
  position: absolute; top: calc(52px + env(safe-area-inset-top, 0px)); right: 8px; z-index: 5;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 12px; display: grid; gap: 10px; min-width: 210px;
}
.reader-menu .r { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.reader-menu .r > div { display: flex; gap: 4px; }
.reader-menu button { min-width: 40px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: var(--paper); }

@media (min-width: 700px) {
  .page-viewport { margin: 0 auto; width: min(560px, 100% - 48px); }
}
@media (prefers-reduced-motion: reduce) {
  .page-flow, .toast, .book-row, .btn { transition: none; }
}
