:root {
    --bg-color: #2c3e50;
    --board-dark: #7f8c8d;
    --board-light: #ecf0f1;
    --highlight: rgba(241, 196, 15, 0.6);
    --capture: rgba(231, 76, 60, 0.6);
    --special: rgba(52, 152, 219, 0.6);
    --immortal: rgba(142, 68, 173, 0.8);
    --white-piece: #fff;
    --black-piece: #000;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
}

h1 { margin-bottom: 5px; }
.subtitle { color: #bdc3c7; margin-bottom: 20px; font-size: 0.9em; }

.game-container {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Chess Board */
#board {
    display: grid;
    grid-template-columns: repeat(8, 80px);
    grid-template-rows: repeat(8, 80px);
    /* border: 8px solid #34495e; */
    border: 8px solid #333;
    user-select: none;
    box-shadow: 0 15px 30px rgba(0,0,0,0.4);
    height: 100%;
}

.cell {
    width: 80px;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
}

.cell.light { background-color: var(--board-light); }
.cell.dark { background-color: var(--board-dark); }
.cell.selected { background-color: var(--highlight) !important; }
.cell.user-marked-light { background-color: rgba(245, 103, 84, 0.8) !important; }
.cell.user-marked-dark { background-color: rgba(216, 90, 73, 0.8) !important; }

.cell.possible-move::after {
    content: '';
    width: 20px;
    height: 20px;
    background: rgba(0,0,0,0.25);
    border-radius: 50%;
}
.cell.capture { background-color: var(--capture) !important; }
.cell.special-move { background-color: var(--special) !important; }

/* Pieces */
.piece {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
    cursor: grab;
    transition: transform 0.2s;
}

.piece img {
    width: 90%;
    height: 90%;
    object-fit: contain;
    filter: drop-shadow(0 4px 4px rgba(0,0,0,0.4));
}

/* Бейджик уровня */
.lvl-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 12px;
    background: rgba(0,0,0,0.85);
    color: #f1c40f;
    padding: 2px 6px;
    border-radius: 6px;
    pointer-events: none;
    font-weight: bold;
    z-index: 3;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: rgba(0,0,0,0.2);
    padding: 20px;
    border-radius: 8px;
}

.panel {
    background: rgba(255,255,255,0.1);
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 5px;
}

.turn-indicator {
    font-size: 1.4em;
    font-weight: bold;
    margin-bottom: 10px;
}

#timers {
    margin-bottom: 15px;
}

.timer {
    font-size: 1.1em;
    font-weight: bold;
    padding: 8px 12px;
    margin: 5px 0;
    border-radius: 4px;
    text-align: center;
    background: rgba(255,255,255,0.1);
}

.timer.active {
    background: rgba(241, 196, 15, 0.3);
    color: #f1c40f;
    animation: pulse 1s infinite;
}

.timer.low-time {
    background: rgba(231, 76, 60, 0.3);
    color: #e74c3c;
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

/* Puzzle Creator Styles */
.puzzle-creator-container {
    display: flex;
    gap: 30px;
    max-width: 1400px;
    margin: 20px auto;
    flex-wrap: wrap;
}

.puzzle-editor-panel, .puzzle-settings-panel {
    flex: 1;
    min-width: 400px;
    background: rgba(255,255,255,0.1);
    padding: 20px;
    border-radius: 8px;
}

.puzzle-editor-panel h3, .puzzle-settings-panel h3 {
    color: #f1c40f;
    margin-bottom: 20px;
}

.editor-tools {
    margin-bottom: 20px;
}

.tool-group {
    margin-bottom: 15px;
}

.tool-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #f1c40f;
}

.color-selector, .turn-selector {
    display: flex;
    gap: 10px;
}

.color-btn, .turn-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.color-btn.active, .turn-btn.active {
    background: #f1c40f;
    color: #333;
}

.color-btn:not(.active) {
    background: #34495e;
    color: white;
}

.turn-btn:not(.active) {
    background: #34495e;
    color: white;
}

.action-btn {
    padding: 8px 12px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 10px;
    transition: background 0.2s;
}

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

