body {
    overflow: auto;
}

.pageMain--melodySearch {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.03));
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
    overflow: visible;
}

.panelHead {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.panelHead h2 {
    margin: 0;
    font-size: 18px;
}

.panelSub {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.panelBody {
    padding: 18px;
}

.melodySearchForm {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 12px;
    align-items: flex-end;
}

.searchField {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 0 0 auto;
}

.searchField--abc {
    min-width: 360px;
    flex: 1 1 620px;
}

.searchField--limit {
    min-width: 220px;
}

.searchField label {
    font-size: 14px;
    opacity: 0.75;
    color: var(--muted);
    font-weight: 600;
}

.searchField textarea,
.searchField select {
    border: 1px solid rgba(255, 255, 255, 0.13);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
}

.searchField textarea {
    width: 100%;
    min-height: 92px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    line-height: 1.45;
    font-size: larger;
    border-color: rgba(96, 165, 250, 0.22);
    background: rgba(10, 20, 40, 0.55);
}

.searchField select {
    min-width: 140px;
    height: 38px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: #172033;
    border: 1px solid rgba(96, 165, 250, 0.3);
    color: #e5e7eb;
    padding: 0 38px 0 12px;
    font-weight: 600;
    cursor: pointer;
    background-image:
        linear-gradient(45deg, transparent 50%, #bfdbfe 50%),
        linear-gradient(135deg, #bfdbfe 50%, transparent 50%);
    background-position:
        calc(100% - 20px) 16px,
        calc(100% - 14px) 16px;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

.searchField select:hover {
    border-color: rgba(96, 165, 250, 0.55);
    background-color: #1d2a42;
}

.searchField select,
.searchField select option,
#sortModeSelect option {
    background-color: #111827;
    color: #e5e7eb;
}

.searchField textarea:focus,
.searchField select:focus,
#resultsFilterInput:focus,
#sortModeSelect:focus {
    outline: none;
    border-color: rgba(96, 165, 250, 0.75);
    background-color: rgba(255, 255, 255, 0.07);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.16);
}

.inputHint {
    min-height: 18px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.inputHint.is-error {
    color: #fca5a5;
}

.inputHint.is-ok {
    color: #86efac;
}

.searchActions {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-start;
    margin-left: auto;
}

#resetBtn,
#exampleBtn,
.primaryBtn {
    height: 38px;
    padding: 0 14px;
    border-radius: 10px;
    font-weight: 700;
    border: 1px solid var(--stroke);
    cursor: pointer;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}

.primaryBtn {
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.30), rgba(59, 130, 246, 0.22));
    border-color: rgba(96, 165, 250, 0.55);
    color: #dbeafe;
    letter-spacing: 0.01em;
}

#resetBtn:hover,
#exampleBtn:hover,
.primaryBtn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.primaryBtn:hover {
    background: rgba(96, 165, 250, 0.26);
    border-color: rgba(96, 165, 250, 0.55);
}

.rangeControl {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 38px;
    background: #172033;
    border: 1px solid rgba(96, 165, 250, 0.3);
    border-radius: 10px;
    padding: 0 12px;
}

#resultLimitRange {
    flex: 1 1 auto;
    accent-color: #60a5fa;
    cursor: pointer;
}

#resultLimitValue {
    min-width: 42px;
    text-align: center;
    font-size: 13px;
    font-weight: 800;
    color: #dbeafe;
    border-radius: 999px;
    padding: 4px 10px;
    background: rgba(96, 165, 250, 0.12);
    border: 1px solid rgba(96, 165, 250, 0.35);
}

.summaryCards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.summaryCard {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 14px;
    padding: 8px 14px;
}

.summaryCardLabel {
    font-size: 12px;
    color: var(--muted);
}

.summaryCardValue {
    margin-top: 4px;
    font-size: 24px;
    font-weight: 800;
    line-height: 1.05;
}

.summaryBadges--filters {
    justify-content: flex-end;
}

.resultsToolbar {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    margin-bottom: 14px;
    width: 100%;
    min-width: 0;
}

.resultsToolGroup {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}


.resultsToolGroup--filter {
    flex: 1 1 auto;
    order: 2;
}

.resultsToolGroup--sort {
    flex: 0 0 240px;
    order: 1;
}

.resultsToolbar label {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    white-space: nowrap;
    margin: 0;
}

#resultsFilterInput,
#sortModeSelect {
    height: 40px;
    max-height: 40px;
    box-sizing: border-box;
    border-radius: 12px;
    font-size: 14px;
}

