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

:root {
  --primary: #4A90D9;
  --primary-dark: #357ABD;
  --bg: #F8F9FA;
  --card-bg: #FFFFFF;
  --text: #2C3E50;
  --text-muted: #7F8C8D;
  --danger: #E74C3C;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Page transitions */
.page {
  display: none;
  min-height: 100vh;
  padding-bottom: 40px;
}
.page.active {
  display: block;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}
.app-header h1 {
  font-size: 22px;
  font-weight: 700;
  flex: 1;
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 28px;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}
.btn-primary:active {
  transform: scale(0.95);
  background: var(--primary-dark);
}
.btn-secondary {
  background: #E8F4FD;
  color: var(--primary);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 28px;
  cursor: pointer;
  transition: transform 0.1s;
}
.btn-secondary:active {
  transform: scale(0.95);
}
.btn-ghost {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 15px;
  padding: 12px 20px;
  cursor: pointer;
}
.btn-danger {
  color: var(--danger);
}
.btn-round {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.btn-large {
  width: 100%;
  padding: 16px;
  font-size: 18px;
}
.btn-back {
  background: none;
  border: none;
  padding: 8px;
  margin-right: 8px;
  cursor: pointer;
  color: var(--text);
}

/* Sections */
.section {
  padding: 0 20px;
  margin-bottom: 24px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 12px;
}
.section-header .section-title {
  margin-bottom: 0;
}

/* Sort */
.sort-select {
  border: 1px solid #DDD;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  background: white;
  color: var(--text);
}

/* Book row (horizontal scroll) */
.book-row {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.book-row::-webkit-scrollbar {
  display: none;
}
.book-row .book-card {
  scroll-snap-align: start;
  flex-shrink: 0;
  width: 120px;
}

/* Book grid */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 16px;
}

/* Book card */
.book-card {
  cursor: pointer;
  transition: transform 0.15s;
}
.book-card:active {
  transform: scale(0.95);
}
.book-cover {
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: #E0E0E0;
  box-shadow: var(--shadow);
}
.book-cover-placeholder {
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 600;
  padding: 10px;
  text-align: center;
  box-shadow: var(--shadow);
  word-break: break-all;
}
.book-title {
  font-size: 13px;
  font-weight: 500;
  margin-top: 8px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
}
.empty-state p {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.empty-hint {
  font-size: 14px !important;
}

/* Scanner */
#scanner-container {
  width: 100%;
  background: black;
  overflow: hidden;
}
#scanner-reader {
  width: 100%;
  min-height: 300px;
}
#scanner-reader video {
  width: 100% !important;
  border: none !important;
}
#scanner-reader img[alt="Info icon"] {
  display: none !important;
}
.scanner-hint {
  text-align: center;
  color: var(--text-muted);
  padding: 12px 16px 4px;
  font-size: 15px;
}
.btn-manual {
  display: block;
  width: 100%;
  text-align: center;
  padding: 10px;
  font-size: 14px;
  color: var(--primary);
}

/* Scanner result */
#scanner-result {
  padding: 20px;
}
.result-card {
  display: flex;
  gap: 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.result-cover {
  width: 80px;
  height: 107px;
  border-radius: 8px;
  object-fit: cover;
  background: #E0E0E0;
}
.result-info h3 {
  font-size: 17px;
  margin-bottom: 6px;
}
.result-info p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

/* Detail page */
#detail-content {
  padding: 20px;
  text-align: center;
}
.detail-cover {
  width: 180px;
  height: 240px;
  border-radius: var(--radius);
  object-fit: cover;
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
  background: #E0E0E0;
}
#detail-title {
  font-size: 22px;
  margin-bottom: 4px;
}
#detail-subtitle {
  font-size: 14px;
  margin-bottom: 6px;
}
.detail-author {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 16px;
}
.detail-tag {
  background: #E8F4FD;
  color: var(--primary);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
}
.detail-rating {
  font-size: 16px;
  color: #F5A623;
  margin-bottom: 16px;
}
.detail-summary {
  text-align: left;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.detail-meta {
  text-align: left;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.8;
}
.detail-meta-row {
  display: flex;
  gap: 8px;
}
.detail-meta-label {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}
.detail-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 32px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  max-width: 300px;
  margin: 0 auto;
}

.text-muted {
  color: var(--text-muted);
}
