/* MoonlightWeb — Session sharing
 *
 * Two surfaces: the owner's Share menu in the stream header, and the invited
 * player's page. Both follow the CP2077 tokens; the pale state colours asked
 * for in the spec are tinted versions of the semantic neons, dimmed enough to
 * read as "status" rather than "alarm" on the near-black header.
 */

/* ── Owner: Share button + dropdown ────────────────────────────────────── */

.share-menu {
    position: relative;
    /* The dropdown hangs below the header, over the picture — and the stream's
       transparent input layer sits there at z-index 50. Without a stacking
       context above it the rows would be painted underneath: visible (the
       layer is transparent) but unclickable, every click landing in the game
       as a mouse press on the host. */
    z-index: 300;
    margin-right: 10px;
}

.share-btn {
    padding: 7px 18px;
    font-size: 12.5px;
    background: var(--surface-3);
    color: var(--text-1);
    border: none;
    box-shadow: var(--edge-cyan);
    cursor: pointer;
    transition:
        background 0.15s,
        color 0.15s,
        filter 0.2s;
}

.share-btn:hover {
    background: var(--surface-4);
    color: var(--neon-cyan);
    filter: var(--glow-cyan);
}

/* Someone is watching right now — the count is worth noticing, in the same
   cyan the "live" rows use. */
.share-btn.has-streams {
    color: var(--c-info);
    box-shadow: inset 0 0 0 1px var(--c-info);
}

.share-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 1;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    background:
        var(--bg-grid) 0 0 / var(--bg-grid-size),
        linear-gradient(160deg, var(--surface-2), var(--surface-1));
    box-shadow:
        var(--edge-cyan),
        0 18px 44px rgba(0, 0, 0, 0.62);
    clip-path: var(--notch-lg);
}

.share-dropdown[hidden] {
    display: none;
}

.share-dropdown-title {
    margin: 2px 2px 4px;
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-3);
}

/* One row per invitable player, built like a host card: round status glyph,
   name + one-line hint, uppercase badge. */
.share-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: 8px 12px 8px 10px;
    font-family: inherit;
    line-height: 1.35;
    text-align: left;
    color: var(--text-1);
    background: var(--surface-2);
    border: none;
    /* Left tick in the state colour — the CP2077 status rail. */
    box-shadow: inset 3px 0 0 var(--row-accent, var(--text-3));
    clip-path: var(--notch-sm);
    cursor: pointer;
    transition:
        background 0.15s,
        filter 0.2s;
}

.share-row:hover {
    background: var(--surface-3);
    filter: drop-shadow(0 0 7px var(--row-glow, transparent));
}

.share-row:active {
    transform: translateY(1px);
}

.share-row:disabled {
    cursor: progress;
    opacity: 0.72;
}

.share-row .status-icon {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    font-size: 0.95rem;
}

.share-row-info {
    flex: 1;
    min-width: 0;
}

.share-row-name {
    display: block;
    font-size: var(--fs-sm);
    font-weight: 600;
    letter-spacing: 0.03em;
}

.share-row-hint {
    display: block;
    margin-top: 1px;
    font-size: var(--fs-xs);
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.share-row .status-badge {
    flex-shrink: 0;
}

/* off / shared / streaming — the semantic trio, same hues as the host list. */
.share-row[data-state='off'] {
    --row-accent: var(--c-danger);
    --row-glow: rgba(255, 42, 109, 0.35);
}
.share-row[data-state='shared'] {
    --row-accent: var(--c-success);
    --row-glow: rgba(42, 212, 160, 0.35);
}
.share-row[data-state='streaming'] {
    --row-accent: var(--c-info);
    --row-glow: rgba(0, 229, 255, 0.4);
}
.share-row[data-state='busy'] {
    --row-accent: var(--text-3);
}

/* "Live" is the one status the hosts page has no equivalent for. */
.status-icon.live {
    color: var(--c-info);
    background-color: var(--c-info-soft);
}
.status-badge.live {
    color: var(--c-info);
    background-color: var(--c-info-soft);
}

/* Someone is on the other end right now — the row should breathe. */
.share-row[data-state='streaming'] .status-icon {
    animation: shareLivePulse 1.8s ease-in-out infinite;
}

@keyframes shareLivePulse {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(0, 229, 255, 0.35);
    }
    50% {
        box-shadow: 0 0 0 5px rgba(0, 229, 255, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .share-row[data-state='streaming'] .status-icon {
        animation: none;
    }
}

/* ── Owner: the share popin ────────────────────────────────────────────── */

.share-popin-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(3px);
}

.share-popin {
    width: min(480px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    padding: 22px 24px 20px;
    background: var(--surface-1);
    border: 1px solid var(--border-1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.share-popin h3 {
    margin: 0 0 16px;
    font-size: 17px;
    color: var(--text-1);
}

.share-field-label {
    display: block;
    margin: 14px 0 6px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-2);
}

.share-copy-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.share-link-input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 12.5px;
    color: var(--text-1);
    background: var(--surface-0);
    border: 1px solid var(--border-1);
}

.share-copy-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 12px;
}

/* A read-only field, not a <div>: focusable, selectable, Ctrl+C-able. */
.share-pin {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 30px;
    letter-spacing: 0.32em;
    text-align: center;
    color: var(--accent-1);
    background: var(--surface-0);
    border: 1px solid var(--accent-ring);
}

.share-pin:focus {
    outline: none;
    border-color: var(--accent-1);
}

.share-pin-hint,
.share-expiry {
    margin: 8px 0 0;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--text-2);
}

