:root {
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    background: var(--cr-bg, #f5f5f7);
    color: var(--cr-text, #1d1d1f);
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

button,
select,
textarea {
    font: inherit;
}

button,
select,
.back-link,
.new-game-link,
.empty-games a {
    min-height: 44px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.back-link:focus-visible,
.new-game-link:focus-visible,
.empty-games a:focus-visible {
    outline: 3px solid rgba(0, 113, 227, 0.38);
    outline-offset: 3px;
}

.games-header {
    width: min(100% - 24px, 1040px);
    min-height: 78px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 16px;
    align-items: center;
}

.games-header h1,
.games-intro h2,
.empty-games h2,
.pgn-viewer h2 {
    margin: 0;
}

.games-header h1 {
    font-size: 28px;
    line-height: 1.1;
}

.games-header .community-header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.section-label {
    margin: 0 0 3px;
    color: var(--cr-accent, #0071e3);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.back-link,
.new-game-link,
.empty-games a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--cr-text-secondary, #68686d);
    font-weight: 800;
    text-decoration: none;
}

.new-game-link,
.empty-games a {
    border-radius: 11px;
    padding: 0 14px;
    background: var(--cr-accent, #0071e3);
    color: #fff;
}

.games-shell {
    width: min(100% - 24px, 1040px);
    margin: 0 auto;
    padding: 8px 0 48px;
}

.games-intro {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    padding: 20px 0 16px;
}

.games-intro h2 {
    font-size: 20px;
}

.games-intro p,
.empty-games p {
    max-width: 65ch;
    margin: 6px 0 0;
    color: var(--cr-text-secondary, #68686d);
    font-size: 14px;
    line-height: 1.5;
}

#gamesCount {
    flex: 0 0 auto;
    padding-top: 3px;
    color: var(--cr-text-secondary, #68686d);
    font-size: 13px;
    font-weight: 800;
}

.games-status {
    min-height: 24px;
    margin: 0 0 8px;
    color: #725000;
    font-size: 13px;
    font-weight: 800;
}

.undo-delete {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #fff4df;
    color: #6f3e00;
}

.undo-delete[hidden] {
    display: none;
}

.undo-delete p {
    margin: 0;
    font-size: 13px;
    font-weight: 800;
}

.undo-delete button,
.game-actions button,
.share-actions button,
.pgn-viewer button {
    border: 1px solid var(--cr-border, #e5e5e7);
    border-radius: 10px;
    background: #fff;
    color: var(--cr-text, #1d1d1f);
    cursor: pointer;
    font-weight: 800;
}

.loading-games {
    display: grid;
    gap: 1px;
    overflow: hidden;
    border-radius: 14px;
    background: var(--cr-border, #e5e5e7);
}

.loading-games span {
    display: block;
    height: 108px;
    background: linear-gradient(90deg, #fff 25%, #f1f1f3 45%, #fff 65%);
    background-size: 220% 100%;
    animation: loading-sheen 1.4s ease-in-out infinite;
}

@keyframes loading-sheen {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}

.empty-games {
    padding: 48px 18px;
    border-radius: 14px;
    background: #fff;
    text-align: center;
}

.empty-games p {
    margin-right: auto;
    margin-left: auto;
}

.empty-games a {
    width: fit-content;
    margin: 18px auto 0;
}

.games-list {
    overflow: hidden;
    border: 1px solid var(--cr-border, #e5e5e7);
    border-radius: 14px;
    background: #fff;
}

.game-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px;
    gap: 12px 20px;
    padding: 18px;
}

.game-row + .game-row {
    border-top: 1px solid var(--cr-border, #e5e5e7);
}

.game-main {
    min-width: 0;
}

.game-title-line {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.game-title {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 18px;
}

.confirmed-badge {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 4px 8px;
    background: #eef8f1;
    color: #245c36;
    font-size: 11px;
    font-weight: 800;
}

.game-players,
.game-details,
.share-snapshot-note {
    margin: 5px 0 0;
    color: var(--cr-text-secondary, #68686d);
    font-size: 13px;
    line-height: 1.45;
}

.game-players {
    color: var(--cr-text, #1d1d1f);
    font-size: 14px;
    font-weight: 800;
}

.orientation-control {
    color: var(--cr-text-secondary, #68686d);
    font-size: 12px;
    font-weight: 800;
}

.orientation-control select {
    display: block;
    width: 100%;
    margin-top: 5px;
    border: 1px solid var(--cr-border, #e5e5e7);
    border-radius: 10px;
    background: #fff;
    padding: 0 9px;
    color: var(--cr-text, #1d1d1f);
}

.share-metadata {
    grid-column: 1 / -1;
    min-width: 0;
    margin: 0;
    border: 0;
    padding: 0;
}

.share-metadata legend {
    margin-bottom: 5px;
    padding: 0;
    color: var(--cr-text-secondary, #68686d);
    font-size: 12px;
    font-weight: 800;
}

.share-metadata-options {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
}

.share-metadata-options label {
    display: inline-flex;
    min-height: 32px;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
}

.share-metadata-options input {
    width: 18px;
    height: 18px;
    margin: 0;
}

.share-snapshot-note {
    grid-column: 1 / -1;
    margin: 0;
    color: #725000;
}

.game-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.game-actions button,
.share-actions button,
.pgn-viewer button {
    min-height: 44px;
    padding: 0 13px;
}

.share-actions {
    display: contents;
}

.share-actions .primary-share {
    border-color: var(--cr-accent, #0071e3);
    background: var(--cr-accent, #0071e3);
    color: #fff;
}

.game-actions .danger-button,
.share-actions .revoke-share {
    color: #b42318;
}

button:disabled,
input:disabled,
select:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.pgn-viewer,
.manual-share-copy {
    margin-top: 16px;
    padding: 18px;
    border-radius: 14px;
    background: #fff;
}

.pgn-viewer-heading {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
}

#pgnText,
.manual-share-copy textarea {
    width: 100%;
    min-height: 240px;
    margin-top: 12px;
    border: 1px solid var(--cr-border, #e5e5e7);
    border-radius: 10px;
    background: #fafafa;
    padding: 12px;
    resize: vertical;
    color: var(--cr-text, #1d1d1f);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
}

.pgn-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.manual-share-copy label {
    display: block;
    font-size: 13px;
    font-weight: 800;
}

.manual-share-copy textarea {
    min-height: 90px;
}

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

@media (max-width: 640px) {
    .games-header {
        grid-template-columns: auto 1fr;
        padding: 10px 0;
    }

    .games-header .community-header-actions {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .games-header .community-header-actions .new-game-link {
        grid-column: auto;
        padding: 0 8px;
        font-size: 13px;
        white-space: nowrap;
    }

    .new-game-link {
        grid-column: 1 / -1;
        width: 100%;
    }

    .games-intro {
        display: block;
    }

    #gamesCount {
        display: block;
        margin-top: 9px;
    }

    .game-row {
        grid-template-columns: 1fr;
        padding: 15px;
    }

    .orientation-control,
    .share-metadata,
    .share-snapshot-note,
    .game-actions {
        grid-column: 1;
    }

    .game-actions,
    .pgn-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .game-actions button,
    .share-actions button,
    .pgn-actions button {
        width: 100%;
    }

    .share-actions {
        display: grid;
        gap: 8px;
    }

    .undo-delete {
        align-items: stretch;
        flex-direction: column;
    }

    #pgnText {
        min-height: 320px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
/* Recover private manual/photo drafts without hiding confirmed games. */
.draft-imports { margin: 1rem 0; padding: 1rem; border: 1px solid #d8dee6; border-radius: 12px; }
.draft-imports h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.draft-import-link { display: block; padding: .6rem 0; overflow-wrap: anywhere; }