#resultsFilterInput {
    width: 100%;
    min-width: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    padding: 0 14px;
}

#resultsFilterInput::placeholder {
    color: rgba(255, 255, 255, 0.45);
}

#resultsFilterInput:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

#sortModeSelect {
    display: block;
    width: 100%;
    min-width: 0;
    border: 1px solid rgba(96, 165, 250, 0.28);
    background-color: #172033;
    color: #e5e7eb;
    padding: 0 38px 0 14px;
    font-weight: 700;
    line-height: 40px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, #bfdbfe 50%),
        linear-gradient(135deg, #bfdbfe 50%, transparent 50%);
    background-position:
        calc(100% - 20px) 17px,
        calc(100% - 14px) 17px;
    background-size:
        6px 6px,
        6px 6px;
    background-repeat: no-repeat;
}

#sortModeSelect:hover {
    border-color: rgba(96, 165, 250, 0.55);
    background-color: #1d2a42;
}

#sortModeSelect option {
    background-color: #111827;
    color: #e5e7eb;
}

#resultsFilterInput:focus,
#sortModeSelect:focus {
    outline: none;
    border-color: rgba(96, 165, 250, 0.75);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.16);
}

@media (max-width: 700px) {
    .resultsToolbar {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
        width: 100%;
    }

    .resultsToolGroup {
        width: 100%;
        min-width: 0;
    }

    .resultsToolGroup--filter,
    .resultsToolGroup--sort {
        width: 100%;
        flex: 0 0 auto;
    }

    .resultsToolbar label {
        margin-top: 0;
    }

    #resultsFilterInput,
    #sortModeSelect {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        height: 44px;
        font-size: 16px;
        box-sizing: border-box;
    }

    .resultsToolbar .helpTooltip {
        left: -40px;
        width: min(340px, calc(100vw - 28px));
    }
}

.melodyResults {
    display: grid;
    gap: 12px;
}

.melodyCard {
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 16px;
    padding: 14px;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.melodyCard:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(96, 165, 250, 0.25);
    transform: translateY(-1px);
}

