/* Background music FAB + settings modal — login / character hub */

.me-fab-dock {
    position: fixed;
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: max(14px, env(safe-area-inset-bottom, 0px));
    z-index: 80;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}

.me-fab-dock > * {
    pointer-events: auto;
}

.me-fab-dock .me-bgm-fab {
    position: relative;
    right: auto !important;
    bottom: auto !important;
}

.me-bgm-fab {
    --gold: #e4c36a;
    position: relative;
    right: auto;
    bottom: auto;
    z-index: 1;
    width: 52px;
    height: 52px;
    padding: 0;
    border: 1px solid rgba(196, 140, 48, .75);
    border-radius: 50%;
    background:
        radial-gradient(circle at 38% 30%, #4a2e14, #140c06 72%);
    cursor: pointer;
    box-shadow:
        0 4px 14px rgba(0, 0, 0, .55),
        inset 0 1px 0 rgba(228, 195, 106, .28),
        0 0 0 2px rgba(20, 12, 6, .55);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    appearance: none;
    -webkit-appearance: none;
    color: #e4c36a !important;
}

.me-bgm-fab:hover,
.me-bgm-fab:focus {
    outline: none;
    color: #f6e7b0;
    border-color: #e4c36a;
    filter: brightness(1.08);
}

.me-bgm-fab svg {
    width: 24px;
    height: 24px;
    display: block;
    pointer-events: none;
}

.me-bgm-fab.is-off::after {
    content: "";
    position: absolute;
    width: 26px;
    height: 2px;
    background: #e4c36a;
    transform: rotate(-32deg);
    box-shadow: 0 0 0 1px rgba(20, 12, 6, .7);
    pointer-events: none;
}

.me-bgm-modal.cs-pick-modal {
    --gold: #e4c36a;
    --gold-deep: #c48c30;
    --cream: #f3e6c8;
    --muted: #cbb89a;
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(4, 2, 1, .64);
    -webkit-backdrop-filter: blur(4px) saturate(.9);
    backdrop-filter: blur(4px) saturate(.9);
}

.me-bgm-modal.cs-pick-modal.is-open {
    display: flex;
}

.me-bgm-modal .cs-pick {
    --gold: #e4c36a;
    --gold-deep: #c48c30;
    --cream: #f3e6c8;
    --muted: #cbb89a;
    display: flex;
    flex-direction: column;
    width: min(440px, 94vw);
    max-height: min(88vh, 820px);
    color: var(--cream);
}

.me-bgm-modal .cs-pick-top,
.me-bgm-modal .cs-pick-bot {
    flex: 0 0 auto;
    width: 100%;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: relative;
}

.me-bgm-modal .cs-pick-top {
    aspect-ratio: 887 / 242;
    background-image: url('../img/charselect/pick-top.png');
    background-position: center top;
}

.me-bgm-modal .cs-pick-bot {
    aspect-ratio: 887 / 152;
    background-image: url('../img/charselect/pick-bot.png');
    background-position: center bottom;
}

.me-bgm-modal .cs-pick-title {
    position: absolute;
    left: 18%;
    right: 18%;
    top: 85%;
    height: auto;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(calc(-50% - 3px));
    font-family: 'TrajanPro-Regular', Georgia, serif;
    font-size: clamp(12px, 3.2vw, 16px);
    font-weight: 400;
    letter-spacing: .1em;
    line-height: 1.15;
    text-transform: uppercase;
    text-align: center;
    color: var(--gold);
    text-shadow: 0 2px 8px rgba(0, 0, 0, .9);
    pointer-events: none;
}

.me-bgm-modal .cs-pick-close {
    position: absolute;
    top: 7%;
    right: 4.5%;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid rgba(196, 140, 48, .7);
    border-radius: 50%;
    background: radial-gradient(circle at 40% 32%, #3a2410, #140c06 72%);
    color: var(--gold);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    text-decoration: none !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(228, 195, 106, .25);
}

.me-bgm-modal .cs-pick-close:hover,
.me-bgm-modal .cs-pick-close:focus {
    color: #fff;
    border-color: var(--gold);
    background: radial-gradient(circle at 40% 32%, #5a3414, #1c1008 72%);
}

.me-bgm-modal .cs-pick-mid {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
    background-image: url('../img/charselect/pick-mid.png');
    background-repeat: repeat-y;
    background-position: center top;
    background-size: 100% auto;
    padding: 8px 18% 14px;
    overflow: visible;
}

.me-bgm-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0;
}

.me-bgm-label {
    font-family: 'TrajanPro-Regular', Georgia, serif;
    font-size: 11px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--gold);
}

.me-bgm-state {
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #cbb89a;
}

.me-bgm-switch {
    position: relative;
    width: 52px;
    height: 28px;
    padding: 0;
    border: 1px solid rgba(196, 140, 48, .65);
    border-radius: 14px;
    background: #120c08;
    cursor: pointer;
    flex-shrink: 0;
    appearance: none;
}

.me-bgm-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #c9a45a;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
    transition: transform .16s ease, background .16s ease;
}

