/* *******************************************************************
 * Jungle Chess (斗兽棋) - Stylesheet
 * ******************************************************************* */

:root {
    --board-bg: #8B4513;
    --cell-light: #DEB887;
    --cell-dark: #D2691E;
    --water-color: #4169E1;
    --trap-color: #FFD700;
    --den-color: #8B0000;
    --white-piece-border: #FFFFFF;
    --black-piece-border: #1a1a1a;
    --highlight-color: rgba(255, 255, 0, 0.5);
    --valid-move-color: rgba(0, 255, 0, 0.4);
    --selected-color: rgba(255, 165, 0, 0.7);
    --capture-color: rgba(255, 0, 0, 0.5);
    --last-move-color: rgba(100, 149, 237, 0.5);
    --animation-duration: 300ms;
    --toolbar-height: 56px;
}

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

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

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color: #fff;
    max-width: 100vw;
    overflow-x: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    overflow: hidden;
}

header.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: transparent;
    flex-shrink: 0;
    gap: 12px;
    min-height: var(--toolbar-height);
}

header .title {
    font-size: 1.3rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    background: linear-gradient(90deg, #f39c12, #e74c3c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

header .title span {
    display: inline;
}

.toolbar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.turn-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 8px;
}

.turn-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.white-dot {
    background: radial-gradient(circle at 30% 30%, #fff, #ccc);
    border: 2px solid #aaa;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.black-dot {
    background: radial-gradient(circle at 30% 30%, #555, #1a1a1a);
    border: 2px solid #666;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.turn-dot.active {
    transform: scale(1.3);
    animation: pulse 1s ease-in-out infinite;
}

.white-dot.active {
    box-shadow: 0 0 10px 3px rgba(255, 255, 255, 0.6);
}

.black-dot.active {
    box-shadow: 0 0 10px 3px rgba(148, 103, 189, 0.6);
}

@keyframes pulse {
    0%, 100% { transform: scale(1.3); }
    50% { transform: scale(1.5); }
}

.language-selector {
    position: relative;
}

.lang-btn {
    display: flex;
    min-height: 36px;
    height: 36px;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.lang-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.lang-icon {
    font-size: 1rem;
}

.lang-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #2c3e50;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 100;
    min-width: 120px;
}

.lang-dropdown.hidden {
    display: none;
}

.lang-option {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    color: #fff;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.lang-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    height: 36px;
    display: flex;
    background: transparent;
    align-items: center;
    justify-content: center;
}

.btn-icon {
    padding: 8px 10px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1rem;
    min-width: 36px;
    width: 36px;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.25);
}

.board-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 8px;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    width: 100%;
    --available-width: calc(100vw - 132px);
    --available-height: calc(100vh - var(--toolbar-height) - 16px);
}

.captured-pieces {
    width: 100px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
    align-items: flex-start;
    justify-content: flex-start;
    align-self: flex-start;
}

.captured-label {
    font-size: 0.75rem;
    text-align: center;
    color: #bdc3c7;
    line-height: 1.2;
}

.captured-list {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    justify-content: center;
    flex: 1;
    align-content: flex-start;
}

.captured-list .piece {
    font-size: 2.8rem;
}

.board {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 2px;
    background: var(--board-bg);
    padding: 6px;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    transition: transform 0.5s ease;
    width: min(calc(var(--available-height) * 7 / 9), var(--available-width));
    height: min(var(--available-height), calc(var(--available-width) * 9 / 7));
}

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

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

.board.flipped .cell::before {
    transform: rotate(180deg);
}

.cell {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

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

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

.cell.water {
    background: linear-gradient(135deg, #3498db, #2980b9);
    animation: water-wave 2s ease-in-out infinite;
}

@keyframes water-wave {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.cell.trap {
    background-color: var(--trap-color);
}

.cell.trap::before {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    top: 20%;
    left: 20%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238B0000'%3E%3Cpath d='M12 2L1 21h22M12 6l7.53 13H4.47M11 10v4h2v-4m-2 6v2h2v-2'/%3E%3C/svg%3E") center/contain no-repeat;
    opacity: 0.8;
    z-index: 1;
}

.cell.den {
    background: linear-gradient(135deg, #c0392b, #e74c3c);
}

.cell.den::before {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    top: 20%;
    left: 20%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M12 3L2 12h3v9h6v-6h2v6h6v-9h3M12 5.8L18 12v8h-4v-6H10v6H6v-8'/%3E%3C/svg%3E") center/contain no-repeat;
    opacity: 0.9;
    z-index: 1;
}

.cell.valid-move {
    background-color: var(--valid-move-color);
}


.cell.water.valid-move {
    background: var(--valid-move-color) !important;
    animation: none;
}

.cell.selected {
    background-color: var(--selected-color);
    box-shadow: inset 0 0 8px rgba(255, 165, 0, 0.8);
}

.cell.last-move {
    background-color: var(--last-move-color);
}

.cell.capture-move {
    background-color: var(--capture-color);
}

.cell:hover:not(.water) {
    filter: brightness(1.1);
}

.piece {
    font-size: 2.8rem;
    cursor: grab;
    transition: transform var(--animation-duration) ease;
    user-select: none;
    z-index: 10;
    position: relative;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.piece.white {
    border: 2px solid #8B7355;
    border-radius: 50%;
    background: linear-gradient(145deg, #FFF8DC, #F5DEB3, #DEB887);
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.3),
        inset 0 -1px 3px rgba(0, 0, 0, 0.15),
        inset 0 1px 3px rgba(255, 255, 255, 0.8);
    padding: 1px;
}

.piece.black {
    border: 2px solid var(--black-piece-border);
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(100, 100, 100, 0.8), rgba(30, 30, 30, 0.9));
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.4),
        inset 0 -1px 3px rgba(0, 0, 0, 0.3),
        inset 0 1px 3px rgba(255, 255, 255, 0.1);
    padding: 1px;
}

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



.cell::before {
    content: attr(data-coord);
    position: absolute;
    top: 0;
    left: 2px;
    font-size: 1.7rem;
    color: rgba(0, 0, 0, 0.4);
    font-weight: bold;
    z-index: 5;
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #2c3e50, #1a252f);
    padding: 24px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: modal-appear 0.3s ease;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modal-appear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
    color: #f39c12;
}

.modal-content p {
    font-size: 1rem;
    margin-bottom: 16px;
    color: #bdc3c7;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 12px;
}

.modal-header h2 {
    margin-bottom: 0;
}

.modal-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.8rem;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    line-height: 1;
}

.modal-close:hover {
    opacity: 1;
}

.modal-body {
    text-align: left;
}

.modal-footer {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

.settings-modal-content {
    width: 360px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.setting-group label {
    font-weight: 500;
    color: #ecf0f1;
    font-size: 0.9rem;
}

.setting-group select,
.setting-group input[type="range"] {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    padding: 8px;
    border-radius: 5px;
    font-size: 0.9rem;
}

.setting-group select option {
    background: #1a1a2e;
    color: #fff;
}

.setting-group input[type="range"] {
    padding: 0;
    height: 6px;
    cursor: pointer;
}

.rules-modal-content {
    width: 440px;
    max-width: 90vw;
}

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

.rules-section h3 {
    color: #f39c12;
    margin-bottom: 8px;
    font-size: 1rem;
}

.rules-section p,
.rules-section li {
    color: #bdc3c7;
    line-height: 1.5;
    font-size: 0.85rem;
}

.rules-section ul {
    list-style-position: inside;
    padding-left: 8px;
}

.rules-section li {
    margin-bottom: 6px;
}

.legend-pieces {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 8px;
    border-radius: 4px;
}

.legend-item .piece {
    font-size: 1rem;
    cursor: default;
}

.legend-item .piece:hover {
    transform: none;
}

.history-modal-content {
    width: 360px;
}

.history-list {
    max-height: 280px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.history-list .move-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 0.8rem;
}

.history-list .move-item.white {
    color: #f1c40f;
}

.history-list .move-item.black {
    color: #9b59b6;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #f39c12;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

@media (max-width: 768px) {
    :root {
        --toolbar-height: 52px;
    }

    header.toolbar {
        padding: 6px 8px;
        flex-wrap: wrap;
    }

    header .title {
        font-size: 1.1rem;
    }

    .toolbar-controls {
        gap: 5px;
        width: 100%;
        justify-content: center;
        order: 3;
    }

    .turn-indicator {
        order: -1;
        margin-right: auto;
        margin-left: 0;
    }

    .btn {
        padding: 5px 8px;
        font-size: 0.7rem;
    }

    .btn-icon {
        padding: 5px 6px;
        font-size: 0.85rem;
    }

    .lang-label {
        display: none;
    }

    .lang-btn {
        padding: 5px 6px;
    }

    .captured-pieces {
        display: none;
    }

    .board-container {
        padding: 6px;
        gap: 4px;
        --available-width: calc(100vw - 12px);
        --available-height: calc(100vh - var(--toolbar-height) - 12px);
    }

    .board {
        width: min(calc(var(--available-height) * 7 / 9), var(--available-width));
        height: min(var(--available-height), calc(var(--available-width) * 9 / 7));
        padding: 4px;
    }

    .piece {
        font-size: 2.3rem;
    }

    .cell::before {
        font-size: 1.1rem;
    }

    .cell.trap::after,
    .cell.den::after {
        font-size: 1rem;
    }

    .modal-content {
        padding: 16px;
    }

    .settings-modal-content,
    .rules-modal-content,
    .history-modal-content {
        width: 94vw;
    }
}

@media (max-width: 480px) {
    :root {
        --toolbar-height: 48px;
    }

    header.toolbar {
        padding: 4px 6px;
    }

    header .title {
        font-size: 1rem;
    }

    .toolbar-controls {
        gap: 4px;
    }

    .btn {
        padding: 4px 6px;
        font-size: 0.65rem;
    }

    .btn-icon {
        padding: 4px 5px;
        font-size: 0.75rem;
    }

    .turn-dot {
        width: 12px;
        height: 12px;
    }

    .board-container {
        padding: 4px;
        --available-width: calc(100vw - 8px);
        --available-height: calc(100vh - var(--toolbar-height) - 8px);
    }

    .board {
        width: min(calc(var(--available-height) * 7 / 9), var(--available-width));
        height: min(var(--available-height), calc(var(--available-width) * 9 / 7));
        gap: 1px;
        padding: 3px;
    }

    .piece {
        font-size: 2.1rem;
        border-width: 1px;
    }
}

@media (max-height: 600px) {
    :root {
        --toolbar-height: 48px;
    }

    header.toolbar {
        padding: 4px 10px;
    }

    header .title {
        font-size: 1rem;
    }

    .board-container {
        padding: 4px;
        --available-height: calc(100vh - var(--toolbar-height) - 8px);
    }
}

/* SVG Piece Icons */
.piece svg {
    width: 100%;
    height: 100%;
    display: block;
}

.piece.white svg {
    color: #5D4037;
}

.piece.black svg {
    color: #1a1a1a;
}
/* SVG Piece Icons */
.piece svg {
    width: 100%;
    height: 100%;
    display: block;
}

.piece.white svg {
    color: #5D4037;
}

.piece.black svg {
    color: #2c2c2c;
}

/* Animation styles */
.piece.animating {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    transition: left 300ms ease, top 300ms ease;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
}

.piece.animating svg {
    width: 100%;
    height: 100%;
}





/* Improve black piece contrast */
.piece.black svg {
    color: #000000;
    filter: drop-shadow(0 0 2px rgba(255,255,255,0.5)) 
            drop-shadow(0 0 1px rgba(255,255,255,0.8));
}

/* Proper animation */
.piece.animatineight: 100% !important;
}
