:root {
  --paper: #f5efe3;
  --card: #fffcf6;
  --line: #e5dac7;
  --line-strong: #d3c4ab;
  --ink: #33291f;
  --muted: #86755f;
  --accent: #46705c;
  --accent-ink: #2f5242;
  --accent-soft: #e2ebe2;
  --star: #d39a35;
  --danger: #b0503b;
  --serif: 'Gowun Batang', 'Nanum Myeongjo', serif;
  --sans: 'Gowun Dodum', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.65 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.ic { display: block; flex: none; }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 18px calc(110px + env(safe-area-inset-bottom));
}

/* ---------- 공통 조각 ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; }
.brand { font-size: 25px; }
.tools { display: flex; gap: 4px; position: relative; }
.icon-btn {
  width: 42px; height: 42px; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: rgba(70, 60, 40, 0.07); color: var(--ink); }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); padding: 8px 8px 8px 0; border: 0; background: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); border-color: #e3c1b6; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: 0.55; cursor: default; }

.section { margin-top: 30px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.section-head h2 { font-size: 18px; }
.count { color: var(--muted); font-size: 14px; font-family: var(--sans); font-weight: 400; margin-left: 6px; }
.hint { color: var(--muted); font-size: 14px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 13px; background: rgba(70, 60, 40, 0.07); color: var(--muted); white-space: nowrap;
}
.chip.reading { background: var(--accent-soft); color: var(--accent-ink); }
.chip.done { background: #f1e3c6; color: #7a5a1c; }
.chip.paused { background: #ece4da; color: #7b6a58; }
.chip.want { background: #e6e3ef; color: #5b5478; }

.stars { display: inline-flex; gap: 1px; color: var(--star); }
.stars .off { color: var(--line-strong); }
.stars svg { fill: currentColor; stroke-width: 1.2; }

/* ---------- 표지 ---------- */
.cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 4px 8px 8px 4px; overflow: hidden;
  background: var(--c, #d9cbb2); box-shadow: 0 1px 2px rgba(60, 40, 20, 0.18), inset 3px 0 0 rgba(0, 0, 0, 0.06);
}
.cover .ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: 12% 10%; font-family: var(--serif); color: #3a2f24; overflow: hidden;
}
.cover .ph span { font-size: clamp(11px, 2.6vw, 15px); line-height: 1.35; font-weight: 700; word-break: keep-all; overflow-wrap: anywhere; }
.cover .ph small { font-family: var(--sans); font-size: 10px; opacity: 0.75; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover.mini .ph span { font-size: 10px; }
.cover.mini .ph small { display: none; }

/* ---------- 잠금 ---------- */
.lock { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; }
.lock-mark { width: 84px; height: 84px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; color: var(--accent); }
.lock h1 { font-size: 28px; margin-top: 8px; }
.lock form { display: flex; gap: 8px; margin-top: 10px; width: min(340px, 100%); }
.lock input { flex: 1; min-width: 0; }
.lock .err { min-height: 1.6em; color: var(--danger); font-size: 14px; margin: 0; }

/* ---------- 입력 ---------- */
input[type="text"], input[type="password"], input[type="search"], input[type="date"], textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--card); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(70, 112, 92, 0.15); }
textarea { resize: vertical; line-height: 1.7; }
textarea.serif { font-family: var(--serif); font-size: 17px; }
label.field { display: block; margin-top: 16px; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  border: 1px solid var(--line-strong); background: var(--card); border-radius: 999px; padding: 6px 14px; font-size: 14px; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 서재 ---------- */
.searchbar { margin-top: 6px; }
.today-quote {
  margin-top: 14px; padding: 20px 22px 16px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); position: relative;
}
.today-quote .label { font-size: 13px; color: var(--accent); display: flex; align-items: center; gap: 6px; }
.today-quote blockquote {
  margin: 10px 0 12px; font-family: var(--serif); font-size: 18px; line-height: 1.75; white-space: pre-line;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}
.today-quote .src { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--muted); }
.today-quote .src a:hover { color: var(--ink); text-decoration: underline; }

