/* Night-violet theme, 60-30-10:
   60  background  #140F22  deep night violet (and its glass/tint surfaces)
   30  text        #ECE8F6  lavender white (secondary text: the same at lower opacity)
   10  accent      #8E6FE6  Pantone 18-3838 Ultra Violet, lightened for a dark screen: buttons, chips, progress */
:root {
  --bg: #140F22;
  --bg-2: #1C162D;
  --bg-3: #261F3A;
  --glass: rgba(30, 23, 48, .62);
  --glass-line: rgba(196, 178, 255, .14);
  --line: rgba(236, 232, 246, .08);
  --fg: #ECE8F6;
  --fg-2: rgba(236, 232, 246, .7);
  --fg-3: rgba(236, 232, 246, .46);
  --accent: #8E6FE6;
  --accent-hi: #B9A2FF;
  --accent-soft: rgba(142, 111, 230, .2);
  --accent-ink: #fff;
  --radius: 16px;
  --gutter: 16px;
  --tab-h: 54px;
  --safe-top: max(env(safe-area-inset-top), calc(var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px)));
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --font: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --serif: "Lora", Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 500 14px/1.45 var(--font); }
body { min-height: 100vh; overscroll-behavior-y: contain; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
img { display: block; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

.page { position: relative; max-width: 760px; margin: 0 auto; padding: calc(var(--safe-top) + 12px) var(--gutter) calc(var(--safe-bottom) + 28px); }
.page.tabbed { padding-bottom: calc(var(--safe-bottom) + var(--tab-h) + 28px); }

/* ---------- glass + icon buttons */
.glass { background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); }
.icon-btn { width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center; color: var(--fg); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:active, .card:active, .row:active { transform: scale(.97); }
.icon-btn.on { color: var(--accent-hi); border-color: rgba(185, 162, 255, .45); }
.go { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; background: rgba(20, 15, 34, .55); border: 1px solid var(--glass-line); color: var(--fg); }

/* ---------- home */
.hero-art { position: absolute; left: 0; right: 0; top: 0; height: calc(var(--safe-top) + 412px); background: center bottom / cover no-repeat;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 62%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 62%, transparent 100%); pointer-events: none; }
.hero-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(20,15,34,.6), rgba(20,15,34,0) 18%); }
.top { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; }
.top .ava { width: 40px; height: 40px; border-radius: 50%; border: 2px solid rgba(185, 162, 255, .5); flex: none; }
.top .who { flex: 1; min-width: 0; }
.top .who b { display: block; font: 600 16px/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .who span { font-size: 11.5px; color: var(--fg-2); }
.hero-gap { height: 165px; }
.continue-card { position: relative; z-index: 2; display: flex; gap: 12px; align-items: center; padding: 9px; border-radius: var(--radius); margin-bottom: 18px; }
.continue-card img { width: 62px; height: 80px; border-radius: 12px; object-fit: cover; flex: none; background: var(--bg-3); }
.continue-card .k { font-size: 11.5px; color: var(--fg-2); }
.continue-card .t { margin-top: 1px; font: 600 15px/1.25 var(--serif); -webkit-line-clamp: 1 !important; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-hi); font-size: 12px; font-weight: 700; }
.prog { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11.5px; color: var(--fg-2); }
.bar { flex: 1; height: 4px; border-radius: 2px; background: rgba(236, 232, 246, .12); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--accent), var(--accent-hi)); }

.sec { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; }
.sec h2 { margin: 0; display: flex; align-items: center; gap: 8px; font: 600 18px/1.2 var(--serif); }
.sec h2 svg { width: 18px; height: 18px; }
.sec h2 svg { color: var(--accent-hi); }
.sec a { color: var(--fg-2); font-size: 13px; display: flex; align-items: center; gap: 2px; }
.rail { position: relative; z-index: 2; display: flex; gap: 10px; overflow-x: auto; margin: 0 calc(-1 * var(--gutter)) 18px; padding: 0 var(--gutter) 4px; scrollbar-width: none; scroll-snap-type: x mandatory; }
.rail::-webkit-scrollbar { display: none; }
.rail > * { scroll-snap-align: start; }

