:root {
  --black: #000000;
  --white: #ffffff;
  --gray-100: #f3f3f3;
  --gray-200: #dedede;
  --gray-600: #555555;
  --red: #ea4f3d;
  --turquoise: #009ba4;
  --purple: #524e9c;
  --lime: #d2d100;
  --header-height: 112px;
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 18px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--black);
  background: var(--gray-100);
  line-height: 1.5;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 10px;
  left: 10px;
  padding: 12px 16px;
  color: var(--white);
  background: var(--black);
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.site-header {
  display: flex;
  min-height: var(--header-height);
  padding: 22px clamp(20px, 4vw, 64px);
  align-items: center;
  justify-content: space-between;
  gap: 36px;
  color: var(--black);
  background: var(--white);
}

.brand { display: flex; align-items: center; flex: 0 0 auto; }
.brand img {
  display: block;
  width: min(320px, 30vw);
  height: auto;
}

.title-block { text-align: right; }
.title-block p {
  margin: 0 0 2px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.title-block h1 { margin: 0; font-size: clamp(24px, 2.7vw, 38px); line-height: 1.1; }

.accent-line { display: grid; grid-template-columns: repeat(4, 1fr); height: 7px; }
.accent-line span:nth-child(1) { background: var(--red); }
.accent-line span:nth-child(2) { background: var(--lime); }
.accent-line span:nth-child(3) { background: var(--purple); }
.accent-line span:nth-child(4) { background: var(--turquoise); }

.toolbar {
  position: sticky;
  z-index: 50;
  top: 0;
  display: flex;
  min-height: 70px;
  padding: 9px clamp(12px, 3vw, 40px);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid var(--black);
  color: var(--white);
  background: var(--black);
}

.toolbar-group { display: flex; align-items: center; gap: 8px; white-space: nowrap; }

.tool-button {
  display: inline-flex;
  min-height: 48px;
  padding: 9px 14px;
  border: 2px solid var(--white);
  border-radius: 0;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--white);
  background: var(--black);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.tool-button:hover { color: var(--black); background: var(--lime); }
.tool-button:disabled { border-color: #777; color: #aaa; cursor: not-allowed; }
.tool-button:disabled:hover { color: #aaa; background: var(--black); }
.icon-button { min-width: 48px; padding-right: 10px; padding-left: 10px; font-size: 24px; }

.toolbar label, #pageCount, #zoomValue { font-size: 17px; font-weight: 700; }
#zoomValue { min-width: 60px; text-align: center; }
#pageInput {
  width: 68px;
  min-height: 48px;
  padding: 5px 7px;
  border: 2px solid var(--white);
  color: var(--black);
  background: var(--white);
  font-weight: 700;
  text-align: center;
}

button:focus-visible, a:focus-visible, input:focus-visible, #bookViewport:focus-visible {
  outline: 4px solid var(--turquoise);
  outline-offset: 3px;
}

.viewer-shell { position: relative; display: flex; min-height: calc(100vh - 189px); }

.book-viewport {
  position: relative;
  width: 100%;
  min-width: 0;
  padding: clamp(24px, 4vw, 56px) clamp(58px, 6vw, 92px);
  overflow: auto;
  background: var(--gray-100);
  overscroll-behavior: contain;
}

.book-spread {
  display: flex;
  width: 100%;
  max-width: 1380px;
  margin: 0 auto;
  align-items: flex-start;
  justify-content: center;
  transform-origin: top center;
}

.book-spread.is-cover .book-page { flex: 0 1 620px; }

.book-page {
  position: relative;
  min-width: 0;
  margin: 0;
  flex: 1 1 50%;
  background: var(--white);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .2);
}

