/* Connection modal styles for mini-games (separate from share-modal) */
.connection-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(3, 6, 23, 0.6);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 100000;
}

.connection-modal.active {
    display: flex;
}

/* Collapsed state - keep overlay, just reposition content */
.connection-modal.collapsed {
    align-items: flex-start;
    padding-top: 20px;
}

.connection-modal.collapsed .modal-content {
    display: none;
}

/* Collapsed header - always use compact layout (PC and mobile) */
.connection-modal .collapsed-header {
    display: none;
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100001;
    width: calc(100% - 32px);
    max-width: 500px;
    transition: all 0.2s ease;
    /* Removed: cursor pointer - header is not clickable, only button is */
}

.connection-modal.collapsed .collapsed-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Removed: hover effect on header - only button should have hover effect */

/* Header row with title and toggle */
.connection-modal .ch-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.connection-modal .ch-left {
    flex: 1;
    min-width: 0;
}

.connection-modal .ch-title {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 2px;
}

.connection-modal .ch-sub {
    font-size: 12px;
    color: #6b7280;
}

/* Shared link note in collapsed header */
.connection-modal .shared-link-note {
    display: flex;
    width: 100%;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    border-left: 3px solid #3b82f6;
    border-radius: 6px;
    padding: 8px 10px;
}

.connection-modal .shared-link-note p {
    margin: 0;
    font-size: 12px;
    color: #1e40af;
    font-weight: 500;
}

/* Username label in collapsed header */
.connection-modal .quick-username-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    width: 100%;
}

/* Username input row (full width) */
.connection-modal .quick-username {
    display: flex;
    width: 100%;
}

.connection-modal .quick-username input {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    width: 100%;
    color: #111827;
    background: #ffffff;
}

.connection-modal .quick-username input::placeholder {
    color: #9ca3af;
    opacity: 1;
}

/* Connect button row (full width) */
.connection-modal .quick-connect-btn {
    display: flex;
    width: 100%;
}

.connection-modal .quick-connect-btn button {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6965db 0%, #7c3aed 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.connection-modal .quick-connect-btn button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(105, 101, 219, 0.3);
}

/* Old quick-connect styles (keep for backward compatibility) */
.connection-modal .quick-connect {
    display: flex;
    gap: 8px;
    align-items: center;
}

.connection-modal .quick-connect input {
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    flex: 1;
    color: #111827;
    background: #ffffff;
}

.connection-modal .quick-connect input::placeholder {
    color: #9ca3af;
    opacity: 1;
}

.connection-modal .quick-connect button {
    padding: 6px 10px;
    font-size: 13px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6965db 0%, #7c3aed 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.connection-modal .quick-connect button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(105, 101, 219, 0.3);
}

.connection-modal .quick-connect button svg {
    display: block;
}

.connection-modal .modal-toggle-btn {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    color: #1f2937;
    font-size: 18px;
    cursor: pointer;
    padding: 6px 10px;
    transition: all 0.2s ease;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.connection-modal .modal-toggle-btn:hover {
    color: #111827;
    background: #e5e7eb;
    border-color: #9ca3af;
}

.connection-modal .modal-toggle-btn:active {
    background: #d1d5db;
    transform: scale(0.95);
}

/* Full modal content */
.connection-modal .modal-content {
    background: white;
    color: #051225;
    width: 420px;
    max-width: calc(100% - 32px);
    border-radius: 12px;
    z-index: 100002;
    box-shadow: 0 10px 30px rgba(2, 6, 23, 0.2);
    padding: 24px;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.connection-modal .modal-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.connection-modal .modal-content h2 {
    margin: 0;
    font-size: 20px;
    color: #1f2937;
}

/* Info note for channel/password explanation */
.connection-modal .connection-info-note {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 8px;
}

.connection-modal .connection-info-note p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: #0369a1;
}

.connection-modal .connection-info-note strong {
    color: #0c4a6e;
}

/* Ensure all text in modal is visible */
.connection-modal .modal-content,
.connection-modal .modal-title,
.connection-modal .modal-subtitle,
.connection-modal .form-label,
.connection-modal label {
    color: #1f2937;
}

.connection-modal form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.connection-modal input[type="text"],
.connection-modal input[type="email"],
.connection-modal input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    color: #111827;
    background: #ffffff;
    transition: border-color 0.2s ease;
    margin-bottom: 8px;
}