/* poster cards: cover full-bleed, text over a dark gradient */
.card { position: relative; display: block; border-radius: var(--radius); overflow: hidden; background: var(--bg-2); border: 1px solid var(--glass-line); aspect-ratio: 1 / 1.24; transition: transform .15s ease; }
.card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, transparent 30%, rgba(14, 10, 25, .7) 58%, rgba(14, 10, 25, .97) 88%); }
.card .meta { position: absolute; z-index: 1; left: 10px; right: 10px; bottom: 9px; }
.card .t { font-size: 14px; font-weight: 700; hyphens: auto; overflow-wrap: break-word; text-shadow: 0 1px 8px rgba(0,0,0,.6); line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .c { margin-top: 2px; color: var(--accent-hi); font-size: 12.5px; font-weight: 600; }
.card .d { margin-top: 3px; display: flex; align-items: center; gap: 5px; padding-right: 38px; color: var(--fg-2); font-size: 11px; white-space: nowrap; overflow: hidden; }
.card .go { position: absolute; z-index: 1; right: 8px; bottom: 7px; width: 26px; height: 26px; }
.badge { position: absolute; z-index: 1; top: 8px; padding: 2px 9px; border-radius: 999px; font-size: 10.5px; font-weight: 700; background: var(--accent); color: var(--accent-ink); }
.badge.l { left: 8px; }
.badge.r { right: 8px; background: rgba(20, 15, 34, .72); border: 1px solid var(--glass-line); color: var(--fg); backdrop-filter: blur(8px); }
.rail .card { flex: 0 0 min(230px, 46%); aspect-ratio: 1 / 1.1; }
.rail .mini { flex: 0 0 min(110px, 24%); aspect-ratio: 1 / 1.05; border-radius: 14px; }
.rail .mini::after { display: none; }

/* ---------- catalog */
.bar-top { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.bar-top .ttl { flex: 1; text-align: center; min-width: 0; }
.bar-top .ttl b { display: block; font: 600 20px/1.2 var(--serif); }
.bar-top .ttl span { font-size: 13px; color: var(--fg-2); }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 calc(-1 * var(--gutter)) 16px; padding: 0 var(--gutter); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; height: 34px; padding: 0 15px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--glass-line); color: var(--fg-2); font-weight: 600; font-size: 13px; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.search { width: 100%; height: 46px; padding: 0 16px; margin-bottom: 14px; border-radius: 14px; border: 1px solid var(--glass-line); background: var(--bg-2); color: var(--fg); font: inherit; outline: none; }
.search::placeholder { color: var(--fg-3); }
.search:focus { border-color: rgba(185, 162, 255, .5); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.grid .card { aspect-ratio: 1 / 1.3; }
.empty { padding: 56px 12px; text-align: center; color: var(--fg-3); }
.empty b { display: block; margin-bottom: 6px; color: var(--fg-2); font: 600 18px/1.3 var(--serif); }

/* ---------- title */
.t-hero { position: relative; margin: calc(-1 * (var(--safe-top) + 12px)) calc(-1 * var(--gutter)) 0; padding: calc(var(--safe-top) + 12px) var(--gutter) 20px; overflow: hidden; }
.t-hero .bg { position: absolute; inset: -40px; background: center / cover; filter: blur(30px) saturate(1.1); opacity: .5; transform: scale(1.1); }
.t-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(20, 15, 34, .2), var(--bg) 94%); }
.t-hero > * { position: relative; z-index: 1; }
.t-head { display: flex; justify-content: space-between; margin-bottom: 18px; }
.t-head .r { display: flex; gap: 10px; }
.t-main { display: flex; gap: 16px; align-items: flex-end; }
.t-main img { width: 104px; aspect-ratio: 1 / 1.42; object-fit: cover; border-radius: 14px; border: 1px solid var(--glass-line); box-shadow: 0 14px 34px rgba(0, 0, 0, .45); background: var(--bg-2); }
.t-main h1 { margin: 0 0 4px; font: 600 20px/1.2 var(--serif); }
.t-main .en { font-size: 13px; color: var(--fg-3); }
.t-main .chip { margin-top: 10px; }
.desc { margin: 16px 0 0; color: var(--fg-2); font-size: 14.5px; }
.actions { display: flex; gap: 10px; margin: 18px 0 8px; }
.btn { flex: 1; height: 46px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 15px; }
.btn-main { background: linear-gradient(135deg, var(--accent), #7656D8); color: #fff; box-shadow: 0 8px 22px rgba(142, 111, 230, .35); }
.btn-ghost { background: var(--bg-2); border: 1px solid var(--glass-line); color: var(--fg); }
.btn:active { opacity: .86; }
.notify { display: flex; align-items: center; gap: 12px; width: 100%; margin: 10px 0 24px; padding: 12px 14px; border-radius: 15px; text-align: left; }
.notify .tx { flex: 1; }
.notify .tx b { display: block; font-size: 14.5px; }
.notify .tx span { font-size: 12.5px; color: var(--fg-3); }
.switch { width: 46px; height: 28px; flex: none; border-radius: 14px; background: var(--bg-3); position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.list-head h2 { margin: 0; font: 600 19px/1.2 var(--serif); }
.sort { color: var(--fg-3); font-size: 13px; font-weight: 600; padding: 8px 0; }
.chapters { list-style: none; margin: 0; padding: 0; }
.ch { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 48px; padding: 0 2px; border-bottom: 1px solid var(--line); }
.ch .n { font-weight: 700; }
.ch .d { color: var(--fg-3); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.ch.read .n { color: var(--fg-3); font-weight: 600; }
.ch .new { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-hi); box-shadow: 0 0 10px var(--accent); }
.ch .cur { color: var(--accent-hi); font-size: 12px; font-weight: 700; }

/* ---------- my chapters / settings */
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px; margin-bottom: 8px; border-radius: var(--radius); text-align: left; transition: transform .15s; }
.row img { width: 54px; height: 70px; border-radius: 10px; object-fit: cover; flex: none; background: var(--bg-3); }
.row .tx { flex: 1; min-width: 0; }
.row .tx b { display: block; font-size: 15px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .tx span { font-size: 13px; color: var(--fg-2); }
.set { display: flex; align-items: center; gap: 14px; width: 100%; padding: 15px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.set:last-child { border-bottom: 0; }
.set .ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-hi); flex: none; }
.set .tx { flex: 1; }
.set .tx b { display: block; font-size: 15px; }
.set .tx span { font-size: 12.5px; color: var(--fg-3); }
.panel { border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.page-title { margin: 4px 0 14px; font: 600 22px/1.2 var(--serif); }

/* ---------- tab bar */
.tabbar { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; padding: 2px 8px calc(var(--safe-bottom) + 2px);
  background: rgba(18, 13, 31, .86); border-top: 1px solid var(--glass-line); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.tabbar a { flex: 1; max-width: 120px; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--fg-3); position: relative; }
.tabbar a.on { color: var(--accent-hi); }
.tabbar svg { width: 22px; height: 22px; }
.tabbar a.on::after { content: ""; position: absolute; bottom: 2px; width: 46px; height: 3px; border-radius: 2px; background: var(--accent-hi); }

/* ---------- reader */
.reader { background: #0E0A18; min-height: 100vh; }
.pages { max-width: 800px; margin: 0 auto; }
.pages img { width: 100%; height: auto; background: var(--bg-2); }
.topbar { position: fixed; z-index: 10; left: 0; right: 0; top: 0; padding: calc(var(--safe-top) + 8px) 12px 10px; display: flex; align-items: center; gap: 10px;
  background: rgba(20, 15, 34, .9); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--glass-line); transition: transform .25s ease; }
.topbar.hide { transform: translateY(-110%); }
.topbar .icon-btn { width: 40px; height: 40px; background: var(--bg-3); }
.topbar .meta { min-width: 0; flex: 1; }
.topbar .meta b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .meta span { font-size: 12.5px; color: var(--accent-hi); font-weight: 600; }
.progress { position: fixed; z-index: 11; left: 0; right: 0; bottom: 0; height: 3px; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-hi)); transition: width .15s linear; }
.end { max-width: 520px; margin: 0 auto; padding: 36px var(--gutter) calc(var(--safe-bottom) + 48px); text-align: center; }
.end p { margin: 0 0 18px; color: var(--fg-2); }
.end .btn { width: 100%; margin-bottom: 10px; flex: none; }
.loading { display: grid; place-items: center; min-height: 60vh; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--bg-3); border-top-color: var(--accent-hi); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 30; left: 50%; bottom: calc(var(--safe-bottom) + var(--tab-h) + 20px); transform: translateX(-50%); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; text-align: center; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 2s !important; } }
