@font-face {
    font-family: 'Crimson Text';
    src:
        url('../assets/fonts/crimson-roman-webfont.woff2') format('woff2'),
        url('../assets/fonts/crimson-roman-webfont.woff') format('woff');
    font-weight: 400;
}

@font-face {
    font-family: 'Crimson Text';
    src:
        url('../assets/fonts/crimson-italic-webfont.woff2') format('woff2'),
        url('../assets/fonts/crimson-italic-webfont.woff') format('woff');
    font-weight: 400;
    font-style: italic;
}

@font-face {
    font-family: 'Crimson Text';
    src:
        url('../assets/fonts/crimson-bold-webfont.woff2') format('woff2'),
        url('../assets/fonts/crimson-bold-webfont.woff') format('woff');
    font-weight: 700;
}

@font-face {
    font-family: 'Versiculum';
    src: url('../assets/versiculum.ttf') format('truetype');
    font-weight: 400;
}

/* ── Clickable notes and syllables ──────────────────────────────────────── */
#chantPreview svg use[source-index],
#chantPreview svg text[source-index] {
    cursor: pointer;
}

/* Hover highlight */
#chantPreview svg use[source-index]:hover {
    fill: #3b82f6;
}

#chantPreview svg text[source-index]:hover {
    fill: #1d4ed8;
}

/* Active highlight during selection / playback */
#chantPreview svg use[source-index].active {
    fill: #2563eb;
}

#chantPreview svg text[source-index].active {
    fill: #1e40af;
    font-weight: bold;
}

/* ── Floating chant toolbar ──────────────────────────────────────────────── */
.chant-toolbar {
    position: absolute;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: #fffcf7;
    border: 1px solid #c4b09a;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgb(74 26 18 / 16%);
    padding: 6px 8px;
    min-width: 170px;
    font-family: system-ui, sans-serif;
}

.toolbar-row {
    display: flex;
    gap: 3px;
}

.toolbar-btn {
    border: none;
    border-radius: 5px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.4;
    transition: filter 0.1s;
}

.toolbar-btn:hover {
    filter: brightness(0.92);
}

.toolbar-btn-primary {
    background: #2563eb;
    color: #fff;
    width: 100%;
    text-align: center;
}

.toolbar-btn-primary-inline {
    background: #2563eb;
    color: #fff;
}

.toolbar-btn-success {
    background: #7a4a1e;
    color: #fff;
    flex: 0 0 auto;
}

.toolbar-btn-info {
    background: #c9973a;
    color: #1a1208;
    flex: 1 1 auto;
    text-align: center;
}

.toolbar-btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
}

.toolbar-pitch-info {
    font-size: 11px;
    line-height: 1.5;
}

.toolbar-pitch-info sub {
    font-size: 9px;
}

.preview-header-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 8px 12px;
}

.preview-pitch-display {
    flex: 0 0 auto;
    pointer-events: none;
    cursor: default;
}

.toolbar-do-label {
    font-size: 11px;
    color: #374151;
    text-align: center;
    padding: 2px 0;
    border-top: 1px solid #e5e7eb;
    margin-top: 1px;
}

/* ── Media controls bar ──────────────────────────────────────────────────── */
#mediaControls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 16px;
    background: #fdf8f0;
    border-top: 1px solid #c4b09a;
    box-shadow: 0 -2px 8px rgb(74 26 18 / 10%);
    font-family: system-ui, sans-serif;
}

#mediaControls.hidden {
    display: none;
}

.mc-btn {
    border: none;
    border-radius: 5px;
    padding: 5px 12px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
    transition: filter 0.1s;
}

.mc-btn:hover {
    filter: brightness(0.88);
}

.mc-btn-primary {
    background: #2563eb;
    color: #fff;
}

.mc-btn-default {
    background: #e8d5b0;
    color: #1a1208;
}

.mc-btn-danger {
    background: #dc2626;
    color: #fff;
}

#bpmDisplay {
    font-size: 12px;
    color: #3d2b1f;
    min-width: 60px;
    text-align: center;
}

/* ── Editor alignment track ──────────────────────────────────────────────── */
.editor-alignment-track {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    min-height: 20px;
    background: #f5ede0;
    border: 1px solid #c4b09a;
    border-radius: 4px;
    padding: 2px 6px;
}

.track-chip {
    font-size: 11px;
    font-family: ui-monospace, monospace;
    line-height: 1.6;
}

