/* Othello Game Stylesheet - Responsive */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Segoe UI', 'Meiryo', sans-serif;
    background: #1a1a2e;
    color: #eee;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}
.container { text-align: center; width: 100%; max-width: 480px; padding: 0 8px; }
h1 { margin-bottom: 16px; font-size: 32px; letter-spacing: 0.1em; }
.controls {
    margin-bottom: 12px;
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}
.controls .label { margin-right: 4px; font-size: 15px; color: #aaa; }
.controls button {
    padding: 6px 18px;
    border: 2px solid #444;
    background: #2a2a4a;
    color: #ccc;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
}
.controls button:hover { background: #3a3a6a; color: #fff; }
.controls button.active {
    border-color: #4CAF50;
    background: #2e4a2e;
    color: #fff;
}
.info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 10px 12px;
    background: #2a2a4a;
    border-radius: 6px;
    width: 100%;
}
.scores { display: flex; gap: 28px; font-size: 17px; }
.scores span { display: flex; align-items: center; gap: 6px; }
.disc-icon {
    width: 18px; height: 18px;
    border-radius: 50%;
    display: inline-block;
}
.disc-icon.black { background: #222; border: 2px solid #666; }
.disc-icon.white { background: #eee; border: 2px solid #bbb; }
#status { font-size: 15px; color: #aaa; }
#status.thinking { color: #ffcc00; }
.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    width: 100%;
    max-width: 460px;
    gap: 2px;
    background: #111;
    padding: 2px;
    border-radius: 4px;
    border: 3px solid #333;
}
.cell {
    aspect-ratio: 1;
    background: #2d8a4e;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
}
.cell:hover { background: #35a55c; }
.cell.valid::after {
    content: '';
    width: 30%; height: 30%;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    position: absolute;
}
/* 学習用: いまCOM（白）が打てる場所を破線の枠で示す。
   自分も打てるマスでは、中央の白丸と枠が同時に出て両方わかる。 */
.cell.opp-valid::before {
    content: '';
    position: absolute;
    top: 7%; left: 7%; right: 7%; bottom: 7%;
    border: 2px dashed rgba(255, 150, 80, 0.85);
    border-radius: 4px;
    pointer-events: none;
}
.disc {
    width: 80%; height: 80%;
    border-radius: 50%;
}
.disc.black {
    background: radial-gradient(circle at 35% 35%, #555, #111);
    box-shadow: 1px 2px 4px rgba(0,0,0,0.5);
}
.disc.white {
    background: radial-gradient(circle at 35% 35%, #fff, #ccc);
    box-shadow: 1px 2px 4px rgba(0,0,0,0.3);
}
.disc.flip {
    animation: flipAnim 0.45s ease-in-out;
}
@keyframes flipAnim {
    0%   { transform: rotateY(0deg); }
    50%  { transform: rotateY(90deg); }
    100% { transform: rotateY(0deg); }
}
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    justify-content: center;
    margin-top: 10px;
    font-size: 13px;
    color: #aaa;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-mark {
    width: 18px; height: 18px;
    display: inline-block;
    background: #2d8a4e;
    border-radius: 3px;
    position: relative;
    flex-shrink: 0;
}
.legend-mark.mine::after {
    content: '';
    position: absolute;
    top: 35%; left: 35%;
    width: 30%; height: 30%;
    background: rgba(255, 255, 255, 0.55);
    border-radius: 50%;
}
.legend-mark.opp::before {
    content: '';
    position: absolute;
    top: 7%; left: 7%; right: 7%; bottom: 7%;
    border: 2px dashed rgba(255, 150, 80, 0.85);
    border-radius: 3px;
}
.legend #oppCount { color: #ff9650; }
.game-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 16px;
}
#undoBtn {
    padding: 10px 28px;
    background: #e6a817;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
}
#undoBtn:hover { background: #c89015; }
#newGameBtn {
    padding: 10px 28px;
    background: #4CAF50;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
}
#newGameBtn:hover { background: #45a049; }
@media (max-width: 430px) {
    .container { padding: 0 4px; }
    h1 { font-size: 22px; margin-bottom: 10px; }
    .controls button { padding: 6px 12px; font-size: 13px; }
    .scores { gap: 16px; font-size: 14px; }
    #status { font-size: 13px; }
    #undoBtn, #newGameBtn {
        padding: 10px 20px;
        font-size: 15px;
        min-height: 44px;
    }
}

