/* ============================================================
   PLAY PAGE
   Free-to-play games (page-play.php, JS/play.js)
   Uses the site's shared look from main.css: Orbitron headings,
   .card panels, .primary-btn / .secondary-btn buttons.
   ============================================================ */

.play-page section {
    padding: 2rem 0;
}

/* Last section on the page (the donate banner, or the games when donations
   are switched off): the usual space above the footer */
.play-page > section:last-of-type {
    padding-bottom: 5rem;
}

/* Same treatment as the About page title */
.play-intro {
    text-align: center;
    padding-top: 5rem !important;
}

/* ---------- Player ---------- */
.player[hidden] {
    display: none;
}

.player {
    /* main.css already leaves room for the sticky header when scrolling to
       anything (html scroll-padding-top); this pulls the player up into that
       air so the title sits just below the header */
    scroll-margin-top: -1.25rem;
    padding-top: 1rem !important;
    /* Fade only: a transform here would put the game frame in a moving layer */
    animation: player-in 0.35s ease both;
}

@keyframes player-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.player-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 2rem;
    align-items: start;
}

/* Sized so the title, the whole 16:9 screen, its controls and the note fit
   on screen below the site header without scrolling. svh is the viewport
   with the browser's toolbars showing, so it doesn't change as you scroll
   on phones (which would resize the game mid-scroll). */
.player-main {
    --player-chrome: calc(clamp(56px, 7vw, 96px) + 255px);
    width: min(100%, max(560px, calc((100vh - var(--player-chrome)) * 16 / 9 + 26px)));
    width: min(100%, max(560px, calc((100svh - var(--player-chrome)) * 16 / 9 + 26px)));
    justify-self: center;
    min-width: 0;
}

.player svg {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Title row above the screen */
.player-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    min-width: 0;
}

.player-heading {
    min-width: 0;
}

.player-heading h2 {
    margin: 0;
    color: #10D9EE;
    letter-spacing: 1px;
    font-size: clamp(1.4rem, 2.4vw, 1.8rem);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-creator {
    margin: 0.15rem 0 0;
    max-width: none;
    font-size: 0.95rem;
    color: #7CF7FC;
}

.player-creator:empty {
    display: none;
}

/* Player buttons: .secondary-btn .btn-sm (main.css), laid out with their icon */
.player .player-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    flex: none;
}

.player .player-btn[hidden] {
    display: none;
}

/* The screen: a site card with the game inside */
.player-screen {
    padding: 12px;
    border-radius: 15px;
    background: linear-gradient(135deg, rgba(34, 8, 0, 0.8), rgba(0, 0, 0, 0.9));
    border: 1px solid #10D9EE;
    box-shadow: 0 0 25px rgba(16, 217, 238, 0.2), 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* No rounded corners or overflow clipping around the iframe: browsers
   re-clip a clipped game frame on every scroll frame, which can smear or
   warp WebGL games while the page scrolls. */
/* The sandboxed game is drawn by its own browser process. Giving the frame
   its own compositor layer makes Chrome move its finished picture as one
   piece while scrolling, instead of showing stale tiles of the page in the
   parts that scroll back out from under the sticky header. */
.player-stage {
    position: relative;
    aspect-ratio: 16 / 9;
    width: 100%;
    background: #000;
}

.player-stage iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #000;
    will-change: transform;
    transform: translateZ(0);
}

/* Fullscreen: the stage fills the screen */
.player-stage:fullscreen {
    aspect-ratio: auto;
    width: 100%;
    height: 100%;
}

.player-stage:-webkit-full-screen {
    width: 100%;
    height: 100%;
}

