*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:        #fafaf8;
  --text:      #1a1a18;
  --text-dim:  #888880;
  --text-faint:#bbbbb2;
  --border:    #e0e0d8;
  --red:       #c0392b;

  --font-serif: 'EB Garamond', Georgia, serif;
  --font-sans:  'Inter', system-ui, sans-serif;

  --measure:    62ch;
  --toolbar-h:  48px;
}

html {
  font-size: 18px;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  line-height: 1.5;
  min-height: 100dvh;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.hidden { display: none !important; }

.screen.active { display: block; }

/* ── Header ── */
.site-header {
  padding: 96px 24px 48px;
  text-align: center;
}

.site-title {
  font-family: var(--font-sans);
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  font-weight: 400;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text);
}

.site-tagline {
  margin-top: 12px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--text-dim);
}

/* ── Search ── */
.search-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 24px 96px;
}

.search-box-wrap {
  margin-bottom: 24px;
}

.search-input {
  width: 100%;
  padding: 0 0 10px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  border-radius: 0;
}

.search-input:focus {
  border-bottom-color: var(--text);
}

.search-input::placeholder {
  color: var(--text-faint);
}

.search-input::-webkit-search-cancel-button {
  opacity: 0.35;
  cursor: pointer;
}

.search-status {
  display: block;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-faint);
  min-height: 1em;
  letter-spacing: 0.02em;
}

/* ── Results ── */
.results-state {
  padding: 48px 0;
  color: var(--text-dim);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1rem;
}

.results-list {
  display: flex;
  flex-direction: column;
}

.result-card {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: opacity 0.1s;
  text-align: left;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  border-radius: 0;
  width: 100%;
}

.result-card:first-child {
  border-top: 1px solid var(--border);
}

.result-card:hover { opacity: 0.6; }

.result-card:focus-visible {
  outline: 1px solid var(--text);
  outline-offset: 4px;
}

.result-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--text);
  line-height: 1.3;
}

.result-author {
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.result-meta {
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

.result-preview {
  margin-top: 8px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Reader toolbar ── */
.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.1s;
  padding: 0;
}

.btn-icon:hover { color: var(--text); }

.btn-text {
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0;
  cursor: pointer;
  transition: color 0.1s;
}

.btn-text:hover,
.btn-text[aria-pressed="true"] {
  color: var(--text);
}

.reader-title-block {
  flex: 1;
  min-width: 0;
}

.reader-title {
  display: block;
  font-family: var(--font-serif);
  font-size: 0.92rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-author {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.reader-progress {
  font-size: 0.72rem;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

/* ── Reader body ── */
.reader-body {
  display: flex;
  justify-content: center;
}

.reader-pane {
  width: 100%;
  max-width: var(--measure);
  padding: 64px 24px 128px;
}

.chunk-container {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  line-height: 1.9;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Dual-pane ── */
.reader-body.dual {
  height: calc(100dvh - var(--toolbar-h));
  overflow: hidden;
  gap: 1px;
  background: var(--border);
}

.reader-body.dual .reader-pane {
  flex: 1;
  max-width: none;
  background: var(--bg);
  overflow-y: auto;
  height: 100%;
}

/* Original text pane is dimmer than the AntiBook */
.reader-body.dual .reader-pane + .reader-pane .chunk-container {
  color: var(--text-dim);
}

/* ── Word highlighting (compare mode) ── */
.w { display: inline; }
.w.hi {
  background: rgba(160, 110, 0, 0.14);
  border-radius: 2px;
  outline: 1px solid rgba(160, 110, 0, 0.22);
  outline-offset: 0;
}

/* ── Spinner ── */
.reader-spinner {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 40px 0;
}

.reader-spinner span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: pulse 1.2s ease-in-out infinite;
}

.reader-spinner span:nth-child(2) { animation-delay: 0.2s; }
.reader-spinner span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.2; }
  40%            { opacity: 1;   }
}

/* ── End ── */
.reader-end {
  margin-top: 80px;
  text-align: center;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--text-faint);
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .site-header  { padding: 56px 20px 32px; }
  .reader-pane  { padding: 40px 20px 80px; }
  .chunk-container { font-size: 1.05rem; }
  .btn-text     { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .reader-spinner span { animation: none; opacity: 0.3; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); }
