/* ═══════════════════════════════════════════════════════
   ManhwaVoid — Upgrade layer v5 (loads after style.css)
   Polish · responsiveness · motion · tab bar · a11y
═══════════════════════════════════════════════════════ */
:root {
  --font-display: 'Syne', system-ui, sans-serif;
  --font-body: 'Noto Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  --max-w: 1200px;
  --tabbar-h: 62px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}
body { font-family: var(--font-body); text-rendering: optimizeLegibility; }
body:has(#manga-hero) { --max-w: 980px; }
html { scroll-padding-top: calc(var(--nav-h) + 12px); }
* { -webkit-tap-highlight-color: transparent; }
::selection { background: var(--primary); color: #000; }

/* ── Accessibility ── */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.search-input:focus-visible { outline: none; }
.muted { color: var(--text-muted); font-weight: 400; }
.pad { padding: 20px 0; font-size: 13px; }
a.manga-card, a.lu-card, a.hero-slide, a.chapter-item, a.lib-list-item, a.cr-card { color: inherit; text-decoration: none; }
a.manga-card, a.lu-card { display: block; }

/* ── Page transitions (cross-document View Transitions, progressive enhancement) ── */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: vtOut .16s ease both; }
::view-transition-new(root) { animation: vtIn .3s var(--ease-out) both; }
@keyframes vtOut { to { opacity: 0; } }
@keyframes vtIn { from { opacity: 0; transform: translateY(6px); } }

/* ── Nav ── */
.nav { padding-top: env(safe-area-inset-top); height: calc(var(--nav-h) + env(safe-area-inset-top)); }
.page, .home { padding-top: calc(var(--nav-h) + env(safe-area-inset-top)); }
.scroll-bar { top: calc(52px + env(safe-area-inset-top)); }
.nav-title { text-align: center; flex: 1; font-size: 15px; letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-btn { transition: transform .18s var(--ease-out), background .18s, border-color .18s, color .18s; }
.nav-btn:active { transform: scale(.9); }
.nav-links { display: none; align-items: center; gap: 4px; margin-right: auto; }
.nav-link {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 10px;
  font-size: 13px; font-weight: 600; color: var(--text-sub); transition: background .18s, color .18s;
}
.nav-link:hover { background: var(--surface3); color: var(--text); }
.nav-link.is-active { color: var(--primary); background: var(--primary-dim); }
.nav-install svg { width: 15px; height: 15px; }
.nav-install { color: var(--primary); }
@media (min-width: 900px) {
  .nav-links { display: flex; }
  .nav { padding-inline: max(16px, calc((100vw - 1200px) / 2 + 16px)); }
  .nav .nav-logo, .nav .nav-logo-wrap { flex: 0 0 auto; }
  .nav .nav-title { flex: 1; text-align: left; margin-left: 8px; }
}

/* ── Mobile tab bar ── */
.tabbar { display: none; }
@media (max-width: 899px) {
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 6px 10px env(safe-area-inset-bottom);
    background: rgba(8, 8, 8, .86); border-top: 1px solid var(--border);
    -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%);
  }
  body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 10.5px; font-weight: 600; letter-spacing: .02em; color: var(--text-muted); border-radius: 14px; position: relative;
    transition: color .2s, transform .18s var(--ease-out);
  }
  .tab svg { width: 21px; height: 21px; transition: transform .3s var(--ease-spring); }
  .tab:active { transform: scale(.9); }
  .tab.is-active { color: var(--primary); }
  .tab.is-active svg { transform: translateY(-1px) scale(1.1); }
  .tab.is-active::before {
    content: ''; position: absolute; top: -7px; width: 22px; height: 3px; border-radius: 0 0 4px 4px;
    background: var(--primary); box-shadow: 0 2px 12px var(--primary-glow);
  }
  .pfx-toast { bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); }
}

/* ── Cards ── */
.manga-card { transition: opacity .4s var(--ease), transform .4s var(--ease-out); }
.manga-card.card--visible:hover { transform: translateY(-4px); }
.manga-card.card--visible:active { transform: scale(.96); }
.card-cover { transition: box-shadow .3s var(--ease), border-color .3s; }
.manga-card:hover .card-cover { box-shadow: 0 14px 34px rgba(0, 0, 0, .55), 0 0 0 1px var(--primary-glow); }
.card-title { transition: color .2s; }
.manga-card:hover .card-title { color: var(--primary); }
.lu-card { display: block; }
.hero-slide { display: block; }
.hdot { width: 6px; padding: 0; border: 0; appearance: none; -webkit-appearance: none; }
.hero-pgbar-fill { will-change: width; }
.cards-grid.lib-grid { padding: 16px 16px 40px; }
.cards-grid.results-grid { padding-bottom: 40px; }
@media (min-width: 640px)  { .cards-grid { grid-template-columns: repeat(auto-fill, minmax(144px, 1fr)); gap: 18px; padding-inline: 20px; } }
@media (min-width: 1024px) { .cards-grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 22px; padding-inline: 24px; } .manga-card { width: auto; } }
.manga-card { width: auto; }