.book-page + .book-page { border-left: 1px solid #999; }
.book-page img { display: block; width: 100%; height: auto; background: var(--white); }
.book-page figcaption {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 3px 8px;
  color: var(--white);
  background: rgba(0, 0, 0, .78);
  font-size: 14px;
  font-weight: 700;
}

.stage-nav {
  position: fixed;
  z-index: 20;
  top: 54%;
  width: 54px;
  height: 76px;
  border: 0;
  color: var(--white);
  background: var(--black);
  font-size: 54px;
  line-height: 1;
  cursor: pointer;
}
.stage-nav:hover { color: var(--black); background: var(--lime); }
.stage-nav:disabled { display: none; }
.stage-nav--prev { left: 0; }
.stage-nav--next { right: 0; }

.thumbnail-panel {
  position: fixed;
  z-index: 100;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(410px, 90vw);
  padding: 0 18px 24px;
  overflow: auto;
  border-right: 4px solid var(--black);
  background: var(--white);
  box-shadow: 10px 0 30px rgba(0, 0, 0, .25);
}

.thumbnail-heading {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  margin: 0 -18px 18px;
  padding: 14px 18px;
  align-items: center;
  justify-content: space-between;
  color: var(--white);
  background: var(--black);
}
.thumbnail-heading h2 { margin: 0; font-size: 26px; }
.thumbnail-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.thumbnail-button {
  min-width: 0;
  padding: 8px;
  border: 3px solid transparent;
  color: var(--black);
  background: var(--gray-100);
  font-weight: 700;
  cursor: pointer;
}
.thumbnail-button:hover { border-color: var(--turquoise); }
.thumbnail-button[aria-current="page"] { border-color: var(--black); box-shadow: 0 0 0 4px var(--lime); }
.thumbnail-button img { display: block; width: 100%; height: auto; margin-bottom: 6px; background: var(--gray-200); }

.viewer-footer { padding: 18px clamp(20px, 4vw, 64px); border-top: 1px solid #bbb; background: var(--white); }
.viewer-footer p { margin: 0; font-size: 17px; }

dialog {
  width: min(620px, calc(100vw - 32px));
  padding: 0 30px 30px;
  border: 4px solid var(--black);
  color: var(--black);
  background: var(--white);
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
.dialog-accent { height: 8px; margin: 0 -30px 24px; background: var(--red); }
dialog h2 { margin: 0 0 20px; font-size: 32px; }
dialog dl { margin: 0 0 24px; }
dialog dl div { display: grid; grid-template-columns: 130px 1fr; padding: 10px 0; border-bottom: 1px solid #bbb; }
dialog dt { font-weight: 800; }
dialog dd { margin: 0; }
.dialog-close { min-height: 50px; padding: 10px 18px; border: 2px solid var(--black); color: var(--white); background: var(--black); font-weight: 700; cursor: pointer; }
.dialog-close:hover { color: var(--black); background: var(--lime); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1100px) {
  .toolbar { overflow-x: auto; justify-content: flex-start; }
  .toolbar-actions { margin-left: auto; }
}

@media (max-width: 800px) {
  :root { font-size: 18px; --header-height: auto; }
  .site-header { min-height: 0; padding: 18px 20px; align-items: flex-start; }
  .brand img { width: min(220px, 38vw); }
  .title-block p { font-size: 14px; }
  .title-block h1 { font-size: 22px; }
  .toolbar { min-height: 68px; padding: 8px 10px; }
  .toolbar .tool-button { min-height: 50px; }
  .toolbar .tool-button:not(.icon-button) { font-size: 16px; }
  .toolbar-actions { margin-left: 0; }
  .book-viewport { padding: 22px 48px; }
  .book-spread { max-width: 680px; }
  .book-page { flex-basis: 100%; }
  .book-page + .book-page { border-left: 0; }
  .stage-nav { top: 56%; width: 42px; height: 68px; font-size: 44px; }
  .viewer-footer p { font-size: 16px; }
}

@media (max-width: 520px) {
  .site-header { gap: 16px; }
  .brand img { width: min(150px, 38vw); }
  .title-block h1 { font-size: 19px; }
  .title-block p { display: none; }
  .book-viewport { padding: 16px 34px; }
  .stage-nav { width: 32px; height: 60px; font-size: 38px; }
  .thumbnail-list { grid-template-columns: repeat(2, 1fr); }
  dialog dl div { grid-template-columns: 105px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .accent-line, .dialog-accent { forced-color-adjust: none; }
}
