:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-muted: #eef1f9;
  --text: #1f2933;
  --text-muted: #5f6c7b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --border: #d0d7e3;
  --radius: 16px;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}


* {
  box-sizing: border-box;
}

/* Ensure HTML hidden attribute works regardless of later display rules */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Base safe-area padding so content never sits under the home indicator */
body {
  padding-bottom: env(safe-area-inset-bottom);
}

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

a:hover {
  text-decoration: underline;
}

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

.flex {
  display: flex;
}

.between {
  justify-content: space-between;
}

.align-center {
  align-items: center;
}

.site-header {
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(208, 215, 227, 0.5);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

.site-header .container {
  padding: 1rem 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--text);
  letter-spacing: -0.02em;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.35);
}

.app-version {
  margin-left: 0.5rem;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  opacity: 0.8;
}

.nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 0.35rem 0.4rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.nav-toggle {
  display: none;
  border: none;
  background: rgba(15, 23, 42, 0.08);
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  font-weight: 600;
  color: var(--text);
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.nav-toggle:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.nav.is-nav-open .nav-toggle {
  background: var(--primary);
  color: #fff;
}

.nav-toggle-icon {
  width: 18px;
  height: 18px;
  position: relative;
}

.nav-toggle-icon::before,
.nav-toggle-icon::after,
.nav-toggle-icon span {
  content: '';
  position: absolute;
  width: 100%;
  height: 2px;
  background: currentColor;
  left: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle-icon::before {
  top: 0;
}

.nav-toggle-icon::after {
  bottom: 0;
}

.nav-toggle-icon span {
  top: 50%;
  transform: translateY(-50%);
}

.nav.is-nav-open .nav-toggle-icon::before {
  transform: translateY(8px) rotate(45deg);
}

.nav.is-nav-open .nav-toggle-icon::after {
  transform: translateY(-8px) rotate(-45deg);
}

.nav.is-nav-open .nav-toggle-icon span {
  opacity: 0;
}

.nav-toggle-label {
  font-size: 0.9rem;
}

.nav-links {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text);
  transition: all 0.2s ease;
}

.nav-link:hover {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  text-decoration: none;
}

.nav-link.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.35);
}

.nav .button {
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  font-size: 0.95rem;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.25);
}

.nav-dropdown {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}

.nav-dropdown-trigger {
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding-right: 1.35rem;
}

.nav-dropdown-trigger::after {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  margin-top: -0.1rem;
}

.nav-dropdown.is-open .nav-dropdown-trigger::after {
  transform: rotate(-135deg);
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  min-width: 220px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.15);
  padding: 0.5rem;
  display: none;
  z-index: 40;
}

.nav-dropdown.is-open .nav-dropdown-menu {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-dropdown.is-open > .nav-dropdown-trigger {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}

.nav-dropdown-link {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease;
}

.nav-dropdown-link:hover,
.nav-dropdown-link:focus {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  outline: none;
}

.nav-dropdown-link.is-active {
  background: rgba(37, 99, 235, 0.18);
  color: var(--primary-dark);
  font-weight: 600;
}

.nav-dropdown-menu::before {
  content: '';
  position: absolute;
  top: -0.4rem;
  right: 1.35rem;
  width: 0.8rem;
  height: 0.8rem;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: -3px -3px 12px rgba(15, 23, 42, 0.04);
}

.nav .button.ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--text);
  box-shadow: none;
}

.nav .button.ghost:hover {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}

.inline-form {
  display: inline;
  margin: 0;
}

.nav .inline-form .button {
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, 0.08);
  box-shadow: none;
  transition: all 0.2s ease;
}

.nav .inline-form .button:hover {
  background: var(--primary);
  color: #fff;
}

main.container {
  padding: 2.5rem 1.5rem 4rem;
  flex: 1 0 auto;
}

