:root {
  --bg-color: var(--tg-theme-bg-color, #f4f6f8);
  --text-color: var(--tg-theme-text-color, #1c1e21);
  --hint-color: var(--tg-theme-hint-color, #82878d);
  --link-color: var(--tg-theme-link-color, #2481cc);
  --button-color: var(--tg-theme-button-color, #2481cc);
  --button-text-color: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg-color: var(--tg-theme-secondary-bg-color, #ffffff);
  --accent-light: rgba(36, 129, 204, 0.10);
  --border-subtle: rgba(0, 0, 0, 0.07);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: 30px;
  min-height: 100vh;
}

.app-container {
  max-width: 650px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.logo-icon {
  font-size: 30px;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.app-subtitle {
  font-size: 13px;
  color: var(--hint-color);
}

.db-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--secondary-bg-color);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
}

.db-badge.healthy .status-dot {
  background: #10b981;
}

.db-badge.unhealthy .status-dot {
  background: #ef4444;
}

/* Nav Tabs */
.app-nav {
  display: flex;
  background: var(--secondary-bg-color);
  border-radius: var(--radius-md);
  padding: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  gap: 4px;
}

.nav-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 10px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint-color);
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-tab.active {
  background: var(--accent-light);
  color: var(--link-color);
}

.badge-count {
  background: var(--link-color);
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
}

/* App Views */
.app-view {
  display: none;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.15s ease;
}

.app-view.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0.7; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
}

.books-count-text, .section-subtitle {
  font-size: 13px;
  color: var(--hint-color);
}

/* Catalog Cards */
.book-entry-card {
  background: var(--secondary-bg-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.book-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.book-badge-lang {
  background: var(--accent-light);
  color: var(--link-color);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
}

.book-qa-tag {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
}

.book-title-main {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-color);
}

.book-title-sub {
  font-size: 14px;
  color: var(--hint-color);
  font-style: italic;
}

.book-stats-row {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: var(--hint-color);
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}

.book-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-read-book, .btn-vocab-book {
  border: none;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s, opacity 0.15s;
}

.btn-read-book {
  background: var(--button-color);
  color: var(--button-text-color);
}

.btn-vocab-book {
  background: var(--accent-light);
  color: var(--link-color);
}

.btn-read-book:active, .btn-vocab-book:active {
  transform: scale(0.98);
  opacity: 0.85;
}

/* Reader View */
.reader-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.back-btn {
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-subtle);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13px;
  color: var(--link-color);
  cursor: pointer;
}

.chapter-dropdown {
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-subtle);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-color);
  cursor: pointer;
  max-width: 250px;
}

.reader-card {
  background: var(--secondary-bg-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  padding-bottom: 260px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
}

.book-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 8px;
  flex-wrap: wrap;
}

.book-meta-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.book-tag {
  background: var(--accent-light);
  color: var(--link-color);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

.reader-cache-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.reader-cache-badge.cached {
  background: #ecfdf5;
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.reader-cache-badge.network {
  background: rgba(36, 129, 204, 0.08);
  color: var(--link-color);
  border: 1px solid rgba(36, 129, 204, 0.2);
}

.book-info {
  font-size: 12px;
  color: var(--hint-color);
}

.text-passage {
  font-family: 'Georgia', serif;
  font-size: 18px;
  line-height: 1.85;
  letter-spacing: 0.01em;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 120px;
}

/* Reader Smooth Content Fade In */
.reader-fade-in {
  animation: readerFadeIn 0.28s ease-out;
}

@keyframes readerFadeIn {
  from {
    opacity: 0.15;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Reader Loading State & Book Animation */
.reader-loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 16px 0 24px 0;
  width: 100%;
}

.book-loader-anim {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.book-anim-pages {
  position: relative;
  width: 48px;
  height: 34px;
  perspective: 200px;
}

.book-spine-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--link-color);
  opacity: 0.35;
  transform: translateX(-50%);
  z-index: 4;
}

.book-page-leaf {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  border: 1.5px solid var(--link-color);
  background: var(--secondary-bg-color);
  box-sizing: border-box;
}

.book-page-leaf.left {
  left: 0;
  border-radius: 4px 0 0 4px;
  border-right: none;
}

.book-page-leaf.right {
  right: 0;
  border-radius: 0 4px 4px 0;
  border-left: none;
}

.book-page-leaf.flipping {
  right: 0;
  border-radius: 0 4px 4px 0;
  border-left: none;
  transform-origin: left center;
  animation: flipPageLeaf 1.3s cubic-bezier(0.4, 0.0, 0.2, 1) infinite;
  background: linear-gradient(to right, rgba(36, 129, 204, 0.12), var(--secondary-bg-color));
}

@keyframes flipPageLeaf {
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(-180deg);
    border-radius: 4px 0 0 4px;
  }
  100% {
    transform: rotateY(-180deg);
    border-radius: 4px 0 0 4px;
  }
}

.book-loader-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-color);
}

.book-loader-desc {
  font-size: 12px;
  color: var(--hint-color);
}

/* Skeleton Placeholder Lines */
.reader-skeleton-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 4px;
}

