:root {
  --navy: #0f2747;
  --blue: #1d4ed8;
  --ink: #111827;
  --muted: #60708a;
  --line: #d7e2f2;
  --soft: #f4f7fc;
  --white: #ffffff;
  --shadow: 0 12px 34px rgba(15, 39, 71, 0.12);
}

* { box-sizing: border-box; }
html {
  color-scheme: light;
  scrollbar-color: #d6aa32 #0f2747;
  scrollbar-width: thin;
}
html::-webkit-scrollbar { width: 10px; height: 10px; }
html::-webkit-scrollbar-track { background: #0f2747; }
html::-webkit-scrollbar-thumb {
  border: 2px solid #0f2747;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe98b, #d6aa32);
}
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Rubik', Arial, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

html.embedded-viewer,
html.embedded-viewer body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
html.embedded-viewer .workbook-shell {
  width: 100%;
  height: 100%;
  padding: 0;
}
html.embedded-viewer .viewer-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
html.embedded-viewer .page-toolbar { flex: 0 0 auto; }
html.embedded-viewer #bookFrame {
  flex: 1 1 0;
  height: auto;
  min-height: 0;
}
html.embedded-viewer .credits { display: none; }

a, button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }

.action-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex-wrap: wrap;
  padding: 7px 10px;
  background: rgba(255,255,255,.98);
  border-bottom: 2px solid var(--navy);
  box-shadow: 0 3px 14px rgba(15,39,71,.07);
  backdrop-filter: blur(10px);
}

.print-menu-wrap { position: relative; }

.button,
.page-button,
.print-option {
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--navy);
  background: #fff;
  font-weight: 600;
  text-decoration: none;
  touch-action: manipulation;
}

.button.primary {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.button:hover,
.page-button:hover:not(:disabled),
.print-option:hover {
  border-color: var(--blue);
  background: #f8fbff;
}

.button.primary:hover {
  color: #fff;
  background: #1e40af;
}

.button:focus-visible,
.page-button:focus-visible,
.print-option:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(37,99,235,.28);
  outline-offset: 2px;
}

.print-menu {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  width: max-content;
  min-width: 168px;
  padding: 5px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(15,39,71,.16);
}

.print-menu[hidden] { display: none; }

.print-option {
  width: 100%;
  text-align: right;
  white-space: nowrap;
  border-color: transparent;
  background: #fff;
}

.workbook-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 12px;
}

.viewer-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
}

.page-toolbar {
  min-height: 52px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  background: #f8fbff;
}

.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: .88rem;
}

.page-jump input {
  width: 62px;
  min-height: 36px;
  padding: 5px 7px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--navy);
  font-weight: 700;
}

#bookFrame {
  display: block;
  width: 100%;
  height: calc(100dvh - 122px);
  min-height: 680px;
  border: 0;
  background: #fff;
}

.viewer-fallback {
  min-height: 360px;
  padding: 30px 16px;
  display: grid;
  place-items: center;
  background: #f8fbff;
}

.viewer-fallback[hidden] { display: none; }

.credits {
  padding: 11px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: center;
  color: var(--navy);
  background: #fff;
  border-top: 2px solid var(--blue);
  font-size: .8rem;
}
.credits span { color: var(--muted); }

.viewer-panel:fullscreen {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100dvh;
  border: 0;
  border-radius: 0;
}
.viewer-panel:fullscreen #bookFrame {
  flex: 1;
  min-height: 0;
  height: auto;
}

@media (max-width: 620px) {
  .action-bar {
    position: relative;
    gap: 5px;
    padding: 6px;
  }

  .button,
  .page-button,
  .print-option {
    min-height: 36px;
    padding: 6px 9px;
    font-size: .86rem;
  }

  .print-menu { min-width: 154px; }
  .workbook-shell { padding: 0; }

  .viewer-panel {
    border-inline: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .page-toolbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 5px;
    padding: 6px;
  }

  #prevPage { grid-column: 1; }
  .page-jump { grid-column: 2; white-space: nowrap; }
  #nextPage { grid-column: 3; }
  .page-button { width: 100%; }

  .page-jump input {
    width: 52px;
    min-height: 34px;
  }

  #bookFrame {
    height: calc(100dvh - 104px);
    min-height: 520px;
  }

  .credits {
    font-size: .74rem;
    padding-inline: max(10px, env(safe-area-inset-left));
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .action-bar { position: relative; }
  #bookFrame {
    height: calc(100dvh - 96px);
    min-height: 260px;
  }
}

@media (min-width: 1500px) {
  .workbook-shell { max-width: 1400px; }
}
