/* Radio dans la nav-bar du chat — panneau type salon / 丁半 */
/*
 * Layout : les 2 boutons d'action (logout / radio) sont
 * répartis à gauche ; le bouton de pliage
 * (chat-collapse-toggle, défini dans chat-collapse-control.css) est
 * repoussé à droite par `margin-left: auto` et séparé visuellement par
 * une bordure subtile à sa gauche. Tous les boutons partagent la même
 * hauteur (42 px) et la même ligne de base, ce qui garantit un
 * alignement vertical strict quel que soit le contenu (SVG, glyphe).
 */
#chat-nav {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: nowrap;
    padding: 10px 12px;
    background: linear-gradient(180deg, #1a0f0a 0%, #0f0a06 100%);
    border-bottom: 1px solid rgba(201, 162, 39, 0.25);
    position: relative;
    overflow: visible;
    z-index: 100;
    isolation: isolate;
    font-family: 'Noto Sans JP', sans-serif;
}

/*
 * Style aligné sur les boutons du canvas Phaser (retour / règles /
 * jumper) : fond noir semi-transparent, icône / glyphe crème, pas de
 * gradient doré. Le DOM utilise les mêmes glyphes ⏻ / ♬ que le dock canvas (cf.
 * phaser-map-runtime.js → attachCanvasChatDockButtons).
 *
 * `flex: 0 0 42px` fige largeur et hauteur (carré régulier) pour que
 * les boutons d'action restent alignés sur la même grille même
 * sur sidebar étroite. Pas de `flex-shrink` — on préfère le scroll
 * horizontal très improbable plutôt qu'un alignement déséquilibré.
 */
.chat-nav-icon-btn {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    color: #e8d5b5;
    cursor: pointer;
    transition: transform 0.15s ease, color 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.18s ease, text-shadow 0.15s ease;
    user-select: none;
    border: 1px solid rgba(201, 162, 39, 0.22);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.32);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
    box-sizing: border-box;
}

/*
 * SVG éventuel sur un bouton nav : `display: block` évite le décalage du baseline.
 */
.chat-nav-icon-btn > svg {
    display: block;
    width: 22px;
    height: 22px;
    pointer-events: none;
    flex-shrink: 0;
}

.chat-nav-icon-btn:hover {
    transform: scale(1.06);
    color: #ffe9b8;
    border-color: rgba(255, 210, 90, 0.7);
    background: rgba(0, 0, 0, 0.55);
    box-shadow:
        0 0 12px rgba(201, 162, 39, 0.4),
        0 0 24px rgba(201, 162, 39, 0.15),
        inset 0 0 8px rgba(255, 210, 90, 0.08);
    text-shadow: 0 0 8px rgba(255, 210, 90, 0.5), 0 1px 2px rgba(0, 0, 0, 0.65);
}

.chat-nav-icon-btn:focus {
    outline: none;
}

.chat-nav-icon-btn:focus-visible {
    outline: 2px solid rgba(201, 162, 39, 0.65);
    outline-offset: 2px;
}

#radio-btn[aria-expanded="true"] {
    color: #ffe9b8;
    border-color: rgba(255, 210, 90, 0.55);
    background: rgba(201, 162, 39, 0.18);
    box-shadow: inset 0 0 0 1px rgba(255, 210, 90, 0.18);
}

/* Notes Lottie : sortent vers le haut depuis le bouton radio (webradio ou 部屋の音楽 actifs). */
#radio-btn {
    overflow: visible;
}
#radio-btn .radio-btn-music-lottie {
    position: absolute;
    left: 50%;
    bottom: 100%;
    width: 155%;
    height: 155%;
    transform: translateX(calc(-50% - 50px)) translateY(-20px) scaleX(-1);
    margin-bottom: -56px;
    pointer-events: none;
    z-index: 6;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.32s ease, visibility 0.32s ease;
    overflow: visible;
}
#radio-btn .radio-btn-music-lottie > svg,
#radio-btn .radio-btn-music-lottie > canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    overflow: visible !important;
}
#radio-btn.is-music-playing .radio-btn-music-lottie {
    opacity: 1;
    visibility: visible;
}

