/* TTSA Chess Academy Styles */
:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --accent-color: #ec4899;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --chess-light: #f0d9b5;
    --chess-dark: #b58863;
    --chess-highlight: #fbbf24;
    --chess-valid: #10b981;
    --chess-capture: #ef4444;
}

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

html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Prevent horizontal scroll on all containers */
div, section, article, main, aside, nav, header, footer {
    max-width: 100%;
    overflow-x: hidden;
}

/* Ensure images and media don't cause overflow */
img, video, iframe, embed, object {
    max-width: 100%;
    height: auto;
}

/* Prevent text overflow */
p, h1, h2, h3, h4, h5, h6, span, a, li {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Table responsiveness */
.table-wrapper,
.overflow-x-auto {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    display: table-header-group;
}

tbody {
    display: table-row-group;
}

tr {
    display: table-row;
}

td, th {
    display: table-cell;
    vertical-align: middle;
}

th {
    text-align: left;
}

tr:not(:last-child) td,
tr:not(:last-child) th {
    border-bottom: 1px solid #e5e7eb;
}

@media (max-width: 767px) {
    .table-responsive table {
        display: block;
        width: 100%;
        overflow-x: auto;
    }
}

.fredoka {
    font-family: 'Fredoka', cursive;
}

/* Chess Board Styles */
.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1;
    border: 4px solid #4a5568;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    margin: 0 auto;
    transition: transform 0.3s ease;
}

.chess-board.flipped {
    transform: rotate(180deg);
}

.chess-board.flipped .chess-piece {
    transform: rotate(180deg);
}

.chess-square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
    width: 100%;
    height: 100%;
    aspect-ratio: 1;
}

.chess-square.light {
    background-color: var(--chess-light);
}

.chess-square.dark {
    background-color: var(--chess-dark);
}

.chess-piece {
    font-size: 2.5rem;
    line-height: 1;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    transition: transform 0.2s ease;
}

.chess-square:hover .chess-piece {
    transform: scale(1.1);
}

.chess-square:hover {
    transform: scale(1.05);
    z-index: 10;
    filter: brightness(1.1);
}

.chess-square.selected {
    background-color: var(--chess-highlight) !important;
    box-shadow: inset 0 0 0 3px #f59e0b;
}

.chess-square.highlight {
    background-color: rgba(16, 185, 129, 0.4) !important;
    box-shadow: inset 0 0 0 2px #10b981;
}


.chess-game-page {
    min-height: 100%;
    padding-top: clamp(0.5rem, 1.5vh, 1.5rem);
    padding-bottom: clamp(0.5rem, 1.5vh, 1.5rem);
}

.chess-game-panel {
    padding: clamp(0.5rem, 1.5vh, 1.5rem);
    margin-bottom: 0;
}

.chess-board-shell {
    width: min(100%, 600px, max(220px, calc(100vh - 20rem)));
    aspect-ratio: 1;
    flex: 0 0 auto;
}

#myBoard,
#myBoard > div {
    width: 100% !important;
    max-width: 100%;
}

.game-options {
    margin-top: clamp(0.5rem, 1.5vh, 1.5rem);
    gap: clamp(0.5rem, 1.2vh, 1rem);
}

.rated-options,
.game-controls,
.game-status {
    margin-top: clamp(0.4rem, 1vh, 1rem);
}

.game-controls {
    padding: clamp(0.4rem, 1vh, 1rem);
}

@supports (height: 100dvh) {
    .chess-board-shell {
        width: min(100%, 600px, max(220px, calc(100dvh - 20rem)));
    }
}

@media (min-width: 1024px) {
    .chess-board-shell {
        width: min(100%, 480px, max(220px, calc(100vh - 20rem)));
    }
}

@supports (height: 100dvh) {
    @media (min-width: 1024px) {
        .chess-board-shell {
            width: min(100%, 480px, max(220px, calc(100dvh - 20rem)));
        }
    }
}

