:root {
  --paper: #6b0e16;
  --ink: #f4ead0;
  --muted: rgba(244, 234, 208, 0.68);
  --line: rgba(244, 234, 208, 0.20);
  --red: #f4ead0;
  --red-dark: #fff5df;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.library-page,
.library-view {
  color: var(--ink);
  font-family: Inter, sans-serif;
}

main {
  position: relative;
  width: min(100% - 48px, 940px);
  margin: 0 auto;
  padding: clamp(72px, 12vw, 150px) 0;
}

.library-intro {
  max-width: 780px;
  margin: 0 auto 44px;
  padding: 0 54px;
  position: relative;
  text-align: center;
}

.library-invocation,
.library-invocation-roman,
.library-invocation-english,
.about-panel h2,
.about-panel p {
  margin: 0;
}

.library-invocation {
  color: var(--ink);
  font: 500 clamp(22px, 3vw, 29px) / 1.28 "Cormorant Garamond", Georgia, serif;
  letter-spacing: 0.012em;
}

.library-invocation-roman {
  color: var(--ink);
  font: 400 clamp(20px, 2.7vw, 26px) / 1.42 "EB Garamond", "Cormorant Garamond", Georgia, serif;
  letter-spacing: 0.008em;
  margin: 13px 0 0;
}

.preface-word {
  appearance: none;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  letter-spacing: inherit;
  margin: 0;
  padding: 0 2px;
  transition: box-shadow 120ms ease, background-color 120ms ease, opacity 120ms ease;
}

.preface-token {
  border-radius: 3px;
  cursor: pointer;
  outline: none;
  padding: 0 2px;
  transition: box-shadow 120ms ease, background-color 120ms ease, opacity 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.preface-token:hover,
.preface-token:focus-visible,
.preface-token.is-hi {
  background: rgba(244, 234, 208, 0.08);
  box-shadow: 0 0 0 1px rgba(244, 234, 208, 0.60);
  outline: none;
}

.library-invocation-english {
  color: var(--muted);
  font: 400 clamp(16px, 2vw, 19px) / 1.45 "Cormorant Garamond", Georgia, serif;
  letter-spacing: 0.01em;
  margin-top: 10px;
}

.preface-meaning {
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.preface-tooltip {
  position: fixed;
  z-index: 100;
  max-width: min(260px, calc(100vw - 24px));
  border: 1px solid rgba(244, 234, 208, 0.38);
  border-radius: 5px;
  background: #5c0c13;
  color: var(--ink);
  font: 13px/1.35 Inter, sans-serif;
  padding: 7px 10px;
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(25, 0, 3, 0.28);
}

.about-toggle,
.about-close {
  appearance: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-family: Inter, sans-serif;
  transition: color 140ms ease, border-color 140ms ease, background-color 140ms ease, opacity 120ms ease, transform 120ms ease;
}

.about-toggle {
  position: absolute;
  top: 30px;
  right: 10px;
  width: 32px;
  height: 32px;
  z-index: 31;
  font-size: 14px;
  font-weight: 600;
}

.about-toggle:hover,
.about-toggle:focus-visible,
.about-toggle[aria-expanded="true"],
.about-close:hover,
.about-close:focus-visible {
  background: rgba(244, 234, 208, 0.10);
  border-color: rgba(244, 234, 208, 0.58);
  color: var(--ink);
  outline: none;
}
.about-toggle:active,
.about-close:active { opacity: 0.76; transform: scale(0.94); }

.about-panel {
  position: absolute;
  z-index: 30;
  top: 72px;
  right: 10px;
  width: min(390px, calc(100% - 20px));
  border: 1px solid rgba(244, 234, 208, 0.30);
  border-radius: 10px;
  background: #5c0c13;
  color: var(--muted);
  padding: 22px 48px 22px 22px;
  box-shadow: 0 18px 60px rgba(25, 0, 3, 0.34);
}

.about-panel h2 {
  color: var(--ink);
  font: 500 20px/1.2 "Cormorant Garamond", Georgia, serif;
}

.about-panel p {
  font: 13px/1.55 Inter, sans-serif;
  margin-top: 9px;
}

.about-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 27px;
  height: 27px;
  font-size: 18px;
  line-height: 1;
}

.song-search {
  display: block;
  margin: 0 10px 16px;
}

.song-search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(244, 234, 208, 0.08);
  color: var(--ink);
  font: 14px/1 Inter, sans-serif;
  outline: none;
  padding: 11px 14px;
}

.song-search input::placeholder { color: var(--muted); }
.song-search input:focus { border-color: rgba(244, 234, 208, 0.65); }

/* iOS Safari magnifies a page when a focused form control is below 16px.
   Keep the library search at that threshold on touch-sized viewports while
   preserving normal user-controlled pinch zoom. */
@media (max-width: 720px) {
  .song-search input { font-size: 16px; }
}

.tag-filters {
  display: grid;
  gap: 8px;
  margin: 0 10px 30px;
}

.tag-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 3px;
  scrollbar-width: none;
}

.tag-row::-webkit-scrollbar { display: none; }

.tag-filter {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: 500 11px/1 Inter, sans-serif;
  padding: 8px 11px;
  transition: color 140ms ease, border-color 140ms ease, background-color 140ms ease, opacity 120ms ease, transform 120ms ease;
}

.tag-filter[aria-pressed="true"],
.tag-filter:hover,
.tag-filter:focus-visible {
  background: rgba(244, 234, 208, 0.12);
  border-color: rgba(244, 234, 208, 0.52);
  color: var(--ink);
  outline: none;
}
.tag-filter:active { opacity: 0.76; transform: scale(0.97); }
.preface-token:active { opacity: 0.72; }

