/* ともだち将棋 — スタイル */
:root {
  --bg: #f4ecdb;
  --card: #fffdf7;
  --ink: #332612;
  --muted: #8a7a60;
  --accent: #a4551e;
  --accent-dark: #7a3c12;
  --wood: #e9c88f;
  --wood-dark: #caa25f;
  --board-line: rgba(90, 61, 27, 0.55);
  --piece-face: linear-gradient(160deg, #fbe9c2 0%, #eecf94 60%, #dfb673 100%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  background: radial-gradient(circle at 50% -10%, #faf3e2 0%, var(--bg) 55%, #ead9bb 100%);
  color: var(--ink);
  min-height: 100dvh;
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app { max-width: 560px; margin: 0 auto; padding: 12px 10px calc(16px + env(safe-area-inset-bottom)); }

/* ---------- ホーム ---------- */
.home-title { text-align: center; margin: 28px 0 20px; }
.logo-piece {
  width: 72px; height: 76px; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--piece-face);
  clip-path: polygon(50% 0%, 89% 22%, 100% 100%, 0% 100%, 11% 22%);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 38px; font-weight: 700;
  box-shadow: 0 3px 6px rgba(0,0,0,.25);
}
.home-title h1 { margin: 0; font-size: 28px; letter-spacing: 2px; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.mode-cards { display: flex; flex-direction: column; gap: 12px; margin: 0 6px; }
.mode-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid #e3d5b8; border-radius: 16px;
  padding: 16px 18px; text-align: left;
  box-shadow: 0 2px 8px rgba(90, 61, 27, 0.10);
  transition: transform .06s;
}
.mode-card:active { transform: scale(0.98); }
.mode-icon { font-size: 30px; }
.mode-texts { display: flex; flex-direction: column; gap: 2px; }
.mode-name { font-size: 17px; font-weight: 700; }
.mode-desc { font-size: 12.5px; color: var(--muted); }

.panel {
  background: var(--card); border: 1px solid #e3d5b8; border-radius: 16px;
  margin: 12px 6px 0; padding: 16px 18px;
  box-shadow: 0 2px 8px rgba(90, 61, 27, 0.10);
  display: flex; flex-direction: column; gap: 12px;
}
.panel-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel-label { font-size: 13.5px; font-weight: 700; min-width: 3.5em; }
.seg { display: flex; background: #efe6d0; border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  border: none; background: transparent; border-radius: 999px;
  padding: 7px 14px; font-size: 13.5px; color: var(--muted);
}
.seg button.on { background: var(--accent); color: #fff; font-weight: 700; }

button.primary {
  border: none; background: var(--accent); color: #fff;
  border-radius: 12px; padding: 12px 16px; font-size: 15.5px; font-weight: 700;
  box-shadow: 0 2px 6px rgba(122, 60, 18, 0.35);
}
button.primary:active { background: var(--accent-dark); }
button.ghost {
  border: 1px solid #d8c8a6; background: #fbf6ea; color: var(--ink);
  border-radius: 12px; padding: 10px 14px; font-size: 14px;
}
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1; border: 1.5px solid #d8c8a6; border-radius: 12px;
  font-size: 18px; padding: 10px 12px; text-transform: uppercase;
  letter-spacing: 3px; text-align: center; background: #fff;
  font-family: "Consolas", monospace; min-width: 0;
}
.join-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.note { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.6; }

/* ---------- 対局画面 ---------- */
.player-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 4px; min-height: 44px;
}
.player-label { font-size: 13px; font-weight: 700; white-space: nowrap; }
.player-label .you { color: var(--accent); }

