@charset "UTF-8";

/* Vollkorn font files are not present in static assets.
 * Keeping these disabled avoids 404s until the files are added. */
/*
@font-face {
  font-family: "Vollkorn";
  font-weight: 400;
  font-style: normal;
  src: url("../font/Vollkorn-Regular.woff2") format("woff2");
}

@font-face {
  font-family: "Vollkorn";
  font-weight: 400;
  font-style: italic;
  src: url("../font/Vollkorn-Italic.woff2") format("woff2");
}

@font-face {
  font-family: "Vollkorn";
  font-weight: 500;
  font-style: normal;
  src: url("../font/Vollkorn-Semibold.woff2") format("woff2");
}

@font-face {
  font-family: "Vollkorn";
  font-weight: 500;
  font-style: italic;
  src: url("../font/Vollkorn-SemiboldItalic.woff2") format("woff2");
}
*/

/* Font-face declarations for OpenDyslexic and Bionic Reading are now in reader.html template using {% static %} tag */

*, *:before, *:after {
  text-rendering: optimizelegibility;
  box-sizing: border-box;
}

:root {
  --base-unit: 5vh;
  --column-width: 50vw;
}

@supports (width: clamp(28px, 5vh, 48px)) {
  :root {
    --base-unit: clamp(28px, 5vh, 48px);
    --column-width: clamp(480px, 50vw, 640px);
  }
}

:root {
  --base-unit-half: calc( var(--base-unit) / 2.0 );
  --body-text-font-stack: "Vollkorn", serif;
  --heading-text-font-stack: "Vollkorn", serif;
  --font-size: var(--base-unit-half);
  --line-height: 1.4rem;
  --print-line-height: 1.4rem;
  --vertical-padding: var(--base-unit);
  --column-height: calc(100vh - calc(var(--vertical-padding) * 2.0));
  --column-height: calc(100svh - calc(var(--vertical-padding) * 2.0));
  --column-gap: var(--base-unit);
  --paper-hue: 100;
  --paper-saturation: 50%;
  --paper-lightness: 99%;
  --paper-color: hsla( var(--paper-hue), var(--paper-saturation), var(--paper-lightness), 1.0 );
  --shade-color-destination: hsla(var(--paper-hue), var(--paper-saturation), var(--paper-lightness), 0.0);
  --shade-color-origin: hsla(var(--paper-hue), var(--paper-saturation), var(--paper-lightness), 0.75);
  --spot-color: hsla(340, 100%, 50%, 1.0);
  --selection-color: hsla(340, 100%, 75%, 1.0);
  --text-color: rgb(5, 5, 5);
}

::-moz-selection { background: var(--selection-color); }
::selection { background: var(--selection-color); }

/* <button> has some gross defaults */
button {
  touch-action: manipulation;
  background: none;
  background-color: transparent;
  border: none;
  outline: none;
}

html {
  scroll-behavior: smooth;
  overflow: hidden; /* This is the key, always */
  font-size: var(--font-size);
  font-feature-settings: "kern", "liga", "ss11"; /* ss11 gives us the more normal 1 digit in Vollkorn */
}

body {
  height: 100vh; /* So the scrollbar appears at the bottom */
  overflow-x: scroll;
  overflow-y: hidden;
  margin: 0;
  padding: var(--vertical-padding) 0 0 0;
  background-color: var(--paper-color);
  font-family: var(--body-text-font-stack);
  font-size: 1rem;
  font-weight: 400;
  text-align: left; /* sigh */
  line-height: var(--line-height);
  color: var(--text-color);
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
}

div.book div.tutorial {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--line-height);
  break-after: column;
  width: var(--column-width);
  height: calc(var(--column-height) - 1px);
  overflow: hidden;  /* hacky, prevents weird flow problems */
  text-align: center;
}

div.book {
  font-family: var(--body-text-font-stack);
  line-height: var(--line-height);
}

div.book div.tutorial h2 {
  flex-grow: 0;
  height: auto;
  margin: 0;
  font-family: var(--body-text-font-stack); /* a bit ugly */
}

div.book div.tutorial p {
  flex-grow: 0;
  margin: 0;
  text-indent: 0;
}

button.toc-button {
  position: fixed;
  display: flex;
  flex-direction: column;
  justify-content: center;
  bottom: 0;
  left: 50vw;
  cursor: pointer;
  width: calc( var(--base-unit) * 2.0 );
  _height: var(--base-unit);
  transform: translateX(-50%) translateY(-50%);
  background-color: var(--paper-color);
  border: 1px solid var(--text-color);
  color: inherit;
  z-index: 100000;
}

button.toc-button:hover {
  border: 1px solid var(--spot-color);
  color: var(--spot-color);
}

button.toc-button svg {
  flex-grow: 1;
  fill: currentColor;
}