.skeleton-para {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.skeleton-line {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    rgba(128, 128, 128, 0.07) 25%,
    rgba(128, 128, 128, 0.18) 50%,
    rgba(128, 128, 128, 0.07) 75%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite linear;
}

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

.sentence-block {
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.sentence-block.active-sentence {
  background: rgba(36, 129, 204, 0.06);
}

.word-token {
  display: inline-block;
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 3px;
  margin: 0 1px;
  transition: background 0.15s ease, transform 0.1s ease;
}

.word-token:active {
  transform: scale(0.96);
}

.word-token.selected {
  background: var(--button-color);
  color: var(--button-text-color);
  font-weight: 600;
}

/* Translation Bottom Sheet Panel (Fixed Docked) */
.translation-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  box-sizing: border-box;
  z-index: 1000;
  background: var(--secondary-bg-color);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.16);
  border: 1px solid var(--border-subtle);
  border-bottom: none;
  padding: 12px 18px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

#view-reader:not(.active) .translation-panel {
  display: none !important;
}

.translation-panel.collapsed {
  transform: translateY(calc(100% - 44px));
}

.panel-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--hint-color);
  opacity: 0.35;
  margin: 0 auto 4px auto;
  cursor: pointer;
}

.panel-tabs {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.05);
  padding: 3px;
  border-radius: 8px;
  width: fit-content;
}

.panel-tab-btn {
  border: none;
  background: transparent;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--hint-color);
  cursor: pointer;
  transition: all 0.15s ease;
}

