/* ============================================================
   チェス - style.css
   ============================================================ */

:root {
  --bg: #f7f3ec;
  --bg-deco: #efe8dc;
  --ink: #3d3833;
  --ink-soft: #8a817a;
  --card: #ffffff;
  --line: #e6ddd1;
  --board-frame: #8a5a33;
  --board-frame-dark: #6f4526;
  --cell-light: #f0dcc0;
  --cell-dark: #b9855a;
  --sel: rgba(240, 165, 50, .55);
  --last: rgba(240, 165, 50, .32);
  --check: rgba(224, 90, 90, .6);
  --accent: #f0a532;
  --danger: #e05a5a;
  --shadow: 0 4px 14px rgba(90, 70, 40, .12);
  --shadow-soft: 0 2px 6px rgba(90, 70, 40, .08);
  --radius: 18px;
}

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

html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(var(--bg-deco) 9%, transparent 10%),
    radial-gradient(var(--bg-deco) 9%, transparent 10%);
  background-size: 42px 42px;
  background-position: 0 0, 21px 21px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  animation: screen-in .3s ease both;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.hidden { display: none !important; }

/* ---------- 駒SVG共通 ---------- */

.pc {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pc use {
  stroke-linejoin: round;
  stroke-linecap: round;
}

.pc-w use {
  fill: #f9f5ec;
  stroke: #5a4632;
  stroke-width: 4;
}

.pc-b use {
  fill: #3a342e;
  stroke: #f3ead9;
  stroke-width: 4;
}

/* symbol内の装飾パーツ（目・スリット・十字）は use から継承した色を反転気味に */
.pc-w .pc-dot, .pc-b .pc-dot { display: none; }
symbol .pc-dot { fill: inherit; }
symbol .pc-slit, symbol .pc-cross { fill: none; }

/* ---------- ボタン共通 ---------- */

.btn {
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 12px 24px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.btn:active { transform: scale(.96); }

.btn:disabled {
  opacity: .4;
  cursor: default;
  pointer-events: none;
}

.btn-big {
  width: 100%;
  font-size: 18px;
  padding: 16px 24px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 5px 0 #cf861b, var(--shadow-soft);
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #cf861b, var(--shadow-soft);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink-soft);
}

.btn-ghost:active { transform: scale(.96); }

.icon-btn {
  width: 44px;
  height: 44px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .12s ease;
}

.icon-btn:active { transform: scale(.92); }

.icon-btn.is-off { opacity: .45; }

/* ---------- タイトル画面 ---------- */

#screen-title { justify-content: center; }

.title-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 14px;
}

.title-logo {
  width: 110px;
  height: 110px;
  filter: drop-shadow(0 6px 12px rgba(90, 70, 40, .25));
  animation: logo-pop .5s cubic-bezier(.2, 1.6, .4, 1) both;
}

@keyframes logo-pop {
  from { opacity: 0; transform: scale(.6); }
  to   { opacity: 1; transform: scale(1); }
}

.title-jp {
  font-size: 40px;
  letter-spacing: .12em;
}

.title-desc {
  font-size: 14px;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.7;
}

.menu-panel {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.btn-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-mode-icon { font-size: 22px; }

.config-group {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-soft);
}

.config-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.seg {
  display: flex;
  gap: 6px;
}

.seg-btn {
  flex: 1;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 10px 4px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}

.seg-btn.is-active {
  background: #fdf1dd;
  border-color: var(--accent);
  color: var(--ink);
}

/* ---------- ゲーム画面 ---------- */

#screen-game { gap: 10px; }

#game-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#game-mode-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-soft);
}

.header-right { display: flex; gap: 8px; }

/* プレイヤーバー */

.player-bar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 6px 12px;
  box-shadow: var(--shadow-soft);
  transition: border-color .2s ease, box-shadow .2s ease;
  min-height: 52px;
}

.player-bar.is-turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 165, 50, .18), var(--shadow-soft);
}

.player-piece {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.player-info {
  flex: 1;
  min-width: 0;
}

.player-name {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}

.player-captured {
  display: flex;
  align-items: center;
  height: 16px;
  overflow: hidden;
}

.player-captured .pc {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.player-captured .cap-score {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-left: 4px;
}

.player-wins {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  flex-shrink: 0;
}

#status {
  font-size: 15px;
  font-weight: 700;
  min-height: 22px;
  text-align: center;
}

#status.is-check { color: var(--danger); }

/* ---------- 盤面 ---------- */

#board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

#board {
  width: min(100%, 62dvh, 480px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  background: var(--board-frame);
  border: 6px solid var(--board-frame);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 6px 0 var(--board-frame-dark), var(--shadow);
}

.cell {
  position: relative;
  background: var(--cell-light);
  cursor: pointer;
}

.cell.dark { background: var(--cell-dark); }

.cell .coord {
  position: absolute;
  font-size: clamp(7px, 1.9vw, 10px);
  font-weight: 700;
  pointer-events: none;
  opacity: .75;
}

.cell .coord-rank { top: 2px; left: 3px; }
.cell .coord-file { bottom: 1px; right: 3px; }
.cell .coord { color: var(--cell-dark); }
.cell.dark .coord { color: var(--cell-light); }

.cell .pc {
  position: absolute;
  inset: 4%;
  width: 92%;
  height: 92%;
  pointer-events: none;
  filter: drop-shadow(0 2px 1px rgba(60, 40, 20, .25));
}

/* ハイライト */

.cell.last::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--last);
}

