/* Main Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
}

h1 {
    font-size: 2.2rem;
    color: #2c3e50;
    margin: 0;
}

.header-icons {
    display: flex;
    gap: 15px;
    align-items: center;
}

.settings-button, .info-button {
    font-size: 1.5rem;
    color: #3498db;
    cursor: pointer;
    transition: color 0.2s;
}

.settings-button:hover, .info-button:hover {
    color: #2980b9;
}

.theme-selector {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

select {
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background-color: white;
    font-size: 0.95rem;
    width: 100%;
}

main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.game-container {
    display: flex;
    gap: 15px;
    height: 100%;
    overflow: hidden;
}

.board-container {
    flex: 1 1 70%;
    max-height: calc(98vh - 120px); /* Account for header and margins */
    display: flex;
    align-items: center;
    justify-content: center;
}

.chess-board {
    width: 100%;
    max-width: min(calc(98vh - 150px), 100%);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 5px solid #2c3e50;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    position: relative;
}

.square {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
}

.piece {
    width: 100%;
    height: 100%;
    position: relative;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.piece::before {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    line-height: 1;
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.6);
}

.piece.black-king::before, 
.piece.black-queen::before, 
.piece.black-rook::before, 
.piece.black-bishop::before, 
.piece.black-knight::before, 
.piece.black-pawn::before {
    color: #000;
    text-shadow: 
        0 0 2px #fff,
        0 0 3px rgba(255, 255, 255, 0.7),
        0 0 5px rgba(255, 255, 255, 0.4);
}

.piece.white-king::before, 
.piece.white-queen::before, 
.piece.white-rook::before, 
.piece.white-bishop::before, 
.piece.white-knight::before, 
.piece.white-pawn::before {
    color: #fff;
    text-shadow: 
        0 0 2px #000,
        0 0 3px rgba(0, 0, 0, 0.7),
        0 0 5px rgba(0, 0, 0, 0.4);
}

/* Sidebar containing controls */
.sidebar {
    flex: 0 0 35%;
    max-width: 35%;
    align-self: flex-start;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: auto;
    max-height: calc(98vh - 150px); /* Match board container max-height */
}

.controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 15px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: auto;
}

.status-message {
    font-size: 1.2rem;
    font-weight: bold;
    padding: 10px;
    border-radius: 4px;
    background-color: #f8f9fa;
    text-align: center;
}

.buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    background-color: #3498db;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

#hint-btn {
    background-color: #2ecc71;
}

#hint-btn:hover {
    background-color: #27ae60;
}

#new-plot-btn {
    background-color: #9b59b6;
}

#new-plot-btn:hover {
    background-color: #8e44ad;
}

.challenge-info {
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 4px;
    border-left: 4px solid #3498db;
}

.challenge-info h3 {
    margin-bottom: 10px;
    color: #2c3e50;
}

/* Info Popup */
.info-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.info-popup.active {
    display: flex;
}

.info-popup-content {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    position: relative;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.close-popup {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #7f8c8d;
}

.close-popup:hover {
    color: #2c3e50;
}

/* Popups */
.popup-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.popup-overlay.active {
    display: flex;
}

.popup-content {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.close-popup {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #7f8c8d;
}

.close-popup:hover {
    color: #2c3e50;
}

.settings-section {
    margin-bottom: 20px;
}

.settings-section h4 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.settings-option {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.settings-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.howto-section {
    margin-top: 15px;
    border-top: 1px solid #eee;
    padding-top: 15px;
}

.howto-section h4 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.howto-section ul {
    padding-left: 20px;
}

.howto-section li {
    margin-bottom: 5px;
}

/* Display option classes */
.hide-labels .file-label,
.hide-labels .rank-label {
    display: none;
}

.hide-valid-moves .valid-move::after {
    display: none;
}

/* Error indicator style */
.invalid-move-indicator {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 0, 0, 0.3);
    z-index: 20;
    pointer-events: none;
    animation: invalidMove 0.5s;
}

@keyframes invalidMove {
    0% { opacity: 0.8; }
    100% { opacity: 0; }
}

/* File and rank labels - improved visibility */
.file-label, .rank-label {
    position: absolute;
    font-size: 12px;
    font-weight: bold;
    pointer-events: none;
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.7), 0 0 3px rgba(0, 0, 0, 0.5);
}

.file-label {
    bottom: 2px;
    right: 4px;
}

.rank-label {
    top: 2px;
    left: 4px;
}

/* Ensure labels are visible on both light and dark squares */
.square.dark .file-label, .square.dark .rank-label {
    color: #ffffff;
}

.square.light .file-label, .square.light .rank-label {
    color: #000000;
}

/* Theme-specific label colors for better visibility */
.theme-classic .square.dark .file-label,
.theme-classic .square.dark .rank-label {
    color: #ffffff;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}

.theme-classic .square.light .file-label,
.theme-classic .square.light .rank-label {
    color: #000000;
    text-shadow: 0 0 3px rgba(255, 255, 255, 0.8);
}

/* Highlight classes */
.selected {
    background-color: rgba(173, 216, 230, 0.7) !important;
    position: relative;
    z-index: 1;
}

.valid-move {
    position: relative;
}

.valid-move::after {
    content: '';
    position: absolute;
    width: 25%;
    height: 25%;
    background-color: rgba(0, 128, 0, 0.5);
    border-radius: 50%;
    z-index: 5;
}

.last-move {
    position: relative;
}

.last-move::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 0, 0.2);
    z-index: 1;
}