div.progress-indicator {
  position: fixed;
  bottom: 0;
  left: var(--base-unit);
  transform: translateY(-50%);
  min-width: calc( var(--base-unit) * 2.0 );
  padding: calc( var(--base-unit-half) / 4.0 ) calc( var(--base-unit-half) / 2.0 );
  background: transparent;
  border: none;
  color: var(--text-color);
  font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.875rem;
  text-align: center;
  z-index: 100000;
}

div.highlight-toolbar {
  position: fixed;
  display: flex;
  gap: calc(var(--base-unit-half) / 2.0);
  padding: calc(var(--base-unit-half) / 2.0);
  background-color: var(--paper-color);
  border: 1px solid var(--text-color);
  border-radius: 6px;
  z-index: 100001;
}

div.highlight-toolbar.hidden {
  display: none;
}

div.highlight-toolbar button {
  border: 1px solid var(--text-color);
  background: transparent;
  color: var(--text-color);
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

div.highlight-toolbar button:hover {
  border-color: var(--spot-color);
  color: var(--spot-color);
}

.book .reader-highlight {
  background-color: rgba(255, 230, 128, 0.6);
}

.book .reader-highlight-underline {
  text-decoration: underline;
  text-decoration-color: #f1c40f;
  text-decoration-thickness: 2px;
}

.book .reader-highlight-errata {
  background-color: rgba(255, 120, 120, 0.2);
  text-decoration: underline wavy #e74c3c;
  text-decoration-thickness: 2px;
}

button.settings-button {
  position: fixed;
  display: flex;
  flex-direction: column;
  justify-content: center;
  bottom: 0;
  right: var(--base-unit);
  cursor: pointer;
  width: calc( var(--base-unit) * 2.0 );
  _height: var(--base-unit);
  transform: translateY(-50%);
  background-color: var(--paper-color);
  border: 1px solid var(--text-color);
  color: inherit;
  z-index: 100000;
}

button.settings-button:hover {
  border: 1px solid var(--spot-color);
  color: var(--spot-color);
}

button.settings-button svg {
  flex-grow: 1;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 0.5;
}

a.library-button {
  position: fixed;
  top: calc( var(--vertical-padding) / 2.0 );
  right: var(--base-unit);
  width: var(--base-unit);
  _height: var(--base-unit);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--paper-color);
  border: 1px solid var(--text-color);
  color: var(--text-color);
  font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.875rem;
  text-decoration: none;
  z-index: 100000;
}

a.library-button:hover {
  border-color: var(--spot-color);
  color: var(--spot-color);
}

nav {
  position: fixed;
  top: calc( var(--vertical-padding) + var(--base-unit) );
  left: calc( 50vw - var(--column-width) * 0.45);
  width: calc( var(--column-width) * 0.9 ); /* This is all a little bit stupid and I'm sure there's a more principled way to do it */
  height: calc( var(--column-height) - var(--base-unit) );
  overflow-x: hidden;
  overflow-y: hidden;
  background-color: hsla(var(--paper-hue), calc(var(--paper-saturation) * 2.0), var(--paper-lightness), 1.0);
  border: 1px solid var(--spot-color);
  box-shadow: 0 0 var(--base-unit-half) 1px var(--spot-color);
  transition: opacity 0.1s;
  text-align: left;
  z-index: 10000;
}

/* Keep UI typography stable regardless of reader settings */
nav,
.settings-panel {
  font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
  font-size: 14px !important;
  line-height: 18px !important;
}

nav * {
  font-family: inherit !important;
  font-size: inherit !important;
  line-height: inherit !important;
}

.settings-panel *:not(.font-button):not(.bionic-button):not(button[data-scale]) {
  font-family: inherit !important;
  font-size: inherit !important;
  line-height: inherit !important;
}

nav.visible {
  pointer-events: auto;
  opacity: 1.0;
}

nav.invisible {
  pointer-events: none;
  opacity: 0.0;
}

nav div.toc {
  position: relative;
  width: calc( var(--column-width) * 0.9 );
  height: calc( var(--column-height) - var(--base-unit) * 2.0 );
  overflow-x: hidden;
  overflow-y: scroll;
  padding: var(--base-unit);
}

nav div.close-button {
  position: fixed;
  top: calc( var(--vertical-padding) + var(--base-unit) + var(--base-unit));
  right: calc( 50vw + var(--base-unit) - var(--column-width) * 0.45);
  width: var(--base-unit-half);
  height: var(--base-unit-half);
  stroke: var(--spot-color);
  stroke-width: 1px;
}

nav div.close-button:hover {
  cursor: pointer;
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  top: calc( var(--vertical-padding) + var(--base-unit) );
  left: calc( 50vw - var(--column-width) * 0.45);
  width: calc( var(--column-width) * 0.9 );
  max-height: calc( var(--column-height) - var(--base-unit) );
  overflow: visible;
  background-color: hsla(var(--paper-hue), calc(var(--paper-saturation) * 2.0), var(--paper-lightness), 1.0);
  border: 1px solid var(--spot-color);
  box-shadow: 0 0 var(--base-unit-half) 1px var(--spot-color);
  transition: opacity 0.1s;
  text-align: left;
  z-index: 10000;
}

