:root {
  --bg: #ffffff;
  --bg-soft: #faf8f3;
  --bg-elevated: #ffffff;
  --ink: #14110e;
  --ink-soft: #4a4640;
  --ink-muted: #8a857c;
  --rule: #e8e3d8;
  --rule-strong: #d4cdbb;
  --accent: #7a1f1f;
  --accent-soft: #f3e6e6;
  --gold: #b88a3a;
  --bar-bg: #14110e;
  --bar-ink: rgba(255,255,255,0.92);
  --bar-ink-muted: rgba(255,255,255,0.65);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(0, 0, 0, 0.10);
  --shadow-card-hover: 0 4px 6px rgba(0, 0, 0, 0.05), 0 20px 44px rgba(0, 0, 0, 0.16);
  --shadow-modal: 0 12px 48px rgba(0, 0, 0, 0.24);
  --serif: 'Crimson Pro', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 4px;
  --radius-lg: 8px;
  --max-width: 1240px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.site-bar {
  background: var(--bar-bg);
  color: var(--bar-ink);
}
.site-bar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.site-bar-brand {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 18px;
  letter-spacing: 0.01em;
  color: var(--bar-ink);
}
.site-bar-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Hero ---------- */
.hero {
  position: relative;
  background-color: #1c1814;
  background-size: cover;
  background-position: center;
  color: #fff;
  isolation: isolate;
  overflow: hidden;
}
.hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.7) 100%);
  z-index: 1;
}
.hero-inner {
  position: relative;
  z-index: 2;
  max-width: 820px;
  margin: 0 auto;
  padding: 100px 32px 110px;
  text-align: center;
}
.hero-kicker {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.78);
  margin: 0 0 18px;
}
.hero-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(40px, 6vw, 64px);
  letter-spacing: -0.015em;
  line-height: 1.05;
  margin: 0 0 18px;
}
.hero-intro {
  font-family: var(--serif);
  font-size: clamp(17px, 1.6vw, 20px);
  font-style: italic;
  font-weight: 400;
  color: rgba(255,255,255,0.85);
  margin: 0;
  line-height: 1.5;
  max-width: 640px;
  margin-inline: auto;
}

/* ---------- Tabs ---------- */
.tabs {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tabs-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-inner::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: none;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-muted);
  padding: 18px 18px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 120ms ease, border-color 120ms ease;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.tab:hover { color: var(--ink); }
.tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* ---------- Toolbar ---------- */
.toolbar {
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.toolbar[hidden] { display: none; }
.toolbar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px 32px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
#search {
  flex: 1 1 240px;
  min-width: 180px;
  font-family: var(--sans);
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
#search:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.toolbar-inner select {
  font-family: var(--sans);
  font-size: 13px;
  padding: 8px 28px 8px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a857c' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.toolbar-inner select:hover { border-color: var(--ink-muted); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
  line-height: 1;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #000; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--rule-strong); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--ink); }
.btn-ghost-light {
  background: transparent;
  color: var(--bar-ink);
  border-color: rgba(255,255,255,0.25);
}
.btn-ghost-light:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.4); }
.btn-small { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-danger {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent-soft);
}
.btn-danger:hover { background: var(--accent-soft); }
.btn-linklike {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}
.btn-linklike:hover { color: var(--ink); }

/* ---------- Selection bar ---------- */
.selection-bar {
  position: sticky;
  top: 53px;
  z-index: 9;
  background: var(--ink);
  color: #fff;
  border-bottom: 1px solid #000;
}
.selection-bar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 32px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.selection-bar-inner strong { font-weight: 600; }
.selection-bar .btn-ghost {
  color: rgba(255,255,255,0.85);
  border-color: rgba(255,255,255,0.25);
  background: transparent;
}
.selection-bar .btn-ghost:hover:not(:disabled) {
  background: rgba(255,255,255,0.1);
  color: #fff;
}
.selection-bar .btn-ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.selection-bar .btn-danger {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  margin-left: auto;
}
.selection-bar .btn-danger:hover:not(:disabled) { background: #9a2828; }
.selection-bar .btn-danger:disabled {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.5);
  cursor: not-allowed;
}