/* Check styling - highlight king in check */
.check {
    position: relative;
}

.check::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 0, 0, 0.4);
    z-index: 1;
    animation: checkPulse 1.5s infinite;
}

@keyframes checkPulse {
    0% { background-color: rgba(255, 0, 0, 0.4); }
    50% { background-color: rgba(255, 0, 0, 0.6); }
    100% { background-color: rgba(255, 0, 0, 0.4); }
}

/* Hint styling */
.hint-from {
    background-color: rgba(255, 215, 0, 0.6) !important; /* Gold */
    z-index: 2;
}

.hint-to {
    background-color: rgba(50, 205, 50, 0.6) !important; /* Lime Green */
    z-index: 2;
}

.hint-arrow {
    position: absolute;
    width: 8px;
    height: 40px;
    background-color: rgba(255, 165, 0, 0.8); /* Orange */
    z-index: 15;
    transform-origin: center;
    pointer-events: none;
    border-radius: 2px;
}

.hint-arrow::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 12px solid rgba(255, 165, 0, 0.8); /* Orange */
}

/* Celebration effects */
@keyframes confetti {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

@keyframes celebrate {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.celebration {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #ffcc00;
  animation: confetti 3s ease-out forwards;
}

.celebrate-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  color: #ffcc00;
  animation: celebrate 1s ease-in-out infinite;
}

/* Responsive Design */
@media screen and (min-width: 1024px) {
    /* Desktop styles */
    .game-container {
        align-items: flex-start;
        justify-content: space-between;
    }
    
    .board-container {
        flex: 0 0 60%;
        max-width: 60%;
        align-self: flex-start;
    }
    
    .sidebar {
        flex: 0 0 35%;
        max-width: 35%;
        align-self: flex-start;
    }
    
    .chess-board {
        max-width: 100%;
    }
}

@media screen and (max-width: 1023px) {
    /* Tablet styles */
    .game-container {
        flex-direction: column;
        height: auto;
    }
    
    .board-container {
        flex: 0 0 auto;
        max-width: 600px;
        width: 100%;
    }
    
    .sidebar {
        flex: 0 0 auto;
        flex-direction: row;
        width: 100%;
        max-width: 600px;
    }
    
    .controls {
        flex: 3;
    }
    
    .buttons {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .btn {
        flex: 1 1 30%;
        padding: 12px 10px;
        font-size: 0.9rem;
        text-align: center;
    }
}

@media screen and (max-width: 767px) {
    /* Mobile styles */
    html, body, .container {
        height: 100%;
        overflow: hidden;
    }
    
    .container {
        padding: 10px 5px;
        display: flex;
        flex-direction: column;
    }
    
    main {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .game-container {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    header {
        flex-direction: row;
        margin-bottom: 10px;
        padding-bottom: 5px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .board-container {
        flex: 0 0 auto;
        width: 100%;
        max-width: 100%;
        aspect-ratio: 1 / 1;
        max-height: 50vh; /* Reduced to make more room for controls */
    }
    
    .chess-board {
        width: 100%;
        height: 100%;
        max-width: min(50vh, 100%);
    }
    
    .sidebar {
        flex: 1;
        flex-direction: column;
        gap: 10px;
        overflow: auto;
        margin-top: 10px;
    }
    
    .controls {
        padding: 10px;
        gap: 8px;
    }
    
    .status-message {
        font-size: 1rem;
        padding: 6px;
        margin-bottom: 5px;
    }
    
    .challenge-info {
        padding: 8px;
        margin-top: 5px;
    }
    
    .challenge-info h3 {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }
    
    .challenge-info p {
        font-size: 0.9rem;
        line-height: 1.4;
    }
    
    .buttons {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .btn {
        flex: 1;
        padding: 8px 5px;
        font-size: 0.8rem;
    }
    
    /* Popup adjustments for mobile */
    .popup-content {
        padding: 15px;
        width: 95%;
        max-height: 85vh;
    }
}

@media screen and (max-width: 480px) {
    /* Small mobile styles */
    .container {
        padding: 5px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .buttons {
        gap: 5px;
    }
    
    .btn {
        flex: 1;
        margin: 0;
        font-size: 0.8rem;
        padding: 8px 5px;
    }
    
    .theme-selector {
        width: 100%;
    }
    
    select {
        width: 100%;
        padding: 6px 8px;
    }
}
