:root {
  --paper: #f6f0e4;
  --ink: #2b2420;
  --muted: #7a6d62;
  --rose: #a8324a;
  --rose-soft: #e9c9cf;
  --line: #ddd2c0;
  --card: #fffdf8;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.masthead { border-bottom: 3px double var(--ink); background: var(--card); }
.masthead-inner { max-width: 1200px; margin: 0 auto; padding: 28px 20px 18px; text-align: center; }
.masthead h1 { font-family: var(--serif); font-size: clamp(30px, 5vw, 52px); margin: 0; letter-spacing: .01em; }
.masthead .sub { font-family: var(--serif); font-style: italic; margin: 6px 0 4px; color: var(--muted); font-size: 18px; }
.masthead .stats { margin: 6px 0 0; font-size: 14px; color: var(--muted); }

.controls { max-width: 1200px; margin: 18px auto 0; padding: 0 20px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.search { flex: 1 1 360px; display: flex; gap: 8px; }
.search input { flex: 1; padding: 11px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 16px; }
.search input:focus { outline: 2px solid var(--rose-soft); border-color: var(--rose); }
.sort { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
.sort select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; }
.ghost:hover { border-color: var(--rose); color: var(--rose); }

.timeline-wrap { max-width: 1200px; margin: 18px auto 0; padding: 14px 20px 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
@media (min-width: 1240px) { .timeline-wrap { padding: 14px 20px 8px; } }
.timeline-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.tl-buttons { display: flex; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip.on { background: var(--rose); border-color: var(--rose); color: #fff; }
.timeline { display: flex; align-items: flex-end; gap: 2px; height: 120px; overflow-x: auto; padding-bottom: 2px; }
.year { flex: 1 0 9px; min-width: 9px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; background: none; border: 0; padding: 0; position: relative; }
.year .bar { background: #c9a9a0; border-radius: 2px 2px 0 0; min-height: 2px; transition: background .15s; }
.year.empty .bar { background: var(--line); }
.year.dim .bar { background: #e6dccd; }
.year:hover .bar, .year:focus-visible .bar { background: var(--rose); }
.year.on .bar { background: var(--rose); }
.year .tip { display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 12px; padding: 3px 7px; border-radius: 4px; white-space: nowrap; pointer-events: none; z-index: 2; }
.year:hover .tip, .year:focus-visible .tip { display: block; }
.decades { position: relative; height: 18px; font-size: 11px; color: var(--muted); }
.decades span { position: absolute; transform: translateX(-2px); }

main { max-width: 1200px; margin: 0 auto; padding: 8px 20px 60px; }
.summary { color: var(--muted); font-size: 14px; margin: 14px 0 6px; }
.group h3 { font-family: var(--serif); font-size: 26px; margin: 22px 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.group h3 small { font-family: var(--sans); font-size: 13px; color: var(--muted); font-weight: normal; margin-left: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; text-align: left; padding: 0; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; }
.card:hover, .card:focus-visible { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(60, 40, 20, .15); outline: none; border-color: var(--rose); }
.card .thumb { aspect-ratio: 4 / 5; background: #eee6d8; overflow: hidden; }
.card img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.card .cap { padding: 8px 10px 10px; font-size: 13px; }
.card .cap b { display: block; font-size: 14px; }
.card .cap .q { color: var(--muted); font-size: 12px; }
.card .snip { margin-top: 6px; font-size: 12px; color: var(--ink); line-height: 1.35; max-height: 4.2em; overflow: hidden; }
mark { background: #ffe08a; color: inherit; padding: 0 1px; border-radius: 2px; }
.empty-msg { padding: 40px 0; text-align: center; color: var(--muted); }

.viewer { position: fixed; inset: 0; z-index: 50; display: flex; background: #1d1916; }
.viewer[hidden] { display: none; }
.stage { position: relative; flex: 1; overflow: hidden; cursor: grab; touch-action: none; }
.stage.dragging { cursor: grabbing; }
.stage img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; max-width: none; box-shadow: 0 4px 30px rgba(0, 0, 0, .5); background: #fff; }
.zoombar { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; gap: 6px; background: rgba(0, 0, 0, .55); padding: 6px; border-radius: 10px; }
.zoombar button { background: #fff; border: 0; border-radius: 6px; min-width: 40px; height: 36px; font-size: 18px; }
.nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, .85); border: 0; width: 44px; height: 64px; font-size: 34px; border-radius: 6px; color: var(--ink); }
.nav.prev { left: 12px; } .nav.next { right: 12px; }
.nav:disabled { opacity: .25; cursor: default; }
.panel { width: 360px; max-width: 42vw; background: var(--card); overflow-y: auto; padding: 14px 18px 30px; border-left: 1px solid #000; }
.panel-top { display: flex; justify-content: flex-end; }
.panel h2 { font-family: var(--serif); font-size: 26px; margin: 10px 0 4px; }
.how { margin: 0; color: var(--muted); font-size: 13px; }
.meta { font-size: 13px; color: var(--muted); }
.pages { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.pages button { border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: 4px 10px; font-size: 13px; }
.pages button.on { background: var(--rose); color: #fff; border-color: var(--rose); }
details summary { cursor: pointer; font-weight: 600; font-size: 14px; margin-top: 10px; }
details .note { font-weight: normal; color: var(--muted); font-size: 12px; }
.ocr { white-space: pre-wrap; font-family: var(--serif); font-size: 14px; line-height: 1.5; margin-top: 8px; }

@media (max-width: 760px) {
  .viewer { flex-direction: column; }
  .panel { width: 100%; max-width: none; height: 38vh; border-left: 0; border-top: 1px solid #000; }
  .nav { width: 36px; height: 52px; font-size: 26px; }
}