.track-chip-matched {
    background: #f5e6cc;
    color: #1e3a8a;
    padding: 0 5px;
    border-radius: 3px;
}

.track-chip-overflow {
    background: #fee2e2;
    color: #b91c1c;
    padding: 0 5px;
    border-radius: 3px;
}

.track-chip-empty {
    color: #c4b09a;
    padding: 0 3px;
}

.track-chip-barline {
    color: #a09080;
    padding: 0 3px;
}

.track-chip-cursor {
    background: #dbeafe;
    color: #1e3a8a;
    padding: 0 5px;
    border-radius: 3px;
}

.editor-melody-input-overflow {
    background: #fee2e2;
    border-color: #fca5a5;
}

.editor-melody-input-strophic {
    background: #f3f4f6;
}

/* ── Word groups in alignment track ──────────────────────────────────────── */

/* Chips that share the same wordIdx are wrapped in .track-word-group so they
   appear visually connected — making same-word (e.g. _ tie) groupings obvious. */
.track-word-group {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border-radius: 3px;
    overflow: hidden;
}

.track-word-group .track-chip-matched,
.track-word-group .track-chip-cursor {
    border-radius: 0;
    border-right: 1px solid rgb(196 176 154 / 55%);
}

.track-word-group .track-chip-matched:last-child,
.track-word-group .track-chip-cursor:last-child {
    border-right: none;
}

/* ── GABC Summary link ───────────────────────────────────────────────────── */
.op-gabc-summary-link {
    margin-left: 32px;
    font-family: 'Crimson Text', Georgia, serif;
    font-style: italic;
    font-size: 11.5px;
    color: #f5c040;
    text-decoration: none;
    letter-spacing: 0.02em;
    opacity: 0.88;
    white-space: nowrap;
    cursor: pointer;
    transition: opacity 0.15s;
}

.op-gabc-summary-link:hover {
    opacity: 1;
}

/* ── GABC Summary popup dialog ───────────────────────────────────────────── */
#gabcSummaryDialog {
    width: 82vw;
    height: 90vh;
    max-width: 1000px;
    border: none;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 8px 40px rgb(74 26 18 / 40%);
    overflow: hidden;
}

#gabcSummaryDialog[open] {
    display: flex;
    flex-direction: column;
}

#gabcSummaryDialog::backdrop {
    background: rgb(26 18 8 / 55%);
}

.gabc-summary-dialog-header {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    background: #3d1a10;
}

.gabc-summary-dialog-title {
    font-family: 'Cinzel', serif;
    font-size: 12px;
    color: #e8d5b0;
    letter-spacing: 0.08em;
}

.gabc-summary-dialog-close {
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 500;
    background: transparent;
    border: 1px solid rgb(196 168 130 / 40%);
    border-radius: 4px;
    color: #e8d5b0;
    cursor: pointer;
    transition: background 0.15s;
}

.gabc-summary-dialog-close:hover {
    background: rgb(196 168 130 / 15%);
}

.gabc-summary-dialog-iframe {
    flex: 1;
    width: 100%;
    border: none;
    display: block;
}

/* ── Dominican site header ───────────────────────────────────────────────── */
.op-tool-nav-link {
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    color: #a09080;
    text-decoration: none;
    transition: color 0.15s;
    white-space: nowrap;
}

.op-tool-nav-link:hover {
    color: #e8d5b0;
}

.op-tool-nav-link.active {
    color: #fdf8f0;
    border-bottom-color: #c9973a;
}

.op-export-btn {
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid rgb(196 168 130 / 50%);
    border-radius: 4px;
    color: #e8d5b0;
    background: transparent;
    cursor: pointer;
    transition:
        background 0.15s,
        border-color 0.15s;
    white-space: nowrap;
}

.op-export-btn:hover {
    background: rgb(196 168 130 / 15%);
    border-color: #c4a882;
}

.op-export-btn:active {
    background: rgb(196 168 130 / 25%);
}

.op-tab-action-btn {
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid #c4b09a;
    border-radius: 4px;
    color: #5a3e2b;
    background: transparent;
    cursor: pointer;
    transition:
        background 0.15s,
        border-color 0.15s;
    white-space: nowrap;
}

.op-tab-action-btn:hover {
    background: rgb(196 168 130 / 20%);
    border-color: #a08060;
}

