/* ============================================================
   Variables & Reset
   ============================================================ */
:root {
    --bg:           #2b2b2b;
    --bg-dark:      #1e1e1e;
    --surface:      #383838;
    --surface-2:    #444444;
    --text:         #ffffff;
    --text-muted:   #999999;
    --blue:         #5b82d4;
    --blue-hover:   #4a71c3;
    --red:          #e04444;
    --gold:         #c9a520;
    --gold-dark:    #5a3d00;
    --radius:       18px;
    --card-radius:  14px;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* ============================================================
   Screens
   ============================================================ */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
    overflow: hidden;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 14px;
    padding: 14px 28px;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    width: 100%;
    max-width: 420px;
    letter-spacing: 0.3px;
}
.btn-primary:hover  { background: var(--blue-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-large { padding: 17px 32px; font-size: 1.05rem; }

.btn-icon {
    width: 36px;
    height: 36px;
    background: var(--surface);
    border: none;
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

.counter-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 2px solid var(--surface-2);
    background: var(--surface-2);
    color: var(--text);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
    font-family: 'Inter', sans-serif;
}
.counter-btn:hover { background: var(--blue); border-color: var(--blue); }

/* ============================================================
   Setup Screen
   ============================================================ */
#screen-setup { overflow-y: auto; }

.setup-container {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 24px;
    gap: 20px;
}

/* These spacers center content when space allows,
   and collapse to nothing when content overflows — allowing scroll to top */
.setup-container::before,
.setup-container::after {
    content: '';
    flex: 1;
    min-height: 12px;
}

.game-logo {
    width: clamp(120px, 40vw, 200px);
    height: auto;
    border-radius: 20px;
    display: block;
}

.game-tagline {
    color: var(--text-muted);
    font-size: 0.88rem;
    text-align: center;
    max-width: 300px;
    line-height: 1.5;
}

.setup-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 26px 22px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 26px;
}

.setup-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setup-label {
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
}

.counter-row {
    display: flex;
    align-items: center;
    gap: 18px;
}

.counter-value {
    font-size: 2.2rem;
    font-weight: 900;
    min-width: 48px;
    text-align: center;
    line-height: 1;
}

.player-names-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-name-input {
    background: var(--bg-dark);
    border: 2px solid var(--surface-2);
    border-radius: 10px;
    padding: 10px 14px;
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    width: 100%;
    transition: border-color 0.15s;
}
.player-name-input:focus { outline: none; border-color: var(--blue); }
.player-name-input::placeholder { color: var(--text-muted); font-weight: 400; }

/* ============================================================
   Toggle Switch
   ============================================================ */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 14px;
}
.toggle-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
    flex: 1;
}
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    flex-shrink: 0;
    cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--surface-2);
    border-radius: 28px;
    transition: background 0.2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.toggle-switch input:checked + .toggle-slider { background: var(--blue); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(22px); }

/* ============================================================
   Game Screen — two halves layout
   ============================================================ */

.cards-half {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    overflow: hidden;
    min-height: 0;
}
.cards-half.top { transform: rotate(180deg); }

/* Single-mode: hide top half */
#screen-game.single-mode .cards-half.top { display: none; }

.center-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: 8px 16px;
    position: relative;
}
.center-bar::before {
    content: '';
    position: absolute;
    left: 0; right: 0;
    top: 50%;
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    pointer-events: none;
}
.round-pill {
    background: var(--surface);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 20px;
    padding: 5px 16px;
    font-size: 0.82rem;
    color: var(--text-muted);
    position: relative;
    z-index: 1;
    white-space: nowrap;
}
.round-pill strong { color: var(--text); font-weight: 800; }

.btn-round {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    transition: all 0.15s;
    position: relative;
    z-index: 2;
}
.btn-round-ghost {
    background: var(--surface);
    color: var(--text-muted);
    font-size: 1rem;
}
.btn-round-ghost:hover { background: rgba(224, 68, 68, 0.35); color: white; }
.btn-round-primary {
    background: var(--blue);
    color: white;
    box-shadow: 0 4px 20px rgba(91, 130, 212, 0.4);
}
.btn-round-primary:hover { background: var(--blue-hover); transform: translateY(-1px); }
.btn-round-primary:active { transform: translateY(0); }

