/* Clef note finder (/:lang/apps/clef-notes and its /embed).
 *
 * Self-contained on purpose: the embed loads this file and nothing else from
 * the site, so the widget may not lean on .mt-btn or the Bootstrap theme.
 * Served from /apps/tools/src/ like the other tool scripts; the relative font
 * path keeps the /{version}/ prefix in production (see games.css). */

@font-face {
    font-family: 'Bravura';
    src: url('../../../public/fonts/bravura-subset.woff2') format('woff2'),
         url('../../../public/fonts/bravura-subset.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: block;
}

.cn-widget {
    --cn-ink: #1c2333;
    --cn-soft: #5b6474;
    --cn-muted: #8b93a5;
    --cn-rule: #e3e7ee;
    --cn-paper: #ffffff;
    --cn-bg: #f7f8fb;
    --cn-accent: #3f51b5;
    --cn-accent-soft: #e8ebf7;
    --cn-guide: #b9c1d3;
    color: var(--cn-ink);
    background: var(--cn-bg);
    border: 1px solid var(--cn-rule);
    border-radius: 12px;
    padding: 14px;
    margin: 16px 0 0;
    font-size: 15px;
    line-height: 1.45;
    box-sizing: border-box;
}
.cn-widget *, .cn-widget *::before, .cn-widget *::after { box-sizing: border-box; }

/* ---------------------------------------------------------------- controls */
.cn-controls { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 0 0 12px; }
.cn-seg { display: inline-flex; border: 1px solid var(--cn-rule); border-radius: 8px; overflow: hidden;
    background: var(--cn-paper); }
.cn-btn { appearance: none; -webkit-appearance: none; border: 0; background: var(--cn-paper);
    color: var(--cn-ink); padding: 8px 12px; font: inherit; font-size: 14px; font-weight: 600;
    cursor: pointer; line-height: 1.2; min-height: 36px; }
.cn-seg .cn-btn + .cn-btn { border-left: 1px solid var(--cn-rule); }
.cn-btn:hover { background: var(--cn-accent-soft); }
.cn-btn[aria-pressed="true"] { background: var(--cn-accent); color: #fff; }
.cn-btn:focus-visible { outline: 2px solid var(--cn-accent); outline-offset: 2px; }
.cn-acc .cn-btn { min-width: 40px; font-size: 18px; padding: 4px 10px; }
.cn-check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--cn-soft);
    cursor: pointer; user-select: none; }
.cn-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--cn-accent); }
.cn-field { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--cn-soft); }
.cn-field select { font: inherit; font-size: 14px; padding: 5px 8px; border: 1px solid var(--cn-rule);
    border-radius: 8px; background: var(--cn-paper); color: var(--cn-ink); }

/* ------------------------------------------------------------ staff + answer */
.cn-stage { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
@media (min-width: 720px) {
    .cn-stage { grid-template-columns: minmax(0, 440px) minmax(180px, 1fr); }
}
.cn-staff { position: relative; background: var(--cn-paper); border: 1px solid var(--cn-rule);
    border-radius: 10px; padding: 4px; }
/* Reserve the drawn height before the script runs, so the page does not jump:
   the aspect ratios match the viewBoxes clef-notes.coffee draws. */
.cn-staff[data-mode="grand"] { aspect-ratio: 200 / 234; }
.cn-staff[data-mode="treble"], .cn-staff[data-mode="bass"] { aspect-ratio: 200 / 124; }
.cn-staff svg { display: block; width: 100%; height: 100%; touch-action: manipulation;
    cursor: pointer; -webkit-tap-highlight-color: transparent; }
.cn-staff svg:focus { outline: none; }
.cn-staff svg:focus-visible { outline: 2px solid var(--cn-accent); outline-offset: 2px; border-radius: 6px; }
.cn-staff noscript p { margin: 12px; color: var(--cn-soft); font-size: 14px; }

.cn-line { stroke: var(--cn-ink); }
.cn-guide { stroke: var(--cn-guide); stroke-dasharray: 2 2; }
.cn-glyph { fill: var(--cn-ink); }
.cn-fallback { fill: none; stroke: var(--cn-ink); stroke-linecap: round; }
.cn-fallback-dot { fill: var(--cn-ink); }
.cn-note { fill: var(--cn-accent); }
.cn-note-ledger { stroke: var(--cn-accent); }
.cn-note-label { fill: var(--cn-accent); font-weight: 700; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; }
.cn-ghost { fill: var(--cn-muted); opacity: 0.45; pointer-events: none; }
.cn-label { fill: var(--cn-soft); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; }
.cn-label.is-on { fill: var(--cn-accent); font-weight: 700; }

.cn-answer { background: var(--cn-paper); border: 1px solid var(--cn-rule); border-radius: 10px;
    padding: 12px 14px; min-height: 120px; }
.cn-answer__eyebrow { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--cn-muted); font-weight: 600; }
.cn-answer__name { margin: 2px 0 0; font-size: 44px; font-weight: 700; line-height: 1.05; color: var(--cn-accent); }
.cn-answer__oct { font-size: 24px; margin-left: 2px; }
.cn-answer__line { margin: 4px 0 0; font-size: 15px; }
.cn-answer__where { margin: 6px 0 0; font-size: 16px; font-weight: 600; }
.cn-answer__middle { display: inline-block; margin: 8px 0 0; padding: 2px 10px; border-radius: 20px;
    background: var(--cn-accent-soft); color: var(--cn-accent); font-size: 13px; font-weight: 700; }
