/* おもろい将棋 — 共通スタイル (和モダン・ダーク) */
:root {
  --bg: #211d19;
  --panel: #2c2620;
  --panel-2: #373028;
  --line: #4a4238;
  --text: #ece5d8;
  --text-dim: #b0a795;
  --accent: #c9a227;
  --accent-2: #d4552f;
  --board: #e9c98d;
  --board-line: #8a6b3f;
  --koma: #f6dfa8;
  --koma-edge: #b08d4f;
  --good: #4caf7d;
  --warn: #e0b73f;
  --bad: #e05f4f;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
body.modal-open { overflow: hidden; position: fixed; width: 100%; }

/* ===== 共通コンポーネント ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; min-width: 44px; padding: 10px 18px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  user-select: none;
}
.btn:hover { background: #443b31; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn--primary { background: var(--accent); color: #221a05; border-color: transparent; }
.btn--primary:hover { background: #ddb63a; }
.btn--danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn--danger:hover { background: rgba(224, 95, 79, 0.12); }
.btn--ghost { background: transparent; }
.btn--sm { min-height: 44px; padding: 6px 12px; font-size: 13px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card + .card { margin-top: 12px; }
.card__title { font-size: 14px; font-weight: 700; color: var(--accent); margin-bottom: 8px; letter-spacing: 0.05em; }

/* ===== モーダル ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 8, 6, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px;
  max-width: 520px; width: 100%; max-height: 86vh; overflow-y: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.modal h2 { font-size: 19px; margin-bottom: 12px; color: var(--accent); }
.modal__actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }

/* ===== ヘッダー ===== */
.app-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0; z-index: 50;
}
.app-header__title { font-size: 17px; font-weight: 800; letter-spacing: 0.04em; }
.app-header__title a { color: var(--text); text-decoration: none; }
.app-header__ver { font-size: 11px; color: var(--text-dim); }
.app-header__spacer { flex: 1; }

/* ===== ロビー ===== */
.lobby { max-width: 760px; margin: 0 auto; padding: 24px 16px 60px; }
.lobby__hero { text-align: center; padding: 28px 0 20px; }
.lobby__hero h1 { font-size: 30px; letter-spacing: 0.08em; }
.lobby__hero p { color: var(--text-dim); margin-top: 8px; font-size: 14px; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
@media (max-width: 640px) { .mode-grid { grid-template-columns: 1fr; } }
.mode-card {
  display: block; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 18px;
  color: var(--text); text-decoration: none;
  transition: border-color 0.15s, transform 0.1s;
}
.mode-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.mode-card__icon { font-size: 26px; }
.mode-card__name { font-size: 17px; font-weight: 800; margin-top: 8px; }
.mode-card__desc { font-size: 13px; color: var(--text-dim); margin-top: 6px; }
.mode-card__badge { display: inline-block; font-size: 11px; background: var(--accent); color: #221a05; padding: 2px 8px; border-radius: 999px; margin-top: 8px; font-weight: 700; }

/* ===== 対局レイアウト ===== */
.game-layout {
  display: grid; grid-template-columns: minmax(320px, 560px) minmax(300px, 1fr);
  gap: 16px; max-width: 1160px; margin: 0 auto; padding: 14px 14px 80px;
  align-items: start;
}
@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; padding-bottom: 120px; }
}

