/* Session failure stays in the native top layer while the lobby is rebuilt below. */
dialog.online-session-ended {
    box-sizing: border-box; width: min(88vw, 1020px); max-width: 92vw; max-height: 90vh;
    margin: auto; padding: 0; border: 3px solid #aa8550; border-radius: 0;
    color: #f0dfbc; background: #171316;
    box-shadow: 0 0 0 5px #251c19, 0 0 0 7px #564333, 0 18px 70px #000c;
    font: clamp(18px, 1.15vw, 28px)/1.45 'SFPixelate', monospace;
}
dialog.online-session-ended[open] { display: flex; flex-direction: column; }
.online-session-ended::backdrop { background: #080709dc; }
.online-session-ended-body { padding: 3vh 2.2vw; overflow-y: auto; min-height: 0; }
.online-session-ended header { display: flex; gap: 1.2vw; align-items: center; padding-bottom: 2vh; border-bottom: 2px solid #604534; }
.online-session-ended h2 { margin: 0; font: inherit; font-size: clamp(24px, 1.8vw, 40px); line-height: 1.25; color: #f4c58f; }
.online-session-ended-icon { flex: 0 0 56px; width: 56px; height: 56px; fill: none; stroke: #e9a079; stroke-width: 3; }
.online-session-ended p { margin: 2vh 0 0; overflow-wrap: anywhere; }
.online-session-ended-instruction { color: #c7b99e; }
.online-session-ended-report { margin-top: 2.5vh; padding: 1.5vh 1.2vw; border-left: 3px solid #aa8550; background: #0d0b0d; }
.online-session-ended h3 { margin: 0 0 1vh; font: inherit; color: #dcc08c; }
.online-session-ended-report p { margin: 0; }
.online-session-ended code { display: block; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; cursor: text; color: #f0dfbc; font: inherit; }
.online-session-ended [hidden] { display: none; }
.online-session-ended-details { color: #b8aaa0; font-size: clamp(16px, 1vw, 22px); }
.online-session-ended footer { flex: 0 0 auto; padding: 1.5vh 2.2vw 2.5vh; display: flex; justify-content: flex-end; }
.online-session-ended button { min-height: 58px; max-width: 100%; padding: 1vh 2vw; border: 2px solid #ac8a55; border-radius: 0; background: #392b21; color: #f0dfbc; font: inherit; cursor: var(--cm-cursor-action, pointer); }
.online-session-ended button:hover:where(body:not(.gamepad-active) *), .online-session-ended button:focus { background: #59432c; border-color: #f4d591; outline: 2px solid #e7c880; outline-offset: 3px; }
@media (max-width: 1920px) { dialog.online-session-ended { max-width: 900px; } }
@media (max-width: 1366px) { dialog.online-session-ended { max-width: 820px; } .online-session-ended-icon { flex-basis: 44px; width: 44px; height: 44px; } }
@media (max-width: 1280px) { .online-session-ended button { min-height: 48px; } }

/* Multiplayer Lobby Styles */
.multiplayer-lobby-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, rgba(26, 15, 31, 0.98) 0%, rgba(10, 10, 10, 0.99) 100%);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 19000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.multiplayer-lobby-overlay.active {
    display: flex;
    opacity: 1;
}

.multiplayer-lobby-container {
    position: relative;
    width: 90%;
    max-width: 1200px;
    height: 85%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lobby-book-background {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.8;
    z-index: 1;
    pointer-events: none;
}

.lobby-back {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(138, 43, 226, 0.2);
    border: 2px solid rgba(138, 43, 226, 0.5);
    color: #dda0dd;
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 18px;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: var(--cm-cursor-action, pointer);
    transition: all 0.3s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
}

.lobby-back:hover:where(body:not(.gamepad-active) *) {
    background: rgba(138, 43, 226, 0.4);
    border-color: rgba(138, 43, 226, 0.8);
    color: #ffffff;
    transform: translateX(-3px);
}

.lobby-header {
    position: relative;
    z-index: 5;
    margin-top: 40px;
    margin-bottom: 30px;
}

.lobby-title {
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 48px;
    color: #dda0dd;
    text-shadow: 0 0 20px rgba(138, 43, 226, 0.8);
    margin: 0;
}

.lobby-content {
    position: relative;
    z-index: 5;
    display: flex;
    gap: 40px;
    width: 100%;
    height: calc(100% - 150px);
    padding: 20px;
}

.lobby-left-panel,
.lobby-right-panel {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(138, 43, 226, 0.3);
    border-radius: 12px;
    padding: 30px;
    overflow-y: auto;
}

.lobby-mode-selection h2,
.lobby-friends-list h2,
.lobby-room h2 {
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 24px;
    color: #dda0dd;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(138, 43, 226, 0.5);
}

.lobby-mode-btn {
    width: 100%;
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.2) 0%, rgba(75, 0, 130, 0.3) 100%);
    border: 2px solid rgba(138, 43, 226, 0.5);
    color: #dda0dd;
    font-family: 'SFPixelate', 'Courier New', monospace;
    padding: 20px;
    border-radius: 8px;
    cursor: var(--cm-cursor-action, pointer);
    transition: all 0.3s ease;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.lobby-mode-btn:hover:where(body:not(.gamepad-active) *) {
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.4) 0%, rgba(75, 0, 130, 0.5) 100%);
    border-color: rgba(138, 43, 226, 0.8);
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(138, 43, 226, 0.3);
}

.mode-icon {
    font-size: 32px;
}

.mode-text {
    font-size: 20px;
    font-weight: bold;
}

.mode-desc {
    font-size: 14px;
    color: #999;
}

.friends-list-container {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.friend-item {
    background: rgba(138, 43, 226, 0.1);
    border: 1px solid rgba(138, 43, 226, 0.3);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: var(--cm-cursor-action, pointer);
    transition: all 0.3s ease;
}

.friend-item:hover:where(body:not(.gamepad-active) *) {
    background: rgba(138, 43, 226, 0.2);
    border-color: rgba(138, 43, 226, 0.5);
    transform: translateX(5px);
}

.friend-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.friend-name {
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 18px;
    color: #dda0dd;
}

.friend-status {
    font-size: 14px;
    color: #999;
}

.friend-status.in-lobby {
    color: #4ade80;
}

.friend-join-btn {
    background: rgba(138, 43, 226, 0.3);
    border: 1px solid rgba(138, 43, 226, 0.5);
    color: #dda0dd;
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 14px;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: var(--cm-cursor-action, pointer);
    transition: all 0.3s ease;
}

.friend-join-btn:hover:where(body:not(.gamepad-active) *) {
    background: rgba(138, 43, 226, 0.5);
    color: #ffffff;
}

.lobby-room {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.lobby-info {
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 16px;
    color: #999;
}

#lobbyRoleDisplay {
    color: #4ade80;
    font-weight: bold;
}

.lobby-members-container h3 {
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 18px;
    color: #dda0dd;
    margin-bottom: 15px;
}

.lobby-members-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.lobby-member-item {
    background: rgba(138, 43, 226, 0.1);
    border: 1px solid rgba(138, 43, 226, 0.3);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.member-number {
    background: rgba(138, 43, 226, 0.5);
    color: #ffffff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.member-name {
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 16px;
    color: #dda0dd;
}

.member-host-badge {
    margin-left: auto;
    background: rgba(74, 222, 128, 0.3);
    color: #4ade80;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: bold;
}

.lobby-actions {
    display: flex;
    gap: 15px;
    margin-top: auto;
}

.lobby-primary-btn,
.lobby-secondary-btn {
    flex: 1;
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 18px;
    padding: 15px 30px;
    border-radius: 8px;
    cursor: var(--cm-cursor-action, pointer);
    transition: all 0.3s ease;
    border: 2px solid;
}

.lobby-primary-btn {
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.2) 0%, rgba(34, 197, 94, 0.3) 100%);
    border-color: rgba(74, 222, 128, 0.5);
    color: #4ade80;
}

.lobby-primary-btn:hover:where(body:not(.gamepad-active) *) {
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.4) 0%, rgba(34, 197, 94, 0.5) 100%);
    border-color: rgba(74, 222, 128, 0.8);
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(74, 222, 128, 0.3);
}

.lobby-secondary-btn {
    background: rgba(138, 43, 226, 0.2);
    border-color: rgba(138, 43, 226, 0.5);
    color: #dda0dd;
}

.lobby-secondary-btn:hover:where(body:not(.gamepad-active) *) {
    background: rgba(138, 43, 226, 0.4);
    border-color: rgba(138, 43, 226, 0.8);
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(138, 43, 226, 0.3);
}

.lobby-waiting {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 18px;
    color: #999;
    text-align: center;
}

/* Online party: the shared menu artwork paints frames; content remains native DOM. */
#multiplayerLobbyOverlay .online-lobby-joining {
    position: absolute; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    background: #080709c9; cursor: progress;
}
#multiplayerLobbyOverlay .online-lobby-joining[hidden] { display: none; }
#multiplayerLobbyOverlay .online-lobby-joining-panel {
    box-sizing: border-box; width: 84vw; max-width: 540px;
    padding: 3vh 2vw; border: 2px solid #aa8550; border-radius: 0;
    background: #171316; color: #ead9ad; text-align: center;
    box-shadow: 0 0 0 4px #251c19, 0 0 0 6px #564333, 0 16px 48px #000a;
    font: clamp(20px, 1.35vw, 30px)/1.4 'SFPixelate', monospace;
}
#multiplayerLobbyOverlay .online-lobby-joining-panel p { margin: 0; overflow-wrap: anywhere; }
#multiplayerLobbyOverlay .online-lobby-joining-dots {
    display: flex; justify-content: center; gap: 12px; margin-top: 2vh;
}
#multiplayerLobbyOverlay .online-lobby-joining-dots span {
    width: 8px; height: 8px; background: #e4c985;
    animation: online-lobby-joining-pulse 1.2s steps(3, end) infinite;
}
#multiplayerLobbyOverlay .online-lobby-joining-dots span:nth-child(2) { animation-delay: .2s; }
#multiplayerLobbyOverlay .online-lobby-joining-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes online-lobby-joining-pulse {
    0%, 100% { opacity: .25; }
    50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    #multiplayerLobbyOverlay .online-lobby-joining-dots span { animation: none; }
}
#multiplayerLobbyOverlay .multiplayer-lobby-container { box-sizing: border-box; }
#multiplayerLobbyOverlay .lobby-header { margin: 1vh 0 2vh; }
#multiplayerLobbyOverlay .lobby-title { font-size: clamp(24px, 2.8vw, 52px); color: #ead9ad; }
#multiplayerLobbyOverlay .online-lobby-content {
    display: grid; grid-template-columns: minmax(240px, 1fr) minmax(0, 2.3fr);
    gap: 2vw; width: 94%; max-width: 2200px; flex: 1; min-height: 0;
    padding: 2vh 1vw; box-sizing: border-box; color: #ead9ad;
    font: clamp(16px, 1.2vw, 28px)/1.3 'SFPixelate', monospace;
}
#multiplayerLobbyOverlay .online-lobby-content section { min-width: 0; min-height: 0; }
#multiplayerLobbyOverlay .online-lobby-actions { display: flex; flex-direction: column; gap: 1.2vh; overflow-y: auto; padding: 1vh 1vw; }
#multiplayerLobbyOverlay .online-lobby-content button {
    width: 100%; flex: 0 0 auto; min-height: 58px; padding: 1.4vh 1vw;
    line-height: 1.2; background: transparent; border-color: transparent; color: #ead9ad;
    font-size: inherit; box-shadow: none;
}
#multiplayerLobbyOverlay .online-lobby-content [data-menu-control] {
    --control-h: 12; --control-type: 4;
    width: 100% !important; min-width: 0 !important; max-width: 100% !important;
}
#multiplayerLobbyOverlay :is(.lobby-secondary-btn, .lobby-back):is(:hover:where(body:not(.gamepad-active) *), :focus, :active) {
    transform: none;
}
#multiplayerLobbyOverlay :is(.lobby-secondary-btn, .lobby-back) {
    transform: none;
    transition: color .15s, opacity .15s;
}
/* Wide enough for the longest locale label ("Indietro", "Takaisin", "Tillbaka") beside the arrow. */
#multiplayerLobbyOverlay .lobby-back[data-menu-control] { --control-w: 32; --control-h: 10; --control-type: 4; }
/* Labels are not .panel-content, so they take the frame's optical offset here. */
#multiplayerLobbyOverlay [data-menu-control] > :is(.online-action-label, .back-arrow, .back-text) { translate: 0 var(--menu-control-label-offset, 0); }
#multiplayerLobbyOverlay button:focus-visible { outline: none; }
#multiplayerLobbyOverlay .online-lobby-content button:disabled { opacity: .45; cursor: default; }
#multiplayerLobbyOverlay .online-lobby-content input {
    display: block; min-height: 54px; width: 100%; box-sizing: border-box; margin-top: 1vh;
    background: #151217; color: #ead9ad; border: 2px solid #8f754b; border-radius: 0;
    padding: 1vh 1vw; font: inherit;
}
#multiplayerLobbyOverlay input.gamepad-selected { outline: 3px solid #e4c985; outline-offset: 3px; }
#multiplayerLobbyOverlay .online-lobby-content p { overflow-wrap: anywhere; margin: .5vh 0; }
#multiplayerLobbyOverlay .online-ready-reminder { color: #e4c985; }
#multiplayerLobbyOverlay button.online-ready-reminded { outline: 2px solid #e4c985; outline-offset: 2px; }
#multiplayerLobbyOverlay .online-lobby-party { display: flex; flex-direction: column; gap: 1vh; overflow-y: auto; padding: 1vh; }
#multiplayerLobbyOverlay .online-lobby-roster { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5vh 1vw; }
#multiplayerLobbyOverlay .online-lobby-player {
    display: flex; flex-direction: column; align-items: stretch; min-width: 0; min-height: 220px;
    padding: 2vh 1.3vw; gap: 1.5vh; box-sizing: border-box; background: #171015; border-radius: 0; border: 0;
}
#multiplayerLobbyOverlay .online-lobby-player.is-empty { justify-content: center; text-align: center; color: #a5947a; }
#multiplayerLobbyOverlay .online-lobby-player-header { display: flex; align-items: center; gap: 1vw; min-width: 0; }
#multiplayerLobbyOverlay .online-lobby-portrait { width: clamp(64px, 5.5vw, 128px); aspect-ratio: 4 / 5; flex: 0 0 auto; }
#multiplayerLobbyOverlay .online-lobby-player-info { display: flex; flex-direction: column; gap: .5vh; min-width: 0; overflow-wrap: anywhere; }
#multiplayerLobbyOverlay .online-lobby-player-info strong { color: #f0d5a0; font-weight: normal; }
#multiplayerLobbyOverlay .online-lobby-ready { color: #b9a58a; font-size: .85em; }
#multiplayerLobbyOverlay .online-lobby-ready.is-ready { color: #a5cc82; }
#multiplayerLobbyOverlay .online-lobby-spells { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
#multiplayerLobbyOverlay .online-lobby-spells:has(.is-scroll) { grid-template-columns: repeat(9, minmax(0, 1fr)); }
#multiplayerLobbyOverlay .online-lobby-spell {
    position: relative; min-width: 0; aspect-ratio: 64 / 80;
    background: url('../sprites/UI/Gameplay/card.webp') center / 100% 100% no-repeat; image-rendering: pixelated;
}
#multiplayerLobbyOverlay .online-lobby-spell img { position: absolute; left: 15%; top: 17%; width: 70%; height: 60%; object-fit: contain; image-rendering: pixelated; }
#multiplayerLobbyOverlay .online-lobby-spell.is-empty { opacity: .35; }
#multiplayerLobbyOverlay .online-lobby-spell.is-scroll { outline: 1px solid #b99451; }
#multiplayerLobbyOverlay [role="status"] { color: #e4c985; }
#multiplayerLobbyOverlay .online-friend-session {
    display: flex; flex-direction: column; gap: 1vh; padding: 1.5vh 1vw;
    background: #171015; overflow-wrap: anywhere;
}
#multiplayerLobbyOverlay .online-friend-session + .online-friend-session { margin-top: 1vh; }
#multiplayerLobbyOverlay .online-lobby-actions label { display: block; }
@media (max-width: 1920px) {
    #multiplayerLobbyOverlay .online-lobby-joining-panel { max-width: 460px; }
    #multiplayerLobbyOverlay .online-lobby-content { max-width: 1760px; }
    #multiplayerLobbyOverlay .online-lobby-player { min-height: 180px; }
    #multiplayerLobbyOverlay .online-lobby-content button { min-height: 48px; }
}
@media (max-width: 1366px) {
    #multiplayerLobbyOverlay .online-lobby-joining-panel { max-width: 420px; }
    #multiplayerLobbyOverlay .online-lobby-player { min-height: 150px; }
    #multiplayerLobbyOverlay .online-lobby-content button { min-height: 44px; }
}
@media (max-width: 1280px) {
    #multiplayerLobbyOverlay .online-lobby-joining-panel { max-width: 380px; }
    #multiplayerLobbyOverlay .online-lobby-player { min-height: 140px; }
    #multiplayerLobbyOverlay .online-lobby-content { gap: 1.5vw; }
}