.panel-tab-btn.active {
  background: var(--secondary-bg-color);
  color: var(--text-color);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.panel-close-btn {
  background: none;
  border: none;
  color: var(--hint-color);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.panel-close-btn:hover {
  opacity: 1;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.word-selected {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-color);
}

.word-transcription {
  font-size: 13px;
  color: var(--hint-color);
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.save-btn {
  background: var(--button-color);
  color: var(--button-text-color);
  border: none;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.secondary-save-btn {
  background: var(--accent-light);
  color: var(--link-color);
}

.save-btn.saved {
  background: #10b981;
  color: #fff;
}

.translation-main {
  font-size: 17px;
  font-weight: 600;
  color: var(--link-color);
  line-height: 1.4;
}

.sentence-context {
  background: rgba(0, 0, 0, 0.03);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.context-label {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--hint-color);
}

.context-en {
  font-style: italic;
  color: var(--text-color);
}

.context-ru {
  color: #4b5563;
}

/* Vocabulary & SRS */
.vocab-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.vocab-mode-toggle {
  display: flex;
  background: var(--secondary-bg-color);
  border-radius: var(--radius-md);
  padding: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.mode-btn {
  border: none;
  background: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--hint-color);
}

.mode-btn.active {
  background: var(--link-color);
  color: #fff;
}

.vocab-mode-view {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.vocab-mode-view.active {
  display: flex;
}

.vocab-filters {
  display: flex;
  gap: 8px;
}

.filter-chip {
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-subtle);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--hint-color);
  cursor: pointer;
}

.filter-chip.active {
  background: var(--text-color);
  color: #fff;
  border-color: var(--text-color);
}

.vocab-items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vocab-card-item {
  background: var(--secondary-bg-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  box-shadow: 0 1px 4px rgba(0,0,0,0.03);
  border: 1px solid var(--border-subtle);
}

.card-item-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-item-front {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-color);
}

.card-item-back {
  font-size: 14px;
  color: var(--link-color);
  font-weight: 600;
}

.card-item-context {
  font-size: 12px;
  color: var(--hint-color);
  font-style: italic;
  margin-top: 2px;
}

.delete-card-btn {
  background: none;
  border: none;
  color: var(--hint-color);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  opacity: 0.6;
}

.delete-card-btn:hover {
  opacity: 1;
  color: #ef4444;
}

/* SRS Flashcards */
.srs-card-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.srs-card {
  width: 100%;
  min-height: 240px;
  background: var(--secondary-bg-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 14px;
}

.card-type-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent-light);
  color: var(--link-color);
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 700;
}

.srs-front-word {
  font-size: 26px;
  font-weight: 800;
}

.srs-front-context {
  font-size: 14px;
  color: var(--hint-color);
  font-style: italic;
}

.reveal-btn {
  margin-top: 8px;
  background: var(--button-color);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
}

.srs-divider {
  width: 80%;
  border: none;
  border-top: 1px dashed var(--border-subtle);
  margin: 12px 0;
}

.srs-back-translation {
  font-size: 22px;
  font-weight: 700;
  color: #059669;
}

.srs-back-context {
  font-size: 13px;
  color: var(--hint-color);
  margin-top: 4px;
}

.srs-ratings {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.srs-rate-btn {
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.srs-rate-btn.again { background: #fee2e2; color: #dc2626; }
.srs-rate-btn.good { background: #fef3c7; color: #d97706; }
.srs-rate-btn.easy { background: #d1fae5; color: #059669; }

.srs-progress {
  font-size: 12px;
  color: var(--hint-color);
  font-weight: 600;
}

/* Backups & Stats Card */
.stat-card {
  background: var(--secondary-bg-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stat-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-icon {
  font-size: 26px;
}

.stat-card-title {
  font-size: 16px;
  font-weight: 700;
}

.stat-card-subtitle {
  font-size: 12px;
  color: var(--hint-color);
}

.stat-metrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.metric-box {
  background: var(--bg-color);
  padding: 12px;
  border-radius: var(--radius-md);
  text-align: center;
}

.metric-value {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-color);
}

.metric-label {
  font-size: 11px;
  color: var(--hint-color);
  margin-top: 2px;
}

.backup-folder-info {
  background: rgba(0, 0, 0, 0.03);
  padding: 12px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.folder-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--hint-color);
}

.folder-path {
  font-family: monospace;
  font-size: 12px;
  word-break: break-all;
  color: var(--link-color);
}

.primary-action-btn {
  background: #10b981;
  color: #ffffff;
  border: none;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, transform 0.1s;
}

.primary-action-btn:active {
  transform: scale(0.98);
}

.backup-status-msg {
  font-size: 13px;
  text-align: center;
  font-weight: 600;
}

.backup-status-msg.success { color: #10b981; }
.backup-status-msg.error { color: #ef4444; }

.history-title {
  font-size: 14px;
  font-weight: 700;
  margin-top: 6px;
}

.backups-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 250px;
  overflow-y: auto;
}

.backup-item {
  background: var(--bg-color);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.backup-name {
  font-weight: 600;
  font-family: monospace;
}

.backup-meta {
  font-size: 11px;
  color: var(--hint-color);
}

.empty-state {
  text-align: center;
  padding: 30px 16px;
  color: var(--hint-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.empty-icon {
  font-size: 36px;
  opacity: 0.5;
}

.loading-spinner {
  text-align: center;
  padding: 20px;
  color: var(--hint-color);
  font-size: 13px;
}

/* Book Progress & Resume Styles */
.book-progress-banner {
  display: flex;
  margin-top: -4px;
}

.book-progress-badge {
  background: #ecfdf5;
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.25);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-resume-book {
  background: #10b981 !important;
  color: #ffffff !important;
  font-weight: 700 !important;
}

.btn-restart-book {
  background: var(--accent-light) !important;
  color: var(--link-color) !important;
}

/* Sentence Action Icon & Translating Spinner */
.sentence-action-icon {
  display: inline-block;
  opacity: 0.25;
  cursor: pointer;
  font-size: 13px;
  margin-right: 6px;
  user-select: none;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.sentence-action-icon:hover,
.sentence-block.active-sentence .sentence-action-icon {
  opacity: 0.85;
  transform: scale(1.1);
}

.translating-spinner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--hint-color);
  font-size: 14px;
  font-style: italic;
  animation: pulseOpacity 1.2s infinite ease-in-out;
}

@keyframes pulseOpacity {
  0% { opacity: 0.5; }
  50% { opacity: 1; }
  100% { opacity: 0.5; }
}

