body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.game-container {
    text-align: center;
    max-width: 780px;
}

.game-area {
    background: #faf6ee;
    padding: 26px;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
    position: relative;
}

h1 {
    color: var(--primary-color);
    margin: 0;
}

.status {
    font-size: 1.18rem;
    margin-bottom: 14px;
    font-weight: 800;
    color: #3a2414;
    min-height: 1.6em;
}

/* ── Board ─────────────────────────────────────────────── */

.shogi-board-wrapper {
    --cell-size: clamp(34px, 8.4vw, 56px);
    display: inline-block;
    position: relative;
    margin: 0 auto;
    padding-left: 20px;
}

.shogi-rank-labels {
    position: absolute;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    height: calc(var(--cell-size) * 9);
}

.shogi-rank-labels .label {
    width: 16px;
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    color: #7a6048;
    font-weight: 700;
}

.shogi-file-labels {
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    margin-left: 0;
}

.shogi-file-labels .label {
    text-align: center;
    font-size: 0.72rem;
    color: #7a6048;
    font-weight: 700;
    padding-top: 3px;
}

.shogi-board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    grid-template-rows: repeat(9, var(--cell-size));
    width: calc(var(--cell-size) * 9);
    height: calc(var(--cell-size) * 9);
    border: 4px solid #6b3f1f;
    border-radius: 6px;
    overflow: hidden;
    background:
        repeating-linear-gradient(
            to right,
            rgba(93, 58, 26, 0.55) 0px,
            rgba(93, 58, 26, 0.55) 1px,
            transparent 1px,
            transparent var(--cell-size)
        ),
        repeating-linear-gradient(
            to bottom,
            rgba(93, 58, 26, 0.55) 0px,
            rgba(93, 58, 26, 0.55) 1px,
            transparent 1px,
            transparent var(--cell-size)
        ),
        linear-gradient(180deg, #f0d58c 0%, #e8c874 100%);
    box-shadow: 0 6px 18px rgba(65, 37, 15, 0.3);
}

/* Star points (hoshi marks) via pseudo-element on individual cells */
.shogi-cell.hoshi::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #5d3a1a;
    top: -4px;
    left: -4px;
    z-index: 1;
    pointer-events: none;
}

/* ── Cells ─────────────────────────────────────────────── */

.shogi-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    cursor: default;
    z-index: 2;
    border: none;
    background: transparent;
    padding: 0;
    outline: none;
}

.shogi-cell.selected {
    background: rgba(255, 224, 102, 0.5);
    box-shadow: inset 0 0 0 3px #f1c40f;
}

.shogi-cell.last-move {
    background: rgba(255, 245, 136, 0.38);
}

.shogi-cell.in-check {
    background: radial-gradient(circle, rgba(231, 76, 60, 0.55), rgba(231, 76, 60, 0.18) 48%, transparent 72%);
}

.shogi-cell.has-piece {
    cursor: pointer;
}

.shogi-cell.has-piece:hover .shogi-piece {
    transform: translateY(-1px) scale(1.04);
}

.shogi-cell.valid-move,
.shogi-cell.valid-capture {
    cursor: pointer;
}

.shogi-cell.valid-move::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(46, 204, 113, 0.72);
    box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.2);
    z-index: 4;
}

.shogi-cell.valid-capture::before {
    content: '';
    position: absolute;
    width: calc(var(--cell-size) - 10px);
    height: calc(var(--cell-size) - 10px);
    border-radius: 4px;
    border: 3px solid rgba(231, 76, 60, 0.82);
    z-index: 4;
    pointer-events: none;
}

.shogi-cell.valid-drop::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(41, 128, 185, 0.65);
    box-shadow: 0 0 0 3px rgba(41, 128, 185, 0.2);
    z-index: 4;
}

/* ── Pieces ─────────────────────────────────────────────── */