.cell.selected::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sel);
}

.cell.check::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, var(--check) 30%, rgba(224, 90, 90, .15) 75%);
}

.cell.move-dot::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26%;
  height: 26%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(61, 56, 51, .28);
}

.cell.move-capt::after {
  content: "";
  position: absolute;
  inset: 4%;
  border: 3px solid rgba(224, 90, 90, .75);
  border-radius: 50%;
}

.cell.cpu-anim .pc { animation: piece-in .18s ease both; }

@keyframes piece-in {
  from { transform: scale(1.25); }
  to   { transform: scale(1); }
}

#game-buttons {
  display: flex;
  gap: 12px;
}

/* ---------- プロモーション ---------- */

#promo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 24, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  animation: fade-in .18s ease both;
}

#promo-panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

#promo-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
}

#promo-buttons {
  display: flex;
  gap: 10px;
}

.promo-btn {
  width: 64px;
  height: 64px;
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  padding: 6px;
  transition: transform .12s ease, border-color .12s ease;
}

.promo-btn:active { transform: scale(.92); }
.promo-btn:hover { border-color: var(--accent); }
.promo-btn .pc { pointer-events: none; }

/* ---------- 結果 ---------- */

#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 24, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  animation: fade-in .25s ease both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#result-panel {
  width: min(86vw, 340px);
  background: var(--card);
  border-radius: 22px;
  padding: 28px 22px 22px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: panel-pop .35s cubic-bezier(.2, 1.5, .4, 1) both;
}

@keyframes panel-pop {
  from { opacity: 0; transform: scale(.7) translateY(16px); }
  to   { opacity: 1; transform: none; }
}

#result-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 8px;
}

#result-text {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 4px;
}

#result-sub {
  font-size: 13px;
  color: var(--ink-soft);
  min-height: 18px;
  margin-bottom: 18px;
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- ヘルプ ---------- */

#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 24, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fade-in .2s ease both;
  padding: 20px;
}

#help-panel {
  width: min(92vw, 400px);
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 22px;
  padding: 24px 22px;
  box-shadow: var(--shadow);
  animation: panel-pop .3s cubic-bezier(.2, 1.5, .4, 1) both;
}

#help-title {
  font-size: 20px;
  text-align: center;
  margin-bottom: 14px;
}

.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.help-list li {
  font-size: 14px;
  line-height: 1.7;
  padding-left: 22px;
  position: relative;
}

.help-list li::before {
  content: "♟";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent);
  font-weight: 700;
}

/* ---------- フッター ---------- */

.footer {
  margin-top: auto;
  padding-top: 18px;
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.8;
}

.footer a {
  color: inherit;
  text-decoration: underline;
}

.footer-game { padding-top: 10px; }

/* ---------- 紙吹雪 ---------- */

#confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -14px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  animation: confetti-fall linear both;
}

@keyframes confetti-fall {
  from { transform: translateY(-5dvh) rotate(0turn); opacity: 1; }
  to   { transform: translateY(110dvh) rotate(3turn); opacity: .85; }
}

/* ---------- レスポンシブ微調整 ---------- */

@media (max-height: 700px) {
  #screen-game { gap: 6px; }
  .player-bar { min-height: 46px; padding: 4px 10px; }
  .footer-game { display: none; }
}

/* PC 幅では、盤を「画面の高さ − 共通ヘッダー − 盤の上下のUI」までに抑えて「待った／はじめから」まで1画面に収める。
   62dvh だけだと共通ヘッダーのぶん下にはみ出し、1280x800 ではボタンが半分切れ、
   1366x657 では自分のプレイヤーバーまで画面外になっていた（スマホ幅は従来どおり） */
@media (min-width: 768px) {
  #board { width: min(100%, 62dvh, 480px, max(300px, calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px) - 300px))); }
}

@media (min-width: 768px) and (max-height: 700px) {
  #board { width: min(100%, 62dvh, 480px, max(300px, calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px) - 270px))); }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

@media print {
  .ad-banner { display: none; }
}
