/* バックギャモン固有スタイル */

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

.bg-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  max-width: min(100%, 720px);
  margin: 0 auto 14px;
  padding: 12px 14px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
}

.bg-scores {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.bg-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 4.8rem;
  padding: 6px 10px;
  border-radius: var(--md-sys-shape-corner-medium);
}

.bg-score--player {
  background: color-mix(in srgb, #22d3ee 16%, var(--md-sys-color-surface));
}

.bg-score--cpu {
  background: color-mix(in srgb, #c084fc 16%, var(--md-sys-color-surface));
}

.bg-score__label {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.bg-score__value {
  color: var(--md-sys-color-on-surface);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.bg-score__meta {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.68rem;
  font-weight: 600;
}

.bg-status__main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
}

.bg-status__text {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.95rem;
  font-weight: 600;
}

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

.status-pill.is-cpu {
  background: color-mix(in srgb, #c084fc 20%, var(--md-sys-color-surface));
  color: #7e22ce;
}

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

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

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

.bg-result {
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  text-align: center;
  animation: bg-result-in 200ms ease-out;
}

.bg-result.is-win {
  border: 1px solid color-mix(in srgb, var(--success, #16a34a) 38%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, var(--success, #16a34a) 10%, var(--md-sys-color-surface));
}

.bg-result.is-lose {
  border: 1px solid color-mix(in srgb, #ef4444 34%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, #ef4444 10%, var(--md-sys-color-surface));
}

.bg-result__title {
  margin: 0 0 4px;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.bg-result__detail {
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

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

@keyframes bg-result-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bg-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  max-width: min(100%, 720px);
  margin: 0 auto 12px;
  padding: 0;
  list-style: none;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.82rem;
  font-weight: 600;
}

.bg-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.bg-legend__swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.bg-legend__swatch--player {
  background: linear-gradient(160deg, #67e8f9, #0891b2);
}

.bg-legend__swatch--cpu {
  background: linear-gradient(160deg, #f0abfc, #a21caf);
  border-radius: 4px;
}

.bg-dice-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  max-width: min(100%, 720px);
  margin: 0 auto 12px;
}

.bg-dice-label {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.82rem;
  font-weight: 700;
}

.bg-dice {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.bg-die {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  min-height: 2.4rem;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, #38bdf8 45%, #1e293b);
  background: linear-gradient(160deg, #1e3a5f, #0f172a);
  color: #e2e8f0;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.12), 0 4px 12px rgba(8, 20, 48, 0.28);
}

.bg-die.is-used {
  opacity: 0.42;
  text-decoration: line-through;
  border-color: #475569;
  box-shadow: none;
}

.bg-dice__empty {
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 600;
}

.bg-board-wrap {
  --bg-frame: #38bdf8;
  --bg-board: #0d1a36;
  --bg-point-a: #1a3a66;
  --bg-point-b: #2a1f4d;
  --bg-player: #22d3ee;
  --bg-cpu: #e879f9;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  overflow: hidden;
}

.bg-board {
  display: grid;
  grid-template-columns: minmax(52px, 0.18fr) minmax(0, 1fr) minmax(52px, 0.18fr);
  gap: 8px;
  padding: 10px;
  border-radius: 18px;
  border: 2px solid color-mix(in srgb, var(--bg-frame) 70%, #0b1224);
  background:
    radial-gradient(ellipse at 20% 15%, rgba(56, 189, 248, 0.16), transparent 42%),
    radial-gradient(ellipse at 80% 85%, rgba(192, 132, 252, 0.14), transparent 40%),
    linear-gradient(160deg, #14284f 0%, #0d1a36 55%, #0a1428 100%);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.12), 0 10px 28px rgba(8, 18, 40, 0.28);
}

.bg-off {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 4px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(8, 18, 40, 0.45);
  min-height: 100%;
  cursor: default;
}

.bg-off.is-legal-to {
  border-color: #67e8f9;
  box-shadow: 0 0 0 2px rgba(103, 232, 249, 0.35);
  cursor: pointer;
}

.bg-off__label {
  color: #cbd5e1;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.2;
}

.bg-off__stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
  min-height: 80px;
}

.bg-off__count {
  color: #e2e8f0;
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bg-tray {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.bg-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr)) minmax(18px, 0.35fr) repeat(6, minmax(0, 1fr));
  gap: 2px;
  min-height: 0;
}

.bg-bar-gap {
  min-width: 0;
}

.bg-point {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 112px;
  padding: 2px;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bg-point--bottom {
  flex-direction: column-reverse;
}

.bg-point__tri {
  position: absolute;
  inset: 4px 2px;
  pointer-events: none;
  opacity: 0.92;
}

.bg-point--top .bg-point__tri {
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.bg-point--bottom .bg-point__tri {
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
}

.bg-point.is-a .bg-point__tri {
  background: linear-gradient(180deg, #1e4b7a, #132f52);
}

.bg-point.is-b .bg-point__tri {
  background: linear-gradient(180deg, #3b2763, #241845);
}

.bg-point--bottom.is-a .bg-point__tri {
  background: linear-gradient(0deg, #1e4b7a, #132f52);
}

.bg-point--bottom.is-b .bg-point__tri {
  background: linear-gradient(0deg, #3b2763, #241845);
}

.bg-point__stack {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: 6px 0;
  min-height: 84px;
}

.bg-point--bottom .bg-point__stack {
  flex-direction: column-reverse;
}

.bg-point__num {
  position: relative;
  z-index: 1;
  color: rgba(226, 232, 240, 0.72);
  font-size: 0.62rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  pointer-events: none;
}

.bg-point.is-legal-from {
  outline: 2px solid rgba(103, 232, 249, 0.55);
  outline-offset: -2px;
  border-radius: 8px;
}

.bg-point.is-selected {
  outline: 2px solid #67e8f9;
  outline-offset: -2px;
  border-radius: 8px;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.28);
}

.bg-point.is-legal-to .bg-point__tri {
  box-shadow: inset 0 0 0 2px #67e8f9;
  filter: brightness(1.25);
}

.bg-point.is-legal-to::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #67e8f9;
  box-shadow: 0 0 8px rgba(103, 232, 249, 0.7);
  transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
}

.bg-point--top.is-legal-to::after {
  bottom: 10px;
}

.bg-point--bottom.is-legal-to::after {
  top: 10px;
}

.bg-mid {
  display: flex;
  justify-content: center;
  min-height: 56px;
}

.bg-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  width: min(100%, 220px);
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px dashed rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.55);
}

.bg-bar.is-legal-from,
.bg-bar.is-selected {
  border-style: solid;
  border-color: #67e8f9;
  box-shadow: 0 0 0 1px rgba(103, 232, 249, 0.35);
  cursor: pointer;
}

.bg-bar__label {
  color: #94a3b8;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.bg-bar__slot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 28px;
}

.bg-checker {
  width: clamp(14px, 3.2vw, 22px);
  height: clamp(14px, 3.2vw, 22px);
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.35);
}

.bg-checker--player {
  background: linear-gradient(160deg, #67e8f9, #0891b2);
  border: 1px solid rgba(207, 250, 254, 0.55);
}

.bg-checker--cpu {
  background: linear-gradient(160deg, #f0abfc, #a21caf);
  border: 1.5px solid rgba(253, 224, 255, 0.7);
  border-radius: 30% 40% 35% 45%;
}

.bg-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.2rem;
  padding: 0 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  color: #f8fafc;
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 1.4;
}

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

.game-controls {
  margin-top: 14px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .bg-board {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 10px;
  }

  .bg-off--cpu {
    order: 0;
    flex-direction: row;
    min-height: 0;
    padding: 8px 10px;
  }

  .bg-tray {
    order: 1;
  }

  .bg-off--player {
    order: 2;
    flex-direction: row;
    min-height: 0;
    padding: 8px 10px;
  }

  .bg-off__stack {
    flex-direction: row;
    min-height: 36px;
    justify-content: flex-start;
  }

  .bg-point {
    min-height: 96px;
  }

  .bg-point__stack {
    min-height: 72px;
  }
}

@media (max-width: 420px) {
  .bg-point {
    min-height: 84px;
    padding: 1px;
  }

  .bg-point__num {
    font-size: 0.55rem;
  }

  .bg-checker {
    width: 12px;
    height: 12px;
  }

  .bg-row {
    gap: 1px;
  }

  .bg-die {
    min-width: 2.1rem;
    min-height: 2.1rem;
    font-size: 0.95rem;
  }
}

/* 外枠・HUD・共通操作は15パズル／パイプパズルと同じ部品を使う。 */
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 .game-panel > .game-controls,
.bg-stage { width: 100%; max-width: 640px; flex: none; }
.bg-stage { position: relative; }
html.gs-playing .bg-status__main {
  justify-content: center;
  flex-wrap: nowrap;
  min-height: 3.6em;
  margin-bottom: 10px;
}
html.gs-playing .bg-status__text { color: var(--play-text); font-size: .82rem; }
html.gs-playing .bg-dice-wrap { min-height: 38px; margin-bottom: 8px; }
html.gs-playing .bg-dice-label { color: var(--play-text-muted); }
html.gs-playing .bg-board-wrap { max-width: none; }
html.gs-playing .bg-board { border-color: var(--play-border); }
html.gs-playing .game-controls { justify-content: center; margin-top: 12px; }
html.gs-playing .bg-guide {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
html.gs-playing .bg-result {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: none;
  margin: 0;
  padding: 16px;
  background: rgba(11, 20, 42, .94);
  color: var(--play-text);
  backdrop-filter: blur(5px);
}
@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: 24px; }
  html.gs-playing .game-controls { margin-top: 24px; }
}
/* 狭幅ではベアオフを上下に置き、24ポイントの盤面幅を確保する。 */
@media (max-width: 720px) {
  html.gs-playing .bg-board { padding: 6px; gap: 5px; }
  html.gs-playing .bg-off { padding: 4px 8px; gap: 6px; }
  html.gs-playing .bg-off__stack { min-height: 20px; }
  html.gs-playing .bg-off__label,
  html.gs-playing .bg-off__count { font-size: .65rem; }
  html.gs-playing .bg-mid { min-height: 40px; }
  html.gs-playing .bg-bar { padding: 3px 8px; }
}
/* 横向きは既存の左右ベアオフ配置で高さを抑える。 */
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .bg-board { grid-template-columns: 52px minmax(0, 1fr) 52px; grid-template-rows: auto; }
  html.gs-playing .bg-off { flex-direction: column; }
  html.gs-playing .bg-off__stack { flex-direction: column; }
}
@media (max-width: 420px) and (max-height: 620px) {
  html.gs-playing .game-panel > .gs-bar { margin-bottom: 6px; }
  html.gs-playing .game-panel > .gs-hud { margin-bottom: 6px; }
  html.gs-playing .bg-status__main { min-height: 2em; margin-bottom: 4px; }
  html.gs-playing .bg-status__text { font-size: .75rem; }
  html.gs-playing .bg-point { min-height: 64px; }
  html.gs-playing .bg-point__stack { min-height: 54px; padding: 2px 0; gap: 0; }
  html.gs-playing .bg-die { min-height: 28px; min-width: 28px; }
  html.gs-playing .bg-dice-wrap { min-height: 28px; }
  html.gs-playing .bg-mid { min-height: 32px; }
  html.gs-playing .game-controls { margin-top: 8px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel {
    display: grid;
    grid-template-columns: 150px minmax(0, 490px);
    grid-template-rows: 44px auto 1fr;
    justify-content: center;
    align-items: start;
    column-gap: 12px;
    row-gap: 10px;
  }
  html.gs-playing .game-panel > .gs-bar { grid-column: 1; grid-row: 1; margin: 0; }
  html.gs-playing .game-panel > .gs-hud { grid-column: 1; grid-row: 2; margin: 0; }
  html.gs-playing .game-panel > .game-controls { grid-column: 1; grid-row: 3; margin: 0; }
  html.gs-playing .bg-stage { grid-column: 2; grid-row: 1 / 4; }
  html.gs-playing .bg-dice-wrap { min-height: 28px; margin: 0; }
  html.gs-playing .bg-die { min-height: 28px; min-width: 28px; font-size: .85rem; }
  html.gs-playing .bg-status__main { min-height: 36px; margin: 0 0 4px; gap: 6px; }
  html.gs-playing .bg-status__text { font-size: .75rem; }
  html.gs-playing .bg-board { padding: 6px; }
  html.gs-playing .bg-point { min-height: 80px; }
  html.gs-playing .bg-point__stack { min-height: 66px; padding: 2px 0; gap: 0; }
  html.gs-playing .bg-checker { width: 12px; height: 12px; }
  html.gs-playing .bg-mid { min-height: 36px; }
  html.gs-playing .bg-bar { padding: 2px 6px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel > .gs-hud { flex-direction: column; }
  html.gs-playing .gs-hud__item + .gs-hud__item { border-left: 0; border-top: 1px solid var(--play-border); padding-top: 6px; margin-top: 4px; }
}
