/*
 * Writing Nights | Editorial Reader v8
 * A restrained presentation inspired by the typography, warmth and negative
 * space of the Writing Nights site.  Presentation only: no changes to paging,
 * PDF delivery, or the HTML interface expected by reader.js.
 */
:root {
  color-scheme: light;
  font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  --wn-ink: #22211f;
  --wn-secondary: #817b74;
  --wn-accent: #dd5d24;
  --wn-line: #e7e3df;
  --wn-mat: #f6f5f3;
  --wn-white: #fff;
}
* { box-sizing: border-box; }
html, body { height: 100%; width: 100%; margin: 0; }
body { background: #fff; color: var(--wn-ink); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--wn-accent);
  outline-offset: 3px;
}

/* FRAME: an extension of the Blogger card, not a competing UI. */
.reader {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: 370px;
  overflow: hidden;
  background: var(--wn-white);
  border: 1px solid #e6e1dc;
  border-radius: 14px;
}
.top-bar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 48px;
  min-height: 48px;
  padding: 5px clamp(15px, 3.5vw, 26px);
  background: #fff;
  border-bottom: 1px solid var(--wn-line);
}
.preview-caption {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
  color: #77726d;
  letter-spacing: .155em;
  text-transform: uppercase;
  white-space: nowrap;
}
.preview-caption-rule {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: var(--wn-accent);
}
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #77716a;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  transition: background .2s ease, border-color .2s ease, color .2s ease;
}
.icon-button svg { width: 16px; height: 16px; display: block; }
.icon-button:hover {
  color: var(--wn-accent);
  background: #f8f5f1;
  border-color: #ece2d9;
}

/* In Author Story modals the Blogger dialog already labels the preview. */
.reader[data-layout="spread"] .top-bar {
  flex-basis: 40px;
  min-height: 40px;
  justify-content: flex-end;
  background: #fff;
}
.reader[data-layout="spread"] .preview-caption { display: none; }

/* READING MAT: visible air above and below a proportionally scaled book. */
.book-stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  padding: clamp(24px, 4.5vh, 38px) clamp(20px, 4.5vw, 48px) 82px;
  background: radial-gradient(ellipse 90% 72% at 50% 45%, #fbfaf9 0%, #f7f6f4 56%, #f3f1ee 100%);
}
.reader[data-layout="spread"] .book-stage {
  padding: clamp(18px, 3.5vh, 30px) clamp(12px, 2.5vw, 28px) 68px;
}
/* A barely visible divider separates the display surface from navigation. */
.book-stage::after {
  content: '';
  position: absolute;
  bottom: 64px;
  left: clamp(20px, 5vw, 48px);
  right: clamp(20px, 5vw, 48px);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(128,118,106,.17) 22%, rgba(128,118,106,.17) 78%, transparent);
  pointer-events: none;
}
.reader[data-layout="spread"] .book-stage::after { bottom: 56px; }
#book {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  max-width: 1160px;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
}
.page {
  overflow: hidden;
  background: #fff;
  box-shadow: inset 0 0 1px rgba(0,0,0,.08);
}
.page[data-density="hard"] {
  box-shadow: 0 20px 38px rgba(43,36,30,.13), 0 5px 12px rgba(43,36,30,.08), 0 0 1px rgba(0,0,0,.06);
}
.page .pdf-page { display: block; width: 100%; height: 100%; object-fit: contain; }
.page .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #fff;
  color: #b3aea8;
  font-size: 12px;
}
.page .placeholder[hidden] { display: none; }

/* NAVIGATION: low-contrast controls resting in the mat, not a toolbar. */
.nav-rail {
  position: absolute;
  z-index: 4;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}
.nav-rail-prev { left: clamp(14px, 3vw, 30px); }
.nav-rail-next { right: clamp(14px, 3vw, 30px); }
.nav-icon {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  padding: 0;
  color: #5f5954;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: border-color .18s ease, color .18s ease, background .18s ease;
}
.nav-icon svg {
  display: block;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-icon:not(:disabled):hover {
  color: var(--wn-accent);
  background: rgba(255,255,255,.82);
  border-color: #e4dad1;
}
.nav-icon:disabled { opacity: .28; }
.nav-icon:active:not(:disabled) { background: #eee8e2; }
.page-position {
  position: absolute;
  z-index: 4;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: #8b837a;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .07em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

/* ERRORS / LOADING */
.status-overlay {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  background: rgba(248,247,245,.97);
  color: var(--wn-secondary);
  font-size: 13px;
  text-align: center;
}
.status-overlay[hidden] { display: none; }
.status-overlay.error { color: #8a3131; }
.status-overlay.error .spinner { display: none; }
.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid #e4dfd9;
  border-top-color: var(--wn-accent);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* RESPONSIVE: the controls stay usable, the book keeps its 6 x 9 ratio. */
@media (max-width: 660px) {
  .reader { border-radius: 12px; }
  .top-bar { flex-basis: 43px; min-height: 43px; padding: 4px 13px; }
  .preview-caption { font-size: 9px; letter-spacing: .13em; gap: 8px; }
  .preview-caption-rule { width: 16px; }
  .reader[data-layout="spread"] .top-bar { flex-basis: 37px; min-height: 37px; }
  .book-stage { padding: 22px 18px 76px; }
  .reader[data-layout="spread"] .book-stage { padding: 16px 12px 62px; }
  .book-stage::after { bottom: 59px; left: 18px; right: 18px; }
  .reader[data-layout="spread"] .book-stage::after { bottom: 51px; }
  .nav-rail { bottom: 9px; gap: 1px; }
  .nav-rail-prev { left: 10px; }
  .nav-rail-next { right: 10px; }
  .nav-icon { width: 34px; height: 36px; }
  .page-position { bottom: 22px; font-size: 9px; letter-spacing: .03em; }
}
@media (max-height: 540px) and (min-width: 661px) {
  .top-bar { flex-basis: 38px; min-height: 38px; }
  .book-stage { padding-top: 13px; padding-bottom: 64px; }
  .book-stage::after { bottom: 53px; }
  .reader[data-layout="spread"] .book-stage { padding-top: 8px; padding-bottom: 59px; }
  .nav-rail { bottom: 6px; }
  .page-position { bottom: 19px; }
}
.reader:fullscreen { border: 0; border-radius: 0; height: 100dvh; }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  .icon-button, .nav-icon { transition: none; }
}