.puzzle-board {
    display: grid;
    grid-template-columns: repeat(8, 50px);
    grid-template-rows: repeat(8, 50px);
    border: 4px solid #34495e;
    margin: 20px auto;
    width: fit-content;
    user-select: none;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
}

.puzzle-board .cell {
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 36px;
    cursor: pointer;
    transition: background 0.2s;
}

.puzzle-board .cell:hover {
    background: rgba(241, 196, 15, 0.3) !important;
}

.piece-selector {
    margin-top: 20px;
}

.piece-selector h4 {
    color: #f1c40f;
    margin-bottom: 10px;
}

.piece-selection {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.piece-selection .piece-option {
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 36px;
    cursor: pointer;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    transition: background 0.2s;
}

.piece-selection .piece-option:hover, .piece-selection .piece-option.selected {
    background: rgba(241, 196, 15, 0.3);
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #f1c40f;
}

.setting-group input, .setting-group textarea, .setting-group select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: rgba(255,255,255,0.9);
    color: #333;
}

.moves-section {
    margin-top: 30px;
}

.moves-section h4 {
    color: #f1c40f;
    margin-bottom: 10px;
}

.moves-list {
    margin-bottom: 15px;
}

.move-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    padding: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

.move-item input {
    flex: 1;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: rgba(255,255,255,0.9);
    color: #333;
}

.move-item .remove-move {
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 4px 8px;
    cursor: pointer;
}

.add-move-btn {
    width: 100%;
    padding: 10px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 30px;
    flex-wrap: wrap;
}

.test-btn, .save-btn, .load-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.test-btn {
    background: #f39c12;
    color: #333;
}

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

.load-btn {
    background: #9b59b6;
    color: white;
}

.puzzle-message {
    margin-top: 20px;
    padding: 10px;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
}

/* Puzzle Solver Styles */
.puzzle-solver-container {
    display: flex;
    gap: 30px;
    max-width: 1400px;
    margin: 20px auto;
    flex-wrap: wrap;
}

.puzzle-board-panel, .puzzle-status-panel {
    flex: 1;
    min-width: 400px;
}

.puzzle-info {
    background: rgba(255,255,255,0.1);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.puzzle-info h3 {
    color: #f1c40f;
    margin-bottom: 10px;
}

.puzzle-info p {
    color: #ecf0f1;
    margin-bottom: 15px;
}

.puzzle-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.difficulty-badge, .theme-badge, .progress-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
}

.difficulty-badge {
    background: #27ae60;
    color: white;
}

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

.progress-badge {
    background: #f39c12;
    color: #333;
}

