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

body {
  font-family: 'Noto Sans JP', 'Yu Mincho', '游明朝', serif;
  background: #F2ECD8;
  /* 和紙風の微細なテクスチャ */
  background-image:
    repeating-linear-gradient(
      0deg, transparent, transparent 3px,
      rgba(180,160,100,0.07) 3px, rgba(180,160,100,0.07) 4px
    );
  color: #2A1800;
  min-height: 100vh;
}

/* ===== ヘッダー ===== */
header {
  background: #111008;
  color: #C8A840;
  padding: 1rem 2rem 0.8rem;
  text-align: center;
  border-bottom: 3px solid #8B6914;
  position: relative;
}

.header-deco {
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  color: #8B6914;
  margin: 0.1rem 0;
}

header h1 {
  font-size: 2.4rem;
  font-weight: bold;
  letter-spacing: 0.5em;
  text-indent: 0.5em; /* letter-spacingの分ずれを補正 */
  color: #D4AF37;
  text-shadow: 0 0 18px rgba(212,175,55,0.5), 2px 2px 4px rgba(0,0,0,0.8);
  margin: 0.3rem 0;
}

.header-sub {
  font-size: 0.85rem;
  color: #A08830;
  margin-top: 0.4rem;
  letter-spacing: 0.1em;
}

/* ===== メインレイアウト ===== */
main {
  max-width: 580px;
  margin: 1rem auto;
  padding: 0 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

/* ===== 持ち駒エリア（後手：左上、先手：右下） ===== */
#white-side {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* 左寄せ */
}

#black-side {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-end; /* 右寄せ */
}

.player-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.white-info {
  flex-direction: row;
}

.black-info {
  flex-direction: row-reverse;
}

.player-name {
  font-size: 0.85rem;
  font-weight: bold;
  color: #5A3010;
  letter-spacing: 0.05em;
}

.hands-label {
  font-size: 0.75rem;
  color: #8B6000;
  border: 1px solid #C8A040;
  padding: 1px 5px;
  border-radius: 2px;
  background: #FDF5DC;
}

.hands {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  background: #EFE0B0;
  border: 1px solid #B89050;
  border-radius: 3px;
  padding: 0.3rem 0.5rem;
  min-height: 36px;
  min-width: 160px;
  max-width: 440px;
  font-size: 0.85rem;
  color: #6B3A10;
}

.hand-piece {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid #9A6830;
  border-radius: 2px;
  background: #FDFAF0;
  font-size: 1rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
  font-family: 'Noto Sans JP', 'Yu Mincho', serif;
}

.hand-piece:hover {
  background: #FFE090;
}

.hand-piece.selected {
  background: #FFC030;
  border-color: #C07800;
  box-shadow: 0 0 4px rgba(200,120,0,0.5);
}

#white-hands .hand-piece {
  transform: rotate(180deg);
  cursor: default;
}

/* ===== 将棋盤エリア ===== */
#board-area {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

#col-labels {
  display: grid;
  grid-template-columns: repeat(9, 52px);
  margin-bottom: 2px;
}

#col-labels span {
  text-align: center;
  font-size: 0.75rem;
  color: #6A4020;
  font-family: sans-serif;
}

#board-inner {
  display: flex;
  align-items: flex-start;
}

#board {
  display: grid;
  grid-template-columns: repeat(9, 52px);
  grid-template-rows: repeat(9, 52px);
  border: 2px solid #5A3008;
  box-shadow: 3px 3px 10px rgba(60,30,0,0.4);
  background: #DCB870;
}

.cell {
  width: 52px;
  height: 52px;
  border: 1px solid #9A7030;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: #DCB870;
  transition: background 0.1s;
  position: relative;
}

.cell:hover {
  background: #C89A40;
}

.cell.selected {
  background: #FFD040 !important;
  border-color: #C07000;
  box-shadow: inset 0 0 6px rgba(200,120,0,0.4);
}

.cell.legal {
  background: #B8D888;
}

.cell.legal::after {
  content: '';
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: rgba(40,130,0,0.35);
}

.cell.legal:hover {
  background: #90C050;
}

/* ===== 駒 ===== */
.piece {
  font-size: 1.3rem;
  font-weight: bold;
  line-height: 1;
  user-select: none;
  display: block;
  text-align: center;
  font-family: 'Noto Sans JP', 'Yu Mincho', serif;
}

.black-piece {
  color: #120800;
}

.white-piece {
  color: #120800;
  transform: rotate(180deg);
}

.promoted {
  color: #B80000;
}

/* ===== 段ラベル ===== */
#row-labels {
  display: flex;
  flex-direction: column;
  margin-left: 4px;
}

#row-labels span {
  height: 52px;
  display: flex;
  align-items: center;
  font-size: 0.75rem;
  color: #6A4020;
}

/* ===== ターン表示 ===== */
#turn-indicator {
  font-size: 1.05rem;
  font-weight: bold;
  color: #5A2800;
  letter-spacing: 0.1em;
  padding: 0.3rem 1rem;
  border-top: 1px solid #C8A040;
  border-bottom: 1px solid #C8A040;
  background: #FDF5DC;
  width: 100%;
  text-align: center;
}

/* ===== 棋譜 ===== */
#kifu-area {
  width: 100%;
}

#kifu-log {
  width: 100%;
  max-height: 70px;
  overflow-y: auto;
  background: #FDFAF0;
  border: 1px solid #B89050;
  border-radius: 3px;
  padding: 0.3rem 0.6rem;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  color: #4A2808;
  line-height: 1.7;
  word-break: break-all;
}

/* ===== リセットボタン ===== */
#reset-btn {
  background: #6B1E00;
  color: #FFF5DC;
  border: none;
  padding: 0.5rem 2.5rem;
  font-size: 0.95rem;
  font-family: 'Noto Sans JP', 'Yu Mincho', serif;
  letter-spacing: 0.15em;
  border-radius: 2px;
  cursor: pointer;
  margin-top: 0.3rem;
  border: 1px solid #A03000;
  transition: background 0.15s;
  box-shadow: 2px 2px 5px rgba(60,20,0,0.35);
}

#reset-btn:hover {
  background: #8B3010;
}

/* ===== ダイアログ ===== */
.dialog-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(20, 10, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog {
  background: #FDFAF0;
  padding: 2rem 2.5rem;
  border-radius: 4px;
  text-align: center;
  box-shadow: 0 6px 30px rgba(80,30,0,0.5);
  border: 2px solid #C8A040;
  position: relative;
}

.dialog::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid #D4AF60;
  pointer-events: none;
  border-radius: 2px;
}

.dialog p {
  font-size: 1.2rem;
  margin-bottom: 1.3rem;
  color: #2A1000;
  letter-spacing: 0.1em;
}

.dialog button {
  margin: 0 0.5rem;
  padding: 0.5rem 1.8rem;
  font-size: 0.95rem;
  font-family: 'Noto Sans JP', 'Yu Mincho', serif;
  letter-spacing: 0.1em;
  border-radius: 2px;
  border: 1px solid;
  cursor: pointer;
  transition: opacity 0.15s;
}

.dialog button:hover { opacity: 0.82; }

#promote-yes, #play-again-btn {
  background: #6B1E00;
  color: #FFF5DC;
  border-color: #A03000;
}

#promote-no {
  background: #C0A060;
  color: #2A1000;
  border-color: #907030;
}

#winner-text {
  font-size: 1.5rem !important;
  font-weight: bold;
  color: #6B1E00;
  letter-spacing: 0.15em;
}