#radio-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    /* 100% = #chat-nav : évite 260px hors colonne quand min(260px,100vw) reste 260 */
    width: min(260px, calc(100% - 8px));
    min-width: min(200px, 100%);
    max-width: 100%;
    box-sizing: border-box;
    z-index: 1000;
    padding: 0;
    overflow: visible;
    pointer-events: auto;
    background: linear-gradient(168deg, #2c2016 0%, #18120e 48%, #0f0a06 100%);
    border: 1px solid rgba(201, 162, 39, 0.45);
    border-radius: 14px;
    /* Ombre légère : une grande ombre assombrit #chat-history sous le panneau */
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.28),
        0 4px 16px rgba(0, 0, 0, 0.38);
    display: none;
}

#radio-panel::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 100%;
    transform: translateX(-50%);
    border: 9px solid transparent;
    border-bottom-color: rgba(201, 162, 39, 0.5);
    pointer-events: none;
}

#radio-panel::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 100%;
    margin-bottom: -1px;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-bottom-color: #2c2016;
    pointer-events: none;
}

/*
 * Voile plein écran : intercepte les clics vers le canvas pendant que la
 * radio est ouverte (#radio-panel chevauche souvent le jeu).
 */
.radio-panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100040;
    pointer-events: auto;
    touch-action: none;
    background: rgba(0, 0, 0, 0.28);
    -webkit-tap-highlight-color: transparent;
}
.radio-panel-backdrop.is-visible {
    display: block;
}

/*
 * Colonne chat + panneau au-dessus du voile ; le jeu reste dessous.
 * overflow: visible : le panneau est centré sous #chat-nav et déborde souvent à
 * gauche sur le canvas ; avec overflow:hidden sur #chat-window, cette zone était
 * rognée → hit-test absent → clics recevaient l’iframe Phaser.
 *
 * play.html impose aussi overflow:hidden sur #game-and-chat : sans levée, le
 * débordement du #radio-panel sur le canvas n’est pas « sous » la colonne aux
 * yeux du hit-test → l’iframe reçoit le clic en parallèle des contrôles radio.
 */
body.radio-panel-open #main-wrapper {
    overflow: visible !important;
}
body.radio-panel-open #game-and-chat {
    overflow: visible !important;
    pointer-events: none !important;
}
body.radio-panel-open #game-chat-wrapper {
    overflow: visible !important;
    pointer-events: auto !important;
}
body.radio-panel-open #chat-window,
body.radio-panel-open .chat-sidebar-root {
    position: relative;
    z-index: 100050;
    overflow: visible !important;
    pointer-events: auto !important;
}
/* Panneau flottant (body, sidebar repliée) : hors #game-and-chat, garder les clics. */
body.radio-panel-open #radio-panel.panel-floating {
    pointer-events: auto !important;
}
/* Garantir que la modale radio est toujours au-dessus de #chat-window,
 * #chat-form et #wallet-display, quelle que soit leur position dans le DOM. */
body.radio-panel-open #chat-form {
    z-index: 1 !important;
}
body.radio-panel-open #wallet-display {
    z-index: 1 !important;
}

/* Bloquer les clics vers l'iframe quand le panneau radio est ouvert.
 * Sans cela l'iframe (document séparé) capture les événements malgré le backdrop. */
body.radio-panel-open #game-container {
    pointer-events: none !important;
}
body.radio-panel-open #canvas-frame {
    pointer-events: none !important;
}

#radio-panel.visible {
    display: block;
    position: absolute;
    z-index: 1000001;
    pointer-events: auto;
    touch-action: manipulation;
    animation: radio-panel-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Fermeture en fondu (dégradé) : on garde display:block via .visible, puis on coupe en JS */