.puzzle-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.hint-btn, .reset-btn, .next-btn {
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.hint-btn {
    background: #f1c40f;
    color: #333;
}

.reset-btn {
    background: #e74c3c;
    color: white;
}

.next-btn {
    background: #27ae60;
    color: white;
}

.puzzle-status-panel {
    background: rgba(255,255,255,0.1);
    padding: 20px;
    border-radius: 8px;
}

.puzzle-status-panel h3, .puzzle-status-panel h4 {
    color: #f1c40f;
    margin-bottom: 15px;
}

.move-history-section {
    margin-bottom: 30px;
}

.move-history {
    max-height: 200px;
    overflow-y: auto;
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
    padding: 10px;
}

.move-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.move-history-item:last-child {
    border-bottom: none;
}

.move-number {
    font-weight: bold;
    color: #f1c40f;
    min-width: 30px;
}

.move-text {
    flex: 1;
    text-align: center;
}

.status-message {
    padding: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    color: #bdc3c7;
}

.stat-value {
    font-weight: bold;
    color: #f1c40f;
}

.feedback-message {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 15px;
    animation: fadeIn 0.5s;
}

.feedback-icon {
    font-size: 24px;
}

.feedback-text {
    font-weight: bold;
}

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

/* Modal Styles */
.piece-selection-modal {
    max-width: 500px;
}

.modal-piece-selection {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
    margin: 20px 0;
}

.modal-piece-option {
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 36px;
    cursor: pointer;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    transition: background 0.2s;
}

.modal-piece-option:hover {
    background: rgba(241, 196, 15, 0.3);
}

.modal-buttons {
    text-align: right;
    margin-top: 20px;
}

.modal-buttons button {
    padding: 8px 16px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
}

/* Puzzle Complete Modal */
.puzzle-complete-modal {
    max-width: 500px;
    text-align: center;
}

.complete-header {
    margin-bottom: 30px;
}

.complete-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.complete-stats {
    margin-bottom: 30px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.stat-row:last-child {
    border-bottom: none;
}

.complete-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.next-puzzle-btn {
    background: #27ae60;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.close-modal-btn {
    background: #34495e;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 4px;
    cursor: pointer;
}

/* Wrong Move Modal */
.wrong-move-modal {
    max-width: 400px;
    text-align: center;
}

.wrong-header {
    margin-bottom: 20px;
}

.wrong-icon {
    font-size: 48px;
    color: #e74c3c;
    margin-bottom: 10px;
}

.wrong-message {
    margin-bottom: 30px;
    color: #ecf0f1;
}

.wrong-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.continue-btn {
    background: #f39c12;
    color: #333;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.wrong-move-modal .hint-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
}

.log {
    height: 300px;
    overflow-y: auto;
    font-size: 0.9em;
    font-family: monospace;
    border-top: 1px solid rgba(255,255,255,0.2);
    padding-top: 5px;
    display: flex;
    flex-direction: column-reverse;
}

/* Modal */
#modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 100;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #fff;
    color: #333;
    padding: 30px;
    border-radius: 12px;
    max-width: 700px;
    width: 90%;
    text-align: center;
    box-shadow: 0 15px 30px rgba(0,0,0,0.5);
    border: 4px solid #f1c40f;
}

.modal-options {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.modal-card {
    border: 2px solid #ddd;
    padding: 15px;
    border-radius: 8px;
    cursor: pointer;
    width: 150px;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-card:hover {
    background: #fffdf0;
    transform: translateY(-5px);
    border-color: #f1c40f;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.modal-card img {
    width: 60px;
    height: 60px;
    margin-bottom: 10px;
}

.modal-name { font-weight: bold; display: block; margin-bottom: 5px; font-size: 1.1em;}
.modal-desc { font-size: 0.8em; color: #555; line-height: 1.2; }

button.reset-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 10px;
    font-weight: bold;
    font-size: 1.1em;
}

/* Settings icon */
.settings-icon {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 32px;
    height: 32px;
    z-index: 180;
    cursor: pointer;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.sidebar .settings-icon.sidebar-settings-icon {
    position: static;
    margin-left: auto;
    margin-bottom: 4px;
    border: 1px solid rgba(255,255,255,0.2);
}

.settings-icon:hover {
    background: rgba(255,255,255,0.2);
}

.settings-icon svg {
    width: 20px;
    height: 20px;
    fill: white;
}

button.ai-btn-white {
    background: #3ce79a;
    color: white;
    border: none;
    padding: 10px 12px;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 0;
    font-weight: bold;
    font-size: 1em;
}

button.ai-btn-black {
    background: #228659;
    color: white;
    border: none;
    padding: 10px 12px;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 0;
    font-weight: bold;
    font-size: 1em;
}

.ai-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
}

/* Стили для загрузки модов */
.mod-upload-container {
    margin-top: 10px;
    text-align: left;
}
.mod-upload-container input[type="file"] {
    display: none;
}
.mod-upload-label {
    display: inline-block;
    background: #3498db;
    color: white;
    padding: 10px 18px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.2s;
    border-bottom: 3px solid #2980b9;
}
.mod-upload-label:hover {
    background: #2980b9;
}
.mod-upload-label:active {
    transform: translateY(2px);
    border-bottom: none;
}

/* Move Navigation Styles */
.nav-btn {
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    min-width: 40px;
}

.nav-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.2);
    transform: translateY(-1px);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.move-counter {
    color: #f1c40f;
    font-weight: bold;
}

/* Drag and Drop Styles - removed drag-target highlighting */

.piece.draggable {
    cursor: grab !important;
    transition: none;
}

.piece.dragging {
    opacity: 0.8;
    z-index: 1000;
    pointer-events: none;
    position: fixed !important;
    transition: none !important;
    cursor: grabbing !important;
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Move History Styles - Minimalist */
.move-history {
    max-height: 250px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.4;
}

.move-row {
    display: flex;
    align-items: center;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.move-number {
    color: #888;
    font-size: 12px;
    min-width: 20px;
    margin-right: 8px;
    font-weight: bold;
}

.move-white, .move-black {
    flex: 1;
    padding: 3px 6px;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.2s;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.move-white:hover, .move-black:hover {
    background-color: rgba(52, 152, 219, 0.15);
}

.move-white.current, .move-black.current {
    background-color: rgba(52, 152, 219, 0.3);
    color: #fff;
    font-weight: bold;
}

.move-empty {
    cursor: default;
    background-color: transparent;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .game-container {
        gap: 20px;
    }

    #board {
        grid-template-columns: repeat(8, 70px);
        grid-template-rows: repeat(8, 70px);
    }

    .cell {
        width: 70px;
        height: 70px;
    }

    .sidebar {
        width: 280px;
    }
}

@media (max-width: 768px) {
    .game-container {
        flex-direction: column;
        gap: 20px;
        align-items: center;
    }

    #board {
        grid-template-columns: repeat(8, 60px);
        grid-template-rows: repeat(8, 60px);
        border-width: 6px;
    }

    .cell {
        width: 60px;
        height: 60px;
    }

    .sidebar {
        width: 100%;
        max-width: 400px;
    }

    .modal-content {
        max-width: 90%;
    }
}

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

    #board {
        grid-template-columns: repeat(8, 45px);
        grid-template-rows: repeat(8, 45px);
        border-width: 4px;
        box-shadow: 0 8px 16px rgba(0,0,0,0.3);
    }

    .cell {
        width: 45px;
        height: 45px;
    }

    .game-container {
        gap: 15px;
    }

    .sidebar {
        padding: 15px;
    }

    .settings-icon {
        top: 10px;
        right: 10px;
        width: 28px;
        height: 28px;
    }

    .settings-icon svg {
        width: 16px;
        height: 16px;
    }

    h1 {
        font-size: 1.5em;
        margin-bottom: 2px;
    }

    .subtitle {
        font-size: 0.85em;
        margin-bottom: 15px;
    }
}

/* Coordinate labels */
.coordinate-label-dark {
    position: absolute;
    font-size: 18px;
    font-weight: bold;
    color: #808c8d;
    pointer-events: none;
    z-index: 1;
}
.coordinate-label-light {
    position: absolute;
    font-size: 18px;
    font-weight: bold;
    color: #ecf0f1;
    pointer-events: none;
    z-index: 1;
}

.coordinate-letter {
    bottom: 2px;
    right: 2px;
}

.coordinate-number {
    top: 2px;
    left: 2px;
}

/* King in check highlighting */
.piece.king-in-check {
    filter: drop-shadow(0 0 8px rgba(255, 0, 0, 0.8)) drop-shadow(0 0 16px rgba(255, 0, 0, 0.6));
    animation: king-check-pulse 1.5s ease-in-out infinite alternate;
}

@keyframes king-check-pulse {
    0% { filter: drop-shadow(0 0 8px rgba(255, 0, 0, 0.8)) drop-shadow(0 0 16px rgba(255, 0, 0, 0.6)); }
    100% { filter: drop-shadow(0 0 12px rgba(255, 0, 0, 1.0)) drop-shadow(0 0 24px rgba(255, 0, 0, 0.8)); }
}

/* Position Editor Styles */
#position-editor-modal {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#editor-board {
    background: var(--bg-color);
}