.site-footer {
  margin-top: auto;
  padding: 1.5rem 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.muted {
  color: var(--text-muted);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.card.music-source-highlights {
  margin-bottom: 0.5rem;
}

.card.danger {
  border: 1px solid rgba(220, 38, 38, 0.35);
}

.card-title {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.card-subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
}

.auth-card {
  max-width: 420px;
  margin: 2rem auto;
}

.page-header {
  margin-bottom: 2rem;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-weight: 600;
  background: var(--surface-muted);
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
}

.button:hover {
  background: #d9def0;
  text-decoration: none;
}

.button.primary {
  background: var(--primary);
  color: #fff;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.success {
  background: var(--success);
  color: #fff;
}

.button.success:hover {
  background: #15803d; /* darker green */
}

.button.ghost {
  background: transparent;
  border: 1px solid var(--border);
}

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

.button.danger.ghost {
  background: transparent;
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.4);
}

.button.small {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.button:disabled,
.button[disabled],
.button[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.button.ghost:disabled,
.button.ghost[disabled],
.button.ghost[aria-disabled="true"] {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

/* Visual hint for disabled generate button when highlights exist */
.button[data-generate-highlight].has-highlights {
  opacity: 1;
  cursor: default;
  pointer-events: auto;
  position: relative;
  background: rgba(22, 163, 74, 0.1);
  border-color: rgba(22, 163, 74, 0.3);
  color: var(--success);
}

.button[data-generate-highlight].has-highlights::before {
  content: '✓';
  margin-right: 0.35rem;
}

.button[data-generate-highlight].has-highlights:hover {
  background: rgba(22, 163, 74, 0.15);
}

.button.full {
  width: 100%;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.annotation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.annotation-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: minmax(0, 1fr);
  margin-bottom: 2rem;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 1080px) {
  .annotation-grid {
    grid-template-columns: minmax(0, 1040px);
    justify-content: center;
  }
}

/* Match the annotation content width to the item grid on wide screens */
.annotation-content {
  margin: 0 auto;
}
@media (min-width: 960px) {
  .annotation-content {
    max-width: 880px;
  }
}

/* Ensure the Firebase search input expands to full card width */
.annotation-search input[type="search"] {
  width: 100%;
}

/* Suggestions table row states */
.audio-table .audio-suggestion-row.is-unannotated td {
  background: rgba(22, 163, 74, 0.08);
}
.audio-table .audio-suggestion-row.is-annotated td {
  background: var(--surface-muted);
}

/* Badges */
.badge.success {
  background: rgba(22, 163, 74, 0.15);
  color: #166534;
}
.badge.muted {
  background: rgba(95, 108, 123, 0.15);
  color: var(--text);
}
.badge.neutral {
  background: rgba(95, 108, 123, 0.12);
  color: var(--text-muted);
}

/* Suggestions collapsible */
.annotation-suggestions {
  position: relative;
}
.annotation-suggestions-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.04);
  cursor: pointer;
  user-select: none;
}
.annotation-suggestions-summary:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}
.annotation-suggestions.is-open .annotation-suggestions-summary {
  background: rgba(37, 99, 235, 0.08);
}
.annotation-suggestions-summary-row {
  display: contents;
}
.annotation-summary-badges {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.annotation-click-hint {
  color: var(--text-muted);
  font-size: 0.875rem;
}
.annotation-caret {
  width: 0.6rem;
  height: 0.6rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}
.annotation-suggestions.is-open .annotation-caret {
  transform: rotate(-135deg);
}
.annotation-suggestions-body {
  margin-top: 1rem;
}

/* Validation panel */
.annotation-validation {
  margin: 0 0 1rem;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
}
.annotation-validation.is-valid {
  background: rgba(22, 163, 74, 0.08);
}
.annotation-validation.is-invalid {
  background: rgba(220, 38, 38, 0.08);
}
.annotation-validation-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.annotation-validation-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: #fff;
  background: var(--text-muted);
}
.annotation-validation.is-valid .annotation-validation-badge {
  background: var(--success);
}
.annotation-validation.is-invalid .annotation-validation-badge {
  background: var(--danger);
}
.annotation-validation-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.annotation-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}
.annotation-chip--info {
  background: var(--primary);
  color: #fff;
}
.annotation-validation-summary {
  color: var(--text-muted);
}
.annotation-validation-list {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}
.annotation-validation-list li {
  margin: 0.15rem 0;
}

/* Audio matches toggle */
.annotation-audio-matches {
  margin-top: 0.25rem;
}
.annotation-audio-matches > summary {
  cursor: pointer;
  color: var(--primary);
}
.annotation-audio-list {
  margin: 0.35rem 0 0;
  padding-left: 1.25rem;
  display: grid;
  gap: 0.35rem;
}
.annotation-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  background: var(--surface-muted);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
}
.annotation-chip--muted {
  background: var(--surface-muted);
  color: var(--text);
}

/* Highlights & explore section */
.annotation-explore {
  margin: 0.5rem 0 0.5rem;
  display: grid;
  gap: 0.5rem;
}
.annotation-highlights {
  margin: 0.5rem 0 1rem;
}
.annotation-highlights > summary,
.annotation-audio-matches > summary,
.annotation-suggestions > summary {
  cursor: pointer;
  color: var(--primary);
  margin-bottom: 0.5rem;
}
.annotation-highlight-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}
.annotation-highlight-item {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.annotation-highlight-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}
.annotation-highlight-desc {
  margin-bottom: 0.4rem;
}
.annotation-highlight-audio audio {
  width: 100%;
}

.highlight-register {
  margin-top: 1.25rem;
}

.highlight-register .list-items {
  margin-top: 1.25rem;
}

.music-source-highlights [data-highlight-empty] {
  margin-top: 0.75rem;
  margin-bottom: 1rem;
}

.music-source-highlights + section[data-highlight-sync-section] {
  margin-top: 0;
}

.movement-accordion {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 1rem;
  background: #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
}

.movement-accordion__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.movement-accordion__header-left {
  display: grid;
  gap: 0.2rem;
}

.movement-accordion__meta {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}

.movement-accordion__actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.movement-accordion__label {
  margin: 0;
  font-weight: 600;
}

.movement-accordion__sub {
  margin: 0;
  color: var(--text-muted);
}

.movement-accordion__sub.is-missing {
  color: #c0392b;
}

.movement-accordion__body {
  display: grid;
  gap: 0.6rem;
}

