:root {
  color-scheme: light;
  --bg: #fbf9f8;
  --surface: #ffffff;
  --surface-2: #f5f3f2;
  --text: #1b1c1b;
  --text-muted: #544246;
  --accent: #c98a3b;
  --accent-tint: #f7ead4;
  --accent-dark: #a8721f;
  --heading: #721c3d;
  --heading-tint: #ffd9e1;
  --primary: #550227;
  --primary-hover: #721c3d;
  --border: #dac0c5;
  --danger: #c14f4f;
  --font-display: "Century Gothic", CenturyGothic, AppleGothic, "URW Gothic", Futura, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Century Gothic", CenturyGothic, AppleGothic, "URW Gothic", Futura, -apple-system, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1417;
    --surface: #241a1d;
    --surface-2: #2c2024;
    --text: #f2e9ea;
    --text-muted: #c7b3b8;
    --accent: #e3a75c;
    --accent-tint: #2c2418;
    --heading: #ffb1c5;
    --heading-tint: #3f001b;
    --primary: #a6445d;
    --primary-hover: #c1567a;
    --border: #4a3238;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  padding: calc(16px + var(--safe-top)) 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  font-family: "Questrial", -apple-system, "Segoe UI", sans-serif;
  color: var(--heading);
  display: flex;
  align-items: center;
  gap: 6px;
}

.view-toggle {
  display: inline-flex;
  margin-top: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.view-toggle-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.view-toggle-btn.active {
  background: var(--primary);
  color: #fff;
}

.tab-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 4;
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tab-add {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.tab-add:hover { color: var(--heading); border-color: var(--heading); }

.tab.dragging, .subtab.dragging { opacity: 0.35; }

.drag-proxy {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  transform: scale(1.05);
}

/* ---------- category drawer ---------- */

.category-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 15;
}

.category-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: var(--bg);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
  overflow-y: auto;
  padding-bottom: calc(20px + var(--safe-bottom));
}

.category-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

.category-drawer-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--heading);
}

.categories-home {
  padding: 4px 16px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
}

.category-row.active {
  background: var(--accent-tint);
  border-color: var(--accent);
}

.category-row-label {
  flex: 1;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--heading);
}

.category-row-edit {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}
.category-row-edit:hover { color: var(--heading); }

.category-row.dragging { opacity: 0.35; }

.category-row-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.category-row-add:hover { color: var(--heading); border-color: var(--heading); }

.category-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 4;
}

.category-bar h2 {
  flex: 1;
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--heading);
  text-align: center;
}

.content.empty-book-state {
  padding-top: 60px;
  text-align: center;
  color: var(--text-muted);
}

.subtab-bar {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 3;
  -webkit-overflow-scrolling: touch;
}

.subtab {
  flex: 0 0 auto;
  padding: 5px 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.subtab.active {
  background: var(--accent-tint);
  color: var(--heading);
  border-color: var(--accent);
}

.subtab-add {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.subtab-add:hover { color: var(--heading); border-color: var(--heading); }

.content {
  padding: 16px 16px calc(100px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 60px;
  font-size: 15px;
  line-height: 1.5;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  cursor: pointer;
}

.card h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-family: var(--font-display);
  color: var(--heading);
}

.card p {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  border: none;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  z-index: 6;
}
.fab:hover { background: var(--primary-hover); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}

.modal-overlay.hidden { display: none; }

.modal {
  width: 100%;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  max-height: 85vh;
  overflow-y: auto;
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-family: var(--font-display);
  color: var(--heading);
}

.modal label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.modal input,
.modal textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-display);
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); flex: 0 0 auto; padding: 12px 16px; }
.btn-neutral { background: transparent; border: 1px solid var(--border); color: var(--text-muted); font-size: 13px; padding: 8px 10px; }
.btn-neutral:hover { color: var(--heading); border-color: var(--heading); }

.move-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.subscribe-copy {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  margin: 0 0 16px;
}
.subscribe-copy strong { color: var(--text); }

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.cal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--heading);
}