#radio-panel.visible.closing {
    animation: none;
    opacity: 0;
    transform: translateX(-50%) translateY(-6px) scale(0.96);
    transition: opacity 0.26s ease, transform 0.26s ease;
}

@keyframes radio-panel-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-6px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

.radio-panel-header {
    position: relative;
    padding: 12px 42px 10px 16px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(201, 162, 39, 0.9);
    text-align: center;
    border-bottom: 1px solid rgba(201, 162, 39, 0.2);
    background: linear-gradient(180deg, rgba(201, 162, 39, 0.08) 0%, transparent 100%);
}

/* Même tonalité que `.regles-close` (modales règles) — adapté au bandeau compact */
.radio-panel-close {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    background: rgba(201, 162, 39, 0.15);
    color: #e8d5b5;
    font-family: inherit;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    transition: background 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.radio-panel-close:hover {
    background: rgba(201, 162, 39, 0.35);
    color: #f5e6c8;
}

.radio-panel-close:focus {
    outline: none;
}

.radio-panel-close:focus-visible {
    outline: 2px solid rgba(201, 162, 39, 0.65);
    outline-offset: 2px;
}

.radio-station-list {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.radio-station {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px 10px 14px;
    margin: 0;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 14px;
    color: #e8d5b5;
    cursor: pointer;
    transition: transform 0.12s ease, color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    text-align: left;
    border: 1px solid transparent;
    border-radius: 10px;
    background: rgba(15, 10, 6, 0.35);
}

.radio-station-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Indicateur chargement / buffer à droite du nom */
.radio-station-load {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    box-sizing: border-box;
    border: 2px solid rgba(201, 162, 39, 0.2);
    border-top-color: #c9a227;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
}

.radio-station.is-loading .radio-station-load {
    opacity: 1;
    visibility: visible;
    animation: radio-station-load-spin 0.65s linear infinite;
}

@keyframes radio-station-load-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ▶ / ■ : même zone que l’ancien bouton オン/オフ pour 「部屋の音楽」 */
.radio-station-play-icon {
    flex-shrink: 0;
    width: 30px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid rgba(201, 162, 39, 0.42);
    background: linear-gradient(145deg, rgba(56, 42, 28, 0.95), rgba(38, 28, 20, 0.98));
    font-size: 12px;
    line-height: 1;
    color: #f5e6c8;
    pointer-events: none;
    box-sizing: border-box;
}

.radio-station.active .radio-station-play-icon {
    border-color: rgba(224, 192, 120, 0.55);
    color: #fffaf2;
}

.radio-station--room-bgm .radio-station-load {
    display: none;
}

.radio-station:hover {
    color: #f5e6c8;
    background: rgba(201, 162, 39, 0.12);
    border-color: rgba(201, 162, 39, 0.2);
}

.radio-station:focus {
    outline: none;
}

.radio-station:focus-visible {
    outline: 2px solid rgba(201, 162, 39, 0.65);
    outline-offset: 0;
}

.radio-station.active {
    color: #f5e6c8;
    font-weight: 600;
    background: linear-gradient(90deg, rgba(201, 162, 39, 0.22) 0%, rgba(201, 162, 39, 0.06) 100%);
    border-color: rgba(201, 162, 39, 0.35);
    box-shadow: inset 3px 0 0 #c9a227;
}

/* En-tête → 音量 → liste (pas de double filet sous le titre). */
.radio-panel-header + .radio-volume {
    border-top: none;
}
.radio-volume + .radio-station-list {
    border-top: 1px solid rgba(201, 162, 39, 0.2);
    margin-top: 0;
}

.radio-volume {
    padding: 14px;
    border-top: 1px solid rgba(201, 162, 39, 0.2);
    margin-top: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
}
.radio-panel-header ~ .radio-station-list + .radio-volume {
    /* Ancien ordre : stations puis volume — reprend une bordure haute nette */
    padding-top: 12px;
    border-top: 1px solid rgba(201, 162, 39, 0.2);
}
.radio-volume-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: #a89880;
    white-space: nowrap;
    cursor: pointer;
}
#radio-volume-slider {
    flex: 1;
    min-width: 0;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(201, 162, 39, 0.2);
    border-radius: 3px;
    outline: none;
}
#radio-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: linear-gradient(145deg, #e8d5b5, #c9a227);
    cursor: pointer;
    border: 2px solid #2c2016;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