.settings-panel.visible {
  pointer-events: auto;
  opacity: 1.0;
}

.settings-panel.invisible {
  pointer-events: none;
  opacity: 0.0;
}

.settings-panel div.controls {
  position: relative;
  width: 100%;
  padding: var(--base-unit);
  max-height: calc( var(--column-height) - var(--base-unit) );
  overflow-x: hidden;
  overflow-y: auto;
}

.settings-panel div.close-button {
  position: fixed;
  top: calc( var(--vertical-padding) + var(--base-unit) + var(--base-unit));
  right: calc( 50vw + var(--base-unit) - var(--column-width) * 0.45);
  width: var(--base-unit-half);
  height: var(--base-unit-half);
  stroke: var(--spot-color);
  stroke-width: 1px;
}

.settings-panel div.close-button:hover {
  cursor: pointer;
}

.settings-panel h1 {
  width: calc( var(--column-width) * 0.9 - calc( var(--base-unit) * 2.0 ) );
  margin: 0 0 calc(var(--base-unit-half) / 2.0) 0;
  padding: 0;
  font-style: italic;
  font-size: 1rem;
  font-weight: 400;
  line-height: var(--line-height);
}

/* Controls styling - applies to both nav and settings-panel */
nav div.controls,
.settings-panel div.controls {
  display: flex;
  flex-direction: column;
  gap: var(--base-unit-half);
}

nav div.controls .control-group,
.settings-panel div.controls .control-group {
  display: flex;
  flex-direction: column;
  gap: calc( var(--base-unit-half) / 2.0 );
}

nav div.controls .control-group label,
.settings-panel div.controls .control-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-color);
  margin-bottom: calc( var(--base-unit-half) / 4.0 );
}

.settings-panel .control-label-with-help {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc( var(--base-unit-half) / 2.0 );
}

.settings-panel .help-button {
  position: relative;
  width: calc( var(--base-unit-half) );
  height: calc( var(--base-unit-half) );
  border: 1px solid var(--spot-color);
  border-radius: 999px;
  color: var(--spot-color);
  font-weight: 600;
  font-size: 0.75rem;
  line-height: 1;
}

.settings-panel .help-button::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 0;
  top: 100%;
  transform: translateY(6px);
  max-width: 360px;
  padding: calc( var(--base-unit-half) * 0.75 );
  background-color: var(--paper-color);
  color: var(--text-color);
  border: 1px solid var(--spot-color);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  font-size: 0.75rem;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  white-space: normal;
  z-index: 100001;
}

.settings-panel .help-button:hover::after {
  opacity: 1;
}

.settings-panel .button-group.font-row,
.settings-panel .button-group.bionic-row {
  width: 100%;
}

.settings-panel .button-group.theme-row .theme-button[data-theme="light"] {
  background-color: hsla(100, 50%, 99%, 1.0);
  color: #222;
  border-color: #222;
}

.settings-panel .button-group.theme-row .theme-button[data-theme="dark"] {
  background-color: hsla(220, 20%, 15%, 1.0);
  color: #f0f0f0;
  border-color: #f0f0f0;
}

.settings-panel .button-group.theme-row .theme-button[data-theme="amber"] {
  background-color: hsla(45, 85%, 90%, 1.0);
  color: #3a2a12;
  border-color: #3a2a12;
}

.settings-panel .font-button[data-font="crimson"] {
  font-family: "Crimson Pro", "Vollkorn", serif !important;
}

.settings-panel .font-button {
  font-size: 14px !important;
  line-height: 18px !important;
}