.op-tab-action-btn:active {
    background: rgb(196 168 130 / 35%);
}

.op-export-btn-primary {
    border-color: rgb(96 165 250 / 70%);
    color: #93c5fd;
}

.op-export-btn-primary:hover {
    background: rgb(59 130 246 / 15%);
    border-color: #60a5fa;
}

/* ── Persistence modals ───────────────────────────────────────────────────── */
.op-modal-panel {
    background: #fdf8f0;
    border: 1px solid #c4b09a;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgb(74 26 18 / 22%);
    padding: 20px 22px;
    min-width: 340px;
    max-width: 480px;
}

.op-modal-panel::backdrop {
    background: rgb(26 18 8 / 45%);
}

.op-modal-title {
    font-size: 13px;
    font-weight: 600;
    color: #1a1208;
    margin-bottom: 12px;
    font-family: 'Cinzel', serif;
}

.op-modal-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.op-modal-input {
    flex: 1;
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid #c4b09a;
    border-radius: 4px;
    background: #fdf8f0;
    color: #3d2b1f;
    outline: none;
}

.op-modal-input:focus {
    border-color: #c9973a;
    box-shadow: 0 0 0 2px rgb(201 151 58 / 20%);
}

.op-modal-error {
    font-size: 11px;
    color: #dc2626;
    margin-bottom: 8px;
    min-height: 14px;
}

.op-modal-list {
    max-height: 220px;
    overflow-y: auto;
    border-top: 1px solid #e8d5b0;
    margin-top: 10px;
    padding-top: 6px;
}

.op-modal-list-empty {
    font-size: 12px;
    color: #8c7660;
    text-align: center;
    padding: 12px 0;
}

.op-modal-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid #e8d5b0;
    font-size: 12px;
    color: #3d2b1f;
}

.op-modal-list-item:last-child {
    border-bottom: none;
}

.op-modal-list-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.op-modal-btn {
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid transparent;
    white-space: nowrap;
    transition: background 0.12s;
}

.op-modal-btn-primary {
    background: #7a1c10;
    color: #fdf8f0;
    border-color: #7a1c10;
}

.op-modal-btn-primary:hover {
    background: #5c1509;
}

.op-modal-btn-primary.confirming {
    background: #c05621;
    border-color: #c05621;
}

.op-modal-btn-primary.confirming:hover {
    background: #9c4318;
}

.op-modal-btn-ghost {
    background: transparent;
    color: #7a5c3e;
    border-color: #c4b09a;
}

.op-modal-btn-ghost:hover {
    background: rgb(196 168 130 / 15%);
}

.op-modal-btn-danger {
    background: transparent;
    color: #dc2626;
    border-color: transparent;
    padding: 3px 6px;
    font-size: 13px;
    line-height: 1;
}

.op-modal-btn-danger:hover {
    background: rgb(220 38 38 / 8%);
}

/* ── Mobile responsive ───────────────────────────────────────────────────── */

/* Use dvh so the layout respects browser chrome (address bar) on mobile */
@supports (height: 100dvh) {
    @media (width <= 767px) {
        body {
            height: 100dvh !important;
        }
    }
}

/* Collapse 3-column header to 2-column on mobile (right export column is hidden) */
@media (width <= 767px) {
    .op-header {
        grid-template-columns: auto 1fr !important;
    }
}

/* Stack the two editor/preview panes on mobile using CSS grid overlay.
   visibility:hidden preserves clientWidth so Exsurge renders at the correct width
   even when the preview pane isn't visible yet. */
@media (width <= 767px) {
    main.mobile-two-pane {
        display: grid !important;
        grid-template-rows: 1fr;
    }

    main.mobile-two-pane > section {
        grid-area: 1 / 1;
        min-width: 0;
        width: 100%;
    }

    main.mobile-two-pane > section.mobile-hidden {
        visibility: hidden;
        pointer-events: none;
    }

    /* Hide keyboard shortcut badges on small screens */
    .op-kbd {
        display: none !important;
    }
}

/* The KBD styling from our previous step, refined for this palette */
.op-kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    padding: 1px 5px;
    margin-left: 6px;
    font-family: ui-monospace, monospace;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    background-color: rgb(255 255 255 / 15%);
    border: 1px solid rgb(255 255 255 / 30%);
    border-radius: 4px;
    box-shadow: 0 1px 0 rgb(0 0 0 / 20%);
    transition: transform 0.1s ease;
}
