/* ============================================================
   style.css (v3)
   - 先後選択モーダル
   - 駒移動アニメーション
   - last-from（指し手の元マス）ハイライト
   - KIF コピーボタン
   - その他 v2 継承
   ============================================================ */
:root {
  --bg: #16130f;
  --bg-vignette: #201a12;
  --board-light: #e7c07f;
  --board-dark: #cf9f56;
  --board-line: #6b4423;
  --frame: #3a2a18;
  --frame-shadow: #0b0906;
  --piece-face: #f4e8d0;
  --piece-face-edge: #d8c399;
  --piece-ink: #241a0d;
  --accent: #b6392a;
  --accent-soft: rgba(182, 57, 42, 0.18);
  --accent-dim: rgba(182, 57, 42, 0.09);
  --ink-cream: #efe4cc;
  --ink-dim: #a99b86;
  --panel: #211b13;
  --panel-border: #4a3a25;
  --font-display: 'Shippori Mincho', serif;
  --font-body: 'Zen Kaku Gothic New', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-vignette) 0%, var(--bg) 60%);
  color: var(--ink-cream);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
  display: grid;
  grid-template-columns: 1fr 240px;
  grid-template-areas: "top top" "board log";
  gap: 18px 24px;
}

/* ---------- ヘッダー ---------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--panel-border);
}

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.06em;
  margin: 0;
  color: var(--ink-cream);
}
.logo span { color: var(--accent); font-style: normal; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.move-counter {
  font-family: var(--font-display); font-size: 13px;
  color: var(--ink-dim); padding: 4px 10px;
  border: 1px solid var(--panel-border); border-radius: 6px;
}
.move-counter span { color: var(--ink-cream); font-weight: 700; }

.btn {
  background: var(--accent); color: #fff2ea; border: none;
  border-radius: 6px; padding: 8px 16px; font-family: var(--font-body);
  font-weight: 700; font-size: 13px; letter-spacing: 0.03em;
  cursor: pointer; transition: filter 0.15s ease, transform 0.1s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent; color: var(--ink-dim);
  border: 1px solid var(--panel-border);
}
.btn-ghost:hover { color: var(--ink-cream); border-color: var(--ink-dim); }

/* ---------- 盤エリア ---------- */
.board-area {
  grid-area: board;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}

.side-panel {
  width: 100%; max-width: 660px;
  display: flex; align-items: center; gap: 14px;
}
.side-panel--top { flex-direction: row; }
.side-panel--bottom { flex-direction: row; }

