/* Online metronome (online_metronome). Сцена — оригинальный flash-арт 728×616, масштабируется
   целиком (transform: scale на .mtrn__scene, высоту обёртки держит JS). Накладные элементы
   позиционируются в px СЦЕНЫ (координаты из config.php через index.php inline-style).
   Цвета кнопок/меню/поля сняты пипеткой с арта, вытащенного из Metronome_en.swf. Префикс .mtrn. */


/* --- Сцена --- */

.mtrn {
    position: relative;
    max-width: calc(var(--mtrn-w) * 1px);
    margin: 0 auto;
    overflow: hidden;
    /* высоту ставит JS по масштабу */
    height: auto;
}

.mtrn__scene {
    position: relative;
    transform-origin: 0 0;
    user-select: none;
    -webkit-user-select: none;
}

.mtrn__bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: block;
}

/* --- Маятник --- */

.mtrn__pendulum {
    position: absolute;
    transform: translateX(-50%);
    /* rotate ставит JS из setInterval-шедулера; шаг ~25 мс сглаживает transition */
    transition: transform 60ms linear;
    will-change: transform;
    pointer-events: none;
    z-index: 2;
}

/* невидимая зона захвата штока: наклонить и отпустить — запуск качания */
.mtrn__rodgrip {
    position: absolute;
    left: 50%;
    top: 0;
    height: 100%;
    transform: translateX(-50%);
    pointer-events: auto;
    touch-action: none;
    cursor: grab;
}

.mtrn__rodgrip:active { cursor: grabbing; }

.mtrn__rod {
    position: absolute;
    /* полоса внутри png смещена (центр 14.25px из 37) — компенсация, чтобы центр полосы = ось */
    left: 4px;
    top: 0;
    pointer-events: none;
    /* шток входит в прорезь (верх ямки y=424, low-координата 349) и растворяется в её темноте */
    /* шток целиком, с родным чётким концом: сверху его перекрывает накладка-зажим (cap.png
       с альфой), снизу — накладка-борт ямки (slot_front); масок-растворений нет */
}

.mtrn__weight {
    position: absolute;
    transform: translateX(-50%);
    transition: transform 60ms linear; /* синхронно со штоком */
    z-index: 6; /* поверх штока, красного зажима и крышки */
    /* left — inline (ось), top и rotate ставит JS по BPM и фазе качания */
    display: flex;
    align-items: flex-start; /* арт прижат к верху зоны: над грузиком захватывается ШТОК, не грузик */
    justify-content: center;
    background: none;
    border: 0;
    padding: 0;
    cursor: grab;
    pointer-events: auto;
    touch-action: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.mtrn__weight.is-dragging { cursor: grabbing; }

.mtrn__weight img {
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
    /* клики ловит только зона-див (от видимого верха): прозрачные поля PNG не перехватывают шток */
    pointer-events: none;
}

.mtrn__weight:hover img,
.mtrn__weight:focus-visible img { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35)) brightness(1.06); }

/* --- Накладки (колпачок и крышка поверх маятника) --- */

.mtrn__overlay {
    position: absolute;
    pointer-events: none;
    z-index: 3;
}

/* --- Громкость (динамик + жёлоб + оранжевый заполнитель + бегунок) --- */

.mtrn__volume {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    touch-action: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    padding: 6px 4px; /* щедрее тач-зона */
}

.mtrn__volume-speaker { display: block; }