.movement-highlights {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

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

.movement-highlights__actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.movement-highlights__list {
  display: grid;
  gap: 0.75rem;
}

.movement-message {
  margin: 0.25rem 0;
}

.movement-actions {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.movement-save-status {
  font-size: 0.875rem;
  color: var(--text-muted, #64748b);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.movement-save-status::before {
  content: '';
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.movement-save-status.is-error {
  color: var(--danger, #dc2626);
}

.movement-save-status.is-error::before {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.highlight-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  background: #f9fafb;
  overflow-wrap: anywhere;
}

.highlight-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.highlight-card__time {
  margin: 0.15rem 0 0;
  font-weight: 600;
}

.highlight-card__actions {
  display: flex;
  gap: 0.35rem;
}

.highlight-card__body {
  display: grid;
  gap: 0.2rem;
  margin-top: 0.35rem;
}

.highlight-card__body audio {
  width: 100%;
  margin-bottom: 0.1rem;
}

.highlight-card__form {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

section[data-highlight-sync-section] {
  margin-top: 0.1rem;
  margin-bottom: 1.25rem;
}

.highlight-sync-status .alert {
  margin: 0.25rem 0;
}

.highlight-sync-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.highlight-sync-header .icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  align-self: flex-start;
}
/* Inline spinner hook retained for future use */
.spinner--inline {
  display: inline-block;
  margin-left: 0;
  width: 1em;
  height: 1em;
}

/* Divider between explore tools and raw fields */
.annotation-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0 1rem;
}

/* Annotation section headers */
.annotation-section-header,
.annotation-subsection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.04);
  margin: 0 0 1rem;
}

/* Canonical: annotation section title; variants must be scoped under their container */
.annotation-section-title {
  margin: 0;
  font-size: 1.1rem;
}
/* Lists of dynamic items */
.list-repeater .list-items {
  display: grid;
  gap: 0.75rem;
}

.list-repeater .list-footer {
  display: flex;
  justify-content: center;
  margin-top: 0.75rem;
}

.list-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
}

.list-card--muted {
  background: var(--surface-muted);
}

/* Grid modifiers */
.form-grid {
  display: grid;
  gap: 1rem;
}

.form-grid--2 {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

/* Wider buttons helper */
.button.wide {
  min-width: 240px;
}

@media (max-width: 720px) {
  .form-grid--2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

.form-grid--stack {
  grid-template-columns: minmax(0, 1fr) !important;
}

/* Field blocks for visual division */
.field-block {
  background: var(--surface-muted);
  border: 1px solid rgba(208, 215, 227, 0.7);
  border-radius: 12px;
  padding: 1rem;
}

.annotation-card-header {
  margin-bottom: 1rem;
}

.annotation-card-title {
  /* Canonical: card title sizing and wrapping */
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.annotation-fields {
  margin: 0;
  display: grid;
  gap: 1rem;
  min-width: 0; /* allow grid children to shrink */
}

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

.annotation-field--inline {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 0.5rem 1rem;
}

.annotation-field-label {
  font-weight: 600;
  margin: 0;
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--text);
  width: fit-content;
}

.annotation-field-label--inline {
  padding: 0;
  background: none;
  color: var(--text-muted);
}

.annotation-field-value {
  margin: 0;
  font-size: 0.95rem;
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(208, 215, 227, 0.6);
}

.annotation-field-value--inline {
  padding: 0;
  border: none;
  background: none;
  text-align: right;
  justify-self: end;
  color: var(--text);
}

.annotation-field-value--structured {
  padding: 0;
  border: none;
  background: transparent;
}

.annotation-field-value--structured .annotation-tree-container {
  margin: 0;
}

.annotation-field-text {
  display: inline-block;
  padding: 0;
}

.annotation-tree-container {
  padding: 0.75rem 1rem;
  border-radius: 14px;
  background: var(--surface-muted);
  border: 1px solid rgba(208, 215, 227, 0.6);
  max-height: 320px;
  overflow: auto;
  max-width: 100%;
}

.annotation-tree-row,
.annotation-tree-branch > summary {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--text);
}

.annotation-tree-branch > summary {
  position: relative;
  cursor: pointer;
  border-radius: 10px;
  padding: 0.4rem 0.65rem 0.4rem 1.75rem;
  transition: background 0.2s ease, color 0.2s ease;
}

.annotation-tree-branch[open] > summary {
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
}

.annotation-tree-key {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.annotation-tree-value {
  word-break: break-word;
}

.annotation-tree-meta {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.annotation-tree-children {
  list-style: none;
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  border-left: 1px solid rgba(208, 215, 227, 0.7);
}

.annotation-tree-branch > summary::before {
  content: "";
  position: absolute;
  left: 0.65rem;
  top: 50%;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-50%) rotate(-45deg);
  transition: transform 0.2s ease;
}

.annotation-tree-branch[open] > summary::before {
  transform: translateY(-50%) rotate(45deg);
}

.annotation-tree-node {
  margin: 0.35rem 0;
}

.annotation-tree-level-0 {
  margin-left: 0;
}

.annotation-tree-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.annotation-tree-container::-webkit-scrollbar-thumb {
  background: rgba(95, 108, 123, 0.35);
  border-radius: 999px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

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

.form-field label {
  font-weight: 600;
}

.form-field input,
.form-field textarea,
.form-field select {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 1rem;
  background: #fff;
}

.form-field textarea {
  resize: vertical;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Center and widen actions in IMSLP piece section */
.annotation-imslp-piece .form-actions {
  justify-content: center;
}
.annotation-imslp-piece .form-actions .button {
  min-width: 260px;
}

/* Inline actions in grid rows */
.form-grid.form-grid--inline-actions {
  align-items: end;
}
.form-field.form-field--align-end {
  align-self: end;
}
.form-field.form-field--no-label label {
  display: none;
}

/* Loading spinner and inline progress */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
.inline-progress {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}
.button.is-loading {
  opacity: 0.85;
  pointer-events: none;
}
.button.is-loading::after {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: 0.5rem;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 1s linear infinite;
}

/* Non-spinner save states */
.button.is-saving {
  opacity: 0.85;
  pointer-events: none;
}

/* Disabled field styling for better affordance */
.form-field input:disabled,
.form-field textarea:disabled,
.form-field select:disabled,
.form-field input[disabled],
.form-field textarea[disabled],
.form-field select[disabled] {
  background: var(--surface-muted);
  color: var(--text-muted);
  border-color: rgba(208, 215, 227, 0.9);
  cursor: not-allowed;
}

/* Add extra spacing below the filter actions before the table */
.audio-filter-form .form-actions {
  margin-bottom: 1.25rem;
}

/* Add more space around the filter controls */
.audio-filter-form {
  margin-top: 1rem;
  margin-bottom: 1.5rem;
}
.audio-filter-form .form-grid {
  gap: 1.75rem;
}
.audio-filter-form .form-field {
  margin-bottom: 1.75rem;
}

.messages {
  margin-bottom: 2rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-weight: 500;
}

.alert.success {
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
}

.alert.info {
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
}

.alert.warning {
  background: rgba(249, 115, 22, 0.15);
  color: #c2410c;
}

.alert.error {
  background: rgba(248, 113, 113, 0.18);
  color: #b91c1c;
}

.error-text {
  color: #b91c1c;
  margin: 0;
  font-size: 0.875rem;
}

.help-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}

.table-responsive {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.table tbody tr:hover {
  background: var(--surface-muted);
}

.table td.actions {
  display: flex;
  gap: 0.5rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.5rem;
}

.badge.warning {
  background: rgba(249, 115, 22, 0.15);
  color: #c2410c;
}

.badge.danger {
  background: rgba(248, 113, 113, 0.18);
  color: #b91c1c;
}

/* Stats grid for status pages */
.stats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.25rem 1.5rem;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(37, 99, 235, 0.15));
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.1);
  text-align: center;
  min-width: 160px;
  flex: 0 0 auto;
}

.stat-tile--warning {
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.1), rgba(249, 115, 22, 0.2));
  box-shadow: 0 8px 24px rgba(249, 115, 22, 0.1);
}