/* Selected-state styling */
.book-row.is-selected { background: var(--accent-soft); }
.book-row.is-selected:hover { background: var(--accent-soft); }
.book-row.is-selected .col-number {
  color: var(--accent);
  font-weight: 600;
}
.book-row.is-selected .col-number::before {
  content: '✓ ';
}
.cover-tile.is-selected .cover-tile-img {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.cover-tile.is-selected .cover-tile-img::after {
  content: '✓';
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  z-index: 2;
}

@media (max-width: 640px) {
  .selection-bar-inner { padding: 10px 20px; flex-wrap: wrap; }
}

/* ---------- Content ---------- */
.content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 36px 32px 80px;
}
.state-message {
  text-align: center;
  color: var(--ink-muted);
  font-style: italic;
  padding: 80px 16px;
  font-family: var(--serif);
  font-size: 18px;
}

/* ---------- Full List table ---------- */
.book-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  font-family: var(--sans);
}
.book-table thead th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 10px 14px;
  border-bottom: 2px solid var(--ink);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.book-table thead th:hover { color: var(--ink); }
.book-table thead th .sort-arrow { opacity: 0.35; margin-left: 4px; font-size: 10px; }
.book-table thead th.sort-asc .sort-arrow,
.book-table thead th.sort-desc .sort-arrow { opacity: 1; }
.book-table tbody td {
  padding: 14px;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}
