/* ==========================================================================
   Shiori — Minimal Personal Book Library Stylesheet
   Mobile-portrait-first, White base + Dark mode
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --bg-subtle: #f6f6f5;
  --bg-chip: #f2f2f0;
  --text: #18181b;
  --text-secondary: #52525b;
  --text-muted: #8a8a93;
  --border: #e6e6e4;
  --border-strong: #d4d4d1;
  --accent: #18181b;
  --accent-contrast: #ffffff;
  --bookmark: #c94a38;
  --bookmark-soft: rgba(201, 74, 56, 0.1);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-cover: 0 4px 12px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-sheet: 0 -8px 30px rgba(0, 0, 0, 0.12);
  --backdrop: rgba(15, 15, 18, 0.45);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --header-h: 54px;
  --nav-h: 62px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", "Georgia", serif;
}

[data-theme="dark"] {
  --bg: #101012;
  --bg-elevated: #18181b;
  --bg-subtle: #1e1e22;
  --bg-chip: #26262b;
  --text: #f4f4f5;
  --text-secondary: #b4b4bd;
  --text-muted: #7c7c87;
  --border: #2a2a30;
  --border-strong: #3c3c45;
  --accent: #f4f4f5;
  --accent-contrast: #101012;
  --bookmark: #e36552;
  --bookmark-soft: rgba(227, 101, 82, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-cover: 0 6px 16px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-sheet: 0 -8px 36px rgba(0, 0, 0, 0.6);
  --backdrop: rgba(0, 0, 0, 0.68);
}

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

html {
  font-size: 16px;
  color-scheme: light;
}

[data-theme="dark"] html,
html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   App Shell & Header
   ========================================================================== */

.app-shell {
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  height: var(--header-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  width: 21px;
  height: 21px;
  color: var(--bookmark);
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

/* Theme toggle icon visibility */
.icon-sun {
  display: none;
}
.icon-moon {
  display: block;
}
[data-theme="dark"] .icon-sun {
  display: block;
}
[data-theme="dark"] .icon-moon {
  display: none;
}

.btn-add-header {
  height: 34px;
  padding: 0 13px 0 10px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-contrast);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.84rem;
  font-weight: 600;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn-add-header:active {
  transform: scale(0.97);
}

.btn-add-header svg {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   Main Content & Views
   ========================================================================== */

.app-main {
  flex: 1;
  padding: 12px 16px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 24px);
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.18s ease;
}

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

/* ==========================================================================
   Bookshelf: Tabs, Search & Filters
   ========================================================================== */

.tabs-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 10px;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
}

.tabs-scroll::-webkit-scrollbar {
  display: none;
}

.tab-pill {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 0.83rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.tab-pill.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 600;
}

.tab-count {
  font-size: 0.75rem;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}

.search-bar-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

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

.search-icon {
  position: absolute;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 32px 0 34px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.search-input:focus {
  border-color: var(--text-secondary);
  background: var(--bg);
}

.search-clear {
  position: absolute;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filter-toggle-btn {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 0.83rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.filter-toggle-btn svg {
  width: 16px;
  height: 16px;
}

.filter-toggle-btn[aria-expanded="true"],
.filter-toggle-btn.has-active {
  border-color: var(--accent);
  color: var(--text);
}

.filter-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--bookmark);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Filter Panel */
.filter-panel {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.filter-label-inline {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toggle-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-chip span {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.toggle-chip input:checked + span {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 600;
}

.choice-chip {
  height: 30px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.choice-chip.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 600;
}

.filter-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.select-compact {
  height: 30px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-size: 0.8rem;
  outline: none;
}

.text-btn {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.text-btn-sm {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--bookmark);
}

.active-filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  background: var(--bg-chip);
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.active-filter-chip button {
  font-size: 0.95rem;
  line-height: 1;
  color: var(--text-muted);
}

.shelf-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Bookshelf Grid & Book Cards
   ========================================================================== */

.book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px 11px;
}

@media (min-width: 520px) {
  .book-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px 14px;
  }
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  min-width: 0;
  text-align: left;
  transition: transform 0.15s ease;
}

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

.book-cover-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.42;
  border-radius: 5px 7px 7px 5px;
  overflow: hidden;
  background: var(--bg-subtle);
  box-shadow: var(--shadow-cover);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

/* Subtle book spine sheen */
.book-cover-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.12) 0%, rgba(255, 255, 255, 0.08) 5%, transparent 11%);
  pointer-events: none;
}

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

/* Generated Typographic Book Cover */
.cover-fallback {
  width: 100%;
  height: 100%;
  padding: 12px 10px 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}

.cover-fallback-top {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cover-fallback-title {
  font-family: var(--font-serif);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.32;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.cover-fallback-author {
  font-size: 0.65rem;
  opacity: 0.78;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cover-fallback-pub {
  font-size: 0.58rem;
  letter-spacing: 0.05em;
  opacity: 0.58;
  text-transform: uppercase;
}

/* Subtle visual Obi band when hasObi is true */
.cover-obi-band {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22%;
  min-height: 20px;
  background: rgba(255, 255, 255, 0.9);
  color: #18181b;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  z-index: 2;
}

[data-theme="dark"] .cover-obi-band {
  background: rgba(244, 244, 245, 0.9);
  color: #101012;
}

/* Badges on Cover */
.cover-fav-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--bookmark);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16);
  z-index: 3;
}

.cover-fav-badge svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.cover-score-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  height: 19px;
  padding: 0 5px;
  border-radius: 4px;
  background: rgba(16, 16, 18, 0.78);
  color: #ffffff;
  font-size: 0.64rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  z-index: 3;
}

