/* Games shared UI — setup/mode/name-entry patterns used across multiple games
   (connect4, quoridor, battleship, snakes-ladders, artillery, ...).
   Keep game-specific rules (board, pieces, special widgets) in each game's file. */


/* -------- Mode selector cards (1 player / 2 players / difficulty / ...) --- */
.mode-cards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.mode-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    text-align: start;
}

.mode-card:hover {
    background: var(--bg-input);
    transform: translateX(-2px);
}
[dir="ltr"] .mode-card:hover {
    transform: translateX(2px);
}

.mode-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 0.75rem;
    background: var(--primary-accent);
    border: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mode-card-icon svg { width: 22px; height: 22px; }
.mode-card-icon:not([style]) svg { stroke: #202935; }

.mode-card-content { flex: 1; }
.mode-card-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.15rem; }
.mode-card-desc { font-size: 0.8rem; color: var(--text-secondary); }


/* -------- Player name entry (column of inputs with optional player dots) -- */
.name-inputs {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1rem;
    align-items: center;
}

.name-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.name-field input {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--card-border);
    border-radius: 0.5rem;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    width: 140px;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}
.name-field input:focus { border-color: var(--primary-accent); }
.name-field input::placeholder { color: var(--text-muted); }

.player-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--card-border);
    flex-shrink: 0;
}
.player-dot.p1, .player-dot.blue { background: #3b82f6; }
.player-dot.p2, .player-dot.red { background: #f43f5e; }


/* -------- Primary action button (Start Game, Back, etc.) ----------------- */
.action-btn {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    background: var(--primary-accent);
    color: #202935;
    border: 1px solid var(--card-border);
    border-radius: 0.6rem;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.action-btn:hover:not(:disabled) {
    filter: brightness(0.93);
}
.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.action-btn.secondary {
    background: var(--bg-card);
    color: var(--text-primary);
}


/* -------- Game-over button row (Play Again / Back to Menu) ---------------
   Tight padding keeps two buttons side-by-side inside the 320px box without
   wrapping to a second line. */
.game-over-btns { display: flex; flex-wrap: nowrap; gap: 0.5rem; }
.game-over-btns .action-btn {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    padding: 0.7rem 0.5rem;
    font-size: 0.95rem;
    white-space: nowrap;
}


/* -------- Floating mute / sound toggle button (bottom-right) ------------- */
.mute-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    transition: all 0.15s;
}
.mute-btn.show { display: flex; }
.mute-btn:hover { filter: brightness(0.95); }
.mute-btn.muted { opacity: 0.75; }
.mute-btn svg { width: 20px; height: 20px; stroke-width: 2.2; color: var(--border-color); }
.mute-btn svg.hidden { display: none; }


/* -------- Party-game setup rows / counters / toggles --------------------
   Used by pantomime, spyfall, tick-tick-boom — a vertical list of options
   (each a flex row with a label + control), a +/- counter, and an on/off toggle. */
.setup-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-light);
}
.setup-row:last-child { border-bottom: none; }

.setup-label { font-weight: 700; font-size: 0.95rem; }

.counter-controls { display: flex; align-items: center; gap: 0.5rem; }

.counter-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--card-border);
    border-radius: 0.5rem;
    background: var(--bg-input);
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    color: var(--text-primary);
    font-family: inherit;
}
.counter-btn:hover { background: var(--primary-accent); color: #202935; }
.counter-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.counter-btn:disabled:hover { background: var(--bg-input); color: var(--text-primary); }

.counter-value {
    font-size: 1.3rem;
    font-weight: 800;
    min-width: 2rem;
    text-align: center;
}

.toggle-btn {
    border: 1px solid var(--card-border);
    border-radius: 0.5rem;
    background: var(--bg-input);
    font-weight: 700;
    cursor: pointer;
    padding: 0 0.75rem;
    height: 36px;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text-primary);
    transition: all 0.15s;
}
.toggle-btn.active { background: var(--primary-accent); color: #202935; }


/* -------- Collapsible player-names panel --------------------------------
   A "▾ Player names (optional)" button that expands a 2-col grid of inputs. */
.names-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.75rem;
    justify-content: center;
    font-weight: 600;
    transition: color 0.15s;
}
.names-toggle:hover { color: var(--primary-accent); }
.names-toggle svg { width: 16px; height: 16px; transition: transform 0.2s; }
.names-toggle.open svg { transform: rotate(180deg); }

.names-grid {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.names-grid.open { display: grid; }

.name-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--card-border);
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--bg-input);
    color: var(--text-primary);
    text-align: center;
    outline: none;
    transition: border-color 0.15s;
}
.name-input:focus { border-color: var(--primary-accent); }


