:root {
  --bg: #efe9df;
  --paper: #fffbf4;
  --ink: #2b2118;
  --muted: #84735f;
  --line: #e1d6c5;
  --accent: #b5523b;
  --floor: #c9b79c;
  --toss: #6b4e9b;
  --box: #3f6e9a;
  --sell: #b07d12;
  --unk: #b5523b;
  --mark: #ffe08a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1815; --paper: #25211c; --ink: #efe6d8; --muted: #a8987f; --line: #3a3229;
    --accent: #e0805f; --floor: #4a3e31; --toss: #a98ad6; --box: #7fa8d4; --sell: #e0b44a; --unk: #e0805f; --mark: #7a5c12;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1815; --paper: #25211c; --ink: #efe6d8; --muted: #a8987f; --line: #3a3229;
  --accent: #e0805f; --floor: #4a3e31; --toss: #a98ad6; --box: #7fa8d4; --sell: #e0b44a; --unk: #e0805f; --mark: #7a5c12;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 820px;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }

/* ── 머리 ── */
.top { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 0 6px; }
.top h1 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.top h1 a { text-decoration: none; }
.bar {
  position: sticky; top: 0; z-index: 5;
  margin: 0 -16px; padding: 8px 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
body.locked .bar, body.locked .top span, body.locked footer { display: none; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input {
  width: 100%; height: 44px; padding: 0 40px 0 38px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink);
  font-size: 16px; outline: none;
}
.search input:focus { border-color: var(--accent); }
.search input::-webkit-search-cancel-button { display: none; }
#clear { position: absolute; right: 4px; top: 4px; width: 36px; height: 36px; border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; }
.chips { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--paper); cursor: pointer; font-size: 14px;
}
.chip span { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--k); }
.c-toss { --k: var(--toss); } .c-box { --k: var(--box); } .c-sell { --k: var(--sell); } .c-unk { --k: var(--unk); }
.chip[aria-pressed="true"] { background: var(--k); border-color: var(--k); color: #fff; }
.chip[aria-pressed="true"] span { color: rgba(255,255,255,.85); }
.chip[aria-pressed="true"]::before { background: #fff; }

.loading, .empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ── 책장 (mm 단위를 --u로 환산) ── */
.case { container-type: inline-size; aspect-ratio: var(--ar); width: 100%; }
.frame {
  --u: calc(100cqw / var(--w));
  height: 100%; display: flex; flex-direction: column;
  padding: calc(var(--u) * 18) calc(var(--u) * 18) 0;
  background: var(--frame);
  border-radius: 2px;
  box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 2px 3px 8px rgba(0,0,0,.18), var(--edge, 0 0 0 0 transparent);
}
.rows { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.row {
  position: relative;
  flex: 1 1 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--inner);
  border-bottom: calc(var(--u) * 18) solid var(--board);
  text-decoration: none; color: inherit; -webkit-tap-highlight-color: transparent;
}
.row:hover, .row:focus-visible, .row.on { outline: 2px solid var(--accent); outline-offset: -1px; z-index: 1; }
.row.on { outline-width: 3px; }
.label {
  flex: 0 1 auto; min-height: 0; overflow: hidden;
  margin: 3px 3px 0; padding: 2px 4px 3px;
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 0 5px;
  background: #fbf7ee; color: #2b2118; border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
  font-size: 10px; line-height: 1.25; letter-spacing: -0.03em; word-break: keep-all;
}
.rn { color: #b5523b; font-weight: 800; }
.topic { flex: 0 0 100%; min-width: 0; font-size: 11.5px; font-weight: 700; line-height: 1.25; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.topic .rn { margin-right: 3px; }
.label.tight .topic { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.label:has(.topic) .tp { color: #6b5d4d; }
.tp i { display: inline-block; width: 6px; height: 6px; margin-right: 2px; border-radius: 1px; background: var(--c); vertical-align: 1px; }
.books { flex: 1 0 22%; display: flex; min-height: 8px; }
.tp[hidden] { display: none !important; }
.label.tight .tp { flex: 1 1 0; min-width: 0; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.more { color: #84735f; font-weight: 700; }
.row.none .label { opacity: .35; }
.hits {
  position: absolute; right: 3px; bottom: 3px;
  min-width: 18px; padding: 0 5px; border-radius: 9px; text-align: center;
  background: var(--mark); color: #2b2118; font-size: 10px; font-weight: 700; line-height: 16px;
}
.cell {
  display: flex; align-items: flex-end; min-width: 0; height: 100%;
  padding: 0 calc(var(--u) * 10); overflow: hidden;
  box-shadow: inset 0 calc(var(--u) * 14) calc(var(--u) * 20) rgba(0,0,0,.18);
}
.cell + .cell { border-left: calc(var(--u) * 18) solid var(--divider); }
.cell i {
  flex: 1 1 0; min-width: 0; max-width: calc(var(--u) * 34);
  background: var(--c); border-radius: 1px 1px 0 0;
  transition: opacity .2s;
}
.cell i:nth-child(even) { filter: brightness(1.15); }
.cell i.dim { opacity: .18; }
.cell i.hit { filter: brightness(1.25) saturate(1.2); }
.plinth { flex: 0 0 auto; background: var(--frame); filter: brightness(.82); }

.t-charcoal { --frame: #2e2f33; --inner: #222326; --board: #c8c8c4; --divider: #2e2f33; }
.t-gray     { --frame: #63656b; --inner: #4d4f55; --board: #f3f3f1; --divider: #63656b; }
.t-white    { --frame: #f4f4f1; --inner: #dcdcd8; --board: #fbfbf9; --divider: #f4f4f1; --edge: 0 0 0 1px #cfcfca; }

/* ── 전체 벽 ── */
.wall { display: flex; align-items: flex-end; margin: 14px -3px 0; }
.wall-item { min-width: 0; padding: 0 3px; display: flex; flex-direction: column; }
.case-label {
  display: flex; justify-content: center; gap: 4px; align-items: baseline;
  padding: 5px 0 0; font-size: 13px; white-space: nowrap;
}
.case-label span { color: var(--muted); font-size: 12px; }
.wall-note {
  align-self: center; padding: 0 6px 0 10px;
  display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); line-height: 1.4; word-break: keep-all;
}
.wall-note b { font-size: 20px; color: var(--ink); }
.hint { color: var(--muted); font-size: 14px; margin: 10px 0 12px; text-align: center; }

/* ── 검색 결과 ── */
.results-head { display: flex; gap: 8px; align-items: baseline; margin: 6px 0 8px; }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.results a {
  display: grid; gap: 2px; padding: 12px 14px; border-radius: 12px;
  background: var(--paper); border: 1px solid var(--line); text-decoration: none;
}
.loc { font-size: 13px; color: var(--accent); }
.loc b { font-size: 15px; }
.results .t { font-size: 16px; }
.meta { display: flex; flex-wrap: wrap; gap: 0 10px; font-size: 13px; color: var(--muted); }
.grp::before { content: "#"; opacity: .6; }
.note { font-size: 13px; color: var(--muted); }
mark { background: var(--mark); color: inherit; border-radius: 2px; }

/* ── 줄 패널 ── */
.panel { margin: 14px 0 10px; }
.panel-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.panel-title { order: -1; flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 18px; line-height: 1.3; }
.panel-title span { font-size: 13px; }
.pn, .close {
  width: 38px; height: 38px; display: grid; place-items: center; flex: none;
  border-radius: 10px; border: 1px solid var(--line); background: var(--paper);
  text-decoration: none; font-size: 22px; line-height: 1;
}
.pn.off { visibility: hidden; }

.strip {
  margin: 0 -16px; padding: 0 16px;
  background: var(--frame);
}
.strip-inner {
  position: relative;
  display: flex; align-items: flex-end; gap: 2px;
  min-height: 320px; padding: 16px 10px 0;
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity;
  background: var(--inner);
  border-bottom: 12px solid var(--board);
  box-shadow: inset 0 18px 24px rgba(0,0,0,.25);
}
.spine {
  flex: none; position: relative; display: flex; flex-direction: column; align-items: center; min-width: 26px;
  padding: 10px 0 0; border: 0; border-radius: 2px 2px 0 0; cursor: pointer;
  background: linear-gradient(90deg, rgba(0,0,0,.22), rgba(255,255,255,.10) 35%, rgba(0,0,0,0) 60%, rgba(0,0,0,.2)), var(--c);
  color: var(--tc); scroll-snap-align: center;
  transition: opacity .2s, transform .15s;
}
.spine::before, .spine::after {
  content: ""; position: absolute; left: 3px; right: 3px; height: 1px; background: currentColor; opacity: .35;
}
.spine::before { top: 5px; } .spine::after { bottom: 26px; }
.spine-t {
  writing-mode: vertical-rl; text-orientation: mixed;
  font-size: 12.5px; line-height: 1.2; letter-spacing: .02em; word-break: keep-all; overflow-wrap: anywhere;
}
.spine-n {
  margin: 4px 0 4px; min-width: 18px; padding: 1px 2px; border-radius: 2px;
  background: #f6efe0; color: #2b2118; font-size: 10px; line-height: 1.2; text-align: center;
}
.spine-flags { position: absolute; top: 0; left: 0; right: 0; display: flex; flex-direction: column; }
.spine-flags em { display: block; height: 5px; }
.f-toss { background: var(--toss); } .f-box { background: var(--box); } .f-sell { background: var(--sell); } .f-unk { background: var(--unk); }
.spine.dim { opacity: .25; }
.spine.focus { transform: translateY(-10px); box-shadow: 0 0 0 2px var(--mark), 0 6px 10px rgba(0,0,0,.35); }
.bookend {
  flex: none; align-self: flex-end; min-width: 24px; height: 160px; margin: 0 4px;
  display: flex; justify-content: center; padding: 8px 0;
  background: var(--board); color: #555; border-radius: 3px 3px 0 0; opacity: .92;
}
.bookend span { writing-mode: vertical-rl; height: 144px; font-size: 11px; line-height: 1.2; word-break: keep-all; padding: 0 3px; }

.booklist { margin-top: 16px; }
.group h4 {
  display: flex; align-items: center; gap: 8px; margin: 18px 0 6px; font-size: 15px;
}
.group h4 small { font-weight: normal; color: var(--muted); font-size: 12px; }
.dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.group ol { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.group li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start;
  padding: 10px 12px; border-top: 1px solid var(--line); cursor: pointer; scroll-margin: 140px 0;
  transition: background .3s, opacity .2s;
}
.group li:first-child { border-top: 0; }
.group li.dim { opacity: .4; }
.group li.focus { background: color-mix(in srgb, var(--mark) 45%, var(--paper)); }
.no {
  min-width: 26px; height: 22px; padding: 0 4px; border-radius: 4px; margin-top: 1px;
  display: grid; place-items: center; font-size: 12px; font-variant-numeric: tabular-nums;
  background: var(--c); color: var(--tc);
}
.info { display: grid; min-width: 0; }
.info .t { font-weight: 600; word-break: keep-all; overflow-wrap: anywhere; }
.info .au { font-size: 13px; color: var(--muted); }
.badges { display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; color: #fff; white-space: nowrap; }
.b-toss { background: var(--toss); } .b-box { background: var(--box); } .b-sell { background: var(--sell); } .b-unk { background: var(--unk); }
.results .note .badge { margin-right: 2px; }

/* ── 로그인 ── */
.login { max-width: 320px; margin: 18vh auto 0; display: grid; gap: 10px; text-align: center; justify-items: center; }
.login h2 { margin: 6px 0 0; }
.login p { margin: 0; }
.login input, .login button { width: 100%; height: 46px; border-radius: 12px; font-size: 16px; }
.login input { border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 0 14px; text-align: center; }
.login button { border: 0; background: var(--ink); color: var(--bg); cursor: pointer; }
.err { color: var(--accent); min-height: 1.5em; }

/* ── 아래 ── */
footer { margin-top: 28px; text-align: center; font-size: 12px; color: var(--muted); }
#refresh { margin-left: 6px; border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 2px 10px; font-size: 12px; cursor: pointer; }

@media (min-width: 760px) {
  body { max-width: 1100px; }
  .wall { margin: 18px -6px 0; }
  .wall-item { padding: 0 6px; }
  .label { font-size: 11.5px; margin: 5px 5px 0; padding: 3px 6px 4px; }
  .topic { font-size: 13.5px; }
  .case-label { font-size: 15px; }
}

/* ── 버리기 ── */
.top-right { display: flex; align-items: baseline; gap: 10px; }
.trash-link {
  font-size: 13px; text-decoration: none; padding: 4px 10px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--paper); color: var(--muted);
}
.trash-link b { color: var(--ink); margin-left: 2px; }
.side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.discard-btn {
  height: 28px; padding: 0 10px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--paper);
  color: var(--accent); font-size: 12.5px;
}
.discard-btn:active { background: color-mix(in srgb, var(--accent) 15%, var(--paper)); }
.discard-btn:disabled { opacity: .4; }
.results li { position: relative; }
.results li > .discard-btn { position: absolute; top: 10px; right: 10px; z-index: 1; }
.results li > a { padding-right: 84px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(24px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: #2b2118; color: #fffbf4; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.toast[hidden] { display: none; }
.toast button { flex: none; white-space: nowrap; border: 0; background: none; color: #ffd27a; font-weight: 700; cursor: pointer; font-size: 14px; padding: 4px; }

/* ── 버린 책 화면 ── */
.trash-nav { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 6px; }
.back { text-decoration: none; color: var(--muted); font-size: 15px; padding: 6px 0; }
.trash-title { margin: 4px 0 10px; font-size: 22px; display: flex; gap: 8px; align-items: baseline; }
.trash-title span { font-size: 14px; font-weight: normal; }
.hint.left { text-align: left; margin: 0 0 8px; }
.trash-list { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.trash-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-top: 1px solid var(--line); }
.trash-list li:first-child { border-top: 0; }
.trash-list .info { flex: 1; }
.trash-list .t { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.loc-was { font-size: 12.5px; color: var(--muted); }
.tr-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.restore { height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 13px; white-space: nowrap; }
.b-insheet { background: var(--muted); }

/* 검색 결과 속 방출한 책 */
.gone-head { margin-top: 18px; }
.results.gone a { background: color-mix(in srgb, var(--muted) 10%, var(--paper)); border-style: dashed; }
.results.gone .t { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.results.gone .loc { color: var(--muted); }
.note.why { color: var(--ink); }
