/* ==========================================================================
   Tibbiy Manba - Modern Apple iOS Design System (Cupertino / iOS 18+ Experience)
   Frosted Glass, Continuous Squircles, Dynamic Type, Fluid Physics & Haptics
   ========================================================================== */

:root {
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --font-main: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --spring-easing: cubic-bezier(0.25, 1, 0.5, 1);
  --spring-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --glass-backdrop: blur(25px) saturate(190%);
  --app-safe-top: 0px;
  --app-safe-bottom: 0px;
  --tg-top-offset: max(
    var(--app-safe-top, 0px),
    calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px))
  );
  --tg-bottom-offset: max(
    var(--app-safe-bottom, 0px),
    calc(var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px))
  );
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, textarea {
  user-select: text;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ================= THEMES ================= */

/* 1. iOS Dark Theme (OLED True Black + Cupertino System Grays) */
body.theme-dark {
  --bg-primary: #000000;
  --bg-secondary: rgba(28, 28, 30, 0.85);
  --bg-card: rgba(44, 44, 46, 0.72);
  --bg-card-solid: #1c1c1e;
  --bg-card-hover: rgba(58, 58, 60, 0.85);
  --bg-input: rgba(118, 118, 128, 0.24);
  --bg-seg-control: rgba(118, 118, 128, 0.24);
  --bg-seg-active: #636366;
  --text-seg-active: #ffffff;
  --border-color: rgba(255, 255, 255, 0.12);
  --border-light: rgba(255, 255, 255, 0.06);
  --border-active: #30b0c7;
  --text-primary: #ffffff;
  --text-secondary: rgba(235, 235, 245, 0.65);
  --text-muted: rgba(235, 235, 245, 0.45);
  --accent-color: #30b0c7;
  --accent-blue: #0a84ff;
  --accent-mint: #30d158;
  --accent-gradient: linear-gradient(135deg, #0a84ff, #30b0c7);
  --balance-gradient: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
  --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --nav-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

/* 2. iOS Light Theme (Cupertino Light System Grays) */
body.theme-light {
  --bg-primary: #f2f2f7;
  --bg-secondary: rgba(255, 255, 255, 0.85);
  --bg-card: rgba(255, 255, 255, 0.82);
  --bg-card-solid: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: rgba(118, 118, 128, 0.12);
  --bg-seg-control: rgba(118, 118, 128, 0.14);
  --bg-seg-active: #ffffff;
  --text-seg-active: #000000;
  --border-color: rgba(60, 60, 67, 0.14);
  --border-light: rgba(60, 60, 67, 0.08);
  --border-active: #007aff;
  --text-primary: #000000;
  --text-secondary: rgba(60, 60, 67, 0.7);
  --text-muted: rgba(60, 60, 67, 0.45);
  --accent-color: #007aff;
  --accent-blue: #007aff;
  --accent-mint: #34c759;
  --accent-gradient: linear-gradient(135deg, #007aff, #30b0c7);
  --balance-gradient: linear-gradient(135deg, #007aff, #0056b3);
  --card-shadow: 0 4px 18px rgba(0, 0, 0, 0.06);
  --nav-shadow: 0 -2px 14px rgba(0, 0, 0, 0.04);
}

/* 3. iOS Sepia Theme (Apple Books Warm Parchment) */
body.theme-sepia {
  --bg-primary: #f4ecd8;
  --bg-secondary: rgba(247, 241, 227, 0.9);
  --bg-card: rgba(253, 248, 237, 0.88);
  --bg-card-solid: #fbf5e8;
  --bg-card-hover: #eae0c9;
  --bg-input: rgba(120, 90, 60, 0.12);
  --bg-seg-control: rgba(120, 90, 60, 0.14);
  --bg-seg-active: #ffffff;
  --text-seg-active: #433422;
  --border-color: rgba(67, 52, 34, 0.12);
  --border-light: rgba(67, 52, 34, 0.06);
  --border-active: #b45309;
  --text-primary: #433422;
  --text-secondary: #6e5944;
  --text-muted: #99836d;
  --accent-color: #b45309;
  --accent-blue: #0284c7;
  --accent-mint: #15803d;
  --accent-gradient: linear-gradient(135deg, #b45309, #d97706);
  --balance-gradient: linear-gradient(135deg, #78350f, #b45309);
  --card-shadow: 0 4px 18px rgba(67, 52, 34, 0.08);
  --nav-shadow: 0 -2px 14px rgba(67, 52, 34, 0.05);
}

/* ================= APP SHELL ================= */
.app-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* iOS Frosted Glass App Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(56px + var(--tg-top-offset, 0px));
  padding-top: var(--tg-top-offset, 0px);
  padding-left: max(16px, var(--tg-safe-area-inset-left, env(safe-area-inset-left, 16px)));
  padding-right: max(16px, var(--tg-safe-area-inset-right, env(safe-area-inset-right, 16px)));
  background: var(--bg-secondary);
  border-bottom: 0.5px solid var(--border-color);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  z-index: 50;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 24px;
  filter: drop-shadow(0 2px 6px rgba(48, 176, 199, 0.3));
}

.brand-texts {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: -0.1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* iOS Dynamic Island Balance Capsule */
.user-balance-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(48, 176, 199, 0.12);
  border: 0.5px solid rgba(48, 176, 199, 0.35);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-color);
  cursor: pointer;
  transition: transform 0.15s var(--spring-easing), background-color 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.user-balance-chip:active {
  transform: scale(0.93);
  background: rgba(48, 176, 199, 0.22);
}

.balance-icon {
  font-size: 14px;
}

.balance-amount {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
}

/* Circular iOS Button */
.btn-icon {
  border: 0.5px solid var(--border-color);
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  outline: none;
  transition: transform 0.15s var(--spring-easing), background-color 0.2s;
}

.btn-icon:active {
  transform: scale(0.88);
}

.btn-icon.active {
  background: var(--accent-color);
  color: #ffffff;
  border-color: transparent;
}

/* App Content Area */
.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(66px + var(--tg-top-offset, 0px)) max(16px, var(--tg-safe-area-inset-right, env(safe-area-inset-right, 16px))) calc(98px + var(--tg-bottom-offset, 0px)) max(16px, var(--tg-safe-area-inset-left, env(safe-area-inset-left, 16px)));
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: iosFadeSlide 0.25s var(--spring-easing);
}

.tab-pane.active.slide-from-right {
  animation: iosSlideRight 0.32s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}

.tab-pane.active.slide-from-left {
  animation: iosSlideLeft 0.32s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}

@keyframes iosSlideRight {
  from {
    opacity: 0;
    transform: translateX(24px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes iosSlideLeft {
  from {
    opacity: 0;
    transform: translateX(-24px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

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

/* ================= iOS 26 FLOATING GLASS CAPSULE TAB BAR ================= */
.bottom-nav {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom, 14px));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 420px;
  height: 64px;
  background: var(--bg-secondary);
  border: 0.5px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(35px) saturate(210%);
  -webkit-backdrop-filter: blur(35px) saturate(210%);
  border-radius: 36px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 5px 8px;
  z-index: 50;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: transform 0.3s var(--spring-easing), background-color 0.3s;
}

body.theme-light .bottom-nav {
  border: 0.5px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

body.theme-sepia .bottom-nav {
  border: 0.5px solid rgba(67, 52, 34, 0.15);
  box-shadow: 0 12px 36px rgba(67, 52, 34, 0.12);
}

.nav-item {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  border-radius: 28px;
  transition: all 0.22s var(--spring-easing);
  padding: 4px 0;
}

.nav-item:active {
  transform: scale(0.92);
}

.nav-item.active {
  color: var(--accent-color);
  background: rgba(48, 176, 199, 0.14);
}

body.theme-light .nav-item.active {
  background: rgba(0, 122, 255, 0.12);
  color: #007aff;
}

body.theme-sepia .nav-item.active {
  background: rgba(180, 83, 9, 0.12);
  color: #b45309;
}

.nav-svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  transition: transform 0.25s var(--spring-bounce), stroke 0.2s;
}

.nav-item.active .nav-svg {
  transform: translateY(-1px) scale(1.08);
  animation: navIconPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes navIconPop {
  0% { transform: scale(0.8); }
  50% { transform: scale(1.22) translateY(-2px); }
  100% { transform: scale(1.08) translateY(-1px); }
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: -0.15px;
  margin-top: 2px;
}

.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  background: #ff3b30; /* Apple System Red */
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(255, 59, 48, 0.4);
}

/* ================= TAB 1: KATALOG (STORE) ================= */
.catalog-search-wrap {
  margin-bottom: 14px;
}

.search-input-box {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  gap: 10px;
  transition: background-color 0.2s;
}

.search-icon {
  font-size: 15px;
  opacity: 0.55;
}

.search-input-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  letter-spacing: -0.2px;
}

.search-input-box input::placeholder {
  color: var(--text-muted);
}

.search-clear-btn {
  background: rgba(120, 120, 128, 0.3);
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.books-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

/* Skeleton Loading Cards */
.book-skeleton-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--card-shadow);
}

.skeleton-cover {
  height: 130px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  animation: pulse-skeleton 1.5s infinite ease-in-out;
}

.skeleton-line {
  height: 14px;
  background: var(--bg-input);
  border-radius: 4px;
  animation: pulse-skeleton 1.5s infinite ease-in-out;
}

@keyframes pulse-skeleton {
  0% { opacity: 0.35; }
  50% { opacity: 0.75; }
  100% { opacity: 0.35; }
}

/* Apple Books Style Card */
.book-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, border-color 0.2s;
}

/* Entrance animation plays only on the very first render (class removed on animationend),
   so tab switches and data refreshes don't make cards vanish and reappear. */
.book-card.entering {
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  animation: iosCardEntrance 0.4s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
  animation-delay: calc(var(--card-idx, 0) * 0.055s);
  will-change: transform, opacity;
}

@keyframes iosCardEntrance {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.book-card:active {
  transform: scale(0.96) translateY(1px);
}

.book-cover-mock {
  height: 136px;
  background: linear-gradient(135deg, #1c2536, #0b1329);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #f8fafc;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
  border: 0.5px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.5);
}

/* 3D Spine highlight */
.book-cover-mock::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 10px;
  height: 100%;
  background: linear-gradient(to right, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.25));
  border-right: 0.5px solid rgba(0, 0, 0, 0.3);
}

.book-cover-icon {
  font-size: 38px;
  margin-bottom: 6px;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
}

.book-cover-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  padding: 3px 8px;
  border-radius: 8px;
  border: 0.5px solid rgba(255, 255, 255, 0.15);
}

.book-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  line-height: 1.3;
  letter-spacing: -0.3px;
}

.book-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.book-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 0.5px solid var(--border-light);
}

.book-card-price {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-color);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
}

.btn-card-action {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.15s var(--spring-easing), opacity 0.15s;
}

.btn-card-action:active {
  transform: scale(0.93);
}

.btn-card-action.owned {
  background: rgba(48, 209, 88, 0.16);
  color: var(--accent-mint);
  border: 0.5px solid rgba(48, 209, 88, 0.35);
}

.btn-card-action.buy {
  background: var(--accent-color);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(48, 176, 199, 0.35);
}

/* ================= TAB 2: KUTUBXONAM (MY LIBRARY) ================= */
.library-header-banner {
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--card-shadow);
}

