/*
 * Same look as the Android app: two colours only (ink and paper, swapped in the dark theme),
 * 2px square borders, selected and pressed controls inverted, no shadows, no animations.
 * Meant to read well on e-ink, where greys smear and every transition is a slow refresh.
 */

* {
  box-sizing: border-box;
}

:root {
  --ink: #000;
  --paper: #fff;
  --line: 2px;
  --gap: 16px;
  --footer-height: 40px;
  --viewport-height: 100vh;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #fff;
    --paper: #000;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ink: #fff;
  --paper: #000;
  color-scheme: dark;
}

@supports (height: 100dvh) {
  :root {
    --viewport-height: 100dvh;
  }
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 16px;
  background: var(--paper);
  color: var(--ink);
  min-height: var(--viewport-height);
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

/* --- Controls ---------------------------------------------------------------- */

button,
input {
  font: inherit;
}

button,
.linkButton {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 12px;
  border: var(--line) solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:active,
.linkButton:active,
button[aria-pressed="true"],
button.active {
  background: var(--ink);
  color: var(--paper);
}

button:disabled,
button:disabled:active {
  border: 1px dashed var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: default;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: var(--line) solid var(--ink);
  outline-offset: 2px;
}

/* A row of buttons sharing their borders: each overlaps its neighbour by one line. */
.segmented {
  display: flex;
}

.segmented > button {
  flex: 1 1 0;
  min-width: 0;
}

.segmented > button + button {
  margin-inline-start: calc(-1 * var(--line));
}

.panel h3 {
  margin: var(--gap) 0 8px;
  font-size: 18px;
  font-weight: 700;
}

/* --- Menu -------------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 1fr;
  height: var(--viewport-height);
  position: relative;
  max-width: 100%;
  overflow: hidden;
}

.panel {
  position: fixed;
  inset: 0 auto auto 0;
  width: 100%;
  height: var(--viewport-height);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}

.panel.hidden {
  display: none !important;
}

.panelHeader {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px var(--gap);
  background: var(--paper);
}

.panelIcon {
  width: 40px;
  height: 40px;
  flex: none;
  /* The mascot is a black drawing: it keeps its own white disc in the dark theme. */
  border-radius: 50%;
  background: #fff;
}

.panelHeader h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.closeButton {
  width: 56px;
  height: 56px;
  flex: none;
  padding: 0;
  font-size: 24px;
}

/* One segmented bar, edge to edge: the outer side borders fall off the screen. */
.panelNav {
  display: flex;
  margin: 0 calc(-1 * var(--line));
  background: var(--paper);
}

.navBtn {
  flex: 1 1 0;
  min-width: 0;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.navBtn + .navBtn {
  margin-inline-start: calc(-1 * var(--line));
}

.panelContent {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  user-select: none;
}

.panelSection {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--gap) var(--gap);
  background: var(--paper);
}

.panelSection.active {
  display: flex;
  flex-direction: column;
}

.meta,
.hint {
  margin: var(--gap) 0 0;
  line-height: 1.4;
}

.hint {
  text-align: center;
}

/* --- Aa: font size ----------------------------------------------------------- */

#stylesSection {
  padding: 0;
  overflow: hidden;
  background: transparent;
}

/* See-through: the page shows inside the frame, paper all around it. */
.stylesPreview {
  flex: 1;
  min-height: 120px;
  margin: var(--gap) var(--gap) 0;
  border: var(--line) solid var(--ink);
  box-shadow: 0 0 0 100vmax var(--paper);
  clip-path: inset(calc(-1 * var(--gap)) calc(-1 * var(--gap)) 0);
}

.stylesControls {
  position: relative;
  padding: 0 var(--gap) var(--gap);
  background: var(--paper);
  text-align: center;
}

.fontSizeControl {
  max-width: 300px;
  margin: 0 auto;
}

.fontSizeControl > button {
  font-size: 22px;
}

.fontSizeControl > button.wide {
  flex-grow: 1.5;
  font-size: inherit;
}

.fontSizeValue {
  margin: 12px 0 0;
  font-variant-numeric: tabular-nums;
}

/* --- Contents ---------------------------------------------------------------- */

.tocList {
  list-style: none;
  margin: 0 calc(-1 * var(--gap));
  padding: 0;
}

.tocList .meta {
  margin: var(--gap);
}

.tocItem {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px var(--gap);
  border: 0;
  border-bottom: 1px solid var(--ink);
  text-align: start;
  line-height: 1.3;
}

.tocItem.active {
  background: var(--ink);
  color: var(--paper);
}

/* --- Library ----------------------------------------------------------------- */

.library {
  list-style: none;
  margin: var(--gap) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--gap);
  align-items: start;
}

.libraryAddItem,
.libraryItem {
  position: relative;
}