.settings-panel .font-button[data-font="inter"] {
  font-family: "Inter", -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

.settings-panel .font-button[data-font="nunito"] {
  font-family: "Nunito", -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

.settings-panel .font-button[data-font="opendyslexic"] {
  font-family: "OpenDyslexicAlta", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="1"] {
  font-family: "BionicReadingSerifL1", "Vollkorn", serif !important;
}

.settings-panel .bionic-button {
  font-size: 14px !important;
  line-height: 18px !important;
}

.settings-panel .bionic-button[data-bionic="2"] {
  font-family: "BionicReadingSerifL2", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="3"] {
  font-family: "BionicReadingSerifL3", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="4"] {
  font-family: "BionicReadingSerifL4", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="5"] {
  font-family: "BionicReadingSerifL5", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="1"][data-bionic-family="sans"] {
  font-family: "BionicReadingL1", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="2"][data-bionic-family="sans"] {
  font-family: "BionicReadingL2", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="3"][data-bionic-family="sans"] {
  font-family: "BionicReadingL3", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="4"][data-bionic-family="sans"] {
  font-family: "BionicReadingL4", "Vollkorn", serif !important;
}

.settings-panel .bionic-button[data-bionic="5"][data-bionic-family="sans"] {
  font-family: "BionicReadingL5", "Vollkorn", serif !important;
}

nav div.controls .button-group,
.settings-panel div.controls .button-group {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: calc( var(--base-unit-half) / 2.0 );
  align-items: center;
}

nav div.controls button,
.settings-panel div.controls button {
  flex-shrink: 0;
  cursor: pointer;
  min-width: var(--base-unit);
  height: auto;
  padding: calc( var(--base-unit-half) / 4.0 ) calc( var(--base-unit-half) / 2.0 );
  font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.875rem;
  text-align: center;
  color: var(--spot-color);
  border: 1px solid var(--spot-color);
  background-color: transparent;
  transition: all 0.2s;
}

nav div.controls button[data-scale],
.settings-panel div.controls button[data-scale] {
  width: var(--base-unit);
  padding: 0;
}

nav div.controls button:hover,
.settings-panel div.controls button:hover {
  color: var(--text-color);
  background-color: rgba(0, 0, 0, 0.05);
}

nav div.controls button.active,
.settings-panel div.controls button.active {
  background-color: var(--spot-color);
  color: white;
}

nav div.controls button.mode-button,
nav div.controls button.theme-button,
nav div.controls button.bionic-button,
.settings-panel div.controls button.mode-button,
.settings-panel div.controls button.theme-button,
.settings-panel div.controls button.bionic-button {
  flex: 1;
  min-width: auto;
}

/* Bionic buttons should be smaller to fit more on one line */
.settings-panel div.controls button.bionic-button {
  flex: 0 1 auto;
  min-width: calc( var(--base-unit) * 0.8 );
  padding: calc( var(--base-unit-half) / 4.0 );
}

nav h1 {
  width: calc( var(--column-width) * 0.9 - calc( var(--base-unit) * 2.0 ) );
  margin: 0 0 var(--line-height) 0;
  padding: 0;
  font-style: italic;
  font-size: 1rem;
  font-weight: 400;
  line-height: var(--line-height);
}

nav ol {
  width: 90%;
  margin: 0 0 var(--line-height) 0;
  padding: 0;
  list-style-type: none;
}

nav ol li,
nav ul li {
  margin: 0;
  font-size: 1rem;
  line-height: var(--line-height);
}

nav ul {
  list-style: none;
  padding-left: 0;
}

nav ol li.toc-level-2,
nav ul li.toc-level-2 {
  margin-left: calc(var(--base-unit-half) * 0.8);
}

nav ol li.toc-level-3,
nav ul li.toc-level-3 {
  margin-left: calc(var(--base-unit-half) * 1.6);
}

nav ol li.toc-level-4,
nav ul li.toc-level-4 {
  margin-left: calc(var(--base-unit-half) * 2.4);
}

nav ol li:last-of-type {
  margin: 0 0 0 0;
}

div.bookmark {
  position: absolute;
  display: none;
  top: calc( var(--vertical-padding) * -2.5 ); /* now THAT is a magic number */
  left: calc( var(--column-width) / 2.0 );
  width: var(--base-unit);
  height: calc( var(--base-unit) * 2.0 );
  transform: translateX(-50%);
  fill: var(--spot-color);
  z-index: 100000;
}

/* GENERAL STYLES */

h2 {
  margin: calc( var(--line-height) * 6.0 ) 0 calc( var(--line-height) * 2.0 ) 0;
  padding: 0;
  break-before: column;
  font-family: var(--heading-text-font-stack);
  font-style: italic;
  font-size: 1.5rem;
  font-weight: 500;
  line-height: calc( var(--line-height) * 2.0 );
}

a, a:link, a:visited {
  color: var(--spot-color);
}

a:hover, a:active {
  color: var(--text-color);
}

p {
  margin: 0;
  padding: 0;
  text-indent: var(--base-unit-half);
  word-wrap: break-word;
  overflow-wrap: break-word;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
}

span.nobr {
  white-space: nowrap;
}

p.spacetime {
  margin-top: var(--line-height);
  text-indent: 0;
}

small {
  font-size: 1.025rem;
  font-feature-settings: "kern", "liga", "ss11", "smcp";
  font-variant: small-caps;
  font-variant-caps: small-caps;
  hyphens: none;
  text-transform: lowercase;
}

img {
  display: block;
  break-before: column;
  break-after: column;
  width: var(--column-width);
  height: var(--column-height);
  max-height: var(--column-height);
  overflow: hidden;
  mix-blend-mode: normal;
  object-fit: contain;
}

hr {
  break-after: avoid-column;
  width: 50%;
  margin: var(--base-unit) auto var(--base-unit) auto;
  border: none;
  border-bottom: 1px solid var(--spot-color);
}

p.last-page {
  break-before: column;
}

p.last-page::after {
  display: block;
  height: var(--column-height);
  content: "";
}

blockquote {
  break-before: avoid-column;
  margin: 0;
  padding: var(--base-unit);
  background-color: rgba(0, 0, 0, 0.125);
  font-style: italic;
}

/* BOOK BLOCK LAYOUT */

div.book {
  position: relative;
  column-gap: var(--base-unit);
  column-fill: auto;
  column-count: auto;
  column-width: var(--column-width);
  width: var(--column-width);
  height: var(--column-height);
  margin: var(--base-unit-half);
  background-color: var(--paper-color);
}

div.book div.title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--line-height);
  width: var(--column-width);
  height: var(--column-height);
  overflow: hidden; /* hacky, prevents weird flow problems */
  text-align: center;
}