.share-perms {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 24px;
}

.share-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-1);
    cursor: pointer;
}

/* Reopened share: the boxes report the frozen policy, they do not set it. */
.share-check.is-locked {
    cursor: default;
    color: var(--text-2);
}
.share-check.is-locked input {
    cursor: default;
}

.share-access {
    margin-top: 16px;
    padding: 12px 14px;
    border-left: 3px solid var(--text-3);
    background: var(--surface-2);
}

.share-access-level {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-1);
}

.share-access-warning {
    margin-top: 5px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-2);
}

/* Full control hands over the keyboard and mouse of this machine — the one
   case where the popin should feel like a warning, not a label. */
.share-access[data-level='gamer'] {
    border-left-color: var(--c-warning);
}
.share-access[data-level='full'] {
    border-left-color: var(--c-danger);
    background: var(--c-danger-soft);
}
.share-access[data-level='full'] .share-access-warning {
    color: var(--c-danger-text);
}

.share-popin-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* Managing a live share: the destructive action goes to the far left, as far
   from "Done" as the box allows. */
.share-popin-actions-split {
    justify-content: space-between;
}

.share-popin-actions-right {
    display: flex;
    gap: 10px;
}

.share-manage-state {
    margin: 0;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-1);
    background: var(--surface-2);
    box-shadow: inset 3px 0 0 var(--c-success);
}

.share-manage-state[data-state='streaming'] {
    box-shadow: inset 3px 0 0 var(--c-info);
    color: var(--c-info);
}

/* ── Invited player's page ─────────────────────────────────────────────── */

body.player-mode {
    background: var(--surface-0);
}

.player-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 100vh;
    padding: 32px 20px;
    text-align: center;
}

.player-art {
    width: min(300px, 70vw);
    color: var(--neon-cyan);
    opacity: 0.85;
}

.player-art-svg {
    width: 100%;
    height: auto;
}

.player-card {
    width: min(440px, 100%);
    padding: 26px 24px;
}

.player-card h1 {
    margin: 0 0 10px;
    font-size: 22px;
    color: var(--text-1);
}

.player-card p {
    margin: 0 0 14px;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text-2);
}

.player-muted {
    color: var(--text-3);
    font-size: 12.5px;
}

.player-access {
    color: var(--accent-1);
}

.player-error {
    color: var(--c-danger-text);
    font-size: 13px;
}

.player-pin-form {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 8px;
}

.player-pin-input {
    width: 190px;
    padding: 10px 12px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 26px;
    letter-spacing: 0.28em;
    text-align: center;
    color: var(--text-1);
    background: var(--surface-0);
    border: 1px solid var(--border-1);
}

.player-pin-input:focus {
    outline: none;
    border-color: var(--accent-ring);
}

.player-quality {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

.player-quality-btn {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    cursor: pointer;
}

.player-quality-btn.is-selected {
    color: var(--on-accent);
    background: var(--accent-1);
    border-color: var(--accent-1);
}

/* Guest input preferences, under the quality picker. */
.player-toggles {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.player-toggles:empty {
    display: none;
}

.player-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
}

.player-toggle-choice {
    display: flex;
    gap: 6px;
}

.player-toggle-btn {
    padding: 6px 12px;
    font-size: 11.5px;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    cursor: pointer;
}

.player-toggle-btn.is-selected {
    color: var(--on-accent);
    background: var(--accent-1);
    border-color: var(--accent-1);
}

.player-join-btn {
    width: 100%;
    padding: 12px 18px;
    font-size: 15px;
}

/* ── Owner: Stop, with guests connected ────────────────────────────────── */

.share-exit-body {
    margin: 0 0 12px;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text-2);
}

.share-exit-options {
    margin: 0;
    padding-left: 18px;
    font-size: 12.5px;
    line-height: 1.7;
    color: var(--text-2);
}

.share-exit-options strong {
    color: var(--text-1);
}

.player-refresh {
    margin-top: 18px;
    padding: 7px 16px;
    font-size: 12px;
}
