/* ============================================
   Puzzle Trainer - Styles
   Adapted from the analysis interface
   ============================================ */

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

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --info-color: #16a085;
    --light-bg: #ecf0f1;
    --dark-bg: #34495e;
    --border-color: #bdc3c7;
    --text-color: #2c3e50;
    --text-light: #7f8c8d;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-color);
}

/* Header */
.header {
    text-align: center;
    color: white;
    margin-bottom: 20px;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    margin-bottom: 5px;
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
}

/* Status */
.status {
    max-width: 1000px;
    margin: 0 auto 20px;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 500;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.status.info { background-color: var(--info-color); color: white; }
.status.success { background-color: var(--success-color); color: white; }
.status.error { background-color: var(--danger-color); color: white; }
.status.warning { background-color: var(--warning-color); color: white; }

/* Level selector */
.level-selector {
    max-width: 800px;
    margin: 0 auto 20px;
    background: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.level-selector h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 20px;
}

.level-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
}

.level-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 30px;
    border: 2px solid var(--secondary-color);
    border-radius: 10px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 140px;
}

.level-btn:hover {
    background: var(--secondary-color);
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

.level-btn .level-number {
    font-size: 1.2rem;
    font-weight: 700;
}

.level-btn .level-count {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 5px;
}

.level-btn:hover .level-count {
    color: rgba(255, 255, 255, 0.9);
}

/* "Mate in ?" button (mystery level): the same button, with a dashed
   border since its level is unknown */
.level-btn.level-btn-mystery {
    border-style: dashed;
}

.no-puzzles {
    color: var(--danger-color);
    font-size: 1rem;
    line-height: 1.8;
}

.no-puzzles code {
    background: var(--light-bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
}

/* Main controls */
.controls {
    max-width: 1000px;
    margin: 0 auto 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.controls button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.controls button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

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

#newPuzzleBtn { background: var(--success-color); color: white; }
#solutionBtn { background: var(--warning-color); color: white; }
#retryBtn { background: var(--secondary-color); color: white; }

/* Main container */
.main-container {
    max-width: 1000px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 20px;
    align-items: start;
}

/* Chessboard wrapper */
.board-wrapper {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 540px;
    max-width: 100%;
    margin: 0 auto;
}

.chess-board {
    width: 100%;
    /* Touch screens: the board handles the finger itself (dragging a piece).
       Without this, the browser turns the gesture into a page scroll and the
       piece never moves. */
    touch-action: none;
}

/* Info panel */
.info-panel {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.section h3 {
    color: var(--primary-color);
    font-size: 1rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background: var(--light-bg);
    border-radius: 5px;
    font-size: 0.9rem;
}

.info-label {
    font-weight: 600;
    color: var(--text-light);
}

.info-value {
    color: var(--text-color);
    font-weight: 500;
}

.info-value.opening {
    font-size: 0.8rem;
    max-width: 180px;
    text-align: right;
}

/* Game message */
.game-message {
    background: var(--light-bg);
    border-radius: 5px;
    padding: 15px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 500;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-message.success {
    background: rgba(39, 174, 96, 0.2);
    color: var(--success-color);
}

.game-message.error {
    background: rgba(231, 76, 60, 0.2);
    color: var(--danger-color);
}

.game-message.info {
    background: rgba(52, 152, 219, 0.2);
    color: var(--secondary-color);
}

/* Lichess link */
.lichess-link {
    display: block;
    padding: 12px;
    background: var(--light-bg);
    border-radius: 5px;
    text-align: center;
    text-decoration: none;
    color: var(--secondary-color);
    font-weight: 500;
    transition: all 0.2s ease;
}

.lichess-link:hover {
    background: var(--secondary-color);
    color: white;
}

/* Mystery level: app.js removes the href until the end of the puzzle,
   since the source game would give the level away. Greyed out, no hover
   effect, and a hint telling when the link comes back */
.lichess-link:not([href]),
.lichess-link:not([href]):hover {
    background: var(--light-bg);
    color: var(--text-light);
    cursor: default;
}

.lichess-link:not([href])::after {
    content: " (after the puzzle)";
}

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

.modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-content h3 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

.promotion-pieces {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.promotion-btn {
    padding: 15px 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.promotion-btn:hover {
    background: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
    transform: scale(1.05);
}

.cancel-btn {
    padding: 10px 30px;
    border: none;
    border-radius: 6px;
    background: var(--text-light);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cancel-btn:hover {
    background: var(--danger-color);
}

/* Footer: white on the gradient, like the header.
   Same max width as .main-container so it lines up with the board. */
.page-footer {
    max-width: 1000px;
    margin: 30px auto 0;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-wrap: anywhere;    /* long URL wraps on narrow screens */
}

/* Links take the text colour: the browser's default blue reads badly
   on the violet. Underline kept so they still look like links. */
.page-footer a {
    color: inherit;
    text-underline-offset: 2px;
}

.page-footer a:hover {
    text-decoration-thickness: 2px;
}

.page-footer a:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
    border-radius: 2px;
}

/* Responsive */
@media (max-width: 900px) {
    .main-container {
        grid-template-columns: 1fr;
    }

    .info-panel {
        order: 2;
    }

    .board-wrapper {
        order: 1;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .header h1 {
        font-size: 1.8rem;
    }

    .controls {
        gap: 5px;
    }

    .controls button {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .level-btn {
        padding: 15px 20px;
        min-width: 120px;
    }

    .promotion-pieces {
        grid-template-columns: repeat(2, 1fr);
    }

    .page-footer {
        margin-top: 20px;
        font-size: 0.8rem;
    }
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--light-bg);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Last move highlight */
.highlight-move {
    box-shadow: inset 0 0 0 4px rgba(255, 255, 0, 0.5) !important;
}

/* Opponent move highlight */
.highlight-opponent {
    box-shadow: inset 0 0 0 4px rgba(52, 152, 219, 0.5) !important;
}

/* Piece selected by a tap (or a click), waiting for its destination */
.highlight-selected {
    box-shadow: inset 0 0 0 4px rgba(46, 204, 113, 0.6) !important;
}
