:root {
  --bg: #0b0e14;
  --surface: #141923;
  --surface-2: #1c2331;
  --glass: rgba(20, 25, 35, 0.84);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.28);
  --accent-2: #2dd4bf;
  --danger: #ef4444;
  --border: rgba(255, 255, 255, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 15% 10%, rgba(59, 130, 246, 0.14), transparent 42%),
    radial-gradient(circle at 85% 85%, rgba(45, 212, 191, 0.09), transparent 45%),
    radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 24px 24px;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  max-width: 920px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-shell--login {
  max-width: 100%;
}

.app-shell--login main {
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* Login split-screen (mobile-first) */
.login-split {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

.login-hero {
  background: linear-gradient(155deg, #10251c 0%, #0d1926 100%);
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.login-hero__brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: #f8fafc;
}

.login-kicker {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin: 0 0 0.5rem 0;
}

.login-hero__title {
  margin: 0 0 0.85rem 0;
  font-size: 1.65rem;
  line-height: 1.2;
  color: #ffffff;
}

.login-pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.login-pill {
  font-size: 0.78rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #e2e8f0;
}

.login-hero__foot {
  font-size: 0.8rem;
  color: #94a3b8;
  margin: 0;
}

.login-panel {
  flex: 1;
  background: var(--bg);
  padding: 1.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-panel__inner {
  width: 100%;
  max-width: 380px;
}

.login-panel__inner h2 {
  margin: 0 0 0.4rem 0;
  font-size: 1.5rem;
}

.password-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin-top: 0.35rem;
}

.password-row input {
  margin-top: 0;
  flex: 1;
}

.password-toggle {
  white-space: nowrap;
  padding: 0 0.85rem !important;
}

.login-help {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.login-help h3 {
  margin: 0 0 0.35rem 0;
  font-size: 1rem;
}

@media (min-width: 768px) {
  .login-split {
    flex-direction: row;
  }

  .login-hero {
    flex: 0 0 46%;
    padding: 2.5rem 3rem;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }

  .login-hero__title {
    font-size: 2.25rem;
  }

  .login-panel {
    flex: 1;
    padding: 3rem;
  }
}

/* Glassmorphic Header */
.topbar {
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  padding: 0.4rem 0.65rem !important;
  font-size: 0.85rem !important;
}

.icon-btn.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
}

main {
  flex: 1;
  padding: 0.9rem 0.9rem 5.5rem 0.9rem;
}

.card {
  background: linear-gradient(180deg, rgba(28, 35, 49, 0.72), rgba(20, 25, 35, 0.92));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 0.9rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 8px 24px rgba(0, 0, 0, 0.3);
}

label {
  display: block;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
}

input:not([type="checkbox"]),
select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

input[type="checkbox"] {
  width: auto;
  margin-right: 0.45rem;
  accent-color: var(--accent);
}

button:not(.nav-btn):not(.tab):not(.chip-btn):not(.icon-btn) {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.68rem 1rem;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: filter 0.15s ease, transform 0.12s ease;
}

button:not(.nav-btn):not(.tab):not(.chip-btn):not(.icon-btn):hover {
  filter: brightness(1.08);
}

button.btn-secondary:not(.nav-btn):not(.tab):not(.chip-btn):not(.icon-btn) {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.btn-block {
  width: 100%;
  margin-top: 0.25rem;
}

/* Filter Drawer & Chips */
.library-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.library-controls__row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.library-controls__row input,
.library-controls__row select {
  margin-top: 0;
  padding: 0.48rem 0.65rem;
  font-size: 0.86rem;
  width: auto;
  flex: 1 1 120px;
}

.library-controls__chips {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
}

.chip-btn {
  background: var(--surface-2) !important;
  color: var(--muted) !important;
  border: 1px solid var(--border) !important;
  border-radius: 999px !important;
  padding: 0.3rem 0.72rem !important;
  font-size: 0.78rem !important;
  font-weight: 600 !important;
  cursor: pointer;
}

.chip-btn.active {
  background: var(--accent-glow) !important;
  color: #93c5fd !important;
  border-color: var(--accent) !important;
}

/* Library Poster Grid */
.tabs {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
  overflow-x: auto;
}

.tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.38rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

@media (min-width: 600px) {
  .grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.8rem;
  }
}

.series-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.series-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

.cover {
  aspect-ratio: 2 / 3;
  height: auto;
  background: var(--surface-2);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover__overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.6rem 0.5rem 0.45rem 0.5rem;
  background: linear-gradient(transparent, rgba(5, 7, 11, 0.94));
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.unread-badge {
  position: absolute;
  top: 7px;
  left: 7px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Series Hero Banner */
.series-hero {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 0.9rem;
  background: var(--surface);
}

.series-hero__bg {
  position: absolute;
  inset: -12px;
  background-size: cover;
  background-position: center;
  filter: blur(22px) brightness(0.42);
  transform: scale(1.08);
}

.series-hero__body {
  position: relative;
  padding: 1rem;
  display: flex;
  gap: 0.9rem;
  align-items: flex-end;
}

.series-hero__poster {
  width: 92px;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: var(--surface-2);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.series-hero__poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.series-hero__meta {
  min-width: 0;
  flex: 1;
}

.series-hero__meta h2 {
  margin: 0 0 0.35rem 0;
  font-size: 1.25rem;
}

.series-hero__controls {
  position: relative;
  padding: 0 1rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Chapter Rows */
.chapter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.78rem 0.9rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.chapter-row.read {
  opacity: 0.48;
}

.chapter-row:last-child {
  border-bottom: none;
}

/* Search Results */
.search-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem;
}

.search-result__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.search-result__thumb {
  width: 54px;
  height: 76px;
  border-radius: 8px;
  background: var(--surface-2);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.search-result__thumb--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--muted);
}

.search-result__meta {
  min-width: 0;
  overflow-wrap: anywhere;
}

.search-result__title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
  margin-bottom: 0.25rem;
}

.search-result button {
  flex-shrink: 0;
}

/* Reader */
.reader-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  background: var(--glass);
  backdrop-filter: blur(12px);
}

.reader-toolbar select {
  width: auto;
  margin-top: 0;
  padding: 0.45rem 0.6rem;
  font-size: 0.875rem;
  flex: 1 1 120px;
}

.reader-pages img {
  width: 100%;
  display: block;
  margin-bottom: 4px;
  border-radius: 4px;
}

.reader-light {
  background: #f8fafc;
  color: #0f172a;
  padding: 0.5rem;
  border-radius: 10px;
}

.reader-sepia {
  background: #f4ecd8;
  color: #433422;
  padding: 0.5rem;
  border-radius: 10px;
}

.reader-end-card {
  margin-top: 1rem;
  background: linear-gradient(180deg, rgba(28, 35, 49, 0.8), rgba(20, 25, 35, 0.96));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 10px 28px rgba(0, 0, 0, 0.35);
}

.reader-end-card h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1rem;
}

.pager-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  margin-top: 0.85rem;
}

@media (min-width: 480px) {
  .pager-row {
    grid-template-columns: 1fr 1fr;
  }
}

.pager-row button {
  width: 100%;
  min-height: 44px;
  white-space: nowrap;
}

/* Floating Pill Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 410px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 999px;
  display: flex;
  justify-content: space-around;
  padding: 0.35rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  z-index: 30;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.5rem 1.05rem;
  border-radius: 999px;
}

.nav-btn.active {
  background: var(--accent);
  color: #fff;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  color: var(--text);
  font-size: 0.9rem;
}

.checkbox-row input[type="checkbox"] {
  margin: 0;
}

.pill-badge {
  font-size: 0.74rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent-2);
  white-space: nowrap;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.alert {
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  margin-bottom: 0.85rem;
  border: 1px solid var(--border);
}

.alert.error {
  background: rgba(239, 68, 68, 0.14);
  border-color: var(--danger);
}

.hidden {
  display: none !important;
}
