*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --red: #C41E3A;
    --red-dark: #9B1630;
    --blue: #1E4D8C;
    --blue-dark: #143766;
    --blue-light: #2E6AB4;
    --cream: #F5F0E6;
    --cream-dark: #E8E0D0;
    --gold: #C8A951;
    --gold-light: #E8D590;
    --white: #FEFEFE;
    --text: #2C1810;
    --text-muted: #8B7D72;

    --font-display: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
    --font-body: 'Outfit', system-ui, -apple-system, sans-serif;

    --shadow-sm: 0 1px 3px rgba(44, 24, 16, 0.12);
    --shadow-md: 0 4px 12px rgba(44, 24, 16, 0.15);
    --shadow-lg: 0 8px 30px rgba(44, 24, 16, 0.2);
    --radius-sm: 12px;
    --radius-md: 16px;
}

html, body {
    height: 100%;
    font-family: var(--font-body);
    color: var(--text);
    background: var(--cream);
    overflow-x: hidden;
}

/* In-app browser banner */
.inapp-banner {
    background: var(--blue);
    color: var(--white);
    text-align: center;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
}
.inapp-banner a {
    color: var(--gold-light);
    font-weight: 700;
    margin-left: 0.5rem;
    text-decoration: underline;
}

/* Dutch flag stripe */
.flag-stripe {
    height: 5px;
    background: linear-gradient(to right, var(--red) 33.3%, var(--white) 33.3% 66.6%, var(--blue) 66.6%);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

/* Screens */
.screen {
    display: none;
    min-height: calc(100vh - 5px);
    margin-top: 5px;
}
.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}
#screen-game.active {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 8px 8px 16px;
}

/* --- Buttons & Inputs --- */
input[type="text"] {
    font-family: var(--font-body);
    font-size: 1rem;
    padding: 0.7rem 1rem;
    border: 2px solid var(--cream-dark);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--text);
    width: 100%;
    max-width: 280px;
    transition: border-color 0.2s;
    outline: none;
}
input[type="text"]:focus {
    border-color: var(--blue-light);
}
input[type="text"]::placeholder {
    color: var(--text-muted);
}

.btn {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    padding: 0.7rem 2rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.02em;
}
.btn-primary {
    background: var(--red);
    color: var(--white);
    box-shadow: 0 2px 8px rgba(196, 30, 58, 0.3);
}
.btn-primary:hover {
    background: var(--red-dark);
    box-shadow: 0 4px 12px rgba(196, 30, 58, 0.4);
    transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--blue);
    color: var(--white);
    box-shadow: 0 2px 8px rgba(30, 77, 140, 0.3);
}
.btn-secondary:hover { background: var(--blue-dark); }

.btn-home {
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: color 0.2s, background 0.2s;
}
.btn-home:hover {
    color: var(--text);
    background: var(--cream-dark);
}

.btn-small {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.35rem 0.7rem;
    background: var(--cream);
    border: 1px solid var(--cream-dark);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
    color: var(--text-muted);
}
.btn-small:hover { background: var(--cream-dark); }

/* --- Intro Screen --- */
.intro-content {
    text-align: center;
    padding: 2rem 1.5rem;
    max-width: 420px;
    width: 100%;
    animation: fadeIn 0.5s ease-out;
}
.cover-image {
    width: 220px;
    height: auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    transform: rotate(-2deg);
    transition: transform 0.4s ease;
    margin-bottom: 1.5rem;
}
.cover-image:hover {
    transform: rotate(0deg) scale(1.03);
}
.title {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--blue);
    margin-bottom: 0.2rem;
    animation: fadeUp 0.5s ease-out 0.1s both;
}
.subtitle {
    font-family: var(--font-display);
    font-size: 1.1rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 2rem;
    animation: fadeUp 0.5s ease-out 0.2s both;
}
.form-group { margin-bottom: 1rem; }

.divider {
    display: flex;
    align-items: center;
    margin: 1.2rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--cream-dark);
}
.divider span { padding: 0 0.75rem; }

.intro-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-bottom: 0.5rem;
}
.join-panel {
    animation: fadeUp 0.3s ease-out;
}
.join-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
}
.join-row input {
    max-width: 130px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.15em;
    text-align: center;
}
.error-msg {
    color: var(--red);
    font-size: 0.85rem;
    margin-top: 1rem;
    min-height: 1.2em;
}