/* ── Scroll reveal ── */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .7s var(--ease-out), transform .7s var(--ease-out); }
.reveal.in { opacity: 1; transform: none; }
@media (scripting: none) { .reveal { opacity: 1; transform: none; } }

/* ── Toast ── */
.pfx-toast { display: flex; align-items: center; gap: 4px; white-space: normal; text-align: center; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 12px 40px rgba(0, 0, 0, .55); }
.pfx-toast--warn { border-color: rgba(245, 158, 11, .4); background: rgba(245, 158, 11, .12); }
.toast-action { margin-left: 10px; padding: 3px 10px; border-radius: 99px; background: var(--primary); color: #000; font-size: 12px; font-weight: 700; }

/* ── Error + empty ── */
.mfx-error-state { color: var(--text-muted); }
.mfx-error-icon svg { width: 100%; height: 100%; }
.mfx-error-msg { font-size: 13px; max-width: 280px; line-height: 1.55; }
.mfx-retry-btn { margin-top: 14px; padding: 9px 20px; border-radius: 99px; background: var(--primary); color: #000; font-size: 12px; font-weight: 700; transition: transform .18s var(--ease-out); }
.mfx-retry-btn:hover { transform: translateY(-1px); } .mfx-retry-btn:active { transform: scale(.95); }
.empty-state { align-items: center; text-align: center; }
.loader-cap { margin-top: 10px; font-size: 12px; color: var(--text-muted); font-family: var(--font-display); letter-spacing: .06em; text-transform: uppercase; }

/* ── Search ── */
.recent { margin-top: 22px; width: 100%; max-width: 440px; text-align: left; padding: 0 16px; }
.recent-head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.recent-head button { color: var(--primary); font-size: 11px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.recent-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 7px 14px; border-radius: 99px; background: var(--surface2); border: 1px solid var(--border); font-size: 12.5px; color: var(--text-sub); transition: all .18s var(--ease); }
.chip:hover { border-color: var(--primary-glow); color: var(--text); background: var(--surface3); transform: translateY(-1px); }
.tab-count { display: inline-block; margin-left: 5px; padding: 0 6px; border-radius: 99px; background: rgba(255, 255, 255, .08); font-size: 10px; line-height: 17px; font-weight: 700; }
.search-tab.active .tab-count { background: rgba(0, 0, 0, .18); }
.results-meta { padding: 10px 16px 4px; font-size: 12px; color: var(--text-sub); }
.results-meta em { font-style: normal; color: var(--text); }

/* ── Manga page ── */
.skel-cover-lg { aspect-ratio: 2/3; width: 116px; border-radius: 12px; }
.manga-info-desc.open { display: block; -webkit-line-clamp: unset; overflow: visible; }
.desc-toggle { margin-top: 6px; font-size: 11.5px; font-weight: 600; color: var(--primary); }
.manga-actions { display: flex; gap: 10px; margin-top: 14px; align-items: center; }
.btn-primary {
  flex: 1; max-width: 280px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px; border-radius: 12px; background: var(--primary); color: #000;
  font-family: var(--font-display); font-size: 13px; font-weight: 800; letter-spacing: .02em;
  box-shadow: 0 6px 24px rgba(255, 212, 0, .28); transition: transform .18s var(--ease-out), box-shadow .18s;
  min-width: 0;
}
.btn-primary span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-primary svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(255, 212, 0, .4); }
.btn-primary:active { transform: scale(.97); }
.btn-ghost, .icon-btn {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; background: var(--surface2); border: 1px solid var(--border2);
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-sub); transition: all .18s var(--ease);
}
.btn-ghost:hover, .icon-btn:hover { background: var(--surface3); color: var(--text); }
.btn-ghost svg, .icon-btn svg { width: 17px; height: 17px; transition: transform .25s var(--ease-out); }
#ch-sort.flip svg { transform: scaleY(-1); }
.ch-tools { display: flex; gap: 8px; padding: 12px 0 8px; }
.ch-tools input, .lib-tools input, .lib-tools select {
  height: 42px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 0 14px; font-size: 13px; outline: none; transition: border-color .18s, box-shadow .18s;
}
.ch-tools input { flex: 1; min-width: 0; }
.ch-tools input:focus, .lib-tools input:focus, .lib-tools select:focus { border-color: var(--primary-glow); box-shadow: 0 0 0 3px var(--primary-dim); }
.chapter-item { display: flex; transition: background .18s, transform .18s var(--ease-out); }
.chapter-item:active { transform: scale(.985); }
.chapter-item.current { background: var(--primary-deep); box-shadow: inset 2px 0 0 var(--primary); }
.chapter-item.current .chapter-name { color: var(--primary); }

