/* ブロック・ドミノ固有スタイル */

.game-panel {
  margin-top: 20px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--md-sys-color-primary) 14%, var(--md-sys-color-surface));
  color: var(--md-sys-color-on-surface);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.status-pill.is-player {
  background: color-mix(in srgb, #22d3ee 22%, var(--md-sys-color-surface));
  color: #0e7490;
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.45);
}

.status-pill.is-cpu {
  background: color-mix(in srgb, #c084fc 20%, var(--md-sys-color-surface));
  color: #7e22ce;
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.4);
}

.status-pill.is-pass {
  background: color-mix(in srgb, #f59e0b 20%, var(--md-sys-color-surface));
  color: #92400e;
}

.status-pill.is-win {
  background: color-mix(in srgb, var(--success, #16a34a) 18%, var(--md-sys-color-surface));
  color: #15803d;
}

.status-pill.is-lose {
  background: color-mix(in srgb, #f43f5e 16%, var(--md-sys-color-surface));
  color: #be123c;
}

.status-pill.is-draw {
  background: color-mix(in srgb, #64748b 18%, var(--md-sys-color-surface));
  color: #334155;
}

/* 結果 */

.bd-result {
  max-width: min(100%, 760px);
  margin: 0 auto 14px;
  padding: 14px 16px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
  text-align: center;
  animation: bd-fade-in 0.25s ease-out;
}

.bd-result.is-win {
  border-color: color-mix(in srgb, #22c55e 40%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, #22c55e 8%, var(--md-sys-color-surface));
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.25);
}

.bd-result.is-lose {
  border-color: color-mix(in srgb, #f43f5e 35%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, #f43f5e 7%, var(--md-sys-color-surface));
}

.bd-result.is-draw {
  border-color: color-mix(in srgb, #64748b 35%, var(--md-sys-color-outline-variant));
}

.bd-result__title {
  margin: 0 0 6px;
  font-size: 1.15rem;
  font-weight: 800;
}

.bd-result__detail {
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 600;
}

.bd-result__score {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 24px;
  margin: 0 0 14px;
}

.bd-result__score div {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.bd-result__score dt {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.85rem;
  font-weight: 600;
}

.bd-result__score dd {
  margin: 0;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bd-result__actions {
  display: flex;
  justify-content: center;
}

/* 盤面全体 */

.bd-stage {
  display: grid;
  gap: 12px;
  max-width: min(100%, 760px);
  margin: 0 auto;
  padding: 16px 14px;
  border-radius: 22px;
  background:
    radial-gradient(120% 90% at 15% 0%, rgba(56, 189, 248, 0.16), transparent 55%),
    radial-gradient(120% 90% at 85% 100%, rgba(168, 85, 247, 0.18), transparent 55%),
    linear-gradient(160deg, #15284f 0%, #0f1c38 55%, #0c1630 100%);
  border: 1px solid rgba(56, 189, 248, 0.38);
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.35),
    0 0 22px rgba(56, 189, 248, 0.12),
    0 12px 28px rgba(15, 23, 42, 0.28);
  color: #e2e8f0;
}

.bd-cpu__label,
.bd-player__label {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 8px;
  color: rgba(226, 232, 240, 0.85);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.bd-count {
  color: rgba(226, 232, 240, 0.72);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0;
}

.bd-count strong {
  color: #f8fafc;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

/* CPU の伏せ牌 */

.bd-cpu__hand {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 26px;
}

.bd-back {
  position: relative;
  width: 14px;
  height: 26px;
  border: 1px solid rgba(165, 180, 252, 0.5);
  border-radius: 3px;
  background: linear-gradient(160deg, #3b4f86, #24346a);
}

.bd-back::after {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  top: 50%;
  height: 1px;
  background: rgba(165, 180, 252, 0.45);
}

/* ドミノ牌 */

.bd-tile {
  --s: 30px;
  display: inline-grid;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: calc(var(--s) * 0.18);
  background: linear-gradient(160deg, #ffffff 0%, #f1f5f9 60%, #e6eefb 100%);
  box-shadow: 0 2px 0 #94a3b8, 0 3px 6px rgba(2, 6, 23, 0.35);
  color: #0f172a;
  font: inherit;
}

.bd-tile--h {
  grid-template-columns: var(--s) var(--s);
  grid-template-rows: var(--s);
}

.bd-tile--v {
  grid-template-columns: var(--s);
  grid-template-rows: var(--s) var(--s);
}

.bd-tile--h .bd-half + .bd-half {
  border-left: 2px solid #94a3b8;
}

.bd-tile--v .bd-half + .bd-half {
  border-top: 2px solid #94a3b8;
}

.bd-half {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: calc(var(--s) * 0.13);
}

.bd-pip {
  align-self: center;
  justify-self: center;
  width: calc(var(--s) * 0.2);
  height: calc(var(--s) * 0.2);
  border-radius: 50%;
  background: #0f172a;
}

.bd-pip--0 { grid-area: 1 / 1; }
.bd-pip--2 { grid-area: 1 / 3; }
.bd-pip--3 { grid-area: 2 / 1; }
.bd-pip--4 { grid-area: 2 / 2; }
.bd-pip--5 { grid-area: 2 / 3; }
.bd-pip--6 { grid-area: 3 / 1; }
.bd-pip--8 { grid-area: 3 / 3; }

/* 場 */

.bd-board {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 3px;
  min-height: 92px;
  padding: 14px 10px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 16px;
  background: rgba(10, 20, 42, 0.55);
}

.bd-tile.is-last--player {
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.85), 0 0 12px rgba(34, 211, 238, 0.4);
}

.bd-tile.is-last--cpu {
  box-shadow: 0 0 0 2px rgba(192, 132, 252, 0.85), 0 0 12px rgba(192, 132, 252, 0.4);
}

.bd-tile.is-new {
  animation: bd-place 0.22s ease-out;
}

.bd-end {
  appearance: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 44px;
  height: 60px;
  margin-inline: 4px;
  padding: 0;
  border: 1px dashed rgba(148, 163, 184, 0.45);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.6);
  color: #e2e8f0;
  font: inherit;
  cursor: default;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.bd-end__label {
  color: rgba(226, 232, 240, 0.7);
  font-size: 0.62rem;
  font-weight: 700;
}

.bd-end strong {
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.25rem;
  line-height: 1;
}

.bd-end.is-target {
  border: 2px solid #22d3ee;
  background: rgba(34, 211, 238, 0.16);
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.5);
  cursor: pointer;
}

.bd-end.is-target:hover {
  background: rgba(34, 211, 238, 0.26);
}

.bd-end:focus-visible {
  outline: 2px solid #fef08a;
  outline-offset: 2px;
}

.bd-board.is-choosing {
  border-color: rgba(34, 211, 238, 0.45);
}

/* 使わない牌・ターン */

.bd-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}

.bd-unused {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  color: rgba(226, 232, 240, 0.72);
  font-size: 0.8rem;
  font-weight: 600;
}

.bd-unused strong {
  color: rgba(248, 250, 252, 0.9);
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-variant-numeric: tabular-nums;
}

.bd-pass-badge {
  padding: 1px 8px;
  border: 1px solid rgba(251, 191, 36, 0.7);
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.14);
  color: #fde68a;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.bd-pass-badge[hidden] {
  display: none;
}

.bd-turn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.bd-turn__text {
  color: #f8fafc;
  font-size: 0.95rem;
  font-weight: 700;
}

.bd-message {
  min-height: 46px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 12px;
  background: rgba(10, 20, 42, 0.5);
  color: rgba(226, 232, 240, 0.9);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
}

/* 手札 */

.bd-hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 80px;
  padding-top: 10px;
}

.bd-hand-tile {
  --s: 34px;
  appearance: none;
  cursor: default;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.bd-hand-tile {
  position: relative;
}

.bd-hand-tile.is-playable::after {
  content: "✓";
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid #0e7490;
  border-radius: 50%;
  background: #22d3ee;
  color: #082f49;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
}

.bd-hand-tile.is-playable {
  border-color: #22d3ee;
  box-shadow:
    0 0 0 2px rgba(34, 211, 238, 0.55),
    0 0 12px rgba(34, 211, 238, 0.35),
    0 3px 0 #94a3b8;
  transform: translateY(-6px);
  cursor: pointer;
}

.bd-hand-tile.is-playable:hover {
  box-shadow:
    0 0 0 2px rgba(34, 211, 238, 0.8),
    0 0 18px rgba(34, 211, 238, 0.5),
    0 3px 0 #94a3b8;
  transform: translateY(-9px);
}

.bd-hand-tile.is-unplayable {
  filter: brightness(0.74) saturate(0.85);
}

.bd-hand-tile.is-selected,
.bd-hand-tile.is-selected:hover {
  border-color: #c084fc;
  box-shadow:
    0 0 0 3px rgba(192, 132, 252, 0.9),
    0 0 18px rgba(192, 132, 252, 0.55),
    0 3px 0 #94a3b8;
  transform: translateY(-10px);
}

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

.bd-hand-tile.is-selected::after {
  content: "選択中";
  top: -10px;
  right: 50%;
  width: auto;
  height: auto;
  padding: 1px 5px;
  border-color: #7e22ce;
  border-radius: 999px;
  background: #c084fc;
  color: #2e1065;
  font-size: 0.6rem;
  white-space: nowrap;
  transform: translateX(50%);
}

/* パス */

.bd-pass {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(251, 191, 36, 0.6);
  border-radius: 14px;
  background: rgba(10, 20, 42, 0.6);
}

.bd-pass[hidden] {
  display: none;
}

.bd-pass__text {
  margin: 0;
  color: #fde68a;
  font-size: 0.9rem;
  font-weight: 700;
}

.bd-pass .btn {
  min-width: 140px;
  min-height: 46px;
}

/* 左右選択 */

.bd-side-choice {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(192, 132, 252, 0.6);
  border-radius: 14px;
  background: rgba(10, 20, 42, 0.6);
  box-shadow: 0 0 14px rgba(192, 132, 252, 0.2);
}

.bd-side-choice__text {
  margin: 0 0 10px;
  color: #e9d5ff;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
}

.bd-side-choice__actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

.bd-side-choice__actions .btn {
  min-height: 46px;
  padding-inline: 10px;
  line-height: 1.25;
}

.bd-side-choice__actions .btn small {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.9;
}

.bd-guide {
  max-width: min(100%, 760px);
  margin: 12px auto 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.88rem;
  line-height: 1.55;
}

.game-controls {
  max-width: min(100%, 760px);
  margin: 14px auto 0;
}

@keyframes bd-place {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: none; }
}

@keyframes bd-fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .bd-tile.is-new,
  .bd-result {
    animation: none;
  }

  .bd-hand-tile {
    transition: none;
  }
}

@media (max-width: 640px) {
  .bd-stage {
    padding: 12px 10px;
    border-radius: 18px;
  }

  .bd-board .bd-tile {
    --s: 26px;
  }
}

@media (max-width: 480px) {
  .bd-stage {
    gap: 10px;
    margin-inline: -10px;
    padding: 10px 8px 12px;
  }

  .bd-board {
    gap: 6px 2px;
    min-height: 76px;
    padding: 10px 4px;
  }

  .bd-board .bd-tile {
    --s: 23px;
  }

  .bd-end {
    width: 36px;
    height: 50px;
    margin-inline: 2px;
  }

  .bd-hand {
    gap: 6px;
  }

  .bd-hand-tile {
    --s: 30px;
  }

  .bd-back {
    width: 11px;
    height: 20px;
  }

  .bd-cpu__hand {
    gap: 3px;
    min-height: 20px;
  }

  .bd-message {
    min-height: 0;
    font-size: 0.84rem;
  }

  .bd-side-choice__actions {
    grid-template-columns: 1fr 1fr;
  }

  .bd-side-choice__actions .btn {
    padding-inline: 6px;
    font-size: 0.85rem;
  }

  .bd-side-choice__actions #place-cancel-btn {
    grid-column: 1 / -1;
  }
}

/* 外枠・HUD・操作は共通UI。牌と対局盤面のみ固有の配置を使う。 */
html.gs-playing .game-panel { align-items: center; }
html.gs-playing .game-panel > .gs-bar,
html.gs-playing .game-panel > .gs-hud,
html.gs-playing .bd-board-wrap,
html.gs-playing .bd-guide,
html.gs-playing .game-controls {
  width: 100%;
  max-width: 640px;
  flex: none;
}
html.gs-playing .status-pill {
  min-height: 22px;
  padding: 0 6px;
  background: transparent;
  color: var(--play-accent);
  box-shadow: none;
}
html.gs-playing .status-pill.is-cpu { color: #d8b4fe; }
html.gs-playing .status-pill.is-pass { color: #fde68a; }
html.gs-playing .status-pill.is-lose { color: #fda4af; }
html.gs-playing .bd-board-wrap { position: relative; }
html.gs-playing .bd-stage {
  max-width: none;
  margin: 0;
  border-color: var(--play-border);
  background: var(--play-bg);
  box-shadow: none;
}
html.gs-playing .bd-cpu__label { min-height: 24px; }
html.gs-playing .bd-message {
  height: calc(4.5em + 22px);
  min-height: calc(4.5em + 22px);
  display: grid;
  align-content: center;
  color: var(--play-text);
  border-color: var(--play-border);
  background: var(--play-hud-bg);
}
/* 選択やパスの案内は手牌の下に確保した同じ領域に表示する。 */
html.gs-playing .bd-player { position: relative; padding-bottom: 100px; }
html.gs-playing .bd-player__label { flex-wrap: wrap; }
html.gs-playing .bd-pass,
html.gs-playing .bd-side-choice {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0;
}
html.gs-playing .bd-result {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 18px;
  background: rgba(11, 20, 42, .96);
  border-color: var(--play-border);
  color: var(--play-text);
  backdrop-filter: blur(5px);
}
html.gs-playing .bd-result__detail,
html.gs-playing .bd-result__score dt { color: var(--play-text-muted); }
html.gs-playing .bd-guide { color: var(--play-text-muted); font-size: .8rem; }
html.gs-playing .game-controls { justify-content: center; margin-top: 12px; }
@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .game-panel {
    padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top));
  }
  html.gs-playing .game-panel > .gs-bar { margin-bottom: 28px; }
  html.gs-playing .game-panel > .gs-hud { margin-bottom: 20px; }
  html.gs-playing .bd-stage { gap: 18px; padding: 20px; }
  html.gs-playing .bd-message { height: calc(3em + 22px); min-height: calc(3em + 22px); }
}
/* 最大13枚の場と7枚の手牌に先に高さを確保し、配牌や進行で操作を動かさない。 */
html.gs-playing .bd-board {
  height: 160px;
  min-height: 160px;
  overflow-y: auto;
  align-content: center;
}
html.gs-playing .bd-hand { height: 90px; min-height: 90px; align-content: start; }
@media (max-width: 480px) {
  html.gs-playing .bd-hand { height: 132px; min-height: 132px; }
}

/* 操作の長文は詳細ページと読み上げに保持する。 */
html.gs-playing .bd-guide {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (max-width: 480px) {
  html.gs-playing .bd-player { padding-bottom: 132px; }
  html.gs-playing .bd-board { height: 180px; min-height: 180px; }
}
/* 左右選択は場に重ね、スマホでも手牌と再開操作の間を空けすぎない。 */
html.gs-playing .bd-player { padding-bottom: 56px; }
html.gs-playing .bd-side-choice {
  top: 74px;
  bottom: auto;
  left: 12px;
  right: 12px;
  z-index: 2;
  background: rgba(11, 20, 42, .97);
}
html.gs-playing .bd-player { position: static; }
html.gs-playing .bd-pass { bottom: 12px; left: 12px; right: 12px; padding: 6px; }
@media (max-width: 480px) {
  html.gs-playing .bd-hand { height: 76px; min-height: 76px; }
}
@media (max-width: 340px) {
  html.gs-playing .bd-hand { height: 132px; min-height: 132px; }
}
