:root {
  color-scheme: light;
  --brand-yellow: #ffd400;
  --brand-dark: #3f3100;
  --brand-gold: #ffea61;
  --brand-red: #b52d32;
  --brand-green: #1f7a50;
  
  --paper: #ffffff;
  --workspace: #f3f1ec;
  --border: #d9e0e8;
  --text: #17212e;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--workspace);
  font-family: "Montserrat", Arial, sans-serif;
}
button, input, select { font: inherit; }
button, select, input, a { -webkit-tap-highlight-color: transparent; }

.reader-header {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 10px clamp(16px, 3vw, 42px);
  color: #fff;
  background: var(--brand-dark);
  border-bottom: 3px solid var(--brand-yellow);
}
.reader-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}
.reader-brand img { flex: 0 0 auto; object-fit: contain; }
.reader-brand span { display: grid; gap: 2px; }
.reader-brand small {
  color: var(--brand-gold);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.reader-brand strong { font-size: clamp(1rem, 2vw, 1.25rem); letter-spacing: -.02em; }
.back-link, .reader-footer a {
  color: inherit;
  font-size: .8rem;
  font-weight: 700;
  text-underline-offset: 3px;
}

.reader-toolbar {
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto minmax(170px, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 8px clamp(12px, 2vw, 28px);
  background: var(--brand-yellow);
  border-bottom: 4px solid var(--brand-dark);
  box-shadow: 0 2px 9px rgb(16 35 59 / 10%);
}
.section-control { justify-self: start; }
.section-control select {
  width: min(250px, 100%);
  min-height: 38px;
  padding: 0 32px 0 11px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.page-controls, .zoom-controls, .page-number { display: flex; align-items: center; }
.page-controls, .zoom-controls { gap: 6px; }
.zoom-controls { justify-self: end; }
.reader-toolbar button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  color: var(--brand-dark);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
}
.reader-toolbar button:hover:not(:disabled),
.reader-toolbar button:focus-visible,
.section-control select:focus-visible,
.page-number input:focus-visible {
  color: #fff;
  background: var(--brand-red);
  border-color: var(--brand-red);
  outline: 3px solid rgb(181 45 50 / 22%);
  outline-offset: 1px;
}
.reader-toolbar button:disabled { opacity: .4; cursor: not-allowed; }
.page-number {
  min-width: 104px;
  justify-content: center;
  gap: 7px;
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}
.page-number input {
  width: 48px;
  height: 34px;
  padding: 0 4px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 5px;
  -moz-appearance: textfield;
}
.page-number input::-webkit-inner-spin-button,
.page-number input::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
#zoom-level { min-width: 50px; text-align: center; font-size: .72rem; font-weight: 700; }

.reader-stage {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  min-height: 0;
  padding: clamp(16px, 3vw, 34px);
  overflow: auto;
  overscroll-behavior: contain;
  background-color: var(--workspace);
  background-image: radial-gradient(rgb(63 49 0 / 10%) .7px, transparent .7px);
  background-size: 8px 8px;
}
.page-sheet {
  flex: 0 0 auto;
  width: min(1080px, calc(100vw - 48px));
  margin: auto;
  overflow: hidden;
  background: var(--paper);
  border-radius: 2px;
  box-shadow: 0 10px 34px rgb(21 34 49 / 27%);
}
.page-sheet img { display: block; width: 100%; height: auto; transition: opacity .16s ease; }
.page-sheet img.is-loading { opacity: .35; }
.loading-message {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  margin: 0;
  padding: 10px 14px;
  transform: translate(-50%, -50%);
  color: #fff;
  background: rgb(63 49 0 / 92%);
  border-radius: 7px;
  font-size: .78rem;
  font-weight: 700;
}
.loading-message[hidden] { display: none; }
.reader-footer {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 6px clamp(16px, 3vw, 42px);
  color: #fff8cf;
  background: var(--brand-dark);
  font-size: .75rem;
  font-weight: 700;
}
.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: 720px) {
  .reader-header { min-height: 62px; }
  .reader-brand img { width: 40px; height: 40px; }
  .reader-brand small, .back-link { display: none; }
  .reader-toolbar { grid-template-columns: 1fr auto; }
  .section-control { grid-column: 1 / -1; justify-self: stretch; }
  .section-control select { width: 100%; }
  .page-controls { justify-self: start; }
  .zoom-controls { justify-self: end; }
  #fullscreen { display: none; }
  .reader-stage { padding: 14px; }
  .page-sheet { width: calc(100vw - 28px); }
}
@media (max-width: 390px) {
  #zoom-level { display: none; }
  .page-number { min-width: 94px; }
}
@media (prefers-reduced-motion: reduce) {
  .page-sheet img { transition: none; }
}
