/* Base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: rgba(0,0,0,0); /* Remove tap highlight on mobile */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    touch-action: manipulation; /* Prevents double-tap zoom on mobile */
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
}

h1 {
    text-align: center;
    margin-bottom: 30px;
    color: #2c3e50;
}

h2 {
    margin-bottom: 20px;
    color: #2c3e50;
}

.section {
    background-color: #fff;
    border-radius: 8px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: visible;
}

.hidden {
    display: none;
}

/* Ensure room link container is always visible when invite section is shown */
#invite-section .room-link-container {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Buttons */
.btn {
    padding: 12px 20px; /* Slightly larger padding for better touch targets */
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.1s;
    min-height: 44px; /* Minimum height for touch targets */
    min-width: 44px; /* Minimum width for touch targets */
}

.btn:hover {
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(0);
}

.primary {
    background-color: #3498db;
    color: white;
}

.primary:hover {
    background-color: #2980b9;
}

.secondary {
    background-color: #7f8c8d;
    color: white;
}

.secondary:hover {
    background-color: #6c7a7a;
}

.danger {
    background-color: #e74c3c;
    color: white;
}

.danger:hover {
    background-color: #c0392b;
}

/* Lobby styles */
.lobby-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
}

/* Form styles */
.form-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

#room-code {
    width: 100%;
    max-width: 200px;
    padding: 12px;
    font-size: 16px;
    text-align: center;
    letter-spacing: 2px;
    border: 2px solid #ddd;
    border-radius: 4px;
    transition: border-color 0.3s;
    height: 48px; /* Taller input for mobile */
}

#room-code:focus {
    border-color: #3498db;
    outline: none;
}

#join-room {
    opacity: 0.6;
    transition: opacity 0.3s, transform 0.2s, background-color 0.3s;
}

#join-room.active {
    opacity: 1;
    background-color: #2ecc71;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(46, 204, 113, 0.3);
}

#invite-section {
    margin-bottom: 30px;
    min-height: 400px;
    overflow: visible;
}

.room-code-section,
.room-link-container,
.waiting-section {
    margin: 20px 0;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.room-code-section {
    border-left: 5px solid #3498db;
    background-color: #ebf5fb;
}

.room-code-section h4 {
    margin-bottom: 10px;
    color: #2c3e50;
    text-align: center;
}

.room-link-container h4 {
    margin-bottom: 15px;
    color: #2e7d32;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
}

.invite-code-container {
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.room-link-container {
    margin: 15px 0;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 20px;
    background-color: #e8f5e9;
    border-left: 5px solid #4caf50;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    position: relative;
    z-index: 10;
}

.waiting-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
}

#waiting-message {
    font-size: 18px;
    color: #7f8c8d;
    margin-bottom: 10px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-left-color: #3498db;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.invite-code {
    font-size: 2.5rem;
    font-weight: bold;
    letter-spacing: 3px;
    padding: 15px 25px;
    background-color: #fff;
    border-radius: 4px;
    border: 2px dashed #3498db;
    text-align: center;
    margin-bottom: 15px;
    color: #2c3e50;
    text-shadow: 0 1px 0 rgba(255,255,255,0.8);
    word-break: break-all; /* Prevents overflow on small screens */
    max-width: 100%;
}

.copy-feedback {
    text-align: center;
    padding: 10px;
    margin: 15px 0;
    border-radius: 4px;
    font-weight: bold;
    min-height: 20px;
}

.copy-feedback.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.copy-feedback.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.room-link {
    font-size: 1rem;
    padding: 12px 20px;
    background-color: #ffffff;
    border-radius: 5px;
    border: 2px solid #4caf50;
    width: 100%;
    max-width: 500px;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-all;
    hyphens: auto;
    font-family: monospace;
    text-align: center;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.link-buttons,
.banner-link-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap;
}

.btn.small {
    padding: 5px 10px;
    font-size: 0.9rem;
}

.or-divider {
    position: relative;
    text-align: center;
    width: 100%;
    margin: 15px 0;
    color: #7f8c8d;
}

.or-divider::before,
.or-divider::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background-color: #ddd;
}

.or-divider::before {
    left: 0;
}

.or-divider::after {
    right: 0;
}

.join-form {
    display: flex;
    width: 100%;
    gap: 10px;
}

.join-form input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
}

.invite-code {
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    padding: 15px;
    margin: 15px 0;
    background-color: #f1f1f1;
    border-radius: 4px;
    letter-spacing: 2px;
}

#waiting-message {
    text-align: center;
    color: #7f8c8d;
    margin-top: 20px;
}

/* Game styles */
.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.game-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.test-mode-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-bottom: 10px;
}

.test-mode-status {
    font-size: 14px;
    color: #3498db;
    margin-top: 5px;
    font-weight: bold;
}

#player-info {
    font-size: 18px;
    padding: 10px 15px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