.cn-answer__also { margin: 6px 0 0; font-size: 14px; color: var(--cn-soft); }
.cn-answer [hidden] { display: none !important; }
.cn-nudge { display: flex; gap: 6px; margin-top: 10px; }
.cn-nudge .cn-btn { border: 1px solid var(--cn-rule); border-radius: 8px; min-width: 44px; font-size: 16px; }

/* ------------------------------------------------------------------ keyboard */
.cn-keys-wrap { margin-top: 12px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
    border-radius: 8px; }
.cn-keys { position: relative; height: 118px; min-width: 100%; user-select: none;
    -webkit-user-select: none; }
.cn-keys__whites { display: flex; height: 100%; }
.cn-key { appearance: none; -webkit-appearance: none; border: 0; padding: 0; margin: 0; font: inherit;
    cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.cn-key--white { flex: 1 0 24px; background: #fff; border: 1px solid #2b3040; border-left-width: 0;
    border-radius: 0 0 5px 5px; display: flex; align-items: flex-end; justify-content: center;
    padding-bottom: 6px; color: var(--cn-soft); font-size: 11px; font-weight: 600; }
.cn-key--white:first-child { border-left-width: 1px; }
.cn-key--black { position: absolute; top: 0; height: 62%; background: #2b3040; border-radius: 0 0 4px 4px;
    z-index: 2; color: #fff; font-size: 10px; display: flex; align-items: flex-end;
    justify-content: center; padding-bottom: 4px; }
.cn-key--white:hover { background: #f1f3fb; }
.cn-key--black:hover { background: #3c4358; }
.cn-key.is-on { background: var(--cn-accent); color: #fff; }
.cn-key--white.is-on { background: var(--cn-accent); }
.cn-key:focus-visible { outline: 2px solid var(--cn-accent); outline-offset: -3px; }
.cn-key__label { pointer-events: none; white-space: nowrap; }

.cn-hint { margin: 10px 0 0; font-size: 13px; color: var(--cn-muted); }

/* ------------------------------------------------------------- reference */
.cn-ref-wrap { overflow-x: auto; }
.cn-ref td.cn-note-cell { font-weight: 700; }
.cn-ref tr.is-line td:first-child::before { content: ''; display: inline-block; width: 16px; height: 0;
    border-top: 2px solid #1c2333; vertical-align: middle; margin-right: 8px; }
.cn-ref tr.is-space td:first-child::before { content: ''; display: inline-block; width: 16px; height: 0;
    margin-right: 8px; }
.cn-ref tr.is-middle td { background: var(--mt-accent-soft, #e8ebf7); }
.cn-mnem { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px;
    margin: 12px 0; padding: 0; list-style: none; }
.cn-mnem li { background: #fff; border: 1px solid #e3e7ee; border-radius: 10px; padding: 12px 14px; }
.cn-mnem__label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
    color: #8b93a5; font-weight: 600; }
.cn-mnem__phrase { display: block; margin-top: 4px; font-size: 16px; }
.cn-mnem__phrase b { color: #3f51b5; }
.cn-mnem__notes { display: block; margin-top: 2px; font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 14px; color: #5b6474; letter-spacing: 0.08em; }
.cn-next { border: 1px solid #e3e7ee; border-radius: 12px; background: #fff; padding: 18px 20px; }
.cn-next h2 { margin-top: 0; }
.cn-next-cta { display: inline-block; padding: 10px 18px; border-radius: 8px; color: #fff; font-weight: 600;
    text-decoration: none; background: linear-gradient(135deg, #5a4fd9, #3d35b5); }
.cn-next-cta:hover, .cn-next-cta:focus { color: #fff; text-decoration: none; opacity: 0.92; }
.cn-embed-box summary { cursor: pointer; font-weight: 600; }
.cn-embed-box textarea { width: 100%; min-height: 96px; margin: 10px 0 8px; font-family: Menlo, Consolas, monospace;
    font-size: 12px; border: 1px solid #e3e7ee; border-radius: 8px; padding: 10px; }
.cn-embed-copied { color: #2e7d32; font-size: 13px; font-weight: 600; margin-left: 8px; }

/* --------------------------------------------------------------- embed page */
.cn-embed { min-width: 300px; padding: 8px 8px 0; }
.cn-embed .cn-widget { margin: 0; }
.cn-embed__bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 0;
    padding: 6px 12px; background: #fff; border: 1px solid #e3e7ee; border-radius: 10px;
    font-size: 14px; font-weight: 600; }
.cn-embed__brand { text-decoration: none; }
.cn-embed__wordmark { font-family: 'Lobster Two', Georgia, serif; font-style: italic; font-weight: 700;
    font-size: 22px; color: #111; line-height: 1; }
.cn-embed__brand:hover .cn-embed__wordmark { color: #000; }
.cn-embed__title { color: #3a3a44; text-decoration: none; }
.cn-embed__title:hover { color: #3f51b5; text-decoration: underline; }

@media (max-width: 480px) {
    .cn-widget { padding: 10px; }
    .cn-answer__name { font-size: 38px; }
    .cn-btn { padding: 7px 9px; font-size: 13px; }
}

/* ---------------------------------------------------- middle C reference */
.cn-mark { fill: #b35c00; }
.cn-mark-ledger { stroke: #b35c00; }
.cn-mark-label { fill: #b35c00; font-weight: 700; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    paint-order: stroke; stroke: #fff; stroke-width: 2.4px; stroke-linejoin: round; }
.cn-label, .cn-note-label { paint-order: stroke; stroke: #fff; stroke-width: 2.4px; stroke-linejoin: round; }
.cn-key--white.is-ref { background: #fbe5cc; color: #8a4600; }
.cn-key--white.is-ref .cn-key__label { font-weight: 700; }
.cn-staff[data-mode="alto"] { aspect-ratio: 200 / 124; }
@media (max-width: 480px) {
    /* Four clef buttons: two rows of two on a phone. */
    #cn-mode { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
    #cn-mode .cn-btn + .cn-btn { border-left: 0; }
    #cn-mode .cn-btn:nth-child(even) { border-left: 1px solid var(--cn-rule); }
    #cn-mode .cn-btn:nth-child(n+3) { border-top: 1px solid var(--cn-rule); }
}
.cn-ref td.is-mid { color: #b35c00; }
.cn-staff .cn-static-svg { cursor: default; }

/* ------------------------------------------------ compact embed on a phone */
/* The iframe has one fixed height, so the tall states must stay short. */
.cn-embed .cn-hint { display: none; }
.cn-embed .cn-keys { height: 96px; }
@media (max-width: 719px) {
    .cn-embed .cn-controls { margin-bottom: 8px; }
    .cn-embed .cn-answer { min-height: 0; padding: 8px 12px; display: grid;
        grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; }
    .cn-embed .cn-answer__eyebrow { display: none; }
    .cn-embed .cn-answer > div[aria-live] { display: contents; }
    .cn-embed .cn-answer__name { font-size: 32px; grid-row: 1 / span 3; margin: 0; }
    .cn-embed .cn-answer__oct { font-size: 18px; }
    .cn-embed .cn-answer__where { margin: 0; font-size: 14px; }
    .cn-embed .cn-answer__line { margin: 0; font-size: 12px; }
    .cn-embed .cn-answer__middle { margin: 2px 0 0; font-size: 11px; justify-self: start; }
    .cn-embed .cn-answer__also { display: none; }
    .cn-embed .cn-nudge { grid-column: 1 / span 2; margin-top: 6px; }
    .cn-embed .cn-nudge .cn-btn { min-height: 32px; padding: 4px 10px; }
}
