:root {
    --bg-primary: #0a0a12;
    --bg-secondary: #12121f;
    --bg-tertiary: #1a1a2e;
    --accent-gold: #ffd700;
    --accent-gold-dim: #b8860b;
    --accent-cyan: #00d4ff;
    --accent-magenta: #ff00aa;
    --text-primary: #f0f0f5;
    --text-secondary: #8888aa;
    --board-green: #1a5c3a;
    --board-green-light: #238b57;
    --board-border: #0d3d24;
    --piece-black: #1a1a1a;
    --piece-white: #f5f5f5;
    --glow-gold: 0 0 20px rgba(255, 215, 0, 0.5);
    --glow-cyan: 0 0 20px rgba(0, 212, 255, 0.5);
}

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

body {
    font-family: 'Zen Maru Gothic', sans-serif;
    min-height: 100vh;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* 背景エフェクト */
.bg-effects {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.bg-gradient {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 20% 20%, rgba(255, 215, 0, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse 60% 40% at 80% 80%, rgba(0, 212, 255, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse 100% 80% at 50% 100%, rgba(255, 0, 170, 0.04) 0%, transparent 40%);
}

.grid-lines {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 215, 0, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 215, 0, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    animation: gridMove 20s linear infinite;
}

@keyframes gridMove {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(60px, 60px);
    }
}

.floating-particles {
    position: absolute;
    inset: 0;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--accent-gold);
    border-radius: 50%;
    opacity: 0.3;
    animation: float 15s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0) translateX(0);
        opacity: 0.3;
    }

    25% {
        transform: translateY(-100px) translateX(50px);
        opacity: 0.6;
    }

    50% {
        transform: translateY(-50px) translateX(-30px);
        opacity: 0.4;
    }

    75% {
        transform: translateY(-150px) translateX(20px);
        opacity: 0.5;
    }
}

/* メインコンテナ */
.game-wrapper {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

/* ヘッダー */
.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.8rem, 5vw, 3rem);
    font-weight: 900;
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-cyan) 50%, var(--accent-magenta) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px rgba(255, 215, 0, 0.3);
    letter-spacing: 0.1em;
    margin-bottom: 8px;
}

.game-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    letter-spacing: 0.2em;
    margin-bottom: 10px;
}

.back-link {
    display: inline-block;
    color: var(--accent-cyan);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s;
    border: 1px solid rgba(0, 212, 255, 0.3);
    padding: 5px 15px;
    border-radius: 20px;
}

.back-link:hover {
    background: rgba(0, 212, 255, 0.1);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

/* ゲームコンテナ */
.game-container {
    display: grid;
    grid-template-columns: 350px 1fr 350px;
    /* パネル幅を固定し、中央（ボード）を最大化 */
    gap: 20px;
    align-items: center;
    /* 垂直方向中央揃え */
    max-width: 100%;
    width: 98%;
    height: 85vh;
    /* 画面の高さを有効活用 */
}

@media (max-width: 1200px) {
    .game-container {
        grid-template-columns: 250px 1fr 250px;
    }
}

@media (max-width: 900px) {
    .game-container {
        grid-template-columns: 1fr;
        height: auto;
        gap: 30px;
    }
}

/* プレイヤーパネル */
.player-panel {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: 20px;
    padding: 20px;
    border: 3px solid rgba(255, 215, 0, 0.6);
    /* デフォルトの枠線を強化 */
    width: 100%;
    height: 100%;
    max-height: 80vh;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.player-panel.ai-panel {
    border-color: rgba(0, 212, 255, 0.6);
    /* アテナ様側の枠線も強化 */
}

.player-panel.active {
    border-color: var(--accent-gold);
    box-shadow: var(--glow-gold);
    transform: scale(1.02);
}

.player-panel.ai-panel.active {
    border-color: var(--accent-cyan);
    box-shadow: var(--glow-cyan);
    transform: scale(1.02);
}

.player-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    margin: 0 auto 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.ai-panel .player-avatar {
    width: 160px;
    height: 160px;
}

.player-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.player-avatar::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, var(--accent-gold), var(--accent-cyan), var(--accent-magenta), var(--accent-gold));
    opacity: 0;
    transition: opacity 0.3s;
    z-index: -1;
}

.player-panel.active .player-avatar::before {
    opacity: 1;
    animation: rotateGlow 3s linear infinite;
}

