:root {
  --bg: #f2efe9;
  --card: #f2efe9;
  --text: #1a1a1a;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --border: #e5e7eb;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

header {
  background: #f2efe9;
  padding: 0.5rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: 'Playfair Display', Georgia, serif;
  letter-spacing: 0.01em;
}

.header-subtitle {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
  font-family: 'Playfair Display', Georgia, serif;
  font-style: italic;
  margin-top: 0.1rem;
  letter-spacing: 0.02em;
}

header nav a {
  margin-left: 1.5rem;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
}

header nav a:hover,
header nav a.active {
  color: var(--accent);
}

main {
  margin: 1rem auto;
  padding: 0 1.5rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.5rem;
}

.tabs button {
  padding: 0.6rem 1.2rem;
  background: none;
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

thead th {
  background: #f2efe9;
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

thead th:hover {
  color: var(--accent);
}

thead th .sort-arrow {
  margin-left: 0.3rem;
  font-size: 0.7rem;
}

tbody td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

tbody tr:hover {
  background: #f9fafb;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Clickable book rows */
tr.book-row {
  cursor: pointer;
  transition: background 0.1s;
}

tr.book-row:hover {
  background: var(--accent-light) !important;
}

tr.book-row.expanded {
  background: var(--accent-light);
  font-weight: 600;
}

/* Detail expand row */
tr.detail-row > td {
  padding: 0 !important;
  border-bottom: 1px solid var(--border);
}

.detail-panel {
  background: #f8fafc;
  padding: 1rem 1.5rem;
  border-top: 2px solid var(--accent);
}

.detail-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.detail-author {
  font-weight: 400;
  color: var(--muted);
}

table.detail-scores {
  width: auto;
  min-width: 280px;
  box-shadow: none;
  border: 1px solid var(--border);
}

table.detail-scores thead th {
  font-size: 0.75rem;
  padding: 0.4rem 0.75rem;
  cursor: default;
}

table.detail-scores tbody td {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

/* Cards & Charts */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
  gap: 1.5rem;
}

.chart-container {
  position: relative;
  height: 350px;
}

/* Forms (admin) */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
  color: var(--muted);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

button.btn {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

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

button.btn-primary:hover {
  background: #1d4ed8;
}

button.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.score-table input {
  width: 70px;
  padding: 0.3rem 0.5rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.score-table input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Password overlay */
.password-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.password-box {
  background: var(--card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  width: 340px;
}

.password-box h2 {
  margin-bottom: 1rem;
}

.password-box input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* Member move link */
.member-item .member-move-link {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.member-item:hover .member-move-link {
  opacity: 1;
}

.member-item .member-move-link:hover {
  text-decoration: underline;
  color: var(--text);
}

/* Stats boxes */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.stat-box .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-box .stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* Search */
.search-bar {
  margin-bottom: 1rem;
}

.search-bar input {
  width: 100%;
  max-width: 400px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

/* Gallery */
.gallery-filter-bar {
  margin-bottom: 0.75rem;
}

.gallery-filter-toggle {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}

.gallery-filter-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}

.gallery-controls {
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.gallery-controls {
  flex-wrap: wrap;
  align-items: center;
}

.gallery-checkbox {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.gallery-checkbox input {
  cursor: pointer;
}

.gallery-controls select {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--card);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 3px;
}

.gallery-tile {
  position: relative;
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0.9rem;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.15s, z-index 0s;
}

.gallery-tile:hover {
  transform: scale(1.06);
  z-index: 2;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}

.gallery-tile .tile-score {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  color: rgba(255,255,255,0.95);
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.gallery-tile .tile-score-quality {
  font-size: 1.1rem;
  font-weight: 800;
  color: rgba(255,255,255,0.7);
}

.gallery-tile .tile-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(255,255,255,0.95);
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
  margin-top: 0.25rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.gallery-tile .tile-author {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.75);
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
  margin-top: 0.15rem;
}

.gallery-tile .tile-dots {
  display: flex;
  gap: 3px;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.gallery-tile .tile-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.4);
}

/* Tile info button */
.tile-icon-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.3);
  color: rgba(255,255,255,0.9);
  font-size: 0.75rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 3;
  padding: 0;
  line-height: 1;
}

.gallery-tile:hover .tile-icon-btn {
  opacity: 1;
}

.tile-icon-btn:hover {
  background: rgba(0,0,0,0.6);
  border-color: rgba(255,255,255,0.9);
}

/* Book info popup */
.info-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.info-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: #f1f5f9;
  color: #475569;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 500;
}

.book-info-body {
  margin-top: 1rem;
}

.info-synopsis {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text);
  margin-bottom: 1rem;
}

.info-subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.info-year {
  font-size: 0.8rem;
  color: var(--muted);
}

.detail-meta-row {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.1rem;
  line-height: 1.3;
}

.detail-meta-row strong {
  color: var(--text);
}

.detail-meta-row:first-child {
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
}

.detail-meta-row--year {
  margin-bottom: 0.6rem;
}

.detail-synopsis {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.detail-synopsis-text {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text);
  margin: 0;
}

.info-loading {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

.info-empty {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}


/* Gallery detail overlay */
.gallery-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.15s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.gallery-detail {
  background: var(--card);
  border-radius: 12px;
  padding: 2rem;
  max-width: 480px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.gallery-detail .detail-header {
  display: flex;
  gap: 1.2rem;
  margin-bottom: 1.2rem;
}

.gallery-detail .detail-cover {
  width: 90px;
  height: auto;
  max-height: 140px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.gallery-detail .detail-header-text {
  min-width: 0;
}

.gallery-detail h2 {
  font-size: 1.2rem;
  margin-bottom: 0.2rem;
}

.gallery-detail .detail-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.gallery-detail .score-bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

.gallery-detail .score-bar-name {
  width: 80px;
  text-align: right;
  flex-shrink: 0;
}

.gallery-detail .score-bar-track {
  flex: 1;
  height: 20px;
  background: #f1f5f9;
  border-radius: 4px;
  overflow: hidden;
}

.gallery-detail .score-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.gallery-detail .score-bar-val {
  width: 30px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 768px) {
  header { flex-direction: column; gap: 0.5rem; }
  header nav a { margin-left: 0; margin-right: 1rem; }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-container { height: 280px; }
  .tabs { flex-wrap: wrap; }
}