@media (max-width: 640px) {
    .chess-game-page {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .chess-game-panel {
        border-radius: 0.75rem;
    }

    .game-actions {
        width: 100%;
    }

    .game-actions > * {
        flex: 1 1 auto;
        padding-left: 0.65rem;
        padding-right: 0.65rem;
        text-align: center;
    }
}

@media (max-height: 700px) {
    .chess-game-page {
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }

    .chess-game-panel {
        padding: 0.4rem;
    }

    .chess-board-shell {
        width: min(100%, 600px, max(160px, calc(100vh - 15.5rem)));
    }

    .game-options {
        margin-top: 0.35rem;
        gap: 0.35rem;
    }

    .rated-options,
    .game-controls,
    .game-status {
        margin-top: 0.3rem;
    }

    .difficulty-step {
        width: 2rem;
        height: 2rem;
    }

    .difficulty-selector > div:last-child {
        margin-top: 0.25rem;
        font-size: 0.7rem;
    }

    .game-controls button {
        width: 2.25rem;
        height: 2.25rem;
    }
}

@supports (height: 100dvh) {
    @media (max-height: 700px) {
        .chess-board-shell {
            width: min(100%, 600px, max(160px, calc(100dvh - 15.5rem)));
        }
    }
}

/* Chessboard.js Click-to-Move Highlighting */
#myBoard .square-55d63 {
    position: relative;
}

#myBoard .board-coordinate {
    position: absolute;
    z-index: 4;
    font-size: clamp(0.5rem, 1.7vw, 0.72rem);
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    text-transform: uppercase;
}

#myBoard .board-coordinate-rank {
    top: clamp(2px, 0.7vw, 5px);
    left: clamp(2px, 0.7vw, 5px);
}

#myBoard .board-coordinate-file {
    right: clamp(2px, 0.7vw, 5px);
    bottom: clamp(2px, 0.7vw, 5px);
}

#myBoard .white-1e1d7 .board-coordinate {
    color: #31572c;
}

#myBoard .black-3c85d .board-coordinate {
    color: #f4f1de;
}

.square-55d63.selected-square {
    background-color: rgba(251, 191, 36, 0.6) !important;
    box-shadow: inset 0 0 0 3px #f59e0b;
}

.square-55d63.valid-move {
    position: relative;
}

.square-55d63.valid-move::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    background-color: rgba(16, 185, 129, 0.6);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.square-55d63.capture-move {
    position: relative;
}

.square-55d63.capture-move::after {
    content: '';
    position: absolute;
    width: 90%;
    height: 90%;
    border: 3px solid rgba(239, 68, 68, 0.8);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: none !important;
}

/* Remove all animated indicators completely */
.chess-square.valid-move::after,
.chess-square.capture-move::after,
.chess-square.valid-move::before,
.chess-square.capture-move::before {
    display: none !important;
    content: none !important;
}

/* Keep only static indicators for Chessboard.js */
.square-55d63.valid-move::after,
.square-55d63.capture-move::after {
    animation: none !important;
    transition: none !important;
    transform: translate(-50%, -50%) scale(1) !important;
}

/* Remove any potential animated pseudo-elements */
.square-55d63.valid-move::before,
.square-55d63.capture-move::before {
    display: none !important;
}

.square-55d63.move-from {
    background-color: rgba(251, 191, 36, 0.4) !important;
}

.square-55d63.move-to {
    background-color: rgba(16, 185, 129, 0.4) !important;
}

/* Check and Checkmate Highlighting */
.square-55d63.in-check {
    background-color: rgba(239, 68, 68, 0.5) !important;
    box-shadow: inset 0 0 0 3px rgba(239, 68, 68, 0.8) !important;
    animation: checkPulse 1.5s infinite;
}

.square-55d63.checkmate {
    background-color: rgba(220, 38, 38, 0.7) !important;
    box-shadow: inset 0 0 0 4px rgba(220, 38, 38, 1) !important;
    animation: checkmatePulse 1s infinite;
}

@keyframes checkPulse {
    0% { 
        box-shadow: inset 0 0 0 3px rgba(239, 68, 68, 0.8); 
        background-color: rgba(239, 68, 68, 0.5);
    }
    50% { 
        box-shadow: inset 0 0 0 5px rgba(239, 68, 68, 1); 
        background-color: rgba(239, 68, 68, 0.7);
    }
    100% { 
        box-shadow: inset 0 0 0 3px rgba(239, 68, 68, 0.8); 
        background-color: rgba(239, 68, 68, 0.5);
    }
}

@keyframes checkmatePulse {
    0% { 
        box-shadow: inset 0 0 0 4px rgba(220, 38, 38, 1); 
        background-color: rgba(220, 38, 38, 0.7);
    }
    50% { 
        box-shadow: inset 0 0 0 6px rgba(220, 38, 38, 1); 
        background-color: rgba(220, 38, 38, 0.9);
    }
    100% { 
        box-shadow: inset 0 0 0 4px rgba(220, 38, 38, 1); 
        background-color: rgba(220, 38, 38, 0.7);
    }
}