.editor-cell {
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    border: 1px solid rgba(255,255,255,0.1);
}

.editor-cell.light {
    background-color: var(--board-light);
}

.editor-cell.dark {
    background-color: var(--board-dark);
}

.editor-cell:hover {
    box-shadow: inset 0 0 0 2px rgba(241, 196, 15, 0.5);
}

.editor-piece {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

.editor-piece img {
    width: 90%;
    height: 90%;
    object-fit: contain;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
}

/* Position Editor Piece Selection */
#piece-selection-panel {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    background: rgba(255,255,255,0.05);
}

.tier-header {
    color: #f1c40f;
    font-size: 14px;
    font-weight: bold;
    margin: 10px 0 5px 0;
    text-align: center;
    border-bottom: 1px solid rgba(241, 196, 15, 0.3);
    padding-bottom: 3px;
}

.tier-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-bottom: 15px;
    justify-content: center;
}

.piece-selection-btn {
    width: 44px;
    height: 44px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
}

.piece-selection-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.05);
    border-color: #f1c40f;
}

.piece-selection-btn[selected] {
    border-color: #f1c40f;
    background: rgba(241, 196, 15, 0.2);
    box-shadow: 0 0 8px rgba(241, 196, 15, 0.4);
}

.piece-selection-btn img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

