:root {
  color-scheme: light;
  --accent: #5f9ea0;
  --bg: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #e2e2e2;
  --badge-petits: #f2aa9b;
  --badge-grands: #87a2d7;
  --badge-essais: #7cbd8a;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: contain;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.view {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view[hidden] {
  display: none;
}

/* --- Liste --- */

.search-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

#search-input {
  min-width: 0;
  flex: 1;
  padding: 10px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f5f5f5;
  color: var(--text);
}

#search-input:focus {
  outline: 2px solid var(--accent);
  background: var(--bg);
}

.install-button {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
}

.radio-button {
  flex-shrink: 0;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: #fff;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.radio-button.playing {
  border-color: #c75b5b;
  background: #c75b5b;
  color: #fff;
}

.radio-button.playing:hover {
  background: #ad4949;
}

.radio-button:active {
  transform: translateY(1px);
}

.radio-button[hidden] {
  display: none;
}

.radio-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.radio-icon-stop,
.radio-button.playing .radio-icon-play {
  display: none;
}

.radio-button.playing .radio-icon-stop {
  display: block;
}

@media all and (display-mode: standalone), all and (display-mode: fullscreen), all and (display-mode: minimal-ui) {
  .install-button {
    display: none !important;
  }
}

.install-icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--bg);
  color: var(--text);
  border-radius: 16px 16px 0 0;
  padding: 24px 20px max(24px, env(safe-area-inset-bottom));
}

@media (min-width: 480px) {
  .modal-overlay {
    align-items: center;
  }
  .modal-card {
    border-radius: 16px;
  }
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: var(--muted);
}

.modal-card h2 {
  margin: 0 0 16px;
  padding-right: 30px;
  font-size: 18px;
}

.modal-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-steps li {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 15px;
}

.modal-step-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(95, 158, 160, 0.12);
  color: var(--accent);
}

.refresh-indicator {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(95, 158, 160, 0.08);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.refresh-indicator[hidden] {
  display: none;
}

.sheet-filter {
  position: sticky;
  top: 62px;
  z-index: 4;
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.filter-button {
  flex: 1;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f7f7;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.filter-button[data-filter="petits"] {
  border-color: var(--badge-petits);
  color: #9b4d43;
}

.filter-button[data-filter="grands"] {
  border-color: var(--badge-grands);
  color: #42619d;
}

.filter-button[data-filter="essais"] {
  border-color: var(--badge-essais);
  color: #3f7a4b;
}

.filter-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.filter-button[data-filter="petits"].active {
  border-color: var(--badge-petits);
  background: var(--badge-petits);
}

.filter-button[data-filter="grands"].active {
  border-color: var(--badge-grands);
  background: var(--badge-grands);
}

.filter-button[data-filter="essais"].active {
  border-color: var(--badge-essais);
  background: var(--badge-essais);
}

.chant-list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0 0 24px;
  list-style: none;
  -webkit-overflow-scrolling: touch;
}

.menu-button {
  flex-shrink: 0;
  width: 36px;
  height: 42px;
  padding: 6px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.menu-button svg,
.menu-links svg,
.print-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}

.recueils-dialog {
  width: calc(100% - 24px);
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  padding: 24px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
}

.recueils-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.menu-dialog {
  margin: max(10px, env(safe-area-inset-top)) auto auto 12px;
  max-width: 350px;
}

.menu-links {
  display: grid;
  gap: 8px;
  margin-top: 24px;
}

.menu-links button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.menu-links svg {
  flex-shrink: 0;
  color: var(--accent);
}

.menu-links button:hover,
.menu-button:hover {
  background: #f5f8f8;
}

.changes-dialog {
  max-width: 540px;
}

.changes-label {
  display: block;
  margin: 24px 0 8px;
  font-size: 13px;
  font-weight: 600;
}

#changes-recueil {
  width: 100%;
  min-height: 44px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.changes-list {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
}

.changes-list li {
  padding: 16px 0 16px 14px;
  border-left: 2px solid var(--border);
}

.changes-list time {
  color: var(--muted);
  font-size: 12px;
}

.changes-list p {
  margin: 6px 0 0;
  color: var(--text);
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.changes-action {
  width: 100%;
  min-height: 44px;
  margin-top: 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--bg);
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.print-heading,
.print-pages {
  display: none;
}

.recueils-dialog h2 {
  margin: 0 28px 12px 0;
  font-size: 18px;
}

.recueils-dialog p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.recueils-list {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
}

.recueils-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.recueils-list small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 400;
}

.recueils-list a > span:last-child {
  color: var(--accent);
  font-size: 13px;
  white-space: nowrap;
}

.radio-active .chant-list {
  padding-bottom: 98px;
}

.radio-player {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 66px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(10px);
}

.radio-active .chant-view {
  padding-bottom: 88px;
}

.radio-player[hidden] {
  display: none;
}

.radio-control[hidden] {
  display: none;
}

.radio-control {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}

.radio-control svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.radio-stop {
  border-color: var(--border);
  background: #fff;
  color: var(--muted);
}

.radio-main {
  min-width: 0;
  flex: 1;
}

.radio-now {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0 2px;
}

.radio-kicker,
.radio-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.radio-kicker {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.radio-title {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 600;
}

.audio-progress {
  display: block;
  width: 100%;
  height: 18px;
  margin: 4px 0 0;
  accent-color: var(--accent);
}

.audio-progress:disabled {
  opacity: 0.45;
}

@media (max-width: 480px) {
  .search-bar {
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .radio-button {
    gap: 5px;
    padding: 0 8px;
  }
}

.chant-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.chant-row .badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  min-width: 32px;
  height: 26px;
  font-size: 11px;
  font-weight: 700;
  padding: 0 4px;
  border-radius: 6px;
  color: #fff;
}

.badge.sheet-petits { background: var(--badge-petits); }
.badge.sheet-grands { background: var(--badge-grands); }
.badge.sheet-essais { background: var(--badge-essais); }

.chant-row .info {
  min-width: 0;
  flex: 1;
}

.chant-row .title {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chant-row .ref {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chant-row .number {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
}

.audio-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}

.audio-mark svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  margin-top: 40px;
}

/* --- Vue chant --- */

.chant-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 10;
}

.chant-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 10px 10px;
  border-bottom: 1px solid var(--border);
}

.icon-button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: var(--text);
  cursor: pointer;
}

