/* ドミノ - Dominoes */

:root {
  --felt-dark: #0d3b2e;
  --felt: #14523f;
  --felt-light: #1a6b52;
  --ink: #22262e;
  --cream: #f7f3e8;
  --cream-shade: #e4dcc8;
  --accent: #f2b134;
  --accent-deep: #d99a1b;
  --blue: #2e6df6;
  --danger: #e85d75;
  --text: #f2efe6;
  --text-dim: rgba(242, 239, 230, 0.72);
  --panel: rgba(8, 32, 25, 0.55);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { 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 Sans", sans-serif;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--felt-light) 0%, var(--felt) 45%, var(--felt-dark) 100%);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.hidden { display: none !important; }

#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;
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  /* 上下のセーフエリアは共通ヘッダー（--sgh-top）と広告枠（--ad-space）が含んでいるので二重に空けない。
     左右は横向きのノッチを避ける */
  padding:
    calc(10px + max(0px, var(--safe-top) - var(--sgh-top, 0px)))
    max(12px, env(safe-area-inset-right, 0px))
    calc(8px + max(0px, var(--safe-bottom) - var(--ad-space, 0px)))
    max(12px, env(safe-area-inset-left, 0px));
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

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

#screen-title {
  justify-content: space-between;
  text-align: center;
}

.title-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 0;
}

.title-logo svg {
  width: clamp(96px, 24vw, 140px);
  height: auto;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}

.title-jp {
  font-size: clamp(34px, 9vw, 52px);
  letter-spacing: 0.14em;
  font-weight: 800;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}

.title-desc {
  color: var(--text-dim);
  font-size: clamp(14px, 3.6vw, 16px);
  line-height: 1.7;
}

.menu-panel {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 18px 16px;
  margin-top: 8px;
  backdrop-filter: blur(4px);
}

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

.config-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-align: left;
}

.config-note {
  font-size: 12px;
  color: var(--text-dim);
  text-align: left;
  line-height: 1.6;
}

.seg {
  display: flex;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.seg-btn {
  flex: 1;
  padding: 10px 4px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.seg-btn.is-active {
  background: var(--accent);
  color: #3a2a05;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.btn {
  border-radius: 14px;
  font-weight: 700;
  transition: transform 0.12s, filter 0.15s;
}

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

.btn-big {
  padding: 15px 18px;
  font-size: 17px;
}

.btn-primary {
  background: linear-gradient(180deg, #ffcf5e, var(--accent) 55%, var(--accent-deep));
  color: #3a2a05;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.btn-ghost {
  padding: 11px 16px;
  font-size: 15px;
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.title-record {
  font-size: 13px;
  color: var(--text-dim);
  min-height: 1em;
}

/* ===== フッター ===== */

.footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.7;
  padding-top: 10px;
}

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

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

/* ===== ゲーム画面 ===== */

#screen-game {
  gap: 8px;
}

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

#game-mode-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s;
}

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

#scoreboard {
  display: flex;
  gap: 8px;
}

.score-card {
  flex: 1;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 7px 10px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.score-card.is-turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 14px rgba(242, 177, 52, 0.35);
}

.score-card-mid {
  flex-direction: column;
  align-items: center;
  gap: 1px;
  flex: 1.1;
}

.score-name { font-size: 12px; font-weight: 700; color: var(--text-dim); }
.score-value { font-size: 21px; font-weight: 800; }
.score-cap { font-size: 11px; color: var(--text-dim); }
.score-target { font-size: 11px; color: var(--text-dim); }

#cpu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 30px;
}

#cpu-hand {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
}

.tile-back {
  width: 15px;
  height: 26px;
  border-radius: 4px;
  background: linear-gradient(160deg, #3d7bff, #1e4dc0);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  display: inline-block;
}

.cpu-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  margin-left: 5px;
}

#boneyard-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap;
}

.pile-icon {
  width: 15px;
  height: 26px;
  border-radius: 4px;
  background: linear-gradient(160deg, #3d7bff, #1e4dc0);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}

#status {
  text-align: center;
  font-size: clamp(13px, 3.4vw, 15px);
  font-weight: 700;
  min-height: 1.3em;
}

/* ===== 盤面 ===== */

#board-wrap {
  flex: 1;
  position: relative;
  min-height: 200px;
  display: flex;
}

