:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --bg-accent: #ebe3d3;
  --panel: rgba(255, 252, 246, 0.96);
  --panel-strong: #fffdf8;
  --text: #1f2937;
  --muted: #5f6b7a;
  --border: #d8cfbf;
  --border-strong: #c5b9a3;
  --link: #1d4ed8;
  --button: #254f78;
  --button-alt: #556271;
  --button-light: #78889a;
  --button-danger: #a53b30;
  --shadow: 0 10px 30px rgba(76, 57, 33, 0.08);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.72), transparent 30rem),
    linear-gradient(180deg, var(--bg-accent) 0, var(--bg) 14rem, #f8f5ee 100%);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5rem;
  line-height: 1.15;
}

p {
  margin: 0;
}

.container {
  width: min(1180px, calc(100vw - 2rem));
  margin: 0 auto;
}

.site-header {
  padding: 1.4rem 0 0.9rem;
}

.site-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
}

.site-header-copy {
  max-width: 42rem;
}

.eyebrow {
  margin-bottom: 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #7a6243;
}

.page-summary {
  max-width: 46rem;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0.55rem 0.95rem;
  border: 1px solid rgba(37, 79, 120, 0.16);
  border-radius: 999px;
  background: rgba(255, 252, 246, 0.82);
  color: var(--text);
  font-weight: 600;
}

.site-nav a[aria-current="page"] {
  background: #1f2937;
  border-color: #1f2937;
  color: #fff;
}

.page-content {
  padding-bottom: 2rem;
}

.page-shell {
  display: grid;
  gap: 1rem;
}

.page-lede {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.page-lede-copy {
  max-width: 42rem;
}

.page-lede-copy h2 {
  margin-bottom: 0.35rem;
}

.page-lede-aside,
.page-sidebar,
.page-stack {
  display: grid;
  gap: 1rem;
}

.page-stack > * {
  min-width: 0;
}

.page-lede-aside {
  width: min(100%, 20rem);
}

.page-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 19rem);
  gap: 1rem;
  align-items: start;
}

.page-main > * {
  min-width: 0;
}

.page-main-solo {
  grid-template-columns: minmax(0, 1fr);
}

.page-note-card {
  padding: 1rem;
  border: 1px solid rgba(216, 207, 191, 0.82);
  border-radius: 16px;
  background: rgba(249, 245, 236, 0.86);
}

.page-note-card h3 {
  margin-bottom: 0.3rem;
}

.page-note-list,
.detail-list {
  display: grid;
  gap: 0.65rem;
}

.page-note-list {
  padding-left: 1rem;
  margin: 0;
  color: var(--muted);
}

.detail-list div {
  display: grid;
  gap: 0.15rem;
}

.inline-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.panel {
  margin-bottom: 1rem;
  padding: 1.2rem;
  border: 1px solid rgba(197, 185, 163, 0.7);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-muted {
  background: rgba(249, 245, 236, 0.92);
}

.meta {
  color: var(--muted);
  font-size: 0.95rem;
}

.small {
  color: var(--muted);
  font-size: 0.88rem;
}

input, textarea, button {
  font: inherit;
  border-radius: 12px;
}

input, textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border-strong);
  background: var(--panel-strong);
  color: var(--text);
}

input[type="file"] {
  padding: 0.55rem 0.65rem;
}

textarea {
  min-height: 7rem;
  resize: vertical;
}