.audio-button,
.print-button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: #fff;
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
}

.print-button[hidden] {
  display: none;
}

.print-button {
  cursor: pointer;
}

.print-button:disabled {
  opacity: 0.45;
  cursor: wait;
}

.audio-button.playing {
  background: var(--accent);
  color: #fff;
}

.chant-header-text {
  min-width: 0;
  flex: 1;
}

.chant-header-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chant-header-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swipe-area {
  flex: 1;
  display: flex;
  width: 200%;
  height: 100%;
  transition: transform 0.25s ease-out;
  touch-action: pan-y;
}

.swipe-area.dragging {
  transition: none;
}

.pane {
  width: 50%;
  height: 100%;
  overflow: hidden;
}

.pane-pdf {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
}

.partition-pages {
  min-height: 100%;
  padding: 10px 0 32px;
}

.partition-page {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto 12px;
  background: #fff;
}

.partition-unavailable {
  margin: 40px auto;
  color: var(--muted);
  text-align: center;
}

.pane-lyrics {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.lyrics-content {
  padding: 20px 20px 60px;
  font-size: 17px;
  line-height: 1.6;
}

.lyrics-content p {
  margin: 0 0 1em;
}

.lyrics-content .no-lyrics {
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
}

.pane-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
}

.pane-dots[hidden] {
  display: none;
}

.pane-tabs {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 4px 10px max(4px, env(safe-area-inset-bottom));
  gap: 6px;
}

.pane-tabs[hidden] {
  display: none;
}

.pane-tab {
  flex: 1;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.pane-tab.active {
  background: rgba(95, 158, 160, 0.14);
  color: var(--accent);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
}

.dot.active {
  background: var(--accent);
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  html, body {
    height: auto;
    background: #fff;
  }

  body > :not(#chant-view),
  .chant-header,
  .pane-lyrics,
  .pane-tabs,
  .pane-dots {
    display: none !important;
  }

  #chant-view:not([hidden]),
  #swipe-area,
  #pane-pdf,
  #partition-pages {
    display: block;
    position: static;
    width: 100%;
    height: auto;
    min-height: 0;
    overflow: visible;
    padding: 0;
    transform: none !important;
    transition: none;
  }

  #chant-view:not([hidden]) {
    width: 190mm;
  }

  .paginated-print #swipe-area {
    display: none;
  }

  .paginated-print .print-pages {
    display: block;
  }

  .print-partition-page {
    display: block;
    width: 100%;
    height: auto;
    break-inside: avoid;
    break-after: page;
  }

  .print-partition-page:last-child {
    break-after: auto;
  }

  .partition-page {
    width: 100%;
    height: auto;
    max-height: 242mm;
    object-fit: contain;
    object-position: top;
    margin: 0;
    break-inside: avoid;
    break-after: page;
  }

  .partition-page:last-child {
    break-after: auto;
  }

  .print-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6mm;
    margin: 0 0 6mm;
    padding: 0 0 4mm;
    border-bottom: 0.4mm solid #555;
    color: #222;
    break-inside: avoid;
    break-after: avoid;
  }

  .print-heading h2 {
    min-width: 0;
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 20pt;
    line-height: 1.2;
    font-weight: 600;
    overflow-wrap: anywhere;
  }

  .print-ref {
    flex-shrink: 0;
    font-size: 12pt;
    font-style: italic;
    text-align: right;
    white-space: nowrap;
  }
}