.addEpubButton,
.portraitBtn {
  width: 100%;
  padding: 12px;
}

.addEpubButton {
  aspect-ratio: 2 / 3;
  align-items: flex-end;
}

.portraitBtn {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.coverContainer {
  aspect-ratio: 2 / 3;
  display: flex;
  overflow: hidden;
}

.coverContainer.noCover {
  border: 1px solid currentColor;
}

.coverImage {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.bookTitle {
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Sits on the tile's corner, sharing its border. */
.deleteBtn {
  position: absolute;
  top: 0;
  right: 0;
  width: 48px;
  height: 48px;
  min-height: 0;
  padding: 0;
  font-size: 20px;
  z-index: 1;
}

/* --- Settings ---------------------------------------------------------------- */

.settingsContent {
  display: flex;
  flex-direction: column;
}

.settingsContent p {
  margin: 0 0 12px;
}

.zoneGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 var(--line) 0 0;
}

.zoneCell {
  min-height: 72px;
  margin: 0 calc(-1 * var(--line)) calc(-1 * var(--line)) 0;
}

.linkButton + .linkButton {
  margin-top: 8px;
}

/* --- Reader ------------------------------------------------------------------ */

.reader {
  position: relative;
  padding: 0 0 var(--footer-height) 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100vw;
  max-width: 100%;
  height: var(--viewport-height);
  background: var(--paper);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.viewer {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: var(--paper);
}

.viewer.hasAspectRatio {
  flex: 0 0 auto;
  align-self: center;
  width: min(100%, calc((var(--viewport-height) - var(--footer-height)) * var(--reader-aspect-ratio)));
  height: auto;
  aspect-ratio: var(--reader-aspect-ratio);
  max-height: calc(var(--viewport-height) - var(--footer-height));
  outline: 1px solid var(--ink);
}

.viewer iframe {
  width: 100% !important;
  height: 100% !important;
  overflow: hidden !important;
  border: none !important;
  display: block !important;
  max-width: 100% !important;
}

.viewerEmptyState {
  position: absolute;
  inset: 0 0 var(--footer-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  pointer-events: none;
  z-index: 2;
}

.viewerEmptyLogo {
  border-radius: 50%;
  background: #fff;
}

.viewerEmptyText {
  font-size: 18px;
}

.readerFooter {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 var(--gap);
  border-top: 1px solid var(--ink);
  background: var(--paper);
  font-size: 14px;
  z-index: 5;
}

.footerLeft,
.footerCenter,
.footerRight {
  display: flex;
  align-items: center;
  gap: 6px;
}

.footerLeft,
.footerRight {
  flex: none;
}

.footerCenter {
  flex: 1 1 auto;
  justify-content: center;
  min-width: 0;
  font-weight: 700;
}

.clock,
.progressPercent,
.chapterNumber {
  font-variant-numeric: tabular-nums;
}

.chapterInfo {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

/* --- Feedback ---------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-height) + var(--gap));
  transform: translateX(-50%);
  max-width: calc(100vw - 2 * var(--gap));
  padding: 12px var(--gap);
  border: var(--line) solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  visibility: hidden;
  pointer-events: none;
  z-index: 1000;
}

.toast.visible {
  visibility: visible;
}

.progress {
  display: none;
  position: fixed;
  inset: 0 0 auto;
  padding: 12px var(--gap);
  border-bottom: var(--line) solid var(--ink);
  background: var(--paper);
  z-index: 1000;
}

.progress.visible {
  display: block;
}

.progress .bar {
  height: 8px;
  border: 1px solid var(--ink);
}

.progress .fill {
  height: 100%;
  width: 0%;
  background: var(--ink);
}

/* Unknown length: a still, striped bar rather than a moving one. */
.progress.indeterminate .fill {
  width: 100% !important;
  background: repeating-linear-gradient(90deg, var(--ink) 0 8px, transparent 8px 16px);
}

.progress .label {
  margin-top: 8px;
}

/* --- Install dialog ---------------------------------------------------------- */

.installModal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: var(--gap);
  border: 0;
  background: transparent;
  color: var(--ink);
  z-index: 1000;
}

.installModal::backdrop {
  background: transparent;
}

.installModal[open] {
  display: flex;
}

.installModalContent {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 24px var(--gap) var(--gap);
  border: var(--line) solid var(--ink);
  background: var(--paper);
}

.installModalClose {
  position: absolute;
  top: calc(-1 * var(--line));
  right: calc(-1 * var(--line));
  width: 48px;
  height: 48px;
  min-height: 0;
  padding: 0;
  font-size: 20px;
}

.installModalBody h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.installModalBody p {
  margin: 0 0 24px;
  line-height: 1.4;
}

.installModalButtons {
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}