.stat-value {
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1.1;
}

.stat-tile--warning .stat-value {
  color: #c2410c;
}

.stat-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Status page table with horizontal scroll and no text wrapping */
.status-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.status-table {
  white-space: nowrap;
  min-width: 100%;
}

.status-table th,
.status-table td {
  white-space: nowrap;
}

.status-table .annotation-code {
  white-space: nowrap;
}

.annotation-results {
  display: grid;
  gap: 1.75rem;
  margin-top: 1.5rem;
}

.annotation-result {
  padding: 1.25rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

/* Highlight existing results with a green-tinted background */
.annotation-result--exists {
  background: rgba(22, 163, 74, 0.08);
  border-color: rgba(22, 163, 74, 0.3);
}

.annotation-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.annotation-result-title {
  flex: 1 1 auto;
  margin: 0;
  min-width: 0; /* allow wrapping within flex container */
  word-break: break-word;
}

.annotation-result-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex-shrink: 0; /* keep actions from shrinking too much */
}

/* Ensure consistent button widths in the actions area */
.annotation-result-actions .button {
  min-width: 140px;
  white-space: nowrap;
  min-height: 44px; /* equalize vertical size across link and form button */
}

/* Wide mode: make anchor and form occupy equal widths */
.annotation-result-actions > a.button,
.annotation-result-actions > .annotation-select-form {
  flex: 1 1 0;
}
/* Make the form fill its flex area so the inner button can match the link size */
.annotation-result-actions > .annotation-select-form {
  display: flex;
}
.annotation-result-actions > .annotation-select-form .button {
  width: 100%;
}

.annotation-result h2 {
  font-size: 1.1rem;
  margin: 0;
}

.annotation-select-form {
  margin: 0;
  display: inline-flex;
}

.annotation-empty {
  margin-top: 1.5rem;
}

.annotation-selection .form-actions {
  margin-top: 0.5rem;
}

.annotation-selection h2 {
  margin-top: 0;
  margin-bottom: 1.25rem;
}

.annotation-audio-field select {
  width: 100%;
}


