:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #2a2622;
  --muted: #6f675e;
  --line: #e7e0d5;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e3efe9;
  --warn: #9a4a1c;
  --ph: #d9d2c6;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08);
  --tabbar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --surface: #26241f;
    --text: #f1ece3;
    --muted: #a9a094;
    --line: #38342d;
    --accent: #7cc7ad;
    --accent-text: #11201b;
    --accent-soft: #263a33;
    --warn: #e0a070;
    --ph: #3b3730;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 4px; padding-top: max(8px, env(safe-area-inset-top));
}
.top h1 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.icon-btn { min-height: 44px; min-width: 44px; padding: 0 8px; border: 0; background: none; color: var(--muted); font-size: 14px; }

main { padding: 8px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); max-width: 640px; margin: 0 auto; }
h2 { font-size: 20px; margin: 12px 0 8px; }
h3 { font-size: 16px; margin: 16px 0 8px; }
.muted { color: var(--muted); font-size: 13px; }
.note { color: var(--muted); font-size: 12px; }
.pad { padding: 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  min-height: var(--tabbar-h); border: 0; background: none; color: var(--muted);
  font-size: 15px; font-weight: 500; position: relative;
}
.tabbar button[aria-selected="true"] { color: var(--accent); font-weight: 700; }
.tabbar button[aria-selected="true"]::before {
  content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
}

/* 폼 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.field { display: block; margin: 0 0 16px; }
.field > span, fieldset > legend { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; padding: 0; }
fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
input[type=password], input[type=text], input[type=search], select {
  width: 100%; min-height: 48px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.btn {
  min-height: 48px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.btn.ghost { background: none; color: var(--accent); }
.btn.block { width: 100%; }
.btn.block + .btn.block { margin-top: 10px; }
.btn[disabled] { opacity: .6; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.chip {
  min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--surface); font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin-left: -16px; margin-right: -16px; padding: 0 16px 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.scroll .chip { flex: none; }
.msg { margin: 12px 0; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 15px; }
.msg.warn { color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 40px 8px; }

/* 책 목록 */
.books { list-style: none; margin: 0; padding: 0; }
.book { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.book-open {
  flex: 1; min-width: 0; display: flex; gap: 12px; align-items: center; text-align: left;
  background: none; border: 0; padding: 10px 0; min-height: 44px;
}
.cover { width: 56px; height: 84px; flex: none; border-radius: 4px; object-fit: cover; background: var(--ph); box-shadow: var(--shadow); }
.cover.ph { display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: var(--muted); }
.cover.big { width: 84px; height: 126px; }
.book-meta { min-width: 0; }
.book-title { display: block; font-weight: 600; line-height: 1.35; }
.book-sub { display: block; color: var(--muted); font-size: 13px; }
.rank { display: block; color: var(--accent); font-weight: 700; font-size: 12px; }
.heart { width: 48px; height: 48px; flex: none; border: 0; background: none; font-size: 24px; color: var(--accent); }

.skel { height: 84px; margin: 10px 0; border-radius: 8px; background: linear-gradient(90deg, var(--line), var(--surface), var(--line)); background-size: 200% 100%; animation: sh 1.4s linear infinite; }
@keyframes sh { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

/* 상세 */
.back { min-height: 44px; border: 0; background: none; color: var(--accent); padding: 0; font-weight: 600; }
.detail-head { display: flex; gap: 14px; margin: 4px 0 12px; }
.detail-head h2 { margin: 0 0 4px; font-size: 19px; line-height: 1.35; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.detail-actions .btn { min-height: 44px; font-size: 15px; }
.libs { list-style: none; margin: 0; padding: 0; }
.lib { padding: 12px 0; border-bottom: 1px solid var(--line); }
.lib-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.lib-name { font-weight: 600; }
.badge { font-size: 14px; font-weight: 600; }
.badge.ok { color: var(--accent); }
.badge.no { color: var(--muted); }
.lib a { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-size: 14px; }

/* 찜 */
details.wish-group { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; }
details.wish-group summary { list-style: none; padding: 14px 16px; min-height: 52px; cursor: pointer; }
details.wish-group summary::-webkit-details-marker { display: none; }
details.wish-group summary { position: relative; padding-right: 44px; }
details.wish-group summary::after {
  content: ""; position: absolute; right: 18px; top: 50%; width: 9px; height: 9px; margin-top: -7px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s;
}
details.wish-group[open] summary::after { transform: rotate(-135deg); margin-top: -2px; }
.wish-group .sum-state.none { color: var(--muted); }
.extra { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; padding: 8px 16px; }
.extra > p { margin: 4px 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.extra ul { list-style: none; margin: 0; padding: 0; }
.extra li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.wish-group .sum-name { font-weight: 700; }
.wish-group .sum-state { display: block; font-size: 14px; color: var(--accent); }
.wish-group ul { list-style: none; margin: 0; padding: 0 16px 8px; }
.wish-group li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.wish-group .gfoot { padding: 0 16px 8px; }
.wish-group .gfoot a { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-size: 14px; }
.wish-count { text-align: center; margin: 20px 0 0; color: var(--muted); }

.toast {
  position: fixed; left: 16px; right: 16px; z-index: 20; text-align: center;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 10px; font-size: 15px;
}
