/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #1a0a00;
    --accent: #e8c060;
    --text: #f0e6d0;
    --text-dim: #a09080;
    --active-glow: #ffcc00;
}

html {
    height: 100%;
    background: var(--bg);
}

body {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* ===== GAME CONTAINER ===== */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 10px 8px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    gap: 6px;
    position: relative;
}

/* ===== SCOREBOARD ===== */
#scoreboard {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 500px;
    padding: 4px 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    flex-shrink: 0;
    gap: 4px;
    flex-wrap: wrap;
}

.player-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 3px 8px;
    border-radius: 8px;
    transition: all 0.3s ease;
    min-width: 55px;
}

.player-score.active {
    background: rgba(255, 204, 0, 0.15);
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.2);
}

.player-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    white-space: nowrap;
}

.player-score.active .player-label {
    color: var(--active-glow);
}

.score-pieces {
    display: flex;
    flex-direction: row;
    gap: 1px;
    height: 6px;
    align-items: center;
}

.score-piece {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    opacity: 0.2;
    display: inline-block;
}

.score-piece.pocketed {
    opacity: 1;
}

.score-piece.white { background: #f0f0f0; }
.score-piece.black { background: #333; border: 1px solid #666; }
.score-piece.queen { background: #cc2020; }

.score-value {
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
}

.score-divider {
    width: 1px;
    height: 28px;
    background: rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

/* ===== CANVAS ===== */
#carromCanvas {
    border-radius: 4px;
    touch-action: none;
    display: block;
}

/* ===== CONTROLS ===== */
#controls {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 6px;
    flex-shrink: 0;
    justify-content: center;
    align-items: center;
}

.controls-break {
    flex-basis: 100%;
    height: 0;
}

#controls button {
    padding: 6px 14px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 40px;
    -webkit-appearance: none;
    appearance: none;
}

#controls button:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.25);
}

#btn-variant {
    border: 1px solid rgba(255, 255, 255, 0.15);
}
#btn-variant.flow {
    background: rgba(232, 192, 96, 0.2);
    border-color: rgba(232, 192, 96, 0.4);
    color: var(--accent);
}

/* ===== OVERLAY ===== */
#overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

#overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#overlay-content {
    text-align: center;
    padding: 32px;
    background: rgba(40, 25, 10, 0.95);
    border-radius: 20px;
    border: 1px solid rgba(255, 204, 0, 0.3);
    max-width: 320px;
    width: 85%;
}

#overlay-title {
    font-size: 36px;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 12px;
}

#overlay-message {
    font-size: 15px;
    color: var(--text-dim);
    margin-bottom: 24px;
    line-height: 1.5;
}

#overlay-btn {
    padding: 14px 48px;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    background: linear-gradient(135deg, #e8c060, #c89830);
    color: #1a0a00;
    min-height: 48px;
    transition: transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}

#overlay-btn:active {
    transform: scale(0.95);
}

/* ===== RULES PANEL ===== */
#rules-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 2000;
    overflow-y: auto;
    touch-action: pan-y;
    padding: 20px 0;
}

#rules-panel.hidden {
    display: none;
}

#rules-content {
    position: relative;
    padding: 28px 24px;
    background: rgba(40, 25, 10, 0.97);
    border-radius: 16px;
    border: 1px solid rgba(255, 204, 0, 0.2);
    max-width: 400px;
    width: 90%;
    flex-shrink: 0;
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
    touch-action: pan-y;
}

#rules-content h2 {
    font-size: 24px;
    color: var(--accent);
    margin-bottom: 16px;
    text-align: center;
}

#rules-content h3 {
    font-size: 15px;
    color: var(--accent);
    margin-top: 16px;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#rules-content p {
    color: var(--text-dim);
    margin-bottom: 8px;
}

#rules-content ul {
    color: var(--text-dim);
    padding-left: 18px;
    margin-bottom: 8px;
}

#rules-content li {
    margin-bottom: 4px;
}

#rules-content b {
    color: var(--text);
}