.player-tag {
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
  white-space: nowrap; display: flex; align-items: center; gap: 8px;
  color: var(--ink-cream);
}
.status-pill {
  font-family: var(--font-body); font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: transparent;
  color: var(--ink-dim); border: 1px solid var(--panel-border); min-width: 12px;
}
.status-pill.turn { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.status-pill.check { background: var(--accent); color: #fff; border-color: var(--accent); }

.hand {
  flex: 1; min-height: 52px; background: var(--panel);
  border: 1px solid var(--panel-border); border-radius: 8px;
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; flex-wrap: wrap;
}

.hand-piece {
  position: relative; width: 40px; height: 44px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.hand-piece.selected .piece-shape { outline: 2px solid var(--accent); outline-offset: 2px; }
.hand-piece .count {
  position: absolute; bottom: -4px; right: -4px;
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 999px; padding: 1px 5px; line-height: 1.3;
}
.hand-empty { color: var(--ink-dim); font-size: 12px; padding: 0 4px; }

/* ---------- 座標 + 評価バー ---------- */
.board-with-coords { display: flex; align-items: stretch; gap: 6px; }

.coord-files {
  display: flex; justify-content: space-around;
  padding: 0 14px 0 30px;
  font-family: var(--font-display); font-size: 11px;
  color: var(--ink-dim); max-width: 660px; width: 100%;
}
.coord-ranks {
  display: flex; flex-direction: column; justify-content: space-around;
  padding: 14px 0; font-family: var(--font-display); font-size: 11px;
  color: var(--ink-dim); width: 16px; flex-shrink: 0; text-align: center;
}

.eval-bar-wrap {
  width: 10px; flex-shrink: 0; border-radius: 4px; overflow: hidden;
  background: var(--accent); border: 1px solid var(--panel-border); position: relative;
}
.eval-bar-sente {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--ink-cream); transition: height 0.4s ease; height: 50%;
}

/* ---------- 盤面 ---------- */
.board-wrap {
  position: relative; padding: 14px;
  background: linear-gradient(180deg, var(--frame), #2a1d10);
  border-radius: 10px;
  box-shadow: 0 18px 40px -12px var(--frame-shadow), 0 0 0 1px #000;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(38px, 56px));
  grid-template-rows: repeat(9, minmax(38px, 56px));
  background: linear-gradient(135deg, var(--board-light), var(--board-dark));
  border: 2px solid var(--board-line);
}

.cell {
  position: relative; border: 1px solid var(--board-line);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.cell.highlight::after {
  content: ""; position: absolute; inset: 6px; border-radius: 50%;
  background: rgba(182, 57, 42, 0.25); border: 2px solid var(--accent);
  pointer-events: none;
}
.cell.selected { box-shadow: inset 0 0 0 3px var(--accent); }
.cell.last-move { box-shadow: inset 0 0 0 2px rgba(182,57,42,0.55); }
/* 前手の出発マス（薄めに） */
.cell.last-from { background: rgba(182,57,42,0.10); }

/* 将棋の駒 */
.piece-shape {
  width: 84%; height: 90%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--piece-face), var(--piece-face-edge));
  clip-path: polygon(50% 0%, 92% 22%, 100% 100%, 0% 100%, 8% 22%);
  box-shadow: 0 2px 3px rgba(0,0,0,0.35); user-select: none;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.piece-shape.gote { transform: rotate(180deg); }
.piece-shape .label {
  font-family: var(--font-display); font-weight: 700;
  color: var(--piece-ink); line-height: 1; text-align: center; white-space: pre;
}
.piece-shape.promoted .label { color: var(--accent); }
.piece-shape.king .label { font-weight: 700; }

/* ---------- 棋譜パネル ---------- */
.log-panel {
  grid-area: log; background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 14px; max-height: 680px; overflow-y: auto;
}
.log-panel h2 {
  font-family: var(--font-display); font-size: 15px; margin: 0 0 8px;
  color: var(--ink-cream); border-bottom: 1px solid var(--panel-border); padding-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.move-log {
  margin: 0; padding: 0 0 0 20px; font-size: 13px;
  color: var(--ink-dim); line-height: 1.9;
}
.move-log li::marker { color: var(--ink-dim); font-size: 11px; }
.move-log li.mine { color: var(--ink-cream); }

.btn-kif {
  background: transparent; color: var(--ink-dim);
  border: 1px solid var(--panel-border); border-radius: 4px;
  padding: 2px 8px; font-size: 11px; font-family: var(--font-body); cursor: pointer;
  flex-shrink: 0;
}
.btn-kif:hover { color: var(--ink-cream); border-color: var(--ink-dim); }

/* ---------- モーダル（共通） ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(10, 8, 5, 0.72);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 24px 28px; text-align: center; min-width: 260px;
}
.modal-card p {
  font-family: var(--font-display); font-size: 17px; margin: 0 0 16px;
  color: var(--ink-cream); white-space: pre-line;
}
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- レスポンシブ ---------- */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "board" "log";
  }
  .log-panel { max-height: 200px; }
  .board {
    grid-template-columns: repeat(9, minmax(28px, 40px));
    grid-template-rows: repeat(9, minmax(28px, 40px));
  }
  .hand-piece { width: 34px; height: 38px; }
  .coord-files { font-size: 9px; }
  .coord-ranks { font-size: 9px; width: 12px; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .eval-bar-sente { transition: none; }
  .piece-shape { transition: none; }
}