.melodyCardHead {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.melodyTitleBlock {
    min-width: 0;
}

.melodyTitleRow {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.melodyTuneName {
    color: #93c5fd;
    font-size: 24px;
    font-weight: 800;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.melodyTuneName:hover {
    color: #bfdbfe;
    text-decoration: underline;
}

.melodyMeta {
    margin-top: 4px;
    color: #45b6ba;
    font-size: 13px;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.melodyCardRight {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex: 0 0 auto;
}

.scorePill {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    min-height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    border: 1px solid rgba(96, 165, 250, 0.35);
    background: rgba(96, 165, 250, 0.12);
    color: #bfdbfe;
}

.matchPills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.matchPill {
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
}

.matchPill--good {
    border-color: rgba(34, 197, 94, 0.35);
    background: rgba(34, 197, 94, 0.12);
    color: #bbf7d0;
}

.matchPill--warn {
    border-color: rgba(245, 158, 11, 0.35);
    background: rgba(245, 158, 11, 0.12);
    color: #fde68a;
}

.sampleMatch {
    margin-top: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.18);
    border-radius: 12px;
    padding: 10px 12px;
}

.sampleMatchLabel {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 5px;
}

.sampleMatchCode {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    color: #e5eef8;
    font-size: 14px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.cardLinks {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.cardLink {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(96, 165, 250, 0.35);
    background: rgba(96, 165, 250, 0.12);
    color: #bfdbfe;
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.cardLink:hover {
    background: rgba(96, 165, 250, 0.22);
    border-color: rgba(96, 165, 250, 0.55);
    color: #dbeafe;
    text-decoration: none;
}

.sessionIconLink {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.06);
    transition: all 0.15s ease;
    flex: 0 0 auto;
}

.sessionIconLink:hover {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.3);
    transform: translateY(-1px);
}

.sessionIconLink img {
    width: 22px;
    height: 22px;
    display: block;
    object-fit: contain;
}

.emptyState,
.errorState,
.loadingState {
    padding: 10px 0;
    color: var(--muted);
    font-size: 14px;
}

.errorState {
    color: #fca5a5;
}

.labelWithHelp {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.helpIcon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: rgba(96, 165, 250, 0.14);
    border: 1px solid rgba(96, 165, 250, 0.35);
    color: #bfdbfe;
    font-size: 11px;
    font-weight: 700;
    cursor: help;
    user-select: none;
}

.helpTooltip {
    position: absolute;
    left: 50%;
    top: calc(100% + 10px);
    transform: translateX(-50%);
    width: min(380px, calc(100vw - 40px));
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #dbe7f5;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 200;
    text-align: left;
}

.helpTooltip strong {
    color: #ffffff;
}

.helpTooltip code {
    color: #bfdbfe;
}

.helpIcon:hover .helpTooltip,
.helpIcon:focus-within .helpTooltip {
    opacity: 1;
}

.snippetPlayButtons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.playBtn {
    appearance: none;
    border: none;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #fff;
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    min-width: 86px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    transition: all 0.15s ease;
}

.playBtn:hover {
    transform: translateY(-1px);
    background: linear-gradient(135deg, #34d399, #22c55e);
}

.playBtn:active {
    transform: scale(0.97);
}

.playBtn.is-playing {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.snippetPlayBtnB {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
}

.snippetPlayBtnB:hover {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.playIcon {
    font-size: 15px;
    line-height: 1;
}

.playText {
    font-size: 13px;
}

.snippetScore {
    margin-top: 12px;
    background: #fff;
    color: #111;
    border-radius: 12px;
    padding: 8px 12px;
    overflow-x: auto;
    min-height: 90px;
}

.snippetScore svg {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    margin: 0 !important;
}

.snippetScore svg text {
    fill: #111 !important;
    opacity: 1 !important;
}

.snippetAudio {
    margin-top: 8px;
}

.resultSectionTitle {
    margin: 20px 0 10px;
    font-size: 18px;
    font-weight: 800;
    color: #dbeafe;
}

.resultSectionSub {
    margin-top: -4px;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

@media (max-width: 900px) {
    .melodySearchForm {
        align-items: stretch;
    }

    .searchField,
    .searchField--abc {
        flex: 1 1 calc(50% - 12px);
        min-width: 180px;
    }

    .searchActions {
        margin-left: 0;
    }

    .summaryCards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

}

@media (max-width: 700px) {
    .pageMain--melodySearch {
        gap: 12px;
    }

    .summaryPanel {
        display: none;
    }

    .panel {
        border-radius: 14px;
    }

    .panelHead {
        padding: 14px;
        flex-direction: column;
    }

    .panelBody {
        padding: 14px;
    }

    .searchField,
    .searchField--abc,
    .searchField--limit {
        flex: 1 1 100%;
        min-width: 100%;
    }

    .searchField textarea {
        min-height: 120px;
        font-size: 16px;
    }

    .searchField select {
        width: 100%;
        min-width: 100%;
        height: 44px;
        font-size: 16px;
    }

    .rangeControl {
        width: 100%;
    }

    .searchActions {
        flex: 1 1 100%;
        margin-left: 0;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .searchActions .primaryBtn {
        grid-column: 1 / -1;
    }

    .searchActions button {
        width: 100%;
        height: 44px;
    }

    .resultsToolbar label {
        margin-top: 0;
    }

    .resultsToolbar label[for="sortModeSelect"] {
        margin-left: 0;
    }

    #resultsFilterInput,
    #sortModeSelect {
        width: 100%;
        min-width: 0;
        height: 44px;
        font-size: 16px;
    }

    .melodyCard {
        padding: 12px;
        border-radius: 14px;
    }

    .melodyCardHead {
        flex-direction: column;
        gap: 10px;
    }

    .melodyTitleRow {
        align-items: flex-start;
    }

    .melodyTuneName {
        font-size: 19px;
        line-height: 1.2;
    }

    .melodyMeta {
        font-size: 12px;
    }

    .melodyCardRight {
        width: 100%;
        align-items: stretch;
    }

    .scorePill {
        align-self: flex-start;
    }

    .matchPills {
        gap: 6px;
    }

    .matchPill {
        font-size: 11px;
        padding: 5px 8px;
    }

    .sampleMatch {
        padding: 9px 10px;
    }

    .sampleMatchCode {
        font-size: 13px;
    }

    .snippetPlayButtons {
        width: 100%;
        justify-content: stretch;
        flex-wrap: nowrap;
    }

    .snippetPlayButtons .playBtn {
        flex: 1 1 0;
        min-width: 0;
        justify-content: center;
    }

    .cardLinks {
        display: grid;
        grid-template-columns: 1fr;
    }

    .cardLink {
        min-height: 36px;
    }

    .snippetScore {
        padding: 6px;
        min-height: 70px;
    }
}

@media (max-width: 420px) {
    .melodyTuneName {
        font-size: 18px;
    }

    .sessionIconLink,
    .sessionIconLink img {
        width: 20px;
        height: 20px;
    }

    .searchActions {
        grid-template-columns: 1fr;
    }

    .playBtn {
        padding-left: 10px;
        padding-right: 10px;
    }
}

.resultsToolbar .helpTooltip {
    left: 0;
    right: auto;
    transform: none;
    width: min(380px, calc(100vw - 32px));
    max-width: 380px;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: normal;
}

.resultsToolbar .helpTooltip * {
    white-space: normal;
    overflow-wrap: break-word;
}

.primaryBtn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    pointer-events: none;
    transform: none !important;
    filter: grayscale(0.15);
}

.primaryBtn:disabled:hover {
    background: rgba(96, 165, 250, 0.18);
    border-color: rgba(96, 165, 250, 0.35);
}


.searchPanel .panelBody {
    padding: 16px 18px;
}

.melodySearchForm {
    display: grid;
    grid-template-columns: minmax(420px, 1fr) 150px 150px 150px 210px auto;
    gap: 10px 12px;
    align-items: end;
}

.searchField--abc {
    grid-row: span 2;
    min-width: 0;
}

.searchField textarea {
    min-height: 118px;
}

.searchField--limit {
    grid-column: 5;
}

.searchSpeedHint {
    grid-column: 2 / -1;
    align-self: start;
    margin-top: -2px;
    padding: 8px 12px;
    border-radius: 10px;

    border: 1px solid rgba(34, 197, 94, 0.22);
    background: linear-gradient(90deg,
            rgba(34, 197, 94, 0.14),
            rgba(16, 185, 129, 0.08));

    color: #bbf7d0;

    box-shadow:
        0 0 0 1px rgba(34, 197, 94, 0.04),
        0 4px 18px rgba(34, 197, 94, 0.08);

    font-size: 14px;
    line-height: 1.4;
}

.searchActions {
    margin-left: 0;
    align-self: end;
}

@media (max-width: 1200px) {
    .melodySearchForm {
        grid-template-columns: 1fr 150px 150px 150px;
    }

    .searchField--abc {
        grid-column: 1 / -1;
        grid-row: auto;
    }

    .searchField--limit {
        grid-column: auto;
    }

    .searchSpeedHint {
        grid-column: 1 / -1;
    }

    .searchActions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 700px) {
    body {
        overflow-x: hidden;
    }

    .header {
        width: 100%;
        padding-left: 10px;
        padding-right: 10px;
    }

    .leftHead {
        width: 100%;
        min-width: 0;
        gap: 8px;
        align-items: flex-start;
    }

    .leftHead>div {
        min-width: 0;
        flex: 1 1 auto;
    }

    .homeBtn,
    .statsBtn {
        width: 34px;
        height: 48px;
        flex: 0 0 34px;
    }

    h1 {
        font-size: 21px;
        line-height: 1.2;
        overflow-wrap: anywhere;
    }

    .pageMain--melodySearch {
        width: 100%;
        max-width: 100vw;
        padding-left: 10px;
        padding-right: 10px;
        overflow-x: hidden;
    }

    .searchPanel .panelBody {
        padding: 14px;
    }

    .melodySearchForm {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        width: 100%;
        min-width: 0;
    }

    .searchField,
    .searchField--abc,
    .searchField--limit,
    .searchActions,
    .searchSpeedHint {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
    }

    .searchField--abc {
        grid-row: auto;
    }

    .searchField textarea,
    .searchField select,
    .rangeControl,
    .searchActions button {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .inputHint,
    .searchSpeedHint {
        overflow-wrap: anywhere;
    }

    .searchActions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
    }

    .searchActions .primaryBtn {
        grid-column: 1 / -1;
    }

    .resultsPanel {
        min-width: 0;
    }
}

@media (max-width: 420px) {
    .header {
        padding-top: 10px;
    }

    .leftHead {
        gap: 6px;
    }

    .homeBtn,
    .statsBtn {
        width: 28px;
        height: 46px;
        flex-basis: 28px;
    }

    .homeBtn svg,
    .statsBtn svg {
        width: 16px;
        height: 16px;
    }

    h1 {
        font-size: 19px;
    }

    .panelBody,
    .searchPanel .panelBody {
        padding: 12px;
    }
}