#rules-close {
    position: absolute;
    top: 10px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 28px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
}

.rule-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 18px 0;
}

.variant-note {
    background: rgba(232, 192, 96, 0.1);
    border: 1px solid rgba(232, 192, 96, 0.2);
    border-radius: 8px;
    padding: 12px;
}

.variant-note p {
    color: var(--text);
    margin-bottom: 6px;
}
.variant-note p:last-child {
    margin-bottom: 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 380px) {
    .player-score {
        min-width: 45px;
        padding: 2px 5px;
    }
    .score-value {
        font-size: 16px;
    }
    .player-label {
        font-size: 9px;
    }
    #controls button {
        padding: 5px 10px;
        font-size: 12px;
        min-height: 36px;
    }
}

/* ===== LOBBY ===== */
#lobby {
    /* Wrapping rows; cards stretch to the tallest card in their row */
    display: flex;
    flex-flow: row wrap;
    align-items: stretch;
    align-content: center;
    align-content: safe center;
    justify-content: center;
    gap: 24px;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 24px 16px;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.lobby-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 32px 28px;
    background: rgba(40, 25, 10, 0.95);
    border-radius: 20px;
    border: 1px solid rgba(232, 192, 96, 0.3);
    width: 220px;
    flex-shrink: 0;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.lobby-card:hover {
    border-color: rgba(232, 192, 96, 0.6);
    transform: translateY(-2px);
}

.lobby-icon {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
}

.lobby-icon svg {
    width: 100%;
    height: 100%;
}

.lobby-card h2 {
    font-size: 28px;
    font-weight: 800;
    color: var(--accent);
    text-align: center;
    margin: 0;
}

.lobby-card p {
    font-size: 13px;
    color: var(--text-dim);
    text-align: center;
    line-height: 1.4;
    margin: 0;
}

.lobby-btn {
    display: block;
    padding: 12px 40px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    background: linear-gradient(135deg, #e8c060, #c89830);
    color: #1a0a00;
    text-decoration: none;
    text-align: center;
    transition: transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    margin-top: auto;
    line-height: 1.2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lobby-btn:active {
    transform: scale(0.95);
}

@media (max-width: 520px) {
    #lobby {
        flex-flow: column nowrap;
        align-items: center;
        justify-content: center;
        justify-content: safe center;
        gap: 16px;
    }
    .lobby-card {
        width: 100%;
        max-width: 300px;
        padding: 24px 20px;
        gap: 10px;
    }
}

/* ===== BACK BUTTON (game pages) ===== */
#btn-lobby {
    padding: 6px 14px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 40px;
    white-space: nowrap;
}

#btn-lobby:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.25);
}

/* ===== HISTORY PANEL ===== */
#history-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 2000;
    overflow-y: auto;
    touch-action: pan-y;
    padding: 20px 0;
}

#history-panel.hidden {
    display: none;
}

#history-content {
    position: relative;
    padding: 28px 24px;
    background: rgba(40, 25, 10, 0.97);
    border-radius: 16px;
    border: 1px solid rgba(255, 204, 0, 0.2);
    max-width: 400px;
    width: 90%;
    flex-shrink: 0;
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
    touch-action: pan-y;
}

#history-content h2 {
    font-size: 24px;
    color: var(--accent);
    margin-bottom: 16px;
    text-align: center;
}

#history-content h3 {
    font-size: 15px;
    color: var(--accent);
    margin-top: 16px;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#history-content p {
    color: var(--text-dim);
    margin-bottom: 8px;
}

#history-content b {
    color: var(--text);
}

#history-close {
    position: absolute;
    top: 10px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 28px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
}

/* ===== PASS BADGE (Go scoreboard) ===== */
.pass-badge {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--active-glow);
    background: rgba(30, 90, 30, 0.5);
    border: 1px solid rgba(60, 160, 60, 0.45);
    border-radius: 5px;
    padding: 2px 6px;
    align-self: center;
    white-space: nowrap;
}