.connection-modal input[type="text"]::placeholder,
.connection-modal input[type="email"]::placeholder,
.connection-modal input[type="password"]::placeholder {
    color: #9ca3af;
    opacity: 1;
}

.connection-modal input[type="text"]:focus,
.connection-modal input[type="email"]:focus,
.connection-modal input[type="password"]:focus {
    outline: none;
    border-color: #6965db;
    box-shadow: 0 0 0 3px rgba(105, 101, 219, 0.1);
}

.connection-modal input[type="text"]:read-only,
.connection-modal input[type="email"]:read-only,
.connection-modal input[type="password"]:read-only {
    background: #f3f4f6;
    cursor: not-allowed;
}

/* Password input wrapper */
.connection-modal .password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.connection-modal .password-input-wrapper input {
    padding-right: 40px;
}

.connection-modal .password-toggle-btn {
    position: absolute;
    right: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    color: #6b7280;
    transition: color 0.2s ease;
}

.connection-modal .password-toggle-btn:hover {
    color: #1f2937;
}

.connection-modal .modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.connection-modal .modal-buttons button {
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.connection-modal .btn-primary {
    background: #6965db;
    color: white;
}

.connection-modal .btn-primary:hover {
    background: #5753c6;
}

.connection-modal .ghost {
    background: transparent;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.connection-modal .ghost:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.connection-modal .error-message {
    display: none;
    padding: 10px 12px;
    background: #fef2f2;
    color: #dc2626;
    border-radius: 8px;
    font-size: 13px;
    margin-top: 8px;
    border: 1px solid #fecaca;
}

.connection-modal .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Ensure the connection status dot is visible (not clipped) in mini-games */
.header, .status, .status-bar {
    overflow: visible !important;
}

.connection-status, .status-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #4CAF50;
    box-shadow: 0 0 0 6px rgba(76,175,80,0.12);
    position: relative;
    z-index: 100003;
    vertical-align: middle;
}

.connection-status.offline, .status-dot.offline {
    background: #bbb;
    box-shadow: 0 0 0 6px rgba(0,0,0,0.06);
}

/* Tooltip text shown on hover for connection status */
.connection-status::after {
    content: attr(data-status);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(11,18,32,0.95);
    color: #e6eef8;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease-in-out, transform 0.12s ease-in-out;
    transform-origin: left center;
}
.connection-status:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* Mobile responsive - only adjust modal content width */
@media (max-width: 600px) {

    .connection-modal .modal-content {
        width: calc(100% - 32px);
    }
}

/* ============================================
   Additional Utility Styles
   ============================================ */

/* Connection Modal hidden state */
.connection-modal.hidden,
#connectionModal.hidden {
    display: none !important;
}

/* Form group */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
}

/* Visible form labels */
.form-label-visible {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 6px;
    margin-top: 4px;
}

/* Disconnect button */
.disconnect-btn,
button[id*="disconnect"],
.btn-danger {
    padding: 8px 16px;
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.disconnect-btn:hover,
button[id*="disconnect"]:hover,
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/* Connect button - consolidated styles */
.connection-modal .connect-btn,
.connection-modal button[id*="connect"],
.connection-modal button[id*="Connect"],
.connection-modal .btn-primary,
.connection-modal #connectBtn,
.connection-modal #quickConnectBtn,
#connectBtn,
#quickConnectBtn {
    background: #6965db;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.connection-modal .connect-btn:hover,
.connection-modal button[id*="connect"]:hover,
.connection-modal button[id*="Connect"]:hover,
.connection-modal .btn-primary:hover,
.connection-modal #connectBtn:hover,
.connection-modal #quickConnectBtn:hover,
#connectBtn:hover,
#quickConnectBtn:hover {
    background: #5753c6;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.connection-modal .connect-btn:active,
.connection-modal button[id*="connect"]:active,
.connection-modal button[id*="Connect"]:active,
.connection-modal .btn-primary:active,
#connectBtn:active,
#quickConnectBtn:active {
    transform: translateY(0);
}

