:root {
  --bg: #14141b;
  --surface: #1e1e2a;
  --surface-2: #272736;
  --border: #34344a;
  --text: #e8e8f0;
  --muted: #9a9ab0;
  --accent: #7c6cff;
  --accent-hover: #9385ff;
  --reading: #4caf82;
  --plan: #4a8fd6;
  --hold: #d6a14a;
  --completed: #8a7cff;
  --dropped: #d65a5a;
}

/* Light theme — overrides the neutral palette; accents/status stay */
:root[data-theme="light"] {
  --bg: #f1f1f6;
  --surface: #ffffff;
  --surface-2: #ebebf2;
  --border: #d9d9e3;
  --text: #1c1c27;
  --muted: #66667a;
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  /* Soft purple halo under the topbar fading into the base colour. */
  background:
    radial-gradient(ellipse 900px 480px at 50% -120px, rgba(124, 108, 255, .22), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Top bar — Asura-style purple navbar */
.topbar {
  background: linear-gradient(90deg, #7a25c4 0%, #a23ce0 55%, #b249e8 100%);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .35);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 9px;
}

.icon { width: 20px; height: 20px; flex: none; }
.logo .icon { width: 24px; height: 24px; }

/* Search box living inside the topbar */
.topbar-search {
  flex: 1 1 240px;
  max-width: 520px;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid rgba(0, 0, 0, .25);
  border-radius: 10px;
  padding: 9px 14px;
}
.topbar-search:focus-within { outline: 2px solid rgba(255, 255, 255, .7); }
.topbar-search .search-icon { width: 18px; height: 18px; opacity: .55; }
.topbar-search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.95rem;
}
.topbar-search input:focus { outline: none; }

/* White action button so it pops against the purple bar */
.topbar .btn-primary {
  background: #fff;
  border-color: #fff;
  color: #7a25c4;
}
.topbar .btn-primary:hover { background: #ede5fb; border-color: #ede5fb; }

/* Notification bell */
.bell-wrap { position: relative; flex: none; }
.icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .28); }
.bell-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e0454a;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #9b3bd6;
}
.account-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4ade80;
  border: 2px solid #9b3bd6;
}
.auth-error {
  color: #ff8a8a;
  margin: 4px 0 0;
  font-size: 0.9rem;
  min-height: 1.2em;
}
.bell-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 330px;
  max-height: 420px;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, .55);
  z-index: 50;
}
.bell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.bell-head-actions { display: flex; gap: 6px; }
.bell-check {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--accent-hover);
  cursor: pointer;
}
.bell-check:hover { background: var(--border); }
.bell-check:disabled { opacity: .6; cursor: default; }
.bell-list { padding: 6px; }
.bell-empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
}
.bell-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
}
.bell-item:hover { background: var(--surface-2); }
.bell-item .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--reading);
  flex: none;
}
.bell-item-body {
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: var(--text);
}
.bell-dismiss {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.bell-dismiss:hover { background: var(--border); color: var(--text); }
.bell-dismiss svg { width: 14px; height: 14px; }
.bell-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bell-item-sub { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all .15s;
}
.chip:hover { color: var(--text); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stats { color: var(--muted); font-size: 0.85rem; margin-bottom: 18px; }

/* Buttons */
.btn {
  padding: 9px 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all .15s;
}
.btn:hover { background: var(--border); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger {
  background: var(--dropped);
  border-color: var(--dropped);
  color: #fff;
  font-weight: 600;
}
.btn-danger:hover { filter: brightness(1.1); }

.confirm-message { color: var(--muted); margin: 4px 0 18px; font-size: 0.95rem; }

/* Grid of cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.card {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.card:hover { box-shadow: 0 8px 24px rgba(124, 108, 255, .18); }
.card:hover { transform: translateY(-3px); border-color: var(--accent); }

.cover {
  aspect-ratio: 3 / 4;
  width: 100%;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}
.cover-link { display: block; }
.cover, .cover-placeholder { transition: opacity .12s; }
.cover-link:hover .cover,
.cover-link:hover .cover-placeholder { opacity: .82; }
.cover-placeholder {
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--surface-2), var(--bg));
  color: var(--muted);
}
.cover-placeholder svg { width: 38%; height: 38%; opacity: .5; }

.card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge {
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
}
.badge.Reading { background: var(--reading); }
.badge.Plan { background: var(--plan); }
.badge.On { background: var(--hold); }
.badge.Completed { background: var(--completed); }
.badge.Dropped { background: var(--dropped); }

/* Tags row: editable status pill + source-site label */
.card-tags { display: flex; align-items: center; gap: 8px; }

.badge-select {
  appearance: none;
  -webkit-appearance: none;
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 4px 22px 4px 10px;
  cursor: pointer;
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0h8L4 5z' fill='%23ffffff'/%3E%3C/svg%3E");
}
.badge-select.Reading { background-color: var(--reading); }
.badge-select.Plan { background-color: var(--plan); }
.badge-select.On { background-color: var(--hold); }
.badge-select.Completed { background-color: var(--completed); }
.badge-select.Dropped { background-color: var(--dropped); }
.badge-select option { background: var(--surface); color: var(--text); }
.badge-select:focus { outline: 2px solid var(--accent-hover); }

.site-tags {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.site-tag {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

.setting-select {
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 140px;
}
.setting-select:focus { outline: 2px solid var(--accent); }

.chapter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
}
.chapter-label { color: var(--muted); font-size: 0.85rem; flex: 1; display: flex; align-items: center; gap: 4px; }
.chapter-num { color: var(--text); font-weight: 700; }
.caught-up {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.step-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.step-btn:hover { background: var(--accent); border-color: var(--accent); }

.card-actions { display: flex; gap: 6px; }
.card-actions a, .card-actions button {
  flex: 1;
  text-align: center;
  font-size: 0.8rem;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.card-actions a:hover, .card-actions button:hover { background: var(--border); }
.danger:hover { background: var(--dropped) !important; border-color: var(--dropped) !important; }

/* Empty state */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty p { margin-bottom: 16px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  /* Stay inside the viewport on short windows; scroll internally if the
     content (Settings panel especially) outgrows it. */
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.modal h2 { margin-bottom: 18px; }
.modal form { display: flex; flex-direction: column; gap: 14px; }
.modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}
.modal input, .modal select {
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}
.modal input:focus, .modal select:focus { outline: 2px solid var(--accent); }
.row { display: flex; gap: 12px; }
.row label { flex: 1; }
.merge-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.merge-hint { font-size: 0.78rem; color: var(--muted); line-height: 1.4; }
.req { color: var(--dropped); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* Sort dropdown */
.sort-select {
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.sort-select:focus { outline: 2px solid var(--accent); }

/* Settings modal */
.modal-section {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 20px 0 2px;
}
.modal h2 + .modal-section { margin-top: 4px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.setting-text { display: flex; flex-direction: column; gap: 3px; }
.setting-name { font-size: 0.92rem; font-weight: 600; color: var(--text); }
.setting-desc { font-size: 0.78rem; color: var(--muted); line-height: 1.4; }

.data-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }

.site-list {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.site-list li {
  font-size: 0.84rem;
  color: var(--muted);
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.site-list li strong { color: var(--text); margin-right: 4px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background .15s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .15s, background .15s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent-hover); }
