/* Tablet viewer: header, photo, caption, buttons in the same order in both orientations.
   Portrait stacks them; landscape puts the caption beside the photo. Buttons always at the bottom. */
body.viewer { background: var(--book); overflow: hidden; }

.book {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  gap: 12px;
}

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 48px; }
.when { font-size: clamp(1.3rem, 3vw, 1.9rem); color: var(--muted); }
.ov-open {
  font-size: 1rem; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
}

.page { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 14px; }
/* Portrait: the photo sits right above its caption; spare height goes above it, not between them. */
.photo { min-height: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.photo img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; display: block; }
.caption {
  margin: 0; font-weight: 700; line-height: 1.25; text-wrap: balance; overflow-wrap: anywhere;
  font-size: clamp(2rem, 4.6vw, 3rem);
  max-height: 34vh; overflow-y: auto;
}
.caption.long { font-size: clamp(1.6rem, 3.4vw, 2.2rem); }

@media (orientation: landscape) {
  .photo { align-items: center; }
  .page { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr); align-items: center; }
  .caption { font-size: clamp(2rem, 3.4vw, 3rem); max-height: 100%; }
  .caption.long { font-size: clamp(1.5rem, 2.4vw, 2rem); }
  .page { min-height: 0; }
}

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.controls button {
  font-size: clamp(1.4rem, 3.4vw, 2rem); font-weight: 700;
  min-height: 84px; padding: 16px; border-radius: 18px; border: 3px solid var(--accent);
}
.earlier { background: var(--accent); color: var(--accent-ink); }
.later { background: var(--surface); color: var(--accent); }

.overview {
  position: fixed; inset: 0; background: var(--book); overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 20px 32px; display: grid; gap: 12px; align-content: start;
}
.ov-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.ov-head h2 { margin: 0; font-size: 1.8rem; }
.ov-close {
  font-size: 1.2rem; font-weight: 700; padding: 14px 18px; border-radius: 14px;
  border: 2px solid var(--accent); background: var(--accent); color: var(--accent-ink);
}
.ov-label { color: var(--muted); }
#ov-search { font-size: 1.2rem; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); width: 100%; }
.ov-month { font-size: 1.3rem; font-weight: 700; margin: 18px 0 8px; }
.ov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr)); gap: 12px; }
.ov-item {
  display: grid; gap: 6px; text-align: left; padding: 0; border: 0; background: transparent; font-size: 1rem; line-height: 1.3;
}
.ov-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; display: block; background: var(--line); }
.ov-empty { color: var(--muted); font-size: 1.1rem; }

.unavailable { font-size: clamp(1.4rem, 3vw, 2rem); color: var(--muted); text-align: center; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.notice { height: 100%; display: grid; place-content: center; text-align: center; padding: 24px; font-size: 1.2rem; color: var(--muted); }
.notice-big { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 700; color: var(--ink); margin: 0 0 12px; }
.notice a { color: var(--accent); }
