/* === YondApp — Cafe Bookshelf Theme === */

:root {
  --bg: #f5f0e8;
  --bg-card: #fffdf8;
  --bg-header: #3d2b1f;
  --bg-shelf: #5c3d2e;
  --text: #3a2e25;
  --text-secondary: #8a7968;
  --text-on-header: #f5efe6;
  --accent: #6b4226;
  --accent-light: #f0e6d8;
  --accent-hover: #8b5a34;
  --border: #d8cbb8;
  --star: #c8963e;
  --completed: #5a7a3a;
  --completed-light: #e8f0d8;
  --audible-accent: #c05e20;
  --audible-light: #fce8d8;
  --shadow: 0 2px 8px rgba(60,40,20,0.08);
  --shadow-hover: 0 6px 20px rgba(60,40,20,0.14);
  --radius: 6px;
  --font-body: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
  --font-title: 'M PLUS Rounded 1c', 'Noto Sans JP', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(200,180,150,0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(180,160,130,0.1) 0%, transparent 50%);
  min-height: 100vh;
}

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

.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem 2rem; }

/* === Header === */
header {
  background: var(--bg-header);
  background-image: linear-gradient(135deg, #3d2b1f 0%, #4a3428 50%, #3d2b1f 100%);
  color: var(--text-on-header);
  padding: 1.25rem 1.5rem;
  border-radius: 0 0 var(--radius) var(--radius);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  position: relative;
  flex-wrap: wrap;
  box-shadow: 0 4px 16px rgba(40,20,10,0.18);
  border-bottom: 3px solid #2a1a10;
}

.header-title h1 {
  font-family: var(--font-title);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.header-library-name {
  font-size: 0.8rem;
  font-weight: 400;
  margin-left: 0.75rem;
  opacity: 0.7;
}

.header-stats { display: flex; gap: 0.75rem; margin-left: auto; }
.header-stat {
  display: flex; flex-direction: column; align-items: center;
  text-decoration: none; color: var(--text-on-header);
  padding: 0.3rem 0.75rem; border-radius: var(--radius);
  transition: background 0.2s; cursor: pointer;
}
.header-stat:hover { background: rgba(255,255,255,0.1); text-decoration: none; }
.header-stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.header-stat-label { font-size: 0.65rem; opacity: 0.75; letter-spacing: 0.04em; }

/* === Hamburger === */
.hamburger-btn {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px; padding: 8px; margin-left: 0.5rem;
}
.hamburger-btn span {
  display: block; width: 22px; height: 2px;
  background: var(--text-on-header); border-radius: 2px;
}
.hamburger-menu {
  display: none; position: absolute; top: 100%; right: 1rem;
  background: var(--bg-card); color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover), 0 4px 16px rgba(0,0,0,0.12);
  padding: 1rem; z-index: 100; min-width: 240px;
  border: 1px solid var(--border);
}
.hamburger-menu.open { display: block; }
.menu-library-select { margin-bottom: 0.75rem; }
.menu-library-select label { font-size: 0.8rem; color: var(--text-secondary); }
.menu-select {
  width: 100%; padding: 0.4rem; border: 1px solid var(--border);
  border-radius: 4px; font-family: var(--font-body); font-size: 0.85rem;
  margin-top: 0.25rem; background: #fff;
}

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.5rem 1.25rem; border: none; border-radius: var(--radius);
  font-family: var(--font-body); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  width: 100%; background: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--accent-light); color: var(--accent); }
.btn-secondary:hover { background: #e4d6c4; }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Filter Bar === */
.filter-bar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 1rem; margin-top: 1rem;
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); flex-wrap: wrap;
  border: 1px solid var(--border);
}
.filter-group { display: flex; align-items: center; gap: 0.3rem; }
.filter-group label { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; }
.filter-input, .filter-select {
  padding: 0.3rem 0.5rem; border: 1px solid var(--border);
  border-radius: 4px; font-family: var(--font-body); font-size: 0.8rem;
  background: #fff;
}
.filter-input { width: 170px; }
.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--accent); }
.view-toggle { display: flex; gap: 2px; margin-left: auto; }
.view-btn {
  padding: 0.3rem 0.55rem; border: 1px solid var(--border); background: #fff;
  cursor: pointer; font-size: 0.95rem; line-height: 1;
  border-radius: 4px; color: var(--text-secondary); transition: background 0.15s;
}
.view-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* === Chart Section === */
.chart-section {
  margin-top: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}