button {
  border: none;
  min-height: 2.7rem;
  padding: 0.6rem 0.95rem;
  background: var(--button);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button.alt {
  background: var(--button-alt);
}

button.light {
  background: var(--button-light);
}

button.danger {
  background: var(--button-danger);
}

button:hover {
  filter: brightness(1.04);
}

img.cover {
  width: 70px;
  border-radius: 8px;
  float: right;
  margin-left: 0.75rem;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid rgba(197, 185, 163, 0.78);
  border-radius: 14px;
  background: var(--panel-strong);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th, td {
  padding: 0.8rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid rgba(216, 207, 191, 0.72);
}

thead th {
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6a7280;
}

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

.actions {
  white-space: nowrap;
}

.actions form {
  display: inline-block;
  margin-right: 0.35rem;
  margin-top: 0.2rem;
}

.title-cell {
  font-weight: 600;
}

.empty {
  padding: 1rem;
}

.stack {
  display: grid;
  gap: 1rem;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.section-heading.tight {
  margin-bottom: 0.65rem;
}

.section-heading h2,
.section-heading h3 {
  margin-bottom: 0.2rem;
}

.search-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.search-row > :first-child {
  flex: 1;
}

.result-list {
  margin-top: 1rem;
}

.summary-grid,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}

.summary-card,
.stat-card {
  padding: 0.9rem 1rem;
  border: 1px solid rgba(197, 185, 163, 0.76);
  border-radius: 14px;
  background: rgba(255, 252, 246, 0.92);
}

.summary-label,
.stat-label {
  margin-bottom: 0.2rem;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7b6d57;
}

.summary-value,
.stat-value {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.1;
}

.summary-note {
  margin-top: 0.35rem;
}

.compact-stat {
  padding: 0.85rem 0.95rem;
}

.result-count {
  margin-top: 0.95rem;
  margin-bottom: 0.15rem;
}

.library-page {
  display: grid;
  gap: 1rem;
}

.library-hero {
  padding-bottom: 1rem;
}

.section-eyebrow,
.section-label {
  margin-bottom: 0.45rem;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7a6243;
}

.library-hero-note {
  max-width: 24rem;
}

.library-shell {
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.library-search-panel,
.library-collection-panel {
  height: 100%;
}

.library-add-form {
  display: grid;
  gap: 0.8rem;
}

.library-search-results {
  display: grid;
  gap: 0.8rem;
}

.library-search-empty {
  margin-top: 1rem;
}

.search-result {
  margin-top: 0.8rem;
  padding: 0.95rem 1rem;
  border: 1px solid rgba(216, 207, 191, 0.82);
  border-radius: 14px;
  background: rgba(255, 252, 246, 0.72);
}

.search-result:first-child {
  margin-top: 0;
}

.search-result h3 {
  margin-bottom: 0.25rem;
}

.result-actions {
  margin-top: 0.65rem;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.55rem;
}

.result-stack {
  display: grid;
  gap: 0.45rem;
}

.result-chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid rgba(197, 185, 163, 0.8);
  border-radius: 999px;
  background: rgba(245, 241, 232, 0.9);
  color: #5d6673;
  font-size: 0.78rem;
  font-weight: 600;
}

.empty-state {
  padding: 1rem 1.05rem;
  border: 1px dashed rgba(197, 185, 163, 0.92);
  border-radius: 14px;
  background: rgba(249, 245, 236, 0.7);
}

.library-filter-bar {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

.library-filter-field {
  flex: 1;
}

.tab-list {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.95rem;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.95rem;
  border: 1px solid rgba(197, 185, 163, 0.95);
  background: rgba(245, 241, 232, 0.92);
  color: var(--text);
}

.tab-btn.active {
  background: #1f2937;
  border-color: #1f2937;
  color: #fff;
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7rem;
  min-height: 1.7rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: rgba(31, 41, 55, 0.08);
  color: inherit;
  font-size: 0.82rem;
}

.tab-btn.active .tab-count {
  background: rgba(255, 255, 255, 0.16);
}

.library-tab-panel {
  display: grid;
  gap: 0.75rem;
}

.library-tab-panel[hidden] {
  display: none;
}

.tab-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
}

.search-empty {
  margin-top: 0.25rem;
}

tbody tr.book-row {
  cursor: pointer;
}

tbody tr.book-row:hover {
  background: rgba(245, 241, 232, 0.68);
}

tbody tr[hidden] {
  display: none;
}

.library-empty-state {
  max-width: 32rem;
}

.upload-panel {
  max-width: 42rem;
}

.field-row {
  display: grid;
  gap: 0.35rem;
}

.field-help {
  margin-top: 0.2rem;
}

.accordion {
  border-top: 1px solid rgba(216, 207, 191, 0.82);
  margin-top: 0.75rem;
  padding-top: 0.45rem;
}

.accordion summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.accordion summary::-webkit-details-marker {
  display: none;
}

.accordion summary::before {
  content: "▸";
  margin-right: 0.35rem;
}

.accordion[open] summary::before {
  content: "▾";
}

.accordion-body {
  margin-top: 0.55rem;
}

.google-result {
  margin-top: 0.6rem;
  padding: 0.75rem;
  border: 1px solid rgba(216, 207, 191, 0.82);
  border-radius: 12px;
  background: rgba(255, 252, 246, 0.78);
}

.google-results-box {
  max-height: 14rem;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.timeline-panel-copy {
  margin-bottom: 0.8rem;
}

.timeline-zoom-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}

.timeline-zoom-btn {
  min-height: 2.35rem;
  padding: 0.45rem 0.8rem;
  background: rgba(120, 136, 154, 0.16);
  color: var(--text);
}

.timeline-zoom-btn.active {
  background: var(--button);
  color: #fff;
}

.timeline-chart {
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.timeline-canvas {
  min-width: 100%;
}

.timeline-axis {
  position: relative;
  height: 2rem;
  margin-bottom: 0.8rem;
  border-bottom: 1px solid rgba(197, 185, 163, 0.92);
}

.tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
}

.tick::after {
  content: "";
  display: block;
  width: 1px;
  height: 0.55rem;
  margin: 0.12rem auto 0;
  background: rgba(120, 136, 154, 0.9);
}

.timeline-lanes {
  position: relative;
  min-height: 2rem;
}

.timeline-bar {
  position: absolute;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  min-height: 1.5rem;
  height: 1.7rem;
  padding: 0 0.55rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(90deg, #254f78, #4f7597);
  color: #fff;
  font-size: 0.76rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.timeline-bar.active {
  background: linear-gradient(90deg, #556271, #7a8b98);
}

.timeline-tooltip {
  position: fixed;
  z-index: 40;
  max-width: min(320px, calc(100vw - 1rem));
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  background: #1f2937;
  color: #fff;
  font-size: 0.78rem;
  pointer-events: none;
  box-shadow: 0 12px 28px rgba(22, 29, 41, 0.28);
}

.google-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.45rem;
}

@media (max-width: 860px) {
  .page-main {
    grid-template-columns: 1fr;
  }

  .library-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .library-filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .library-filter-bar button {
    width: 100%;
  }

  .tab-btn {
    justify-content: space-between;
    width: 100%;
  }
}

.google-fields label {
  font-size: 0.82rem;
  color: var(--text);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(840px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  margin: 1rem auto;
  padding: 1rem;
  overflow-x: hidden;
  overflow-y: auto;
  border-radius: 18px;
  background: #fffdf8;
  box-shadow: 0 20px 48px rgba(22, 29, 41, 0.26);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

#modal-content {
  overflow-wrap: anywhere;
}

.modal-layout {
  display: grid;
  gap: 0.9rem;
}

.modal-section {
  padding: 1rem;
  border: 1px solid rgba(216, 207, 191, 0.82);
  border-radius: 16px;
  background: rgba(255, 252, 246, 0.78);
}

.modal-section-heading {
  margin-bottom: 0.75rem;
}

.modal-section-heading h4 {
  margin-bottom: 0.2rem;
}

.modal-summary {
  background: linear-gradient(180deg, rgba(249, 245, 236, 0.9), rgba(255, 252, 246, 0.82));
}

.modal-summary-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.modal-summary-copy {
  flex: 1;
  min-width: 0;
}

.modal-cover {
  float: none;
  width: 110px;
  margin: 0;
}

.modal-description {
  margin-top: 0.8rem;
}

.modal-actions,
.modal-form-actions,
.modal-inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.modal-actions {
  margin-top: 0.9rem;
}

.modal-actions form,
.modal-danger-zone form {
  margin: 0;
}

.modal-form-stack {
  display: grid;
  gap: 0.55rem;
}

.modal-inline-form input {
  flex: 1;
  min-width: 14rem;
}

.modal-status {
  margin-top: 0.55rem;
}

.modal-danger-zone {
  border-color: rgba(165, 59, 48, 0.28);
  background: rgba(165, 59, 48, 0.06);
}

.session {
  margin: 0.45rem 0;
  padding: 0.65rem;
  border-radius: 12px;
  background: rgba(245, 241, 232, 0.9);
}

.session-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: end;
}

.session-delete-form {
  display: flex;
  align-items: end;
}

.session-divider {
  margin: 0.65rem 0;
  border: none;
  border-top: 1px dashed rgba(197, 185, 163, 0.88);
}

.save-indicator {
  margin-top: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.save-indicator.success {
  color: #0f766e;
}

.save-indicator.error {
  color: #b91c1c;
}

@media (max-width: 720px) {
  .container {
    width: min(100vw - 1rem, 1180px);
  }

  .site-header {
    padding-top: 0.9rem;
  }

  .site-header-inner,
  .page-lede,
  .section-heading,
  .search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .site-nav {
    justify-content: flex-start;
  }

  .site-nav a {
    justify-content: center;
  }

  .panel {
    padding: 1rem;
    border-radius: 16px;
  }

  .page-lede-aside {
    width: 100%;
  }

  .modal-dialog {
    width: calc(100vw - 1rem);
    max-height: calc(100vh - 0.75rem);
    margin: 0.375rem auto;
    padding: 0.85rem;
  }

  .modal-head,
  .modal-summary-main,
  .modal-inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-cover {
    width: min(180px, 100%);
  }

  .table-wrap {
    border: none;
    background: transparent;
    overflow-x: visible;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody tr {
    display: block;
    margin-bottom: 0.7rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid rgba(197, 185, 163, 0.75);
    border-radius: 12px;
    background: var(--panel-strong);
  }

  tbody td {
    display: block;
    padding: 0.24rem 0;
    border: none;
  }

  td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.1rem;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #7b8390;
  }
  .session-form-grid {
    grid-template-columns: 1fr;
  }

  img.cover {
    max-width: 38%;
  }
}