/* ── Library ── */
.lib-tools { display: flex; gap: 8px; padding: 12px 16px 0; }
.lib-tools input { flex: 1; min-width: 0; }
.lib-tools select { appearance: none; -webkit-appearance: none; padding-right: 12px; cursor: pointer; }
.lib-list { padding: 8px 8px 100px; }
.lib-list-item { display: flex; }
.lib-actions { gap: 6px; }

/* ── Desktop refinements ── */
@media (min-width: 1024px) {
  .manga-hero { border-radius: 0 0 20px 20px; overflow: hidden; }
  .hero-wrap { box-shadow: 0 24px 70px rgba(0, 0, 0, .5); }
  .search-sticky, .lib-toolbar { padding-inline: 24px; }
  .lib-tools { padding-inline: 24px; }
  .chapter-item:hover { background: var(--surface2); }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

/* ── Downloads ── */
.chip-btn { display: inline-flex; align-items: center; gap: 7px; height: 42px; padding: 0 14px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--border2); color: var(--text-sub); font-size: 12.5px; font-weight: 600; flex-shrink: 0; transition: all .18s var(--ease); }
.chip-btn svg { width: 15px; height: 15px; }
.chip-btn:hover { background: var(--surface3); color: var(--text); }
.chip-btn.active { background: var(--primary-dim); border-color: rgba(255,212,0,.35); color: var(--primary); }
.ch-dl { width: 34px; height: 34px; border-radius: 10px; margin-left: 6px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--text-muted); transition: all .18s; }
.ch-dl svg { width: 16px; height: 16px; }
.ch-dl:hover { background: var(--primary-dim); color: var(--primary); }
.ch-check { display: none; width: 22px; height: 22px; margin-right: 10px; flex-shrink: 0; border-radius: 7px; border: 1.5px solid var(--border3); align-items: center; justify-content: center; color: transparent; transition: all .15s; }
.ch-check svg { width: 13px; height: 13px; }
.selecting .ch-check { display: flex; }
.selecting .ch-dl, .selecting .chapter-read-icon { display: none; }
.chapter-item.sel { background: var(--primary-deep); }
.chapter-item.sel .ch-check { background: var(--primary); border-color: var(--primary); color: #000; }
.sel-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); z-index: 1100; width: min(560px, calc(100% - 20px)); display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 16px; background: rgba(20,20,20,.94); border: 1px solid var(--border2); box-shadow: 0 16px 50px rgba(0,0,0,.6); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); animation: selIn .28s var(--ease-out); }
@keyframes selIn { from { opacity: 0; transform: translate(-50%, 16px); } }
.sel-bar #sel-count { flex: 1; font-size: 12.5px; font-weight: 600; color: var(--text-sub); white-space: nowrap; }
.sel-bar select { height: 38px; border-radius: 10px; background: var(--surface3); border: 1px solid var(--border2); color: var(--text); padding: 0 8px; font-size: 12px; }
.sel-bar .chip-btn { height: 38px; padding: 0 12px; }
.sel-bar .btn-primary { flex: 0 0 auto; height: 38px; padding: 0 16px; font-size: 12px; box-shadow: none; }
.sel-bar .btn-primary:disabled { opacity: .4; pointer-events: none; }
@media (min-width: 900px) { .sel-bar { bottom: 24px; } }
.dl-panel { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom)); transform: translate(-50%, 24px); opacity: 0; pointer-events: none; z-index: 2100; width: min(420px, calc(100% - 20px)); padding: 12px 12px 14px; border-radius: 16px; background: rgba(18,18,18,.96); border: 1px solid var(--border2); box-shadow: 0 18px 60px rgba(0,0,0,.65); transition: opacity .25s, transform .3s var(--ease-out); }
.dl-panel.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.reader-page .dl-panel { bottom: calc(76px + env(safe-area-inset-bottom)); }
.dl-top { display: flex; align-items: center; gap: 12px; }
.dl-ic { width: 38px; height: 38px; border-radius: 11px; background: var(--primary-dim); color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dl-ic svg { width: 18px; height: 18px; }
.dl-txt { flex: 1; min-width: 0; }
.dl-title { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.dl-cancel { width: 32px; height: 32px; border-radius: 50%; background: var(--surface3); color: var(--text-sub); display: flex; align-items: center; justify-content: center; }
.dl-cancel svg { width: 14px; height: 14px; }
.dl-bar { height: 4px; margin-top: 11px; border-radius: 9px; background: var(--surface4); overflow: hidden; }
.dl-fill { height: 100%; width: 0; background: var(--primary); border-radius: 9px; transition: width .2s linear; box-shadow: 0 0 10px var(--primary-glow); }
@media (min-width: 900px) { .dl-panel { bottom: 24px; } }
@media (max-width: 600px) { #btn-fs { display: none; } }