#board {
  flex: 1;
  position: relative;
  background:
    radial-gradient(110% 100% at 50% 30%, rgba(255, 255, 255, 0.05), transparent 60%),
    rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  box-shadow: inset 0 3px 16px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.tile {
  position: absolute;
  display: flex;
  background: linear-gradient(160deg, #fffdf6, var(--cream) 55%, var(--cream-shade));
  border-radius: 0.18em;
  box-shadow: 0 0.06em 0.18em rgba(0, 0, 0, 0.45), inset 0 0.03em 0 rgba(255, 255, 255, 0.8);
  border: 0.03em solid #b9ad92;
}

.tile.vert { flex-direction: column; }

.tile .half {
  position: relative;
  flex: 1;
}

.tile .divider {
  background: rgba(60, 52, 36, 0.45);
  border-radius: 1px;
}

.tile:not(.vert) .divider { width: 0.045em; margin: 0.1em 0; }
.tile.vert .divider { height: 0.045em; margin: 0 0.1em; }

.tile .dot {
  position: absolute;
  width: 19%;
  height: 19%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a5060, var(--ink) 65%);
  transform: translate(-50%, -50%);
}

.tile.pop {
  animation: tile-pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tile-pop {
  0% { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.drop-zone {
  position: absolute;
  border: 2px dashed var(--accent);
  border-radius: 6px;
  background: rgba(242, 177, 52, 0.16);
  animation: zone-pulse 1.1s ease-in-out infinite;
  z-index: 5;
}

.drop-zone:focus-visible {
  outline: 3px solid #fff;
}

@keyframes zone-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242, 177, 52, 0.5); }
  50% { box-shadow: 0 0 0 7px rgba(242, 177, 52, 0); }
}

#event-toast {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  background: rgba(8, 26, 20, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 10;
  animation: toast-in 0.25s ease-out;
  pointer-events: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== 手札 ===== */

#hand-wrap {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  padding: 4px 0;
}

.hand-tile {
  position: relative;
  padding: 0;
  border-radius: 8px;
  transition: transform 0.15s, filter 0.2s;
}

.hand-tile .tile {
  position: relative;
  width: 44px;
  height: 84px;
  font-size: 42px;
  left: auto;
  top: auto;
}

#hand.crowded .hand-tile .tile {
  width: 36px;
  height: 69px;
  font-size: 34px;
}

.hand-tile:disabled .tile {
  filter: grayscale(0.35) brightness(0.72);
}

.hand-tile.playable .tile {
  box-shadow: 0 0 0 2px var(--accent), 0 3px 10px rgba(0, 0, 0, 0.45);
}

.hand-tile.playable:hover { transform: translateY(-4px); }

.hand-tile.selected { transform: translateY(-8px); }

.hand-tile.selected .tile {
  box-shadow: 0 0 0 3px #fff, 0 0 16px rgba(255, 255, 255, 0.5);
}

.hand-tile:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

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

#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 18, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fade-in 0.25s ease-out;
  padding: 20px;
}

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

#result-panel {
  width: min(360px, 100%);
  background: linear-gradient(180deg, #1d5c47, #123c2f);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 22px;
  padding: 26px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: panel-in 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes panel-in {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#result-count {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

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

#result-sub {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.7;
  min-height: 1em;
}

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

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

#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 18, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 18px;
  animation: fade-in 0.2s ease-out;
}

#help-panel {
  width: min(460px, 100%);
  max-height: min(80dvh, 640px);
  overflow-y: auto;
  background: linear-gradient(180deg, #1d5c47, #123c2f);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 22px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

#help-title {
  font-size: 21px;
  text-align: center;
  letter-spacing: 0.1em;
}

.help-sub {
  font-size: 16px;
  color: var(--accent);
  margin-top: 4px;
}

.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.help-list li {
  font-size: 13.5px;
  line-height: 1.75;
  padding-left: 1.2em;
  position: relative;
  color: var(--text);
}

.help-list li::before {
  content: "●";
  position: absolute;
  left: 0;
  top: 0.15em;
  font-size: 0.7em;
  color: var(--accent);
}

.help-list strong { color: #ffd579; }

/* ===== 紙吹雪 ===== */

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

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

@keyframes confetti-fall {
  0% { transform: translateY(0) translateX(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) translateX(var(--drift, 0px)) rotate(560deg); opacity: 0.6; }
}

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

@media (min-width: 700px) {
  .hand-tile .tile {
    width: 52px;
    height: 100px;
    font-size: 50px;
  }
  #hand-wrap { min-height: 112px; }
  .tile-back { width: 17px; height: 30px; }
}

@media (max-height: 640px) {
  #hand-wrap { min-height: 78px; }
  .hand-tile .tile {
    width: 38px;
    height: 72px;
    font-size: 36px;
  }
}

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