/* 4ブロックス */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --c-blue: #3f7ce8;
  --c-yellow: #eec411;
  --c-red: #e2493f;
  --c-green: #3aa356;
  --bg-panel: rgba(255, 255, 255, 0.07);
  --bg-panel-border: rgba(255, 255, 255, 0.12);
}

html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background: linear-gradient(160deg, #232f55 0%, #16203e 45%, #101830 100%);
  color: #f2f4fa;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* viewport-fit=cover 用セーフエリア */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
button:disabled { cursor: default; }

/* ---------- 汎用ボタン ---------- */
.btn {
  display: inline-block;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  color: #fff;
  transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(180deg, #4d8bf5, #2f63cf);
  box-shadow: 0 4px 14px rgba(47, 99, 207, 0.45);
  padding: 12px 28px;
  font-size: 16px;
}
.btn-primary:disabled {
  filter: grayscale(0.7) brightness(0.6);
  box-shadow: none;
}
.btn-sub {
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  color: #cdd6ea;
  padding: 10px 22px;
  font-size: 14px;
}
.btn-big {
  width: 100%;
  padding: 14px 20px;
  font-size: 17px;
}

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  color: #fff;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  line-height: 1;
}

/* ---------- 画面共通 ---------- */
.screen {
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- タイトル画面 ---------- */
#screen-title { justify-content: center; padding: 24px 16px; }
.title-inner {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.title-logo {
  display: grid;
  grid-template-columns: repeat(2, 34px);
  gap: 6px;
  margin-bottom: 18px;
}
.logo-block {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.3), inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.35);
  animation: float 2.6s ease-in-out infinite;
}
.lb-blue { background: var(--c-blue); }
.lb-yellow { background: var(--c-yellow); animation-delay: 0.3s; }
.lb-red { background: var(--c-red); animation-delay: 0.6s; }
.lb-green { background: var(--c-green); animation-delay: 0.9s; }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.title-jp {
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.title-en {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.45em;
  color: #8fa3cc;
  margin: 4px 0 14px;
}
.title-desc {
  font-size: 14px;
  line-height: 1.7;
  color: #c3cde2;
  margin-bottom: 22px;
}

.menu-panel {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}
.btn-mode {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.14);
  text-align: left;
}
.btn-mode:hover { background: rgba(255, 255, 255, 0.15); }
.btn-mode-icon { font-size: 24px; }

.opt-group { text-align: left; }
.opt-label { font-size: 13px; color: #a9b6d4; margin-bottom: 8px; font-weight: 700; }
.seg {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: #aab7d4;
  font-weight: 700;
  font-size: 14px;
  padding: 9px 0;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.seg-btn.active {
  background: linear-gradient(180deg, #4d8bf5, #2f63cf);
  color: #fff;
}

.howto {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  border-radius: 14px;
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  margin-bottom: 24px;
}
.howto summary {
  font-weight: 700;
  cursor: pointer;
  color: #cdd6ea;
}
.howto ul {
  margin: 10px 0 4px;
  padding-left: 18px;
  color: #b6c1da;
  line-height: 1.8;
}
.howto strong { color: #ffd76a; }

.title-footer {
  font-size: 11.5px;
  color: #7e8db0;
  line-height: 1.9;
}
.title-footer a { color: #9fb4e0; text-decoration: none; }
.title-footer a:hover { text-decoration: underline; }

/* ---------- ゲーム画面 ---------- */
#screen-game {
  padding: 10px 10px 24px;
  align-items: stretch;
}
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 960px;
  margin: 0 auto 8px;
}
.game-header-title {
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 0.06em;
}

.game-layout {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.board-col { min-width: 0; }
.side-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

#players-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.chip {
  flex: 1 1 100px;
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  border-left: 5px solid var(--chip-color);
  border-radius: 10px;
  padding: 6px 9px;
  min-width: 96px;
  opacity: 0.75;
  transition: opacity 0.2s, box-shadow 0.2s;
}
.chip.current {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--chip-color), 0 3px 12px rgba(0, 0, 0, 0.3);
}
.chip.done { opacity: 0.45; }
.chip-name {
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
}
.chip-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--chip-color);
  flex: 0 0 auto;
}
.chip-info { font-size: 11px; color: #a9b6d4; margin-top: 2px; white-space: nowrap; }

#board-wrap {
  display: flex;
  justify-content: center;
}
#board {
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

#turn-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  border-radius: 12px;
  padding: 10px;
  font-weight: 800;
  font-size: 15px;
}
.turn-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--turn-color, #888);
  box-shadow: 0 0 8px var(--turn-color, transparent);
}