.shogi-piece {
    width: calc(var(--cell-size) - 8px);
    height: calc(var(--cell-size) - 6px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Noto Serif CJK JP", "Yu Mincho", "MS Mincho", "Hiragino Mincho Pro", Georgia, serif;
    font-size: clamp(1.1rem, 4.8vw, 1.85rem);
    font-weight: 900;
    line-height: 1;
    clip-path: polygon(12% 10%, 50% 0%, 88% 10%, 96% 100%, 4% 100%);
    background: linear-gradient(180deg, #fff7df 0%, #f0ddb5 50%, #dfc48e 100%);
    border: none;
    box-shadow: 1px 2px 4px rgba(0, 0, 0, 0.22);
    transition: transform 0.12s ease;
    z-index: 3;
    color: #1a1a1a;
}

.shogi-piece.sente-piece {
    color: #1a1a1a;
}

.shogi-piece.gote-piece {
    transform: rotate(180deg);
    color: #8b0000;
}

.shogi-piece.promoted {
    color: #c0392b;
}

.shogi-piece.gote-piece.promoted {
    color: #c0392b;
}

/* Keyboard focus on cells */
.shogi-cell:focus-visible {
    box-shadow: inset 0 0 0 3px var(--focus-ring-color, #6d5efc);
    z-index: 5;
}

/* ── Hand sections ─────────────────────────────────────── */

.hand-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 8px 0;
    min-height: 38px;
    flex-wrap: wrap;
}

.hand-label {
    font-size: 0.86rem;
    color: #73543a;
    font-weight: 700;
    white-space: nowrap;
}

.hand-pieces {
    display: inline-flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.hand-piece-btn {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 4px 7px;
    border: 2px solid #c8aa78;
    border-radius: 6px;
    background: #faf0da;
    cursor: pointer;
    font-family: "Noto Serif CJK JP", "Yu Mincho", "MS Mincho", Georgia, serif;
    font-size: 1.05rem;
    font-weight: 900;
    color: #1a1a1a;
    min-width: var(--touch-target-min, 44px);
    min-height: 34px;
    transition: background 0.12s, border-color 0.12s;
    line-height: 1;
}

.hand-piece-btn.gote-hand {
    color: #8b0000;
}

.hand-piece-btn:hover {
    background: #f5e2b8;
    border-color: #a8884e;
}

.hand-piece-btn.selected {
    background: rgba(255, 224, 102, 0.6);
    border-color: #f1c40f;
    box-shadow: 0 0 0 2px rgba(241, 196, 15, 0.4);
}

.hand-piece-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.hand-piece-btn:focus-visible {
    box-shadow: var(--focus-ring);
}

.hand-piece-count {
    font-size: 0.74rem;
    color: #7a6048;
    font-family: system-ui, sans-serif;
    font-weight: 700;
}

.hand-empty {
    font-size: 0.82rem;
    color: #b5a08a;
    font-style: italic;
}

/* ── Move history ──────────────────────────────────────── */

.move-history {
    margin: 15px auto 0;
    border: 1px solid rgba(107, 63, 31, 0.24);
    border-radius: 8px;
    overflow: hidden;
    text-align: left;
    max-width: 560px;
    background: #fdfaf4;
}

.move-history-header {
    background: #f0dbb2;
    padding: 8px 12px;
    font-weight: 800;
    font-size: 0.86rem;
    color: #5b351b;
    border-bottom: 1px solid rgba(107, 63, 31, 0.18);
}

.move-list {
    max-height: 150px;
    overflow-y: auto;
    padding: 8px 12px;
    font-family: "Consolas", "Courier New", monospace;
    font-size: 0.84rem;
}

.move-row {
    display: grid;
    grid-template-columns: 38px 1fr 1fr;
    gap: 10px;
    padding: 2px 0;
}

.move-number {
    color: #9b7a55;
    text-align: right;
}

.move-sente {
    color: #1a1a1a;
    font-weight: 700;
}

.move-gote {
    color: #8b0000;
    font-weight: 700;
}

/* ── AI difficulty toggle ──────────────────────────────── */

.ai-difficulty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.difficulty-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: #5b351b;
}

.difficulty-toggle {
    display: flex;
    border-radius: 20px;
    overflow: hidden;
    border: 2px solid #9b7a55;
}

.diff-btn {
    padding: 5px 16px;
    border: none;
    background: #fff3d6;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 800;
    color: #5b351b;
    transition: background 0.15s, color 0.15s;
}

.diff-btn.active {
    background: #7b3f1d;
    color: #fff;
}

.diff-btn:hover:not(.active) {
    background: #f1d29b;
}

/* ── Promotion dialog ──────────────────────────────────── */

.promotion-dialog {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: 12px;
}

.promotion-dialog.hidden {
    display: none;
}

.promotion-dialog-content {
    background: #fffbf2;
    border-radius: 14px;
    padding: 28px 36px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    max-width: 300px;
}

.promotion-question {
    font-size: 1.1rem;
    font-weight: 800;
    color: #3a2414;
    margin: 0 0 16px;
}

.promotion-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.promotion-char {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 56px;
    clip-path: polygon(12% 10%, 50% 0%, 88% 10%, 96% 100%, 4% 100%);
    background: linear-gradient(180deg, #fff7df 0%, #f0ddb5 50%, #dfc48e 100%);
    font-family: "Noto Serif CJK JP", "Yu Mincho", "MS Mincho", Georgia, serif;
    font-weight: 900;
    color: #1a1a1a;
}

.promotion-char.promoted-char {
    color: #c0392b;
}

.promotion-arrow {
    font-size: 1.4rem;
    color: #9b7a55;
}

.promotion-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.promote-btn {
    padding: 10px 22px;
    border: 2px solid #9b7a55;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.promote-yes {
    background: #c0392b;
    color: #fff;
    border-color: #a0301f;
}

.promote-yes:hover {
    background: #e74c3c;
}

.promote-no {
    background: #fff3d6;
    color: #5b351b;
}

.promote-no:hover {
    background: #f1d29b;
}

/* ── Game buttons ──────────────────────────────────────── */

.game-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

#exit-game-btn {
    padding: 10px 20px;
    font-size: 1rem;
}

/* ── Online info ───────────────────────────────────────── */

.online-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 15px;
}

.opponent-name {
    font-weight: 700;
    color: var(--text-muted, #666);
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 540px) {
    .game-container {
        max-width: 100%;
    }

    .game-area {
        padding: 14px 8px;
    }

    .shogi-board-wrapper {
        --cell-size: clamp(30px, 9.6vw, 42px);
        padding-left: 16px;
    }

    .shogi-board {
        border-width: 3px;
    }

    .shogi-cell.valid-move::before,
    .shogi-cell.valid-drop::before {
        width: 11px;
        height: 11px;
    }

    .move-list {
        font-size: 0.76rem;
    }

    .hand-piece-btn {
        font-size: 0.92rem;
        padding: 3px 5px;
        min-width: 38px;
        min-height: 30px;
    }

    .promotion-dialog-content {
        padding: 20px 22px;
    }

    .promotion-preview {
        font-size: 1.4rem;
    }

    .promotion-char {
        width: 42px;
        height: 46px;
    }
}

/* ── Reduced motion ────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .shogi-piece,
    .shogi-cell,
    .hand-piece-btn,
    .diff-btn,
    .promote-btn {
        transition: none !important;
        animation: none !important;
    }

    .shogi-cell.has-piece:hover .shogi-piece {
        transform: none;
    }

    .shogi-piece.gote-piece {
        transform: rotate(180deg);
    }
}
