:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --muted: #4b5563;
  --border: #e5e7eb;
  --accent: #b45309;
  --accent-bg: #fffbeb;
  --accent-border: #f59e0b;
  --selected-bg: #ecfdf5;
  --selected-border: #10b981;
  --selected-text: #065f46;
  --danger: #dc2626;
  --topbar-bg: #111827;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  touch-action: manipulation;
}

body {
  padding-bottom: calc(88px + var(--safe-bottom));
}

.topbar {
  background: var(--topbar-bg);
  color: #f9fafb;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.topbar-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 14px 14px 10px;
}

h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 4px 0 10px;
  font-size: 0.82rem;
  color: #d1d5db;
}

.subtitle a {
  color: #fbbf24;
  text-decoration: underline;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#searchInput {
  width: 100%;
  padding: 11px 38px 11px 14px;
  border-radius: 10px;
  border: 1px solid #374151;
  background: #1f2937;
  color: #ffffff;
  font-size: 1rem;
  outline: none;
}

#searchInput::placeholder {
  color: #9ca3af;
}

#searchInput:focus {
  border-color: #fbbf24;
}

.clear-search {
  position: absolute;
  right: 8px;
  background: #374151;
  color: #f9fafb;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.filters::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  flex: 0 0 auto;
  border: 1px solid #374151;
  background: #1f2937;
  color: #e5e7eb;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-height: 36px;
}

.filter-pill.active {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #111827;
}

.filter-pill.selected-tab.active {
  background: #10b981;
  border-color: #10b981;
  color: #ffffff;
}

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 12px 24px;
}

.results-info {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 2px 2px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.book-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.08s ease;
  user-select: none;
}

.book-card:active {
  transform: scale(0.992);
}

.book-card.selected {
  background: var(--selected-bg);
  border-color: var(--selected-border);
}

.cover-wrap {
  flex: 0 0 72px;
  width: 72px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  background: #e5e7eb;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

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

.book-meta-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.badge-cat {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #374151;
  background: #e5e7eb;
  padding: 2px 7px;
  border-radius: 6px;
}

.badge-new {
  font-size: 0.72rem;
  font-weight: 700;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  padding: 1px 7px;
  border-radius: 6px;
}

.book-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.book-details {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 5px;
}

.book-desc {
  font-size: 0.84rem;
  color: #374151;
  margin: 0 0 8px;
}

.book-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.book-price {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
}

.book-card.selected .book-price {
  color: var(--selected-text);
}

.book-link {
  font-size: 0.78rem;
  color: #2563eb;
  text-decoration: none;
  padding: 4px 6px;
  margin: -4px -6px;
}

.book-link:hover {
  text-decoration: underline;
}

.check-col {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  align-self: center;
}

.check-box {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid #9ca3af;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 800;
  color: transparent;
  transition: all 0.15s ease;
}

.book-card.selected .check-box {
  background: #10b981;
  border-color: #10b981;
  color: #ffffff;
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #111827;
  color: #f9fafb;
  border-top: 1px solid #374151;
  z-index: 30;
  padding-bottom: var(--safe-bottom);
}

.bottom-bar-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.summary-main {
  font-size: 0.98rem;
}

.summary-main .dot {
  margin: 0 5px;
  color: #9ca3af;
}

.save-status {
  font-size: 0.76rem;
  color: #34d399;
  margin-top: 2px;
}

.save-status.saving {
  color: #fbbf24;
}

.save-status.error {
  color: #f87171;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.btn-primary {
  background: #f59e0b;
  color: #111827;
}

.btn-secondary {
  background: #e5e7eb;
  color: #111827;
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.btn-icon {
  background: #f3f4f6;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal {
  background: #ffffff;
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }
  .modal {
    border-radius: 16px;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
}

.modal-note {
  margin: 0 0 10px;
  font-size: 0.86rem;
  color: var(--muted);
}

.txt-preview {
  margin: 0;
  padding: 12px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: #f9fafb;
}

.modal-actions > * {
  flex: 1 1 auto;
}

.hidden {
  display: none !important;
}

.loading,
.empty-state {
  text-align: center;
  padding: 36px 16px;
  background: var(--surface);
  border-radius: 14px;
  border: 1px dashed #d1d5db;
  color: var(--muted);
}