.cal-nav-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}
.cal-nav-btn:hover { color: var(--heading); border-color: var(--heading); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 20px;
}

.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 4px;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  position: relative;
}

.cal-day.empty { background: transparent; cursor: default; }
.cal-day.today { border-color: var(--accent); }
.cal-day.selected { background: var(--primary); color: #fff; }

.cal-day .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 3px;
}
.cal-day.selected .dot { background: #fff; }

.cal-day-events { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }

.cal-subscribe {
  width: 100%;
}

/* ---------- auth ---------- */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px calc(20px + var(--safe-bottom)) calc(24px + var(--safe-bottom)) 20px;
  padding-top: calc(24px + var(--safe-top));
  z-index: 20;
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.08);
  padding: 32px 28px;
}

.auth-brand {
  font-family: "Questrial", -apple-system, "Segoe UI", sans-serif;
  font-size: 24px;
  color: var(--heading);
  margin: 0 0 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.brand-icon {
  height: 1.4em;
  width: auto;
  flex-shrink: 0;
  display: block;
}

.auth-card h2 {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--heading);
  margin: 0 0 16px;
  text-align: center;
}

.auth-copy {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  margin: 0 0 16px;
}

.auth-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.auth-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}

.auth-full-btn {
  width: 100%;
  margin-top: 4px;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin: -6px 0 12px;
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 18px;
}

.auth-switch a {
  color: var(--heading);
  font-weight: 600;
  text-decoration: none;
}

/* ---------- avatar & account menu ---------- */

.topbar-icon-btn {
  position: absolute;
  top: calc(16px + var(--safe-top));
  right: 64px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.topbar-icon-btn:hover { color: var(--heading); border-color: var(--heading); }

.topbar-avatar {
  position: absolute;
  top: calc(16px + var(--safe-top));
  right: 20px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.account-dropdown {
  position: absolute;
  top: calc(56px + var(--safe-top));
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  padding: 10px;
  min-width: 160px;
  z-index: 6;
}

.account-dropdown-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  padding: 6px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.account-dropdown-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-body);
}
.account-dropdown-link:hover { background: var(--surface-2); }

/* ---------- admin ---------- */

.modal-wide { max-width: 480px; margin: 0 auto; }

.admin-section { margin-bottom: 20px; }

.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.admin-section-head h3 {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--heading);
  margin: 0;
}

.admin-list { display: flex; flex-direction: column; gap: 8px; }

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
}

.admin-row-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.admin-row-info strong { font-size: 14px; color: var(--text); }
.admin-row-info span { font-size: 12px; color: var(--text-muted); }

.admin-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.admin-row-actions .btn-neutral {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-body);
}
.admin-row-actions .btn-neutral:hover { color: var(--heading); border-color: var(--heading); }
.admin-danger-text { color: var(--danger) !important; }

/* ---------- help ---------- */

.help-modal { max-height: 85vh; overflow-y: auto; }

.help-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.help-modal-head h2 { margin: 0; }

.help-section { margin-top: 22px; }
.help-section h3 {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--heading);
  margin: 0 0 2px;
}
.help-section .help-intro-text {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.5;
}

.help-list { display: flex; flex-direction: column; gap: 12px; }
.help-list .term { font-size: 13.5px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.help-list .desc { font-size: 13px; color: var(--text-muted); line-height: 1.55; margin: 0; }

/* ---------- settings ---------- */

.settings-menu { display: flex; flex-direction: column; gap: 6px; }

.settings-menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  background: var(--surface-2);
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-body);
}
.settings-menu-row:hover { background: var(--accent-tint); }

.settings-menu-text { display: flex; flex-direction: column; gap: 2px; }
.settings-menu-label { font-size: 14px; font-weight: 700; color: var(--text); }
.settings-menu-sub { font-size: 12px; color: var(--text-muted); }
.settings-menu-chevron { color: var(--text-muted); font-size: 18px; flex-shrink: 0; }

.settings-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.hidden { display: none !important; }
