:root {
  --main: #009688;
  --main-light: #4db6ac;
  --main-dark: #00796b;
  --bg: #f7fffd;
  --text: #333;
  --text-light: #777;
  --card-bg: #fff;
  --border: #e0f2f1;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --radius: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Kaku Gothic ProN', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--main);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}
header h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: 0.02em; }
#book-count {
  font-size: 0.82rem;
  background: rgba(255,255,255,0.22);
  padding: 4px 12px;
  border-radius: 999px;
}

/* ── Book Grid ── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 14px;
  padding-bottom: 96px;
}

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 72px 20px;
  color: var(--text-light);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 1rem; }
.empty-sub { font-size: 0.85rem; margin-top: 6px; opacity: 0.8; }

/* ── Book Card ── */
.book-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.book-card:active { transform: scale(0.95); box-shadow: none; }

.book-card img.book-cover {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: var(--border);
}
.book-card .book-cover-ph {
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

.book-info { padding: 6px 8px 8px; }
.book-title {
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 2px;
}
.book-author {
  font-size: 0.62rem;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--main);
  color: #fff;
  font-size: 1.9rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,150,136,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: background 0.15s, transform 0.1s;
}
.fab:active { background: var(--main-dark); transform: scale(0.92); }

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.48);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-content {
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 500px;
  max-height: 92vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.modal-content h2 {
  text-align: center;
  font-size: 1.05rem;
  color: var(--main-dark);
  margin-bottom: 20px;
}

/* ── Method Buttons ── */
.method-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px;
  margin-bottom: 10px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.method-btn:active { border-color: var(--main); background: #e0f2f1; }
.method-icon { font-size: 1.6rem; }

.close-btn {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 0.9rem;
  cursor: pointer;
}

/* ── Scanner ── */
.scanner-wrap {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}
#scanner-video {
  width: 100%;
  display: block;
  max-height: 55vw;
  object-fit: cover;
}
.scan-frame {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scan-line {
  width: 75%;
  height: 2px;
  background: var(--main-light);
  box-shadow: 0 0 8px var(--main);
  animation: scanMove 2s ease-in-out infinite;
}
@keyframes scanMove {
  0%, 100% { transform: translateY(-30px); }
  50%       { transform: translateY(30px); }
}
.scanner-hint {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-light);
  margin: 12px 0 4px;
}

/* ── Search ── */
.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-row input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
.search-row input:focus { border-color: var(--main); }
.search-row button {
  padding: 10px 16px;
  background: var(--main);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.search-row button:active { background: var(--main-dark); }

#search-results { max-height: 48vh; overflow-y: auto; }

.search-status {
  text-align: center;
  color: var(--text-light);
  padding: 20px;
  font-size: 0.9rem;
}

.result-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  align-items: flex-start;
  transition: background 0.1s;
}
.result-item:active { background: #f0faf9; margin: 0 -4px; padding-left: 4px; padding-right: 4px; }

.result-cover {
  width: 44px;
  height: 66px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--border);
  flex-shrink: 0;
}
.result-cover-ph {
  width: 44px;
  height: 66px;
  border-radius: 4px;
  background: var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.result-info { flex: 1; min-width: 0; }
.result-title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 4px;
}
.result-author { font-size: 0.78rem; color: var(--text-light); }

/* ── Confirm ── */
.confirm-book {
  display: flex;
  gap: 16px;
  margin-bottom: 22px;
  align-items: flex-start;
}
.confirm-cover-wrap {
  flex-shrink: 0;
  width: 80px;
  height: 120px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--border);
  position: relative;
}
.confirm-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cover-ph {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: var(--border);
}
.confirm-meta { flex: 1; }
.confirm-title { font-size: 1rem; font-weight: 700; line-height: 1.45; margin-bottom: 6px; }
.confirm-author { font-size: 0.85rem; color: var(--text-light); }

.confirm-btns { display: flex; gap: 10px; }
.btn-primary {
  flex: 1;
  padding: 13px;
  background: var(--main);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:active { background: var(--main-dark); }
.btn-ghost {
  flex: 1;
  padding: 13px;
  background: none;
  color: var(--text-light);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}

/* ── Detail ── */
.modal-detail-content { text-align: center; }
.detail-cover-wrap {
  width: 110px;
  height: 165px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
  margin: 0 auto 16px;
}
.detail-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.detail-cover-ph { font-size: 3rem; }

#modal-detail h3 { font-size: 1.1rem; line-height: 1.4; margin-bottom: 8px; }
.detail-author { color: var(--text-light); font-size: 0.9rem; margin-bottom: 4px; }
.detail-isbn { font-size: 0.72rem; color: var(--text-light); margin-bottom: 22px; }

.btn-danger {
  display: block;
  width: 100%;
  padding: 12px;
  background: #ef5350;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
}
.btn-danger:active { background: #c62828; }

/* ── Loading ── */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.75);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading.hidden { display: none; }
.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--main);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #333;
  color: #fff;
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
