/* ボールソートパズル固有スタイル */

.bsp-settings {
  max-width: min(100%, 520px);
  margin: 4px auto 14px;
  text-align: center;
}

.bsp-settings .field-label {
  margin-bottom: 8px;
}

.option-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.option-tab {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 8px 6px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.04s ease;
}

.option-tab small {
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.75;
}

.option-tab:hover {
  background: var(--md-sys-color-primary-container);
}

.option-tab:active {
  transform: translateY(1px);
}

.option-tab.is-active {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.option-tab:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--md-sys-color-primary) 70%, white);
  outline-offset: 2px;
}

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

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

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

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

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

.bsp-result {
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  text-align: center;
  border: 1px solid color-mix(in srgb, var(--success) 38%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, var(--success) 10%, var(--md-sys-color-surface));
  animation: bsp-result-in 200ms ease-out;
}

.bsp-result__title {
  margin: 0;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--success);
}

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

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

.bsp-result__actions .btn {
  min-width: 9rem;
}

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

.bsp-board-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: min(100%, 640px);
  margin: 0 auto 10px;
}

.bsp-board {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(10px, 2.4vw, 18px) clamp(8px, 2vw, 14px);
  width: 100%;
  padding: clamp(12px, 2.5vw, 20px);
  border: 1px solid rgba(96, 154, 214, 0.35);
  border-radius: var(--md-sys-shape-corner-large);
  background:
    radial-gradient(circle at 18% 0%, rgba(63, 196, 255, 0.12), transparent 62%),
    radial-gradient(circle at 86% 100%, rgba(122, 157, 255, 0.12), transparent 60%),
    linear-gradient(160deg, #16264a 0%, #101c38 55%, #0d1730 100%);
  box-shadow: 0 14px 34px rgba(28, 52, 96, 0.24), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  user-select: none;
  -webkit-user-select: none;
}

.bsp-tube {
  --bsp-tube-w: clamp(42px, 11vw, 56px);
  --bsp-ball: calc(var(--bsp-tube-w) * 0.72);
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: var(--bsp-tube-w);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.bsp-tube:focus-visible {
  outline: none;
}

.bsp-tube:focus-visible .bsp-tube__glass {
  outline: 3px solid rgba(64, 200, 255, 0.9);
  outline-offset: 3px;
}

.bsp-tube.is-selected {
  transform: translateY(-10px);
}

.bsp-tube.is-selected .bsp-tube__glass {
  border-color: rgba(100, 210, 255, 0.95);
  box-shadow:
    0 0 0 2px rgba(64, 200, 255, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    0 10px 18px rgba(20, 40, 80, 0.28);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05));
}

.bsp-tube.is-shake {
  animation: bsp-shake 0.32s ease;
}

@keyframes bsp-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.bsp-tube.is-selected.is-shake {
  animation: bsp-shake-selected 0.32s ease;
}

@keyframes bsp-shake-selected {
  0%, 100% { transform: translateY(-10px) translateX(0); }
  25% { transform: translateY(-10px) translateX(-5px); }
  75% { transform: translateY(-10px) translateX(5px); }
}

.bsp-tube__glass {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: calc(var(--bsp-ball) * 4 + 18px);
  padding: 8px 5px 6px;
  border: 2px solid rgba(180, 210, 245, 0.42);
  border-bottom: 0;
  border-radius: 12px 12px 8px 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.14), transparent 28%, transparent 72%, rgba(255, 255, 255, 0.08)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.bsp-tube__stack {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  width: 100%;
  min-height: 0;
}

.bsp-ball {
  display: block;
  width: var(--bsp-ball);
  height: var(--bsp-ball);
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.55), transparent 42%),
    radial-gradient(circle at 70% 78%, rgba(0, 0, 0, 0.18), transparent 45%),
    var(--bsp-ball-color, #ccc);
  box-shadow:
    0 2px 3px rgba(0, 0, 0, 0.22),
    inset 0 -2px 3px rgba(0, 0, 0, 0.12);
  animation: bsp-ball-in 0.16s ease-out;
}