/* ===== 盤 ===== */
.board-area { display: flex; flex-direction: column; gap: 8px; }
.hand {
  display: flex; align-items: center; gap: 6px; min-height: 46px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 8px; flex-wrap: wrap;
}
.hand__label { font-size: 11px; color: var(--text-dim); width: 3.2em; }
.hand__piece {
  position: relative; cursor: pointer; border-radius: 6px; padding: 2px;
  border: 2px solid transparent;
}
.hand__piece.is-selected { border-color: var(--accent-2); background: rgba(212, 85, 47, 0.15); }
.hand__count {
  position: absolute; right: -4px; bottom: -4px;
  background: var(--accent); color: #221a05; font-size: 10px; font-weight: 800;
  border-radius: 999px; min-width: 16px; height: 16px; line-height: 16px; text-align: center;
}
.board {
  display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
  aspect-ratio: 1 / 1.08;
  background: var(--board);
  border: 3px solid var(--board-line);
  border-radius: 6px;
  touch-action: manipulation;
  position: relative;
}
.cell {
  border: 0.5px solid var(--board-line);
  position: relative; display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.cell.is-dest::after {
  content: ""; position: absolute; width: 30%; height: 30%;
  background: rgba(212, 85, 47, 0.55); border-radius: 50%;
}
.cell.is-dest-capture::after {
  width: 88%; height: 88%; background: transparent;
  border: 3px solid rgba(212, 85, 47, 0.75); border-radius: 8px;
}
.cell.is-selected { background: rgba(212, 85, 47, 0.28); }
.cell.is-last { background: rgba(201, 162, 39, 0.38); }
.cell.is-preview { background: rgba(76, 175, 125, 0.35); }
.cell.is-check { box-shadow: inset 0 0 0 3px var(--bad); }

.koma {
  width: 86%; height: 90%;
  clip-path: polygon(50% 0%, 88% 22%, 100% 100%, 0% 100%, 12% 22%);
  background: linear-gradient(160deg, var(--koma), #e3c17e);
  border-bottom: 2px solid var(--koma-edge);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #2a1c08;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(13px, 4.2vw, 26px);
  padding-top: 12%;
  user-select: none;
}
.game-layout .koma { font-size: clamp(13px, min(4.2vw, 30px), 30px); }
.koma--white { transform: rotate(180deg); }
.koma--promoted { color: #b02515; }
.koma--small { width: 34px; height: 36px; font-size: 16px; padding-top: 4px; }
.koma__text--two { font-size: 0.55em; line-height: 1.05; text-align: center; white-space: nowrap; }

.board-coords-top { display: grid; grid-template-columns: repeat(9, 1fr); font-size: 10px; color: var(--text-dim); text-align: center; padding-right: 16px; }
.board-row { display: flex; align-items: stretch; }
.board-row .board { flex: 1; min-width: 0; }
.board-coords-right {
  display: grid; grid-template-rows: repeat(9, 1fr); width: 16px;
  font-size: 10px; color: var(--text-dim);
  align-items: center; justify-items: center;
  padding: 3px 0; /* 盤のborder分の高さ合わせ */
}

/* ===== サイドパネル ===== */
.side-panel { display: flex; flex-direction: column; gap: 12px; }
.turn-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; font-weight: 700;
}
.turn-bar .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); }
.turn-bar.is-thinking .dot { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.eval-meter { height: 10px; border-radius: 999px; background: #555; overflow: hidden; display: flex; }
.eval-meter__black { background: var(--accent); transition: width 0.4s; }
.eval-meter__white { background: #999; flex: 1; }

/* コーチパネル */
.coach-grade { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.coach-grade__mark { font-size: 34px; font-weight: 900; }
.coach-grade__mark.g-best { color: var(--good); }
.coach-grade__mark.g-good { color: #7ec8e3; }
.coach-grade__mark.g-dubious { color: var(--warn); }
.coach-grade__mark.g-bad { color: var(--bad); }
.coach-grade__label { font-size: 15px; font-weight: 700; }
.coach-grade__score { font-size: 12px; color: var(--text-dim); margin-left: auto; }
.coach-list { list-style: none; font-size: 13px; }
.coach-list li { padding: 5px 0 5px 22px; position: relative; border-top: 1px dashed var(--line); }
.coach-list li:first-child { border-top: none; }
.coach-list li::before { position: absolute; left: 0; }
.coach-list--good li::before { content: "👍"; }
.coach-list--bad li::before { content: "⚠️"; }
.coach-list--consider li::before { content: "💡"; }
.coach-section-title { font-size: 12px; font-weight: 700; color: var(--text-dim); margin: 10px 0 2px; }

.cand {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px;
  cursor: pointer; transition: border-color 0.15s;
}
.cand:hover { border-color: var(--accent); }
.cand.is-user { border-color: var(--good); }
.cand__head { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; }
.cand__rank { font-size: 11px; background: var(--panel-2); border-radius: 4px; padding: 1px 6px; color: var(--text-dim); }
.cand__intent { font-size: 11px; color: var(--accent); margin-left: auto; }
.cand__pv { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

/* ガイドパネル */
.guide-phase { font-size: 13px; font-weight: 800; color: var(--accent-2); }
.castle-progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.castle-progress__bar { flex: 1; height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.castle-progress__fill { height: 100%; background: linear-gradient(90deg, var(--accent), #ddb63a); transition: width 0.4s; }
.castle-progress__label { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.enemy-plan { margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--warn); }
.guide-check { list-style: none; font-size: 13px; margin-top: 6px; }
.guide-check li { padding: 3px 0; color: var(--text-dim); }
.guide-check li.done { color: var(--good); text-decoration: line-through; }
.guide-check li.done::before { content: "✔ "; }
.guide-check li:not(.done)::before { content: "・"; }
.guide-next { margin-top: 8px; font-size: 13px; }
.guide-next b { color: var(--accent); }
.guide-tips { font-size: 12px; color: var(--text-dim); margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }

/* AIコーチ 注記・ガイド候補 */
.coach-note { font-size: 11px; color: var(--text-dim); background: var(--panel-2); border-radius: 6px; padding: 6px 8px; margin-top: 6px; }
.cand.is-guide { border-color: var(--accent); background: rgba(201, 162, 39, 0.07); }

/* AIチャット */
.chat-log { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.chat-msg { font-size: 13px; padding: 8px 10px; border-radius: 10px; white-space: pre-line; max-width: 92%; }
.chat-msg--user { align-self: flex-end; background: rgba(201, 162, 39, 0.18); border: 1px solid var(--accent); }
.chat-msg--ai { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); }
.chat-msg--error { border-color: var(--bad); color: var(--bad); }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input {
  flex: 1; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-size: 14px;
}
.chat-input-row input:focus { outline: 2px solid var(--accent); }
.chat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chat-chip {
  font-size: 12px; padding: 6px 10px; min-height: 32px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--text-dim); cursor: pointer;
}
.chat-chip:hover { border-color: var(--accent); color: var(--text); }

/* 棋譜 */
.kifu-list { font-size: 12px; max-height: 180px; overflow-y: auto; columns: 2; }
.kifu-list div { padding: 2px 4px; break-inside: avoid; }
.kifu-list .kifu-move { cursor: pointer; border-radius: 4px; }
.kifu-list .kifu-move:hover { background: var(--panel-2); }
.kifu-list .kifu-move.is-current { background: rgba(201, 162, 39, 0.25); font-weight: 700; }

/* 感想戦 */
.review-counter { display: inline-flex; align-items: center; font-size: 13px; font-weight: 700; padding: 0 6px; white-space: nowrap; }
.review-played { font-size: 14px; padding: 6px 0; }
.g-best { color: var(--good); }
.g-good { color: #7ec8e3; }
.g-dubious { color: var(--warn); }
.g-bad { color: var(--bad); }

/* アクションバー (仮指しの確定/やり直し) */
.action-bar { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 900px) {
  .action-bar--sticky {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: var(--panel); border-top: 1px solid var(--line);
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  }
}

/* 詰将棋 */
.tsume-layout { max-width: 900px; margin: 0 auto; padding: 14px; display: grid; grid-template-columns: minmax(300px, 480px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .tsume-layout { grid-template-columns: 1fr; } }
.problem-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.problem-chip {
  min-width: 44px; min-height: 44px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; padding: 4px 10px;
}
.problem-chip.is-active { border-color: var(--accent); background: rgba(201, 162, 39, 0.15); }
.problem-chip.is-cleared { border-color: var(--good); color: var(--good); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 80;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 18px; font-size: 14px; font-weight: 700;
  box-shadow: 0 8px 26px rgba(0,0,0,0.45);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.toast.show { opacity: 1; }

.badge { display: inline-block; font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; color: var(--text-dim); }
.hidden { display: none !important; }