.book-table tbody tr {
  cursor: pointer;
  transition: background 120ms ease;
}
.book-table tbody tr:hover { background: var(--bg-soft); }
.book-table .col-number {
  width: 56px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink-muted);
  font-weight: 500;
}
.book-table .col-author {
  width: 24%;
  font-family: var(--sans);
  color: var(--ink-soft);
}
.book-table .col-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.book-table .col-title .book-subtitle {
  display: block;
  font-size: 14px;
  font-style: italic;
  color: var(--ink-muted);
  font-weight: 400;
  margin-top: 2px;
}
.book-table .col-year {
  width: 100px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.book-table .col-tags {
  color: var(--ink-muted);
  font-size: 13px;
  max-width: 220px;
}
.book-table .col-status { width: 140px; }
.book-table .col-rating {
  width: 100px;
  color: var(--gold);
  letter-spacing: 1px;
  white-space: nowrap;
  font-size: 13px;
}
.status-pill {
  display: inline-block;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 99px;
}
.status-pill.status-reading { background: rgba(184, 138, 58, 0.12); color: #8a6620; }
.status-pill.status-finished { background: rgba(20, 17, 14, 0.85); color: #fff; }
.status-pill.status-want_to_read { background: rgba(122, 31, 31, 0.10); color: var(--accent); }

@media (max-width: 900px) {
  .book-table .col-tags { display: none; }
}
@media (max-width: 720px) {
  .book-table .col-author { font-size: 13px; }
  .book-table .col-title { font-size: 16px; }
  .book-table .col-rating { display: none; }
  .book-table .col-year { width: 70px; }
  .book-table tbody td, .book-table thead th { padding: 12px 10px; }
}

/* ---------- Cover grid (Completed, Currently Reading, Want to Read) ---------- */
.section-heading {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 500;
  margin: 0 0 8px;
  letter-spacing: -0.005em;
}
.section-sub {
  color: var(--ink-muted);
  margin: 0 0 28px;
  font-size: 14px;
}
.cover-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 36px 20px;
}
@media (max-width: 1280px) { .cover-grid { grid-template-columns: repeat(5, 1fr); gap: 32px 18px; } }
@media (max-width: 1024px) { .cover-grid { grid-template-columns: repeat(4, 1fr); gap: 28px 16px; } }
@media (max-width: 720px) { .cover-grid { grid-template-columns: repeat(3, 1fr); gap: 24px 14px; } }
@media (max-width: 460px) { .cover-grid { grid-template-columns: repeat(2, 1fr); gap: 22px 12px; } }

.cover-tile {
  background: transparent;
  border: none;
  padding: 0;
  text-align: center;
  cursor: pointer;
  font: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cover-tile-img {
  position: relative;
  aspect-ratio: 2 / 3;
  background: linear-gradient(135deg, #efe9da, #d9d0b8);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 3px 24px rgba(0,0,0,0.10);
  transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 280ms ease;
}
.cover-tile:hover .cover-tile-img {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}
.cover-tile-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cover-tile-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  font-family: var(--serif);
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.25;
}
.cover-tile-progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(255,255,255,0.4);
}
.cover-tile-progress-fill { height: 100%; background: var(--gold); }
.cover-tile-title {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.3;
  font-weight: 500;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  padding: 0 2px;
}
.cover-tile-author {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-muted);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal.modal-anchored {
  position: absolute;
  inset: auto;
  top: 0;
  left: 0;
  right: 0;
  height: auto;
  align-items: flex-start;
  padding-top: 32px;
  padding-bottom: 32px;
}
.modal.modal-anchored .modal-panel { max-height: 700px; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 17, 14, 0.55);
  backdrop-filter: blur(3px);
  animation: fade-in 160ms ease;
}
.modal-panel {
  position: relative;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  padding: 32px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  animation: panel-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-panel-small { max-width: 400px; }
.modal-panel-wide { max-width: 760px; }
.modal-panel h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 26px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.modal-subtitle {
  color: var(--ink-muted);
  margin: 0 0 24px;
  font-size: 14px;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: transparent;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--rule); color: var(--ink); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Forms ---------- */
form label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 14px;
}
form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="number"],
form input[type="date"],
form input[type="search"],
form input[type="url"],
form select,
form textarea {
  width: 100%;
  margin-top: 6px;
  font-family: var(--sans);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
form textarea { resize: vertical; min-height: 80px; font-family: var(--serif); font-size: 15px; line-height: 1.5; }
form input:focus, form select:focus, form textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.form-error {
  color: var(--accent);
  font-size: 13px;
  margin: 8px 0 12px;
  padding: 8px 12px;
  background: var(--accent-soft);
  border-radius: var(--radius);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- Add modal: search results ---------- */
.search-row { display: flex; gap: 8px; margin-bottom: 16px; }
.search-row input { flex: 1; padding: 10px 14px; font-size: 14px; border: 1px solid var(--rule-strong); border-radius: var(--radius); }
.search-row input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(0,0,0,0.06); }
.ol-results { display: flex; flex-direction: column; gap: 6px; }
.ol-result {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  align-items: flex-start;
  background: transparent;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
}
.ol-result:hover { background: var(--bg-soft); border-color: var(--rule); }
.ol-result-cover { width: 48px; height: 72px; flex-shrink: 0; background: var(--rule); border-radius: 2px; overflow: hidden; }
.ol-result-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ol-result-info { flex: 1; min-width: 0; }
.ol-result-title { font-family: var(--serif); font-size: 16px; font-weight: 500; line-height: 1.2; margin-bottom: 2px; }
.ol-result-meta { font-size: 12px; color: var(--ink-muted); }

/* ---------- Book detail modal ---------- */
.book-detail {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 32px;
}
@media (max-width: 600px) {
  .book-detail { grid-template-columns: 1fr; }
  .book-detail .cover-col { max-width: 160px; }
}
.book-detail .cover-col img {
  width: 100%;
  border-radius: 3px;
  box-shadow: var(--shadow-card);
  display: block;
}
.book-detail .cover-col .cover-tile-placeholder {
  position: relative;
  aspect-ratio: 2/3;
  background: linear-gradient(135deg, #efe9da, #d9d0b8);
  border-radius: 3px;
}
.book-detail h2 {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.1;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.book-detail .book-detail-author {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: var(--ink-soft);
  margin-bottom: 16px;
}
.book-detail .book-detail-meta {
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 16px;
  line-height: 1.7;
}
.book-detail .book-detail-meta strong { color: var(--ink-soft); font-weight: 500; }
.book-detail .book-detail-notes {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  border-left: 2px solid var(--rule-strong);
  padding-left: 16px;
  margin: 16px 0;
}
.book-detail .book-detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}
.book-detail .tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 14px; }
.tag {
  display: inline-block;
  padding: 3px 10px;
  background: var(--rule);
  color: var(--ink-soft);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}
.tag.tag-genre { background: var(--accent-soft); color: var(--accent); }

/* ---------- Footer ---------- */
.site-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 32px 48px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 12px;
  border-top: 1px solid var(--rule);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .site-bar-inner { padding: 12px 20px; }
  .hero-inner { padding: 72px 24px 80px; }
  .tabs-inner { padding: 0 20px; }
  .tab { padding: 16px 12px 14px; font-size: 13px; }
  .toolbar-inner { padding: 14px 20px; }
  .content { padding: 28px 20px 64px; }
  .modal-panel { padding: 24px 20px; }
}
