:root {
  --bg: #ffffff;
  --fg: #222222;
  --accent: #4a6fa5;
  --muted: #888;
  --surface: #f4f4f4;
  --border: #e0e0e0;

  --font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-size: 18px;
  --line-height: 1.7;
  --letter-spacing: 0em;
  --word-spacing: 0em;
  --para-spacing: 1em;
  --max-width: 72ch;
  --text-align: left;
  --text-indent: 0;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --fg: #e0e0e0;
  --accent: #7aa7d9;
  --muted: #9a9a9a;
  --surface: #2a2a2a;
  --border: #3a3a3a;
}

[data-theme="sepia"] {
  --bg: #f4ecd8;
  --fg: #5b4636;
  --accent: #7a5a3e;
  --muted: #a08a70;
  --surface: #ebe0c4;
  --border: #d9cbae;
}

[data-theme="black"] {
  --bg: #000000;
  --fg: #d0d0d0;
  --accent: #8fb4e3;
  --muted: #888;
  --surface: #0e0e0e;
  --border: #222;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.15s ease, color 0.15s ease;
}

.topbar,
.bottombar {
  position: sticky;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  z-index: 10;
  transition: transform 0.22s ease;
  will-change: transform;
}

.topbar.panel-hidden {
  transform: translateY(-100%);
}

.bottombar.panel-hidden {
  transform: translateY(100%);
}

.topbar {
  top: 0;
}

.bottombar {
  top: auto;
  bottom: 0;
  border-top: 1px solid var(--border);
  border-bottom: none;
  justify-content: space-between;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.jump {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95em;
}

.muted {
  color: var(--muted);
  font-size: 0.9em;
}

button,
select,
input[type="number"],
input[type="text"] {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  background: var(--surface);
  border-color: var(--accent);
}

input[type="number"] {
  width: 5.5rem;
  cursor: text;
}

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

#reader {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 2.5rem auto 4rem;
  padding: 0 1.5rem;
  font-size: var(--font-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  word-spacing: var(--word-spacing);
  text-align: var(--text-align);
}

#chapterTitle {
  font-size: calc(var(--font-size) * 1.4);
  line-height: 1.25;
  text-align: center;
  color: var(--accent);
  margin: 0 0 2rem 0;
}

#chapterBody p {
  margin: 0 0 var(--para-spacing) 0;
  text-indent: var(--text-indent);
}

#status {
  margin-top: 3rem;
  text-align: center;
  word-break: break-all;
}

.settings {
  position: fixed;
  right: 1rem;
  top: 3.5rem;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  width: 340px;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

.settings.hidden {
  display: none;
}

.settings h2 {
  margin: 0 0 0.25rem 0;
  font-size: 1.05em;
}

.settings label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.settings label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.settings .row {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

@media (max-width: 480px) {
  .settings {
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
  }
  #reader {
    padding: 0 1rem;
    margin: 1.5rem auto 3rem;
  }
}

/* Home page */

.home-page .topbar {
  justify-content: space-between;
}

.home {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.novel-card {
  display: flex;
  gap: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.novel-cover {
  flex: 0 0 140px;
  aspect-ratio: 2 / 3;
  background: linear-gradient(135deg, var(--accent), var(--border));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  color: var(--bg);
}

.novel-cover-emoji {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.novel-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.novel-title {
  margin: 0;
  font-size: 1.75rem;
  color: var(--accent);
  line-height: 1.2;
}

.novel-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.95em;
}

.novel-desc {
  margin: 0.25rem 0 0.5rem 0;
  color: var(--fg);
  line-height: 1.5;
}

.novel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.btn,
.btn-primary,
.btn-quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  text-decoration: none;
  cursor: pointer;
  background: var(--bg);
  color: var(--fg);
  transition: background 0.1s ease, border-color 0.1s ease;
}

.btn:hover,
.btn-quiet:hover {
  background: var(--surface);
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-quiet {
  background: transparent;
  color: var(--muted);
}

#progress-info {
  margin-top: 0.75rem;
}

.history-section h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1.1rem;
  color: var(--fg);
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.history-list li {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}

.history-list li:hover {
  background: var(--surface);
}

.history-list a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.history-list a:hover {
  text-decoration: underline;
}

@media (max-width: 600px) {
  .novel-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .novel-cover {
    flex-basis: auto;
    width: 120px;
  }
  .novel-actions {
    justify-content: center;
  }
}
