/* Знаки нотного письма (ключи, диезы, бемоли) — вырезка из Noto Music, SIL OFL. */
@font-face {
    font-family: 'Noto Music';
    src: url('fonts/noto-music.woff2') format('woff2');
    font-display: block;
}

:root {
    --accent: #ffc107;  /* нажатая или ожидаемая нота */
    --hint: #4dd0e1;    /* подсказка и воспроизведение */
    --done: #6fcf97;    /* сыгранные ноты */
    --miss: #ff6b6b;
}

html, body {
    height: 100%;
    overflow: hidden;
    /* Жесты на инструменте не должны тянуть и обновлять страницу. */
    overscroll-behavior: none;
    /* На странице нечего выделять. Запрет нужен везде, а не только на
       инструменте: iOS по долгому нажатию выделяет ближайший текст, даже
       если палец стоит не на нём, и показывает лупу и меню «Скопировать». */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* В полях ввода выделение нужно: без него в iOS в них нельзя печатать. */
input, textarea, select {
    user-select: text;
    -webkit-user-select: text;
}

body {
    background-color: #1c1f24;
    background-image: radial-gradient(ellipse at top, #2a2f37 0%, #1c1f24 60%, #15171b 100%);
    -webkit-tap-highlight-color: transparent;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* без адресной строки мобильного браузера */
    /* Вырез и скругления экрана телефона в пейзажной ориентации. */
    padding: .5rem max(.5rem, env(safe-area-inset-right)) max(.5rem, env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left));
    gap: .5rem;
}

.bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .375rem;
}

.bar .btn, .bar .form-select {
    white-space: nowrap;
}

.bar-melody {
    flex: 1 1 6rem;
    min-width: 0;
    display: flex;
    gap: .4rem;
    text-align: left;
}

.bar-melody #title {
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-note {
    color: var(--accent);
}

.bar-input {
    width: auto;
}

.bar-play {
    display: inline-flex;
    gap: .35em;
}

/* Значок вместо подписи — для узких экранов, см. ниже. */
.bar-icon {
    display: none;
}

/* Телефон в пейзаже: с подписями панель не помещается в строку. */
@media (max-width: 920px) {
    .bar-text {
        display: none;
    }

    .bar-icon {
        display: inline;
    }
}

.stage {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .5rem;
}

/* ——— Полоса с мелодией */

.strip {
    position: relative;
    flex: 1 1 auto;
    min-height: 88px;
    max-height: 230px;
}

.notation {
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: .5rem;
    background: rgba(0, 0, 0, .28);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .2) transparent;
}

.notation svg {
    display: block;
}