.lib-banner-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: -0.3px;
}

.lib-banner-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

.my-books-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Grouped Inset Row */
.my-book-row {
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.my-book-row.entering {
  opacity: 0;
  transform: translateY(14px);
  animation: iosRowEntrance 0.38s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
  animation-delay: calc(var(--row-idx, 0) * 0.06s);
  will-change: transform, opacity;
}

@keyframes iosRowEntrance {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.my-book-row:active {
  transform: scale(0.97);
}

.my-book-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(48, 176, 199, 0.2), rgba(10, 132, 255, 0.2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 0.5px solid rgba(48, 176, 199, 0.3);
  flex-shrink: 0;
}

.my-book-info {
  flex: 1;
  min-width: 0;
}

.my-book-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.2px;
}

.my-book-progress-text {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.my-book-progress-bar {
  width: 100%;
  height: 5px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.my-book-progress-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.btn-read-now {
  background: var(--accent-color);
  color: #ffffff;
  border: none;
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(48, 176, 199, 0.3);
}

/* ================= TAB 3: KABINET & HAMKORLIK ================= */
.profile-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  box-shadow: var(--card-shadow);
}

.user-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  box-shadow: 0 4px 14px rgba(48, 176, 199, 0.35);
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
  letter-spacing: -0.3px;
}

.user-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

/* iOS Wallet / Apple Card Balance Widget */
.balance-card {
  background: var(--balance-gradient);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  margin-bottom: 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  position: relative;
  overflow: hidden;
  border: 0.5px solid rgba(255, 255, 255, 0.15);
}

.balance-card::before {
  content: "";
  position: absolute;
  top: -50px;
  right: -50px;
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.balance-card::after {
  content: "";
  position: absolute;
  top: -60%;
  left: -120%;
  width: 70%;
  height: 240%;
  background: linear-gradient(
    115deg,
    transparent 20%,
    rgba(255, 255, 255, 0.22) 48%,
    rgba(255, 255, 255, 0.35) 50%,
    rgba(255, 255, 255, 0.22) 52%,
    transparent 80%
  );
  transform: rotate(25deg);
  pointer-events: none;
  animation: glassShimmer 6.5s infinite ease-in-out;
}

@keyframes glassShimmer {
  0%, 75% {
    left: -120%;
  }
  100% {
    left: 200%;
  }
}

.balance-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  opacity: 0.8;
  margin-bottom: 6px;
}

.balance-big {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.8px;
  margin-bottom: 18px;
  font-variant-numeric: tabular-nums;
}

.balance-actions {
  display: flex;
  gap: 10px;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.15s var(--spring-easing), opacity 0.15s;
  text-align: center;
}

.btn-primary {
  background: #ffffff;
  color: #000000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
  color: #ffffff;
  border: 0.5px solid rgba(255, 255, 255, 0.25);
}

.btn-primary:active, .btn-secondary:active {
  transform: scale(0.95);
}

/* Referral Section */
.referral-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--card-shadow);
}

