/* スライディングブロックパズル固有スタイル — ネオン中程度 */

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

/* ---- ステージ切り替え ---- */

.sb-stage-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: min(100%, 480px);
  margin: 0 auto 12px;
}

.sb-stage-nav__btn {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 10px 12px;
  white-space: nowrap;
}

.sb-stage-nav__btn:focus-visible {
  outline: 3px solid rgba(63, 196, 255, 0.85);
  outline-offset: 2px;
}

.sb-stage-nav__info {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  text-align: center;
}

.sb-stage-nav__title {
  color: var(--md-sys-color-on-surface);
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
}

.sb-stage-nav__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.sb-level,
.sb-cleared {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.sb-level--easy {
  color: #0b6b8f;
  background: rgba(63, 196, 255, 0.14);
  border: 1px solid rgba(63, 196, 255, 0.45);
}

.sb-level--medium {
  color: #2449a8;
  background: rgba(79, 124, 255, 0.12);
  border: 1px solid rgba(79, 124, 255, 0.45);
}

.sb-level--hard {
  color: #6d28d9;
  background: rgba(167, 139, 250, 0.14);
  border: 1px solid rgba(167, 139, 250, 0.55);
}

.sb-cleared {
  color: #047857;
  background: rgba(52, 211, 153, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.5);
}

.sb-cleared[hidden] {
  display: none;
}

/* ---- ステータス ---- */

.sb-status {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  max-width: min(100%, 420px);
  margin: 0 auto 14px;
  padding: 10px;
  border: 1px solid rgba(96, 154, 214, 0.28);
  border-radius: var(--md-sys-shape-corner-medium);
  background:
    radial-gradient(circle at 8% 0%, rgba(63, 196, 255, 0.06), transparent 55%),
    var(--md-sys-color-surface);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.sb-status__item {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 6px 4px;
  border-radius: var(--md-sys-shape-corner-medium);
  background: color-mix(in srgb, var(--md-sys-color-primary) 8%, var(--md-sys-color-surface));
}

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

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

/* ---- クリア表示 ---- */

.sb-result {
  max-width: min(100%, 520px);
  margin: 0 auto 14px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, #ff4fa8 40%, var(--md-sys-color-outline-variant));
  border-radius: var(--md-sys-shape-corner-medium);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 79, 168, 0.14), transparent 60%),
    color-mix(in srgb, #ff4fa8 6%, var(--md-sys-color-surface));
  text-align: center;
  animation: sb-result-in 220ms ease-out;
}

.sb-result:focus {
  outline: none;
}

.sb-result:focus-visible {
  outline: 3px solid rgba(63, 196, 255, 0.85);
  outline-offset: 2px;
}

.sb-result__title {
  margin: 0;
  color: #d61f7f;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-shadow: 0 0 16px rgba(255, 79, 168, 0.4);
}

.sb-result__detail {
  margin: 6px 0 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.875rem;
  line-height: 1.6;
}

.sb-result__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.sb-result__actions .btn {
  min-width: 8.5rem;
  min-height: 44px;
}

@keyframes sb-result-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* ---- 盤面 ---- */

.sb-arena {
  --sb-gap: 3px;
  --sb-cell: calc(100% / 6);
  box-sizing: border-box;
  width: min(100%, 520px);
  margin: 0 auto 14px;
  padding: 14px 40px 14px 14px;
  border: 1px solid rgba(96, 154, 214, 0.35);
  border-radius: 18px;
  background:
    radial-gradient(circle at 15% 0%, rgba(63, 196, 255, 0.12), transparent 45%),
    radial-gradient(circle at 90% 100%, rgba(167, 139, 250, 0.12), transparent 40%),
    #0f1a33;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 10px 28px rgba(15, 30, 60, 0.18);
  user-select: none;
  -webkit-user-select: none;
}

.sb-board {
  position: relative;
}

.sb-grid {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid rgba(120, 170, 230, 0.4);
  border-radius: 10px;
  background-color: #162447;
  background-image:
    linear-gradient(rgba(120, 170, 230, 0.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 170, 230, 0.13) 1px, transparent 1px);
  background-size: var(--sb-cell) var(--sb-cell);
  background-position: -1px -1px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* 出口のある行を薄く示す */
.sb-grid::before {
  content: "";
  position: absolute;
  top: calc(var(--sb-cell) * 2);
  right: 0;
  left: 0;
  height: var(--sb-cell);
  background: linear-gradient(90deg, transparent 20%, rgba(63, 196, 255, 0.12));
  pointer-events: none;
}

.sb-exit {
  position: absolute;
  top: calc((100% - 4px) / 6 * 2 + 2px);
  left: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 38px;
  height: calc((100% - 4px) / 6);
  margin-left: -3px;
  border-left: 4px solid #3fc4ff;
  border-radius: 2px;
  box-shadow: -4px 0 12px rgba(63, 196, 255, 0.45);
  pointer-events: none;
}

.sb-exit__arrow {
  color: #7fdcff;
  font-size: 0.95rem;
  line-height: 1;
}

.sb-exit__label {
  color: #bfeeff;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
}

.sb-arena.is-cleared .sb-exit {
  box-shadow: -4px 0 22px rgba(63, 196, 255, 0.85);
  animation: sb-exit-flash 900ms ease-out;
}

@keyframes sb-exit-flash {
  0%, 100% { border-left-color: #3fc4ff; }
  40% { border-left-color: #e0fbff; }
}

/* ---- ブロック ---- */

.sb-block {
  --r: 0;
  --c: 0;
  --len: 2;
  appearance: none;
  position: absolute;
  top: calc(var(--r) * var(--sb-cell) + var(--sb-gap));
  left: calc(var(--c) * var(--sb-cell) + var(--sb-gap));
  z-index: 1;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.78);
  font: inherit;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -2px 0 rgba(0, 0, 0, 0.22),
    0 2px 4px rgba(0, 0, 0, 0.3);
  transition: top 0.14s ease, left 0.14s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.sb-block.is-horizontal {
  width: calc(var(--len) * var(--sb-cell) - var(--sb-gap) * 2);
  height: calc(var(--sb-cell) - var(--sb-gap) * 2);
}

.sb-block.is-vertical {
  width: calc(var(--sb-cell) - var(--sb-gap) * 2);
  height: calc(var(--len) * var(--sb-cell) - var(--sb-gap) * 2);
}

.sb-block__mark {
  font-size: clamp(0.8rem, 3.4vw, 1.05rem);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.sb-block--h2 {
  background: linear-gradient(145deg, #5ab4ff 0%, #2f7de0 100%);
}

.sb-block--h3 {
  background: linear-gradient(145deg, #3f82e8 0%, #2250b0 100%);
}

.sb-block--v2 {
  background: linear-gradient(145deg, #a58bff 0%, #7150e6 100%);
}

.sb-block--v3 {
  background: linear-gradient(145deg, #8266ee 0%, #5033c0 100%);
}

.sb-block--target {
  border-color: #ffd0ea;
  color: #fff;
  background: linear-gradient(145deg, #ff86cc 0%, #ff3d9a 55%, #d81b78 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2),
    0 0 12px rgba(255, 61, 154, 0.45),
    0 2px 4px rgba(0, 0, 0, 0.3);
}

.sb-block--target .sb-block__mark {
  text-shadow: 0 1px 2px rgba(120, 0, 60, 0.45);
}

@media (hover: hover) {
  .sb-block:hover:not(:disabled) {
    filter: brightness(1.1);
  }
}

.sb-block.is-selected {
  z-index: 2;
  border-color: #c9f6ff;
  box-shadow:
    0 0 0 2px #3fc4ff,
    0 0 16px rgba(63, 196, 255, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.sb-block:focus-visible {
  outline: 3px solid #e6fbff;
  outline-offset: 2px;
}

.sb-block.is-dragging {
  z-index: 3;
  cursor: grabbing;
  transition: none;
}

.sb-block:disabled {
  cursor: default;
}

.sb-arena.is-cleared .sb-block--target {
  box-shadow:
    0 0 0 2px #ffc2e3,
    0 0 22px rgba(255, 61, 154, 0.85),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* ---- 方向ボタン ---- */

.sb-dpad {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 0 auto 12px;
  touch-action: manipulation;
}

.sb-dpad__btn {
  appearance: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(96, 154, 214, 0.4);
  border-radius: 12px;
  background: linear-gradient(180deg, #1a2d52, #122240);
  color: #e8f4ff;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 2px 0 rgba(10, 20, 40, 0.35);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, transform 0.04s ease;
}

.sb-dpad__btn:hover:not(:disabled) {
  border-color: rgba(63, 196, 255, 0.7);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 0 12px rgba(63, 196, 255, 0.25);
}

.sb-dpad__btn:active:not(:disabled) {
  transform: translateY(1px);
}

.sb-dpad__btn:focus-visible {
  outline: 3px solid rgba(63, 196, 255, 0.85);
  outline-offset: 2px;
}

.sb-dpad__btn:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

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

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

@media (prefers-reduced-motion: reduce) {
  .sb-block,
  .sb-result,
  .sb-arena.is-cleared .sb-exit {
    transition: none;
    animation: none;
  }
}

@media (max-width: 600px) {
  .sb-stage-nav__btn {
    padding: 10px;
    font-size: 0.8125rem;
  }

  .sb-stage-nav__title {
    font-size: 0.9rem;
  }

  /* 盤面を少しでも大きくするため、カードの内側余白に左右8pxずつはみ出させる */
  .sb-arena {
    --sb-gap: 2px;
    width: calc(100% + 16px);
    margin: 0 -8px 14px;
    padding: 6px 26px 6px 6px;
    border-radius: 14px;
  }

  .sb-exit {
    width: 25px;
  }

  .sb-exit__arrow {
    font-size: 0.8rem;
  }

  .sb-exit__label {
    font-size: 0.5rem;
    letter-spacing: 0;
  }

  .game-controls.tool-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .game-controls.tool-actions .btn {
    width: 100%;
    min-height: 44px;
  }
}

/* 共通の背景・HUD・アイコン操作を使用し、6×6盤面と方向ボタンの配置だけ指定する。 */
html.gs-playing .game-panel {
  --sb-chrome: 346px;
  display: grid;
  grid-template-columns: 44px minmax(0, 586px);
  grid-template-areas: "bar nav" "status status" "board board" "dpad dpad" "guide guide" "controls controls";
  justify-content: center;
  align-content: start;
  gap: 10px;
}
html.gs-playing .game-panel > .gs-bar { grid-area: bar; margin: 0; }
html.gs-playing .sb-stage-nav { grid-area: nav; width: 100%; max-width: none; margin: 0; }
html.gs-playing .gs-hud { grid-area: status; max-width: 640px; margin: 0; }
html.gs-playing .sb-stage-nav__title { color: var(--play-text); }
html.gs-playing .sb-stage-nav__btn,
html.gs-playing .sb-dpad__btn,
html.gs-playing .sb-result__actions .btn--secondary {
  border: 1px solid var(--play-border);
  background: var(--play-hud-bg);
  color: var(--play-text);
  box-shadow: none;
}
html.gs-playing .sb-level--easy { color: #7fdcff; }
html.gs-playing .sb-level--medium { color: #a4baff; }
html.gs-playing .sb-level--hard { color: #c4b5fd; }
html.gs-playing .sb-cleared { color: #6ee7b7; }
html.gs-playing .sb-arena {
  grid-area: board;
  position: relative;
  justify-self: center;
  width: min(100%, 520px, calc(100dvh - var(--sb-chrome)));
  margin: 0;
  padding: 8px 30px 8px 8px;
  border-color: var(--play-border);
}
html.gs-playing .sb-exit { width: 29px; }
html.gs-playing .sb-dpad { grid-area: dpad; margin: 0; justify-content: center; }
html.gs-playing .sb-guide {
  grid-area: guide;
  width: 100%;
  max-width: 640px;
  min-height: 2.6em;
  margin: 0;
  color: var(--play-text-muted);
  font-size: .75rem;
  line-height: 1.3;
}
html.gs-playing .game-controls.tool-actions { grid-area: controls; display: flex; gap: 12px; margin: 0; }
html.gs-playing .game-controls.tool-actions .btn { width: 44px; min-height: 44px; }
html.gs-playing .sb-result {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: none;
  margin: 0;
  padding: 12px;
  overflow: auto;
  background: rgba(8, 15, 31, .96);
  border-color: var(--play-border);
}
html.gs-playing .sb-result__detail { color: var(--play-text); }
html.gs-playing .sb-result__actions .btn { min-width: 0; padding: 8px 12px; }
@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .game-panel {
    --sb-chrome: 436px;
    gap: 22px 10px;
    padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top));
  }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel {
    --sb-chrome: 28px;
    grid-template-columns: 44px minmax(0, 252px) minmax(0, 350px);
    grid-template-areas: "bar nav board" "status status board" "dpad dpad board" "guide guide board" "controls controls board";
    gap: 8px;
  }
}
/* クリア済みバッジが狭幅で折り返しても、ステータス以下を動かさない。 */
html.gs-playing .sb-stage-nav__meta { height: 52px; align-content: center; }
