/* ハルマ固有スタイル */

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

.hm-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  max-width: min(100%, 520px);
  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);
}

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

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

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

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

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

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

.hm-score__slash {
  margin-left: 1px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.85rem;
  font-weight: 600;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

.hm-legend__swatch--cpu {
  background: linear-gradient(160deg, #e9d5ff, #a21caf);
}

.hm-legend__camp {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.hm-legend__camp--player {
  background: color-mix(in srgb, #22d3ee 28%, #1a3358);
}

.hm-legend__camp--cpu {
  background: color-mix(in srgb, #c084fc 28%, #1a3358);
}

.hm-board-wrap {
  --hm-player: #22d3ee;
  --hm-player-deep: #0891b2;
  --hm-cpu: #e879f9;
  --hm-cpu-deep: #a21caf;
  --hm-frame: #38bdf8;
  --hm-light: #c9d7ec;
  --hm-dark: #162a4a;
  --hm-board-bg: linear-gradient(160deg, #14284f 0%, #0d1a36 55%, #0a1428 100%);
  --hm-goal-player: color-mix(in srgb, #22d3ee 18%, #162a4a);
  --hm-goal-cpu: color-mix(in srgb, #c084fc 18%, #162a4a);
  display: flex;
  justify-content: center;
  margin: 0 auto 12px;
  max-width: min(100%, 520px);
}

.hm-board {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  width: min(100%, 520px);
  aspect-ratio: 1 / 1;
  padding: 8px;
  border: 2px solid color-mix(in srgb, var(--hm-frame) 70%, #0ea5e9);
  border-radius: 16px;
  background: var(--hm-board-bg);
  box-shadow:
    0 0 0 1px rgba(56, 189, 248, 0.18),
    0 10px 28px rgba(8, 20, 48, 0.28);
}

.hm-cell {
  position: relative;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--hm-light);
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hm-cell--dark {
  background: var(--hm-dark);
}

.hm-cell--goal-player {
  background: color-mix(in srgb, #22d3ee 14%, var(--hm-light));
}

.hm-cell--dark.hm-cell--goal-player {
  background: var(--hm-goal-player);
}

.hm-cell--goal-cpu {
  background: color-mix(in srgb, #c084fc 14%, var(--hm-light));
}

.hm-cell--dark.hm-cell--goal-cpu {
  background: var(--hm-goal-cpu);
}

.hm-cell--goal-player::before,
.hm-cell--goal-cpu::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  pointer-events: none;
}

.hm-cell--goal-player::before {
  border-color: color-mix(in srgb, #22d3ee 28%, transparent);
}

.hm-cell--goal-cpu::before {
  border-color: color-mix(in srgb, #c084fc 28%, transparent);
}

.hm-cell:focus-visible {
  outline: 2px solid #67e8f9;
  outline-offset: -2px;
  z-index: 2;
}

.hm-cell.is-selected {
  box-shadow: inset 0 0 0 3px #67e8f9;
  z-index: 1;
}

.hm-cell.is-last-move {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, #fbbf24 75%, white);
}

.hm-cell.is-selected.is-last-move {
  box-shadow:
    inset 0 0 0 3px #67e8f9,
    inset 0 0 0 5px color-mix(in srgb, #fbbf24 55%, transparent);
}

.hm-cell.is-move-target::after,
.hm-cell.is-jump-target::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

.hm-cell.is-move-target::after {
  width: 22%;
  height: 22%;
  min-width: 7px;
  min-height: 7px;
  background: color-mix(in srgb, #67e8f9 55%, transparent);
}

.hm-cell.is-jump-target::after {
  width: 46%;
  height: 46%;
  min-width: 12px;
  min-height: 12px;
  border: 2px solid color-mix(in srgb, #67e8f9 85%, white);
  background: color-mix(in srgb, #67e8f9 12%, transparent);
  box-shadow: 0 0 8px color-mix(in srgb, #67e8f9 30%, transparent);
}

.hm-piece {
  position: relative;
  z-index: 1;
  display: block;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.35),
    inset 0 1px 2px rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.hm-piece--player {
  background: linear-gradient(160deg, #67e8f9 0%, #22d3ee 45%, #0891b2 100%);
}

.hm-piece--cpu {
  background: linear-gradient(160deg, #f0abfc 0%, #e879f9 45%, #a21caf 100%);
}

.hm-jump-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  max-width: min(100%, 520px);
  margin: 0 auto 12px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, #22d3ee 28%, var(--md-sys-color-outline-variant));
  border-radius: var(--md-sys-shape-corner-medium);
  background: color-mix(in srgb, #22d3ee 8%, var(--md-sys-color-surface));
}

.hm-jump-bar__text {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.88rem;
  font-weight: 600;
}

.hm-guide {
  max-width: min(100%, 520px);
  margin: 0 auto 14px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.86rem;
  line-height: 1.55;
  text-align: center;
}

.game-controls {
  justify-content: center;
}

@media (max-width: 480px) {
  .hm-status {
    padding: 10px 12px;
  }

  .hm-score {
    min-width: 4.2rem;
    padding: 5px 8px;
  }

  .hm-board {
    padding: 6px;
    border-radius: 12px;
  }

  .hm-cell.is-move-target::after {
    width: 26%;
    height: 26%;
  }

  .hm-cell.is-jump-target::after {
    width: 52%;
    height: 52%;
  }

  .hm-guide {
    font-size: 0.82rem;
  }

  .hm-piece {
    width: 74%;
    height: 74%;
  }
}

/* 外枠・ボタン・HUDは15パズル／パイプパズルと同じ共通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 .game-panel > .game-controls,
.hm-stage { width: 100%; max-width: 640px; }
.hm-stage { position: relative; flex: none; }
html.gs-playing .hm-board-wrap {
  width: min(100%, max(180px, min(100dvh - 320px, 560px)));
  max-width: none;
  margin: 0 auto;
}
html.gs-playing .hm-board { border-color: var(--play-border); }
html.gs-playing .status-pill { min-height: 0; padding: 0; font-size: 1.15rem; line-height: 1.2; background: none; }
html.gs-playing .status-pill.is-player { color: var(--play-accent); }
html.gs-playing .status-pill.is-cpu { color: #e9b8fa; }
html.gs-playing .status-pill.is-win { color: #86efac; }
html.gs-playing .status-pill.is-lose { color: #fca5a5; }
html.gs-playing .hm-legend { flex: none; margin: 12px auto 0; color: var(--play-text-muted); font-size: .75rem; gap: 8px 14px; }
html.gs-playing .hm-status__text {
  flex: none;
  width: 100%;
  max-width: 640px;
  min-height: 3.2em;
  margin: 10px auto;
  color: var(--play-text);
  font-size: .9rem;
  line-height: 1.6;
  text-align: center;
}
html.gs-playing .game-controls { flex: none; margin: 0; }
html.gs-playing .hm-result {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin: 0;
  border: 1px solid var(--play-border);
  background: rgba(8, 15, 31, .94);
  color: var(--play-text);
}
html.gs-playing .hm-result__detail { color: var(--play-text-muted); }
@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 .hm-board-wrap { width: min(100%, max(180px, min(100dvh - 370px, 560px))); }
  html.gs-playing .hm-legend { margin-top: 24px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel {
    display: grid;
    grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto 1fr;
    grid-template-areas: "bar board" "status board" "legend board" "hint board" "controls board";
    column-gap: 16px;
    align-items: start;
  }
  html.gs-playing .game-panel > .gs-bar { grid-area: bar; }
  html.gs-playing .game-panel > .gs-hud { grid-area: status; }
  html.gs-playing .hm-stage { grid-area: board; align-self: center; }
  html.gs-playing .hm-board-wrap { width: min(100%, 100dvh - 24px); }
  html.gs-playing .hm-legend { grid-area: legend; }
  html.gs-playing .hm-status__text { grid-area: hint; }
  html.gs-playing .game-controls { grid-area: controls; }
}
@media (prefers-reduced-motion: reduce) { .hm-result { animation: none; } }

/* ジャンプ操作は専用の固定領域に収め、表示切替で盤面を動かさない。 */
html.gs-playing .hm-jump-bar {
  flex: none; width: 100%; max-width: 640px; min-height: 70px;
  margin: 0 auto 8px; padding: 0; border: 0; background: none;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--play-text-muted);
}
html.gs-playing .hm-jump-bar[hidden] { display: flex !important; visibility: hidden; }
html.gs-playing .hm-jump-bar__text { color: var(--play-text-muted); font-size: .8rem; }
html.gs-playing .hm-status__text { min-height: 1.6em; margin: 8px auto; }
html.gs-playing .hm-legend { gap: 6px 12px; font-size: .7rem; }
html.gs-playing .hm-board-wrap { width: min(100%, max(180px, min(100dvh - 390px, 560px))); }
html.gs-playing .hm-board { width: 100%; }
html.gs-playing .gs-hud__value small { font-size: .7em; }
@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .hm-board-wrap { width: min(100%, max(180px, min(100dvh - 430px, 560px))); }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel { grid-template-rows: auto auto auto auto auto 1fr; grid-template-areas: "bar board" "status board" "legend board" "hint board" "jump board" "controls board"; }
  html.gs-playing .hm-jump-bar { grid-area: jump; min-height: 54px; }
  html.gs-playing .hm-board-wrap { width: min(100%, 100dvh - 24px); }
}
