/* Shogi board styles */

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    max-width: 700px;
    margin: 0 auto;
    touch-action: manipulation;  /* Prevent double-tap zoom */
    -webkit-tap-highlight-color: transparent;
}

/* Board area: hands + board in a row */
.board-area {
    display: flex;
    align-items: stretch;
    gap: 6px;
    position: relative;
}

/* Board wrapper with file/rank labels */
.board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.file-labels {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    width: var(--board-size, min(80vw, 450px));
    text-align: center;
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 2px;
}

.board-with-ranks {
    display: flex;
    align-items: stretch;
}

.rank-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    margin-left: 4px;
    font-size: 0.75rem;
    color: #888;
}

/* The 9x9 board - wooden texture */
.shogi-board {
    --board-size: min(80vw, 450px);
    width: var(--board-size);
    height: var(--board-size);
    display: grid;
    touch-action: none;  /* Prevent scroll/zoom on board */
    -webkit-user-select: none;
    user-select: none;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    background:
        /* Wood grain */
        repeating-linear-gradient(
            88deg,
            transparent 0px,
            transparent 12px,
            rgba(139, 100, 40, 0.06) 12px,
            rgba(139, 100, 40, 0.06) 14px
        ),
        repeating-linear-gradient(
            92deg,
            transparent 0px,
            transparent 20px,
            rgba(120, 80, 30, 0.04) 20px,
            rgba(120, 80, 30, 0.04) 22px
        ),
        /* Base gradient */
        linear-gradient(180deg, #e8c870 0%, #dcb85c 30%, #d4a840 70%, #c89830 100%);
    border: 4px solid var(--theme-board-border, #8b6914);
    border-top-color: var(--theme-board-border, #a07820);
    border-left-color: var(--theme-board-border, #a07820);
    border-right-color: var(--theme-board-border, #705010);
    border-bottom-color: var(--theme-board-border, #705010);
    box-shadow:
        0 6px 20px rgba(0, 0, 0, 0.5),
        inset 0 1px 3px rgba(255, 255, 200, 0.2),
        inset 0 -1px 3px rgba(0, 0, 0, 0.1);
}

.cell {
    border: 1px solid var(--theme-cell-border, #b8941f);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
    aspect-ratio: 1;
    min-width: 0;
    min-height: 0;
    -webkit-tap-highlight-color: transparent;
}

.cell:hover {
    background: #e8c96a;
}

/* Active tap feedback for mobile */
.cell:active {
    background: #d4a840;
}

/* Selected cell */
.cell.selected {
    background: #4CAF50 !important;
}

/* Legal move destination */
.cell.legal-target {
    background: #a8d5a2;
}

.cell.legal-target:hover {
    background: #7bc673;
}

/* Last move highlight */
.cell.last-move {
    background: #d4a843;
}

/* Check highlight */
.cell.in-check {
    background: #ff6b6b !important;
}

/* Piece display - realistic koma style */
.piece {
    font-family: 'Noto Serif JP', serif;
    font-weight: 700;
    font-size: calc(var(--board-size, 450px) / 20);
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
    width: 82%;
    height: 88%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Pentagon koma shape - Premium lacquered wood */
.piece::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        /* Lacquer sheen */
        radial-gradient(ellipse at 35% 25%, rgba(255,250,230,0.35) 0%, transparent 50%),
        /* Rich aged wood gradient */
        linear-gradient(170deg,
            #f5e8c8 0%,
            #ecd8a0 10%,
            #ddc488 25%,
            #d0b574 45%,
            #c5a560 65%,
            #ba9850 80%,
            #a88840 100%
        );
    clip-path: polygon(50% 1%, 96% 20%, 96% 99%, 4% 99%, 4% 20%);
    z-index: 0;
    filter: drop-shadow(0px 4px 3px rgba(0,0,0,0.55))
            drop-shadow(0px 1px 1px rgba(0,0,0,0.3))
            drop-shadow(1px 0px 1px rgba(0,0,0,0.15));
}

/* Inner bevel highlight + premium wood grain texture */
.piece::after {
    content: '';
    position: absolute;
    inset: 0;
    clip-path: polygon(50% 1%, 96% 20%, 96% 99%, 4% 99%, 4% 20%);
    background:
        /* Top-edge chamfer highlight */
        linear-gradient(160deg,
            rgba(255,255,245,0.55) 0%,
            rgba(255,252,230,0.2) 15%,
            transparent 35%,
            transparent 70%,
            rgba(0,0,0,0.12) 88%,
            rgba(0,0,0,0.22) 100%
        ),
        /* Fine wood grain */
        repeating-linear-gradient(
            177deg,
            transparent 0px,
            transparent 2.5px,
            rgba(120, 75, 30, 0.08) 2.5px,
            rgba(120, 75, 30, 0.08) 3.2px
        ),
        repeating-linear-gradient(
            174deg,
            transparent 0px,
            transparent 7px,
            rgba(90, 55, 20, 0.06) 7px,
            rgba(90, 55, 20, 0.06) 8px
        ),
        /* Subtle knot pattern */
        radial-gradient(ellipse at 60% 70%, rgba(100,60,20,0.06) 0%, transparent 30%);
    z-index: 1;
    pointer-events: none;
}

/* Edge outline for koma definition */
.piece {
    filter: drop-shadow(0 0 0.5px rgba(80,50,10,0.4));
}

.piece span {
    position: relative;
    z-index: 2;
}

.piece.sente {
    color: #0a0500;
    text-shadow:
        0.5px 0.5px 0px rgba(0,0,0,0.25),
        0 0 2px rgba(60, 30, 10, 0.15);
}

.piece.gote {
    color: #0a0500;
    transform: rotate(180deg);
    text-shadow:
        0.5px 0.5px 0px rgba(0,0,0,0.25),
        0 0 2px rgba(60, 30, 10, 0.15);
}

.piece.promoted span {
    color: #8b0000;
    text-shadow:
        0.5px 0.5px 0px rgba(100,0,0,0.3),
        0 0 3px rgba(180, 0, 0, 0.15);
}

.piece.gote.promoted span {
    color: #8b0000;
}

/* King/Gyoku piece - premium aged boxwood */
.piece.king::before {
    background:
        radial-gradient(ellipse at 30% 20%, rgba(255,250,235,0.4) 0%, transparent 45%),
        linear-gradient(170deg, #f9eed8 0%, #ecdbb0 25%, #dcc898 55%, #ccb480 100%);
}

/* Hand (captured pieces) area - vertical beside board */
.hand-area {
    background: #2a2a4a;
    border-radius: 6px;
    padding: 6px 8px;
    min-width: 44px;
    display: flex;
    flex-direction: column;
}

.hand-vertical {
    align-self: stretch;
}

/* Gote hand: top-left (align to top) */
.hand-top {
    order: 0;
    justify-content: flex-start;
}

/* Sente hand: bottom-right (align to bottom) */
.hand-bottom {
    order: 2;
    justify-content: flex-end;
}

.board-wrapper {
    order: 1;
}

.hand-label {
    font-size: 0.7rem;
    color: #888;
    margin-bottom: 4px;
    text-align: center;
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: 2px;
    align-self: center;
    margin-bottom: 8px;
}

.hand-pieces {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.hand-piece {
    font-family: 'Noto Serif JP', serif;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
    background: #3a3a5a;
    color: #e0e0e0;
    user-select: none;
}

.hand-piece:hover {
    background: #4a4a6a;
}

.hand-piece.selected {
    background: #4CAF50;
    color: #fff;
}

.hand-piece .count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e94560;
    color: #fff;
    font-size: 0.6rem;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Move list */
.move-list {
    width: var(--board-size, min(80vw, 450px));
    background: #2a2a4a;
    border-radius: 6px;
    max-height: 200px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.move-list-header {
    font-size: 0.8rem;
    color: #888;
    padding: 6px 10px;
    border-bottom: 1px solid #3a3a5a;
}

.move-list-body {
    padding: 6px 10px;
    overflow-y: auto;
    font-size: 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.move-entry {
    padding: 2px 6px;
    border-radius: 3px;
    white-space: nowrap;
}

.move-entry:nth-child(odd) {
    background: #3a3a5a;
}

.move-entry.current {
    background: #e94560;
    color: #fff;
}

/* Status bar */
.game-status {
    width: var(--board-size, min(80vw, 450px));
    text-align: center;
    padding: 8px;
    font-size: 0.9rem;
    color: #e94560;
    font-weight: bold;
}

/* Mobile: hands go above/below board */
@media (max-width: 500px) {
    .board-area {
        flex-direction: column;
        align-items: center;
    }

    .hand-vertical {
        flex-direction: row;
        min-width: unset;
        width: var(--board-size, min(80vw, 450px));
    }

    .hand-label {
        writing-mode: horizontal-tb;
        text-orientation: mixed;
        letter-spacing: normal;
        margin-bottom: 0;
        margin-right: 8px;
    }

    .hand-pieces {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .hand-top { order: 0; }
    .board-wrapper { order: 1; }
    .hand-bottom { order: 2; }
}

/* Board flip (view from gote side) */
.shogi-board.flipped {
    transform: rotate(180deg);
}

.shogi-board.flipped .piece span {
    /* Counter-rotate text so it stays readable */
}

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

.shogi-board.flipped .piece.gote {
    transform: rotate(0deg);
}
