/* ============================================================
   Inkshelf — base: tokens, shell, shared components.
   Mobile-first. Screen-specific styles live in their own files:
   discover.css · detail.css · reader.css · tabs.css
   ============================================================ */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #ebe6de;          /* grey chip / filter box */
  --text: #1b1917;
  --text-2: #4a4540;
  --muted: #6f6860;
  --border: #e3ddd3;
  --accent: #d6360f;             /* primary purple */
  --accent-light: #c42d0e;       /* active tab / links */
  --accent-soft: #fbe9e2;        /* selected chip fill */
  --accent-contrast: #ffffff;
  --pink: #e0568a;               /* stat numbers */
  --orange: #f2763a;             /* status badge */
  --star: #f6c544;

  /* frosted liquid glass */
  --glass-bg: rgba(255, 255, 255, .72);
  --glass-strong: rgba(255, 255, 255, .9);
  --glass-border: rgba(255, 255, 255, .6);
  --glass-edge: rgba(0, 0, 0, .06);
  --glass-shadow: 0 8px 32px rgba(50, 30, 18, .10);
  --blur: blur(22px) saturate(180%);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 18px;
  --header-h: 56px;
  --tabbar-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --gutter: 16px;
  --font: "Onest", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif; /* css/fonts.css */
  color-scheme: light;
}
/* dark + amoled (amoled overrides live in themes.css); scheme is set on <html> by js/theme-boot.js */
:root:where([data-scheme="dark"], [data-scheme="amoled"]) {
  --bg: #0f0e0d;
  --surface: #181614;
  --surface-2: #25221f;
  --text: #f2eee8;
  --text-2: #c9c3ba;
  --muted: #968f86;
  --border: #2b2724;
  --accent: #e0401a;
  --accent-light: #ff7a5c;
  --accent-soft: rgba(240, 80, 42, .16);
  --glass-bg: rgba(24, 24, 28, .72);
  --glass-strong: rgba(28, 28, 33, .92);
  --glass-border: rgba(255, 255, 255, .08);
  --glass-edge: rgba(255, 255, 255, .06);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- glass surfaces ---------- */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.glass-strong {
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

/* ---------- page shell ---------- */
.view { min-height: 100vh; }
.page { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px); }
.page.no-tabbar { padding-bottom: 24px; }
.wrap { width: 100%; max-width: 1024px; margin: 0 auto; padding: 0 var(--gutter); }

.app-header {
  position: sticky; top: 0; z-index: 30;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 8px 0;
  border-bottom: 1px solid var(--glass-edge);
}
.app-header-title { font-size: 19px; font-weight: 600; text-align: center; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header-side { display: flex; align-items: center; gap: 2px; }
.app-header-side.right { justify-content: flex-end; }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; justify-content: center;
  border-top: 1px solid var(--glass-edge);
  box-shadow: 0 -4px 24px rgba(50, 30, 18, .05);
}
.tabbar-inner { display: flex; width: 100%; max-width: 640px; }
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11.5px; font-weight: 500; letter-spacing: 0;
}
.tab-item .icon { width: 27px; height: 27px; }
.tab-item.is-active { color: var(--accent-light); }
.tab-item.is-active .icon svg { fill: var(--accent-soft); }

/* ---------- icons & buttons ---------- */
.icon { display: inline-flex; width: 24px; height: 24px; flex-shrink: 0; }
.icon svg { width: 100%; height: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%; color: inherit;
}
.icon-btn:active { background: rgba(127, 127, 127, .14); }
.icon-btn .icon { width: 26px; height: 26px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 20px; border-radius: var(--radius);
  font-size: 16px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--text);
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); box-shadow: 0 6px 18px rgba(214, 54, 15, .28); }
.btn-primary:active { filter: brightness(.94); }
.btn-outline { background: transparent; color: var(--accent-light); border: 1.5px solid var(--accent-light); }
.btn-block { width: 100%; }
.btn-sm { height: 34px; padding: 0 14px; font-size: 14px; }
.pill-outline {
  display: inline-flex; align-items: center; height: 30px; padding: 0 14px;
  border: 1.5px solid var(--accent-light); color: var(--accent-light);
  border-radius: 999px; font-size: 15px;
}
.btn-danger { color: #e03131; }

.input {
  height: 44px; width: 100%; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
textarea.input { height: auto; min-height: 110px; padding: 10px 14px; resize: vertical; line-height: 1.5; }
.input:focus { outline: none; border-color: var(--accent-light); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label { font-size: 13px; color: var(--muted); }

/* ---------- section head (purple bar + title + More...) ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 14px; }
.section-title { position: relative; padding-left: 18px; font-size: 19px; font-weight: 500; }
.section-title::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 5px; height: 18px; border-radius: 3px;
  background: linear-gradient(180deg, var(--accent-light), var(--accent));
}
.section-more { color: var(--accent-light); font-size: 15px; }

/* ---------- manga card ---------- */
.card { display: flex; flex-direction: column; min-width: 0; }
.cover {
  position: relative; aspect-ratio: 5 / 7; overflow: hidden;
  border-radius: var(--radius-sm); background: var(--surface-2);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 4px 14px rgba(50, 30, 18, .08);
}
.cover-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-img:not([src]) { visibility: hidden; }
.card:active .cover { transform: scale(.98); }
.card-title {
  margin-top: 8px; font-size: 14.5px; line-height: 1.3; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: calc(14.5px * 1.3 * 2);
}
.card-sub { margin-top: 3px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  position: absolute; left: 0; top: 0; z-index: 1;
  padding: 2px 8px; font-size: 12px; color: #fff; background: var(--orange);
}

/* 3-column grid on phones, more columns as the screen grows */
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 14px; }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 18px; } }