div.book div.title h1 {
  flex-grow: 0;
  height: auto;
  margin: 0;
  padding: 0;
  font-family: var(--heading-text-font-stack);
  font-size: 2rem;
  font-weight: 500;
  font-feature-settings: "kern", "liga", "smcp", "ss11";
  font-variant: small-caps;
  font-variant-caps: small-caps;
  text-transform: lowercase;
  line-height: calc( var(--line-height) * 2.0 );
  color: var(--text-color);
}

div.book div.title h1 span {
  display: block;
}

div.book div.title h2 {
  flex-grow: 0;
  margin: 0;
}

div.book h1 {
  break-before: column;
  overflow: hidden; /* hacky */
  margin: 0;
  padding: 0;
  font-family: var(--heading-text-font-stack);
  font-size: 2rem;
  font-weight: 500;
  font-feature-settings: "kern", "liga", "smcp", "ss11";
  font-variant: small-caps;
  font-variant-caps: small-caps;
  text-align: center;
  text-transform: lowercase;
  line-height: var(--column-height);
  color: var(--spot-color);
}

div.book::before {
  position: fixed;
  top: 0;
  left: 0;
  width: calc( ( 100vw - var(--column-width) - var(--base-unit) ) / 2.0 );
  height: 100vh;
  background: linear-gradient(to right, var(--shade-color-origin) 0%, var(--shade-color-origin) 95%, var(--shade-color-destination) 100%);
  content: "";
  z-index: 1000;
}

div.book::after {
  position: fixed;
  top: 0;
  right: 0;
  width: calc( ( 100vw - var(--column-width) - var(--base-unit) ) / 2.0 );
  height: 100vh;
  background: linear-gradient(to left, var(--shade-color-origin) 0%, var(--shade-color-origin) 95%, var(--shade-color-destination) 100%);
  content: "";
  z-index: 1000;
}

/* PRINT STYLES */
/* This is a mess... */

div.print-cover {
  display: none;
  page-break-after: always;
  width: 100%;
  height: 100%;
}

div.print-cover div.title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  height: 100%;
  text-align: center;
}

div.print-cover div.title h1 {
  flex-grow: 0;
  margin: 0;
  padding: 0;
  font-family: var(--heading-text-font-stack);
  font-size: 2rem;
  font-weight: 500;
  font-feature-settings: "kern", "liga", "smcp", "ss11";
  font-variant:small-caps;
  font-variant-caps: small-caps;
  text-transform: lowercase;
  line-height: calc( var(--line-height) * 2.0 );
}

div.print-cover div.title h1 span {
  display: block;
}

div.print-cover div.title h2 {
  flex-grow: 0;
  margin-top: var(--line-height);
}

/* RESPONSIVE STUFF */

@media screen and (max-width: 640px) {
  :root {
    --column-width: calc(100vw - var(--base-unit));
  }

  div.book::before, div.book::after {
    display: none;
  }
}

@media screen and (min-width: 640px) {
  div.book {
    margin-left: calc(50vw - var(--column-width) / 2.0);
  }
}

@media screen and (min-height: 1000px) {
  :root {
    --vertical-padding: calc( var(--base-unit) * 2.0 );
  }

  div.bookmark {
    top: calc( var(--vertical-padding) * -1.5 ); /* Now THAT is a stupid magic number */
  }
}

/* Reading Modes */

/* Standard Mode - word wrap + full justify */
body.reading-mode-standard div.book p {
  word-wrap: break-word;
  overflow-wrap: break-word;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  -moz-hyphens: auto;
  -ms-hyphens: auto;
}

/* Simplified Mode - OpenDyslexic font, keep words together, left justify, no indent, paragraph margins */
body.reading-mode-simplified div.book {
  font-family: "OpenDyslexicAlta", sans-serif;
  line-height: calc( var(--line-height) * 1.5 ); /* Increased line spacing for readability */
}

body.reading-mode-simplified div.book p {
  text-align: left;
  text-indent: 0;
  margin-top: calc( var(--line-height) * 1.2 );
  margin-bottom: calc( var(--line-height) * 1.2 );
  word-break: normal; /* Don't break words mid-word */
  overflow-wrap: normal;
  word-wrap: normal;
  hyphens: none; /* Disable hyphenation */
  -webkit-hyphens: none;
  -moz-hyphens: none;
  -ms-hyphens: none;
  white-space: normal; /* Allow normal wrapping but don't break words */
}

body.reading-mode-simplified div.book p:first-of-type,
body.reading-mode-simplified div.book article p:first-child {
  margin-top: 0;
}

body.reading-mode-simplified div.book h1,
body.reading-mode-simplified div.book h2,
body.reading-mode-simplified div.book h3,
body.reading-mode-simplified div.book h4 {
  font-family: "OpenDyslexicAlta", sans-serif;
  text-align: left;
  font-weight: 700;
  margin-bottom: calc( var(--line-height) * 1.2 );
}