@keyframes rotateGlow {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.human-avatar {
    background: linear-gradient(135deg, #2a2a3a 0%, #1a1a2a 100%);
}

.ai-avatar {
    background: linear-gradient(135deg, #1a2a3a 0%, #0a1a2a 100%);
}

.player-name {
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 5px;
}

.player-color {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.player-score {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.score-piece {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.score-piece.black {
    background: radial-gradient(circle at 30% 30%, #555, var(--piece-black));
}

.score-piece.white {
    background: radial-gradient(circle at 30% 30%, #fff, #ddd);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.score-number {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 900;
}

/* AI思考インジケーター */
.ai-thinking {
    display: none;
    margin-top: 15px;
    padding: 10px;
    background: rgba(0, 212, 255, 0.1);
    border-radius: 10px;
    text-align: center;
}

.ai-thinking.active {
    display: block;
}

.thinking-dots {
    display: inline-flex;
    gap: 4px;
}

.thinking-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent-cyan);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.16s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }
}

/* AIステータス */
.ai-status {
    margin-top: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.ai-status-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 10px;
}

.status-bar {
    margin-bottom: 8px;
}

.status-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    margin-bottom: 4px;
}

.status-bar-track {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.status-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.status-bar.tension .status-bar-fill {
    background: linear-gradient(90deg, #ff6b6b, #ffd93d);
}

.status-bar.mood .status-bar-fill {
    background: linear-gradient(90deg, #6bcb77, #4d96ff);
}

.status-bar.condition .status-bar-fill {
    background: linear-gradient(90deg, #a66cff, #9c27b0);
}

.status-bar.stamina .status-bar-fill {
    background: linear-gradient(90deg, #ffd93d, #ff9f43);
}

.status-bar.focus .status-bar-fill {
    background: linear-gradient(90deg, #00d4ff, #0099cc);
}

/* ボード */
.board-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.board-frame {
    background: linear-gradient(135deg, #2a1a0a 0%, #1a0f05 100%);
    padding: 15px;
    border-radius: 16px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.5),
        inset 0 2px 4px rgba(255, 255, 255, 0.1);
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    /* 隙間を少し広げる */
    background: var(--board-border);
    padding: 4px;
    border-radius: 8px;
    /* ボードサイズを画面高さに合わせて最大化 */
    width: 80vh;
    height: 80vh;
    max-width: 100%;
    aspect-ratio: 1;
}

.cell {
    width: 100%;
    height: 100%;
    background: var(--board-green);
    border: none;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

.cell:hover {
    background: var(--board-green-light);
}

.cell.valid-move {
    cursor: pointer;
}

.cell.valid-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: rgba(255, 215, 0, 0.4);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
    animation: validPulse 1.5s ease-in-out infinite;
}

@keyframes validPulse {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 0.3;
    }
}

/* 石 */
.piece {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80%;
    height: 80%;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transform-style: preserve-3d;
}

.piece-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.piece-side {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    backface-visibility: hidden;
}

.piece-black {
    background: radial-gradient(circle at 30% 30%, #666, #333, #111);
    transform: rotateY(0deg);
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.4),
        inset 0 -3px 6px rgba(0, 0, 0, 0.3),
        inset 0 3px 6px rgba(255, 255, 255, 0.1);
}

.piece-white {
    background: radial-gradient(circle at 30% 30%, #fff, #f0f0f0, #d0d0d0);
    transform: rotateY(180deg);
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.3),
        inset 0 -3px 6px rgba(0, 0, 0, 0.1),
        inset 0 3px 6px rgba(255, 255, 255, 0.5);
}

.piece.black .piece-inner {
    transform: rotateY(0deg);
}

.piece.white .piece-inner {
    transform: rotateY(180deg);
}

.piece.flip-to-white .piece-inner {
    animation: flipToWhite 0.6s ease-in-out forwards;
}

.piece.flip-to-black .piece-inner {
    animation: flipToBlack 0.6s ease-in-out forwards;
}

@keyframes flipToWhite {
    0% {
        transform: rotateY(0deg) scale(1);
    }

    50% {
        transform: rotateY(90deg) scale(1.1) translateZ(10px);
    }

    100% {
        transform: rotateY(180deg) scale(1);
    }
}

@keyframes flipToBlack {
    0% {
        transform: rotateY(180deg) scale(1);
    }

    50% {
        transform: rotateY(90deg) scale(1.1) translateZ(10px);
    }

    100% {
        transform: rotateY(0deg) scale(1);
    }
}

.piece.new-piece {
    animation: dropIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dropIn {
    0% {
        transform: translate(-50%, -200%) scale(0.5);
        opacity: 0;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

/* 最後に置いた場所のハイライト */
.cell.last-move::before {
    background: rgba(255, 215, 0, 0.2);
    border: 2px solid rgba(255, 215, 0, 0.5);
    border-radius: 4px;
}

/* コントロール */
.controls {
    display: flex;
    gap: 15px;
    margin-top: 25px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    font-family: 'Zen Maru Gothic', sans-serif;
    padding: 12px 28px;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
    pointer-events: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-gold-dim) 100%);
    color: #000;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(255, 215, 0, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    border-color: var(--accent-cyan);
    box-shadow: 0 5px 20px rgba(0, 212, 255, 0.3);
}

/* 難易度セレクト */
.difficulty-select {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 15px;
}

.difficulty-select label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.difficulty-select select {
    font-family: 'Zen Maru Gothic', sans-serif;
    padding: 8px 16px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
}

/* ゲームオーバーモーダル */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    padding: 50px;
    border-radius: 24px;
    text-align: center;
    border: 1px solid rgba(255, 215, 0, 0.2);
    box-shadow: 0 30px 100px rgba(0, 0, 0, 0.5);
    animation: modalIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 90%;
}

@keyframes modalIn {
    0% {
        transform: scale(0.8) translateY(50px);
        opacity: 0;
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}

.modal h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    margin-bottom: 15px;
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal p {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.final-scores {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 30px;
}

.final-score-item {
    text-align: center;
}

.final-score-piece {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin: 0 auto 10px;
}

.final-score-piece.black {
    background: radial-gradient(circle at 30% 30%, #555, var(--piece-black));
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.final-score-piece.white {
    background: radial-gradient(circle at 30% 30%, #fff, #ddd);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.final-score-number {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    font-weight: 900;
}

/* ゲーム履歴 */
.game-info {
    margin-top: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.game-info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

/* レスポンシブ */
@media (max-width: 600px) {
    .cell {
        min-width: 38px;
        min-height: 38px;
    }

    .player-panel {
        padding: 15px;
        min-width: 150px;
    }

    .ai-status {
        display: none;
    }
}