.reading-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.reading-card {
  display: grid; grid-template-columns: 64px 1fr; gap: 14px; padding: 14px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line);
}
.reading-card .info { display: flex; flex-direction: column; min-width: 0; }
.reading-card .t { font-family: var(--serif); font-weight: 700; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.reading-card .a { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reading-card .m { font-size: 13px; color: var(--muted); margin-top: auto; }
.reading-card .quick { align-self: flex-start; margin-top: 8px; display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--accent); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; margin-top: 26px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button { flex: none; border: 1px solid var(--line-strong); background: transparent; border-radius: 999px; padding: 5px 13px; font-size: 14px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.filters button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.filters button svg { fill: currentColor; stroke-width: 1.2; }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 18px 14px; }
.shelf a { display: block; min-width: 0; }
.shelf .t { margin-top: 7px; font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.shelf .stars { margin-top: 2px; }
.shelf.small { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 14px 10px; }

.empty { text-align: center; padding: 60px 10px; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 20px; margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }

.fab {
  position: fixed; right: max(18px, calc(50vw - 362px)); bottom: calc(22px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 6px; height: 54px; padding: 0 22px 0 18px; border-radius: 999px;
  background: var(--accent); color: #fff; border: 0; box-shadow: 0 6px 18px rgba(47, 82, 66, 0.3); font-size: 16px; z-index: 5;
}
.fab:hover { background: var(--accent-ink); }

.menu {
  position: absolute; right: 0; top: 46px; z-index: 10; min-width: 190px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 28px rgba(60, 40, 20, 0.16);
}
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; background: none; border-radius: 8px; font-size: 15px; text-align: left; }
.menu button:hover, .menu a:hover { background: rgba(70, 60, 40, 0.06); }

.results .note-hit { display: block; padding: 14px 16px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); margin-bottom: 8px; }
.results .note-hit q { font-family: var(--serif); quotes: none; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.results .note-hit small { display: block; color: var(--muted); margin-top: 4px; }
mark { background: #f6df9c; color: inherit; border-radius: 2px; padding: 0 1px; }

/* ---------- 책 ---------- */
.hero { display: grid; grid-template-columns: 120px 1fr; gap: 20px; margin-top: 8px; align-items: start; }
.hero h1 { font-size: 23px; line-height: 1.4; word-break: keep-all; }
.hero .by { color: var(--muted); font-size: 15px; margin-top: 4px; }
.hero .dates { font-size: 14px; color: var(--muted); margin-top: 10px; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.rate { display: flex; gap: 0; margin-top: 8px; margin-left: -6px; }
.rate button { border: 0; background: none; padding: 6px; color: var(--line-strong); }
.rate button.on { color: var(--star); }
.rate svg { fill: currentColor; stroke-width: 1.2; }
.status-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

.notes { display: flex; flex-direction: column; gap: 10px; }
.note { padding: 14px 18px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.note-meta { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); }
.note-meta .icon-btn { width: 34px; height: 34px; margin: -6px -10px -6px 0; }
.note blockquote { margin: 4px 0 0; font-family: var(--serif); font-size: 17px; line-height: 1.8; white-space: pre-line; }
.note .thought { margin: 4px 0 0; font-size: 15px; color: #5d4f40; white-space: pre-line; }
.note blockquote + .thought { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.note .thought::before { content: '내 생각'; display: block; font-size: 12px; color: var(--accent); margin-bottom: 2px; }
.page-badge { display: inline-block; min-width: 2.2em; padding: 0 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-ink); font-size: 12px; text-align: center; margin-right: 6px; }

.note-form { padding: 16px; background: var(--card); border: 1px solid var(--accent); border-radius: var(--radius); }
.note-form .row { margin-bottom: 10px; align-items: end; }
.note-form .row label { font-size: 13px; color: var(--muted); }
.note-form textarea { margin-bottom: 8px; }
.note-form .tip { font-size: 12.5px; color: var(--muted); margin: -2px 0 10px; display: flex; gap: 5px; align-items: flex-start; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }

.review { padding: 18px 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); white-space: pre-line; line-height: 1.85; }
.review-empty { padding: 18px 20px; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- 책 추가·고치기 ---------- */
.page-title { font-size: 22px; margin: 8px 0 4px; }
.find-row { display: flex; gap: 8px; margin-top: 14px; }
.find-row input { flex: 1; }
.found { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.found button {
  display: grid; grid-template-columns: 44px 1fr; gap: 12px; text-align: left; padding: 8px 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); align-items: center;
}
.found button:hover { border-color: var(--accent); }
.found .t { font-family: var(--serif); font-weight: 700; line-height: 1.35; }
.found .a { font-size: 13px; color: var(--muted); }
.cover-edit { display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: center; margin-top: 18px; }
.cover-edit .btns { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 22px 0 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.save-bar { margin-top: 26px; display: flex; gap: 10px; }
.save-bar .btn.primary { flex: 1; }
.danger-zone { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); text-align: center; }

/* ---------- 알림·확인 창 ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 30; max-width: calc(100vw - 40px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.overlay { position: fixed; inset: 0; background: rgba(40, 30, 20, 0.35); display: grid; place-items: center; z-index: 40; padding: 20px; }
.dialog { width: min(360px, 100%); background: var(--card); border-radius: 18px; padding: 22px 22px 16px; }
.dialog p { margin: 0 0 18px; line-height: 1.6; }
.dialog .form-actions { justify-content: flex-end; }

.loading { padding: 80px 0; text-align: center; color: var(--muted); }

@media (min-width: 640px) {
  .hero { grid-template-columns: 150px 1fr; gap: 28px; }
  .hero h1 { font-size: 27px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
}