/* Responsive design for piece selection */
@media (max-width: 768px) {
    #piece-selection-panel {
        max-height: 350px;
    }

    .piece-selection-btn {
        width: 40px;
        height: 40px;
    }

    .piece-selection-btn img {
        width: 28px;
        height: 28px;
    }
}

/* Unified puzzle-like design layer for ec-fe pages */
:root {
    --app-bg: #111;
    --app-bg-soft: #151515;
    --panel-bg: rgba(255, 255, 255, 0.06);
    --panel-bg-hover: rgba(255, 255, 255, 0.1);
    --panel-border: rgba(255, 255, 255, 0.14);
    --text-main: #ececec;
    --text-muted: #9f9f9f;
    --brand-accent: #f1c40f;
    --brand-green: #27ae60;
    --brand-blue: #3498db;
    --brand-red: #e74c3c;
    --glass: rgba(255, 255, 255, 0.08);
    --glass-2: rgba(255, 255, 255, 0.14);
}

body {
    background:
        radial-gradient(circle at 12% 10%, rgba(255, 255, 255, 0.07), transparent 42%),
        radial-gradient(circle at 85% 18%, rgba(241, 196, 15, 0.07), transparent 36%),
        var(--app-bg);
    color: var(--text-main);
}

h1,
h2,
h3,
h4 {
    letter-spacing: 0.01em;
}

.subtitle,
.muted {
    color: var(--text-muted);
}

.sidebar {
    background: var(--app-bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
}

button,
.menu-btn,
.submit-btn,
.save-btn,
.load-btn,
.test-btn,
.add-move-btn,
.action-btn,
.copy-code-btn,
.next-btn,
.hint-btn,
.close-modal-btn,
.continue-btn {
    border: none;
    border-radius: 8px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

button:hover,
.menu-btn:hover,
.submit-btn:hover,
.save-btn:hover,
.load-btn:hover,
.test-btn:hover,
.add-move-btn:hover,
.action-btn:hover,
.copy-code-btn:hover,
.next-btn:hover,
.hint-btn:hover,
.close-modal-btn:hover,
.continue-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
    filter: saturate(1.04);
}

.back-link {
    position: fixed;
    top: 18px;
    left: 18px;
    z-index: 1100;
    color: var(--text-main);
    text-decoration: none;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: 1px solid var(--panel-border);
    background: rgba(0, 0, 0, 0.45);
    border-radius: 999px;
    padding: 8px 14px;
}

.back-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

input,
select,
textarea {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: rgba(241, 196, 15, 0.8);
    box-shadow: 0 0 0 2px rgba(241, 196, 15, 0.22);
}

/* Home page */
body.home-page {
    align-items: stretch;
    padding: 0;
    min-height: 100vh;
}

body.home-page .main-container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 60px 20px 40px;
}

body.home-page .welcome-section {
    text-align: center;
    margin-bottom: 38px;
}

body.home-page .welcome-section h1 {
    position: relative;
    display: inline-block;
    font-size: clamp(2rem, 5vw, 3rem);
    color: var(--text-main);
    margin-bottom: 8px;
}

#typing {
    position: absolute;
    left: 100%;
    white-space: nowrap;
    padding-left: 2px; 
}

body.home-page .typing {
    color: var(--brand-accent);
}

body.home-page .game-modes {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-top: 26px;
}

body.home-page .game-mode-card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 26px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.22s ease, border-color 0.22s ease, background 0.22s ease;
}

body.home-page .game-mode-card:hover {
    transform: translateY(-4px);
    border-color: rgba(241, 196, 15, 0.7);
    background: var(--panel-bg-hover);
}

body.home-page .game-mode-card h2 {
    color: var(--text-main);
    margin-bottom: 10px;
}