#radio-volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: linear-gradient(145deg, #e8d5b5, #c9a227);
    cursor: pointer;
    border: 2px solid #2c2016;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
/* Bascule effets sonores (voix/animations) — placée entre 音量 et la liste */
.radio-sfx-toggle {
    padding: 10px 14px 12px;
    border-top: 1px solid rgba(201, 162, 39, 0.18);
    margin-top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: rgba(0, 0, 0, 0.15);
}
.radio-volume + .radio-sfx-toggle {
    border-top: 1px dashed rgba(201, 162, 39, 0.18);
    background: rgba(0, 0, 0, 0.2);
}
.radio-sfx-toggle + .radio-station-list {
    border-top: 1px solid rgba(201, 162, 39, 0.2);
    margin-top: 0;
}
.radio-sfx-toggle-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: #a89880;
    white-space: nowrap;
}
.radio-sfx-toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 4px 4px;
    margin: 0;
    border: 1px solid rgba(201, 162, 39, 0.32);
    border-radius: 999px;
    background: rgba(15, 10, 6, 0.55);
    cursor: pointer;
    font-family: inherit;
    color: #e8d5b5;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.radio-sfx-toggle-switch:hover {
    border-color: rgba(201, 162, 39, 0.5);
    color: #f5e6c8;
}
.radio-sfx-toggle-switch:focus { outline: none; }
.radio-sfx-toggle-switch:focus-visible {
    outline: 2px solid rgba(201, 162, 39, 0.65);
    outline-offset: 2px;
}
.radio-sfx-toggle-track {
    position: relative;
    width: 30px;
    height: 16px;
    border-radius: 999px;
    background: rgba(201, 162, 39, 0.18);
    transition: background 0.18s ease;
    flex-shrink: 0;
}
.radio-sfx-toggle-thumb {
    position: absolute;
    top: 1px;
    left: 1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: linear-gradient(145deg, #e8d5b5, #c9a227);
    border: 1px solid rgba(30, 22, 14, 0.55);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
    transition: transform 0.18s ease, background 0.18s ease;
}
.radio-sfx-toggle-switch[aria-checked="true"] .radio-sfx-toggle-track {
    background: rgba(201, 162, 39, 0.55);
}
.radio-sfx-toggle-switch[aria-checked="true"] .radio-sfx-toggle-thumb {
    transform: translateX(14px);
}
.radio-sfx-toggle-switch[aria-checked="false"] .radio-sfx-toggle-thumb {
    background: linear-gradient(145deg, #8a7660, #5a4a36);
}
.radio-sfx-toggle-state {
    min-width: 26px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: #c9a227;
    text-align: left;
}
.radio-sfx-toggle-switch[aria-checked="false"] .radio-sfx-toggle-state {
    color: #8a7660;
}

.radio-error-toast {
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.4;
    color: #f5c4c4;
    background: rgba(120, 30, 30, 0.55);
    border-top: 1px solid rgba(180, 80, 80, 0.35);
    text-align: center;
    animation: radio-error-fade 4s ease-out forwards;
}
@keyframes radio-error-fade {
    0%   { opacity: 0; transform: translateY(-4px); }
    8%   { opacity: 1; transform: translateY(0); }
    75%  { opacity: 1; }
    100% { opacity: 0; }
}
