/* ═══════════════════════════════════════════════════════════
   PDF Book Library Mini App — Style
   Adapts to Telegram's native theme automatically
═══════════════════════════════════════════════════════════ */

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

:root {
  --bg:        var(--tg-theme-bg-color,           #0e0e1a);
  --bg2:       var(--tg-theme-secondary-bg-color, #16162a);
  --text:      var(--tg-theme-text-color,         #e8e8f4);
  --hint:      var(--tg-theme-hint-color,         #6b6b94);
  --btn:       var(--tg-theme-button-color,       #7b6ef6);
  --btn-text:  var(--tg-theme-button-text-color,  #ffffff);

  --accent:   #7b6ef6;
  --accent2:  #e96cf7;
  --glass:    rgba(255,255,255,0.04);
  --border:   rgba(255,255,255,0.07);
  --r:        16px;
  --r-sm:     10px;
  --ease:     cubic-bezier(0.4,0,0.2,1);
  --dur:      0.22s;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

/* ══════════════════════════════════════════════════════════
   HEADER
══════════════════════════════════════════════════════════ */
.header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 6px;
}

.hrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; }

.brand-icon {
  width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}

.brand h1 { font-size: 17px; font-weight: 700; letter-spacing: -.3px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: var(--hint); }

/* Icon Button */
.ibtn {
  width: 36px; height: 36px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--glass);
  color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.ibtn:active { background: rgba(123,110,246,.2); border-color: var(--accent); }
.ibtn.on { background: linear-gradient(135deg,var(--accent),var(--accent2)); border-color: transparent; color: #fff; }

/* Search */
.sbox {
  position: relative; display: flex; align-items: center;
  margin-bottom: 6px;
}
.s-ico {
  position: absolute; left: 11px; color: var(--hint); pointer-events: none; flex-shrink: 0;
}
.s-input {
  width: 100%; height: 42px;
  background: var(--glass); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text);
  font-size: 14.5px; font-family: inherit;
  padding: 0 40px 0 38px; outline: none;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.s-input::placeholder { color: var(--hint); }
.s-input:focus {
  border-color: var(--accent);
  background: rgba(123,110,246,.07);
  box-shadow: 0 0 0 3px rgba(123,110,246,.18);
}
.s-clear {
  position: absolute; right: 9px;
  width: 26px; height: 26px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.1);
  color: var(--hint); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease);
}
.s-clear:active { background: rgba(255,255,255,.2); }

/* Sort Chips */
.chips {
  display: none; gap: 7px; padding: 2px 0 6px;
  overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips.open { display: flex; }

.chip {
  flex-shrink: 0; height: 30px; padding: 0 13px;
  border-radius: 100px; border: 1px solid var(--border);
  background: var(--glass); color: var(--hint);
  font-size: 12.5px; font-family: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: all var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.chip.on {
  background: linear-gradient(135deg,var(--accent),var(--accent2));
  border-color: transparent; color: #fff;
}
.chip:active { transform: scale(0.94); }

/* ══════════════════════════════════════════════════════════
   MAIN / STATES
══════════════════════════════════════════════════════════ */
.main {
  padding: 14px 14px 48px;
  min-height: calc(100dvh - 120px);
}

.state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; min-height: 340px; text-align: center; padding: 32px 20px;
}
.state-ico { font-size: 54px; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
.state h3  { font-size: 18px; font-weight: 700; }
.state p   { font-size: 13.5px; color: var(--hint); }

@keyframes bob {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-10px); }
}

/* Spinner */
.ring {
  width: 46px; height: 46px;
  border: 3px solid rgba(123,110,246,.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pill Button ─────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 22px; border-radius: 100px; border: none;
  background: linear-gradient(135deg,var(--accent),var(--accent2));
  color: #fff; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.pill:active { opacity: .85; transform: scale(.95); }

/* ══════════════════════════════════════════════════════════
   BOOK GRID
══════════════════════════════════════════════════════════ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 11px;
}

/* ── Book Card ──────────────────────────────────────── */
.card {
  background: var(--glass); border: 1px solid var(--border);
  border-radius: var(--r); padding: 13px 11px 11px;
  cursor: pointer; position: relative; overflow: hidden;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
  animation: riseUp .35s var(--ease) both;
  -webkit-tap-highlight-color: transparent;
}
.card::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg,rgba(123,110,246,.1),rgba(233,108,247,.05));
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.card:active { transform: scale(.95); border-color: var(--accent); }
.card:active::after { opacity: 1; }

@keyframes riseUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Cover */
.cover {
  width: 100%; aspect-ratio: 3/4;
  border-radius: var(--r-sm); margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; overflow: hidden; position: relative;
  background: linear-gradient(140deg, var(--bg2), rgba(123,110,246,.12));
}
.cover-stripe {
  position: absolute; top: 0; left: 0; width: 6px; height: 100%;
  border-radius: 4px 0 0 4px;
}

/* Title */
.c-title {
  font-size: 12.5px; font-weight: 600; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; margin-bottom: 7px;
}

/* Footer */
.c-foot {
  display: flex; align-items: center; justify-content: space-between;
}
.c-size {
  font-size: 10.5px; color: var(--hint);
}
.c-badge {
  font-size: 10px; font-weight: 600; padding: 2px 7px;
  border-radius: 100px; letter-spacing: .3px;
  background: rgba(123,110,246,.15);
  border: 1px solid rgba(123,110,246,.25);
  color: var(--accent);
}

/* ── Skeleton Cards ─────────────────────────────────── */
.sk-card {
  background: var(--glass); border: 1px solid var(--border);
  border-radius: var(--r); padding: 13px 11px 11px;
}
.sk { background: linear-gradient(90deg,rgba(255,255,255,.04) 25%,rgba(255,255,255,.08) 50%,rgba(255,255,255,.04) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
.sk-cover  { width: 100%; aspect-ratio: 3/4; border-radius: var(--r-sm); margin-bottom: 10px; }
.sk-l1     { height: 12px; width: 85%; margin-bottom: 5px; }
.sk-l2     { height: 12px; width: 55%; margin-bottom: 9px; }
.sk-badge  { height: 16px; width: 44px; border-radius: 100px; }

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Load More ──────────────────────────────────────── */
#load-area { padding: 18px 0 4px; text-align: center; display: none; }
.load-btn {
  width: 100%; max-width: 260px; height: 46px;
  border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--glass); color: var(--text);
  font-size: 14.5px; font-weight: 600; font-family: inherit;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.load-btn:active { border-color: var(--accent); color: var(--accent); transform: scale(.97); }

/* ══════════════════════════════════════════════════════════
   BOTTOM SHEET / MODAL
══════════════════════════════════════════════════════════ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity .3s var(--ease);
}
.overlay.on { opacity: 1; pointer-events: all; }

.sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 101;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  border-top-left-radius: 24px; border-top-right-radius: 24px;
  padding: 0 18px calc(env(safe-area-inset-bottom, 0px) + 28px);
  transform: translateY(105%);
  transition: transform .38s cubic-bezier(0.32,0.72,0,1);
  max-height: 82dvh; overflow-y: auto;
}
.sheet.on { transform: translateY(0); }

.sh-handle {
  width: 38px; height: 4px;
  background: rgba(255,255,255,.12);
  border-radius: 100px; margin: 14px auto 18px;
}

.sh-body { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }

.sh-cover {
  width: 88px; height: 118px; border-radius: 14px;
  border: 1px solid rgba(123,110,246,.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 46px;
  box-shadow: 0 16px 48px rgba(123,110,246,.25);
}

.sh-title {
  font-size: 16.5px; font-weight: 700; line-height: 1.45;
  max-width: 280px; padding: 0 4px;
}

.sh-tags { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 11px; border-radius: 100px;
  border: 1px solid var(--border); background: var(--glass);
  color: var(--hint); font-size: 12px; font-weight: 500;
}

/* Send button */
.send-btn {
  width: 100%; max-width: 300px; height: 50px;
  border-radius: var(--r-sm); border: none;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  color: #fff; font-size: 15.5px; font-weight: 700;
  font-family: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  box-shadow: 0 10px 28px rgba(123,110,246,.38);
  -webkit-tap-highlight-color: transparent;
}
.send-btn:active  { opacity: .87; transform: scale(.97); box-shadow: none; }
.send-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.cancel-link {
  background: none; border: none; color: var(--hint);
  font-size: 14px; font-family: inherit; cursor: pointer; padding: 6px 12px;
}
.cancel-link:active { opacity: .7; }

/* ══════════════════════════════════════════════════════════
   TOAST
══════════════════════════════════════════════════════════ */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(70px);
  background: rgba(22,22,42,.96);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px; font-weight: 500;
  padding: 11px 18px; border-radius: var(--r-sm);
  z-index: 200; white-space: nowrap; pointer-events: none;
  transition: transform .3s var(--ease), opacity .3s;
  opacity: 0; backdrop-filter: blur(14px);
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.ok   { border-color: rgba(72,199,142,.4); color: #48c78e; }
.toast.err  { border-color: rgba(247,108,108,.4); color: #f76c6c; }