body.home-page .game-mode-card p {
    color: var(--text-muted);
    margin: 0;
}

body.home-page .game-mode-card .icon {
    font-size: 2.8rem;
    margin-bottom: 12px;
}

body.home-page .login-prompt {
    max-width: 520px;
    margin: 28px auto 0;
    text-align: center;
    padding: 18px;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
    background: var(--panel-bg);
    font-size: 1.3em;
}

body.home-page .login-prompt a {
    color: var(--brand-accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1em;
}

body.home-page .back-link {
    display: none !important;
}

body.with-static-sidebar {
    padding-left: 264px;
}

body.solve-board-page.with-static-sidebar {
    padding-left: 0;
}

body.sidebar-auth-gated:not(.with-static-sidebar) {
    padding-left: 20px;
}

body.sidebar-auth-gated:not(.with-static-sidebar) .site-sidebar {
    display: none !important;
}

.site-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 232px;
    height: 100vh;
    z-index: 1400;
    background: #151515;
    border-right: 1px solid var(--panel-border);
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.site-sidebar h3 {
    margin: 0;
    color: var(--text-main);
}

.site-sidebar-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    order: 2;
}

.site-nav-link {
    color: var(--text-muted);
    text-decoration: none;
    display: block;
    padding: 9px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
}

.site-nav-link:hover {
    color: var(--text-main);
    background: var(--panel-bg);
    border-color: var(--panel-border);
}

.site-nav-group {
    position: relative;
    padding-right: 8px;
    margin-right: -8px;
}

.site-submenu {
    position: absolute;
    top: 0;
    left: 100%;
    margin-left: 2px;
    min-width: 170px;
    background: #1a1a1a;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-6px);
    transition: opacity 220ms ease, transform 220ms ease;
    transition-delay: 90ms;
    z-index: 1500;
}

.site-nav-group:hover .site-submenu {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
    transition-delay: 0ms;
}

.site-submenu a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    padding: 7px 8px;
}

.site-submenu a:hover {
    color: var(--text-main);
    background: #252525;
}

.site-sidebar-user {
    order: 1;
    margin-top: 0;
    margin-bottom: 0;
    padding: 10px 11px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
}

.site-user-name {
    font-weight: 700;
    color: var(--text-main);
    font-size: 14px;
}

.site-user-elo {
    margin-top: 5px;
    color: #dbc170;
    font-weight: 700;
    font-size: 12px;
}

/* Auth pages */
body.auth-page {
    display: block;
    min-height: 100vh;
    padding: 0;
}

body.auth-page .auth-container {
    max-width: 420px;
    margin: 90px auto 24px;
    background: var(--app-bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
}

body.auth-page .auth-container h1 {
    text-align: center;
    color: var(--text-main);
    margin-bottom: 24px;
}

body.auth-page .form-group {
    margin-bottom: 16px;
}

body.auth-page .form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-main);
    font-weight: 700;
}

body.auth-page .form-group input {
    width: 100%;
    padding: 12px;
    box-sizing: border-box;
}

body.auth-page .submit-btn {
    width: 100%;
    padding: 12px;
    background: var(--brand-blue);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    margin-top: 10px;
}

body.auth-page .submit-btn:hover {
    background: #2f89c3;
}

body.auth-page.register-page .submit-btn {
    background: var(--brand-green);
}

body.auth-page.register-page .submit-btn:hover {
    background: #219150;
}

body.auth-page .link-text {
    text-align: center;
    margin-top: 20px;
    color: var(--text-muted);
}

body.auth-page .link-text a {
    color: var(--brand-accent);
    text-decoration: none;
}

body.auth-page .error-message {
    color: var(--brand-red);
    margin-top: 10px;
    display: none;
}

body.auth-page .back-link {
    position: absolute;
}

/* Friend game page */
body.friend-page .friend-game-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1300;
}

body.friend-page .friend-game-menu.hidden {
    display: none;
}

body.friend-page .friend-menu-content {
    background: var(--app-bg-soft);
    padding: 36px;
    border-radius: 12px;
    text-align: center;
    max-width: 520px;
    width: 92%;
    border: 1px solid var(--panel-border);
}

body.friend-page .friend-menu-content h2 {
    color: var(--text-main);
    margin-bottom: 14px;
}