/* ============================================================
   Cards Area
   ============================================================ */
.cards-area {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
    align-content: center;
    max-width: 100%;
}

/* ============================================================
   Card
   ============================================================ */
.card {
    --w: var(--card-size, 90px);
    width: var(--w);
    height: calc(var(--w) * 1.44);
    perspective: 900px;
    flex-shrink: 0;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}
.card.revealed .card-inner { transform: rotateY(180deg); }

/* Back & Front share absolute positioning */
.card-back,
.card-face {
    position: absolute;
    inset: 0;
    border-radius: var(--card-radius);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* --- Card Back --- */
.card-back {
    background: #c0c0c0;
    border: 3px solid rgba(255,255,255,0.5);
    overflow: hidden;
}
.card-back::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 9px,
        rgba(255,255,255,0.3) 9px,
        rgba(255,255,255,0.3) 18px
    );
}
.card-back-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    opacity: 1;
    pointer-events: none;
}

/* --- Card Front --- */
.card-face {
    transform: rotateY(180deg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid rgba(255, 255, 255, 0.88);
}

/* Inner decorative frame */
.card-face::after {
    content: '';
    position: absolute;
    inset: 5px;
    border: 1.5px solid rgba(255, 255, 255, 0.28);
    border-radius: calc(var(--card-radius) - 5px);
    pointer-events: none;
}

.card-face.card-blue { background: var(--blue); }
.card-face.card-red  { background: var(--red); }
.card-face.card-gold { background: var(--gold); }

/* --- Letter --- */
.card-letter {
    font-family: 'Alfa Slab One', serif;
    font-size: calc(var(--card-size, 90px) * 0.52);
    color: white;
    text-shadow: 0 3px 10px rgba(0,0,0,0.22);
    line-height: 1;
    user-select: none;
    position: relative;
    z-index: 1;
}

/* --- Inversion Card --- */
.card-face.card-inversion {
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}
.card-face.card-inversion::after { display: none; }

.inversion-half {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.inversion-top    { background: var(--blue); border-bottom: 2px solid rgba(255,255,255,0.5); }
.inversion-bottom { background: var(--red);  border-top:    2px solid rgba(255,255,255,0.5); }

.inversion-half svg {
    width: calc(var(--card-size, 90px) * 0.42);
    height: calc(var(--card-size, 90px) * 0.42);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

/* --- Special Card --- */
.card-special-content {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.card-special-corner {
    position: absolute;
    font-family: 'Cinzel', serif;
    font-size: clamp(0.42rem, 1.1vw, 0.58rem);
    font-weight: 900;
    color: rgba(255,255,255,0.9);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    line-height: 1.3;
    text-align: center;
    z-index: 2;
}
.card-special-corner.top-right {
    top: 10px;
    right: 9px;
}
.card-special-corner.bottom-left {
    bottom: 10px;
    left: 9px;
    transform: rotate(180deg);
}

.card-special-band {
    position: absolute;
    width: 260%;
    left: -80%;
    padding: clamp(8px, 2vw, 14px) 0;
    background: var(--gold-dark);
    transform: rotate(-28deg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.card-special-band-text {
    font-family: 'Cinzel', serif;
    font-size: calc(var(--card-size, 90px) * 0.15);
    font-weight: 900;
    color: white;
    letter-spacing: 2px;
    text-transform: uppercase;
    white-space: nowrap;
    line-height: 1.2;
}
.card-special-band-text.inv { transform: rotate(180deg); }

/* ============================================================
   Scoring Screen
   ============================================================ */
.scoring-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 22px 24px;
    overflow-y: auto;
}
.scoring-container::before,
.scoring-container::after {
    content: '';
    flex: 1;
    min-height: 12px;
}

.scoring-title {
    font-size: 1.3rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 6px;
}

.scoring-subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 18px;
    max-width: 320px;
    line-height: 1.5;
}

.players-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
    width: 100%;
    max-width: 420px;
    margin-bottom: 16px;
}

.player-score-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 16px;
    background: var(--surface-2);
    border: 2px solid transparent;
    border-radius: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
    text-align: left;
}
.player-score-btn:hover { background: #505050; }
.player-score-btn.selected {
    background: rgba(224, 68, 68, 0.14);
    border-color: var(--red);
}

.player-btn-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.player-btn-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.current-score {
    font-size: 1.3rem;
    font-weight: 800;
}

.penalty-badge {
    background: var(--red);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 20px;
    padding: 2px 8px;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s, transform 0.2s;
}
.player-score-btn.selected .penalty-badge {
    opacity: 1;
    transform: scale(1);
}

.scoring-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    width: 100%;
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text-muted);
    border: none;
    border-radius: 14px;
    padding: 14px 28px;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
    flex: 1;
    max-width: 200px;
}
.btn-secondary:hover { background: #555; color: var(--text); }

.scoring-actions .btn-primary {
    flex: 1;
    max-width: 200px;
}

/* ============================================================
   Results Screen
   ============================================================ */
.results-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    gap: 20px;
    overflow-y: auto;
}

.results-trophy { font-size: 4rem; line-height: 1; }

.results-title {
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    font-weight: 900;
    text-align: center;
}

.final-podium {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.podium-entry {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 16px;
    background: var(--surface);
    border-radius: 13px;
    border: 2px solid transparent;
    transition: border-color 0.3s;
}
.podium-entry.winner {
    background: rgba(91, 130, 212, 0.12);
    border-color: var(--blue);
}

.podium-rank {
    font-size: 1.4rem;
    min-width: 34px;
    text-align: center;
    flex-shrink: 0;
}

.podium-name {
    flex: 1;
    font-size: 1rem;
    font-weight: 700;
}

.podium-score {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-muted);
}
.winner .podium-score { color: var(--blue); }

.winner-label {
    font-size: 0.65rem;
    font-weight: 800;
    background: var(--blue);
    color: white;
    border-radius: 20px;
    padding: 3px 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.hidden { display: none !important; }

/* ============================================================
   Generic Modal
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
    transition: opacity 0.25s ease;
}
.modal-overlay.hidden { opacity: 0; pointer-events: none; }

.modal-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px 28px 28px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
    text-align: center;
}

.modal-icon { font-size: 2.4rem; line-height: 1; margin-bottom: 4px; }

.modal-title {
    font-size: 1.2rem;
    font-weight: 800;
}

.modal-desc {
    font-size: 0.86rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 8px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-top: 4px;
}
.modal-actions .btn-secondary,
.modal-actions .btn-danger { flex: 1; max-width: none; }

.btn-danger {
    background: var(--red);
    color: white;
    border: none;
    border-radius: 14px;
    padding: 14px 28px;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.btn-danger:hover  { background: #c93333; transform: translateY(-1px); }
.btn-danger:active { transform: translateY(0); }

/* ============================================================
   Rules Modal
   ============================================================ */
.rules-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: flex-end;
    z-index: 100;
    transition: opacity 0.3s ease;
}
.rules-overlay.hidden { opacity: 0; pointer-events: none; }

.rules-panel {
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.4);
}

.rules-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 22px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.rules-title {
    font-size: 1.2rem;
    font-weight: 800;
}

.rules-body {
    overflow-y: auto;
    padding: 20px 22px 32px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 0.92rem;
    line-height: 1.6;
    color: rgba(255,255,255,0.85);
}

.rules-body h3 {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-top: 6px;
}

.rules-body p { margin: 0; }

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

.rules-body li {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.rules-body strong { color: var(--text); }

.rule-tag {
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 20px;
    padding: 3px 10px;
    color: white;
    white-space: nowrap;
    flex-shrink: 0;
}
.tag-blue { background: var(--blue); }
.tag-red  { background: var(--red); }
.tag-gold { background: var(--gold); color: #1a1200; }
.tag-inv  { background: linear-gradient(to bottom, var(--blue) 50%, var(--red) 50%); }

/* Link style for rules trigger */
.regles-jeu {
    color: var(--text-muted);
    font-size: 0.82rem;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    transition: color 0.15s;
    text-align: center;
    padding-bottom: 50px;
}
.regles-jeu:hover { color: var(--text); }

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 4px; }
