:root {
  --bg: #f5f5f2;
  --panel: #ffffff;
  --text: #202020;
  --muted: #707070;
  --border: #dddddd;
  --accent: #4f6f52;
  --accent-light: #e8efe8;
  --shadow: rgba(0, 0, 0, 0.08);
  --reader-font-size: 18px;
}

body.dark {
  --bg: #151515;
  --panel: #202020;
  --text: #eeeeee;
  --muted: #aaaaaa;
  --border: #3a3a3a;
  --accent: #9bbf9e;
  --accent-light: #253126;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 2px 12px var(--shadow);
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 18px;
  padding: 18px;
  min-height: calc(100vh - 130px);
}

.sidebar {
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel,
.readerPanel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 6px 20px var(--shadow);
}

.panel {
  padding: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

#searchInput {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.list {
  display: grid;
  gap: 8px;
}

.list button {
  width: 100%;
  text-align: left;
  line-height: 1.35;
}

.list button.active {
  background: var(--accent-light);
  border-color: var(--accent);
}

.itemTitle {
  display: block;
  font-weight: 700;
}

.itemMeta {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.readerPanel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.readerHeader {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.readerHeader h2 {
  margin: 0 0 6px;
}

.readerHeader p {
  margin: 0;
  color: var(--muted);
}

.readerActions,
.epubControls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.epubControls {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}

.reader {
  padding: 28px;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
  font-size: var(--reader-font-size);
  line-height: 1.9;
  overflow-wrap: anywhere;
}

.reader p {
  margin: 0 0 1.1em;
}

.reader img {
  max-width: 100%;
  height: auto;
}

.reader .error {
  color: #b00020;
  background: rgba(176, 0, 32, 0.08);
  border: 1px solid rgba(176, 0, 32, 0.2);
  padding: 12px;
  border-radius: 8px;
}

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

.hidden {
  display: none;
}

.footer {
  padding: 12px 24px 18px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .topbar,
  .readerHeader {
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .reader {
    padding: 20px;
  }
}