body.friend-page .friend-menu-content p,
body.friend-page .code-instructions {
    color: var(--text-muted);
}

body.friend-page .menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

body.friend-page .menu-btn {
    padding: 13px 20px;
    background: var(--brand-blue);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
}

body.friend-page .menu-btn.secondary {
    background: #4f5968;
}

body.friend-page .menu-btn.back {
    background: #8d3434;
}

body.friend-page .copy-code-btn {
    background: var(--brand-green);
    margin-top: 8px;
}

body.friend-page .friend-code-display {
    background: rgba(255, 255, 255, 0.04);
    padding: 18px;
    border-radius: 8px;
    margin: 20px 0;
    border: 1px dashed rgba(241, 196, 15, 0.65);
}

body.friend-page .friend-code {
    font-size: 2rem;
    font-weight: 700;
    color: var(--brand-accent);
    letter-spacing: 0.18em;
    font-family: monospace;
    margin: 10px 0;
}

body.friend-page .join-code-input input {
    padding: 12px;
    font-size: 1.1rem;
    text-align: center;
    letter-spacing: 0.16em;
    font-family: monospace;
    width: 220px;
    margin: 10px 0;
}

body.friend-page .buffer-message,
body.friend-page .waiting-message {
    color: var(--brand-accent) !important;
}

/* Rules page */
body.rules-page {
    display: block;
    min-height: 100vh;
    padding: 24px 20px 40px;
}

body.rules-page .main-container {
    width: min(980px, 100%);
    margin: 0 auto;
    background: var(--app-bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 34px 28px;
}

body.rules-page .main {
    color: var(--text-main);
}

body.rules-page .divider {
    height: 1px;
    background: var(--panel-border);
    width: 100%;
    margin: 16px 0 18px;
}

body.rules-page .links {
    color: var(--brand-accent);
    text-decoration: none;
}

body.rules-page h2 {
    color: var(--brand-accent);
}

body.rules-page h3 {
    color: #e3b727;
}

body.rules-page img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
}

/* Generic game page overrides */
body.game-page {
    --site-sidebar-width: 232px;
    --game-sidebar-width: 320px;
    --layout-gap: clamp(12px, 1.8vw, 24px);
    --layout-offset: 0px;
    --status-center-shift: 0px;
}

body.game-page #game-status {
    position: fixed;
    top: 12px;
    left: calc(50% + var(--status-center-shift));
    transform: translateX(-50%);
    width: min(820px, calc(100vw - var(--layout-offset) - 24px));
    max-height: 3.6em;
    overflow-y: auto;
    overflow-wrap: anywhere;
    text-align: center;
    margin: 0;
    color: var(--brand-accent);
    font-weight: 700;
    line-height: 1.3;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid var(--panel-border);
    z-index: 150;
}

body.game-page #piece-info {
    min-height: 88px;
    max-height: 230px;
    overflow-y: auto;
    overflow-wrap: anywhere;
    line-height: 1.35;
    padding: 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

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

.piece-info-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.piece-info-name {
    font-size: 1.15em;
    line-height: 1.2;
}

.piece-info-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.72em;
    font-weight: 700;
    line-height: 1.2;
}

.piece-info-badge-tier {
    background: #f1c40f;
    color: #111;
}

.piece-info-badge-immortal {
    background: #9b59b6;
    color: #fff;
}

.piece-info-description {
    color: #ccc;
}

.piece-info-progress {
    color: #f0f0f0;
}

.piece-info-next {
    color: #aaa;
    font-size: 0.9em;
}

.piece-info-max {
    color: #f1c40f;
    font-weight: 700;
}

.move-history-empty {
    color: #777;
    font-style: italic;
    text-align: center;
    padding: 15px;
    font-size: 12px;
}

.move-navigation {
    display: flex;
    gap: 5px;
    margin: 10px 0;
    justify-content: center;
    align-items: center;
}

.move-navigation .move-counter {
    min-width: 64px;
    text-align: center;
    font-size: 14px;
}

.join-code-field {
    text-transform: uppercase;
}

.game-container.is-hidden {
    display: none !important;
}