.audio-card {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.audio-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.audio-page-header-text {
  flex: 1 1 240px;
}

.audio-toolbar-card {
  margin-bottom: 2rem;
}

.audio-toolbar {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.audio-toolbar-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.audio-toolbar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.audio-input,
.audio-select {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 0.95rem;
  min-width: 220px;
}

.audio-select {
  min-width: 200px;
}

.audio-input:focus,
.audio-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.audio-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.audio-summary-note {
  margin: 0;
  font-size: 0.85rem;
}

.audio-summary-stat {
  padding: 1rem 1.25rem;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(37, 99, 235, 0.15));
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.12);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.audio-summary-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.audio-summary-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.audio-collections {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.audio-collection-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 0.85rem;
}

.audio-collection-pill.muted {
  background: rgba(95, 108, 123, 0.1);
  color: var(--text-muted);
}

.audio-table-wrapper {
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(208, 215, 227, 0.6);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.08);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.audio-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 720px;
}

.audio-table thead {
  background: rgba(15, 23, 42, 0.04);
}

.audio-table th {
  text-align: left;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.85rem 1rem;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(208, 215, 227, 0.6);
}

.audio-table td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid rgba(208, 215, 227, 0.35);
  vertical-align: middle;
  background: #fff;
}

.audio-row:last-child td {
  border-bottom: none;
}

.audio-row:hover td {
  background: rgba(37, 99, 235, 0.06);
}

.audio-row.is-playing td {
  background: rgba(37, 99, 235, 0.08);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.25);
}

.audio-control-cell {
  width: 72px;
}

.audio-control {
  --audio-icon-color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(37, 99, 235, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.audio-control:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.25);
}

.audio-control:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
}

.audio-control.is-playing {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  --audio-icon-color: #fff;
  box-shadow: 0 18px 30px rgba(37, 99, 235, 0.35);
}

.audio-control-icon {
  position: relative;
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.audio-control-icon::before,
.audio-control-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  transition: all 0.2s ease;
  background: var(--audio-icon-color);
  border-radius: 1px;
}

.audio-control-icon::before {
  left: 6px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 0 8px 12px;
  border-color: transparent transparent transparent var(--audio-icon-color);
  background: transparent;
}

.audio-control-icon::after {
  left: 12px;
  width: 0;
  height: 0;
  opacity: 0;
}

.audio-control.is-playing .audio-control-icon::before {
  border-width: 0;
  border-color: transparent;
  width: 4px;
  height: 14px;
  left: 6px;
  background: var(--audio-icon-color);
}

.audio-control.is-playing .audio-control-icon::after {
  opacity: 1;
  width: 4px;
  height: 14px;
}

.audio-title {
  font-weight: 600;
  color: var(--text);
}

.audio-collection {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.6rem;
  border-radius: 10px;
  background: rgba(95, 108, 123, 0.12);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.audio-size {
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.audio-path {
  max-width: 480px;
  padding: 0.4rem 0.6rem;
  border-radius: 10px;
  background: var(--surface-muted);
  overflow-x: auto;
  white-space: nowrap;
  border: 1px solid rgba(208, 215, 227, 0.6);
}

.audio-path:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.audio-path code {
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--text);
}

.audio-element {
  display: none;
}

.audio-empty-state {
  text-align: center;
  padding: 2rem 1rem;
}

.audio-empty-state h2 {
  margin-bottom: 0.5rem;
}

.audio-pagination,
.annotation-pagination {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
}

.audio-pagination-links,
.annotation-pagination-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.audio-pagination-status,
.annotation-pagination-status {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.audio-pagination-buttons,
.annotation-pagination-buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
}

.audio-page-link,
.annotation-page-link,
.audio-page-ellipsis,
.annotation-page-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(208, 215, 227, 0.9);
  background: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.audio-page-link:hover,
.annotation-page-link:hover {
  background: rgba(37, 99, 235, 0.12);
  border-color: rgba(37, 99, 235, 0.4);
  color: var(--primary);
}

.audio-page-link.is-active,
.annotation-page-link.is-active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-color: transparent;
  color: #fff;
  cursor: default;
}