.chess-square.hint-square::before {
    content: '💡';
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 1rem;
    animation: bounce 1s infinite;
    z-index: 20;
}

/* Animations */
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

@keyframes pieceMove {
    0% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.2) rotate(10deg); }
    100% { transform: scale(1) rotate(0deg); }
}

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

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

/* Sidebar Styles */
.sidebar {
    background: white;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.sidebar-collapsed {
    transform: translateX(-100%);
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        z-index: 50;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
}

/* Navigation Links */
.sidebar nav ul li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    text-decoration: none;
    color: #4b5563;
    font-weight: 500;
}

.sidebar nav ul li a:hover {
    background-color: #f3f4f6;
    color: var(--primary-color);
    transform: translateX(5px);
}

.sidebar nav ul li a.active {
    background-color: #ede9fe;
    color: var(--primary-color);
}

/* Card Styles */
.card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Achievement Badges */
.achievement-badge {
    animation: bounce 2s infinite;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-size: 1.5rem;
}

.achievement-badge.silver {
    background: linear-gradient(135deg, #c0c0c0, #e8e8e8);
}

.achievement-badge.bronze {
    background: linear-gradient(135deg, #cd7f32, #e4a853);
}

/* Button Styles */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: white;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-danger {
    background: var(--error-color);
    color: white;
}

/* Progress Bars */
.progress-bar {
    width: 100%;
    height: 0.5rem;
    background-color: #e5e7eb;
    border-radius: 9999px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    border-radius: 9999px;
    transition: width 0.5s ease;
}

/* Learning Mode Styles */
.learning-mode .chess-square {
    position: relative;
}

.learning-mode .hint-square::before {
    content: '💡';
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 1rem;
    animation: bounce 1s infinite;
}

.learning-assistant {
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-left: 4px solid var(--primary-color);
}

/* Stats Display */
.stat-card {
    background: white;
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.15);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.875rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Notification Styles */
.notification {
    position: fixed;
    top: 5rem;
    right: 1rem;
    z-index: 50;
    padding: 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
    animation: slideIn 0.3s ease;
}

.notification.success {
    background: var(--success-color);
    color: white;
}

.notification.warning {
    background: var(--warning-color);
    color: white;
}

.notification.error {
    background: var(--error-color);
    color: white;
}

.notification.info {
    background: var(--primary-color);
    color: white;
}

/* Modal Styles */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    max-width: 28rem;
    width: 90%;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    animation: slideIn 0.3s ease;
}

/* Responsive Design */
@media (max-width: 640px) {
    .chess-board {
        max-width: 90vw;
        font-size: 1.8rem;
    }
    
    .chess-square {
        font-size: 1.8rem;
    }
    
    .sidebar {
        width: 16rem;
    }
    
    .card {
        margin: 0.5rem;
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Tooltip Styles */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: white;
    padding: 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.tooltip:hover::after {
    opacity: 1;
}

/* Form Styles */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #374151;
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

/* Game Specific Styles */
.game-header {
    background: linear-gradient(135deg, white, #f9fafb);
    border-bottom: 1px solid #e5e7eb;
}

.player-card {
    background: white;
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.player-card.active {
    border: 2px solid var(--primary-color);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
}

.move-history {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
}

.control-button {
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.control-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.control-button:active {
    transform: translateY(0);
}

/* Difficulty Indicators */
.difficulty-beginner { background: linear-gradient(135deg, #10b981, #34d399); }
.difficulty-easy { background: linear-gradient(135deg, #3b82f6, #60a5fa); }
.difficulty-intermediate { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.difficulty-advanced { background: linear-gradient(135deg, #ef4444, #f87171); }
.difficulty-expert { background: linear-gradient(135deg, #8b5cf6, #a78bfa); }
.difficulty-master { background: linear-gradient(135deg, #1f2937, #374151); }

/* Mobile Optimizations */
@media (max-width: 768px) {
    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    .game-header {
        padding: 0.5rem;
    }
    
    .control-button {
        padding: 0.5rem;
        font-size: 0.875rem;
    }
    
    .modal-content {
        margin: 1rem;
        padding: 1.5rem;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus Styles */
.btn:focus,
.form-input:focus,
.control-button:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .chess-square.light {
        background-color: #ffffff;
    }
    
    .chess-square.dark {
        background-color: #000000;
    }
    
    .card {
        border: 2px solid #000000;
    }
}
