/**
 * Game Component Styles for AIML Games Framework
 *
 * Generic UI components that can be used across all game types.
 * Includes hint systems, refresh/reshuffle buttons, mode indicators,
 * loading states, and other common game UI elements.
 *
 * @package AIML_Games_Framework
 */

/* ============================================
 * Hint System
 * ============================================ */

.aiml-games-hint-btn {
    padding: 6px 12px;
    font-size: 0.9em;
    background-color: #17a2b8;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
    min-width: 80px;
}

.aiml-games-hint-btn:hover {
    background-color: #138496;
}

.aiml-games-hint-btn:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

.aiml-games-hint {
    font-size: 0.9em;
    color: #666;
    font-style: italic;
    display: none;
    padding: 8px;
    background-color: #fff3cd;
    border-radius: 4px;
    min-width: 500px;
    /*border-left: 4px solid #ffc107;*/
}

.aiml-games-hint.aiml-games-visible {
    display: block;
}

/* ============================================
 * Refresh/Reshuffle Button
 * ============================================ */

.aiml-games-refresh-icon {
    cursor: pointer;
    font-size: 14px;
    opacity: 0.4;
    filter: grayscale(100%);
    transition: all 0.2s ease;
    user-select: none;
    display: inline-block;
}

.aiml-games-refresh-icon:hover {
    opacity: 0.8;
    filter: grayscale(0%);
    transform: rotate(180deg);
}

.aiml-games-refresh-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.aiml-games-refresh-btn:hover {
    transform: rotate(180deg);
}

/* ============================================
 * Game Area Loading State
 * ============================================ */

.aiml-games-game-area.is-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.aiml-games-game-area.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #0073aa;
    border-radius: 50%;
    animation: aiml-games-spin 1s linear infinite;
}

/* ============================================
 * Word/Item Row (for games with multiple items)
 * ============================================ */

.aiml-games-word-row {
    display: grid;
    grid-template-columns: 30px 1fr 1fr 100px;
    gap: 15px;
    align-items: center;
    margin: 10px 0;
    padding: 10px;
    background-color: #f9f9f9;
    border-radius: 5px;
    min-width: 650px;
}

.aiml-games-word-index {
    font-weight: bold;
    color: #666;
    text-align: center;
    font-size: 1.1em;
}

.aiml-games-scrambled-word {
    font-size: 1.2em;
    font-weight: bold;
    color: #333;
    text-align: center;
    padding: 8px;
    background-color: #e9ecef;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.aiml-games-scrambled-text {
    flex-grow: 1;
}

.aiml-games-word-row input[type="text"] {
    padding: 8px;
    font-size: 1em;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 100%;
}

/* ============================================
 * Answer Feedback Styles
 * ============================================ */

.aiml-games-answer-correct {
    background-color: #d4edda !important;
    border-color: #28a745 !important;
    color: #155724 !important;
}

.aiml-games-answer-incorrect {
    background-color: #f8d7da !important;
    border-color: #dc3545 !important;
    color: #721c24 !important;
}

.aiml-games-answer-unanswered {
    background-color: #fff3cd !important;
    border-color: #ffc107 !important;
    color: #856404 !important;
}

/* ============================================
 * Game Ended State
 * ============================================ */

.aiml-game-ended {
    opacity: 0.95;
}

.aiml-game-ended .aiml-game-click-button {
    opacity: 0.7;
    cursor: not-allowed;
}

/* ============================================
 * Game Over Modal
 * ============================================ */

.aiml-game-over-modal .aiml-games-modal-content,
.aiml-game-over-modal-fallback .aiml-games-modal-content {
    max-width: 300px !important;
    width: 90% !important;
    padding: 20px;
    text-align: center;
}

/* ============================================
 * Right-Positioned Button (for Game Set progression)
 * ============================================ */

.aiml-games-btn-right {
    float: right;
    margin-left: auto;
    clear: both;
}

/* Ensure the button container clears floats properly */
.aiml-game-buttons::after {
    content: '';
    display: table;
    clear: both;
}

.aiml-game-over-modal .aiml-game-over-content,
.aiml-game-over-modal-fallback .aiml-game-over-content {
    font-size: 14px;
    color: #666;
}

/* ============================================
 * Error/Info Messages
 * ============================================ */

.aiml-games-error {
    padding: 15px;
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 5px;
    margin: 20px 0;
}

.aiml-games-info {
    padding: 15px;
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
    border-radius: 5px;
    margin: 20px 0;
}

.aiml-games-warning {
    padding: 15px;
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
    border-radius: 5px;
    margin: 20px 0;
}