/* --- Lobby Screen --- */
.lobby-content {
    text-align: center;
    padding: 2rem 1.5rem;
    max-width: 480px;
    width: 100%;
    animation: fadeIn 0.4s ease-out;
}
.section-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
    color: var(--blue);
    margin-bottom: 1.5rem;
}
.code-box {
    background: var(--white);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: inline-block;
    margin-bottom: 0.4rem;
}
.code-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.3rem;
}
.code-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}
.code-value {
    font-family: var(--font-body);
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    color: var(--red);
}
.link-row {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}
.lobby-link {
    font-size: 0.75rem !important;
    padding: 0.4rem 0.6rem !important;
    max-width: 240px !important;
    color: var(--text-muted) !important;
    text-align: left !important;
    letter-spacing: normal !important;
    font-weight: 400 !important;
}
.player-list {
    text-align: left;
    margin: 1.5rem auto;
    max-width: 300px;
}
.player-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.35rem;
    background: var(--white);
    font-weight: 500;
}
.player-item.disconnected { opacity: 0.5; }
.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.host-badge {
    font-size: 0.65rem;
    background: var(--gold);
    color: var(--white);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin-left: auto;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.pairs-control { margin: 1.5rem 0; }
.pairs-control label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.size-options {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}
.btn-size {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border: 2px solid var(--cream-dark);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}
.btn-size:hover { border-color: var(--blue-light); }
.btn-size.selected {
    border-color: var(--blue);
    background: var(--blue);
    color: var(--white);
}
.btn-start { margin-top: 0.5rem; }
.status-msg {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* --- Game Screen --- */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    margin-bottom: 6px;
    background: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    gap: 0.5rem;
}
.scoreboard {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.score-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: all 0.3s;
}
.score-item.active {
    background: var(--cream);
    box-shadow: inset 0 0 0 2px var(--gold);
}
.score-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.score-name { font-size: 0.9rem; }
.score-val {
    font-weight: 700;
    font-size: 1.1rem;
    margin-left: 0.15rem;
}
.turn-info {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}
.turn-info.your-turn { color: var(--red); }

/* Game body: board + side panel */
.game-body {
    display: flex;
    gap: 12px;
    flex: 1;
    min-height: 0;
}

/* Board */
.board {
    display: grid;
    gap: 6px;
    flex: 1;
    max-width: 1000px;
    margin: 0 auto;
    padding: 8px;
    align-content: start;
}

/* Side panel */
.side-panel {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding-top: 12px;
}
.side-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}
.side-card-wrap {
    text-align: center;
}
.side-cards img {
    width: 200px;
    height: 200px;
    object-fit: cover;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    animation: scaleIn 0.3s ease-out;
}
.side-card-wrap .card-label {
    margin-top: 4px;
}
.side-card-wrap .name-nl {
    font-size: 1.3rem;
}
.side-card-wrap .name-en {
    font-size: 1.05rem;
}
.side-status {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    min-height: 1.2em;
}
.btn-seen, .btn-force {
    width: 100%;
    max-width: 200px;
}
.btn-force {
    font-size: 0.7rem;
    padding: 0.3rem 0.6rem;
    opacity: 0.6;
    max-width: 140px;
}

/* Cards */
.card {
    aspect-ratio: 1;
    perspective: 800px;
    cursor: pointer;
    transform: translate(var(--jx, 0px), var(--jy, 0px)) rotate(var(--jr, 0deg));
    transition: transform 0.4s ease-out;
    z-index: 1;
}
.card:hover { z-index: 2; }

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
}
.card.flipped .card-inner {
    transform: rotateY(180deg);
}
.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.card.rotating .card-front {
    overflow: visible;
}
.card-face img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}
.card-back { background: var(--cream-dark); }
.card-front {
    transform: rotateY(180deg);
    background-color: transparent;
}

/* Card front image wrapper — handles upside-down animation */
.card-img {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    border-radius: var(--radius-sm);
}

/* Card name label */
.card-label {
    text-align: center;
    margin-top: 2px;
    line-height: 1.2;
    display: none;
}
.card-label .name-nl {
    display: block;
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--text);
}
.card-label .name-en {
    display: block;
    font-size: 0.45rem;
    color: var(--text-muted);
    font-style: italic;
}
.btn-speak {
    cursor: pointer;
    opacity: 0.5;
    font-style: normal;
}
.btn-speak:hover { opacity: 1; }

/* Hoverable face-down cards when it's your turn */
.board.my-turn .card:not(.flipped):not(.matched):hover .card-face {
    box-shadow: 0 2px 14px rgba(30, 77, 140, 0.35);
}
.board:not(.my-turn) .card:not(.flipped):not(.matched) {
    cursor: default;
}

