/* ============================================================
   デザイントークン
   将棋会館の対局室のような、静かな夜の木目の中に朱の印(手番・王手)が灯るイメージ。
   ============================================================ */
: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;
  --piece-ink-gote: #241a0d;
  --accent: #b6392a;
  --accent-soft: rgba(182, 57, 42, 0.18);
  --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: 1180px;
  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;
}

.difficulty {
  font-size: 13px;
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.difficulty select {
  background: var(--panel);
  color: var(--ink-cream);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--font-body);
  font-size: 13px;
}

.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: 620px;
  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-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: var(--accent-soft);
  border: 1.5px solid var(--accent);
}
.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); }

/* 将棋の駒: 五角形(clip-path)で本物の駒の形を再現するのがこのUIの署名要素 */
.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;
}
.piece-shape.gote { transform: rotate(180deg); }
.piece-shape .label {
  transform: rotate(0deg);
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--piece-ink);
  line-height: 1;
  text-align: center;
  white-space: pre;
}
.piece-shape.gote .label { transform: rotate(180deg); }
.piece-shape.promoted .label { color: var(--accent); }
.piece-shape.king .label { font-weight: 700; }

.thinking {
  position: absolute;
  left: 50%;
  bottom: -30px;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--ink-dim);
}
.dots span { animation: blink 1.4s infinite; opacity: 0; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 20% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- 棋譜パネル ---------- */
.log-panel {
  grid-area: log;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 14px;
  max-height: 640px;
  overflow-y: auto;
}
.log-panel h2 {
  font-family: var(--font-display);
  font-size: 15px;
  margin: 0 0 10px;
  color: var(--ink-cream);
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 8px;
}
.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); }

/* ---------- モーダル ---------- */
.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: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "board"
      "log";
  }
  .log-panel { max-height: 240px; }
  .board { grid-template-columns: repeat(9, minmax(30px, 42px)); grid-template-rows: repeat(9, minmax(30px, 42px)); }
}

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

@media (prefers-reduced-motion: reduce) {
  .dots span { animation: none; opacity: 1; }
  .btn { transition: none; }
}