#player-info.your-turn {
    background-color: rgba(46, 204, 113, 0.2);
    border-left: 4px solid #2ecc71;
    animation: pulse-turn 1.5s infinite alternate;
    box-shadow: 0 2px 10px rgba(46, 204, 113, 0.3);
}

#player-color {
    font-weight: bold;
}

#turn-indicator {
    margin-left: 10px;
    font-weight: bold;
}

#player.my-turn {
    color: #2ecc71;
    font-weight: bold;
}

.opponent-turn {
    color: #e74c3c;
    font-weight: bold;
}

@keyframes pulse-turn {
    from { box-shadow: 0 2px 10px rgba(46, 204, 113, 0.2); }
    to { box-shadow: 0 2px 15px rgba(46, 204, 113, 0.5); }
}

.board-container {
    width: 100%;
    max-width: 600px;
    margin: 20px auto;
    position: relative;
    border: 6px solid transparent;
    border-radius: 8px;
    transition: border-color 0.3s ease;
    box-sizing: border-box;
    overflow: hidden;
}

.board-container.your-turn {
    border-color: #2ecc71;
    animation: pulse-board-highlight 2s infinite;
}



#board {
    display: block;
    width: 100%;
    height: auto;
    background-color: transparent;
}

/* Board squares */
.square {
    stroke: #333;
    stroke-width: 1;
}

.square.light {
    fill: #f0d9b5;
}

.square.dark {
    fill: #b58863;
}

.square.highlight {
    fill: rgba(106, 159, 181, 0.5) !important;
    animation: pulse-highlight 1.5s infinite alternate;
    stroke: #6a9fb5;
    stroke-width: 3;
}

.square.selected {
    fill: rgba(106, 159, 181, 0.8);
}

@keyframes pulse-highlight {
    from { fill: rgba(106, 159, 181, 0.4); }
    to { fill: rgba(106, 159, 181, 0.7); }
}

/* Pieces */
.piece {
    cursor: pointer;
}

/* Only apply hover effect to player's pieces */
.piece-group.player-piece:hover .piece {
    stroke: #f1c40f;
    stroke-width: 3;
    filter: brightness(1.1);
}

.piece-group.selected .piece {
    stroke: #2ecc71;
    stroke-width: 3;
    filter: brightness(1.2);
}

.piece-group.animated {
    animation: move-piece 0.6s ease-in-out;
}

@keyframes move-piece {
    0% { transform: translate(0, 0); opacity: 0.7; }
    100% { transform: translate(0, 0); opacity: 1; }
}

.piece.red {
    fill: #d63031;
}

.piece.black {
    fill: #2d3436;
}

.piece-border {
    fill: none;
    stroke: #fff;
    stroke-width: 2;
}

.king-marker {
    fill: #f1c40f;
}

/* Game over styles */
#game-over {
    position: relative;
    z-index: 10;
    background-color: rgba(255, 255, 255, 0.95);
    border: 3px solid #7f8c8d; /* Default neutral color */
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
    animation: pulse-neutral 1.5s infinite alternate;
}

/* Winner style */
#game-over.winner {
    border: 3px solid #2ecc71;
    animation: pulse-winner 1.5s infinite alternate;
}

/* Loser style */
#game-over.loser {
    border: 3px solid #e74c3c;
    animation: pulse-loser 1.5s infinite alternate;
}

/* Draw style */
#game-over.draw {
    border: 3px solid #3498db;
    animation: pulse-draw 1.5s infinite alternate;
}

@keyframes pulse-winner {
    from { box-shadow: 0 4px 15px rgba(46, 204, 113, 0.2); }
    to { box-shadow: 0 4px 20px rgba(46, 204, 113, 0.6); }
}

@keyframes pulse-loser {
    from { box-shadow: 0 4px 15px rgba(231, 76, 60, 0.2); }
    to { box-shadow: 0 4px 20px rgba(231, 76, 60, 0.6); }
}

@keyframes pulse-draw {
    from { box-shadow: 0 4px 15px rgba(52, 152, 219, 0.2); }
    to { box-shadow: 0 4px 20px rgba(52, 152, 219, 0.6); }
}

@keyframes pulse-neutral {
    from { box-shadow: 0 4px 15px rgba(127, 140, 141, 0.2); }
    to { box-shadow: 0 4px 20px rgba(127, 140, 141, 0.6); }
}

@keyframes pulse-board-highlight {
    0% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.4); }
    50% { box-shadow: 0 0 15px 5px rgba(46, 204, 113, 0.3); }
    100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

#game-over h2 {
    font-size: 28px;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#game-over.winner h2 {
    color: #27ae60;
}

#game-over.loser h2 {
    color: #c0392b;
}

#game-over.draw h2 {
    color: #2980b9;
}

.rematch-options {
    text-align: center;
    margin-top: 15px;
}

.rematch-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 15px 0;
}

#rematch-timer {
    font-size: 14px;
    color: #7f8c8d;
    font-weight: bold;
}