.book-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.book-card-title {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card-author {
  font-size: 0.69rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 2px;
}

.mini-badge {
  font-size: 0.6rem;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
  background: var(--bg-chip);
  color: var(--text-secondary);
}

.mini-badge-accent {
  background: var(--bookmark-soft);
  color: var(--bookmark);
  font-weight: 600;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 20px;
}

.empty-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  color: var(--text-muted);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 0.95rem;
  font-weight: 600;
}

.empty-desc {
  margin: 0 0 16px;
  font-size: 0.83rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Stats / Review View
   ========================================================================== */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.segmented-control {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px;
}

.seg-btn {
  height: 28px;
  padding: 0 13px;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

.year-selector-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 14px;
}

.icon-btn-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.icon-btn-sm svg {
  width: 16px;
  height: 16px;
}

.year-label {
  font-size: 0.98rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: center;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.kpi-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 1.08rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-unit {
  font-size: 0.66rem;
  color: var(--text-muted);
}

.card-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0 0 8px;
  font-size: 0.92rem;
  font-weight: 700;
}

.card-desc {
  margin: 0 0 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.chart-header .card-title {
  margin: 0;
}

.metric-pills {
  display: inline-flex;
  gap: 4px;
}

.metric-pill {
  height: 26px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}

.metric-pill.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 600;
}

.chart-container {
  width: 100%;
  overflow-x: auto;
}

.chart-svg {
  width: 100%;
  height: 185px;
  display: block;
}

.chart-bar {
  fill: var(--accent);
  opacity: 0.82;
  cursor: pointer;
  transition: opacity 0.15s ease, fill 0.15s ease;
}

.chart-bar:hover,
.chart-bar.selected {
  fill: var(--bookmark);
  opacity: 1;
}

.chart-gridline {
  stroke: var(--border);
  stroke-dasharray: 2 3;
}

.chart-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.chart-value-label {
  fill: var(--text-secondary);
  font-size: 9.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart-detail {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Breakdown Table */
.table-wrap {
  overflow-x: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.stats-table th,
.stats-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.stats-table th {
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stats-table .num {
  text-align: right;
}

.stats-table tr:last-child td {
  border-bottom: none;
}

.stats-table tr.is-zero td {
  color: var(--text-muted);
}

.summary-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
}

.summary-row span:first-child {
  color: var(--text-secondary);
}

.summary-row strong {
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Data Management View
   ========================================================================== */

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.83rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.file-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.file-dropzone:hover {
  border-color: var(--accent);
  color: var(--text);
}

.file-dropzone svg {
  width: 22px;
  height: 22px;
}

.status-msg {
  margin: 10px 0 0;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  background: var(--bg-subtle);
  color: var(--text);
}

.status-msg.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.data-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ==========================================================================
   Buttons & Form Controls
   ========================================================================== */

.btn-primary,
.btn-secondary,
.btn-danger-outline {
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary svg,
.btn-secondary svg {
  width: 16px;
  height: 16px;
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
}

.btn-danger-outline:hover {
  background: var(--danger-soft);
}

.btn-full {
  width: 100%;
}

/* ==========================================================================
   Bottom Navigation
   ========================================================================== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  z-index: 30;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  transition: color 0.15s ease;
}

.nav-item svg {
  width: 20px;
  height: 20px;
}

.nav-item.active {
  color: var(--text);
  font-weight: 700;
}

/* ==========================================================================
   Modals / Bottom Sheets
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--backdrop);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-sheet-tall {
  max-height: 93dvh;
}

@media (min-width: 600px) {
  .modal-sheet {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
  }
}

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

.modal-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
}

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

.modal-footer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.detail-footer {
  justify-content: space-between;
}

/* ==========================================================================
   Book Detail Sheet Content
   ========================================================================== */

.detail-hero {
  display: flex;
  gap: 14px;
  margin-bottom: 16px;
}

.detail-cover-wrap {
  width: 102px;
  flex-shrink: 0;
}

.detail-hero-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-book-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
}

.detail-book-author {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.detail-book-pub {
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.detail-quick-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.status-pill-select {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-subtle);
  font-size: 0.78rem;
  font-weight: 600;
}

.fav-toggle-btn {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.fav-toggle-btn svg {
  width: 14px;
  height: 14px;
}

.fav-toggle-btn.active {
  border-color: var(--bookmark);
  background: var(--bookmark-soft);
  color: var(--bookmark);
  font-weight: 600;
}

.fav-toggle-btn.active svg {
  fill: currentColor;
}

.detail-section {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.detail-section-title {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 8px;
  letter-spacing: 0.03em;
}

.detail-kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.detail-kv {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.detail-kv-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.detail-kv-value {
  font-size: 0.84rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.detail-memo {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.65;
  white-space: pre-wrap;
  color: var(--text);
}

.read-date-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.read-date-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.read-date-pill small {
  color: var(--text-muted);
  font-size: 0.68rem;
}

/* ==========================================================================
   Form Layout
   ========================================================================== */

.form-section {
  border: none;
  padding: 0;
  margin: 0 0 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-section:last-child {
  margin-bottom: 4px;
}

.form-legend {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  padding-bottom: 6px;
  margin-bottom: 4px;
  width: 100%;
  border-bottom: 1px solid var(--border);
}

.cover-preview-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.form-cover-preview {
  width: 68px;
  flex-shrink: 0;
}

.cover-url-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field-grid-2-align {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: end;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

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

.req {
  color: var(--bookmark);
}

.field-hint {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.input:focus {
  border-color: var(--text);
}

.textarea {
  height: auto;
  padding: 10px 11px;
  resize: vertical;
  line-height: 1.55;
}

/* Switch */
.switch-row {
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 42px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  position: relative;
  transition: background-color 0.2s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.switch-row input:checked + .switch-track {
  background: var(--bookmark);
}

.switch-row input:checked + .switch-track::after {
  transform: translateX(18px);
}

.switch-label {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 28px;
}

/* Rating */
.rating-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rating-display {
  font-size: 0.84rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--bookmark);
}

.rating-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-input {
  flex: 1;
  accent-color: var(--bookmark);
  height: 24px;
}

.input-score {
  width: 72px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Read Dates List */
.read-dates-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.read-date-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.read-date-index {
  font-size: 0.74rem;
  color: var(--text-muted);
  min-width: 38px;
  font-variant-numeric: tabular-nums;
}

.read-date-remove {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1.05rem;
  flex-shrink: 0;
}

.read-date-remove:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* Tags in Form */
.isbn-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.isbn-input-row .input {
  flex: 1;
  min-width: 0;
}

.isbn-fetch-btn {
  flex-shrink: 0;
  padding: 0 13px;
  white-space: nowrap;
}

.isbn-fetch-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.isbn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid color-mix(in srgb, var(--text) 25%, transparent);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: isbnSpin 0.7s linear infinite;
}

@keyframes isbnSpin {
  to { transform: rotate(360deg); }
}

.isbn-status {
  margin: 4px 0 0;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  line-height: 1.45;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.isbn-status.is-success {
  color: var(--text);
  border-color: var(--border-strong);
}

.isbn-status.is-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

.tag-input-row {
  display: flex;
  gap: 6px;
}

.tag-input-row .btn-secondary {
  flex-shrink: 0;
}

.selected-tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.tag-chip-removable {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.78rem;
  font-weight: 500;
}

.tag-chip-removable button {
  color: inherit;
  opacity: 0.8;
  font-size: 0.95rem;
  line-height: 1;
}

.suggested-tags-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.collector-checks {
  margin-bottom: 2px;
}

/* ==========================================================================
   Toast
   ========================================================================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 14px);
  transform: translateX(-50%);
  z-index: 80;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  max-width: calc(100vw - 32px);
  text-align: center;
  animation: fadeIn 0.16s ease;
}