.strip-status {
    position: absolute;
    top: .25rem;
    right: .6rem;
    font-size: .75rem;
    color: rgba(255, 255, 255, .5);
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

.st-line {
    stroke: rgba(255, 255, 255, .32);
    stroke-width: 1;
}

.st-clef, .st-alter {
    font-family: 'Noto Music', serif;
}

.st-clef {
    fill: rgba(255, 255, 255, .75);
}

.st-alter {
    fill: currentColor;
    text-anchor: end;
}

.nt {
    color: #dfe3e8;
    cursor: pointer;
}

.nt-hit {
    fill: transparent;
}

.nt-head, .nt-dot, .nt-letter {
    fill: currentColor;
}

/* Пустая головка (половинная, целая), штиль и флажок. */
.nt-open, .nt-flag {
    fill: none;
    stroke: currentColor;
}

.nt-stem {
    stroke: currentColor;
    stroke-width: 1.4;
}

.nt-flag {
    stroke-linecap: round;
}

.st-rest {
    font-family: 'Noto Music', serif;
    fill: rgba(255, 255, 255, .6);
    text-anchor: middle;
}

.nt .st-line {
    stroke: currentColor;
    opacity: .6;
}

.nt-letter {
    text-anchor: middle;
    dominant-baseline: central;
    font-size: 16px;
    font-weight: 600;
}

.nt.done {
    color: var(--done);
}

.nt.current {
    color: var(--accent);
}

.nt.current .nt-hit {
    fill: rgba(255, 193, 7, .13);
}

.nt.playing {
    color: var(--hint);
}

.nt.playing .nt-hit {
    fill: rgba(77, 208, 225, .13);
}

.nt.miss {
    color: var(--miss);
    animation: shake .35s;
}

@keyframes shake {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.praise {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
    border-radius: .5rem;
    background: rgba(21, 23, 27, .86);
    color: var(--accent);
    font-size: clamp(1.25rem, 5vh, 2.25rem);
    font-weight: 700;
    text-align: center;
    animation: pop .4s cubic-bezier(.2, 1.6, .4, 1);
}

/* Вторая строка — оценка ритма. */
.praise small {
    font-size: .5em;
    font-weight: 500;
    color: rgba(255, 255, 255, .75);
}

.praise[hidden] {
    display: none;
}

@keyframes pop {
    from { transform: scale(.6); opacity: 0; }
}

/* ——— Инструменты */

.instrument {
    flex: 0 0 auto;
    height: clamp(150px, 46vh, 360px);
    /* Жесты на инструменте не должны скроллить, зумить или вызывать меню. */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.piano {
    display: flex;
    gap: .375rem;
}

.piano-keys {
    position: relative;
    flex: 1;
    min-width: 0;
    touch-action: none;
}

.piano-shift {
    flex: 0 0 2.1rem;
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: .375rem;
    background: rgba(255, 255, 255, .06);
    color: rgba(255, 255, 255, .8);
    font-size: 1.5rem;
    line-height: 1;
}

.piano-shift:disabled {
    opacity: .3;
}

.piano-shift.hint {
    border-color: var(--hint);
    color: var(--hint);
    animation: pulse 1s infinite alternate;
}

.key {
    position: absolute;
    top: 0;
}

.key.white {
    height: 100%;
    border: 1px solid #7d776b;
    border-radius: 0 0 5px 5px;
    background: linear-gradient(#e9e5dc, #fbf9f4 10%, #f1ede4);
}

.key.white span {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 5px;
    font-size: .68rem;
    text-align: center;
    color: #8a8478;
    pointer-events: none;
}

.key.black {
    z-index: 1;
    height: 62%;
    border-radius: 0 0 4px 4px;
    background: linear-gradient(#41454d, #111317);
    box-shadow: 0 2px 3px rgba(0, 0, 0, .5);
}

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

/* Промах в режиме подбора. */
.key.wrong {
    background: var(--miss);
}

/* Подсказка — пульсирующая точка внизу клавиши. */
.key.hint::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 22px;
    width: min(56%, 22px);
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--hint);
    transform: translateX(-50%);
    animation: pulse 1s infinite alternate;
}

.key.black.hint::after {
    bottom: 10px;
    width: 62%;
}

@keyframes pulse {
    from { opacity: .45; }
}

.fretboard svg {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.fb-board {
    fill: #35271d;
}

.fb-fret {
    stroke: #a4a9af;
    stroke-width: 2;
}

.fb-nut {
    stroke: #ece6d6;
    stroke-width: 5;
}

.fb-string {
    stroke: #d6cfbb;
}

.fb-inlay {
    fill: rgba(255, 255, 255, .13);
}

.fb-number {
    fill: rgba(255, 255, 255, .45);
    font-size: 10px;
    text-anchor: middle;
}

.fb-hit {
    fill: transparent;
}

/* Точка с названием ноты видна только на нажатом ладу и на подсказке. */
.fb-dot, .fb-label {
    opacity: 0;
    pointer-events: none;
}

.fb-dot {
    fill: var(--accent);
}

.fb-label {
    fill: #1c1f24;
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: central;
}

.fb-cell.hint .fb-dot {
    opacity: 1;
    fill: var(--hint);
    animation: pulse 1s infinite alternate;
}

.fb-cell.active .fb-dot {
    opacity: 1;
    fill: var(--accent);
    animation: none;
}

.fb-cell.wrong .fb-dot {
    fill: var(--miss);
}

.fb-cell.hint .fb-label, .fb-cell.active .fb-label {
    opacity: 1;
}

.rotate-tip {
    display: none;
    margin: 0;
    font-size: .75rem;
    text-align: center;
    color: rgba(255, 255, 255, .45);
}

/* ——— Панели */

.catalog-caption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin: 1rem 0 .4rem;
    font-size: .75rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .5);
}

.catalog-caption:first-child {
    margin-top: 0;
}

.catalog-caption .form-select {
    width: auto;
}

.catalog-item {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    padding: .4rem .6rem;
}

.catalog-item small {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: rgba(255, 255, 255, .5);
}

.catalog-item.active small {
    color: rgba(0, 0, 0, .6);
}

.catalog-mark {
    color: var(--done);
}

.catalog-item.active .catalog-mark {
    color: inherit;
}

.catalog-remove {
    padding: 0 .3rem;
    border: 0;
    background: none;
    color: inherit;
    opacity: .6;
}

.catalog-item.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #1c1f24;
}

.fx {
    margin-top: .75rem;
    padding: .6rem .75rem;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: .5rem;
}

.fx.off .fx-param {
    opacity: .45;
}

.fx-param {
    display: grid;
    grid-template-columns: 4.5rem 1fr 4rem;
    align-items: center;
    gap: .5rem;
    margin-top: .35rem;
    font-size: .8rem;
}

.fx-param output {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, .6);
}

/* Строка струны: номер, полутон вниз, нота, полутон вверх. */
.tune {
    display: grid;
    grid-template-columns: 4.5rem 2.25rem 1fr 2.25rem;
    align-items: center;
    gap: .5rem;
    margin-top: .5rem;
    font-size: .8rem;
}

/* Сдвиг всех струн разом — отдельно от самих струн. */
.tune-all {
    margin-top: .75rem;
    padding-top: .75rem;
    border-top: 1px solid rgba(255, 255, 255, .12);
}

.tune output {
    text-align: center;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, .6);
}

.form-check-input:checked {
    border-color: var(--accent);
    background-color: var(--accent);
}

/* Открытая панель звука на широком экране не накрывает инструмент, а
   сдвигает его: можно крутить ручки и тут же играть. */
@media (min-width: 992px) {
    .app {
        transition: padding-right .3s;
    }

    .sound-open .app {
        padding-right: calc(var(--bs-offcanvas-width, 400px) + .5rem);
    }
}

.form-range::-webkit-slider-thumb {
    background-color: var(--accent);
}

.form-range::-moz-range-thumb {
    background-color: var(--accent);
}

/* ——— Телефон. В пейзаже высоты мало: полоса с нотами сжимается, инструмент
   занимает всё остальное. */
@media (max-height: 480px) {
    .app {
        padding-top: .375rem;
        gap: .375rem;
    }

    .stage {
        gap: .375rem;
    }

    .strip {
        flex: 0 0 88px;
    }

    .instrument {
        flex: 1;
        height: auto;
        min-height: 0;
    }
}

@media (orientation: portrait) and (max-width: 600px) {
    .rotate-tip {
        display: block;
    }
}