.ref-badge {
  display: inline-block;
  background: rgba(48, 209, 88, 0.15);
  color: var(--accent-mint);
  border: 0.5px solid rgba(48, 209, 88, 0.35);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 10px;
}

.ref-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.ref-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 14px;
}

.ref-link-box {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.ref-link-box input {
  flex: 1;
  background: var(--bg-input);
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
}

.btn-copy {
  background: var(--accent-color);
  color: #ffffff;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s;
}

.btn-copy:active {
  transform: scale(0.93);
}

.btn-share {
  width: 100%;
  background: var(--accent-blue);
  color: #ffffff;
  border: none;
  padding: 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 16px;
  transition: transform 0.15s;
}

.btn-share:active {
  transform: scale(0.96);
}

.ref-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 14px;
  border-top: 0.5px solid var(--border-light);
}

.stat-box {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.stat-number {
  display: block;
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-color);
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Support Card */
.support-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.support-text {
  display: flex;
  flex-direction: column;
}

.support-text strong {
  font-size: 13px;
  color: var(--text-primary);
}

.support-text span {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-outline {
  background: none;
  border: 0.5px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s;
}

.btn-outline:active {
  transform: scale(0.93);
}

/* ================= iOS BOTTOM SHEET MODAL ================= */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fadeIn 0.22s var(--spring-easing);
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
}

.modal-card {
  background: var(--bg-card-solid);
  border-top: 0.5px solid var(--border-color);
  border-radius: 28px 28px 0 0;
  padding: 12px 24px 34px 24px;
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  animation: iosSheetSpring 0.38s cubic-bezier(0.18, 0.89, 0.32, 1.15);
}

@keyframes iosSheetSpring {
  0% { transform: translateY(100%); }
  85% { transform: translateY(-4px); }
  100% { transform: translateY(0); }
}

@media (min-width: 600px) {
  .modal-card {
    border-radius: var(--radius-lg);
    border: 0.5px solid var(--border-color);
  }
}

.modal-grabber {
  width: 38px;
  height: 5px;
  background: rgba(120, 120, 128, 0.35);
  border-radius: 3px;
  margin: 4px auto 18px auto;
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--bg-input);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.modal-close-btn:active {
  transform: scale(0.85);
}

.modal-book-cover {
  width: 74px;
  height: 94px;
  background: var(--accent-gradient);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  color: #ffffff;
  margin-bottom: 14px;
  box-shadow: 0 6px 20px rgba(48, 176, 199, 0.35);
}

.modal-book-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.modal-book-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-color);
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.modal-book-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 22px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-modal-primary {
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(48, 176, 199, 0.35);
  transition: transform 0.15s var(--spring-easing);
}

