/* ============================================================
   ダイヤモンドゲーム - style.css
   ============================================================ */

:root {
  --bg: #f7f3ec;
  --bg-deco: #efe8dc;
  --ink: #3d3833;
  --ink-soft: #8a817a;
  --card: #ffffff;
  --line: #e6ddd1;
  --frame: #7a4526;
  --board: #f0dfbc;
  --hole: #d9c294;
  --red: #e05043;
  --red-hi: #f0837a;
  --red-lo: #b83227;
  --green: #4fae60;
  --green-hi: #7fd08d;
  --green-lo: #35804a;
  --yellow: #f2b933;
  --yellow-hi: #ffd970;
  --yellow-lo: #c98f16;
  --gold: #f2b933;
  --accent: #f0a532;
  --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;
  /* 上のセーフエリアは共通ヘッダー（body の padding-top = --sgh-top）が含むので足さない */
  padding: 14px calc(16px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  /* fill は backwards（both だと終了後も transform が残り、中の position: fixed の
     結果オーバーレイが画面全体ではなくこの枠を基準にしてしまう） */
  animation: screen-in .3s ease backwards;
}

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

.hidden { display: none !important; }

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

.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);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card);
  font-size: 19px;
  font-weight: 700;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: transform .12s ease;
}

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

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

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

.title-logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: bob 3s ease-in-out infinite;
}

.title-logo img { width: 100%; height: 100%; display: block; object-fit: cover; }

@keyframes bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -6px; }
}

.title-jp {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: .04em;
}

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

.menu-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

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

/* CPU・対戦設定 */

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

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

.seg {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border-radius: 999px;
  padding: 5px;
}

.seg-btn {
  flex: 1;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 9px 4px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
}

.seg-btn.is-active {
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow-soft);
}

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

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

#game-mode-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  flex: 1;
  text-align: center;
}

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

/* スコアボード */

#scoreboard {
  width: 100%;
  max-width: 440px;
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

#scoreboard.players-2 { grid-template-columns: 1fr 1fr; }
#scoreboard.players-3 { grid-template-columns: 1fr 1fr 1fr; }

.score-card {
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  padding: 8px 6px 7px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color .2s ease, transform .2s ease;
}

.score-card.is-turn {
  transform: translateY(-3px);
  border-color: var(--accent);
}

.score-disc {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .18);
}

.score-card.disc-c0 .score-disc { background: radial-gradient(circle at 35% 30%, var(--red-hi), var(--red) 70%); }
.score-card.disc-c1 .score-disc { background: radial-gradient(circle at 35% 30%, var(--green-hi), var(--green) 70%); }
.score-card.disc-c2 .score-disc { background: radial-gradient(circle at 35% 30%, var(--yellow-hi), var(--yellow) 70%); }

.score-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.score-value {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}

.score-value small {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
}

.score-wins {
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-soft);
}

/* ステータス */

#status {
  font-size: 15px;
  font-weight: 800;
  min-height: 24px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-disc {
  display: inline-block;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  flex: none;
}

.status-disc.c0 { background: radial-gradient(circle at 35% 30%, var(--red-hi), var(--red) 70%); }
.status-disc.c1 { background: radial-gradient(circle at 35% 30%, var(--green-hi), var(--green) 70%); }
.status-disc.c2 { background: radial-gradient(circle at 35% 30%, var(--yellow-hi), var(--yellow) 70%); }

#status.thinking::after {
  content: "";
  width: 13px;
  height: 13px;
  border: 3px solid var(--line);
  border-top-color: var(--ink-soft);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

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

#board-wrap {
  position: relative;
  width: min(94vw, 430px);
  /* JS 側の WORLD 定数（17.3 : 19.62）と合わせる */
  aspect-ratio: 17.3 / 19.62;
  background: linear-gradient(160deg, #855030, var(--frame) 55%, #6a3a1e);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 6px 18px rgba(90, 45, 20, .35);
  /* 開始時に scrollIntoView で盤を見せるとき、上の共通ヘッダー・下の広告の裏に入れない */
  scroll-margin-top: var(--sgh-top, 0px);
  scroll-margin-bottom: var(--ad-space, 0px);
}

#board {
  position: relative;
  width: 100%;
  height: 100%;
}

#board svg.board-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

#board.locked .cell { pointer-events: none; }

/* マス（穴） */

.cell {
  position: absolute;
  border: none;
  padding: 0;
  background: transparent;
  cursor: default;
  border-radius: 50%;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 24%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(0, 0, 0, .22), rgba(0, 0, 0, .1) 70%);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25), 0 1px 0 rgba(255, 255, 255, .35);
}

/* 移動先のヒント */

.cell.hint { cursor: pointer; }

.cell.hint::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: rgba(242, 185, 51, .6);
  box-shadow: 0 0 0 2px rgba(242, 185, 51, .35);
  animation: hint-pulse 1.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes hint-pulse {
  0%, 100% { transform: scale(1); opacity: .95; }
  50% { transform: scale(1.3); opacity: .55; }
}

.cell.last::before {
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25), 0 0 0 2.5px rgba(255, 214, 102, .8);
}

/* 駒 */

.piece {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
  transition: transform .24s ease;
}

.piece::before {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 50%;
}