/* Loading screen: the game's cover, blurred, behind a spinner */
.player-loading {
    position: absolute;
    inset: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: radial-gradient(ellipse at center, #2a0b00 0%, #000 75%);
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.player-loading.is-done {
    opacity: 0;
}

.player-loading[hidden] {
    display: none;
}

.player-loading-bg {
    position: absolute;
    inset: -30px;
    background-size: cover;
    background-position: center;
    filter: blur(22px) brightness(0.35) saturate(1.2);
}

.player-loading-inner {
    position: relative;
    padding: 1rem;
}

.player-spinner {
    width: 56px;
    height: 56px;
    margin: 0 auto 1.1rem;
    border-radius: 50%;
    border: 3px solid rgba(16, 217, 238, 0.18);
    border-top-color: #10D9EE;
    border-right-color: #FB9E0A;
    animation: player-spin 0.9s linear infinite;
    box-shadow: 0 0 24px rgba(16, 217, 238, 0.25);
}

@keyframes player-spin {
    to { transform: rotate(360deg); }
}

.player-loading-title {
    margin: 0 0 0.25rem;
    max-width: none;
    font-family: "Orbitron", sans-serif;
    font-size: 1.15rem;
    letter-spacing: 1px;
    color: #fff;
}

.player-loading-note {
    margin: 0;
    max-width: none;
    font-size: 0.85rem;
    color: #7CF7FC;
}

/* Shown when the game doesn't have keyboard focus */
.player-focus-hint {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid rgba(16, 217, 238, 0.5);
    color: #d6f9fc;
    font-size: 0.85rem;
    white-space: nowrap;
    pointer-events: none;
    animation: hint-pulse 2s ease-in-out infinite;
}

.player-focus-hint[hidden] {
    display: none;
}

.player-focus-hint svg {
    width: 16px;
    height: 16px;
    color: #10D9EE;
}

@keyframes hint-pulse {
    50% { border-color: rgba(16, 217, 238, 0.15); }
}

/* Control bar under the screen */
.player-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 12px 2px 0;
}

.player-keys {
    margin: 0;
    max-width: none;
    font-size: 0.85rem;
    color: #7CF7FC;
    min-width: 0;
}

.player-keys kbd {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border-radius: 5px;
    border: 1px solid rgba(16, 217, 238, 0.4);
    border-bottom-width: 2px;
    background: rgba(16, 217, 238, 0.08);
    color: #d6f9fc;
    font-family: inherit;
    font-size: 0.78rem;
    line-height: 1.5;
}

.player-tools {
    display: flex;
    gap: 0.6rem;
    flex: none;
}

/* "Plays best on a computer" note, right under the screen */
.play-device-note {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    max-width: none;
    margin: 0.9rem 0 0;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #7CF7FC;
}

.play-device-note svg {
    margin-top: 0.1rem;
    color: #FB9E0A;
}

/* ---------- Side panel ---------- */
.player-side {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    /* lines the panel up with the top of the screen, under the title row */
    margin-top: 5rem;
}

/* .card from main.css supplies the background, border and radius */
/* Same inner padding as every other card (2rem; 1.5rem on phones) */
.donate-panel.card {
    text-align: center;
    padding: 2rem;
}

.donate-heart {
    width: 34px;
    height: 34px;
    fill: #FB9E0A;
    stroke: none;
    filter: drop-shadow(0 0 10px rgba(251, 158, 10, 0.7));
    animation: heart-beat 2.4s ease-in-out infinite;
}

.player .donate-heart {
    width: 34px;
    height: 34px;
    fill: #FB9E0A;
    stroke: none;
}

@keyframes heart-beat {
    0%, 60%, 100% { transform: scale(1); }
    30% { transform: scale(1.12); }
}

.donate-panel.card h3 {
    text-align: center;
    font-size: 1.4rem;
    color: #FB9E0A;
    margin: 0.5rem 0 0.75rem;
}

.donate-panel.card p {
    font-size: 0.95rem;
    line-height: 1.6;
    margin: 0 0 1.25rem;
}

.donate-panel .donate-btn {
    display: block;
    width: 100%;
    max-width: none;
}

.player-itch {
    display: inline-block;
    margin-top: 1.1rem;
    font-size: 0.9rem;
    color: #10D9EE;
    text-decoration: none;
    border-bottom: 1px solid rgba(16, 217, 238, 0.35);
}

.player-itch:hover {
    color: #7CF7FC;
    border-bottom-color: #7CF7FC;
}

.player-itch[hidden] {
    display: none;
}

/* More games */
.player-more[hidden] {
    display: none;
}

.player-more h4 {
    margin: 0 0 0.75rem;
    font-family: "Orbitron", sans-serif;
    font-size: 1rem;
    letter-spacing: 1px;
    color: #10D9EE;
}

.player-more-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Small versions of the game cards */
.player button.player-more-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    width: 100%;
    padding: 0.6rem;
    text-align: left;
    font-family: inherit;
    font-weight: 600;
    border-radius: 15px;
    background: linear-gradient(135deg, rgba(34, 8, 0, 0.8), rgba(0, 0, 0, 0.9));
    color: #d6f9fc;
    border: 1px solid rgba(16, 217, 238, 0.45);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
    transform: none;
    cursor: pointer;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.player button.player-more-item:hover,
.player button.player-more-item:focus-visible {
    background: linear-gradient(135deg, rgba(34, 8, 0, 0.8), rgba(0, 0, 0, 0.9));
    border-color: #7CF7FC;
    color: #fff !important;
    transform: none;
    box-shadow: 0 0 25px rgba(16, 217, 238, 0.3);
}

.player-more-thumb {
    width: 64px;
    height: 48px;
    flex: none;
    border-radius: 8px;
    overflow: hidden;
    background: linear-gradient(135deg, #3a1000, #000);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Orbitron", sans-serif;
    font-weight: 700;
    color: #FB9E0A;
}

.player-more-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.player-more-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.3;
}

.player-more-text strong {
    font-family: "Orbitron", sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: #10D9EE;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-more-text small {
    margin-top: 0.15rem;
    font-size: 0.8rem;
    font-weight: 400;
    color: #d6f9fc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Game grid ---------- */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 2rem;
}

.game-card {
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, rgba(34, 8, 0, 0.8), rgba(0, 0, 0, 0.9));
    border: 1px solid #10D9EE;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

/* Same lift and glow as the About page cards */
.game-card:hover {
    transform: translateY(-10px);
    border-color: #7CF7FC;
    box-shadow: 0 0 25px rgba(16, 217, 238, 0.3);
}

.game-card.is-playing {
    border-color: #FB9E0A;
    box-shadow: 0 0 25px rgba(251, 158, 10, 0.35), 0 10px 30px rgba(0, 0, 0, 0.5);
}

.game-cover {
    aspect-ratio: 5 / 4;
    background: #000;
}

.game-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.game-cover img.game-cover-fallback {
    object-fit: contain;
    padding: 15%;
}

.game-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 1.5rem 1.75rem 1.75rem;
}