.chart-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; cursor: pointer;
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
  user-select: none;
  transition: background 0.15s;
}
.chart-toggle:hover { background: #e4d6c4; }
.chart-toggle-title {
  font-size: 0.85rem; font-weight: 600; color: var(--accent);
}
.chart-toggle-arrow {
  font-size: 0.75rem; color: var(--text-secondary);
  transition: transform 0.2s;
}
.chart-section.open .chart-toggle-arrow { transform: rotate(180deg); }
.chart-body {
  display: none; padding: 1rem;
}
.chart-section.open .chart-body { display: block; }
.chart-genre-filter {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.75rem; padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.chart-genre-filter label { font-size: 0.8rem; font-weight: 600; color: var(--accent); }
.chart-genre-filter .filter-select { min-width: 200px; }
.chart-tabs {
  display: flex; gap: 0; margin-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}
.chart-tab {
  padding: 0.4rem 1.2rem;
  background: none; border: none;
  font-family: var(--font-body); font-size: 0.8rem; font-weight: 600;
  color: var(--text-secondary); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.chart-tab:hover { color: var(--accent); }
.chart-tab.active {
  color: var(--accent); border-bottom-color: var(--accent);
}
.chart-canvas-wrap {
  position: relative; height: 250px;
}
#chartGenreWrap {
  height: 400px;
}

/* === Loading === */
#loading { text-align: center; padding: 3rem 1rem; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadingMessage { color: var(--text-secondary); font-size: 0.85rem; }

/* === Error / Empty === */
.error {
  padding: 1rem; background: #fae8e8; color: #8b3030;
  border-radius: var(--radius); margin-top: 1rem;
  border: 1px solid #e8c8c8;
}
.empty-state {
  text-align: center; padding: 4rem 1rem; color: var(--text-secondary);
}
.empty-state p { margin-bottom: 0.5rem; }

/* === Card View (Bookshelf) === */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
  margin-top: 1rem;
}
.book-card {
  display: flex; gap: 0.75rem; padding: 0.75rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform 0.15s, box-shadow 0.15s;
  text-decoration: none; color: inherit;
  position: relative;
}
.book-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  text-decoration: none;
}
.book-cover {
  width: 60px; height: 85px; object-fit: cover;
  border-radius: 3px; background: var(--accent-light);
  flex-shrink: 0;
  box-shadow: 2px 2px 6px rgba(60,40,20,0.15);
}
.book-card-body { flex: 1; min-width: 0; }
.book-card-title {
  font-family: var(--font-title);
  font-size: 0.85rem; font-weight: 600; line-height: 1.35;
  margin-bottom: 0.2rem;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
  color: var(--text);
}
.book-card-author {
  font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 0.3rem;
}
.book-card-meta {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  font-size: 0.7rem; color: var(--text-secondary);
}
.book-card-meta .stars { color: var(--star); letter-spacing: -1px; }
.book-card-genre {
  display: inline-block;
  font-size: 0.65rem; color: var(--text-secondary);
  background: var(--accent-light); padding: 0.1rem 0.4rem;
  border-radius: 3px; margin-bottom: 0.25rem;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.book-card-summary {
  font-size: 0.7rem; color: var(--text-secondary);
  line-height: 1.4; margin-top: 0.2rem;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}

/* === Badges === */
.badge-completed {
  display: inline-block; padding: 0.08rem 0.35rem;
  background: var(--completed); color: #fff;
  border-radius: 3px; font-size: 0.6rem; font-weight: 600;
  vertical-align: middle; letter-spacing: 0.04em;
}
.badge-source {
  display: inline-block; padding: 0.08rem 0.3rem;
  border-radius: 3px; font-size: 0.55rem; font-weight: 600;
  vertical-align: middle; letter-spacing: 0.03em;
}
.badge-setagaya { background: var(--accent-light); color: var(--accent); }
.badge-audible_jp { background: var(--audible-light); color: var(--audible-accent); }
.badge-favorite { color: #c45c6a; font-size: 0.75rem; }

.book-card.completed { border-left: 3px solid var(--completed); }
.book-card-clickable, .book-row-clickable { cursor: pointer; }
.book-row-clickable:hover td { background: #f5efe8 !important; }
.book-card.source-audible { border-left: 3px solid var(--audible-accent); }
.book-card.source-audible.completed { border-left: 3px solid var(--completed); }

/* === Table View === */
.book-table {
  width: 100%; border-collapse: collapse; margin-top: 1rem;
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  border: 1px solid var(--border);
}
.book-table th, .book-table td {
  padding: 0.45rem 0.65rem; text-align: left;
  border-bottom: 1px solid var(--border); font-size: 0.8rem;
}
.book-table th {
  background: var(--accent-light); font-weight: 600;
  font-size: 0.75rem; color: var(--accent);
  position: sticky; top: 0;
}
.book-table tr:last-child td { border-bottom: none; }
.book-table tr:hover td { background: #faf6f0; }
.book-table .stars { color: var(--star); white-space: nowrap; }
.book-table .col-title { min-width: 180px; }
.book-table .col-title a { font-weight: 500; }
.book-table .col-genre { max-width: 160px; font-size: 0.7rem; color: var(--text-secondary); }
.book-table .col-cover { width: 38px; }
.book-table .col-cover img {
  width: 34px; height: 48px; object-fit: cover;
  border-radius: 3px; vertical-align: middle;
  box-shadow: 1px 1px 4px rgba(60,40,20,0.12);
}
.row-completed td:first-child { border-left: 3px solid var(--completed); }

/* === Pagination === */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 1rem; padding: 1rem; margin-top: 0.75rem;
}
.pagination-info { font-size: 0.8rem; color: var(--text-secondary); }
.pagination-buttons { display: flex; align-items: center; gap: 0.5rem; }
.pagination-page { font-size: 0.85rem; font-weight: 600; min-width: 5rem; text-align: center; }

/* === Year group header === */
.year-group-header {
  grid-column: 1 / -1;
  padding: 0.6rem 0 0.2rem;
  font-family: var(--font-title);
  font-size: 1rem; font-weight: 700;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  margin-top: 0.4rem;
}

/* === Menu credential status === */
.menu-credential-status {
  font-size: 0.8rem; padding: 0.35rem 0.5rem;
  border-radius: 4px; margin-bottom: 0.5rem;
}
.menu-credential-status.configured { background: var(--completed-light); color: var(--completed); }
.menu-credential-status.not-configured { background: #fae8e8; color: #8b3030; }
.menu-btn { width: 100%; margin-bottom: 0.5rem; }
.menu-btn:last-child { margin-bottom: 0; }

/* === Modal === */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(30,20,10,0.5); z-index: 1000;
  align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(40,20,10,0.25);
  width: 100%; max-width: 420px; animation: modalIn 0.2s ease-out;
  border: 1px solid var(--border);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
  background: var(--accent-light);
}
.modal-header h2 { font-size: 1rem; font-weight: 700; color: var(--accent); }
.modal-close {
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  color: var(--text-secondary); padding: 0 0.25rem; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem; }
.modal-field { margin-bottom: 1rem; }
.modal-field label {
  display: block; font-size: 0.8rem; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 0.3rem;
}
.modal-input {
  width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--border);
  border-radius: 4px; font-family: var(--font-body); font-size: 0.9rem;
  background: #fff; transition: border-color 0.15s;
}
.modal-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(107,66,38,0.1);
}
.modal-status { min-height: 1.5rem; font-size: 0.8rem; margin-bottom: 0.75rem; padding: 0 0.25rem; }
.modal-status.success { color: var(--completed); }
.modal-status.error { color: #8b3030; }
.modal-status.loading { color: var(--text-secondary); }
.modal-actions { display: flex; gap: 0.75rem; }
.modal-actions .btn { flex: 1; }
.modal-note { margin-top: 1rem; font-size: 0.7rem; color: var(--text-secondary); text-align: center; }

/* === Book Detail Modal === */
.modal-book-detail { max-width: 560px; }
.book-detail-layout {
  display: flex; gap: 1.25rem; margin-bottom: 1.25rem;
}
.book-detail-cover {
  flex-shrink: 0;
}
.book-detail-cover img {
  width: 120px; height: 170px; object-fit: cover;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.book-detail-meta { flex: 1; min-width: 0; }
.book-detail-author { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 0.35rem; }
.book-detail-genre { font-size: 0.8rem; color: var(--accent); margin-bottom: 0.35rem; }
.book-detail-favorite { font-size: 0.85rem; color: #c45c6a; margin-bottom: 0.35rem; }
.book-detail-rating { font-size: 0.9rem; margin-bottom: 0.35rem; }
.book-detail-rating .stars { color: var(--star); }
.book-detail-review-headline { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.35rem; font-style: italic; }
.rating-link { color: inherit; text-decoration: none; cursor: pointer; }
.rating-link:hover { text-decoration: underline; color: var(--accent); }
.book-detail-dates { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.35rem; }
.book-detail-completed { color: var(--completed); font-weight: 600; margin-left: 0.5rem; }
.book-detail-comment { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.75rem; line-height: 1.5; }
.book-detail-summary-wrap h3 {
  font-size: 0.85rem; font-weight: 600; color: var(--accent);
  margin-bottom: 0.5rem; padding-top: 0.75rem; border-top: 1px solid var(--border);
}
.book-detail-summary {
  font-size: 0.85rem; line-height: 1.7; color: var(--text);
  white-space: pre-wrap; max-height: 200px; overflow-y: auto;
}

/* === Responsive === */
@media (max-width: 768px) {
  header { flex-wrap: wrap; padding: 1rem; gap: 0.75rem; }
  .header-stats { gap: 0.4rem; }
  .header-stat { padding: 0.2rem 0.4rem; }
  .header-stat-value { font-size: 1.1rem; }
  .filter-bar { flex-direction: column; align-items: stretch; gap: 0.4rem; }
  .filter-input { width: 100%; }
  .view-toggle { justify-content: flex-end; }
  .book-grid { grid-template-columns: 1fr; }
  .book-table { font-size: 0.75rem; }
  .book-table th, .book-table td { padding: 0.35rem 0.45rem; }
  .chart-canvas-wrap { height: 200px; }
  #chartGenreWrap { height: 350px; }
  .book-detail-layout { flex-direction: column; }
  .book-detail-cover img { width: 100px; height: 140px; }
}