@keyframes bsp-ball-in {
  from { transform: translateY(-8px); opacity: 0.65; }
  to { transform: none; opacity: 1; }
}

.bsp-tube__base {
  display: block;
  width: calc(100% + 6px);
  height: 8px;
  margin-top: -2px;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(180deg, rgba(180, 210, 245, 0.35), rgba(120, 150, 200, 0.45));
  box-shadow: 0 2px 0 rgba(20, 35, 70, 0.25);
}

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

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

.bsp-tube:disabled {
  cursor: default;
  opacity: 0.98;
}

@media (max-width: 480px) {
  .option-tabs {
    gap: 8px;
  }

  .option-tab {
    min-height: 44px;
    font-size: 0.8rem;
    padding: 7px 4px;
  }

  .bsp-board {
    gap: 10px 8px;
    padding: 12px 8px;
  }

  .bsp-tube {
    --bsp-tube-w: clamp(38px, 14vw, 48px);
  }

  .game-controls .btn {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }
}

@media (min-width: 721px) {
  .bsp-board[data-difficulty="hard"] {
    max-width: 560px;
    margin-inline: auto;
  }
}

/* ——— プレイ画面（/css/game-screen.css の全画面表示中・ダークテーマ） ——— */
/* 背景・戻るボタン・アイコンボタンの配色は共通テーマ（gs-theme-dark）を使い、ここでは配置と HUD だけを決める */
/* 戻る・設定・情報・盤面を中央のまとまりに収める。 */
/* 容器の盤面は既存の折り返しを維持し、低い画面では容器を縮める。 */
html.gs-playing .game-panel {
  display: grid;
  grid-template-columns: 44px minmax(0, 506px);
  grid-template-rows: auto auto auto auto;
  grid-template-areas:
    "bar settings"
    "status status"
    "board board"
    "controls controls";
  column-gap: 10px;
  justify-content: center;
  align-content: start;
}

html.gs-playing .game-panel > .gs-bar {
  grid-area: bar;
}

html.gs-playing .bsp-settings {
  grid-area: settings;
  justify-self: stretch;
  width: 100%;
  max-width: none;
  margin: 0 0 10px;
}

html.gs-playing .bsp-settings .field-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html.gs-playing .option-tabs {
  gap: 6px;
}

html.gs-playing .option-tab {
  flex-direction: column;
  gap: 0;
  min-height: 44px;
  padding: 4px 6px;
  border-color: var(--play-border);
  background: var(--play-hud-bg);
  color: var(--play-text);
  font-size: .8125rem;
}

html.gs-playing .option-tab small {
  font-size: .6875rem;
}

@media (hover: hover) {
  html.gs-playing .option-tab:hover {
    border-color: color-mix(in srgb, var(--play-accent) 55%, var(--play-border));
    background: var(--play-btn-hover);
  }
}

html.gs-playing .option-tab.is-active {
  border-color: var(--play-accent);
  background: color-mix(in srgb, var(--play-accent) 18%, var(--play-hud-bg));
  color: var(--play-accent);
}

html.gs-playing .option-tab:focus-visible {
  outline: 2px solid var(--play-accent);
  outline-offset: 2px;
}

html.gs-playing .bsp-status,
html.gs-playing .game-panel .game-controls {
  justify-self: center;
  width: 100%;
  max-width: min(100%, 560px);
}

html.gs-playing .bsp-status {
  grid-area: status;
  gap: 0;
  margin: 0 0 10px;
  padding: 6px 4px;
  border-color: var(--play-border);
  background: color-mix(in srgb, var(--play-hud-bg) 88%, transparent);
}

html.gs-playing .bsp-status__item {
  padding: 2px 8px;
  border-radius: 0;
  background: none;
}

html.gs-playing .bsp-status__item + .bsp-status__item {
  border-left: 1px solid var(--play-border);
}