/* Bionic Reading Fonts - Level 0 (default, no bionic)
   Uses default fonts - no CSS needed */

/* Bionic Reading Fonts - Standard mode (serif) */
body.reading-mode-standard.bionic-1 div.book {
  font-family: "BionicReadingSerifL1", var(--body-text-font-stack);
}

body.reading-mode-standard.bionic-1 div.book em,
body.reading-mode-standard.bionic-1 div.book i,
body.reading-mode-standard.bionic-1 div.book blockquote {
  font-family: "BionicReadingSerifL1", var(--body-text-font-stack);
  font-style: italic;
}

body.reading-mode-standard.bionic-2 div.book {
  font-family: "BionicReadingSerifL2", var(--body-text-font-stack);
}

body.reading-mode-standard.bionic-2 div.book em,
body.reading-mode-standard.bionic-2 div.book i,
body.reading-mode-standard.bionic-2 div.book blockquote {
  font-family: "BionicReadingSerifL2", var(--body-text-font-stack);
  font-style: italic;
}

body.reading-mode-standard.bionic-3 div.book {
  font-family: "BionicReadingSerifL3", var(--body-text-font-stack);
}

body.reading-mode-standard.bionic-3 div.book em,
body.reading-mode-standard.bionic-3 div.book i,
body.reading-mode-standard.bionic-3 div.book blockquote {
  font-family: "BionicReadingSerifL3", var(--body-text-font-stack);
  font-style: italic;
}

body.reading-mode-standard.bionic-4 div.book {
  font-family: "BionicReadingSerifL4", var(--body-text-font-stack);
}

body.reading-mode-standard.bionic-4 div.book em,
body.reading-mode-standard.bionic-4 div.book i,
body.reading-mode-standard.bionic-4 div.book blockquote {
  font-family: "BionicReadingSerifL4", var(--body-text-font-stack);
  font-style: italic;
}

body.reading-mode-standard.bionic-5 div.book {
  font-family: "BionicReadingSerifL5", var(--body-text-font-stack);
}

body.reading-mode-standard.bionic-5 div.book em,
body.reading-mode-standard.bionic-5 div.book i,
body.reading-mode-standard.bionic-5 div.book blockquote {
  font-family: "BionicReadingSerifL5", var(--body-text-font-stack);
  font-style: italic;
}

/* Bionic Reading (Sans) */
body.bionic-family-sans.reading-mode-standard.bionic-1 div.book {
  font-family: "BionicReadingL1", var(--body-text-font-stack);
}

body.bionic-family-sans.reading-mode-standard.bionic-1 div.book em,
body.bionic-family-sans.reading-mode-standard.bionic-1 div.book i,
body.bionic-family-sans.reading-mode-standard.bionic-1 div.book blockquote {
  font-family: "BionicReadingL1", var(--body-text-font-stack);
  font-style: italic;
}

body.bionic-family-sans.reading-mode-standard.bionic-2 div.book {
  font-family: "BionicReadingL2", var(--body-text-font-stack);
}

body.bionic-family-sans.reading-mode-standard.bionic-2 div.book em,
body.bionic-family-sans.reading-mode-standard.bionic-2 div.book i,
body.bionic-family-sans.reading-mode-standard.bionic-2 div.book blockquote {
  font-family: "BionicReadingL2", var(--body-text-font-stack);
  font-style: italic;
}

body.bionic-family-sans.reading-mode-standard.bionic-3 div.book {
  font-family: "BionicReadingL3", var(--body-text-font-stack);
}

body.bionic-family-sans.reading-mode-standard.bionic-3 div.book em,
body.bionic-family-sans.reading-mode-standard.bionic-3 div.book i,
body.bionic-family-sans.reading-mode-standard.bionic-3 div.book blockquote {
  font-family: "BionicReadingL3", var(--body-text-font-stack);
  font-style: italic;
}

body.bionic-family-sans.reading-mode-standard.bionic-4 div.book {
  font-family: "BionicReadingL4", var(--body-text-font-stack);
}

body.bionic-family-sans.reading-mode-standard.bionic-4 div.book em,
body.bionic-family-sans.reading-mode-standard.bionic-4 div.book i,
body.bionic-family-sans.reading-mode-standard.bionic-4 div.book blockquote {
  font-family: "BionicReadingL4", var(--body-text-font-stack);
  font-style: italic;
}

body.bionic-family-sans.reading-mode-standard.bionic-5 div.book {
  font-family: "BionicReadingL5", var(--body-text-font-stack);
}

body.bionic-family-sans.reading-mode-standard.bionic-5 div.book em,
body.bionic-family-sans.reading-mode-standard.bionic-5 div.book i,
body.bionic-family-sans.reading-mode-standard.bionic-5 div.book blockquote {
  font-family: "BionicReadingL5", var(--body-text-font-stack);
  font-style: italic;
}