/* Common/Online/Friend board layout */
body.solve-board-page {
    background: #111;
    color: #ececec;
    padding: 0;
    align-items: stretch;
    overflow-x: hidden;
}

body.solve-board-page.with-static-sidebar {
    --layout-offset: var(--site-sidebar-width);
    --status-center-shift: calc(var(--site-sidebar-width) / 2);
}

body.solve-board-page #game-title {
    display: none;
}

body.solve-board-page .game-shell {
    min-height: 100vh;
}

body.solve-board-page .game-container {
    --board-size: min(
        calc(100vh - 100px),
        calc(100vw - var(--layout-offset) - var(--game-sidebar-width) - 88px)
    );
    box-sizing: border-box;
    width: calc(100vw - var(--layout-offset));
    min-height: 100vh;
    margin: 0;
    margin-left: var(--layout-offset);
    display: grid;
    grid-template-columns: minmax(8px, 1fr) minmax(280px, var(--board-size)) minmax(8px, 1fr) minmax(250px, var(--game-sidebar-width));
    column-gap: var(--layout-gap);
    align-items: start;
    padding: 70px clamp(10px, 1.6vw, 22px) 16px;
}

body.solve-board-page #board {
    grid-column: 2;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    margin: 0;
    border: none;
    box-shadow: 0 18px 32px rgba(0, 0, 0, 0.35);
    justify-self: center;
    align-self: start;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
}

body.solve-board-page .cell {
    width: auto;
    height: auto;
    aspect-ratio: 1 / 1;
}

body.solve-board-page .sidebar {
    grid-column: 4;
    margin: 0;
    width: min(100%, var(--game-sidebar-width));
    max-height: calc(100vh - 88px);
    border-radius: 12px;
    background: #1b1b1b;
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    justify-self: end;
    align-self: start;
}

body.solve-board-page .sidebar .panel {
    margin: 0;
    background: #222;
    border: 1px solid rgba(255, 255, 255, 0.07);
}

body.solve-board-page .sidebar .reset-btn {
    margin-top: 0;
}

body.solve-board-page .sidebar .mod-upload-container {
    margin-top: 4px;
}

@media (max-width: 1280px) {
    body.game-page {
        --game-sidebar-width: 286px;
    }

    body.home-page .game-modes {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 980px) {
    body.solve-board-page {
        overflow: auto;
        --layout-offset: 0px;
        --status-center-shift: 0px;
    }

    body.solve-board-page .game-container {
        width: 100%;
        margin-left: 0;
        min-height: auto;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        row-gap: 12px;
        padding: 84px 10px 16px;
    }

    body.solve-board-page #board,
    body.solve-board-page .sidebar {
        grid-column: 1;
        justify-self: center;
    }

    body.solve-board-page #board {
        width: min(calc(100vw - 20px), 84vh);
    }

    body.solve-board-page .sidebar {
        width: min(100%, 520px);
        max-height: none;
    }

    body.game-page #game-status {
        width: calc(100vw - 20px);
        top: 70px;
    }
}

@media (max-width: 780px) {
    body.with-static-sidebar {
        padding-left: 20px;
        padding-top: 220px;
    }

    .site-sidebar {
        width: auto;
        height: auto;
        right: 0;
        bottom: auto;
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
    }

    .site-sidebar-links {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .site-nav-group {
        position: static;
    }

    .site-submenu {
        position: static;
        opacity: 1;
        pointer-events: auto;
        transform: none;
        min-width: 0;
        background: transparent;
        border: none;
        padding: 0 0 0 6px;
    }

    body.solve-board-page.with-static-sidebar {
        padding-top: 0;
    }

    body.solve-board-page.with-static-sidebar .game-container {
        padding-top: 248px;
    }

    body.solve-board-page #board {
        width: min(calc(100vw - 16px), 82vh);
    }

    body.game-page #game-status {
        top: 206px;
        max-height: 4.2em;
    }

    body.home-page .main-container {
        padding-top: 80px;
    }

    body.home-page .game-modes {
        grid-template-columns: 1fr;
    }

    body.home-page .user-info-header {
        position: static;
        margin: 0 auto 16px;
    }

    body.auth-page .auth-container {
        margin-top: 110px;
        width: calc(100% - 28px);
        padding: 24px;
    }
}
