* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: #f3ede1;
  color: #2b2b2b;
}

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  text-align: center;
}

h1 { font-size: 20px; margin: 8px 0 12px; }

.controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.controls label {
  display: flex;
  align-items: center;
  gap: 4px;
}
.controls select, .controls button {
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid #b89b6e;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.controls button:hover { background: #f6efe0; }
.controls button:disabled {
  opacity: 0.45;
  cursor: default;
}

.sfen-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 13px;
  color: #6b5a3e;
}
.sfen-input {
  flex: 1 1 320px;
  max-width: 440px;
  min-width: 200px;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid #b89b6e;
  border-radius: 4px;
  font-family: monospace;
}
.sfen-bar button {
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid #b89b6e;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.sfen-bar button:hover { background: #f6efe0; }

.status {
  min-height: 22px;
  font-size: 15px;
  font-weight: bold;
  margin: 8px 0;
  color: #7a3b2e;
}

.eval-panel {
  width: 100%;
  max-width: 520px;
  margin: 8px auto 10px;
  padding: 8px;
  background: #fffaf0;
  border: 1px solid #d4bd8f;
  border-radius: 6px;
  text-align: left;
}
.eval-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.eval-title {
  font-size: 12px;
  color: #6b5a3e;
}
.eval-value {
  min-width: 56px;
  font-size: 18px;
  font-weight: bold;
  color: #6b4f2a;
  font-variant-numeric: tabular-nums;
}
.eval-value.sente { color: #2f6f3e; }
.eval-value.gote { color: #8f2d2d; }
.eval-label {
  font-size: 13px;
  color: #4d4332;
}
.eval-graph {
  display: block;
  width: 100%;
  height: 96px;
  border: 1px solid #e0cca3;
  border-radius: 4px;
  background: #fffaf0;
}
.eval-breakdown {
  margin-top: 8px;
  font-size: 12px;
  color: #6b5a3e;
}
.eval-breakdown > summary {
  cursor: pointer;
  font-weight: bold;
  color: #6b4f2a;
  padding: 2px 0;
}
.eval-breakdown-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
}
.eval-breakdown-table td {
  padding: 2px 6px;
  border-bottom: 1px solid #f0e6cf;
}
.eval-bd-label { color: #6b5a3e; }
.eval-bd-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: bold;
  white-space: nowrap;
}
.eval-bd-value.sente { color: #2f6f3e; }
.eval-bd-value.gote { color: #8f2d2d; }
.eval-bd-total td {
  border-top: 2px solid #d4bd8f;
  border-bottom: none;
  font-size: 13px;
  padding-top: 4px;
}
.eval-bd-total .eval-bd-label { font-weight: bold; color: #4d4332; }

/* 検討中バナー（思考中＝操作できないことを伝える） */
.busy-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 14px;
  background: #4d4332;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.busy-banner.show { display: flex; }
.busy-spinner {
  width: 16px; height: 16px;
  border: 3px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: busy-spin 0.8s linear infinite;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }
.busy-stop {
  font-size: 13px;
  font-weight: bold;
  padding: 4px 14px;
  border: 1px solid #fff;
  border-radius: 4px;
  background: #8f2d2d;
  color: #fff;
  cursor: pointer;
}
.busy-stop:hover { background: #a83636; }
/* 検討中は対局エリアを薄暗くして操作できないことを示す（検討パネルは明るいまま） */
.app.analyzing .controls,
.app.analyzing .sfen-bar,
.app.analyzing .board-wrap,
.app.analyzing .hand,
.app.analyzing .kifu-panel {
  opacity: 0.5;
  pointer-events: none;
  cursor: progress;
}

/* 検討 */
.hidden { display: none !important; }
.analysis-panel {
  width: 100%;
  max-width: 520px;
  margin: 0 auto 10px;
  padding: 8px;
  background: #fffaf0;
  border: 1px solid #d4bd8f;
  border-radius: 6px;
  text-align: left;
}
.analysis-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.analysis-head {
  font-size: 12px;
  color: #6b5a3e;
}
.analysis-lines-btn {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: bold;
  padding: 4px 10px;
  border: 1px solid #b89b6e;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  color: #6b4f2a;
}
.analysis-lines-btn:hover { background: #f6efe0; }
.analysis-lines-btn:disabled { opacity: 0.4; cursor: default; }
.analysis-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.analysis-item, .analysis-head-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 4px;
  border-bottom: 1px solid #f0e6cf;
  border-radius: 4px;
}
.analysis-item { cursor: pointer; }
.analysis-item:hover { background: #f6efe0; }
.analysis-item:last-child { border-bottom: none; }
.analysis-head-row {
  font-size: 11px;
  color: #8a7755;
  font-weight: bold;
  cursor: default;
  border-bottom: 1px solid #d4bd8f;
}
.analysis-open {
  flex: 0 0 12px;
  text-align: right;
  color: #b89b6e;
  font-size: 16px;
  font-weight: bold;
}
.analysis-head-row .analysis-open { font-size: 11px; }
.analysis-rank {
  flex: 0 0 18px;
  text-align: center;
  font-size: 12px;
  color: #8a7755;
  font-weight: bold;
}
.analysis-move {
  flex: 0 0 72px;
  font-size: 15px;
  color: #4d4332;
  font-weight: bold;
}
.analysis-head-row .analysis-move { font-size: 11px; font-weight: bold; }
.analysis-eval {
  flex: 0 0 64px;
  font-size: 14px;
  font-weight: bold;
  color: #6b4f2a;
  font-variant-numeric: tabular-nums;
}
.analysis-head-row .analysis-eval { font-size: 11px; }
.analysis-eval.sente { color: #2f6f3e; }
.analysis-eval.gote { color: #8f2d2d; }
.analysis-pv {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  color: #6b5a3e;
  line-height: 1.5;
  word-break: break-word;
}
.analysis-head-row .analysis-pv { font-size: 11px; color: #8a7755; }
.analysis-empty {
  font-size: 13px;
  color: #8a7755;
  padding: 4px;
}

/* 検討手順ウィンドウ */
.lines-dialog {
  text-align: left;
  width: min(560px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
}
.lines-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: bold;
  color: #6b4f2a;
}
.lines-header button {
  font-size: 13px;
  padding: 5px 12px;
  border: 1px solid #b89b6e;
  border-radius: 4px;
  background: #f6efe0;
  cursor: pointer;
}
.lines-body {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}
.lines-item {
  padding: 8px 8px;
  border-bottom: 1px solid #eadfc4;
}
.lines-item:last-child { border-bottom: none; }
.lines-item.focus { background: #fff6df; border-radius: 4px; }
.lines-item-head {
  font-size: 15px;
  font-weight: bold;
  color: #4d4332;
  margin-bottom: 3px;
}
.lines-seq {
  font-size: 13px;
  color: #6b5a3e;
  line-height: 1.7;
  word-break: break-word;
}

/* 持ち駒 */
.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  margin: 6px 0;
}
.hand-label { font-size: 12px; color: #6b5a3e; margin-right: 6px; }
.hand-piece {
  position: relative;
  width: 38px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: 0;
  color: #2b2b2b;
  font: inherit;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.hand-piece-face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7e3b0;
  border: 1px solid #8a6a3a;
  border-radius: 3px 3px 2px 2px;
  clip-path: polygon(50% 0%, 88% 22%, 100% 100%, 0% 100%, 12% 22%);
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
}
.hand-piece.gote .hand-piece-face { transform: rotate(180deg); }
.hand-piece-count {
  position: absolute;
  right: -5px;
  bottom: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #fffaf0;
  border-radius: 999px;
  background: #7a3b2e;
  color: #fffaf0;
  font-size: 11px;
  font-weight: bold;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hand-piece:hover .hand-piece-face { background: #fbe9bd; }
.hand-piece:focus-visible { outline: none; }
.hand-piece:focus-visible .hand-piece-face {
  box-shadow: 0 0 0 3px rgba(122, 59, 46, 0.45);
}
.hand-piece.selected .hand-piece-face {
  background: #f6d69a;
  border-color: #b85f1d;
  box-shadow: 0 0 0 3px rgba(217, 138, 61, 0.7);
}

/* 盤 */
.board-wrap {
  width: 100%;
  max-width: 486px;
  margin: 0 auto;
}
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1;
  background: #e8c27a;
  border: 3px solid #6b4f2a;
}
.cell {
  position: relative;
  border: 1px solid #9c7b46;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}
.cell.last-move {
  background: #f1d26a;
}
.piece {
  width: 84%; height: 84%;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(16px, 4.6vw, 26px);
  font-weight: bold;
  background: #f7e3b0;
  border: 1px solid #8a6a3a;
  border-radius: 3px 3px 2px 2px;
  /* 駒らしい五角形 */
  clip-path: polygon(50% 0%, 88% 22%, 100% 100%, 0% 100%, 12% 22%);
  color: #2b2b2b;
}
.piece.gote { transform: rotate(180deg); }
.piece.promoted { color: #b3261e; }

.cell.selected { background: #f4cd86; }
.cell.target::after {
  content: '';
  position: absolute;
  width: 26%; height: 26%;
  background: rgba(60, 130, 60, 0.55);
  border-radius: 50%;
}
.cell.target.capture::after {
  width: 70%; height: 70%;
  background: transparent;
  border: 3px solid rgba(200, 60, 40, 0.7);
  border-radius: 50%;
}

/* 棋譜 */
.kifu-panel {
  width: 100%;
  max-width: 520px;
  margin: 10px auto 0;
  background: #fffaf0;
  border: 1px solid #d4bd8f;
  border-radius: 6px;
  text-align: left;
}
.kifu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid #e0cca3;
  color: #6b4f2a;
  font-size: 13px;
  font-weight: bold;
}
.kifu-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.kifu-nav button {
  width: 28px;
  height: 24px;
  padding: 0;
  border: 1px solid #b89b6e;
  border-radius: 4px;
  background: #fffaf0;
  color: #6b4f2a;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.kifu-nav button:disabled {
  opacity: 0.4;
  cursor: default;
}
.kifu-nav .kifu-copy {
  width: auto;
  min-width: 76px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
}
.kifu-count {
  color: #7b6a4d;
  font-size: 12px;
  font-weight: normal;
}
.kifu-list {
  max-height: 180px;
  margin: 0;
  padding: 6px 8px;
  overflow-y: auto;
  list-style: none;
}
.kifu-item {
  display: grid;
  grid-template-columns: 34px 1fr 54px;
  gap: 6px;
  align-items: baseline;
  padding: 4px 2px;
  border-bottom: 1px solid rgba(212, 189, 143, 0.55);
  font-size: 14px;
}
.kifu-item[role="button"] {
  cursor: pointer;
}
.kifu-item[role="button"]:hover,
.kifu-item.active {
  background: #f6ecd2;
}
.kifu-item.active {
  box-shadow: inset 3px 0 0 #d98a3d;
}
.kifu-item:last-child { border-bottom: 0; }
.kifu-no,
.kifu-eval {
  color: #7b6a4d;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.kifu-move {
  font-weight: bold;
  color: #2b2b2b;
}
.kifu-item.sente .kifu-move { color: #2f6f3e; }
.kifu-item.gote .kifu-move { color: #8f2d2d; }
.kifu-eval {
  text-align: right;
}
.kifu-empty {
  padding: 14px 4px;
  color: #7b6a4d;
  font-size: 13px;
  text-align: center;
}

/* ダイアログ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center;
}
.overlay.show { display: flex; }
.dialog {
  background: #fff; padding: 20px 28px; border-radius: 8px; text-align: center;
}
.dialog-buttons { display: flex; gap: 12px; margin-top: 12px; }
.dialog-buttons button {
  font-size: 15px; padding: 8px 18px; cursor: pointer;
  border: 1px solid #b89b6e; border-radius: 4px; background: #f6efe0;
}