.game-info h3 {
    font-size: 1.5rem;
    text-align: left;
    margin-bottom: 0.35rem;
}

.game-info p {
    margin: 0 0 0.75rem;
    max-width: none;
}

.game-creator {
    font-size: 0.95rem;
    color: #7CF7FC;
}

.game-desc {
    font-size: 1rem;
    line-height: 1.6;
}

.play-btn {
    margin-top: auto;
    align-self: flex-start;
}

.games-empty {
    text-align: center;
    padding: 2rem 0;
}

.games-empty h3 {
    margin-bottom: 1rem;
}

/* ---------- Donate banner ---------- */
.donate-banner {
    text-align: center;
}

/* ---------- Motion off ---------- */
@media (prefers-reduced-motion: reduce) {
    .player,
    .player-spinner,
    .player-focus-hint,
    .donate-heart {
        animation: none;
    }
}

/* ---------- Tablets / phones ---------- */
@media (max-width: 1024px) {
    .player-layout {
        grid-template-columns: 1fr;
    }

    .player-main {
        width: 100%;
    }

    .player-side {
        margin-top: 0;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
        align-items: start;
    }

    /* main.css centres h3 on tablets; the player title stays left */
    .player-heading h2 {
        text-align: left;
    }
}

@media (max-width: 768px) {
    .play-page section {
        padding: 1.5rem 0;
    }

    .play-page > section:last-of-type {
        padding-bottom: 3.5rem;
    }

    .play-intro {
        padding-top: 3rem !important;
    }

    .player-screen {
        padding: 8px;
    }

    .player-keys-esc {
        display: none;
    }

    .player .player-btn span {
        display: none;
    }

    .player .player-btn {
        padding: 0.55rem 0.7rem;
    }

    /* Keeps the "All games" label: it's the way back */
    .player .player-back span {
        display: inline;
    }

    .games-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .play-btn {
        align-self: stretch;
        max-width: none;
    }
}

/* ---------- Mute button ---------- */
.player .player-btn .icon-muted,
.player .player-btn[aria-pressed="true"] .icon-sound {
    display: none;
}

.player .player-btn[aria-pressed="true"] .icon-muted {
    display: block;
}

/* Muted: orange, so it's clear the sound is off */
.player .player-btn[aria-pressed="true"],
.player .player-btn[aria-pressed="true"]:hover,
.player .player-btn[aria-pressed="true"]:focus-visible {
    color: #FB9E0A !important;
    border-color: #FB9E0A;
    box-shadow: 0 0 12px rgba(251, 158, 10, 0.4);
}

/* Photosensitivity / accessibility notice under the device note */
.play-safety-note a {
    color: #10D9EE;
}
