:root {
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --text: #2b2622;
  --muted: #7a716a;
  --rule: #e6ded2;
  --accent: #9a4a2b;
  --mark: #ffe9a8;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);
  --serif:
    "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
    "Times New Roman", serif;
  --sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
}

[data-theme="dark"] {
  --bg: #181613;
  --surface: #211e1a;
  --text: #e8e1d6;
  --muted: #9a9088;
  --rule: #34302a;
  --accent: #e0926a;
  --mark: #6a531f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="dark"]) {
    --bg: #181613;
    --surface: #211e1a;
    --text: #e8e1d6;
    --muted: #9a9088;
    --rule: #34302a;
    --accent: #e0926a;
    --mark: #6a531f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header ------------------------------------------------------------------ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--rule);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}
.title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.4rem;
  margin: 0;
  letter-spacing: 0.01em;
}
.controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

#search {
  width: min(46vw, 320px);
  font: inherit;
  font-size: 0.95rem;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
#search:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.theme {
  font-size: 1.05rem;
  line-height: 1;
  width: 38px;
  height: 38px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.theme:hover {
  border-color: var(--accent);
}
.theme[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

/* Status & pager ---------------------------------------------------------- */
.status {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 18px 0 10px;
  min-height: 1.4em;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 14px 0 22px;
  flex-wrap: wrap;
}
.pager button {
  font: inherit;
  font-size: 1rem;
  min-width: 38px;
  height: 34px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 7px;
  cursor: pointer;
}
.pager button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.pager button:disabled {
  opacity: 0.35;
  cursor: default;
}
.pageinfo {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0 6px;
}
#jump {
  width: 4.2em;
  font: inherit;
  text-align: center;
  padding: 4px 6px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 6px;
}

/* Quotes ------------------------------------------------------------------ */
.quotes {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 40px;
}
.quote {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 18px 20px 16px;
  box-shadow: var(--shadow);
  position: relative;
}
.quote p {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.55;
}
.quote .num {
  position: absolute;
  top: 10px;
  right: 14px;
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.quote mark {
  background: var(--mark);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.quote.empty {
  color: var(--muted);
  font-style: italic;
}

/* Footer ------------------------------------------------------------------ */
.site-footer {
  border-top: 1px solid var(--rule);
  padding: 18px 0 40px;
  color: var(--muted);
  font-size: 0.85rem;
}
.site-footer p {
  margin: 0;
}
kbd {
  font-family: var(--sans);
  font-size: 0.78em;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 50px 0;
  font-family: var(--serif);
  font-size: 1.05rem;
}

/* Floating action buttons ------------------------------------------------- */
.fab {
  position: fixed;
  right: 22px;
  z-index: 20;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}
.fab:hover {
  border-color: var(--accent);
  color: var(--accent);
}
#random-btn {
  bottom: 24px;
}
#top-btn {
  bottom: 80px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
#top-btn.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
@media (max-width: 480px) {
  .fab {
    right: 16px;
    width: 42px;
    height: 42px;
  }
  #random-btn {
    bottom: 18px;
  }
  #top-btn {
    bottom: 70px;
  }
}

/* Random quote modal ------------------------------------------------------ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal[hidden] {
  display: none;
}
.modal-card {
  position: relative;
  max-width: 560px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
  padding: 34px 32px 26px;
  animation: pop 0.15s ease-out;
}
@keyframes pop {
  from {
    transform: scale(0.96);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 34px;
  height: 34px;
  font-size: 1.5rem;
  line-height: 1;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
}
.modal-close:hover {
  color: var(--accent);
}
.random-quote {
  margin: 0 0 22px;
  font-family: var(--serif);
  font-size: 1.3rem;
  line-height: 1.55;
}
.random-again {
  font: inherit;
  font-size: 0.92rem;
  padding: 9px 16px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 8px;
  cursor: pointer;
}
.random-again:hover {
  border-color: var(--accent);
  color: var(--accent);
}
@media (prefers-reduced-motion: reduce) {
  .modal-card {
    animation: none;
  }
  html {
    scroll-behavior: auto;
  }
}
