/* doomreader styles. Colours come from variables so the light, dark and
   automatic themes only change the variables below. */

:root {
  color-scheme: light dark;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --ui-bg: #ffffff;
  --ui-fg: #17171b;
  --ui-muted: #6a6a75;
  --ui-line: rgba(0, 0, 0, 0.14);
  --ui-soft: #f1f1f5;
  --ui-accent: #4f46e5;
  --ui-on-accent: #ffffff;

  /* Cards: the hue changes with the chapter, the rest comes from the theme. */
  --card-s: 38%;
  --card-l: 96%;
  --card-fg: #1d1d22;
  --card-muted: #6a6a75;
  --card-line: rgba(0, 0, 0, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ui-bg: #101013;
    --ui-fg: #ececf1;
    --ui-muted: #9a9aa8;
    --ui-line: rgba(255, 255, 255, 0.16);
    --ui-soft: #1c1c22;
    --ui-accent: #8b85ff;
    --ui-on-accent: #101013;
    --card-s: 26%;
    --card-l: 11%;
    --card-fg: #ececf1;
    --card-muted: #9d9dab;
    --card-line: rgba(255, 255, 255, 0.2);
  }
}

:root[data-theme="light"] { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --ui-bg: #101013;
  --ui-fg: #ececf1;
  --ui-muted: #9a9aa8;
  --ui-line: rgba(255, 255, 255, 0.16);
  --ui-soft: #1c1c22;
  --ui-accent: #8b85ff;
  --ui-on-accent: #101013;
  --card-s: 26%;
  --card-l: 11%;
  --card-fg: #ececf1;
  --card-muted: #9d9dab;
  --card-line: rgba(255, 255, 255, 0.2);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ui-bg);
  color: var(--ui-fg);
  font-family: var(--sans);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
}

.muted { color: var(--ui-muted); }

:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

/* Library */

#library-view,
#likes-view {
  max-width: 46rem;
  min-height: 100%;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 32px) 20px calc(env(safe-area-inset-bottom) + 40px);
}

.lib-head h1 {
  margin: 0 0 0.4rem;
  font: 700 2rem/1.1 var(--serif);
}

.sub {
  margin: 0 0 1.8rem;
  color: var(--ui-muted);
}

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 24px 16px;
  margin-bottom: 28px;
}

.shelf:empty { display: none; }

.book-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.book {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.cover {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 2 / 3;
  padding: 10px;
  overflow: hidden;
  border-radius: 6px;
  background: hsl(var(--h, 230) 38% 34%);
  color: #ffffff;
  font: 600 0.95rem/1.2 var(--serif);
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.cover.has-img { padding: 0; }

.cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-title { font-weight: 600; font-size: 0.95rem; line-height: 1.25; }
.book-author { color: var(--ui-muted); font-size: 0.85rem; }
.book-status { color: var(--ui-muted); font-size: 0.8rem; }

.bar {
  height: 3px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--ui-line);
}

.bar > i {
  display: block;
  width: var(--p, 0%);
  height: 100%;
  background: var(--ui-accent);
}

.dropzone {
  padding: 24px 20px;
  border: 2px dashed var(--ui-line);
  border-radius: 16px;
  text-align: center;
}

.dropzone p { margin: 0 0 0.5rem; }
.drop-title { font: 700 1.15rem var(--serif); }

#library-view.dragging .dropzone {
  border-color: var(--ui-accent);
  background: var(--ui-soft);
}

.primary {
  margin-top: 0.6rem;
  padding: 0.75rem 1.4rem;
  border: 0;
  border-radius: 999px;
  background: var(--ui-accent);
  color: var(--ui-on-accent);
  font-weight: 600;
  cursor: pointer;
}

.link-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ui-accent);
  font-size: 0.9rem;
  cursor: pointer;
}

.note {
  margin: 20px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--ui-soft);
  font-size: 0.9rem;
}

/* Reader */