/* ============================================
 * Share Section
 * ============================================ */

.aiml-games-share-section {
    margin-top: 15px;
    text-align: center;
}

/* ============================================
 * Score Summary Component
 * ============================================ */

.aiml-games-score-summary {
    max-width: 100%;
    margin: 20px auto;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    clear: both;
}

.aiml-games-score-summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #dee2e6;
}

.aiml-games-score-summary-title {
    margin: 0;
    font-size: 1.4em;
    color: #28a745;
    font-weight: 600;
}

.aiml-games-score-summary-mode {
    font-size: 0.9em;
    color: #6c757d;
    display: flex;
    align-items: center;
    gap: 10px;
}

.aiml-games-score-summary-time {
    background-color: #e9ecef;
    padding: 4px 10px;
    border-radius: 15px;
    font-weight: 500;
}

.aiml-games-score-summary-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(135deg, #0073aa 0%, #005177 100%);
    border-radius: 8px;
    margin-bottom: 20px;
}

.aiml-games-score-summary-total-label {
    font-size: 1.1em;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.aiml-games-score-summary-total-value {
    font-size: 2em;
    color: #fff;
    font-weight: 700;
}

.aiml-games-score-summary-breakdown {
    margin-bottom: 20px;
}

.aiml-games-score-summary-breakdown-title {
    margin: 0 0 12px 0;
    font-size: 1em;
    color: #495057;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.aiml-games-score-summary-table {
    width: 100%;
    border-collapse: collapse;
}

.aiml-games-score-summary-table tbody tr {
    border-bottom: 1px solid #e9ecef;
}

.aiml-games-score-summary-table tbody tr:last-child {
    border-bottom: none;
}

.aiml-games-score-summary-item td {
    padding: 12px 8px;
    vertical-align: middle;
}

.aiml-games-score-summary-item-icon {
    width: 40px;
    text-align: center;
}

.aiml-games-score-summary-icon {
    font-size: 1.2em;
}

.aiml-games-score-summary-item-label {
    font-weight: 500;
    color: #343a40;
}

.aiml-games-score-summary-item-detail {
    display: block;
    font-size: 0.85em;
    color: #6c757d;
    font-weight: 400;
    margin-top: 2px;
}

.aiml-games-score-summary-item-total {
    text-align: right;
    font-weight: 600;
    font-size: 1.1em;
    white-space: nowrap;
}

/* Score type colors */
.aiml-games-score-positive {
    color: #28a745;
}

.aiml-games-score-negative {
    color: #dc3545;
}

.aiml-games-score-bonus {
    color: #fd7e14;
}

/* Item type row styling */
.aiml-games-score-summary-item--positive {
    background-color: rgba(40, 167, 69, 0.03);
}

.aiml-games-score-summary-item--negative {
    background-color: rgba(220, 53, 69, 0.03);
}

.aiml-games-score-summary-item--bonus {
    background-color: rgba(253, 126, 20, 0.05);
}

/* Stats section */
.aiml-games-score-summary-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding-top: 15px;
    border-top: 1px solid #dee2e6;
}

.aiml-games-score-summary-stat {
    flex: 1;
    min-width: 100px;
    text-align: center;
    padding: 10px 15px;
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.aiml-games-score-summary-stat-label {
    display: block;
    font-size: 0.8em;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    overflow-wrap: break-word;
    word-break: break-word;
}

.aiml-games-score-summary-stat-value {
    display: block;
    font-size: 1.3em;
    font-weight: 600;
    color: #343a40;
}

.aiml-games-score-summary-rank {
    color: #ffc107;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Responsive adjustments for score summary */
@media (max-width: 768px) {
    .aiml-games-score-summary {
        padding: 15px;
    }

    .aiml-games-score-summary-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .aiml-games-score-summary-total {
        flex-direction: column;
        text-align: center;
        gap: 5px;
    }

    .aiml-games-score-summary-total-value {
        font-size: 1.8em;
    }

    .aiml-games-score-summary-stats {
        flex-direction: column;
    }

    .aiml-games-score-summary-stat {
        min-width: unset;
    }
}

/* ============================================
 * Standalone Leaderboard Styles
 * ============================================ */

.aiml-games-leaderboard-standalone {
    margin: 20px auto;
    max-width: 800px;
}

.aiml-games-leaderboard-standalone h3 {
    margin-bottom: 15px;
    color: #333;
    text-align: center;
}

/* ============================================
 * Responsive Design
 * ============================================ */

@media (max-width: 1024px) and (min-width: 769px) {
    .aiml-games-word-row {
        grid-template-columns: 30px 1.2fr 1.2fr 100px;
        min-width: 550px;
    }
}

@media (max-width: 768px) {
    .aiml-games-word-row {
        grid-template-columns: 30px 1fr;
        gap: 10px;
        min-width: unset;
    }

    .aiml-games-scrambled-word {
        text-align: left;
    }

    .aiml-games-hint-btn {
        justify-self: start;
        width: auto;
    }
}

/* ============================================
 * Native Dialog Element Styles
 * ============================================ */

/* Game container must be positioned for dialog containment */
.aiml-games-container {
    position: relative;
}

/* Backdrop overlay for contained dialogs (replaces native ::backdrop which only works with showModal) */
.aiml-games-dialog-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99;
    display: none;
}

.aiml-games-dialog-backdrop.visible,
.aiml-games-dialog-backdrop[style*="display: block"],
.aiml-games-dialog-backdrop:not([style*="display: none"]) {
    /* Shown via inline style */
}

/* Base dialog styling - contained within game container */
.aiml-games-dialog {
    position: absolute;
    max-width: 450px;
    width: 90%;
    max-height: 80vh;
    padding: 0;
    border: none;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    background: #fff;
    overflow: hidden;
    z-index: 100;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
}

/* Dialog backdrop (semi-transparent overlay) - only works with showModal() */
.aiml-games-dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.5);
}

