/* ============================================================
   ボーダークラウン - style.css
   ============================================================ */

:root {
  --bg: #f4f5fa;
  --bg-deco: #e8eaf3;
  --ink: #363a48;
  --ink-soft: #8a8ea0;
  --card: #ffffff;
  --line: #e0e3ee;
  --gold: #d9a514;
  --gold-dark: #b3880e;
  --accent: #4a7de0;
  --accent-dark: #3560bd;
  --shadow: 0 4px 14px rgba(45, 60, 110, .13);
  --shadow-soft: 0 2px 6px rgba(45, 60, 110, .09);
  --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, 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: 16px 16px calc(12px + env(safe-area-inset-bottom));
  /* forwards（both）で終わりの transform を残すと、画面が position: fixed の基準になり
     結果オーバーレイが画面全体ではなくこの枠の中に閉じ込められるので 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, opacity .12s ease;
}

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

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

.btn-primary {
  background: linear-gradient(180deg, #f3c93e, var(--gold));
  border-color: var(--gold-dark);
  color: #fff;
  text-shadow: 0 1px 2px rgba(90, 60, 0, .25);
}

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

.btn-small { font-size: 14px; padding: 9px 18px; }

.icon-btn {
  font-size: 20px;
  line-height: 1;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

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

/* ---------- セグメントボタン ---------- */

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

.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 8px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}

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

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

#screen-title { justify-content: center; gap: 6px; }

.title-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 380px;
  margin: auto 0;
}

.title-logo { width: 92px; height: 92px; }
.title-logo svg { width: 100%; height: 100%; filter: drop-shadow(0 6px 12px rgba(180, 130, 10, .35)); }

.title-jp {
  font-size: 34px;
  letter-spacing: .06em;
  color: var(--ink);
}

.title-en {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3em;
  color: var(--gold-dark);
  margin-top: -6px;
}

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

.menu-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

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

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

.config-group { display: flex; flex-direction: column; gap: 7px; }

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

.mark-inline { font-size: 12px; }
.mark-red-inline { color: #e0524a; }
.mark-blue-inline { color: #3f7fd6; }

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

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

.footer a { color: inherit; }

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

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

#screen-game { gap: 10px; }

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

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

/* プレイヤーカード */

#players {
  width: 100%;
  display: flex;
  gap: 8px;
}

.player-card {
  flex: 1;
  min-width: 0;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow-soft);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.player-card.active {
  border-color: var(--pc);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pc) 22%, transparent), var(--shadow-soft);
}

.pc-name {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
}

.pc-chip {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--pc);
}

.pc-score {
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.1;
}

.pc-unit { font-size: 11px; font-weight: 700; color: var(--ink-soft); margin-left: 2px; }

.pc-sub { font-size: 12px; font-weight: 700; color: var(--ink-soft); }

/* ステータス */

#status {
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 700;
}

.turn-chip {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  background: var(--pc);
}

/* 盤面 */

#board-wrap {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
}

#board {
  display: block;
  width: 100%;
  height: auto;
}

/* CPU の番などでキーボードのフォーカスを一時的に預けるだけなので枠は出さない */
#board:focus { outline: none; }

#board .dot { fill: #4a4f63; }

#board .diag-hint {
  stroke: #c3c8da;
  stroke-width: 2.5;
  stroke-dasharray: 5 6;
  stroke-linecap: round;
}

#board .edge-line.last { filter: drop-shadow(0 0 3px rgba(0, 0, 0, .28)); }

#board .edge-target {
  stroke: transparent;
  stroke-width: 24;
  cursor: pointer;
  outline: none;
}

@media (hover: hover) {
  #board .edge-target:hover { stroke: color-mix(in srgb, var(--cur) 38%, transparent); stroke-width: 8; }
}

#board .edge-target:focus-visible {
  stroke: color-mix(in srgb, var(--cur) 55%, transparent);
  stroke-width: 8;
}

#board .pop {
  animation: region-pop .45s ease both;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes region-pop {
  0% { opacity: 0; transform: scale(.6); }
  70% { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

/* ゲーム下部ボタン */

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

/* ---------- オーバーレイ共通 ---------- */

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

/* 結果パネルはヘッダーと広告の間に置き、画面の低い横向きのスマホ等で収まらないときはスクロールさせる */
#result-overlay {
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  overflow-y: auto;
}

#result-panel { margin: auto; }

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

#result-panel, #howto-panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: panel-in .25s ease both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

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

#result-mark {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: var(--pc);
  position: relative;
  box-shadow: var(--shadow-soft);
}

#result-mark::after {
  content: "👑";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

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

#result-detail {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 700;
}

.rr-rank { color: var(--ink-soft); flex-shrink: 0; }

.rr-chip {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--pc);
  flex-shrink: 0;
}

.rr-name { flex-shrink: 0; }

.rr-detail {
  flex: 1;
  text-align: right;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rr-total { flex-shrink: 0; font-size: 15px; }

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

/* ---------- あそびかた ---------- */

#howto-panel {
  align-items: stretch;
  max-height: min(82dvh, 640px);
  overflow-y: auto;
}

#howto-title { font-size: 20px; text-align: center; }

.howto-section { display: flex; flex-direction: column; gap: 5px; }

.howto-section h3 {
  font-size: 14px;
  color: var(--gold-dark);
  border-bottom: 2px solid var(--bg-deco);
  padding-bottom: 3px;
}

.howto-section ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.howto-section li {
  font-size: 13px;
  line-height: 1.65;
}

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

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

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

@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(600deg); }
}

/* ---------- レスポンシブ ---------- */

@media (max-width: 380px) {
  .pc-score { font-size: 18px; }
  .pc-name { font-size: 11px; }
  .title-jp { font-size: 28px; }
}

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