/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --red: #e53935;
    --red-light: #ff6f60;
    --blue: #1e88e5;
    --blue-light: #6ab7ff;
    --yellow: #fdd835;
    --yellow-light: #ffff6b;
    --green: #43a047;
    --green-light: #76d275;
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --text-light: #eee;
    --text-muted: #888;
    --border-color: #333;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #0f0f23 100%);
    color: var(--text-light);
    min-height: 100vh;
    overflow-x: hidden;
    touch-action: manipulation;
}

/* Game Container */
#game-container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    justify-content: flex-end;
    padding: 0.5rem 1rem;
}

/* Board Header - centered over game board */
#board-header {
    text-align: center;
    margin-bottom: 0.5rem;
}

#board-header h1 {
    font-size: 2.5rem;
    color: var(--red);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.1em;
    margin-bottom: 0.2rem;
}

/* Dropdown Menu */
.game-menu {
    position: relative;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-btn {
    background: var(--bg-card);
    color: var(--text-light);
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.dropdown-btn:hover {
    background: var(--red);
    border-color: var(--red);
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--bg-card);
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    z-index: 1000;
    overflow: hidden;
    margin-top: 4px;
}

.dropdown-content a {
    color: var(--text-light);
    padding: 0.8rem 1rem;
    text-decoration: none;
    display: block;
    transition: background 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.dropdown-content a:last-child {
    border-bottom: none;
}

.dropdown-content a:hover {
    background: rgba(255, 255, 255, 0.1);
}

.dropdown-content a#menu-quit {
    color: var(--red);
}

.dropdown-content a#menu-quit:hover {
    background: var(--red);
    color: white;
}

.dropdown:hover .dropdown-content,
.dropdown.active .dropdown-content {
    display: block;
}

#board-header .tagline {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

#board-header .tagline a {
    color: var(--blue-light);
    text-decoration: none;
    transition: color 0.2s;
}

#board-header .tagline a:hover {
    color: var(--blue);
    text-decoration: underline;
}

#turn-indicator {
    font-size: 1.2rem;
    margin-top: 0.5rem;
    min-height: 1.5rem;
}

/* Status Display - below game board, centered */
#status-display {
    font-size: 1rem;
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    min-height: 1.5rem;
    color: var(--yellow-light);
    text-align: center;
    width: 100%;
    max-width: 850px;
}

#status-display:empty {
    display: none;
}

#status-display .move-options {
    margin-top: 0.3rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

#status-display .move-option {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin: 0.2rem;
    font-size: 0.85rem;
}

#status-display .ai-action {
    color: var(--blue-light);
}

#status-display .human-action {
    color: var(--green-light);
}

main {
    flex: 1;
    display: flex;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

/* Board Area */
#board-area {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game-board {
    border: 3px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    max-width: 100%;
    height: auto;
}

/* Game Panel */
#game-panel {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1rem;
    min-width: 250px;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* Card Area */
#card-area {
    text-align: center;
}

#card-display {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.card-back, .card {
    width: 80px;
    height: 110px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.card-back {
    background: linear-gradient(135deg, #1e88e5 0%, #0d47a1 100%);
    color: white;
    font-size: 1.8rem;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s;
    border: 2px solid #fff;
    letter-spacing: 0.1em;
}

.card-back:hover {
    transform: scale(1.05);
}

.card {
    background: white;
    color: #333;
    font-size: 2rem;
    border: 2px solid #ccc;
}

.card.apologies-card {
    font-size: 0.85rem;
    color: var(--red);
    font-weight: bold;
}

.card.hidden {
    visibility: hidden;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    background: #444;
    color: white;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--red) 0%, #c62828 100%);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--red-light) 0%, var(--red) 100%);
}

#draw-btn {
    width: 100%;
}

#end-turn-btn, #new-game-btn {
    width: 100%;
    margin-top: 0.5rem;
}

#new-game-btn {
    background: linear-gradient(135deg, var(--green) 0%, #2e7d32 100%);
}

/* Player Info */
#player-info h3, #game-log h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
}

#player-list {
    list-style: none;
}

#player-list li {
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

#player-list li.current-player {
    background: rgba(255, 255, 255, 0.1);
    border-left: 3px solid var(--red);
}

#player-list li .pawn-count {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.color-dot.red { background: var(--red); }
.color-dot.blue { background: var(--blue); }
.color-dot.yellow { background: var(--yellow); }
.color-dot.green { background: var(--green); }