.sr-only {
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.song-list { border-top: 1px solid var(--line); }

.song-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  transition: background-color 160ms ease;
}

.song-card-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 32px;
  align-items: center;
  color: inherit;
  padding: 28px 10px;
  text-decoration: none;
  transition: color 160ms ease, padding 160ms ease, opacity 120ms ease;
}

.song-card:hover { background: rgba(244, 234, 208, 0.075); }
.song-card-link:hover,
.song-card-link:focus-visible {
  color: var(--red-dark);
  outline: none;
  padding-left: 14px;
}

.song-card-link:focus-visible { box-shadow: inset 2px 0 var(--ink); }
.song-card-link:active { opacity: 0.78; }

.song-actions-trigger {
  appearance: none;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.66;
  transition: color 140ms ease, border-color 140ms ease, background-color 140ms ease, opacity 140ms ease, transform 120ms ease;
}

.song-card:hover .song-actions-trigger,
.song-actions-trigger:hover,
.song-actions-trigger:focus-visible {
  opacity: 1;
  color: var(--ink);
  border-color: var(--line);
  background: rgba(244, 234, 208, 0.08);
  outline: none;
}
.song-actions-trigger:active { transform: scale(0.94); }

.song-copy {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.library-song-title {
  font: 400 clamp(30px, 3.5vw, 42px) / 1.04 "EB Garamond", "Cormorant Garamond", Georgia, serif;
  letter-spacing: -0.012em;
}

.credit {
  color: var(--muted);
  font-family: "EB Garamond", "Cormorant Garamond", Georgia, serif;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.015em;
  line-height: 1.35;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
  max-width: 218px;
}

.tags span {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.025em;
  line-height: 1;
  padding: 6px 9px;
  white-space: nowrap;
}

.tags .subject-tag { border-color: rgba(244, 234, 208, 0.52); }
.tags .language-tag { color: var(--muted); }

/* Living-room displays sit farther away than a laptop. Use the available
   canvas there, with larger readable metadata and controls rather than
   centering the same narrow desktop column in a much wider screen. */
@media (min-width: 1800px) {
  main {
    width: min(calc(100% - clamp(96px, 8vw, 180px)), 1680px);
    padding: clamp(84px, 7vw, 144px) 0;
  }

  .library-intro {
    max-width: 1120px;
    margin-bottom: 60px;
    padding: 0 72px;
  }

  .library-invocation { font-size: clamp(34px, 2.6vw, 48px); }
  .library-invocation-roman { font-size: clamp(30px, 2.25vw, 42px); margin-top: 18px; }
  .library-invocation-english { font-size: clamp(24px, 1.8vw, 32px); margin-top: 14px; }
  .preface-tooltip { font-size: 18px; padding: 11px 15px; max-width: 400px; }

  .about-toggle { width: 52px; height: 52px; font-size: 24px; top: 24px; right: 20px; }
  .about-panel { top: 80px; right: 20px; width: min(520px, calc(100% - 40px)); padding: 28px 58px 28px 28px; }
  .about-panel h2 { font-size: 30px; }
  .about-panel p { font-size: 20px; }
  .about-close { width: 42px; height: 42px; font-size: 30px; }

  .song-search { margin: 0 20px 22px; }
  .song-search input { font-size: 24px; padding: 18px 24px; }
  .tag-filters { gap: 12px; margin: 0 20px 42px; }
  .tag-row { flex-wrap: wrap; gap: 10px; overflow: visible; padding-bottom: 5px; }
  .tag-filter { font-size: 20px; padding: 16px 24px; min-height: 58px; }

  .song-card { grid-template-columns: minmax(0, 1fr) 58px; }
  .song-card-link { gap: 48px; padding: 36px 20px; }
  .song-card-link:hover,
  .song-card-link:focus-visible { padding-left: 28px; }
  .song-actions-trigger { width: 52px; height: 52px; }
  .song-actions-trigger svg { width: 27px; height: 27px; }
  .song-copy { gap: 10px; }
  .library-song-title { font-size: clamp(48px, 3.25vw, 66px); }
  .credit { font-size: 24px; }
  .tags { gap: 9px; max-width: 440px; }
  .tags span { font-size: 18px; padding: 12px 18px; }
}

@media (max-width: 600px) {
  main {
    width: min(100% - 32px, 940px);
    padding-top: 68px;
  }

  .library-intro {
    margin-bottom: 34px;
    padding: 0 8px;
  }

  .library-invocation { font-size: 22px; }
  .library-invocation-roman { font-size: 20px; }
  .library-invocation-english { font-size: 16px; }

  .about-toggle { top: 16px; right: 0; }
  .about-panel { top: 56px; right: 0; width: 100%; }

  .tag-filters { margin-bottom: 24px; }

  .song-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px;
  }

  .song-card-link {
    display: block;
    padding: 24px 2px;
  }

  .song-card-link:hover,
  .song-card-link:focus-visible {
    padding-left: 10px;
  }

  .song-actions-trigger { width: 42px; height: 42px; }
  .song-actions-trigger svg { width: 19px; height: 19px; }

  .library-song-title { font-size: 31px; }

  .tags {
    justify-content: flex-start;
    margin-top: 12px;
    max-width: none;
  }
}

@media (min-width: 601px) and (max-width: 1100px) {
  .song-card { grid-template-columns: minmax(0, 1fr) 48px; }
  .song-actions-trigger { width: 42px; height: 42px; }
  .song-actions-trigger svg { width: 20px; height: 20px; }
}