#game-result {
    text-align: center;
    font-size: 22px;
    margin: 15px 0;
    font-weight: bold;
    color: #2c3e50;
}

/* Room code banner */
#room-code-banner {
    display: none;
    background-color: #f8f9fa;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.room-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 15px;
}

.room-code-info, .room-link-info {
    text-align: center;
    padding: 20px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.room-code-info {
    border-left: 5px solid #3498db;
}

.room-link-info {
    border-left: 5px solid #4caf50;
}

.room-code-info h3, .room-link-info h3 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 16px;
}

.code-display {
    font-size: 28px;
    font-weight: bold;
    letter-spacing: 3px;
    color: #2c3e50;
    padding: 10px;
    margin-bottom: 15px;
}

.link-display {
    font-size: 14px;
    font-family: monospace;
    color: #2c3e50;
    padding: 10px;
    margin-bottom: 15px;
    word-break: break-all;
    background-color: #f0f0f0;
    border-radius: 4px;
    min-height: 40px;
}

#banner-copy-code, #banner-copy-link {
    padding: 8px 20px;
    font-size: 14px;
}

#banner-copy-feedback {
    text-align: center;
    font-size: 14px;
    font-weight: bold;
    color: #2ecc71;
}

.qr-code-container {
    text-align: center;
    margin-top: 20px;
    padding: 20px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.qr-code-container h3 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 16px;
}

#qr-code {
    display: inline-block;
    padding: 20px;
    background-color: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
}

#qr-code canvas {
    display: block;
}

/* Room info section */
#room-info {
    overflow: visible !important;
    min-height: 500px;
    width: 100%;
    position: relative;
}

#room-info.hidden {
    display: none;
}

/* When room-info is shown, ensure all content is visible */
#room-info:not(.hidden) {
    display: block !important;
    background-color: transparent;
    box-shadow: none;
    padding: 0;
}

#room-info .waiting-section {
    background-color: #fff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#invite-section {
    display: none !important; /* Hide the redundant invite section since we use the banner */
}

/* Status message */
#status-message {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background-color: rgba(44, 62, 80, 0.9);
    color: white;
    border-radius: 4px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
}

#status-message.show {
    opacity: 1;
}

/* Move arrow styles */
.move-arrow {
    animation: pulse-glow 1.5s infinite alternate;
    filter: drop-shadow(0 0 5px rgba(255, 204, 0, 0.7));
    z-index: 100;
    pointer-events: none;
}

@keyframes pulse-glow {
    from { filter: drop-shadow(0 0 3px rgba(255, 204, 0, 0.5)); }
    to { filter: drop-shadow(0 0 8px rgba(255, 204, 0, 0.8)); }
}

/* Jump marker (X) styles */
.jump-marker {
    opacity: 0.9;
    animation: pulse-jump-marker 1.2s infinite alternate;
    filter: drop-shadow(0 0 5px rgba(255, 51, 51, 0.8));
    z-index: 100;
}

@keyframes pulse-jump-marker {
    from { opacity: 0.7; filter: drop-shadow(0 0 3px rgba(255, 51, 51, 0.6)); }
    to { opacity: 1; filter: drop-shadow(0 0 8px rgba(255, 51, 51, 0.9)); }
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .room-info-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .code-display {
        font-size: 24px;
    }
    
    .link-display {
        font-size: 12px;
    }
    
    .qr-code-container {
        margin-top: 15px;
        padding: 15px;
    }
    
    #qr-code {
        padding: 15px;
    }
    
    #qr-code canvas {
        max-width: 200px !important;
        height: auto !important;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 15px 10px;
    }
    
    h1 {
        font-size: 1.8rem;
        margin-bottom: 20px;
    }
    
    h2 {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
    
    .section {
        padding: 20px 15px;
        margin-bottom: 20px;
    }
    
    .btn {
        padding: 12px 16px;
        font-size: 15px;
        width: 100%;
        margin-bottom: 5px;
    }
    
    .invite-code {
        font-size: 1.8rem;
        padding: 10px 15px;
    }
    
    .game-info {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .game-controls {
        width: 100%;
        align-items: center;
        margin-top: 10px;
    }
    
    #player-info {
        width: 100%;
        text-align: center;
    }
    
    .rematch-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    #room-code-banner h2 {
        font-size: 16px;
    }
    
    #banner-room-code {
        font-size: 18px;
        display: block;
        margin: 10px auto;
    }
    
    .join-form {
        flex-direction: column;
    }
    
    .room-code-section, 
    .room-link-container {
        padding: 15px 10px;
    }
    
    #game-over h2 {
        font-size: 24px;
    }
    
    #game-result {
        font-size: 18px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .container {
        padding: 10px 5px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .section {
        padding: 15px 10px;
    }
    
    .invite-code {
        font-size: 1.5rem;
        letter-spacing: 2px;
    }
    
    #status-message {
        width: 90%;
        font-size: 14px;
        padding: 8px 12px;
    }
}
