:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-alt: #eef2f1;
  --text: #102a27;
  --muted: #526865;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --border: #d8e2e0;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --warn-bg: #fef9c3;
  --warn-text: #854d0e;
  --shadow: 0 4px 16px rgba(16, 42, 39, 0.08);
}

body.theme-sepia {
  --bg: #f6efe2;
  --surface: #fbf6ec;
  --surface-alt: #efe5d3;
  --text: #3b2f23;
  --muted: #705c48;
  --primary: #8c5a2b;
  --primary-hover: #6e451f;
  --border: #e0d2ba;
}

body.theme-dark {
  --bg: #0e1414;
  --surface: #172020;
  --surface-alt: #202c2c;
  --text: #e6efef;
  --muted: #9db0ae;
  --primary: #2dd4bf;
  --primary-hover: #14b8a6;
  --border: #283636;
  --success-bg: #133824;
  --success-text: #86efac;
  --warn-bg: #3b3010;
  --warn-text: #fde047;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Noto Sans Bengali", "Hind Siliguri", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 26px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.status-pill {
  display: inline-block;
  margin-top: 3px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.status-pill.online {
  background: var(--success-bg);
  color: var(--success-text);
}

.status-pill.offline {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.icon-btn-sm {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
}

.icon-btn-sm {
  width: 32px;
  height: 32px;
  font-size: 14px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.action-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.primary-btn,
.secondary-btn,
.nav-btn,
.ghost-btn,
.mini-btn {
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.primary-btn {
  background: var(--primary);
  color: #ffffff;
  width: 100%;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.secondary-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.ghost-btn {
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
}

.mini-btn {
  padding: 6px 10px;
  font-size: 12px;
  background: var(--primary);
  color: #fff;
}

.url-import-box {
  display: flex;
  gap: 8px;
}

.url-import-box input,
.modal-body input {
  flex: 1;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 14px;
}

.sync-banner {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 12px;
}

.section-header h2 {
  margin: 0;
  font-size: 16px;
}

.badge {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

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

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow);
}

.book-cover {
  height: 110px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--surface-alt), var(--border));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  cursor: pointer;
}

.book-title {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  word-break: break-word;
  cursor: pointer;
}

.book-meta {
  font-size: 11px;
  color: var(--muted);
}

.sync-tag {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.sync-tag.synced {
  background: var(--success-bg);
  color: var(--success-text);
}

.sync-tag.pending {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.book-actions {
  display: flex;
  gap: 6px;
}

.book-actions button {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.book-actions button.open-btn {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.reader-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.reader-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.reader-title-wrap {
  min-width: 0;
  flex: 1;
  text-align: center;
}

.reader-title-wrap h2 {
  margin: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-title-wrap span {
  font-size: 11px;
  color: var(--muted);
}

.reader-tools {
  display: flex;
  gap: 4px;
}

.reader-stage {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 14px;
  position: relative;
}

#pdf-canvas {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  box-shadow: var(--shadow);
  background: #ffffff;
}

.page-loading {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
}

.reader-bottombar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.reader-bottombar input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.nav-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  color: var(--text);
  cursor: pointer;
}

.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.modal-footer {
  margin-top: 6px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  box-shadow: var(--shadow);
}