/* horizontal scrolling row (bleeds to the screen edge) */
.hscroll {
  display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - 28px) / 3.3);
  gap: 14px; overflow-x: auto; scroll-snap-type: x mandatory;
  margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter);
  scrollbar-width: none;
}
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { scroll-snap-align: start; }
@media (min-width: 640px) { .hscroll { grid-auto-columns: 150px; gap: 18px; } }

/* ---------- chips (Genre / Status / Sort sheets) ---------- */
.chip-grid { display: grid; gap: 10px; }
.chip-grid.cols-2 { grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.chip-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.chip-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.chip-grid.cols-1 { grid-template-columns: 1fr; }
.chip {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 40px; padding: 4px 6px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted); font-size: 13.5px; line-height: 1.2;
  border: 1.5px solid transparent;
}
.chip.pill { border-radius: 999px; min-height: 42px; font-size: 16px; }
.chip.is-active { background: var(--accent-soft); color: var(--accent-light); border-color: var(--accent-light); }
.tag { display: inline-flex; align-items: center; height: 36px; padding: 0 18px; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-size: 14px; }

/* ---------- underline tabs (Description / Chapters) ---------- */
.u-tabs { display: flex; border-bottom: 1px solid var(--border); }
.u-tab { flex: 1; height: 50px; position: relative; font-size: 17px; color: var(--muted); }
.u-tab.is-active { color: var(--text); font-weight: 500; }
.u-tab.is-active::after {
  content: ""; position: absolute; left: 50%; bottom: -1px; transform: translateX(-50%);
  width: 38%; max-width: 90px; height: 4px; border-radius: 2px; background: var(--accent);
}

/* ---------- bottom sheet ---------- */
#sheet-root { position: relative; z-index: 80; }
.sheet-wrap { position: fixed; inset: 0; z-index: 80; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .38); opacity: 0; transition: opacity .25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 640px;
  max-height: 86vh; display: flex; flex-direction: column;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .18);
  padding-bottom: calc(var(--safe-b) + 12px);
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: translateY(0); }
.sheet-grabber { width: 38px; height: 5px; border-radius: 3px; background: rgba(127, 127, 127, .35); margin: 8px auto 2px; }
.sheet-title { text-align: center; font-size: 17px; padding: 10px 16px 14px; }
.sheet-body { overflow-y: auto; padding: 0 var(--gutter) 8px; }
.sheet-section-title { text-align: center; font-size: 17px; margin: 22px 0 14px; }
.sheet-footer { display: flex; gap: 14px; padding: 14px var(--gutter) 0; }
.sheet-footer .btn { flex: 1; height: 52px; font-size: 18px; }
.sheet-footer .btn-outline { flex: 0 0 34%; }
.sheet-list { display: flex; flex-direction: column; }
.sheet-list-item { display: flex; align-items: center; gap: 14px; height: 52px; padding: 0 4px; font-size: 16px; border-bottom: 1px solid var(--border); text-align: left; width: 100%; }
.sheet-list-item:last-child { border-bottom: 0; }

/* ---------- empty state ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 18vh 32px 40px; }
.empty-illus {
  display: grid; place-items: center; width: 132px; height: 132px; border-radius: 50%;
  background: radial-gradient(circle at 50% 70%, rgba(127, 127, 127, .14), transparent 70%);
  color: var(--muted); margin-bottom: 18px;
}
.empty-illus .icon { width: 84px; height: 84px; stroke-width: 1.2; }
.empty-title { font-size: 19px; color: var(--text); margin-bottom: 10px; }
.empty-text { font-size: 15px; color: var(--muted); max-width: 320px; margin-bottom: 20px; }

/* ---------- list rows (Recent / Downloads / Account) ---------- */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.list-row .thumb { width: 64px; flex-shrink: 0; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }

/* ---------- gestures ---------- */
.card { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.card .cover { transition: transform .18s ease; }
.card.is-pressing .cover { transform: scale(.95); }

.swipe-row { display: block; position: relative; overflow: hidden; padding: 0; }
.swipe-content {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 14px;
  padding: 14px 0; background: var(--bg); touch-action: pan-y;
}
.swipe-action {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600; color: #fff; background: var(--accent); opacity: 0;
}
.swipe-action.danger { background: #e03131; }

.quick-head { display: flex; gap: 14px; align-items: center; padding: 4px 0 14px; border-bottom: 1px solid var(--border); }
.quick-cover { width: 64px; flex-shrink: 0; }
.quick-meta { min-width: 0; }
.quick-title { font-size: 17px; font-weight: 600; }
.quick-sheet .sheet-list-item .icon { color: var(--accent-light); }
.quick-sheet .sheet-list-item.is-fav .icon { color: var(--star); }

@keyframes slide-in-right { from { transform: translateX(28px); opacity: .3; } to { transform: none; opacity: 1; } }
@keyframes slide-in-left { from { transform: translateX(-28px); opacity: .3; } to { transform: none; opacity: 1; } }
.slide-in-right { animation: slide-in-right .22s ease-out; }
.slide-in-left { animation: slide-in-left .22s ease-out; }
@media (prefers-reduced-motion: reduce) { .slide-in-right, .slide-in-left { animation: none; } }

/* ---------- overlays ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 20px); transform: translateX(-50%); z-index: 100;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 18px; border-radius: 999px;
  background: rgba(30, 30, 36, .88); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  color: #fff; font-size: 14px; text-align: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.busy { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(0, 0, 0, .3); }
.busy-box { display: flex; align-items: center; gap: 12px; padding: 16px 22px; border-radius: var(--radius); background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