/* жёлоб рисуется CSS-пилюлей (не артом) — полоса и бегунок выровнены с ним по построению */
.mtrn__volume-track {
    position: relative;
    display: block;
    height: 16px;
    border-radius: 8px;
    background: linear-gradient(180deg, #241f1c 0%, #3a332e 85%, #4a423c 100%);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.7), 0 1px 0 rgba(255, 255, 255, 0.08);
}

.mtrn__volume-fill {
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(180deg, #ffc23e 0%, #f79a00 100%);
    pointer-events: none;
    /* ширину ставит JS по громкости */
}

/* Бегунок — белая точка, как во flash-оригинале */
.mtrn__volume-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ffffff 0%, #e8e6e0 60%, #b9b6ae 100%);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    /* left ставит JS по громкости */
}

/* --- Кнопки в стиле арта (Start/Stop, Tap): тёмная кожаная клавиша, цвета с арта SWF --- */

.mtrn__btn {
    position: absolute;
    background: linear-gradient(180deg, #5a5249 0%, #4a433c 55%, #38332e 100%);
    border: 1px solid #26221e;
    border-radius: 6px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 1px 2px rgba(0, 0, 0, 0.5);
    color: #ece7dc;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.55);
}

.mtrn__btn:hover { filter: brightness(1.08); }

.mtrn__btn:active,
.mtrn__btn.is-pressed {
    background: linear-gradient(180deg, #332f2a 0%, #423c35 60%, #4a433c 100%);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
    transform: translateY(1px);
}

/* Tap: короткая вспышка при тапе */
.mtrn__tap.is-tapped { filter: brightness(1.25); }

/* --- Поле BPM + спиннер --- */

.mtrn__bpm { position: absolute; display: block; }

/* поле BPM в оригинале — ТЁМНАЯ клавиша с белыми цифрами (сверено по крупному композиту) */
.mtrn__bpm-input {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    background: linear-gradient(180deg, #575047 0%, #453f38 55%, #36312c 100%);
    border: 1px solid #26221e;
    border-radius: 6px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), inset 0 -2px 5px rgba(0, 0, 0, 0.35);
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 24px;
    color: #f2eee4;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.55);
    outline: none;
    padding: 0 4px;
}

/* спиннер — тёмный столбик-кнопка со стрелками вплотную (как в оригинале); размеры — inline из config */
.mtrn__spinner {
    position: absolute;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, #575047 0%, #453f38 55%, #36312c 100%);
    border: 1px solid #26221e;
    border-radius: 6px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.mtrn__spin {
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 15px;
}

.mtrn__spin img { display: block; }
.mtrn__spin:hover img { filter: brightness(1.2); }
.mtrn__spin:active img { filter: brightness(0.8); }

/* --- Шестерёнка --- */

/* шестерёнка: тёмная клавиша на всё гнездо, иконка из арта — native-размер по центру (не растягивать) */
.mtrn__cog {
    position: absolute;
    background: linear-gradient(180deg, #5a5249 0%, #4a433c 55%, #38332e 100%);
    border: 1px solid #26221e;
    border-radius: 8px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 1px 2px rgba(0, 0, 0, 0.5);
    padding: 0;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mtrn__cog img { display: block; }
.mtrn__cog:hover img { filter: brightness(1.12); }
.mtrn__cog:active img,
.mtrn__cog[aria-expanded="true"] img { filter: brightness(0.85); }

/* --- Переключатель такта (• / 2/4 / 3/4 / 4/4) --- */

.mtrn__beats {
    position: absolute;
    transform: translateX(-50%); /* строка по центру под корпусом */
    display: flex;
    gap: 8px;
    z-index: 5;
}

.mtrn__beats-opt {
    /* компактнее и чуть контрастнее фона (просьба владельца): светлее корпус, светлая кромка */
    background: linear-gradient(180deg, #4a443c 0%, #38332c 100%);
    border: 1px solid #262119;
    border-radius: 4px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    color: #b6ac9a;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 12px;
    line-height: 1;
    padding: 4px 0;
    min-width: 36px;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    text-align: center;
}

.mtrn__beats-opt:hover { color: #ded7c9; }

.mtrn__beats-opt.is-active {
    color: #f2a93b;
    background: linear-gradient(180deg, #2b2721 0%, #221e19 100%);
    border-color: #4d4438; /* светлый контур — вдавленная кнопка не сливается с фоном */
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.55);
}

/* --- Точки-удары такта --- */

.mtrn__dots {
    position: absolute;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 12px;
    pointer-events: none;
    z-index: 4;
}

.mtrn__dots[hidden] { display: none; }

.mtrn__dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #241f1b;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8), 0 1px 0 rgba(255, 255, 255, 0.06);
    transition: background-color 0.06s linear;
}

.mtrn__dot.is-on { background: #efe8d8; box-shadow: 0 0 8px rgba(239, 232, 216, 0.7); }
.mtrn__dot.is-accent.is-on { background: #f2a93b; box-shadow: 0 0 10px rgba(242, 169, 59, 0.85); }

/* --- Подпись темпа (Largo… Prestissimo) --- */

.mtrn__tempo-name {
    position: absolute;
    transform: translateX(-50%);
    color: #b3a88e; /* светлее — читаемо в тёмной зоне над корпусом */
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 19px;
    font-style: italic;
    letter-spacing: 0.08em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    white-space: nowrap;
}

/* --- Меню звуков (2 колонки, как во flash) --- */

.mtrn__menu {
    position: absolute;
    transform: translateX(-50%);
    width: 336px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-flow: column; /* заполнение по колонкам, как в оригинале */
    gap: 1px;
    background: #3e3831;
    border: 1px solid #26221e;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
    z-index: 10;
}

.mtrn__menu-item {
    background: #4a433c;
    border: 0;
    color: #d6d0c4;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 14px;
    line-height: 1;
    padding: 7px 6px;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mtrn__menu-item:hover { background: #554d44; }

.mtrn__menu-item.is-active { color: #f2a93b; }

/* --- Мобильная панель: крупные альтернативы (видна только на узких экранах) --- */

.mtrn__mobilebar {
    display: none;
    gap: 6px;
    justify-content: center;
    margin-top: 10px;
}

.mtrn__mb-btn {
    background: linear-gradient(180deg, #5a5249 0%, #4a433c 55%, #38332e 100%);
    border: 1px solid #26221e;
    border-radius: 8px;
    color: #ece7dc;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 18px;
    line-height: 1;
    min-width: 46px;
    min-height: 44px;
    padding: 0 12px;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.mtrn__mb-btn:active { box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5); }

.mtrn__mb-start { min-width: 74px; }

.mtrn__mb-bpm {
    width: 62px;
    min-height: 44px;
    box-sizing: border-box;
    background: linear-gradient(180deg, #cfc9ba 0%, #efeadd 40%, #e7e1d2 100%);
    border: 1px solid #221e1a;
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.28);
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 19px;
    font-weight: 700;
    color: #33291d;
    outline: none;
}

/* заплатка панели без кнопок — только на мобайле */
.mtrn__slotcover { display: none; }

/* инфо-табличка на передней панели (мобайл) — латунный шильдик по макету владельца:
   кремовая латунь, двойная рамка, ромбик-орнамент снизу, коричнево-золотой текст */
.mtrn__panelinfo {
    display: none;
    position: absolute;
    transform: translateX(-50%);
    z-index: 4;
    flex-direction: column;
    align-items: center;
    gap: 0;
    /* ровно геометрия зоны старых кнопок (заплатки slot_cover 410×68): закрывает её собой,
       углами не свисает — панель в этой зоне гарантированно плоская */
    width: 410px;
    height: 68px;
    box-sizing: border-box;
    justify-content: center;
    padding: 0 0 4px;
    background: linear-gradient(180deg, #e9dcba 0%, #e0d1a9 55%, #d2c093 100%);
    border: 1px solid #7d5f36;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 250, 230, 0.55);
    pointer-events: none;
    font-family: Georgia, 'Times New Roman', serif;
    text-align: center;
    white-space: nowrap;
}

/* внутренняя тонкая рамка шильдика */
.mtrn__panelinfo::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px solid #b09257;
    border-radius: 3px;
    pointer-events: none;
}

/* ромбик-орнамент — сидит НА нижней линии внутренней рамки */
.mtrn__panelinfo::after {
    content: '◆';
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    font-size: 9px;
    line-height: 9px;
    color: #96773e;
    background: #d5c397;
    padding: 0 7px;
}

.mtrn__panelinfo-main {
    font-size: 27px;
    font-style: italic;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #6e4f16;
    text-shadow: 0 1px 0 rgba(255, 250, 225, 0.5);
}

.mtrn__panelinfo-sub {
    font-size: 13px;
    letter-spacing: 0.22em;
    color: #6d5729;
    text-shadow: 0 1px 0 rgba(255, 250, 225, 0.45);
}

@media (max-width: 575.98px) {
    .mtrn__mobilebar {
        display: flex;
        flex-direction: column;
        align-items: center;
        position: relative; /* якорь меню звуков (раскрывается вверх, над прибором) */
    }

    .mtrn__slotcover { display: block; }
    .mtrn__panelinfo { display: flex; }

    /* сцена очищается от ВСЕХ элементов управления — они в панели снизу */
    .mtrn__volume,
    .mtrn__bpm,
    .mtrn__spinner,
    .mtrn__btn,
    .mtrn__cog,
    .mtrn__tempo-name { display: none; }

    /* ряд управления во всю ширину: темп слева, Старт по центру, звук справа */
    .mtrn__mb-row {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: center;
        gap: 6px;
    }

    .mtrn__mb-group { display: flex; gap: 6px; }

    .mtrn__mb-cog {
        font-size: 20px;
        color: #d6d0c4;
        min-width: 54px;
    }

    /* такты: компактнее основных кнопок, блок подписан легендой */
    .mtrn__mb-beatswrap {
        margin: 12px 0 0;
        padding: 2px 12px 9px;
        border: 1px solid #3a352f;
        border-radius: 9px;
        min-width: 0;
    }

    .mtrn__mb-beatslabel {
        float: none;
        width: auto;
        font-size: 11px;
        letter-spacing: 0.05em;
        color: #8d8474;
        padding: 0 7px;
        margin: 0;
    }

    .mtrn__mb-beatswrap .mtrn__beats {
        position: static;
        transform: none;
        justify-content: center;
        gap: 7px;
    }

    .mtrn__mb-beatswrap .mtrn__beats-opt {
        min-width: 42px;
        padding: 6px 0;
        font-size: 12px;
    }

    /* меню звуков: раскрывается ВВЕРХ, поверх прибора (как на десктопе от шестерёнки).
       !important — инлайновые left/bottom сценического позиционирования надо перебить */
    .mtrn__mb-extra .mtrn__menu {
        position: absolute;
        bottom: calc(100% + 8px) !important;
        left: 50% !important;
        transform: translateX(-50%);
        width: 100%;
        z-index: 30;
    }

    .mtrn__mb-extra .mtrn__menu-item {
        font-size: 15px;
        padding: 11px 6px;
    }
}

/* --- Подсказка клавиатуры --- */

.mtrn-keys {
    text-align: center;
    color: var(--tls-muted, #6c757d);
    font-size: 0.85rem;
    margin: 0.6rem auto 0;
}

/* --- Explain (How it works) --- */





@media (prefers-reduced-motion: reduce) {
    .mtrn__pendulum { transition: none; }
}