#piece-controls {
  display: flex;
  gap: 8px;
}
.ctrl-btn {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--bg-panel-border);
  background: var(--bg-panel);
  color: #fff;
  font-size: 21px;
  line-height: 1;
  flex: 0 0 auto;
}
.ctrl-btn:disabled { opacity: 0.35; }
.btn-place { flex: 1; padding: 10px; font-size: 15px; }

#tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 14px;
  padding: 10px;
  align-content: flex-start;
  justify-content: center;
}
.tray-piece {
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.12s, border-color 0.12s;
}
.tray-piece:hover { background: rgba(255, 255, 255, 0.13); }
.tray-piece.selected {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.16);
}
.tray-piece:disabled { opacity: 0.5; }
.tray-hint {
  font-size: 11px;
  color: #8b99bd;
  line-height: 1.7;
  text-align: center;
}

/* デスクトップ: 盤面とサイドを横並び */
@media (min-width: 900px) {
  .game-layout { flex-direction: row; align-items: flex-start; }
  .board-col { flex: 1 1 auto; }
  .side-col { flex: 0 0 330px; position: sticky; top: 10px; }
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 28, 0.78);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  /* 共通ヘッダー・フッター固定バナー広告（どちらもこの上に重なる）に隠れないよう、上下とも両者の高いほうだけ空ける。
     上下対称なので中央寄せの位置は変わらない。収まらない画面（横向きのスマホ等）では中身をスクロールできる */
  padding: max(20px, var(--sgh-top, 0px), var(--ad-space, 0px)) 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 50;
}
/* 収まるときは中央、収まらないときは上端から（align-items: center だと上がはみ出して届かなくなる） */
.overlay > * { margin: auto; }
.modal-box {
  background: #1d2748;
  border: 1px solid var(--bg-panel-border);
  border-radius: 18px;
  padding: 26px 24px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  font-size: 15px;
  line-height: 1.8;
}
.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

/* ---------- 結果 ---------- */
.result-inner {
  background: #1d2748;
  border: 1px solid var(--bg-panel-border);
  border-radius: 20px;
  padding: 26px 22px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  animation: pop 0.35s ease-out;
}
@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.result-title {
  font-size: 15px;
  font-weight: 700;
  color: #8fa3cc;
  letter-spacing: 0.2em;
}
#result-winner {
  font-size: 23px;
  font-weight: 900;
  margin: 10px 0 18px;
}
#result-ranking {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
.result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}
.result-medal { width: 24px; font-size: 17px; }
.result-name { font-weight: 700; }
.result-detail {
  flex: 1;
  text-align: right;
  font-size: 11.5px;
  color: #a9b6d4;
}
.result-score {
  font-weight: 900;
  font-size: 16px;
  min-width: 52px;
  text-align: right;
}
.result-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

#btn-show-result {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(16px + env(safe-area-inset-bottom) + var(--ad-space, 0px));
  z-index: 40;
  padding: 12px 20px;
}

/* ---------- トースト ---------- */
#toast {
  position: fixed;
  left: 50%;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(84px + env(safe-area-inset-bottom) + var(--ad-space, 0px));
  transform: translateX(-50%);
  background: rgba(15, 20, 40, 0.92);
  border: 1px solid var(--bg-panel-border);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 60;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast.show { animation: toast-in 0.25s ease-out; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

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