/* Fallback for browsers without ::backdrop support */
.aiml-games-dialog + .backdrop {
    background-color: rgba(0, 0, 0, 0.5);
}

/* Dialog content wrapper — the card centered inside the modal backdrop */
.aiml-games-dialog-content {
    display: flex;
    flex-direction: column;
    max-height: 90%;
    width: 100%;
    max-width: 450px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.aiml-games-start-dialog, .aiml-games-start-dialog .aiml-games-dialog-content {
    max-width:100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    border-radius: 5px;
}

/* Dialog header */
.aiml-games-dialog-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid #e9ecef;
    background: linear-gradient(135deg, #0073aa 0%, #005177 100%);
}

.aiml-games-dialog-title {
    margin: 0;
    font-size: 1.2em;
    font-weight: 600;
    color: #fff;
    line-height: 1.3;
}

/* Dialog body */
.aiml-games-dialog-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Dialog instructions section */
.aiml-games-dialog-instructions {
    margin-bottom: 16px;
    overflow-y: scroll;
}

.aiml-games-dialog-instructions h4 {
    margin: 0 0 8px 0;
    font-size: 0.95em;
    color: #343a40;
}

.aiml-games-dialog-instructions ul {
    margin: 0;
    padding-left: 18px;
}

.aiml-games-dialog-instructions li {
    margin-bottom: 4px;
    color: #495057;
    font-size: 0.9em;
}

/* Mode selection styling - compact horizontal layout */
.aiml-games-mode-selection {
    margin: 0;
    padding-top: 12px;
    border-top: 1px solid #e9ecef;
}

.aiml-games-mode-selection h4 {
    margin: 0 0 10px 0;
    font-size: 0.9em;
    color: #343a40;
}

.aiml-games-mode-options {
    display: flex;
    flex-direction: row;
    gap: 10px;
}

.aiml-games-mode-option {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 10px 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.aiml-games-mode-option:hover {
    border-color: #0073aa;
    background-color: rgba(0, 115, 170, 0.03);
}

.aiml-games-mode-option input[type="radio"] {
    margin: 0 0 6px 0;
}

.aiml-games-mode-option input[type="radio"]:checked + strong {
    color: #0073aa;
}

.aiml-games-mode-option:has(input[type="radio"]:checked) {
    border-color: #0073aa;
    background-color: rgba(0, 115, 170, 0.05);
}

.aiml-games-mode-option strong {
    font-size: 0.9em;
    color: #343a40;
    margin-bottom: 4px;
    display: block;
}

.aiml-games-mode-description {
    font-size: 0.75em;
    color: #6c757d;
    margin-bottom: 0;
}

.aiml-games-mode-option small {
    font-size: 0.7em;
    color: #6c757d;
    line-height: 1.3;
    display: none; /* Hide detailed description for compact view */
}

/* Mode locked info */
.aiml-games-mode-locked-info {
    padding: 10px 14px;
    background-color: #e7f3ff;
    border-radius: 8px;
    border-left: 4px solid #0073aa;
}

.aiml-games-mode-locked-message {
    margin: 0;
    font-size: 0.85em;
    color: #343a40;
}

.aiml-games-mode-locked-info small {
    display: block;
    color: #6c757d;
    margin-top: 4px;
}

/* Dialog footer */
.aiml-games-dialog-footer {
    padding: 12px 20px 16px;
    border-top: 1px solid #e9ecef;
    background-color: #f8f9fa;
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* Game Over dialog specific styles */
.aiml-games-game-over-dialog {
    max-width: 320px;
}

.aiml-games-game-over-dialog .aiml-games-dialog-header {
    background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
}

.aiml-games-final-score {
    text-align: center;
    padding: 16px 0;
}

.aiml-games-final-score-value {
    font-size: 2.5em;
    font-weight: 700;
    color: #28a745;
}

.aiml-games-final-score-label {
    display: block;
    font-size: 0.85em;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.aiml-games-game-over-content {
    text-align: center;
    font-size: 0.9em;
    color: #495057;
}

.aiml-games-congratulations {
    font-size: 1.2em;
    font-weight: 600;
    color: #28a745;
    margin: 12px 0;
}

/* Dialog buttons */
.aiml-games-btn {
    padding: 10px 24px;
    font-size: 0.9em;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.aiml-games-btn-primary {
    background-color: #0073aa;
    color: #fff;
}

.aiml-games-btn-primary:hover {
    background-color: #005177;
}

.aiml-games-btn-secondary {
    background-color: #6c757d;
    color: #fff;
}

.aiml-games-btn-secondary:hover {
    background-color: #545b62;
}

/* Dialog animations */
.aiml-games-dialog[open] {
    animation: aiml-dialog-fade-in 0.2s ease-out;
}

.aiml-games-dialog.closing {
    animation: aiml-dialog-fade-out 0.15s ease-in;
}

@keyframes aiml-dialog-fade-in {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes aiml-dialog-fade-out {
    from {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
}

/* Responsive dialog styles */
@media (max-width: 768px) {
    .aiml-games-dialog {
        max-width: 95%;
        width: 95%;
    }

    .aiml-games-dialog-header {
        padding: 14px 16px 10px;
    }

    .aiml-games-dialog-title {
        font-size: 1.1em;
    }

    .aiml-games-dialog-body {
        padding: 14px 16px;
    }

    .aiml-games-dialog-footer {
        padding: 10px 16px 14px;
    }

    .aiml-games-btn {
        padding: 8px 20px;
    }

    .aiml-games-mode-options {
        flex-direction: column;
    }

    .aiml-games-mode-option {
        flex-direction: row;
        text-align: left;
        padding: 8px 10px;
    }

    .aiml-games-mode-option input[type="radio"] {
        margin: 0 8px 0 0;
    }
}

/* Score Summary Container */
.aiml-games-score-summary-container {
    max-width: 100%;
    margin: 20px auto;
    clear: both;
}

/* Scoring Details (collapsible) */
.aiml-games-scoring-details {
    margin: 12px 0;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #f8f9fa;
}

.aiml-games-scoring-details summary {
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    color: #495057;
    user-select: none;
    list-style: none;
}

.aiml-games-scoring-details summary::-webkit-details-marker {
    display: none;
}

.aiml-games-scoring-details summary::before {
    content: '▸ ';
    display: inline-block;
    transition: transform 0.2s ease;
}

.aiml-games-scoring-details[open] summary::before {
    content: '▾ ';
}

.aiml-games-scoring-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.aiml-games-scoring-table tr {
    border-bottom: 1px solid #e9ecef;
}

.aiml-games-scoring-table tr:last-child {
    border-bottom: none;
}

.aiml-games-scoring-table td {
    padding: 8px 14px;
}

.aiml-games-scoring-table td:first-child {
    color: #495057;
    font-weight: 500;
}

.aiml-games-scoring-table td.positive {
    color: #198754;
    font-weight: 600;
    text-align: right;
}

.aiml-games-scoring-table td.bonus {
    color: #0d6efd;
    font-weight: 600;
    text-align: right;
}

.aiml-games-scoring-table td.penalty {
    color: #dc3545;
    font-weight: 600;
    text-align: right;
}

.aiml-games-scoring-table td.multiplier {
    color: #6f42c1;
    font-weight: 600;
    text-align: right;
}

.aiml-games-scoring-table td.count {
    color: #495057;
    font-weight: 600;
    text-align: right;
}

.aiml-games-scoring-table td.disabled {
    color: #6c757d;
    font-weight: 600;
    font-style: italic;
    text-align: right;
}

.aiml-games-page-scoring-details {
    margin: 10px 0;
}

@media (max-width: 768px) {
    .aiml-games-scoring-table td {
        padding: 6px 10px;
        font-size: 0.85em;
    }
}