#reader-view {
  position: fixed;
  inset: 0;
  background: var(--ui-bg);
}

#feed {
  position: absolute;
  inset: 0;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  touch-action: pan-y;
  outline: none;
  --fs: 32px;
}

#feed::-webkit-scrollbar { display: none; }

.card {
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100%;
  padding: calc(env(safe-area-inset-top) + 64px) 26px calc(env(safe-area-inset-bottom) + 68px);
  background: hsl(var(--hue, 220) var(--card-s) var(--card-l));
  color: var(--card-fg);
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

/* The content area of a card. Its one child is centred, and scrolls only if it cannot fit. */
.inner {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}

.inner::-webkit-scrollbar { display: none; }
.inner > * { margin: auto; }

.text {
  width: 100%;
  max-width: 34rem;
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: 1.55;
  hyphens: auto;
  overflow-wrap: break-word;
  text-wrap: pretty;
}

.text p {
  margin: 0 0 0.9em;
  white-space: pre-line;
}

.text p:last-child { margin-bottom: 0; }

.text p.quote {
  padding-left: 1em;
  border-left: 3px solid var(--card-line);
}

.text p.pre {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.85em;
  white-space: pre-wrap;
}

.text h3 {
  margin: 0 0 0.7em;
  font: 700 1.15em/1.3 var(--serif);
}

.scene {
  margin: 0 0 0.9em;
  color: var(--card-muted);
  letter-spacing: 0.5em;
  text-align: center;
}

.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 30rem;
  text-align: center;
}

.cover-img {
  max-width: min(70%, 320px);
  max-height: 46vh;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.cover-title {
  margin: 8px 0 0;
  font: 700 1.7rem/1.15 var(--serif);
}

.cover-by {
  margin: 0;
  color: var(--card-muted);
}

.hint {
  margin: 18px 0 0;
  color: var(--card-muted);
  font-size: 0.9rem;
  animation: nudge 1.8s ease-in-out infinite;
}

@keyframes nudge {
  50% { transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
  .hint { animation: none; }
}

.chapter {
  width: 100%;
  max-width: 30rem;
  text-align: center;
}

.chapter h2 {
  margin: 0;
  font: 700 clamp(1.6rem, 6vw, 2.4rem)/1.15 var(--serif);
  overflow-wrap: break-word;
}

.rule {
  width: 3rem;
  height: 3px;
  margin: 1.2rem auto 0;
  border-radius: 2px;
  background: var(--ui-accent);
}

.figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
}

.figure img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  object-fit: contain;
}

.missing {
  color: var(--card-muted);
  font-size: 0.9rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.pill {
  padding: 0.65rem 1.2rem;
  border: 1px solid var(--card-line);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.card-end h2 {
  margin: 0;
  font: 700 2rem var(--serif);
}

.topbar {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  color: var(--card-muted);
  pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font: 600 0.82rem var(--sans);
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--card-fg) 9%, transparent);
  color: var(--card-fg);
  font-weight: 600;
  cursor: pointer;
}

.bottombar {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px calc(env(safe-area-inset-bottom) + 14px);
  color: var(--card-muted);
  font: 600 0.78rem var(--sans);
  pointer-events: none;
}

.track {
  flex: 1;
  height: 3px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--card-line);
}

.track > i {
  display: block;
  width: var(--p, 0%);
  height: 100%;
  background: var(--ui-accent);
}

#progress-text {
  min-width: 2.6em;
  text-align: right;
}

/* Sheets (settings and chapters) */

dialog.sheet {
  width: min(100%, 32rem);
  max-width: 100%;
  max-height: 85dvh;
  margin: auto auto 0;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
  overflow: auto;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--ui-bg);
  color: var(--ui-fg);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.35);
}

dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }

@media (min-width: 640px) {
  dialog.sheet {
    margin: auto;
    border-radius: 18px;
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.sheet-head h2 {
  margin: 0;
  font: 700 1.1rem var(--sans);
}

.row {
  padding: 14px 0;
  border-top: 1px solid var(--ui-line);
}

.row.line {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.row-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.row input[type="range"] {
  width: 100%;
  accent-color: var(--ui-accent);
}

.scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stepper button,
.segmented button {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--ui-line);
  background: var(--ui-soft);
  cursor: pointer;
}

.stepper button { border-radius: 10px; }
.stepper span { min-width: 3.4em; text-align: center; }

.segmented { display: flex; }
.segmented button:first-child { border-radius: 10px 0 0 10px; }
.segmented button:last-child { border-radius: 0 10px 10px 0; }
.segmented button + button { border-left: 0; }

.segmented button[aria-pressed="true"] {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: var(--ui-on-accent);
}

.wide {
  width: 100%;
  margin-top: 6px;
  padding: 0.8rem;
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  background: var(--ui-soft);
  cursor: pointer;
}

.contents {
  margin: 0;
  padding: 0;
  list-style: none;
}

.chapter-link {
  display: block;
  width: 100%;
  padding: 12px 4px;
  border: 0;
  border-top: 1px solid var(--ui-line);
  background: none;
  text-align: left;
  cursor: pointer;
}

.chapter-link[aria-current="true"] {
  color: var(--ui-accent);
  font-weight: 700;
}

.contents .muted { padding: 12px 4px; }

/* Busy overlay and messages */

.busy {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: color-mix(in srgb, var(--ui-bg) 82%, transparent);
  text-align: center;
}

.busy p { margin: 0; font-weight: 600; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--ui-line);
  border-top-color: var(--ui-accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  left: 16px;
  z-index: 20;
  max-width: 28rem;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--ui-fg);
  color: var(--ui-bg);
  font-size: 0.92rem;
  text-align: center;
}

/* Home: title row, choosing books, likes page */

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.title-row h1 { margin: 0; }
.lib-head .sub { margin-top: 0.5rem; }
.lib-head .link-btn { margin-bottom: 6px; }

.title-actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.pill-btn {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-soft);
  font-size: 0.9rem;
  cursor: pointer;
}

.primary:disabled {
  opacity: 0.45;
  cursor: default;
}

#library-view.selecting { padding-bottom: 110px; }
.shelf.selecting .link-btn { visibility: hidden; }

.select-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--ui-line);
  background: var(--ui-bg);
}

.select-bar span {
  flex: 1;
  font-size: 0.92rem;
}

.select-bar .primary { margin-top: 0; }

.check {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  color: #ffffff;
  font: 700 0.85rem var(--sans);
}

.book.picked .cover {
  outline: 3px solid var(--ui-accent);
  outline-offset: 2px;
}

.book.picked .check {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: var(--ui-on-accent);
}

.likes {
  margin: 0;
  padding: 0;
  list-style: none;
}

.like {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 14px 0;
  border-top: 1px solid var(--ui-line);
}

.like-open {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.like-snippet {
  display: -webkit-box;
  overflow: hidden;
  font: 1rem/1.5 var(--serif);
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.like-meta {
  color: var(--ui-muted);
  font-size: 0.85rem;
}

/* Wall: the heart, and the line that names the book on a mixed wall */

.bottombar > .like-btn {
  flex: none;
  pointer-events: auto;
}

.like-btn svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}

.shuffle-btn[aria-pressed="true"] {
  background: var(--ui-accent);
  color: var(--ui-on-accent);
}

.like-btn[aria-pressed="true"] { color: #e11d48; }
.like-btn[aria-pressed="true"] svg path { fill: currentColor; }

.post-head {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  max-width: 34rem;
  min-width: 0;
  margin: 0 auto;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--card-line);
}

.post-book,
.post-chapter {
  overflow: hidden;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.post-book { font: 700 0.85rem var(--sans); }

.post-chapter {
  color: var(--card-muted);
  font: 500 0.8rem var(--sans);
}
