/* ============================================================
   バックギャモン - style.css
   ============================================================ */

:root {
  --bg: #f7f3ec;
  --bg-deco: #efe8dc;
  --ink: #3d3833;
  --ink-soft: #8a817a;
  --card: #ffffff;
  --line: #e6ddd1;
  --wood: #7c4f2a;
  --wood-dark: #5f3a1d;
  --accent: #f0a532;
  --danger: #e05a5a;
  --white-piece: #f7f2e8;
  --black-piece: #463225;
  --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;
  /* 上端のセーフエリアは共通ヘッダー（--sgh-top）側で空けているので足さない */
  padding: 16px 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;
}

.screen-game { max-width: 680px; }

@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: 14px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, opacity .12s ease;
}

.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; cursor: default; }
.btn:disabled:active { transform: none; }

.btn-big {
  width: 100%;
  font-size: 18px;
  padding: 14px 20px;
  border-radius: 16px;
}

.btn-primary {
  background: var(--accent);
  border-color: #d98f1f;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0,0,0,.15);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn:focus-visible, .icon-btn:focus-visible, .seg-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

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

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

.title-logo { width: 110px; }
.title-logo svg { display: block; width: 100%; height: auto; filter: drop-shadow(0 6px 10px rgba(90,70,40,.25)); }

.title-jp {
  font-size: 34px;
  letter-spacing: .08em;
}

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

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

.btn-mode {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}

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

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

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

.config-note {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.7;
  text-align: center;
}

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

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

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

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

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

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

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

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

.icon-btn:active { transform: scale(.92); }
.icon-btn.is-muted { color: var(--ink-soft); opacity: .6; }

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

.score-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 8px 12px;
  box-shadow: var(--shadow-soft);
  transition: border-color .2s ease, box-shadow .2s ease;
}

.score-card.is-turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 165, 50, .25);
}

.score-disc {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}

.score-disc-white { background: var(--white-piece); border: 2px solid #c9bda6; }
.score-disc-black { background: var(--black-piece); border: 2px solid #2b201a; }

.score-main { flex: 1; min-width: 0; }

.score-name {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-pip {
  font-size: 11px;
  color: var(--ink-soft);
}

.score-wins {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
}

#status {
  width: 100%;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  min-height: 24px;
  margin-bottom: 6px;
}

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

#board-wrap {
  position: relative;
  width: 100%;
}

/* 画面の高さが足りないとき（低めの PC 画面など）は、ロール・サイコロまで1画面に収まるよう盤面の幅を絞る。
   250px は盤面以外（ヘッダー・スコア・状態表示・操作列・余白）の高さ。盤面の高さは幅の 0.7 倍。
   タッチ端末（スマホの横向きなど）は絞っても1画面に収まらず、コマが小さく押しにくくなるだけなので対象外 */
@media (hover: hover) and (pointer: fine) {
  #board-wrap {
    max-width: max(280px, calc((100vh - var(--sgh-top, 0px) - var(--ad-space, 0px) - 250px) * 10 / 7));
    max-width: max(280px, calc((100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px) - 250px) * 10 / 7));
  }
}

#bg-board {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  box-shadow: var(--shadow);
}

#bg-board [data-loc] { cursor: pointer; }
#bg-board .loc-overlay { pointer-events: all; }
#bg-board .loc-overlay:focus { outline: none; }
/* キーボード操作のときだけ、フォーカス中の場所を枠で示す */
#bg-board .loc-overlay:focus-visible { stroke: #2f6fd0; stroke-width: 6; }

.checker-flash { animation: checker-flash .5s ease; }
@keyframes checker-flash {
  0% { opacity: .2; }
  100% { opacity: 1; }
}

#board-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(40, 30, 20, .88);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 14px;
  white-space: nowrap;
  pointer-events: none;
  animation: toast-in .25s ease both;
  z-index: 5;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -40%); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

/* ---------- コントロール ---------- */

#controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  min-height: 56px;
}

#btn-undo { flex-shrink: 0; }

#dice-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
}

.die {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 6px;
  box-shadow: 0 2px 5px rgba(60, 40, 20, .3), inset 0 -2px 0 rgba(0,0,0,.08);
  transition: opacity .2s ease, transform .2s ease;
}

.die.small { width: 36px; height: 36px; padding: 5px; border-radius: 8px; }

.die-white { background: #fdfaf3; border: 1px solid #d8cdb8; }
.die-white .pip { background: #3d3833; }
.die-black { background: #4a3a2d; border: 1px solid #2b201a; }
.die-black .pip { background: #f3ecdd; }

.die .pip {
  width: 70%;
  height: 70%;
  border-radius: 50%;
  place-self: center;
  visibility: hidden;
}

.die .pip.on { visibility: visible; }

.die.used { opacity: .3; transform: scale(.9); }

.die.rolling { animation: die-shake .1s linear infinite; }
@keyframes die-shake {
  0%   { transform: rotate(-6deg); }
  50%  { transform: rotate(6deg); }
  100% { transform: rotate(-6deg); }
}

.die-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  align-self: center;
}

#btn-roll {
  flex-shrink: 0;
  animation: roll-pulse 1.4s ease infinite;
}

#btn-roll.hidden { animation: none; }

@keyframes roll-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 165, 50, .45); }
  60% { box-shadow: 0 0 0 10px rgba(240, 165, 50, 0); }
}

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

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

.footer a { color: inherit; }

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

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

#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 20, .45);
  display: grid;
  place-items: center;
  z-index: 40;
  animation: fade-in .25s ease both;
}

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

#result-panel {
  width: min(88vw, 340px);
  background: var(--card);
  border-radius: 22px;
  padding: 28px 22px 22px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(40, 30, 20, .3);
  animation: pop-in .3s cubic-bezier(.2, 1.4, .4, 1) both;
}

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

#result-text {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
}

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

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

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

#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 20, .45);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
  animation: fade-in .25s ease both;
}

#help-panel {
  width: min(92vw, 420px);
  max-height: 82dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 22px;
  padding: 24px 22px;
  box-shadow: 0 12px 40px rgba(40, 30, 20, .3);
  animation: pop-in .3s cubic-bezier(.2, 1.4, .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: 13px;
  line-height: 1.8;
  padding-left: 20px;
  position: relative;
}

.help-list li::before {
  content: "●";
  position: absolute;
  left: 2px;
  color: var(--accent);
  font-size: 10px;
  top: 5px;
}

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

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

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

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

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

@media (max-width: 400px) {
  .title-jp { font-size: 28px; }
  #status { font-size: 14px; }
  .die { width: 38px; height: 38px; }
  .score-name { font-size: 12px; }
}

/* 320px 幅などでは「白（あなた）の番：サイコロを振ってください」が2行に折り返す。
   手番ごとに盤面が上下しないよう、状態表示に2行ぶんの高さを確保する */
@media (max-width: 359px) {
  #status {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

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