/* ================================================
   探索の可視化
   ================================================ */
.viz {
    width: 100%;
    max-width: 1100px;
    margin: 28px auto 40px;
    padding: 0 10px;
    text-align: left;
}
.viz h2 { font-size: 20px; margin-bottom: 8px; }
.viz-lead { font-size: 13px; color: #aaa; line-height: 1.7; margin-bottom: 14px; }
.viz-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.viz-label { font-size: 13px; color: #aaa; }
.viz button {
    padding: 6px 14px;
    border: 2px solid #444;
    background: #2a2a4a;
    color: #ccc;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}
.viz button:hover:not(:disabled) { background: #3a3a6a; color: #fff; }
.viz button:disabled { opacity: 0.4; cursor: default; }
.viz button.active { border-color: #4CAF50; background: #2e4a2e; color: #fff; }
.viz-depth { display: inline-flex; gap: 4px; }
.viz-depth button { padding: 6px 12px; }
.viz-msg {
    font-size: 13px;
    color: #ffcc00;
    background: #22223c;
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 12px;
}
.viz-main { display: flex; flex-direction: column; gap: 12px; }
/* (1)盤面と集計は横並び、(2)ツリーはその下。狭い画面では自動で折り返す */
.viz-side { display: flex; flex-direction: row; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.viz-side > .viz-panel:first-child { flex: 1 1 340px; }   /* 調べている盤面 */
.viz-side > .viz-panel:last-child  { flex: 0 1 250px; }   /* 集計は右に詰める */
.viz-panel { background: #22223c; border-radius: 6px; padding: 10px; }
.viz-panel-title { font-size: 12px; color: #8ab; margin-bottom: 8px; }
.viz-info { display: grid; grid-template-columns: auto auto; gap: 3px 8px; font-size: 12px; margin: 8px 0 0; }
.viz-info dt { color: #888; }
.viz-info dd { margin: 0; color: #eee; text-align: right; }
.viz-treebox { min-width: 0; background: #22223c; border-radius: 6px; padding: 10px; }
.viz-tree { overflow: auto; max-height: 520px; padding: 6px 4px 14px; }

/* --- ミニ盤面 --- */
.miniboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 1px;
    background: #111;
    padding: 1px;
    width: 72px;
    margin: 0 auto;
}
.mcell { aspect-ratio: 1; background: #2d8a4e; position: relative; }
.mcell.mb::after, .mcell.mw::after {
    content: '';
    position: absolute;
    top: 12%; left: 12%; right: 12%; bottom: 12%;
    border-radius: 50%;
}
.mcell.mb::after { background: #111; }
.mcell.mw::after { background: #eee; }
.mcell.mhit { background: #d8a62a; }
#vizMini { width: 260px; }

/* --- ツリー --- */
.vnode { display: flex; flex-direction: column; align-items: center; }
.vnode-body {
    position: relative;
    border: 2px solid #555;
    border-radius: 6px;
    padding: 5px 7px;
    background: #2a2a4a;
    text-align: center;
    min-width: 54px;
}
.vnode-body.vmax { border-color: #4a7fb5; }
.vnode-body.vmin { border-color: #b57a4a; }
.vlabel { font-size: 12px; font-weight: 700; color: #ddd; margin-bottom: 3px; }
.vscore { font-size: 12px; color: #777; margin-top: 3px; }
.vscore-done { color: #ffd466; font-weight: 700; }

.vnode-pending { opacity: 0.38; }
.vnode-pending > .vnode-body { background: #23233c; border-color: #3a3a55; }
.vnode-open > .vnode-body { box-shadow: 0 0 0 2px #ffcc00 inset; }
.vnode-leaf > .vnode-body { background: #2e4a2e; }
.vnode-done > .vnode-body { background: #30305a; }
.vnode-cut > .vnode-body { border-style: dashed; border-color: #c25; }
.vnode-cut > .vnode-body .vlabel::after { content: ' ✕'; color: #e66; }
.vnode-current > .vnode-body {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* 親から子へ伸ばす線 */
.vnode-body.has-children::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -14px;
    width: 2px;
    height: 14px;
    background: #567;
}
.vchildren {
    display: flex;
    align-items: flex-start;
    gap: 5px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 2px solid #567;
}
.vchildren > .vnode { position: relative; }
.vchildren > .vnode::before {
    content: '';
    position: absolute;
    left: 50%;
    top: -14px;
    width: 2px;
    height: 14px;
    background: #567;
}

/* --- 凡例 --- */
.viz-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 12px;
    color: #aaa;
    margin-top: 12px;
}
.viz-legend span { display: flex; align-items: center; gap: 5px; }
.vl { width: 14px; height: 14px; border-radius: 3px; border: 2px solid #555; display: inline-block; }
.vl-max { border-color: #4a7fb5; background: #2a2a4a; }
.vl-min { border-color: #b57a4a; background: #2a2a4a; }
.vl-leaf { border-color: #555; background: #2e4a2e; }
.vl-cut { border-color: #c25; border-style: dashed; background: #2a2a4a; }

.viz-player { margin-top: 12px; }
.viz-progress { font-size: 12px; color: #aaa; }
#vizSpeed { width: 110px; }

/* スマートフォン向け：操作部を小さくまとめ、盤面とツリーに画面を使う */
@media (max-width: 760px) {
    .viz { padding: 0 8px; }
    .viz h2 { font-size: 17px; }
    .viz-lead { font-size: 12px; line-height: 1.6; margin-bottom: 10px; }
    .viz-row { gap: 5px; margin-bottom: 6px; }
    .viz button { padding: 9px 10px; font-size: 12px; min-height: 40px; }
    .viz-depth { gap: 3px; }
    .viz-depth button { padding: 9px 0; min-width: 36px; }
    .viz-label { font-size: 12px; }

    /* 操作ボタンは画面に貼り付けて、ツリーを見ながら押せるようにする */
    .viz-player {
        position: sticky;
        top: 0;
        z-index: 5;
        background: #1a1a2e;
        padding: 6px 0;
        margin: 0 0 6px;
        border-bottom: 1px solid #333;
    }
    .viz-player button { flex: 1 1 0; min-width: 0; }
    #vizSpeed { width: 70px; }
    .viz-progress { font-size: 11px; }

    /* 凡例は2列にたたむ */
    .viz-legend {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 3px 8px;
        font-size: 10px;
    }
    .vl { width: 11px; height: 11px; border-width: 2px; }

    .viz-msg { font-size: 12px; padding: 6px 8px; margin-bottom: 8px; }
    .viz-panel { padding: 8px; }
    .viz-info { font-size: 11px; }
    #vizMini { width: min(260px, 66vw); }
    .viz-tree { max-height: 44vh; }
}

/* 可視化セクションを盤の下に置くため、全体を縦並びにする */
body {
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 20px 0 40px;
}

/* 枝刈りで調べなかった手 */
.vnode-body.vskip {
    border-style: dashed;
    border-color: #c25;
    background: #2a1a24;
    opacity: 0.8;
}
.vnode-body.vskip .vlabel { color: #e88; }
.vnode-body.vskip .vscore { color: #c66; font-size: 10px; }
.vnode-body.vskip .vlabel::after { content: ' ✕'; }
.vnode-cut > .vnode-body .vlabel::after { content: ''; }
.vnode-cut > .vnode-body { border-color: #c25; border-style: solid; }