.connection-modal .connect-btn:disabled,
.connection-modal button[id*="connect"]:disabled,
.connection-modal button[id*="Connect"]:disabled,
.connection-modal #connectBtn:disabled,
.connection-modal #quickConnectBtn:disabled,
#connectBtn:disabled,
#quickConnectBtn:disabled {
    background: #d1d5db;
    color: #6b7280;
    cursor: not-allowed;
    transform: none;
    opacity: 0.6;
}

/* Portrait orientation specific */
@media (orientation: portrait) and (max-width: 768px) {
    .connection-modal {
        align-items: flex-start;
        padding-top: 5vh;
    }

    .connection-modal .modal-content {
        max-height: 80vh;
        max-height: 80dvh;
        overflow-y: auto;
    }
}

/* A screen shorter than the card — a phone held sideways — put the Connect
 * button below the fold with no way to reach it: the overlay does not scroll,
 * and games that set `touch-action: none` on the body stop the card scrolling
 * under a finger too. Both are answered here rather than per game.
 */
@media (max-height: 560px) {
    .connection-modal .modal-content {
        max-height: calc(100vh - 16px);
        overflow-y: auto;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
    }
}

/* ---- when a connect fails -------------------------------------------------
 * The form is where the person is looking, so this is where the reason goes.
 * A toast in the corner of a screen they are not watching is not a report.
 */
.connection-modal .connect-error {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
    padding: 12px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left-width: 4px;
    border-radius: 8px;
}

.connection-modal .connect-error[hidden] { display: none; }

.connection-modal .connect-error p {
    margin: 0;
    font-size: 14px;
    line-height: 1.45;
    color: #b91c1c;
}

.connection-modal .connect-error button { align-self: flex-start; }
.connection-modal .connect-error button[hidden] { display: none; }

/* A button that is busy says so and cannot be pressed twice. */
.connection-modal button:disabled { opacity: 0.6; cursor: progress; }

/* The collapse control is one chevron that turns, rather than two different
   arrow glyphs that render differently on every platform. */
.connection-modal .modal-toggle-btn .chev {
    transition: transform 0.15s ease;
}

.connection-modal.collapsed .modal-toggle-btn .chev {
    transform: rotate(-90deg);
}

/* The reveal control holds an icon and nothing else.
 *
 * It was 34x26, which is under the size a fingertip can reliably hit — and
 * this form is the first thing anyone who scans the QR code sees, on the
 * device least able to hit a 26px target. 36 square, centred, everywhere. */
.connection-modal .password-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
}

/* :not([hidden]) matters. The button holds both glyphs — eye and eye-off — and
 * the script swaps them with the `hidden` attribute, which works only because
 * the UA stylesheet maps it to display:none. A bare `display: block` here is an
 * author rule and beats that, so both icons painted at once, stacked inside the
 * button, whatever the field's state. */
.connection-modal .password-toggle-btn svg:not([hidden]) {
    width: 18px;
    height: 18px;
    min-width: 18px;
    display: block;
}

.connection-modal .password-toggle-btn svg[hidden] { display: none; }

/* --- Tabs, the saved list, and the save row ------------------------------
   All of this is inside the EXPANDED modal. The collapsed quick card is
   untouched, so a first-time visitor still meets a name field and one
   Connect button with no tab to choose. */