.audio-page-ellipsis {
  border: none;
  background: transparent;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .site-header .container {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  /* Ensure code and links wrap on small screens within annotation area */
  .annotation-grid code,
  .annotation-grid a,
  .annotation-grid .annotation-card-subtitle {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .annotation-grid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .nav {
    position: relative;
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0.6rem;
    width: auto;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    -webkit-tap-highlight-color: transparent;
  }

  .nav-toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .nav-links {
    display: none;
    flex-direction: column;
    gap: 0.35rem;
    position: fixed;
    left: 0;
    right: 0;
    top: calc(var(--header-height, 72px));
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    border-radius: 0;
    padding: 1rem 1.5rem;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    z-index: 100;
    border-bottom: 1px solid rgba(208, 215, 227, 0.5);
  }

  .nav.is-nav-open .nav-links {
    display: flex;
  }

  .nav-link,
  .nav-dropdown,
  .nav .button,
  .nav .inline-form {
    width: 100%;
  }

  .nav-link {
    justify-content: center;
    padding: 0.65rem 1rem;
    border-radius: 12px;
  }

  .nav-dropdown {
    flex-direction: column;
  }

  .nav-dropdown-trigger {
    width: 100%;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    border-radius: 12px;
  }

  .nav-dropdown-menu {
    position: static;
    width: 100%;
    margin-top: 0.4rem;
    box-shadow: none;
    padding: 0.2rem 0.35rem;
  }

  .nav-dropdown-menu::before {
    display: none;
  }

  .nav .button {
    box-shadow: none;
  }

  .nav .inline-form {
    display: flex;
  }

  .nav .inline-form .button {
    width: 100%;
  }

  .table td.actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .audio-toolbar {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .audio-toolbar-fields {
    width: 100%;
  }

  .audio-input,
  .audio-select {
    width: 100%;
    min-width: 0;
  }

  .audio-pagination {
    justify-content: center;
  }

  .audio-pagination-links {
    align-items: center;
  }
}

/* Sticky annotation audio player */
.annotation-player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #111;
  color: #fff;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding: 0.5rem 1rem;
  /* Ensure controls sit above the iOS home indicator */
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
}
.annotation-player__button {
  appearance: none;
  border: none;
  background: #fff;
  color: #111;
  width: 36px;
  height: 36px;
  border-radius: 18px;
  font-weight: 700;
  cursor: pointer;
}
.annotation-player__button.is-playing {
  background: #f33;
  color: #fff;
}
.annotation-player__track {
  position: relative;
  flex: 1 1 auto;
  height: 8px;
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
  cursor: pointer;
}
.annotation-player__progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: #0bd;
  border-radius: 4px;
}
.annotation-player__time {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  min-width: 120px;
  text-align: right;
}

/* Volume controls */
.annotation-player__volume {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 160px;
}
.annotation-player__mute {
  appearance: none;
  border: none;
  background: #fff;
  color: #111;
  width: 28px;
  height: 28px;
  border-radius: 14px;
  font-size: 0.9rem;
  cursor: pointer;
}
.annotation-player__mute.is-muted {
  background: #666;
  color: #fff;
}
.annotation-player__vol-range {
  width: 120px;
  height: 6px;
}

/* Mobile: single-row layout for audio player */
@media (max-width: 768px) {

  /* Play/Pause button (left) */
  .annotation-player__button {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 16px;
  }

  /* Playbar (flexible width) */
  .annotation-player__track {
    flex: 1 1 auto;
    display: flex !important;
    min-width: 0;
    height: 8px;
  }

  /* Time display */
  .annotation-player__time {
    flex: 0 0 auto;
    display: block !important;
    font-variant-numeric: tabular-nums;
    font-size: 0.7rem;
    opacity: 0.85;
    white-space: nowrap;
    min-width: 105px;
    text-align: right;
    padding-right: 0.25rem;
  }

  /* Mute button only (hide volume slider) */
  .annotation-player__volume {
    flex: 0 0 auto;
    display: flex !important;
    align-items: center;
    margin-left: -0.2rem;
    min-width: 0;
    gap: 0;
    width: auto;
  }

  .annotation-player__vol-range {
    display: none !important;
    width: 0 !important;
  }

  .annotation-player__mute {
    flex: 0 0 auto;
  }
}

/* =========================================================
 * Mobile overflow fixes for Annotation pages (≤768px)
 * - Prevent page-level horizontal scroll
 * - Wrap long code, IDs, paths, and field values
 * - Contain tables and tree views within their containers
 * ========================================================= */

/* Global safeguard: prevent entire page from scrolling horizontally */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Wrap long code blocks, IDs, and identifiers */
.annotation-code,
.annotation-code pre,
.annotation-code code {
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Wrap annotation field values and text */
.annotation-field-value,
.annotation-field-text {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.annotation-field-value a,
.annotation-field-text a {
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* Wrap long audio paths */
.annotation-audio-path,
.annotation-audio-path code,
.annotation-audio-path a {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* Ensure tree container scrolls horizontally without expanding page */
.annotation-tree-container {
  max-width: 100%;
  min-width: 0;
}

/* Ensure table wrapper contains wide tables without page overflow */
.audio-table-wrapper {
  max-width: 100%;
}

/* Mobile-specific fixes */
@media (max-width: 768px) {
  /* Constrain annotation cards and ensure children don't overflow */
  .annotation-card {
    max-width: 100%;
    overflow-x: hidden;
  }

  .annotation-card * {
    max-width: 100%;
  }

  /* Ensure annotation card containers allow wrapping */
  .annotation-card,
  .annotation-card .card-body,
  .annotation-card .card-content {
    min-width: 0;
  }

  /* Force normal wrapping for code and text in cards */
  .annotation-card pre,
  .annotation-card code,
  .annotation-card .annotation-field-value,
  .annotation-card .annotation-field-text {
    white-space: normal;
  }

  /* Fix inline field values (like ID) to wrap downward instead of overlapping */
  .annotation-field--inline {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 0.5rem;
  }

  .annotation-field-value--inline {
    text-align: left;
    justify-self: start;
    margin-top: 0.25rem;
  }

  /* Keep label styling consistent on mobile */
  .annotation-field--inline .annotation-field-label {
    width: fit-content;
  }

  /* Ensure audio table wrapper has proper margins on mobile */
  .audio-table-wrapper {
    margin-left: 0;
    margin-right: 0;
  }

}


/* Make ID field bold and prominent in Firebase Annotations */
.annotation-card .annotation-field:first-child .annotation-field-label,
.annotation-card .annotation-field:first-child .annotation-field-value {
  font-weight: 700;
  font-size: 1.1rem;
}

.annotation-card .annotation-field:first-child .annotation-field-label {
  background: rgba(37, 99, 235, 0.18);
}

.annotation-card .annotation-field:first-child .annotation-field-value {
  color: var(--primary-dark);
}

/* ==============================================
 * Mobile-specific tweaks for Annotation page
 * - Hide Annotated + MSID columns in audio table
 * - Compact table layout and wrap long paths
 * - Stack IMSLP result actions and make them full-width
 * ============================================== */
@media (max-width: 768px) {
  /* Audio sources table: hide Annotated (2) and Music Source ID (5) */
  .audio-table th:nth-child(2),
  .audio-table td:nth-child(2),
  .audio-table th:nth-child(5),
  .audio-table td:nth-child(5) {
    display: none;
  }

  /* Make table more compact and allow smaller width */
  .audio-table {
    min-width: 520px; /* allow tighter fit on mobile than the desktop 720px */
    table-layout: fixed;
    font-size: 0.9rem;
  }

  .audio-table th,
  .audio-table td {
    padding: 0.6rem 0.7rem;
    vertical-align: middle;
  }

  /* Column widths using original indices:
     1=Select, 3=Preview, 4=Audio path (flex) */
  .audio-table th:nth-child(1),
  .audio-table td:nth-child(1) {
    width: 84px; /* widen to avoid overlap with Select button */
  }

  .audio-table th:nth-child(3),
  .audio-table td:nth-child(3) {
    width: 140px;
  }

  .audio-table th:nth-child(4),
  .audio-table td:nth-child(4) {
    width: auto;
  }

  /* Constrain audio player in Preview column (minimal controls look) */
  .audio-table td:nth-child(3) audio {
    width: 120px;
    max-width: 40vw; /* ensure it fits narrow screens */
    height: 28px;
    display: inline-block;
    overflow: hidden;
  }
  /* Hide timeline and less-crucial controls in WebKit-based browsers */
  .audio-table td:nth-child(3) audio::-webkit-media-controls-timeline,
  .audio-table td:nth-child(3) audio::-webkit-media-controls-current-time-display,
  .audio-table td:nth-child(3) audio::-webkit-media-controls-time-remaining-display,
  .audio-table td:nth-child(3) audio::-webkit-media-controls-seek-back-button,
  .audio-table td:nth-child(3) audio::-webkit-media-controls-seek-forward-button,
  .audio-table td:nth-child(3) audio::-webkit-media-controls-volume-slider {
    display: none !important;
  }

  /* Wrap long audio paths */
  .audio-table td:nth-child(4),
  .audio-table td:nth-child(4) code {
    white-space: normal;
    word-break: break-all;
    overflow-wrap: anywhere;
    display: block;
  }

  /* Slightly smaller small buttons inside the table */
  .audio-table .button.small {
    font-size: 0.85rem;
    padding: 0.35rem 0.5rem;
  }

  /* Keep horizontal scroll available if still needed */
  .audio-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* IMSLP results: stack title and actions; make buttons full-width */
  .annotation-result-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .annotation-result-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .annotation-result-actions .button {
    width: 100%;
    min-width: 0;
  }

  /* Ensure the form wrapper doesn't shrink to content so its button can fill width */
  .annotation-result-actions .annotation-select-form {
    display: block;
    width: 100%;
  }
  .annotation-result-actions .annotation-select-form .button {
    width: 100%;
  }
}

/* Music source register */
.music-source-card {
  display: grid;
  gap: 1rem;
}

.music-source-results {
  display: grid;
  gap: 1.25rem;
}

.music-source-results__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.music-source-results__ids {
  display: grid;
  gap: 0.75rem;
  min-width: 240px;
}

.music-source-results__ids .annotation-code {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.id-row {
  display: grid;
  gap: 0.25rem;
}

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

.meta-tile {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  background: var(--surface-muted);
  min-height: 110px;
}

.meta-label {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.meta-value {
  margin: 0;
  font-weight: 600;
  line-height: 1.4;
  word-break: break-word;
}

.music-source-results__movements {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  display: grid;
  gap: 0.75rem;
}

.music-source-results__movements-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.movement-heading {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.movement-list {
  margin: 0;
  padding-left: 0;
  display: grid;
  gap: 0.75rem;
}

.movement-row {
  display: grid;
  grid-template-columns: 1fr;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.15);
}

.movement-row__info {
  display: grid;
  gap: 0.5rem;
}

.movement-row__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.movement-row__label {
  margin: 0;
  font-weight: 700;
  color: var(--text-muted);
}

.movement-row__fields {
  display: grid;
  gap: 0.35rem;
  grid-template-columns: minmax(120px, 160px) minmax(220px, 1fr);
}

.movement-field {
  display: grid;
  gap: 0.25rem;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid rgba(208, 215, 227, 0.8);
}

.movement-field-input {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
}

.movement-field-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.movement-field-value {
  font-weight: 700;
  color: var(--text);
}

.movement-upload-field {
  align-self: stretch;
}

.movement-upload-row {
  width: 100%;
}

.movement-upload-controls {
  display: grid;
  gap: 0.35rem;
}

.movement-upload.is-uploaded {
  background: #f9e79f;
  border-color: #f1c40f;
  color: #5d4b00;
}

.movement-upload.is-disabled {
  background: #fff;
  border-color: var(--border);
  color: var(--text-muted);
  pointer-events: none;
  cursor: not-allowed;
}

.movement-upload.is-pending {
  background: #e8f7ec;
  border-color: #2ecc71;
  color: #1b5e20;
}

.movement-upload__name {
  font-size: 0.9rem;
  color: var(--text-muted);
  word-break: break-word;
}

.movement-upload__status {
  font-size: 0.9rem;
  color: var(--text-muted);
  word-break: break-word;
}

.movement-upload__audio-id {
  display: grid;
  gap: 0.25rem;
  align-items: center;
}

.movement-upload__audio-id-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.movement-upload__audio-id-value {
  max-width: 100%;
  overflow-wrap: anywhere;
  display: inline-block;
}

.movement-audio {
  display: grid;
  gap: 0.35rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid rgba(208, 215, 227, 0.8);
}

.movement-audio__label {
  margin: 0;
  font-weight: 700;
  color: var(--text-muted);
}

.movement-audio__player {
  width: 100%;
}

.movement-audio__hint {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.movement-upload__status.is-error {
  color: var(--danger, #b91c1c);
  font-weight: 700;
}

.movement-upload__status.is-pending {
  color: var(--primary, #2563eb);
  font-weight: 500;
}

.movement-upload-meta {
  display: grid;
  gap: 0.35rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  background: #fff;
  border: 1px dashed rgba(37, 99, 235, 0.3);
}

.movement-upload-meta__field {
  display: grid;
  gap: 0.25rem;
  font-weight: 600;
  color: var(--text);
}

.movement-upload-meta__input {
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  width: 100%;
}

.movement-upload-meta__textarea {
  min-height: 110px;
  resize: vertical;
}

.movement-nonpd {
  display: grid;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.movement-nonpd__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.movement-nonpd__title {
  margin: 0;
  font-weight: 700;
  color: var(--text);
}

.movement-nonpd__status {
  margin: 0;
  font-size: 0.92rem;
  color: var(--danger, #b91c1c);
  font-weight: 600;
}

.movement-nonpd__status.is-detected {
  color: var(--primary);
}

.movement-nonpd__hint {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.movement-nonpd__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.movement-nonpd__option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  color: var(--text);
}

.movement-nonpd__option input {
  accent-color: var(--primary);
}

@media (max-width: 640px) {
  .movement-row__fields {
    grid-template-columns: minmax(0, 1fr);
  }
  .movement-upload-row {
    grid-column: 1 / -1;
  }
  .movement-upload-controls .button {
    width: 100%;
  }
}

.sticky-audio {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(135deg, #0f172a, #13274b 45%, #0b224b);
  color: #fff;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 -12px 32px rgba(6, 14, 26, 0.35);
}

.sticky-audio__inner {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: auto;
  gap: 0.75rem;
}

.sticky-audio__controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.sticky-audio__controls select {
  flex: 1 1 260px;
  min-width: 200px;
  max-width: 420px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 0.55rem 0.7rem;
  font-size: 1rem;
  backdrop-filter: blur(10px);
}

.sticky-audio__controls select:disabled {
  opacity: 0.7;
}

.sticky-audio__status {
  margin: 0;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.78);
  max-width: 640px;
}

.sticky-audio__status.is-error {
  color: #fecaca;
}

.sticky-audio__status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.4);
}

.sticky-audio__status-dot.is-ready {
  background: #22c55e;
}

.sticky-audio__status-dot.is-loading {
  background: #fbbf24;
}

.sticky-audio__status-dot.is-missing {
  background: #f87171;
}

.sticky-audio__player {
  width: 100%;
  display: flex;
}

.sticky-audio__player audio {
  width: 100%;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0.25rem;
}

.sticky-audio-spacer {
  height: 30px;
  pointer-events: none;
}

@media (max-width: 640px) {
  /* Mobile: music source register tweaks */
  main.container {
    padding: 1.5rem 1rem 4rem;
  }

  .card.music-source-card,
  .card.music-source-results {
    padding: 1.25rem;
  }

  .music-source-results__header {
    flex-direction: column;
    align-items: stretch;
  }

  .music-source-results__ids {
    width: 100%;
    min-width: 0;
  }

  .music-source-results__grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }

  .music-source-results__movements-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .movement-accordion {
    padding: 0.9rem;
    overflow: hidden;
  }

  .movement-accordion__actions {
    width: 100%;
    justify-content: flex-start;
  }

  .movement-accordion__actions .button {
    flex: 1 1 140px;
  }

  .movement-highlights__actions {
    width: 100%;
  }

  .movement-highlights__actions .button {
    flex: 1 1 140px;
    min-width: 0;
  }

  .highlight-card__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .highlight-card__actions {
    width: 100%;
  }

  .highlight-card__actions .button {
    flex: 1 1 140px;
  }

  .movement-upload-meta__flag-list {
    flex-wrap: wrap;
  }

  .form-actions {
    justify-content: stretch;
  }

  .form-actions .button {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .sticky-audio__inner {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sticky-audio-spacer {
    height: 40px;
  }
  .sticky-audio__status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}