.btn-modal-balance {
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  background: var(--accent-mint);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(48, 209, 88, 0.35);
  transition: transform 0.15s var(--spring-easing);
}

.btn-modal-bot {
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  border: 0.5px solid var(--border-color);
  cursor: pointer;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: transform 0.15s var(--spring-easing);
}

.btn-modal-sample {
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid rgba(48, 176, 199, 0.4);
  cursor: pointer;
  background: rgba(48, 176, 199, 0.12);
  color: var(--accent-color);
  transition: transform 0.15s var(--spring-easing), background 0.15s;
}

.btn-modal-sample:hover {
  background: rgba(48, 176, 199, 0.2);
}

.btn-modal-primary:active,
.btn-modal-balance:active,
.btn-modal-bot:active,
.btn-modal-sample:active {
  transform: scale(0.96);
}

.book-sample-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(48, 176, 199, 0.85);
  color: #ffffff;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.reader-sample-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(48, 176, 199, 0.2);
  color: var(--accent-color);
  border: 0.5px solid rgba(48, 176, 199, 0.4);
  margin-left: 6px;
  vertical-align: middle;
}

.sample-end-card {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 28px auto 60px auto;
  padding: 24px 20px;
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  border: 1px dashed var(--accent-color);
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.sample-end-icon {
  font-size: 38px;
  margin-bottom: 8px;
}

.sample-end-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.sample-end-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 18px;
}