.connection-modal .mp-tabs {
    display: flex;
    gap: 4px;
    margin: 0 0 16px;
    border-bottom: 1px solid #e2e8f0;
}

.connection-modal .mp-tab {
    appearance: none;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 8px 12px;
    font: inherit;
    font-size: 14px;
    color: #64748b;
    cursor: pointer;
}

.connection-modal .mp-tab:hover { color: #1e293b; }
.connection-modal .mp-tab.is-active { color: #4f46e5; border-bottom-color: #4f46e5; font-weight: 600; }
.connection-modal .mp-tab:focus-visible { outline: 2px solid #4f46e5; outline-offset: 2px; border-radius: 4px; }
.connection-modal .mp-tab[hidden] { display: none; }
.connection-modal .mp-panel[hidden] { display: none; }

.connection-modal .mp-saved-list { display: flex; flex-direction: column; gap: 6px; }

.connection-modal .mp-saved-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 10px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.connection-modal .mp-saved-row:hover { background: #f1f5f9; border-color: #cbd5e1; }
.connection-modal .mp-saved-row:focus-visible { outline: 2px solid #4f46e5; outline-offset: 2px; }
.connection-modal .mp-saved-label { font-weight: 600; color: #1e293b; font-size: 14px; }

/* The channel name is identity, so it is shown in full and monospaced --
   truncating it would hide the one thing that decides which room you join. */
.connection-modal .mp-saved-name {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: #64748b;
    overflow-wrap: anywhere;
}

.connection-modal .mp-note { font-size: 12px; color: #64748b; margin: 8px 0 0; line-height: 1.6; }

.connection-modal .mp-save-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 0 0;
    font-size: 14px;
    color: #1e293b;
    cursor: pointer;
}

.connection-modal .mp-save-row input[disabled] { cursor: not-allowed; }
.connection-modal .mp-save-row:has(input[disabled]) { color: #94a3b8; cursor: default; }
.connection-modal .mp-save-note { margin-top: 4px; }
.connection-modal .mp-google { width: 100%; margin-bottom: 12px; }

/* Sign in / create, laid out like the Rooms gate this shares an account with. */
.connection-modal .mp-signin__lead { margin: 0 0 14px; }

.connection-modal .mp-subtabs {
    display: flex;
    gap: 4px;
    margin: 0 0 14px;
    padding: 3px;
    background: #f1f5f9;
    border-radius: 8px;
}

.connection-modal .mp-subtab {
    flex: 1;
    appearance: none;
    border: 0;
    border-radius: 6px;
    background: transparent;
    padding: 7px 10px;
    font: inherit;
    font-size: 13px;
    color: #64748b;
    cursor: pointer;
}

.connection-modal .mp-subtab.is-active { background: #ffffff; color: #1e293b; font-weight: 600; }
.connection-modal .mp-subtab:focus-visible { outline: 2px solid #4f46e5; outline-offset: 1px; }

/* "or" with a rule either side, so Google reads as an alternative to the
   email path above it rather than a competing primary action. */
.connection-modal .mp-or {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0 12px;
    color: #94a3b8;
    font-size: 12px;
}
.connection-modal .mp-or::before,
.connection-modal .mp-or::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}
.connection-modal .mp-or[hidden] { display: none; }

.connection-modal .mp-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
}
.connection-modal .mp-google:hover { background: #f8fafc; border-color: #cbd5e1; }
.connection-modal .mp-google__g {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 50%;
    background: #4285f4; color: #fff; font-size: 11px; font-weight: 700;
}
.connection-modal .mp-signin__ok { color: #15803d; }

/* The action row squeezes its secondary button until the label breaks across
   two lines ("Forgotten your / password?"). Let the row wrap instead: a
   button that moves to its own line reads fine; a broken label does not. */
.connection-modal #panelSignin .modal-buttons { flex-wrap: wrap; }
.connection-modal #panelSignin .modal-buttons > button { white-space: nowrap; }
