* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #cdd6f4;
    --secondary-color: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #c0392b;
    --light-bg: #1e2030;
    --white: #181926;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 5px 20px rgba(0, 0, 0, 0.5);
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

/* Écran configuration joueurs (iPad / icône écran d'accueil) : pas de plein écran fixe */
html.setup-mode,
html.setup-mode body {
    height: auto;
    min-height: 100%;
    overflow: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

body.setup-mode .container {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    max-width: 1200px;
    height: auto !important;
    min-height: 100dvh;
    overflow: visible;
    margin: 0 auto;
}

body.setup-mode input,
body.setup-mode textarea,
body.setup-mode button,
body.setup-mode select {
    touch-action: auto;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0a0c1a 0%, #11082a 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
}

.container {
    width: 100%;
    height: 100vh;
    max-width: 100%;
    background: var(--white);
    border-radius: 12px;
    padding: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

body.fullscreen-mode {
    padding: 0;
}

body.fullscreen-mode .container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    /* height fixée par JS via visualViewport pour exclure le clavier */
    height: 100vh;
    border-radius: 0;
    z-index: 100;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
}

#fullscreenBtn {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    z-index: 1000;
    background: rgba(44, 62, 80, 0.75);
    color: white;
    border: none;
    border-radius: 6px;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#fullscreenBtn:hover {
    background: rgba(44, 62, 80, 1);
}

header {
    text-align: center;
    margin-bottom: 0;
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 8px;
    flex-shrink: 0;
    overflow: hidden;
}

header h1 {
    color: var(--primary-color);
    font-size: 1em;
    margin-bottom: 2px;
}

.subtitle {
    color: #a6adc8;
    font-size: 0.9em;
}

/* Ticker de scores */
.score-ticker {
    overflow: hidden;
    height: 2em;
    display: flex;
    align-items: center;
    width: 100%;
}

.score-ticker-track {
    display: inline-flex;
    white-space: nowrap;
    animation: tickerScroll 18s linear infinite;
}

.score-ticker:hover .score-ticker-track {
    animation-play-state: paused;
}

@keyframes tickerScroll {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

.ticker-item {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary-color);
    padding: 0 6px;
}

.ticker-item .ticker-medal {
    margin-right: 2px;
}

.ticker-item .ticker-score {
    color: #2ecc71;
    font-weight: 800;
}

.ticker-sep {
    color: var(--secondary-color);
    font-weight: 900;
    padding: 0 4px;
    opacity: 0.6;
}

/* Section Configuration */
.players-setup {
    background: var(--light-bg);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 0;
    flex-shrink: 0;
}

.players-setup h2 {
    color: var(--primary-color);
    margin-bottom: 12px;
    font-size: 1rem;
}

.input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.player-add-form {
    flex-direction: column;
    align-items: stretch;
}

.player-add-form > input,
.player-add-form > .dept-field-wrap,
.player-add-form > button {
    width: 100%;
}

.dept-field-wrap input {
    width: 100%;
}

.dept-mode-check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.88rem;
    color: #a6adc8;
    margin-bottom: 14px;
    cursor: pointer;
    user-select: none;
}

.dept-mode-check input {
    width: auto;
    margin: 3px 0 0;
    accent-color: #d4af37;
}

.player-dept {
    display: block;
    font-size: 0.78rem;
    color: #5dade2;
    margin-top: 3px;
    font-weight: 500;
}

.ranking-item .player-dept,
.ticker-dept {
    font-size: 0.85em;
    color: #5dade2;
    margin-left: 0.35em;
}

.endgame-dept {
    display: block;
    font-size: 0.72rem;
    color: #5dade2;
    margin-top: 2px;
}

#playerName {
    flex: 1;
    min-width: 160px;
    padding: 10px 12px;
    border: 2px solid #3a3f5c;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.3s;
    background: #252840;
    color: #cdd6f4;
}

#playerName:focus {
    outline: none;
    border-color: var(--secondary-color);
}

.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.btn-primary {
    background: var(--secondary-color);
    color: white;
}

.btn-primary:hover {
    background: #c0392b;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #229954;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-warning:hover {
    background: #e67e22;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #a93226;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-large {
    width: 100%;
    padding: 15px;
    font-size: 1.1em;
    margin-top: 15px;
}

