:root {
  --max: 680px;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, sans-serif;
  --bg: #fdfaf6;
  --text: #1a1a1a;
  --muted: #666;
  --border: #e0dbd3;
  --accent: #2c2c2c;
  --card-bg: #fff;
}

body.dark {
  --bg: #181614;
  --text: #e5e0d8;
  --muted: #888;
  --border: #2e2a27;
  --accent: #e5e0d8;
  --card-bg: #1e1c1a;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

/* ── Login ─────────────────────────────────── */
[data-view="login"] {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-box {
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.login-box h1 {
  font-family: var(--serif);
  font-size: 2rem;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.login-box .subtitle {
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#login-form input {
  font-family: var(--sans);
  font-size: 1rem;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--text);
  text-align: center;
  letter-spacing: 0.05em;
}

#login-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#login-form button {
  font-family: var(--sans);
  font-size: 1rem;
  padding: 0.65rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#login-form button:hover { background: #444; }

.error {
  color: #c0392b;
  font-size: 0.875rem;
}

/* ── Top bar ────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.site-title {
  font-family: var(--serif);
  font-size: 1rem;
  letter-spacing: 0.05em;
}

.counter {
  font-size: 0.8rem;
  color: var(--muted);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  height: 28px;
  min-width: 28px;
  line-height: 1;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

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

/* ── Books ──────────────────────────────────── */
.books-main {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.books-main h2 {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: normal;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

.chapter-picker {
  position: relative;
}

.chapter-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 240px;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
}

.chapter-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 1rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  font-family: var(--serif);
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  line-height: 1.3;
}

.chapter-dropdown button:last-child { border-bottom: none; }
.chapter-dropdown button:hover { background: var(--border); }
.chapter-dropdown button.active { color: var(--accent); font-style: italic; }

.book-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s;
  background: var(--card-bg);
}

.book-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); }

.book-card img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: var(--border);
}

.book-card-body {
  padding: 0.75rem 1rem;
}

.book-card-body h3 {
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: normal;
  line-height: 1.3;
  margin-bottom: 0.25rem;
}

.book-card-body p {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Reader ─────────────────────────────────── */
.reader-main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 2rem 1.5rem 1rem;
  overflow-x: hidden;
  touch-action: pan-y;
}

.chapter-title-bar {
  font-family: var(--serif);
  font-size: 0.9rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 0.5rem;
}


#chapter-body {
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.8;
  will-change: transform, opacity;
}

@keyframes slide-out-left  { from { transform: translateX(0);     opacity: 1;   } to { transform: translateX(-100%); opacity: 0.3; } }
@keyframes slide-out-right { from { transform: translateX(0);     opacity: 1;   } to { transform: translateX( 100%); opacity: 0.3; } }
@keyframes slide-in-right  { from { transform: translateX( 100%); opacity: 0.3; } to { transform: translateX(0);     opacity: 1;   } }
@keyframes slide-in-left   { from { transform: translateX(-100%); opacity: 0.3; } to { transform: translateX(0);     opacity: 1;   } }

.slide-out-left  { animation: slide-out-left  0.28s cubic-bezier(0.4,0,1,1)   forwards; }
.slide-out-right { animation: slide-out-right 0.28s cubic-bezier(0.4,0,1,1)   forwards; }
.slide-in-right  { animation: slide-in-right  0.28s cubic-bezier(0,0,0.2,1)   forwards; }
.slide-in-left   { animation: slide-in-left   0.28s cubic-bezier(0,0,0.2,1)   forwards; }

#chapter-body p { margin: 1.1em 0; }
#chapter-body h1, #chapter-body h2, #chapter-body h3 {
  font-family: var(--serif);
  font-weight: normal;
  margin: 1.5em 0 0.5em;
}
#chapter-body em { font-style: italic; }

.reader-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  max-width: var(--max);
  margin: 2rem auto;
  padding: 0 1.5rem 1.5rem;
}

.btn-nav {
  font-size: 1.4rem;
  padding: 0.3rem 0.5rem;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.15s;
  line-height: 1;
}

.btn-nav:hover:not(:disabled) { color: var(--text); }
.btn-nav:disabled { opacity: 0.2; cursor: default; }

.nav-ornament {
  font-size: 0.9rem;
  color: var(--muted);
  opacity: 0.6;
  pointer-events: none;
  user-select: none;
}

/* ── Utility ────────────────────────────────── */
[hidden] { display: none !important; }