.piece.c0::before {
  background:
    radial-gradient(circle at 36% 28%, rgba(255, 255, 255, .5), rgba(255, 255, 255, 0) 46%),
    radial-gradient(circle, var(--red) 0 62%, var(--red-lo) 63% 100%);
  box-shadow: 0 1.5px 3px rgba(0, 0, 0, .38), inset 0 -2px 3px rgba(0, 0, 0, .2);
}

.piece.c1::before {
  background:
    radial-gradient(circle at 36% 28%, rgba(255, 255, 255, .5), rgba(255, 255, 255, 0) 46%),
    radial-gradient(circle, var(--green) 0 62%, #35804a 63% 100%);
  box-shadow: 0 1.5px 3px rgba(0, 0, 0, .38), inset 0 -2px 3px rgba(0, 0, 0, .2);
}

.piece.c2::before {
  background:
    radial-gradient(circle at 36% 28%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 46%),
    radial-gradient(circle, var(--yellow) 0 62%, var(--yellow-lo) 63% 100%);
  box-shadow: 0 1.5px 3px rgba(0, 0, 0, .38), inset 0 -2px 3px rgba(0, 0, 0, .2);
}

/* 王駒の王冠 */

.piece::after {
  content: "\265B";
  position: relative;
  z-index: 1;
  font-size: min(3.4vw, 15px);
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .45);
  opacity: 0;
}

.piece.is-king::after { opacity: 1; }

/* 動かせる駒・選択中の駒 */

.piece.movable::before {
  outline: 2px solid rgba(255, 255, 255, .55);
  outline-offset: 1px;
}

.piece.selected { z-index: 3; }

.piece.selected::before {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  animation: selected-pulse 1.2s ease-in-out infinite;
}

@keyframes selected-pulse {
  0%, 100% { outline-color: rgba(242, 185, 51, 1); }
  50% { outline-color: rgba(242, 185, 51, .45); }
}

/* 移動中 */

.piece.moving { z-index: 4; }

.piece.moving::before {
  animation: piece-hop .24s ease;
}

@keyframes piece-hop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}

/* ゴール到達の駒がはねる */

.piece.goal-pop::before {
  animation: goal-pop .5s cubic-bezier(.2, 1.5, .4, 1);
}

@keyframes goal-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.45); }
  100% { transform: scale(1); }
}

/* トースト */

#toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(61, 40, 25, .9);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  padding: 12px 22px;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-pop .3s cubic-bezier(.2, 1.4, .4, 1) both;
  pointer-events: none;
}

@keyframes toast-pop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.7); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

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

/* ---------- 結果オーバーレイ ---------- */

#result-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(61, 56, 51, .45);
  animation: fade-in .25s ease both;
  padding: 24px;
}

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

#result-panel {
  width: 100%;
  max-width: 320px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: 0 12px 40px rgba(40, 30, 15, .3);
  padding: 28px 24px 24px;
  text-align: center;
  animation: panel-pop .35s cubic-bezier(.2, 1.4, .4, 1) both;
}

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

#result-piece {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .4);
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, .2), 0 3px 8px rgba(0, 0, 0, .2);
}

#result-piece.c0 { background: radial-gradient(circle at 35% 30%, var(--red-hi), var(--red) 70%); }
#result-piece.c1 { background: radial-gradient(circle at 35% 30%, var(--green-hi), var(--green) 70%); }
#result-piece.c2 { background: radial-gradient(circle at 35% 30%, var(--yellow-hi), var(--yellow) 70%); }

#result-text {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 4px;
}

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

#result-counts {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}

.result-count-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  font-weight: 800;
}

.result-count-item .status-disc { width: 14px; height: 14px; }

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

/* ---------- 遊び方モーダル ---------- */

#help-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(61, 56, 51, .45);
  animation: fade-in .25s ease both;
  padding: 24px;
}

#help-panel {
  width: 100%;
  max-width: 360px;
  max-height: min(80dvh, 560px);
  overflow-y: auto;
  background: var(--card);
  border-radius: 24px;
  box-shadow: 0 12px 40px rgba(40, 30, 15, .3);
  padding: 24px 22px 22px;
  animation: panel-pop .35s cubic-bezier(.2, 1.4, .4, 1) both;
}

#help-title {
  font-size: 20px;
  font-weight: 800;
  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.75;
  padding-left: 20px;
  position: relative;
}

.help-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: .62em;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--frame);
}

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

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

.confetti {
  position: absolute;
  top: -14px;
  width: 10px;
  height: 14px;
  opacity: .95;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: .7;
  }
}

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

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

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

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

/* ---------- 小さい画面調整 ---------- */

@media (max-height: 740px) {
  .title-logo { width: 76px; height: 76px; }
  .title-jp { font-size: 24px; }
  #scoreboard { margin-bottom: 6px; }
  #status { margin-bottom: 6px; }
  #board-wrap { width: min(94vw, 370px); }
  #game-buttons { margin-top: 8px; }
}

/* アニメーションを減らす設定への配慮 */
@media (prefers-reduced-motion: reduce) {
  .piece { transition: none; }
  .title-logo { animation: none; }
  .cell.hint::after { animation: none; }
  .piece.selected::before { animation: none; }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / 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; }
}