/* Liste des joueurs */
.players-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.player-card {
    background: #252840;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--secondary-color);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-card p {
    color: var(--primary-color);
    font-weight: 600;
}

.player-card button {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
}

.player-card button:hover {
    background: #922b21;
}

/* Section de Jeu */
.game-section {
    display: flex;
    flex-direction: row;
    gap: 12px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
    grid-column: 1;
    grid-row: 3;
    position: relative;
}

.game-container {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    order: 1;
}

.game-info-bar {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    background: var(--light-bg);
    padding: 8px 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.round-counter,
.joker-reminder {
    display: flex;
    gap: 8px;
    align-items: center;
    font-weight: 600;
    color: var(--primary-color);
}

.round-counter strong,
.joker-reminder strong {
    font-weight: 800;
}

.chrono-display {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.82rem;
    color: #a6adc8;
    font-weight: 600;
}

#chronoDisplay {
    font-family: 'Courier New', Courier, monospace;
    color: #cdd6f4;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.06em;
}

/* Joueur actuel */
.current-player {
    background: var(--light-bg);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.current-player h2 {
    color: var(--primary-color);
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.player-selector-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.player-selector-card {
    background: #252840;
    color: #cdd6f4;
    padding: 12px;
    border-radius: 10px;
    border: 2px solid #3a3f5c;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow);
    user-select: none;
    font-family: inherit;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
}

@media (hover: hover) {
    .player-selector-card:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-lg);
        border-color: var(--secondary-color);
    }
}

.player-selector-card.active {
    background: linear-gradient(135deg, var(--secondary-color), #c0392b);
    color: #ffffff;
    border-color: var(--secondary-color);
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.4);
}

.player-selector-card.active .player-name,
.player-selector-card.active .player-score {
    color: #ffffff;
}

.player-selector-card .player-name {
    font-weight: 700;
    font-size: 1em;
    margin-bottom: 8px;
    color: inherit;
}

.player-selector-card .player-score {
    font-size: 1.4em;
    font-weight: 700;
    color: inherit;
}

.player-selector-card.active .player-score {
    color: #ffd700;
}

.player-info {
    background: #252840;
    padding: 12px;
    border-radius: 8px;
    margin-top: 8px;
    text-align: center;
}

.player-info p {
    color: var(--primary-color);
    font-size: 1.15em;
    font-weight: 700;
}

#playerPoints {
    color: var(--secondary-color);
    font-size: 1.5em;
}

/* Cartes */
.cards-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.cards-section h2 {
    color: var(--primary-color);
    margin-bottom: 8px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    grid-auto-flow: row dense;
    gap: 12px;
    margin-bottom: 0;
    flex: 1;
    overflow: auto;
    padding-right: 3px;
    overscroll-behavior: contain;
}

.card {
    background: #f0f0f0;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border: 2px solid #e0e0e0;
    user-select: none;
    aspect-ratio: 70 / 100;
    position: relative;
    padding: 8px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    /* reset bouton */
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
    text-align: center;
}

@media (hover: hover) {
    .card:hover {
        transform: translateY(-10px);
        box-shadow: 0 18px 40px rgba(0,0,0,0.18);
        border-color: #dcdcdc;
    }
}

.card:active {
    transform: translateY(-6px);
}

.card-corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-weight: 800;
}

.card-corner-top {
    top: 12px;
    left: 12px;
    align-items: flex-start;
}

.card-corner-bottom {
    bottom: 16px;
    right: 16px;
    align-items: flex-end;
    transform: rotate(180deg);
}

.card-rank {
    font-size: 1.3rem;
    line-height: 1;
}

.card-suit {
    font-size: 1.1rem;
    line-height: 1;
}

.card-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 6px;
    padding: 4px;
    margin-top: 28px;
    flex: 1;
}

.card-symbol {
    font-size: 3.8rem;
    line-height: 1;
}

.card-label {
    font-weight: 700;
    letter-spacing: 0.05em;
    font-size: 0.95rem;
    color: #333;
    text-transform: uppercase;
}

.card-points {
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    color: #2c3e50;
    text-align: center;
    padding-bottom: 6px;
    flex-shrink: 0;
}