.btn-sample-buy {
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  padding: 13px 20px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(48, 176, 199, 0.4);
  transition: transform 0.15s var(--spring-easing);
}

.btn-sample-buy:active {
  transform: scale(0.96);
}

/* ================= FULLSCREEN READER VIEW ================= */
.reader-view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-primary);
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reader-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(54px + var(--tg-top-offset, 0px));
  padding-top: var(--tg-top-offset, 0px);
  padding-left: max(12px, calc(var(--tg-safe-area-inset-left, env(safe-area-inset-left, 0px)) + var(--tg-content-safe-area-inset-left, 0px)));
  padding-right: max(12px, calc(var(--tg-safe-area-inset-right, env(safe-area-inset-right, 0px)) + var(--tg-content-safe-area-inset-right, 0px)));
  background: var(--bg-secondary);
  border-bottom: 0.5px solid var(--border-color);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  z-index: 160;
  transition: transform 0.25s var(--spring-easing), opacity 0.25s;
}

.reader-header.hidden {
  transform: translateY(-100%);
  opacity: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

/* In Telegram, native BackButton handles closing; hide duplicate internal back arrow to save space */
body.is-telegram #btn-reader-back {
  display: none !important;
}

.book-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.book-title {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.page-indicator {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 5px;
}

@media (max-width: 480px) {
  .reader-header {
    padding-left: 8px;
    padding-right: 8px;
  }
  .header-left {
    gap: 6px;
  }
  .header-right {
    gap: 3px;
  }
  .header-right .btn-icon {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }
  .book-title {
    font-size: 13px;
  }
}

.viewer-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(66px + var(--tg-top-offset, 0px)) 0 calc(80px + var(--tg-bottom-offset, 0px)) 0;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  box-sizing: border-box;
  width: 100%;
}

