/* ドミノ固有スタイル */

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

/* 結果 */

.dm-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: dm-fade-in 0.25s ease-out;
}

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

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

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

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

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

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

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

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

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

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

/* 盤面全体 */

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

.dm-cpu__label,
.dm-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;
}

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

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

/* CPU の伏せ牌 */

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

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

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

/* ドミノ牌 */

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

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

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

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

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

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

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

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

/* 場 */

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

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

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

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

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

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

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

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

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

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

/* 山札・ターン */

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

.dm-stock {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
}

.dm-stock__pile {
  position: relative;
  width: 22px;
  height: 36px;
}

.dm-stock__pile span {
  position: absolute;
  width: 18px;
  height: 32px;
  border: 1px solid rgba(165, 180, 252, 0.55);
  border-radius: 3px;
  background: linear-gradient(160deg, #3b4f86, #24346a);
}

.dm-stock__pile span:nth-child(1) { left: 4px; top: 4px; }
.dm-stock__pile span:nth-child(2) { left: 2px; top: 2px; }
.dm-stock__pile span:nth-child(3) { left: 0; top: 0; }

.dm-stock__text {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: rgba(226, 232, 240, 0.85);
  font-size: 0.82rem;
  font-weight: 700;
}

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

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

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

/* 手札 */

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

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

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

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

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

.dm-hand-tile.is-selected,
.dm-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);
}

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

.dm-hand-tile.is-drawn {
  animation: dm-draw 0.28s ease-out;
}

/* 左右選択 */

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

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

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

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

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

.dm-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 dm-place {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: none; }
}

@keyframes dm-draw {
  from { opacity: 0; transform: translateY(-16px); }
}

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

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

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

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

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

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

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

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

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

  .dm-hand {
    gap: 6px;
  }

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

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

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

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

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

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

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

/* 共通の背景・HUD・操作ボタンを使い、牌の描画は既存のまま保つ。 */
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-controls { flex: none; width: 100%; max-width: 640px; }
html.gs-playing .status-pill { padding: 0; background: none; box-shadow: none; color: var(--play-accent); font-size: 1.15rem; }
html.gs-playing .status-pill.is-cpu,
html.gs-playing .status-pill.is-lose { color: #f0abfc; }
html.gs-playing .status-pill.is-draw { color: var(--play-text-muted); }
html.gs-playing .dm-board-wrap { position: relative; flex: none; width: 100%; max-width: 640px; }
html.gs-playing .dm-stage { height: min(560px, calc(100dvh - 210px)); min-height: 300px; max-width: none; margin: 0; grid-template-rows: 28px minmax(0, 1fr) 72px 116px; gap: 10px; padding: 12px; }
html.gs-playing .dm-cpu { min-width: 0; }
html.gs-playing .dm-cpu__hand { flex-wrap: nowrap; overflow-x: auto; height: 28px; }
html.gs-playing .dm-back { flex: none; }
html.gs-playing .dm-board { min-height: 0; overflow: auto; align-content: safe center; padding: 10px 6px; }
html.gs-playing .dm-message { display: flex; align-items: center; justify-content: center; height: 72px; min-height: 0; padding: 6px 8px; font-size: .8125rem; }
html.gs-playing .dm-player { min-width: 0; min-height: 0; }
html.gs-playing .dm-player__label { margin: 0 0 4px; font-size: .75rem; }
html.gs-playing .dm-hand { align-content: start; min-height: 0; height: 88px; overflow: auto; padding: 12px 6px 8px; gap: 8px; }
html.gs-playing .dm-hand-tile { --s: 28px; }
html.gs-playing .dm-side-choice { position: absolute; left: 6px; right: 6px; bottom: 6px; z-index: 2; margin: 0; padding: 10px; background: rgba(8, 15, 31, .97); }
html.gs-playing .dm-side-choice__actions { grid-template-columns: 1fr 1fr auto; }
html.gs-playing .dm-side-choice__actions #place-cancel-btn { grid-column: auto; }
html.gs-playing .dm-side-choice .btn--secondary { border: 1px solid var(--play-border); background: var(--play-hud-bg); color: var(--play-text); box-shadow: none; }
html.gs-playing .dm-result { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 0; padding: 12px; background: rgba(8, 15, 31, .97); border: 1px solid var(--play-border); color: var(--play-text); }
html.gs-playing .dm-result__detail,
html.gs-playing .dm-result__score dt { color: var(--play-text-muted); }
html.gs-playing .dm-guide { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
html.gs-playing .game-controls { justify-content: center; margin: 12px 0 0; }
html.gs-playing #game-error { position: fixed; bottom: 8px; z-index: 4; }
@media (min-width: 720px) and (min-height: 650px) {
  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: 24px; }
  html.gs-playing .game-panel > .gs-hud { margin-bottom: 24px; }
  html.gs-playing .dm-stage { height: min(560px, calc(100dvh - 270px)); }
  html.gs-playing .game-controls { margin-top: 24px; }
}
@media (max-width: 480px) {
  html.gs-playing .dm-stage { padding: 8px; gap: 8px; grid-template-rows: 22px minmax(0, 1fr) 72px 110px; }
  html.gs-playing .dm-hand { height: 84px; }
  html.gs-playing .dm-hand-tile { --s: 26px; }
  html.gs-playing .dm-board { align-content: start; }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel { display: grid; grid-template-columns: minmax(160px, 190px) minmax(0, 434px); grid-template-areas: "bar board" "hud board" "controls board"; gap: 8px 16px; align-content: start; justify-content: center; }
  html.gs-playing .gs-bar { grid-area: bar; }
  html.gs-playing .gs-hud { grid-area: hud; flex-wrap: wrap; }
  html.gs-playing .gs-hud__item { flex-basis: 45%; }
  html.gs-playing .gs-hud__item:nth-child(3) { border-left: 0; }
  html.gs-playing .game-controls { grid-area: controls; }
  html.gs-playing .dm-board-wrap { grid-area: board; }
  html.gs-playing .dm-stage { height: calc(100dvh - 24px); min-height: 0; padding: 8px; gap: 6px; grid-template-rows: 22px minmax(0, 1fr) 60px 90px; }
  html.gs-playing .dm-message { height: 60px; font-size: .75rem; }
  html.gs-playing .dm-hand { height: 64px; padding-top: 10px; }
  html.gs-playing .dm-hand-tile { --s: 22px; }
  html.gs-playing .dm-board .dm-tile { --s: 22px; }
}
