/* ============================================================
   囲碁 - style.css
   ============================================================ */

:root {
  --bg: #f6f2ea;
  --bg-deco: #ece5d8;
  --ink: #3a352e;
  --ink-soft: #877f74;
  --card: #ffffff;
  --line: #e4dccf;
  --black-color: #26262c;
  --white-color: #a8823a;
  --accent: #2f8f63;
  --accent-dark: #226c4a;
  --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 Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "BIZ UDGothic", "Yu Gothic", "Meiryo", 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: 14px 14px calc(10px + env(safe-area-inset-bottom));
  /* both だと終了後も transform が残り、中の position: fixed（結果オーバーレイ）が
     画面全体ではなく .screen を基準に配置されてしまうので backwards にする */
  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, opacity .15s ease;
}

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

.btn-big { width: 100%; font-size: 18px; padding: 16px 24px; }
.btn-small { font-size: 14px; padding: 10px 18px; }
.btn-tiny { font-size: 13px; padding: 7px 14px; }

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

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

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--accent-dark), 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: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card);
  font-size: 18px;
  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: 12px;
  padding: 18px 0;
}

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

.title-logo svg { display: block; width: 100%; height: 100%; }

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

.title-jp {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: .02em;
  text-indent: 0;
}

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

.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; }

/* 設定パネル */

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

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

.config-note {
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin-top: 9px;
  text-align: center;
}

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

.seg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  border-radius: 16px;
}

.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;
}

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

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

/* インフォバー */

#infobar {
  width: 100%;
  max-width: 440px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.info-card {
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  padding: 7px 9px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: border-color .2s ease, transform .2s ease;
  min-width: 0;
}

.info-card.is-turn { transform: translateY(-3px); }
#info-black.is-turn { border-color: var(--black-color); }
#info-white.is-turn { border-color: var(--white-color); }

.info-stone {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 1px 3px rgba(60, 40, 10, .35);
}

.info-stone-black { background: radial-gradient(circle at 34% 30%, #6d6d76, #14141a 78%); }
.info-stone-white { background: radial-gradient(circle at 34% 30%, #ffffff, #cdc8bc 80%); border: 1px solid #c3bdb0; }

.info-body { min-width: 0; }

.info-name {
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-sub {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 700;
  line-height: 1.4;
  /* 収まらないときだけ折り返す（はみ出して中央の手数・コミに重ならないように） */
  white-space: normal;
}

#info-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  padding: 0 4px;
  white-space: nowrap;
}

/* ステータス */

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

#status .status-black { color: var(--black-color); }
#status .status-white { color: var(--white-color); }

#status.thinking::after {
  content: "";
  width: 14px;
  height: 14px;
  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: clamp(232px, min(94vw, calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px) - 296px)), 500px);
  aspect-ratio: 1;
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
}

/* inset の box-shadow は canvas の絵の下に隠れて見えないので outline で内側に描く */
#board:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

/* 確定タップ方式（19路など）: 押したまま指を動かす微調整がスクロールに奪われないようにする。
   ピンチでの拡大（iOS は user-scalable=no でも拡大できる）は止めない。pinch-zoom を解釈できない環境では none */
#board-wrap.is-fine #board { touch-action: none; touch-action: pinch-zoom; }

#board-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(40, 36, 30, .86);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 999px;
  pointer-events: none;
  animation: toast-in .2s ease both;
}

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

/* 確定バー（小さい盤で2タップ確定するとき） */

#confirm-bar {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

#confirm-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

#game-buttons {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* 整地（死石判定）バー */

#score-bar {
  margin-top: 10px;
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 12px 14px;
  text-align: center;
}

#score-bar-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.6;
}

#score-bar-count {
  font-size: 16px;
  font-weight: 800;
  margin: 6px 0 10px;
}

#score-bar-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

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

#result-overlay, #help-overlay {
  position: fixed;
  inset: 0;
  /* 共通ヘッダーと下部の広告に隠れないよう、その間に収める */
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(58, 53, 46, .45);
  animation: fade-in .25s ease both;
  padding: 20px;
  overflow-y: auto;
}

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

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

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

#result-stone {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  margin: 0 auto 10px;
  box-shadow: 0 3px 8px rgba(60, 40, 10, .3);
}

#result-stone.stone-black { background: radial-gradient(circle at 34% 30%, #6d6d76, #14141a 78%); }
#result-stone.stone-white { background: radial-gradient(circle at 34% 30%, #ffffff, #cdc8bc 80%); border: 1px solid #c3bdb0; }
#result-stone.stone-draw { background: linear-gradient(135deg, #26262c 0 50%, #efeae0 50% 100%); }

#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: 14px;
  line-height: 1.6;
}

#result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 16px;
}

#result-table th, #result-table td {
  padding: 5px 4px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

#result-table th { font-size: 12px; color: var(--ink-soft); }
#result-table td:first-child, #result-table th:first-child {
  text-align: left;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

#result-table .rt-total td {
  font-weight: 800;
  font-size: 16px;
  border-bottom: none;
}

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

/* ---------- 遊び方 ---------- */

#help-panel {
  max-width: 380px;
  text-align: left;
}

#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: 9px;
  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: 0;
  top: 0;
  font-size: 11px;
  color: var(--accent);
}

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

#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: 18px;
  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: 14px; }

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

@media (max-width: 359px) {
  #infobar { gap: 6px; }
  .info-card { padding: 6px; gap: 6px; }
  .info-stone { width: 18px; height: 18px; }
  .info-sub { font-size: 10px; }
}

@media (max-height: 700px) {
  .title-logo { width: 76px; height: 76px; border-radius: 20px; }
  .title-jp { font-size: 30px; }
  .title-desc { font-size: 13px; }
  .config-group { padding: 10px 12px 12px; }
}

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