/* -------- Full-width "Start Game" button (party-game setup screens) ---- */
.btn-start {
    margin-top: 1.25rem;
    width: 100%;
    padding: 0.875rem;
    background: var(--primary-accent);
    color: #202935;
    border: 1px solid var(--card-border);
    border-radius: 0.75rem;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.btn-start:hover { filter: brightness(0.93); }


/* -------- Game container + UI reveal -------------------------------------
   Used by: connect4, quoridor, battleship, backgammon, snakes-ladders.
   Games override --game-max-width to control their board width. */
.game-container {
    max-width: var(--game-max-width, 700px);
    margin: 0 auto;
}

.game-ui { display: none; }
.game-ui.show { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}


/* -------- Game-over overlay + card ---------------------------------------
   Used by: connect4, quoridor, battleship, backgammon, snakes-ladders.
   Per-game title color variants (.won, .draw-title, .lost) stay in each game. */
.game-over-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}
.game-over-overlay.show { opacity: 1; visibility: visible; }

.game-over-box {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 1rem;
    text-align: center;
    border: 1px solid var(--card-border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    max-width: 320px;
    transform: scale(0.8) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.game-over-overlay.show .game-over-box { transform: scale(1) translateY(0); }

.game-over-title { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }
.game-over-subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }


/* -------- Lifetime stats widget (shown on setup screens before play) -----
   Used by: connect4, quoridor, battleship, backgammon, artillery. */
.lifetime-stats {
    display: none;
    justify-content: center;
    align-items: stretch;
    gap: 0;
    margin: 0 auto 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--card-border);
    border-radius: 0.75rem;
    padding: 0.75rem 0.5rem;
    width: fit-content;
    min-width: 240px;
}
.lifetime-stats.show { display: flex; }

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    flex: 1;
    position: relative;
}
.stat-box + .stat-box::before {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    top: 15%;
    height: 70%;
    width: 1px;
    background: var(--border-color);
}
.stat-value {
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.2;
    color: var(--primary-accent);
}
.stat-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

@media (max-width: 500px) {
    .stat-value { font-size: 1.15rem; }
}


/* -------- In-game controls (inline horizontal row below the game) -------
   Horizontal row of pill-style buttons (sound toggle, pause, menu/restart)
   shown below the game section on both mobile and desktop. Previously
   floated bottom-right on desktop, but clashed with .promo-card. */
.game-controls-floating {
    display: none;
    flex-direction: row;
    justify-content: center;
    gap: 0.5rem;
    margin: 0.75rem auto 0;
}
.game-controls-floating.show { display: flex; }

.game-controls-floating .ctrl-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    color: var(--text-primary);
    transition: all 0.15s;
    padding: 0;
}
.game-controls-floating .ctrl-btn:hover {
    filter: brightness(0.95);
}
.game-controls-floating .ctrl-btn.muted { opacity: 0.75; }
.game-controls-floating .ctrl-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.2;
    color: var(--border-color);
}
.game-controls-floating .ctrl-btn svg.hidden { display: none; }

@media (max-width: 640px) {
    .game-controls-floating .ctrl-btn {
        width: 40px;
        height: 40px;
    }
    .game-controls-floating .ctrl-btn svg { width: 18px; height: 18px; }
}


/* -------- Party-game scoreboard + timer + result screen ------------------
   Used by: spyfall, pantomime, tick-tick-boom. */
.scoreboard {
    margin-top: 1rem;
    background: var(--bg-input);
    border: 1px solid var(--card-border);
    border-radius: 0.75rem;
    overflow: hidden;
}
.scoreboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
}
.scoreboard-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border-light);
}
.scoreboard-row:last-child { border-bottom: none; }
.scoreboard-row.highlight { background: rgba(255, 193, 7, 0.1); }
.scoreboard-name { font-weight: 700; }
.scoreboard-pts {
    font-weight: 800;
    color: var(--primary-accent);
    min-width: 1.5rem;
    text-align: center;
}

.timer-display {
    font-size: 3rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    direction: ltr;
    display: inline-block;
}
.timer-display.warning {
    color: #ef4444;
    animation: timer-blink 1s ease-in-out infinite;
}
@keyframes timer-blink {
    50% { opacity: 0.5; }
}

.result-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.result-title { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }

@media (max-width: 480px) {
    .timer-display { font-size: 2.5rem; }
}


/* -------- Utility ---------------------------------------------------------- */
.hidden { display: none !important; }