.viewer-container.zoomed {
  overflow-x: auto;
  touch-action: pan-x pan-y;
}

.viewer-container.can-pan {
  cursor: grab;
}

.viewer-container.is-panning {
  cursor: grabbing;
  user-select: none;
}

.pages-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  width: 100%;
  max-width: 100%;
  padding: 0 12px;
  box-sizing: border-box;
}

.viewer-container.zoomed .pages-list {
  width: max-content;
  max-width: none;
}

.pdf-page-wrap {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  position: relative;
  min-height: 350px;
  margin: 0 auto;
  max-width: 100%;
  box-sizing: border-box;
}

.pdf-page-wrap canvas {
  display: block;
  border-radius: 8px;
}

.page-skeleton {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  color: #8e8e93;
  font-size: 13px;
  font-weight: 500;
  gap: 8px;
  border-radius: 8px;
}

.page-skeleton-spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #e5e5ea;
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Floating iOS Bottom Progress Pill */
.floating-progress {
  position: fixed;
  bottom: max(16px, calc(16px + var(--tg-bottom-offset, 0px)));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-color);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  padding: 8px 18px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.35);
  z-index: 160;
  transition: transform 0.25s var(--spring-easing), opacity 0.25s;
  min-width: 270px;
  max-width: 90%;
}

.floating-progress.hidden {
  transform: translate(-50%, 80px);
  opacity: 0;
}

#floating-page-text {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.bottom-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  outline: none;
}

.bottom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ================= OVERLAYS & TOAST ================= */
.overlay-state {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  gap: 12px;
  padding: 24px;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.loading-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Native iOS Style Notification Pill */
.toast-notification {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 28, 30, 0.95);
  backdrop-filter: var(--glass-backdrop);
  -webkit-backdrop-filter: var(--glass-backdrop);
  color: #ffffff;
  padding: 11px 20px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  z-index: 210;
  border: 0.5px solid rgba(255, 255, 255, 0.16);
  animation: toastIn 0.25s var(--spring-easing);
  pointer-events: none;
  text-align: center;
  letter-spacing: -0.2px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.7;
}

.empty-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.empty-desc {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 300px;
  line-height: 1.4;
}

/* Catalog Filter Pills (All / Paid / Free) */
.catalog-filter-pills {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.filter-pill {
  border: 0.5px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 6px 13px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--spring-easing);
}

.filter-pill.active {
  background: var(--accent-color);
  color: #ffffff;
  border-color: transparent;
}

.book-free-badge {
  background: rgba(52, 199, 89, 0.9) !important;
  color: #ffffff !important;
}

/* Modal Promo Code Box */
.modal-promo-box {
  margin-bottom: 12px;
}

.modal-promo-row {
  display: flex;
  gap: 8px;
}

.modal-promo-row input {
  flex: 1;
  background: var(--bg-input);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 13px;
  text-transform: uppercase;
  outline: none;
}

.btn-promo-apply {
  background: var(--accent-color);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.modal-promo-status {
  font-size: 12px;
  margin-top: 5px;
  min-height: 14px;
}

.modal-promo-status.ok {
  color: #34c759;
}

.modal-promo-status.err {
  color: #ff453a;
}

.promo-badge {
  display: inline-block;
  background: rgba(52, 199, 89, 0.18);
  color: #34c759;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  margin-left: 4px;
}