/* Matched cards */
.card.matched .card-inner {
    opacity: 0.6;
}
.card.matched .card-face {
    box-shadow: 0 0 0 2px var(--gold), var(--shadow-sm);
}
.card.matched { cursor: pointer; }
.card.just-matched .card-face {
    animation: matchGlow 0.6s ease-out;
}
.card.matched-hidden .card-inner {
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.4s, transform 0.4s;
}
.card.matched-hidden {
    pointer-events: none;
}

/* Match flash */
.match-flash {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    font-family: var(--font-display);
    font-size: 4rem;
    font-weight: 700;
    color: var(--gold);
    text-shadow: 0 2px 20px rgba(200, 169, 81, 0.5);
    z-index: 600;
    pointer-events: none;
    animation: matchFlash 1.2s ease-out forwards;
}
@keyframes matchFlash {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    60% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(0.8); }
}

/* Player piles */
.player-piles {
    width: 100%;
    margin-top: 8px;
}
.player-pile {
    margin-bottom: 8px;
}
.pile-header {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}
.pile-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.pile-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}
.pile-cards img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* --- Overlay (for individual card zoom) --- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 15, 10, 0.75);
    backdrop-filter: blur(5px);
    z-index: 500;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.overlay.visible {
    display: flex;
    animation: fadeIn 0.15s ease-out;
}
.overlay-cards {
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
}
.overlay-cards img {
    max-width: 340px;
    max-height: 65vh;
    border-radius: var(--radius-md);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.4);
    animation: scaleIn 0.25s ease-out;
}

/* --- End Screen --- */
.end-content {
    text-align: center;
    padding: 2rem 1.5rem;
    max-width: 480px;
    width: 100%;
    animation: fadeIn 0.5s ease-out;
}
.end-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--white);
    background: var(--blue);
    padding: 0.3rem 1rem;
    border-radius: 20px;
    margin-bottom: 1rem;
}
.end-title {
    font-family: var(--font-display);
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--red);
    margin-bottom: 0.3rem;
}
.end-subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}
.final-scores {
    margin: 1.5rem auto;
    max-width: 300px;
}
.final-score-item {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    margin-bottom: 0.3rem;
    background: var(--white);
    border-radius: var(--radius-sm);
    font-weight: 500;
}
.final-score-item.winner {
    background: var(--gold);
    color: var(--white);
    font-weight: 700;
}
.final-score-item .fs-score { font-weight: 700; }

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.85); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes matchGlow {
    0% { box-shadow: 0 0 0 0 rgba(200, 169, 81, 0.7); }
    100% { box-shadow: 0 0 0 2px var(--gold), var(--shadow-sm); }
}
@keyframes wiggle {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-6px); }
    30% { transform: translateX(5px); }
    45% { transform: translateX(-4px); }
    60% { transform: translateX(3px); }
    75% { transform: translateX(-2px); }
    90% { transform: translateX(1px); }
}
.wiggle {
    animation: wiggle 0.5s ease-in-out;
}

/* --- Responsive --- */
@media (max-width: 800px) {
    #screen-game.active {
        padding: 4px 4px 8px;
        min-height: auto;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }
    .game-header {
        padding: 0.3rem 0.5rem;
        margin-bottom: 4px;
        flex-shrink: 0;
    }
    .game-body {
        flex-direction: column;
        overflow: hidden;
        flex: 1;
        min-height: 0;
    }
    .board {
        flex: 1;
        min-height: 0;
        width: 100%;
        max-width: 100%;
        gap: 3px;
        padding: 3px;
        align-content: start;
    }
    .card {
        aspect-ratio: 1;
    }
    .side-panel {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        padding: 6px 0 0;
        gap: 6px;
        flex-shrink: 0;
        max-height: 30vh;
        overflow-y: auto;
    }
    .side-cards {
        flex-direction: row;
        gap: 6px;
    }
    .side-cards img {
        width: 80px;
        height: 80px;
    }
    .side-card-wrap .name-nl { font-size: 0.75rem; }
    .side-card-wrap .name-en { font-size: 0.6rem; }
    .btn-seen { max-width: 140px; }
    .player-piles { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
    .pile-cards img { width: 24px; height: 24px; }
    .scoreboard { gap: 0.4rem; }
    .score-name { font-size: 0.75rem; }
    .score-val { font-size: 0.9rem; }
}
@media (max-width: 600px) {
    .cover-image { width: 170px; }
    .title { font-size: 2.4rem; }
    .board { gap: 2px; padding: 2px; }
}