/* Game Log */
#game-log {
    flex: 1;
    min-height: 150px;
    max-height: 200px;
    display: flex;
    flex-direction: column;
}

#log-messages {
    flex: 1;
    overflow-y: auto;
    font-size: 0.85rem;
    color: var(--text-muted);
}

#log-messages p {
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#log-messages p:last-child {
    color: var(--text-light);
}

/* Leaderboard */
#leaderboard {
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}

#leaderboard h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
}

#leaderboard-list {
    list-style: none;
    counter-reset: leaderboard;
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.85rem;
}

#leaderboard-list li {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.2rem;
    counter-increment: leaderboard;
}

#leaderboard-list li::before {
    content: counter(leaderboard) ".";
    min-width: 1.5rem;
    color: var(--text-muted);
    font-weight: bold;
}

#leaderboard-list li:nth-child(1) {
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.2) 0%, transparent 100%);
}

#leaderboard-list li:nth-child(1)::before {
    color: gold;
}

#leaderboard-list li:nth-child(2) {
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.15) 0%, transparent 100%);
}

#leaderboard-list li:nth-child(2)::before {
    color: silver;
}

#leaderboard-list li:nth-child(3) {
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.15) 0%, transparent 100%);
}

#leaderboard-list li:nth-child(3)::before {
    color: #cd7f32;
}

#leaderboard-list .player-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#leaderboard-list .player-name.is-ai {
    color: var(--text-muted);
    font-style: italic;
}

#leaderboard-list .player-name.is-human {
    color: var(--text-light);
}

#leaderboard-list .win-count {
    font-weight: bold;
    color: var(--green-light);
    margin-left: 0.5rem;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    position: relative;
}

.modal-content h2 {
    margin-bottom: 1rem;
    color: var(--red);
}

.modal-content p {
    margin-bottom: 1rem;
    color: var(--text-muted);
}

#name-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#player-name {
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-dark);
    color: var(--text-light);
    text-align: center;
}

#player-name:focus {
    outline: none;
    border-color: var(--red);
}

.opponents-info {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.opponents-info ul {
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 0.5rem;
}

.opponents-info li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* Instructions */
.floating-btn {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    color: var(--text-light);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 100;
}

.floating-btn:hover {
    background: var(--red);
    border-color: var(--red);
}

.modal-content.instructions {
    max-width: 500px;
    text-align: left;
    max-height: 80vh;
    overflow-y: auto;
}

.close-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.close-btn:hover {
    color: var(--text-light);
}

.instructions-content h3 {
    color: var(--red);
    margin: 1rem 0 0.5rem;
    font-size: 1rem;
}

.instructions-content p,
.instructions-content li {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.instructions-content ul,
.instructions-content ol {
    margin-left: 1.5rem;
}

.instructions-content li {
    margin-bottom: 0.3rem;
}

/* Large Modals (Rules & Strategy) */
.modal-large {
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal-large h2 {
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.modal-scroll-content {
    overflow-y: auto;
    flex: 1;
    padding-right: 0.5rem;
    text-align: left;
}

.rules-section {
    margin-bottom: 1.5rem;
}

.rules-section h3 {
    color: var(--red);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
}

.rules-section h4 {
    color: var(--blue-light);
    margin: 0.8rem 0 0.4rem;
    font-size: 0.95rem;
}

.rules-section p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.rules-section ul,
.rules-section ol {
    margin-left: 1.5rem;
    margin-bottom: 0.5rem;
}

.rules-section li {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 0.3rem;
}

.rules-section li strong {
    color: var(--text-light);
}

.rules-section em {
    color: var(--yellow-light);
    font-style: italic;
}

/* Card Reference Table */
.card-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
    font-size: 0.85rem;
}

.card-table th,
.card-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.card-table th {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-light);
    font-weight: bold;
}

.card-table td {
    color: var(--text-muted);
}

.card-table td strong {
    color: var(--red-light);
}

.card-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

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

/* Responsive */
@media (max-width: 900px) {
    main {
        flex-direction: column;
        align-items: center;
    }

    #game-panel {
        width: 100%;
        max-width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }

    #card-area {
        flex: 1;
        min-width: 200px;
    }

    #player-info, #game-log, #leaderboard {
        flex: 1;
        min-width: 200px;
    }

    #game-board {
        max-width: 100%;
        width: 100%;
    }
}

@media (max-width: 500px) {
    header h1 {
        font-size: 1.8rem;
    }

    #game-panel {
        flex-direction: column;
    }

    .card-back, .card {
        width: 60px;
        height: 85px;
    }

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