.hand { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; min-height: 36px; align-items: center; }
.hand-piece {
  position: relative; width: 32px; height: 35px;
  display: flex; align-items: center; justify-content: center;
  background: var(--piece-face);
  clip-path: polygon(50% 0%, 89% 22%, 100% 100%, 0% 100%, 11% 22%);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 17px; font-weight: 700; color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.hand-piece .cnt {
  position: absolute; right: -2px; bottom: -3px;
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 10px; line-height: 1; padding: 2px 4px; font-family: sans-serif;
}
.hand-piece.sel { outline: 3px solid #f5a623; outline-offset: 1px; }
.hand-piece.dim { opacity: 0.9; }

#board-wrap {
  display: grid;
  grid-template-columns: 1fr 18px;
  grid-template-rows: 16px auto;
  width: min(calc(100vw - 44px), 500px, calc(100vh - 320px));
  min-width: 280px;
  margin: 0 auto;
}
#file-labels {
  grid-column: 1; grid-row: 1;
  display: grid; grid-template-columns: repeat(9, 1fr);
  font-size: 10.5px; color: var(--muted); text-align: center;
}
#rank-labels {
  grid-column: 2; grid-row: 2;
  display: grid; grid-template-rows: repeat(9, 1fr);
  font-size: 10.5px; color: var(--muted);
  align-items: center; justify-items: center;
}
#board {
  grid-column: 1; grid-row: 2;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.25), transparent 60%),
    linear-gradient(160deg, var(--wood) 0%, var(--wood-dark) 100%);
  border: 2.5px solid #5a3d1b;
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(90, 61, 27, 0.35);
}
.cell {
  position: relative;
  aspect-ratio: 1 / 1; /* マス自体を正方形に固定（段の高さが中身で変わらないように） */
  border: 0.5px solid var(--board-line);
  display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none;
}
#board, .hand { touch-action: none; }
.piece, .hand-piece { cursor: pointer; }
.cell.last { background: rgba(255, 166, 61, 0.30); }
.cell.sel { background: rgba(255, 205, 66, 0.55); }
.cell.dot::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 28%; aspect-ratio: 1; border-radius: 50%;
  background: rgba(58, 122, 66, 0.45);
  pointer-events: none;
}
.cell.dot.cap::after {
  width: 78%; background: transparent;
  border: 3px solid rgba(58, 122, 66, 0.55);
}
.piece {
  width: 86%; height: 92%;
  display: flex; align-items: center; justify-content: center;
  background: var(--piece-face);
  clip-path: polygon(50% 0%, 89% 22%, 100% 100%, 0% 100%, 11% 22%);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-weight: 700; color: var(--ink);
  font-size: clamp(13px, 5.2vw, 26px);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  user-select: none;
  padding-top: 8%;
}
#board-wrap[data-small="1"] .piece { font-size: clamp(11px, 4.6vw, 22px); }
.piece.upside { transform: rotate(180deg); }
.piece.promoted { color: #b3261e; }

#status-line {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13.5px; padding: 8px 6px 2px; color: var(--ink); min-height: 30px;
}
#move-info { font-weight: 700; }
#turn-info { color: var(--muted); }
#turn-info .thinking { color: var(--accent); font-weight: 700; }

.controls { display: flex; gap: 8px; justify-content: center; padding: 8px 0 0; flex-wrap: wrap; }
.controls button {
  border: 1px solid #d8c8a6; background: #fbf6ea; color: var(--ink);
  border-radius: 12px; padding: 9px 14px; font-size: 13.5px;
}
.controls button:disabled { opacity: 0.4; cursor: default; }

/* ---------- モーダル・トースト ---------- */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(30, 20, 8, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 20px;
}
.modal {
  background: #fffdf7; border-radius: 18px; padding: 22px 24px;
  max-width: 330px; width: 100%; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.modal p { margin: 0 0 14px; font-size: 15.5px; line-height: 1.7; }
.modal .modal-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.modal .modal-btns button { min-width: 100px; }
#room-code-big {
  font-family: "Consolas", monospace; font-size: 42px; letter-spacing: 8px;
  font-weight: 700; color: var(--accent); margin: 6px 0 12px;
  user-select: all;
}
#gameover-text { font-size: 18px; font-weight: 700; }

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: rgba(40, 28, 12, 0.92); color: #fff;
  border-radius: 999px; padding: 10px 22px; font-size: 14.5px;
  z-index: 60; white-space: nowrap;
  animation: toast-in .18s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* 横長画面（PC）では余白を少し広く */
@media (min-width: 700px) {
  #app { padding-top: 24px; }
  .home-title h1 { font-size: 32px; }
}