.red-card .card-rank,
.red-card .card-suit,
.red-card .card-symbol {
    color: #c0392b;
}

.black-card .card-rank,
.black-card .card-suit,
.black-card .card-symbol {
    color: #2c3e50;
}

.card.joker {
    background: linear-gradient(135deg, #f4e242, #f19b11);
    color: #2b1b03;
}

.card.joker .card-rank,
.card.joker .card-suit,
.card.joker .card-label {
    color: #2b1b03;
}

.card.clicked {
    animation: pulse 0.5s;
    border-color: var(--success-color);
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Classement */
.ranking-section {
    background: var(--light-bg);
    padding: 12px;
    border-radius: 8px;
    width: 220px;
    min-width: 220px;
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    order: 2;
}

.ranking-section .joker-reminder {
    background: linear-gradient(135deg, #252840, #2f3358);
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
}

.joker-reminder-label {
    font-size: 0.8rem;
    color: #a6adc8;
    font-weight: 600;
    line-height: 1.3;
}

/* Mini carte joker du tour */
.mini-card {
    background: #f4f4f4;
    border-radius: 8px;
    border: 2px solid #ddd;
    width: 75px;
    height: 105px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 12px rgba(0,0,0,0.5);
    flex-shrink: 0;
    padding: 5px;
}

.mini-card-corner {
    position: absolute;
    top: 6px;
    left: 7px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.1;
}

.mini-card-rank {
    font-size: 1.1rem;
    font-weight: 900;
}

.mini-card-suit {
    font-size: 0.85rem;
}

.mini-card-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    margin-top: 14px;
}

.mini-card-symbol {
    font-size: 2.4rem;
    line-height: 1;
}

.mini-card-face-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #333;
    letter-spacing: 0.03em;
}

.mini-card.red-card .mini-card-rank,
.mini-card.red-card .mini-card-suit,
.mini-card.red-card .mini-card-symbol {
    color: #c0392b;
}

.mini-card.black-card .mini-card-rank,
.mini-card.black-card .mini-card-suit,
.mini-card.black-card .mini-card-symbol {
    color: #2c3e50;
}

.ranking-section h2 {
    color: var(--primary-color);
    margin-bottom: 8px;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ranking-item {
    background: #252840;
    padding: 15px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.ranking-item.first {
    border-left: 5px solid gold;
    background: linear-gradient(to right, rgba(212, 175, 55, 0.15), #252840);
}

.ranking-item.second {
    border-left: 5px solid silver;
}

.ranking-item.third {
    border-left: 5px solid #cd7f32;
}

.ranking-item .rank {
    font-weight: 700;
    color: var(--secondary-color);
    font-size: 1.2em;
    min-width: 30px;
}

.ranking-item .name {
    flex: 1;
    margin-left: 15px;
    color: var(--primary-color);
    font-weight: 600;
}

.ranking-item .score {
    font-weight: 700;
    color: var(--success-color);
    font-size: 1.2em;
}

.ranking-section .btn-danger {
    flex-shrink: 0;
    margin-top: auto;
}

/* Responsive */
@media (max-width: 1024px) {
    .container {
        padding: 8px;
    }

    /* Sur iPad/tablet: Layout vertical */
    .game-section {
        flex-direction: column;
        gap: 8px;
    }

    .ranking-section {
        width: 100%;
        height: auto;
        max-height: 25vh;
        overflow-y: auto;
        margin-top: 8px;
        padding: 10px;
    }

    .cards-container {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
        gap: 8px;
        max-height: 35vh;
    }

    .card {
        min-height: 100px;
        padding: 6px;
    }

    .card-symbol {
        font-size: 2.5rem;
    }

    .card-label {
        font-size: 0.75rem;
    }

    .card-points {
        font-size: 0.9rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 1.6em;
        margin-bottom: 8px;
    }

    .players-setup {
        padding: 18px;
        margin-bottom: 25px;
    }

    .players-setup h2 {
        font-size: 1rem;
        margin-bottom: 12px;
    }

    .input-group {
        flex-direction: column;
        gap: 6px;
        margin-bottom: 12px;
    }

    #playerName {
        min-width: 120px;
        padding: 8px 10px;
        font-size: 0.9rem;
    }

    .btn {
        padding: 8px 16px;
        font-size: 0.85rem;
    }

    .players-list {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
        margin-bottom: 12px;
    }

    .player-card {
        padding: 10px;
    }

    .game-section {
        flex-direction: column;
        gap: 15px;
    }

    .ranking-section {
        width: 100%;
        height: auto;
        max-height: 35vh;
        margin-top: 0;
        padding: 12px;
    }

    .ranking-section h2 {
        font-size: 0.95rem;
        margin-bottom: 10px;
    }

    .cards-container {
        grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
        gap: 12px;
        margin-bottom: 0;
    }

    .card {
        min-height: 130px;
        padding: 10px;
        gap: 4px;
    }

    .card-symbol {
        font-size: 2.5rem;
    }

    .card-label {
        font-size: 0.8rem;
    }

    .card-points {
        font-size: 1rem;
        margin-bottom: 6px;
    }

    .action-buttons {
        gap: 6px;
        margin-top: 6px;
    }

    .current-player {
        padding: 10px;
        margin-bottom: 12px;
    }

    .current-player h2 {
        font-size: 0.9rem;
        margin-bottom: 8px;
    }

    .player-selector-cards {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 8px;
        margin-bottom: 8px;
    }

    .player-selector-card {
        padding: 8px;
    }

    .player-selector-card .player-name {
        font-size: 0.9em;
        margin-bottom: 6px;
    }

    .player-selector-card .player-score {
        font-size: 1.2em;
    }

    .player-info {
        padding: 8px;
        margin-top: 6px;
    }

    .player-info p {
        font-size: 1rem;
    }

    .ranking-list {
        gap: 8px;
        margin-bottom: 12px;
    }

    .ranking-item {
        padding: 10px;
    }

    .ranking-item .rank {
        font-size: 1.1em;
    }

    .ranking-item .name {
        font-size: 0.9rem;
        margin-left: 10px;
    }

    .ranking-item .score {
        font-size: 1.1em;
    }

    .game-info-bar {
        padding: 8px 10px;
        margin-bottom: 12px;
        font-size: 0.85rem;
    }

    .round-counter,
    .joker-reminder {
        gap: 6px;
    }

    #playerName {
        min-width: auto;
    }

    .player-selector-cards {
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    }
}

.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-shrink: 0;
}

.btn-info {
    background: #2980b9;
    color: white;
}

.btn-info:hover {
    background: #1f618d;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-next-turn {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 220px;
    height: 160px;
    font-size: 1.5rem;
    font-weight: 700;
    background: #1a6fb0;
    border: 2px solid #5dade2;
    border-radius: 12px;
    margin: 0;
    z-index: 2;
}

.game-player-input {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border: 2px solid #3a3f5c;
    border-radius: 8px;
    font-size: 0.85rem;
    background: #252840;
    color: #cdd6f4;
}

.game-player-input:focus {
    outline: none;
    border-color: var(--secondary-color);
}

.game-manage-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e2030;
    border-radius: 6px;
    padding: 6px 8px;
    margin-bottom: 5px;
    color: #cdd6f4;
    font-size: 0.85rem;
}