html.gs-playing .bsp-status__label {
  color: var(--play-text-muted);
}

html.gs-playing .bsp-status__value {
  color: var(--play-text);
}

html.gs-playing .bsp-result__actions .btn--secondary {
  border: 1px solid var(--play-border);
  background: var(--play-bg);
  color: var(--play-text);
  box-shadow: none;
}

@media (hover: hover) {
  html.gs-playing .bsp-result__actions .btn--secondary:hover {
    border-color: color-mix(in srgb, var(--play-accent) 55%, var(--play-border));
    background: var(--play-btn-hover);
    color: var(--play-accent);
  }
}

html.gs-playing .bsp-stage {
  grid-area: board;
  position: relative;
  justify-self: center;
  width: 100%;
  margin-bottom: 10px;
}
html.gs-playing .bsp-board-wrap { max-width: none; margin: 0; }
html.gs-playing .bsp-board { max-width: none; margin: 0; border-color: var(--play-border); }
html.gs-playing .bsp-result {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  background: rgba(11, 20, 42, .92);
  backdrop-filter: blur(5px);
}
html.gs-playing .bsp-result__title { color: #a8f0ff; }
html.gs-playing .bsp-result__detail { color: var(--play-text); }
/* 凡例と操作説明はプレイ中は画面に出さない。操作説明は盤面の説明（aria-describedby）として読み上げだけに残す */
html.gs-playing .bsp-guide {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html.gs-playing .game-panel .game-controls {
  grid-area: controls;
  justify-content: center;
  gap: 12px;
  margin: 0;
}

/* PCは最大640pxを基準にし、盤面は高さにも収める。 */
@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .game-panel {
    grid-template-columns: 44px minmax(0, 586px);
    padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top));
  }

  html.gs-playing .game-panel > .gs-bar,
  html.gs-playing .bsp-settings {
    margin-bottom: 28px;
  }

  html.gs-playing .bsp-status,
  html.gs-playing .bsp-board-wrap,
  html.gs-playing .game-panel .game-controls {
    max-width: 640px;
  }

  html.gs-playing .bsp-status,
  html.gs-playing .bsp-stage {
    margin-bottom: 24px;
  }
}

/* スマートフォン横向きなど高さが足りない画面では、戻る・操作・難易度・情報を左、盤面を右に並べる */
/* 操作ボタンは戻るボタンと同じ行の右端に置き、左列の高さを抑える */
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel {
    grid-template-columns: minmax(200px, 280px) minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "bar board"
      "settings board"
      "status board"
      ". board";
    column-gap: 16px;
  }

  html.gs-playing .game-panel > .gs-bar {
    justify-self: start;
  }

  html.gs-playing .bsp-settings {
    justify-self: stretch;
    width: 100%;
  }

  html.gs-playing .game-panel .game-controls {
    grid-area: bar;
    justify-self: end;
    width: auto;
    margin-bottom: 10px;
  }

  html.gs-playing .bsp-stage {
    align-self: center;
    margin: 0;
    max-width: 360px;
  }
  html.gs-playing .bsp-board { gap: 10px 8px; padding: 14px 10px; }
  html.gs-playing .bsp-tube { --bsp-tube-w: clamp(34px, 5vw, 42px); }
}
@media (max-width: 480px) {
  html.gs-playing .game-controls .gs-icon-btn { flex: none; min-width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .bsp-ball, .bsp-result, .bsp-tube.is-shake { animation: none; }
  .bsp-tube { transition: none; }
}

/* 高さの低いPCでも、2段の容器と操作列を画面内に収める。 */
@media (min-width: 768px) and (min-height: 501px) and (max-height: 700px) {
  html.gs-playing .bsp-tube { --bsp-tube-w: 42px; }
}
@media (max-width: 480px) and (max-height: 600px) {
  html.gs-playing .bsp-tube { --bsp-tube-w: 40px; }
}