/* Bionic Reading Fonts - Simplified mode (sans-serif) */
body.reading-mode-simplified.bionic-1 div.book {
  font-family: "BionicReadingL1", "OpenDyslexicAlta", sans-serif;
}

body.reading-mode-simplified.bionic-1 div.book em,
body.reading-mode-simplified.bionic-1 div.book i,
body.reading-mode-simplified.bionic-1 div.book blockquote {
  font-family: "BionicReadingL1", "OpenDyslexicAlta", sans-serif;
  font-style: italic;
}

body.reading-mode-simplified.bionic-2 div.book {
  font-family: "BionicReadingL2", "OpenDyslexicAlta", sans-serif;
}

body.reading-mode-simplified.bionic-2 div.book em,
body.reading-mode-simplified.bionic-2 div.book i,
body.reading-mode-simplified.bionic-2 div.book blockquote {
  font-family: "BionicReadingL2", "OpenDyslexicAlta", sans-serif;
  font-style: italic;
}

body.reading-mode-simplified.bionic-3 div.book {
  font-family: "BionicReadingL3", "OpenDyslexicAlta", sans-serif;
}

body.reading-mode-simplified.bionic-3 div.book em,
body.reading-mode-simplified.bionic-3 div.book i,
body.reading-mode-simplified.bionic-3 div.book blockquote {
  font-family: "BionicReadingL3", "OpenDyslexicAlta", sans-serif;
  font-style: italic;
}

body.reading-mode-simplified.bionic-4 div.book {
  font-family: "BionicReadingL4", "OpenDyslexicAlta", sans-serif;
}

body.reading-mode-simplified.bionic-4 div.book em,
body.reading-mode-simplified.bionic-4 div.book i,
body.reading-mode-simplified.bionic-4 div.book blockquote {
  font-family: "BionicReadingL4", "OpenDyslexicAlta", sans-serif;
  font-style: italic;
}

body.reading-mode-simplified.bionic-5 div.book {
  font-family: "BionicReadingL5", "OpenDyslexicAlta", sans-serif;
}

body.reading-mode-simplified.bionic-5 div.book em,
body.reading-mode-simplified.bionic-5 div.book i,
body.reading-mode-simplified.bionic-5 div.book blockquote {
  font-family: "BionicReadingL5", "OpenDyslexicAlta", sans-serif;
  font-style: italic;
}

/* Dark Mode */
body.dark-mode {
  --paper-hue: 220;
  --paper-saturation: 20%;
  --paper-lightness: 15%;
  --paper-color: hsla(220, 20%, 15%, 1.0); /* Explicitly recalculate paper color for dark mode */
  --shade-color-destination: hsla(220, 20%, 15%, 0.0);
  --shade-color-origin: hsla(220, 20%, 15%, 0.5); /* Darker shade for dark mode */
  --text-color: rgb(240, 240, 240);
  --spot-color: hsla(340, 100%, 65%, 1.0);
  --selection-color: hsla(340, 100%, 35%, 1.0);
  background-color: hsla(220, 20%, 12%, 1.0) !important; /* Explicitly set dark body background */
}

body.dark-mode div.book {
  background-color: hsla(220, 20%, 15%, 1.0) !important; /* Explicit dark background for book */
  color: rgb(240, 240, 240) !important;
}

/* Override the base div.book background-color in dark mode */
body.dark-mode div.book[style*="background"] {
  background-color: hsla(220, 20%, 15%, 1.0) !important;
}

body.dark-mode div.book article,
body.dark-mode div.book p,
body.dark-mode div.book h1,
body.dark-mode div.book h2,
body.dark-mode div.book h3,
body.dark-mode div.book h4,
body.dark-mode div.book div.title,
body.dark-mode div.book div.title h1,
body.dark-mode div.book div.title h2 {
  background-color: transparent !important; /* Text elements should be transparent */
  color: var(--text-color) !important;
}

body.dark-mode div.book div.tutorial {
  background-color: hsla(220, 20%, 18%, 1.0) !important; /* Slightly lighter for tutorial */
  color: var(--text-color) !important;
}

body.dark-mode div.book img.cover {
  filter: none;
}

body.dark-mode div.book * {
  color: var(--text-color) !important;
}

/* But allow specific elements to override if needed */
body.dark-mode div.book a {
  color: var(--spot-color) !important;
}

body.dark-mode div.book a:hover {
  color: var(--text-color) !important;
}

body.dark-mode div.book .tagline,
body.dark-mode div.book .collection {
  color: rgba(240, 240, 240, 0.8) !important;
}

body.dark-mode nav {
  background-color: hsla(var(--paper-hue), calc(var(--paper-saturation) * 2.0), calc(var(--paper-lightness) + 10%), 1.0);
  border-color: var(--spot-color);
  color: var(--text-color);
}

body.dark-mode nav div.controls {
  background-color: hsla(var(--paper-hue), calc(var(--paper-saturation) * 2.0), calc(var(--paper-lightness) + 10%), 1.0);
  border-color: var(--spot-color);
}