.me-bgm-switch.is-on {
    background: linear-gradient(180deg, #5a3414, #2a180c);
}

.me-bgm-switch.is-on::after {
    transform: translateX(24px);
    background: #e4c36a;
}

.me-bgm-vol {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.me-bgm-vol input[type="range"] {
    width: 100%;
    height: 6px;
    appearance: none;
    -webkit-appearance: none;
    background: linear-gradient(90deg, #3a2410, #c48c30);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.me-bgm-vol input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid #e4c36a;
    background: radial-gradient(circle at 40% 32%, #f3e6c8, #c48c30 70%);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
}

.me-bgm-vol input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid #e4c36a;
    background: #e4c36a;
}

.me-lang-fab-wrap {
    position: relative;
    flex: 0 0 auto;
}
.me-lang-fab-wrap[hidden] { display: none !important; }

.me-discord-icon {
    display: block;
    width: 35px;
    height: 35px;
    background: url('../img/buttons/discord.png') left center / 125px 35px no-repeat;
}
.me-discord-fab { display: none !important; align-items: center; justify-content: center; }
body.me-village-map-page .me-discord-fab { display: inline-flex !important; }
.me-discord-fab::after,
.cs-discord-link::after {
    position: absolute;
    right: 50%;
    bottom: calc(100% + 8px);
    transform: translate(50%, 4px);
    padding: 6px 10px;
    border: 1px solid #ad853e;
    border-radius: 6px;
    background: #21180e;
    box-shadow: 0 4px 10px #0009;
    color: #f7e6b9;
    content: attr(data-tooltip);
    font: 600 12px/1.2 TrajanPro-Regular, Trajan, Georgia, serif;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease, transform .15s ease;
}
.me-discord-fab:hover::after,
.me-discord-fab:focus-visible::after,
.cs-discord-link:hover::after,
.cs-discord-link:focus-visible::after { opacity: 1; transform: translate(50%, 0); }

.me-lang-fab {
    overflow: hidden;
}

.me-lang-fab img {
    display: block;
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 50%;
    pointer-events: none;
    box-shadow: 0 0 0 1px rgba(20, 12, 6, .45);
}

.me-fab-dock > a.me-bgm-fab {
    text-decoration: none;
}

.me-fab-dock > a.me-bgm-fab img {
    display: block;
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 50%;
    pointer-events: none;
}

.me-lang-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 10px);
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 188px;
    padding: 8px;
    border: 1px solid rgba(196, 140, 48, .55);
    border-radius: 12px;
    background:
        linear-gradient(180deg, rgba(42, 24, 12, .96), rgba(14, 8, 4, .96));
    box-shadow:
        0 10px 24px rgba(0, 0, 0, .55),
        inset 0 1px 0 rgba(228, 195, 106, .18);
}

.me-lang-menu[hidden] {
    display: none !important;
}

.me-lang-menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin: 0;
    padding: 7px 8px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 8px;
    background: rgba(0, 0, 0, .35);
    color: #e8e2d2;
    font: 600 13px/1.2 system-ui, sans-serif;
    letter-spacing: .04em;
    text-align: left;
    cursor: pointer;
    appearance: none;
}

.me-lang-menu__item:hover,
.me-lang-menu__item:focus {
    outline: none;
    border-color: rgba(239, 173, 77, .55);
    background: rgba(0, 0, 0, .55);
}

.me-lang-menu__item.is-active,
.me-lang-menu__item:disabled {
    border-color: rgba(239, 173, 77, .85);
    background: linear-gradient(90deg, rgba(140, 55, 12, .35), rgba(0, 0, 0, .45));
    cursor: default;
    opacity: 1;
}

.me-lang-menu__flag {
    flex: 0 0 auto;
    width: 28px;
    height: 20px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .18);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}

.me-lang-menu__flag img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.me-lang-menu__name {
    flex: 1 1 auto;
    min-width: 0;
}

body.cs-page .me-lang-fab-wrap {
    display: none !important;
}

@media (max-width: 699px) {
    html.login-page .me-lang-fab-wrap,
    body.login-page .me-lang-fab-wrap,
    body.cs-page .me-lang-fab-wrap {
        display: none !important;
    }
}

@media (max-width: 420px) {
    .me-bgm-fab {
        width: 46px;
        height: 46px;
    }
    .me-bgm-modal .cs-pick {
        width: min(100%, 420px);
    }
    .me-bgm-modal .cs-pick-mid { padding: 8px 20% 12px; }
    .me-bgm-modal .cs-pick-title { font-size: 12px; letter-spacing: .08em; }
    .me-bgm-modal .cs-pick-close { top: 6%; right: 4%; }
}

body.me-stage-page .me-fab-dock,
body.me-stage-page .me-bgm-fab,
body.me-stage-page .me-bgm-modal,
body.me-summon-page .me-fab-dock,
body.me-summon-page .me-bgm-fab,
body.me-summon-page .me-bgm-modal,
body.me-summon-page .me-lang-fab-wrap {
    display: none !important;
}

/* Keep controls on the village, login/register stage and character selection. */
body:not(.me-village-map-page):not(.cs-page):not(.login-page) [data-bgm-fab],
body:not(.me-village-map-page):not(.cs-page):not(.login-page) .me-bgm-modal {
    display: none !important;
}