.game-manage-item small {
    color: #a6adc8;
}

/* Feedback : sélection joueur requise */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-8px); }
    40%       { transform: translateX(8px); }
    60%       { transform: translateX(-5px); }
    80%       { transform: translateX(5px); }
}

.current-player.needs-selection {
    animation: shake 0.5s ease-in-out;
    border: 2px solid var(--secondary-color) !important;
    box-shadow: 0 0 14px rgba(231, 76, 60, 0.6);
}

/* Carte saisie directe */
.direct-entry-card {
    background: linear-gradient(135deg, #252840, #1e2030) !important;
    border: 2px dashed #4a5080 !important;
    color: #a6adc8;
}

.direct-entry-card:hover {
    border-color: var(--secondary-color) !important;
    color: var(--secondary-color);
}

.direct-entry-card .card-symbol {
    color: inherit;
}

.direct-entry-card .card-label {
    color: inherit;
}

/* Modal saisie directe */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    backdrop-filter: blur(3px);
}

.modal-box {
    background: linear-gradient(160deg, #1a1c2e 0%, #252840 100%);
    border-radius: 20px;
    width: 300px;
    max-width: 94vw;
    box-shadow: 0 24px 64px rgba(0,0,0,0.85), 0 0 0 1px rgba(212,175,55,0.25);
    border: 1px solid rgba(212,175,55,0.3);
    overflow: hidden;
}

/* En-tête joueur */
.modal-header {
    background: linear-gradient(135deg, #252840, #2f3358);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(212,175,55,0.15);
    position: relative;
}

.modal-player-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--secondary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 900;
    color: white;
    flex-shrink: 0;
    text-transform: uppercase;
    box-shadow: 0 3px 10px rgba(0,0,0,0.5);
}

.modal-player-info {
    flex: 1;
    min-width: 0;
}

.modal-player-name {
    color: #d4af37;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-player-sub {
    color: #a6adc8;
    font-size: 0.75rem;
    margin-top: 2px;
}

.modal-player-sub span {
    color: #cdd6f4;
    font-weight: 700;
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    color: #4a5080;
    font-size: 1rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.2s;
    line-height: 1;
}

.modal-close-btn:hover { color: #cdd6f4; }

/* Zone saisie */
.modal-score-area {
    padding: 14px 16px 6px;
}

.modal-score-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #0d0f1a;
    border-radius: 12px;
    padding: 10px 14px;
    border: 1px solid rgba(212,175,55,0.2);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-score-row:focus-within {
    border-color: rgba(212,175,55,0.6);
    box-shadow: 0 0 0 3px rgba(212,175,55,0.08);
}

.modal-plus {
    color: #d4af37;
    font-size: 2rem;
    font-weight: 900;
    line-height: 1;
    user-select: none;
}

.modal-input {
    flex: 1;
    min-width: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 2.6rem;
    font-weight: 800;
    color: #f4e09b;
}

/* Div affichage sans clavier iOS */
.modal-display {
    background: transparent;
    border: none;
    outline: none;
    user-select: none;
    cursor: default;
    line-height: 1;
    padding: 4px 0;
    display: flex;
    align-items: center;
}

/* Placeholder quand vide */
.modal-display:empty::before {
    content: '0';
    color: #252840;
}

/* Curseur clignotant */
.modal-display::after {
    content: '▌';
    color: #d4af37;
    font-size: 0.65em;
    margin-left: 2px;
    animation: blink-cursor 1s step-start infinite;
}

@keyframes blink-cursor {
    50% { opacity: 0; }
}

.modal-preview {
    color: #6b7280;
    font-size: 0.8rem;
    text-align: right;
    margin-top: 7px;
    padding-right: 2px;
}

.modal-preview span {
    color: #2ecc71;
    font-weight: 800;
    font-size: 0.92rem;
}

/* Pavé numérique style jetons */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px 16px;
}

.numpad button {
    background: radial-gradient(circle at 35% 35%, #2f3358, #1e2030);
    color: #cdd6f4;
    border: 1px solid #3a3f5c;
    border-radius: 50%;
    aspect-ratio: 1;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 3px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);
}

.numpad button:hover {
    background: radial-gradient(circle at 35% 35%, #3a3f5c, #2a2f50);
    border-color: #d4af37;
    color: #d4af37;
    box-shadow: 0 4px 12px rgba(212,175,55,0.25);
}

.numpad button:active {
    transform: scale(0.88);
    background: radial-gradient(circle at 35% 35%, #d4af37, #b8941f);
    color: #1a1c2e;
    border-color: #d4af37;
    box-shadow: none;
}

.numpad-clear {
    color: #f39c12 !important;
    border-color: rgba(243,156,18,0.4) !important;
}

.numpad-back {
    color: #e74c3c !important;
    border-color: rgba(231,76,60,0.4) !important;
}

/* Boutons action */
.modal-actions {
    display: flex;
    gap: 10px;
    padding: 8px 16px 16px;
}

.modal-actions .btn {
    flex: 1;
    padding: 12px;
    font-size: 0.9rem;
    border-radius: 10px;
}

.btn-gold {
    background: linear-gradient(135deg, #d4af37, #b8941f);
    color: #1a1c2e;
    font-weight: 800;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-gold:hover {
    background: linear-gradient(135deg, #e4c040, #c9a227);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(212,175,55,0.4);
}

/* ── Bouton classement mobile (caché sur desktop/iPad) ── */
.btn-ranking-toggle {
    display: none;
}

/* ── Layout dédié iPhone (≤ 480px) ── */
@media (max-width: 480px) {

    /* La game-section devient le scroll container vertical */
    .game-section {
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
        align-items: stretch;
        gap: 8px;
    }

    /* game-container s'étend à sa hauteur naturelle */
    .game-container {
        flex: none;
        overflow: visible;
    }

    /* Barre infos compacte */
    .game-info-bar {
        padding: 6px 8px;
        font-size: 0.78rem;
        margin-bottom: 6px;
    }

    /* Sélecteur joueur compact */
    .current-player {
        padding: 8px;
        margin-bottom: 6px;
    }

    .current-player h2 {
        font-size: 0.82rem;
        margin-bottom: 6px;
    }

    .player-selector-cards {
        grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
        gap: 5px;
        margin-bottom: 6px;
    }

    .player-selector-card {
        padding: 7px 4px;
        min-height: 44px;
    }

    .player-selector-card .player-name {
        font-size: 0.8em;
        margin-bottom: 3px;
    }

    .player-selector-card .player-score {
        font-size: 1em;
    }

    /* Cartes : section non contrainte, défile avec la page */
    .cards-section {
        flex: none;
        min-height: auto;
        overflow: visible;
    }

    .cards-section h2 {
        font-size: 0.78rem;
        margin-bottom: 6px;
    }

    .cards-container {
        grid-template-columns: repeat(5, 1fr);
        grid-auto-flow: row dense;
        gap: 4px;
        overflow: visible;
        max-height: none;
        flex: none;
    }

    .card {
        min-height: 76px;
        padding: 4px;
    }

    .card-rank {
        font-size: 0.75rem;
    }

    .card-suit {
        font-size: 0.65rem;
    }

    .card-corner-top {
        top: 6px;
        left: 6px;
    }

    .card-corner-bottom {
        bottom: 8px;
        right: 8px;
    }

    .card-symbol {
        font-size: 1.5rem;
    }

    .card-label {
        display: none;
    }

    .card-points {
        font-size: 0.7rem;
        padding-bottom: 2px;
    }

    /* Boutons action : 2 colonnes */
    .action-buttons {
        flex-wrap: wrap;
        gap: 5px;
        margin-top: 8px;
    }

    .action-buttons .btn {
        flex: 1 1 calc(50% - 5px);
        font-size: 0.78rem;
        padding: 9px 4px;
        min-height: 44px;
    }

    /* Bouton classement visible sur iPhone */
    .btn-ranking-toggle {
        display: block;
        flex: 1 1 100%;
        min-height: 44px;
    }

    /* Tour suivant : redevient statique sous les cartes sur mobile */
    .btn-next-turn {
        position: static;
        width: 100%;
        height: auto;
        font-size: 1rem;
        padding: 14px 10px;
        min-height: 54px;
        border-radius: 8px;
        margin-top: 6px;
    }

    /* Classement masqué par défaut, affiché au tap */
    .ranking-section {
        display: none;
        width: 100%;
        min-width: 0;
        max-height: none;
        margin-top: 0;
    }

    .ranking-section.mobile-open {
        display: flex;
        flex-direction: column;
    }

    .ranking-section h2 {
        font-size: 0.85rem;
    }

    .ranking-item {
        padding: 10px;
    }
}

/* === Modal fin de partie === */
.endgame-box {
    width: 360px;
    max-width: 94vw;
    padding: 0;
}

.endgame-title {
    background: linear-gradient(135deg, #252840, #2f3358);
    text-align: center;
    font-size: 1.45rem;
    font-weight: 900;
    color: #d4af37;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(212,175,55,0.2);
    letter-spacing: 0.04em;
}

.endgame-time {
    text-align: center;
    color: #5dade2;
    font-size: 0.95rem;
    font-weight: 700;
    padding: 14px 20px 4px;
    letter-spacing: 0.04em;
}

.endgame-winner-block {
    text-align: center;
    padding: 10px 20px 12px;
    border-bottom: 1px solid rgba(212,175,55,0.15);
}

.endgame-winner-name {
    font-size: 1.65rem;
    font-weight: 900;
    color: #d4af37;
    letter-spacing: 0.03em;
}

.endgame-winner-pts {
    font-size: 0.9rem;
    color: #a6adc8;
    margin-top: 2px;
}

.endgame-ranking {
    padding: 10px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
}

.endgame-rank-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #1e2030;
}

.endgame-rank-row.is-first {
    background: rgba(212,175,55,0.10);
    border: 1px solid rgba(212,175,55,0.22);
}

.endgame-pos {
    font-size: 1.15rem;
    min-width: 30px;
    text-align: center;
}

.endgame-name {
    flex: 1;
    font-weight: 700;
    color: #cdd6f4;
    font-size: 0.98rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.endgame-rank-row.is-first .endgame-name {
    color: #d4af37;
}

.endgame-pts {
    font-weight: 700;
    color: #2ecc71;
    font-size: 0.92rem;
    white-space: nowrap;
}

.endgame-rank-row.is-first .endgame-pts {
    color: #d4af37;
}

.endgame-actions {
    display: flex;
    gap: 8px;
    padding: 12px 14px 16px;
}

.endgame-actions .btn {
    flex: 1;
    padding: 11px 4px;
    font-size: 0.78rem;
    border-radius: 10px;
}

/* === Aperçu image score === */
.score-image-box {
    background: linear-gradient(160deg, #1a1c2e 0%, #252840 100%);
    border-radius: 20px;
    width: 340px;
    max-width: 94vw;
    padding: 0 0 16px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.85), 0 0 0 1px rgba(212,175,55,0.25);
    border: 1px solid rgba(212,175,55,0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

.score-image-title {
    width: 100%;
    text-align: center;
    font-size: 1rem;
    font-weight: 800;
    color: #d4af37;
    background: linear-gradient(135deg, #252840, #2f3358);
    padding: 14px 20px;
    border-bottom: 1px solid rgba(212,175,55,0.2);
    letter-spacing: 0.05em;
}

.score-preview-img {
    width: 90%;
    margin: 14px 0 4px;
    border-radius: 8px;
    border: 1px solid rgba(212,175,55,0.2);
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
    display: block;
}

.score-save-hint {
    color: #6b7280;
    font-size: 0.72rem;
    text-align: center;
    padding: 0 20px;
    margin-bottom: 2px;
    line-height: 1.4;
}

.score-image-actions {
    display: flex;
    gap: 10px;
    width: 90%;
    margin-top: 8px;
}

.score-image-actions .btn {
    flex: 1;
    padding: 11px 6px;
    font-size: 0.82rem;
    border-radius: 10px;
}

.score-image-game-actions {
    display: flex;
    gap: 10px;
    width: 90%;
    margin-top: 8px;
    padding-bottom: 4px;
}

.score-image-game-actions .btn {
    flex: 1;
    padding: 11px 6px;
    font-size: 0.82rem;
    border-radius: 10px;
}

/* === Tirage au sort === */
.draw-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    backdrop-filter: blur(4px);
}

.draw-box {
    background: linear-gradient(160deg, #1a1c2e 0%, #252840 100%);
    border-radius: 24px;
    padding: 40px 48px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0,0,0,0.85), 0 0 0 1px rgba(212,175,55,0.3);
    border: 1px solid rgba(212,175,55,0.4);
    max-width: 90vw;
    min-width: 280px;
}

.draw-title {
    font-size: 1.8rem;
    font-weight: 900;
    color: #d4af37;
    margin-bottom: 6px;
}

.draw-subtitle {
    font-size: 0.8rem;
    color: #a6adc8;
    margin-bottom: 24px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.draw-player-name {
    font-size: 2.6rem;
    font-weight: 900;
    color: #cdd6f4;
    min-height: 3.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    min-width: 200px;
    transition: color 0.15s;
}

.draw-player-name.draw-winner {
    color: #d4af37;
    text-shadow: 0 0 30px rgba(212,175,55,0.5);
    animation: drawWin 0.5s ease;
}

@keyframes drawWin {
    0%   { transform: scale(0.75); opacity: 0.4; }
    65%  { transform: scale(1.12); }
    100% { transform: scale(1);    opacity: 1; }
}

.draw-close-btn {
    margin-top: 28px !important;
    padding: 14px 36px !important;
    font-size: 1rem !important;
    border-radius: 12px !important;
    width: 100%;
}

.brand-credit {
    position: fixed;
    bottom: 10px;
    right: 14px;
    font-size: 0.7rem;
    color: rgba(212, 175, 55, 0.55);
    font-style: italic;
    letter-spacing: 0.03em;
    pointer-events: none;
    z-index: 100;
    user-select: none;
}

/* Bouton Solo */
.btn-solo {
    background: linear-gradient(135deg, #6c3f9e, #9b59b6);
    color: white;
    margin-top: 8px !important;
}

.btn-solo:hover {
    background: linear-gradient(135deg, #5a3286, #8e44ad);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* Bouton Règles */
.btn-rules {
    background: rgba(212, 175, 55, 0.15);
    color: #d4af37;
    border: 1px solid rgba(212, 175, 55, 0.35);
}

.btn-rules:hover {
    background: rgba(212, 175, 55, 0.25);
    transform: translateY(-2px);
}

/* Modal règles */
.rules-box {
    max-width: 440px;
    width: 95%;
    max-height: 88vh;
    overflow-y: auto;
}

.rules-content {
    padding: 10px 2px 4px;
    color: #cdd6f4;
    font-size: 0.9rem;
    line-height: 1.6;
}

.rules-section {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}

.rules-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.rules-section-title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #d4af37;
    margin-bottom: 8px;
}

.rules-section p {
    color: #a6adc8;
    margin: 0;
}

.rules-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.rules-section ul li {
    color: #a6adc8;
    padding-left: 14px;
    position: relative;
}

.rules-section ul li::before {
    content: '›';
    position: absolute;
    left: 0;
    color: #d4af37;
    font-weight: 700;
}

.rules-cards-grid {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.rules-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    background: rgba(255,255,255,0.04);
    border-radius: 6px;
    font-size: 0.88rem;
}

.rules-card-name {
    color: #cdd6f4;
}

.rules-card-pts {
    color: #2ecc71;
    font-weight: 700;
}

.rules-card-wild {
    background: rgba(212,175,55,0.08);
    border: 1px solid rgba(212,175,55,0.2);
}

.rules-card-wild .rules-card-name {
    color: #d4af37;
}

.rules-card-wild .rules-card-pts {
    color: #e74c3c;
}

/* Badge mode solo */
.game-info-bar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.solo-mode-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: linear-gradient(135deg, rgba(108, 63, 158, 0.9), rgba(155, 89, 182, 0.85));
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 8px rgba(108, 63, 158, 0.45);
}

/* Joker du tour — bandeau mobile (zone de jeu) */
.joker-strip-mobile {
    display: none;
}

.joker-pts-hint {
    color: #e74c3c;
    font-weight: 800;
    font-size: 0.78rem;
}

.ranking-section .joker-reminder {
    box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.25), 0 4px 16px rgba(0, 0, 0, 0.35);
}

.ranking-section .joker-reminder .joker-reminder-label {
    color: #d4af37;
    font-size: 0.85rem;
}

/* Toasts */
.toast-container {
    position: fixed;
    left: 50%;
    bottom: max(16px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 10050;
    width: min(92vw, 360px);
    pointer-events: none;
}

.toast {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.35;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast-visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-info {
    background: rgba(41, 128, 185, 0.95);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.toast-error {
    background: rgba(192, 57, 43, 0.95);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.toast-success {
    background: rgba(39, 174, 96, 0.95);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

@media (max-width: 768px) {
    .joker-strip-mobile {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 10px;
        padding: 10px 12px;
        border-radius: 10px;
        background: linear-gradient(135deg, rgba(212, 175, 55, 0.22), rgba(41, 128, 185, 0.12));
        border: 2px solid rgba(212, 175, 55, 0.55);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
        flex-shrink: 0;
    }

    .joker-strip-mobile .joker-reminder-label {
        font-size: 0.95rem;
        color: #d4af37;
        font-weight: 700;
        line-height: 1.25;
        flex: 1;
        min-width: 0;
    }

    .joker-strip-mobile .mini-card {
        width: 58px;
        height: 82px;
        border-width: 2px;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    }

    .joker-strip-mobile .mini-card-symbol {
        font-size: 2rem;
    }

    .ranking-section .joker-reminder {
        display: none;
    }
}
