:root {
    --bg-a: #f2f5f1;
    --bg-b: #e9efea;
    --ink: #213042;
    --ink-soft: #5a6b7e;
    --brand: #63be6a;
    --brand-dark: #3f9f4b;
    --accent: #2b3a4f;
    --panel: #ffffff;
    --panel-border: #cfd5dc;
    --shadow: 0 10px 24px rgba(20, 33, 55, 0.12);
    --radius: 16px;
}

html {
    box-sizing: border-box;
}

*,
*::before,
*::after {
    box-sizing: inherit;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
}

body {
    background:
        linear-gradient(90deg, rgba(35, 57, 42, 0.025) 1px, transparent 1px),
        linear-gradient(180deg, rgba(35, 57, 42, 0.025) 1px, transparent 1px),
        linear-gradient(160deg, var(--bg-a), var(--bg-b));
    background-size: 16px 16px, 16px 16px, auto;
    color: var(--ink);
    font-family: "Space Grotesk", "Open Sans", sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

a {
    color: var(--brand);
    text-underline-offset: 2px;
}

a:hover {
    color: #064969;
}

.container {
    --container-side-pad: 1.5rem;
    width: min(1120px, 94vw);
    margin: 1.2rem auto 1.5rem;
    padding: 0 1.5rem 1.5rem;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
    background: var(--panel);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    flex-direction: column;
}

.masthead {
    width: calc(100% + (2 * var(--container-side-pad)));
    max-width: none;
    display: flex;
    align-items: center;
    margin: 0 calc(-1 * var(--container-side-pad)) 1rem;
    padding: 0.8rem var(--container-side-pad);
    justify-content: flex-start;
    background: linear-gradient(180deg, #f8fcf7, #eef7ef);
    border-top: 5px solid var(--brand);
    border-bottom: 1px solid #d4e4d6;
}

.masthead-link {
    display: inline-flex;
    align-items: center;
}

.masthead-brand {
    height: 34px;
    width: auto;
    max-width: min(360px, 100%);
    display: block;
    filter: none;
}

h1 {
    margin: 0 0 0.6rem;
    text-align: center;
    font-family: "Londrina Solid", cursive;
    font-size: clamp(1.9rem, 4.4vw, 3rem);
    letter-spacing: 0.01em;
    color: var(--ink);
}

p {
    width: min(72rem, 100%);
    margin: 0.25rem 0 0.65rem;
    color: var(--ink-soft);
}

.site-footer {
    width: min(72rem, 100%);
    margin: 1.15rem 0 0.1rem;
    padding: 0.65rem 0.9rem;
    border-top: 1px solid #d7dfe8;
    background: linear-gradient(180deg, #fbfdfb, #f4f8f5);
    border-radius: 8px;
    color: #607082;
    font-size: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    text-align: center;
}

.site-footer-copy {
    color: #5f7083;
}

.site-footer-sep {
    color: #9aa8b8;
}

.site-footer a {
    color: #2f8f3f;
    font-weight: 600;
    text-decoration: none;
}

.site-footer a:hover {
    color: #256f31;
    text-decoration: underline;
}

.deck {
    width: min(72rem, 100%);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #c6dbca;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
    background: linear-gradient(180deg, #dff0e2, #d3e9d7);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    margin: 0 0 1.8rem;
}

.deck .card {
    width: clamp(74px, 9.2vw, 120px);
    aspect-ratio: 1 / 1;
    margin: 0;
    background-image: url("../img/sargasso-icon.png");
    background-repeat: no-repeat;
    background-size: cover;
    border-radius: 10px;
    border: 1px solid rgba(39, 79, 52, 0.25);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
    transition: transform 150ms ease, box-shadow 150ms ease;
}

.deck .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 16px rgba(0, 0, 0, 0.3);
}

.deck .card.open {
    cursor: default;
    animation-name: flipInY;
    animation-duration: .55s;
    -webkit-backface-visibility: visible !important;
    backface-visibility: visible !important;
    transform: scale(1.02);
}

.deck .card.show {
    font-size: 0;
}

.deck .card.match {
    cursor: default;
    animation-name: rubberBand;
    animation-duration: .6s;
    -webkit-backface-visibility: visible !important;
    backface-visibility: visible !important;
    transform: scale(1.02);
}

.deck .card.match i {
    background: #a1e832;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    opacity: 0.36;
}

.deck .card.unmatched {
    animation-name: pulse;
    animation-duration: .45s;
    -webkit-backface-visibility: visible !important;
    backface-visibility: visible !important;
}

.deck .card.unmatched i {
    background: #e2043b;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    opacity: 0.45;
}

.deck .card.disabled {
    pointer-events: none;
}

.open-play .deck .card.open:not(.match):not(.disabled) {
    cursor: pointer;
}

.inverted-play .deck .card.open {
    animation: none;
    transform: none;
}

.inverted-play .deck .card.open:not(.match):not(.disabled) {
    cursor: pointer;
}

.inverted-play .deck .card.active-pick {
    outline: none;
    transform: scale(1.04);
}

.inverted-play .deck .card.matched-away {
    opacity: 0;
    transform: rotateY(90deg) scale(0.82);
    transition: transform 260ms ease, opacity 260ms ease;
    pointer-events: none;
}

.mini-mode .deck {
    width: min(36rem, 100%);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.55rem;
}

.mini-mode .deck .card {
    width: 100%;
    min-width: 0;
}

.score-panel {
    width: min(72rem, 100%);
    margin: 0.85rem 0 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    border-top: 4px solid var(--brand);
    background: #f8fcf8;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.8rem;
    align-items: center;
}

.score-meta {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.score-chip,
.timer {
    min-width: 100px;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-weight: 700;
    color: #1f3a2a;
    background: #ffffff;
    border: 1px solid #c9d2de;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.score-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
}

.game-controls {
    justify-content: flex-start;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.55rem;
}

.game-controls .score-row-top,
.game-controls .score-row-middle,
.game-controls .score-row-bottom {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.game-controls .score-row-middle {
    margin-left: auto;
}

@media (min-width: 761px) and (max-width: 1080px) {
    .game-controls {
        flex-wrap: wrap;
    }

    .game-controls .score-row-top {
        flex: 1 1 100%;
        justify-content: space-between;
    }

    .game-controls .score-row-top .action-reset {
        margin-left: auto;
    }

    .game-controls .score-row-middle {
        margin-left: 0;
    }

    .game-controls .score-row-bottom {
        margin-left: auto;
    }
}

.scores-page-actions {
    width: 100%;
}

.score-switcher-wrap {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.action-button {
    border: 1px solid var(--brand-dark);
    background: linear-gradient(180deg, #76cc7d, #4eb25a);
    color: #ffffff;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.95rem;
    height: 2.1rem;
    padding: 0 0.8rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    transition: filter 160ms ease;
}

.action-button:link,
.action-button:visited,
.action-button:hover,
.action-button:active {
    color: #ffffff;
    text-decoration: none;
}

.action-button:hover {
    filter: brightness(0.93);
}

.action-button:focus-visible,
#play-again:focus-visible {
    filter: brightness(0.93);
}

.action-button-subtle {
    background: #eef3f9;
    color: #1f2f43;
    border-color: #bfcad8;
}

.action-button-subtle:link,
.action-button-subtle:visited,
.action-button-subtle:hover,
.action-button-subtle:active {
    color: #1f2f43;
}

.action-button-icon {
    width: 2.3rem;
    height: 2.3rem;
    padding: 0;
    font-size: 1.25rem;
}

.version-switcher {
    font-size: 0.9rem;
    color: var(--ink-soft);
}

.version-switcher-select {
    border-radius: 6px;
    border: 1px solid #bfcad8;
    padding: 0.4rem 0.55rem;
    background: #fff;
    color: var(--ink);
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    transition: opacity 300ms;
    visibility: hidden;
    opacity: 0;
}

.overlay:target {
    visibility: visible;
    opacity: 1;
}

.popup {
    margin: 70px auto;
    padding: 20px;
    background: #ffffff;
    border-radius: 14px;
    width: min(680px, 92vw);
    position: relative;
    font-family: "Londrina Solid", cursive;
}

.popup h2 {
    margin-top: 0;
    color: #1f2f43;
    font-size: 2rem;
}

.popup .close {
    position: absolute;
    top: 14px;
    right: 18px;
    transition: color 200ms;
    font-size: 32px;
    font-weight: bold;
    text-decoration: none;
    color: #333;
}

.popup .close:hover {
    color: var(--brand-dark);
}

.popup .content-1,
.popup .content-2 {
    text-align: center;
    color: #384f67;
}

.leaderboard {
    margin-top: 0.8rem;
    text-align: left;
    border-top: 1px solid #d7e3d9;
    padding-top: 0.6rem;
}

.leaderboard h3 {
    margin: 0 0 0.35rem;
    font-family: "Space Grotesk", "Open Sans", sans-serif;
    font-size: 1rem;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.leaderboard-table th,
.leaderboard-table td {
    text-align: left;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #e1e7e4;
    font-size: 0.9rem;
}

.leaderboard-table thead th {
    background: #edf7ef;
    color: #21432a;
    font-weight: 700;
}

.score-submit {
    margin-top: 0.9rem;
    border-top: 1px solid #d7e3d9;
    padding-top: 0.7rem;
}

.score-submit-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.score-submit-input {
    min-width: 180px;
    max-width: 280px;
    width: 100%;
    padding: 0.45rem 0.55rem;
    border: 1px solid #bfcad8;
    border-radius: 6px;
    font-family: "Space Grotesk", "Open Sans", sans-serif;
}

.score-submit-status {
    min-height: 1.2rem;
    margin: 0.45rem 0 0;
    font-size: 0.95rem;
}

.scores-page-panel {
    overflow-x: auto;
}

.scores-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.scores-table th,
.scores-table td {
    text-align: left;
    padding: 0.55rem 0.65rem;
    border-bottom: 1px solid #e1e7e4;
    font-size: 0.95rem;
}

.scores-table thead th {
    background: #edf7ef;
    color: #21432a;
    font-weight: 700;
}

.scores-table tbody tr:nth-child(even) {
    background: #f9fcfa;
}

.show {
    visibility: visible !important;
    opacity: 1 !important;
}

#play-again {
    background: linear-gradient(180deg, #76cc7d, #4eb25a);
    padding: 0.7rem 1rem;
    font-size: 1.1rem;
    display: block;
    margin: 0.8rem auto 0;
    width: min(280px, 100%);
    font-family: "Londrina Solid", cursive;
    color: #ffffff;
    border-radius: 9px;
    border: 0;
    transition: filter 160ms ease;
}

#play-again:hover {
    filter: brightness(0.93);
}

@keyframes flipInY {
    from {
        transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
        animation-timing-function: ease-in;
        opacity: 0;
    }

    40% {
        transform: perspective(400px) rotate3d(0, 1, 0, -20deg);
        animation-timing-function: ease-in;
    }

    60% {
        transform: perspective(400px) rotate3d(0, 1, 0, 10deg);
        opacity: 1;
    }

    80% {
        transform: perspective(400px) rotate3d(0, 1, 0, -5deg);
    }

    to {
        transform: perspective(400px);
    }
}

@keyframes rubberBand {
    from {
        transform: scale3d(1, 1, 1);
    }

    30% {
        transform: scale3d(1.18, 0.82, 1);
    }

    40% {
        transform: scale3d(0.82, 1.18, 1);
    }

    50% {
        transform: scale3d(1.1, 0.9, 1);
    }

    65% {
        transform: scale3d(.95, 1.05, 1);
    }

    75% {
        transform: scale3d(1.04, .96, 1);
    }

    to {
        transform: scale3d(1, 1, 1);
    }
}

@keyframes pulse {
    from {
        transform: scale3d(1, 1, 1);
    }

    50% {
        transform: scale3d(1.1, 1.1, 1.1);
    }

    to {
        transform: scale3d(1, 1, 1);
    }
}

@media (max-width: 760px) {
    .container {
        --container-side-pad: 0.65rem;
        width: 100%;
        margin: 0;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        padding: 1rem 0.65rem 1.2rem;
    }

    .score-panel {
        align-items: stretch;
    }

    .game-controls {
        flex-direction: column;
        gap: 0.55rem;
        flex-wrap: nowrap;
    }

    .game-controls .score-row {
        display: flex;
        align-items: center;
        width: 100%;
        gap: 0.55rem;
    }

    .game-controls .score-row-top {
        justify-content: space-between;
        flex-wrap: nowrap;
    }

    .game-controls .score-row-top .score-meta {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        min-width: 0;
    }

    .game-controls .score-row-top .score-chip,
    .game-controls .score-row-top .timer {
        min-width: 80px;
        padding: 0.32rem 0.55rem;
        font-size: 0.9rem;
    }

    .game-controls .score-row-top .action-reset {
        margin-left: auto;
        flex-shrink: 0;
    }

    .game-controls .score-row-middle .version-switcher-select {
        flex: 1;
        min-width: 0;
    }

    .game-controls .score-row-middle,
    .game-controls .score-row-bottom {
        justify-content: flex-end;
    }

    .game-controls .score-row-bottom .action-button {
        flex: 1;
    }

    .score-actions {
        width: 100%;
    }

    .version-switcher-select {
        flex: 1;
        min-width: 180px;
    }

    .deck {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .deck .card {
        width: 100%;
        min-width: 0;
    }

    .mini-mode .deck {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 540px) and (max-width: 760px) {
    .mini-mode .deck {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 430px) {
    .deck {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