body.dark-mode nav div.controls label {
  color: var(--text-color);
}

body.dark-mode nav div.controls button {
  color: var(--spot-color);
  border-color: var(--spot-color);
}

body.dark-mode nav div.controls button:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode nav div.controls button.active {
  background-color: var(--spot-color);
  color: var(--paper-color);
}

body.dark-mode nav div.close-button {
  stroke: var(--spot-color);
}

body.dark-mode nav h1 {
  color: var(--text-color);
}

body.dark-mode nav a {
  color: var(--spot-color);
}

body.dark-mode nav a:hover {
  color: var(--text-color);
}

/* Dark mode for settings panel */
body.dark-mode .settings-panel {
  background-color: hsla(var(--paper-hue), calc(var(--paper-saturation) * 2.0), calc(var(--paper-lightness) + 10%), 1.0);
  border-color: var(--spot-color);
}

body.dark-mode .settings-panel div.controls label {
  color: var(--text-color);
}

body.dark-mode .settings-panel div.controls button {
  color: var(--spot-color);
  border-color: var(--spot-color);
}

body.dark-mode .settings-panel div.controls button:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .settings-panel div.controls button.active {
  background-color: var(--spot-color);
  color: var(--paper-color);
}

body.dark-mode .settings-panel div.close-button {
  stroke: var(--spot-color);
}

body.dark-mode .settings-panel h1 {
  color: var(--text-color);
}

/* Amber Theme (black on yellowish) */
body.theme-amber {
  --paper-hue: 45;
  --paper-saturation: 85%;
  --paper-lightness: 90%;
  --paper-color: hsla(45, 85%, 90%, 1.0);
  --shade-color-destination: hsla(45, 85%, 90%, 0.0);
  --shade-color-origin: hsla(45, 85%, 90%, 0.6);
  --text-color: rgb(15, 12, 5);
  --spot-color: hsla(30, 80%, 30%, 1.0);
  --selection-color: hsla(45, 90%, 70%, 1.0);
  background-color: hsla(45, 85%, 88%, 1.0) !important;
}

body.theme-amber div.book {
  background-color: hsla(45, 85%, 90%, 1.0) !important;
  color: var(--text-color) !important;
}

body.theme-amber div.book[style*="background"] {
  background-color: hsla(45, 85%, 90%, 1.0) !important;
}

body.theme-amber div.book article,
body.theme-amber div.book p,
body.theme-amber div.book h1,
body.theme-amber div.book h2,
body.theme-amber div.book h3,
body.theme-amber div.book h4,
body.theme-amber div.book div.title,
body.theme-amber div.book div.title h1,
body.theme-amber div.book div.title h2 {
  background-color: transparent !important;
  color: var(--text-color) !important;
}

body.theme-amber div.book * {
  color: var(--text-color) !important;
}

body.theme-amber div.book a {
  color: var(--spot-color) !important;
}

body.theme-amber div.book a:hover {
  color: var(--text-color) !important;
}

body.theme-amber nav,
body.theme-amber .settings-panel {
  background-color: hsla(var(--paper-hue), calc(var(--paper-saturation) * 1.1), calc(var(--paper-lightness) - 5%), 1.0);
  border-color: var(--spot-color);
  color: var(--text-color);
}

body.theme-amber .settings-panel div.controls button {
  color: var(--spot-color);
  border-color: var(--spot-color);
}

body.theme-amber .settings-panel div.controls button:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

body.theme-amber .settings-panel div.controls button.active {
  background-color: var(--spot-color);
  color: var(--paper-color);
}

@media print {
  html {
    width: 100%;
    overflow: auto;
    overflow: visible !important; /* BLERF this fixed a lot of my print style woes */
    font-size: 16pt;
  }

  div.book::before, div.book::after, nav, button.toc-button, button.settings-button, .settings-panel, img.cover, div.last-page, div.bookmark, div.tutorial {
    display: none;
  }

  div.book div.title {
    display: none;
  }

  @page {
    margin: 1.5in;
  }

  body {
    width: 100%;
    height: auto;
    overflow-x: auto;
    overflow-y: auto;
    background-color: rgb(255, 255, 255);
    line-height: var(--print-line-height);
    color: rgb(0, 0, 0);
  }

  div.print-cover {
    display: block;
  }

  div.book {
    columns: 100% 1;
    column-gap: 0;
    column-fill: auto;
    column-count: 0;
    column-width: auto;
    width: 100%;
    height: auto;
    margin: 0;
  }

  h2 {
    position: relative;
    display: block;
    break-before: page !important; /* This isn't working :( */
    margin-top: 0;
    margin-bottom: var(--print-line-height);
    font-size: 1rem;
    line-height: var(--print-line-height);
  }

  hr {
    break-after: avoid-page !important;
  }

  small {
    font-size: 1.0rem;
    font-weight: 400;
    font-variant: none;
    font-variant-caps: none;
    text-transform: none; /* Small caps weren't working correctly when actually printed, so! */
  }
}
