/* シャット・ザ・ボックス固有スタイル */

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

.stb-status {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  max-width: min(100%, 460px);
  margin: 0 auto 12px;
  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);
}

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

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

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

.stb-guide {
  margin: 0 auto 12px;
  max-width: min(100%, 460px);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
}

.stb-dice-mode {
  margin: 0 auto 12px;
  max-width: min(100%, 460px);
  padding: 8px 12px;
  border-radius: var(--md-sys-shape-corner-medium);
  border: 1px solid color-mix(in srgb, #966aff 35%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, #966aff 10%, var(--md-sys-color-surface));
  color: #5a3d9e;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
}

.stb-result {
  margin: 0 auto 14px;
  max-width: min(100%, 460px);
  padding: 16px 18px;
  border-radius: var(--md-sys-shape-corner-medium);
  text-align: center;
  border: 1px solid color-mix(in srgb, #7a93b8 40%, var(--md-sys-color-outline-variant));
  background:
    radial-gradient(circle at 50% 0%, rgba(80, 110, 150, 0.14), transparent 70%),
    color-mix(in srgb, #101c38 6%, var(--md-sys-color-surface));
  box-shadow: 0 0 18px rgba(80, 110, 150, 0.1);
  animation: stb-result-in 200ms ease-out;
}

.stb-result.is-clear {
  border-color: color-mix(in srgb, #c77dff 45%, var(--md-sys-color-outline-variant));
  background:
    radial-gradient(circle at 50% 0%, rgba(150, 106, 255, 0.2), transparent 70%),
    radial-gradient(circle at 80% 100%, rgba(63, 196, 255, 0.14), transparent 60%),
    color-mix(in srgb, #101c38 8%, var(--md-sys-color-surface));
  box-shadow: 0 0 28px rgba(150, 106, 255, 0.18);
}

.stb-result.is-over {
  border-color: color-mix(in srgb, #7a93b8 40%, var(--md-sys-color-outline-variant));
}

.stb-result__title {
  margin: 0;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #3a5278;
}

.stb-result.is-clear .stb-result__title {
  font-size: 1.7rem;
  letter-spacing: 0.1em;
  color: #6a3db8;
  text-shadow: 0 0 18px rgba(150, 106, 255, 0.35);
}

.stb-result__detail,
.stb-result__score,
.stb-result__best {
  margin: 6px 0 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.6;
}

.stb-result__best {
  color: #1a6fb8;
}

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

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

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

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

.stb-board {
  --stb-gap: clamp(6px, 1.8vw, 10px);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--stb-gap);
  width: 100%;
  padding: clamp(12px, 3vw, 18px);
  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.14), transparent 62%),
    radial-gradient(circle at 86% 100%, rgba(150, 106, 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);
}

.stb-number {
  appearance: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 48px;
  padding: 0;
  border: 1.5px solid rgba(120, 180, 230, 0.45);
  border-radius: 12px;
  background:
    linear-gradient(160deg, rgba(80, 170, 230, 0.35), rgba(40, 100, 180, 0.45)),
    #1a3a68;
  color: #e8f7ff;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: clamp(1.1rem, 4.2vw, 1.45rem);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    0 0 12px rgba(63, 196, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.12s ease,
    opacity 0.15s ease,
    box-shadow 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.stb-number:nth-child(6) {
  grid-column: 2;
}

.stb-number__value {
  position: relative;
  z-index: 1;
}

.stb-number__state {
  position: absolute;
  inset: auto 4px 4px auto;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0;
}

.stb-number.is-open:hover:not(:disabled) {
  border-color: rgba(160, 235, 255, 0.8);
  box-shadow: 0 0 16px rgba(63, 196, 255, 0.28);
  transform: translateY(-1px);
}

.stb-number.is-selected {
  border-color: rgba(200, 170, 255, 0.9);
  background:
    linear-gradient(160deg, rgba(180, 140, 255, 0.55), rgba(90, 70, 180, 0.55)),
    #4a2f8a;
  color: #f6f0ff;
  box-shadow:
    0 0 18px rgba(150, 106, 255, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
  outline: 2px solid rgba(210, 190, 255, 0.75);
  outline-offset: 1px;
}

.stb-number.is-selected .stb-number__state {
  opacity: 1;
  color: #efe6ff;
}

.stb-number.is-selected .stb-number__state::before {
  content: "選択";
}

.stb-number.is-closed,
.stb-number.is-closed:disabled {
  border-color: rgba(70, 90, 120, 0.4);
  background: #0a1224;
  color: #4a5a78;
  opacity: 0.55;
  cursor: not-allowed;
  transform: perspective(180px) rotateX(28deg) translateY(4px);
  box-shadow: inset 0 8px 14px rgba(0, 0, 0, 0.35);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.stb-number.is-closed .stb-number__state {
  opacity: 1;
  color: #6a7a98;
}

.stb-number.is-closed .stb-number__state::before {
  content: "閉";
}

.stb-number:focus-visible {
  outline: 2px solid #3fc4ff;
  outline-offset: 2px;
}

.stb-number:disabled:not(.is-closed) {
  cursor: default;
  opacity: 0.85;
}

.stb-play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: min(100%, 460px);
  margin: 0 auto 14px;
  padding: clamp(14px, 3vw, 18px);
  border: 1px solid rgba(96, 154, 214, 0.28);
  border-radius: var(--md-sys-shape-corner-large);
  background:
    radial-gradient(circle at 50% 0%, rgba(63, 196, 255, 0.1), transparent 65%),
    linear-gradient(180deg, #142448 0%, #0f1a34 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.stb-dice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 18px);
  min-height: 72px;
}

.stb-die {
  --dot: #1a2744;
  position: relative;
  width: clamp(56px, 14vw, 68px);
  height: clamp(56px, 14vw, 68px);
  border-radius: 14px;
  border: 1.5px solid rgba(180, 220, 255, 0.55);
  background:
    linear-gradient(145deg, #f4fbff 0%, #d7ecfb 55%, #c4dff4 100%);
  box-shadow:
    0 8px 18px rgba(10, 24, 48, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.stb-die.is-blank {
  background:
    linear-gradient(145deg, rgba(200, 220, 240, 0.35), rgba(140, 170, 200, 0.28));
  border-color: rgba(140, 180, 220, 0.3);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.stb-die.is-blank::before,
.stb-die.is-blank::after {
  content: none;
}

.stb-die.is-rolling {
  animation: stb-die-roll 0.32s ease-in-out;
}

@keyframes stb-die-roll {
  0% { transform: rotate(0deg) scale(1); }
  30% { transform: rotate(-12deg) scale(0.94); }
  60% { transform: rotate(10deg) scale(1.04); }
  100% { transform: rotate(0deg) scale(1); }
}

/* ドット表現（CSSのみ） */
.stb-die::before {
  content: "";
  position: absolute;
  inset: 18%;
  background-image: radial-gradient(circle, var(--dot) 45%, transparent 48%);
  background-repeat: no-repeat;
  background-size: 28% 28%;
  opacity: 0;
}

.stb-die[data-value="1"]::before {
  opacity: 1;
  background-position: center center;
}

.stb-die[data-value="2"]::before {
  opacity: 1;
  background-position:
    left top,
    right bottom;
  background-image:
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%);
}

.stb-die[data-value="3"]::before {
  opacity: 1;
  background-position:
    left top,
    center center,
    right bottom;
  background-image:
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%);
}

.stb-die[data-value="4"]::before {
  opacity: 1;
  background-position:
    left top,
    right top,
    left bottom,
    right bottom;
  background-image:
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%);
}

.stb-die[data-value="5"]::before {
  opacity: 1;
  background-position:
    left top,
    right top,
    center center,
    left bottom,
    right bottom;
  background-image:
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%);
}

.stb-die[data-value="6"]::before {
  opacity: 1;
  background-position:
    left top,
    right top,
    left center,
    right center,
    left bottom,
    right bottom;
  background-image:
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%),
    radial-gradient(circle, var(--dot) 45%, transparent 48%);
}

.stb-totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 280px;
}

.stb-total {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(8, 16, 32, 0.45);
  border: 1px solid rgba(120, 170, 220, 0.25);
}

.stb-total__label {
  color: rgba(190, 220, 255, 0.75);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.stb-total__value {
  color: #e8f7ff;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  text-shadow: 0 0 12px rgba(63, 196, 255, 0.25);
}

.stb-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.stb-actions .btn {
  min-width: min(100%, 11rem);
}

.stb-hint {
  margin: 0 auto;
  max-width: min(100%, 460px);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.85rem;
  line-height: 1.55;
  text-align: center;
}

@media (max-width: 420px) {
  .stb-board {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
    padding: 10px;
  }

  .stb-number {
    min-height: 44px;
    border-radius: 10px;
    font-size: 1.05rem;
  }

  .stb-number.is-closed {
    transform: perspective(160px) rotateX(22deg) translateY(2px);
  }

  .stb-actions .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }

  .stb-actions .btn#roll-btn {
    flex: 1 1 100%;
  }
}

/* 外枠とHUDは15パズル・パイプパズルの共通UIを利用する。 */
html.gs-playing .stb-panel { align-items: center; }
html.gs-playing .stb-panel > .gs-bar,
html.gs-playing .stb-panel > .gs-hud,
.stb-stage { width: 100%; max-width: 640px; }
.stb-stage { position: relative; flex: none; }
html.gs-playing .stb-guide {
  color: var(--play-text-muted);
  min-height: 3em;
  margin-bottom: 0;
}
/* 1個への切り替えでも盤面・操作位置を変えない。 */
html.gs-playing .stb-dice-mode {
  display: block;
  min-height: 3em;
  margin-bottom: 10px;
  padding: 0 8px;
  border: 0;
  background: none;
  color: var(--play-accent);
  font-size: .75rem;
  line-height: 1.5;
}
html.gs-playing .stb-dice-mode[hidden] { display: block !important; visibility: hidden; }
html.gs-playing .stb-board-wrap { max-width: 460px; }
html.gs-playing .stb-play {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 460px;
  padding: 12px;
}
html.gs-playing .stb-dice { gap: 10px; min-height: 56px; }
html.gs-playing .stb-die { width: 56px; height: 56px; }
html.gs-playing .stb-actions { grid-column: 1 / -1; flex-wrap: nowrap; }
html.gs-playing .stb-actions .btn { min-width: 0; flex: 1; padding-inline: 8px; }
html.gs-playing .stb-actions #restart-btn { flex: none; width: 44px; }
html.gs-playing .stb-actions .btn--secondary:not(.gs-icon-btn) {
  border: 1px solid var(--play-border);
  background: var(--play-hud-bg);
  color: var(--play-text);
  box-shadow: none;
}
html.gs-playing .stb-hint { color: var(--play-text-muted); }
html.gs-playing .stb-result {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: none;
  margin: 0;
  background: rgba(11, 20, 42, .96);
  backdrop-filter: blur(5px);
}
html.gs-playing .stb-result__title { color: var(--play-accent); }
html.gs-playing .stb-result.is-clear .stb-result__title { color: #d6b6ff; }
html.gs-playing .stb-result__detail,
html.gs-playing .stb-result__score { color: var(--play-text); }
html.gs-playing .stb-result__best { color: var(--play-accent); }
@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .stb-panel {
    padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top));
  }
  html.gs-playing .stb-panel > .gs-bar { margin-bottom: 28px; }
  html.gs-playing .stb-panel > .gs-hud,
  html.gs-playing .stb-board-wrap { margin-bottom: 24px; }
}
@media (max-width: 420px) {
  html.gs-playing .stb-play { gap: 8px; padding: 8px; }
  html.gs-playing .stb-dice { gap: 6px; }
  html.gs-playing .stb-die { width: 48px; height: 48px; }
  html.gs-playing .stb-actions .btn { font-size: .75rem; }
  html.gs-playing .stb-hint { font-size: .75rem; }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .stb-stage {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 16px;
  }
  html.gs-playing .stb-guide,
  html.gs-playing .stb-dice-mode { grid-column: 1; width: 100%; }
  html.gs-playing .stb-board-wrap { grid-column: 1; margin-bottom: 0; }
  html.gs-playing .stb-play { grid-column: 2; grid-row: 1 / 4; align-self: center; }
  html.gs-playing .stb-hint { margin-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .stb-result, .stb-die.is-rolling { animation: none; }
}
/* 旧スマホ用の全幅ロール指定を解除し、閉じる操作の幅を確保する。 */
html.gs-playing .stb-actions .btn#roll-btn { flex: 1.5 1 0; }
html.gs-playing .stb-actions #close-btn { flex: 1 1 0; white-space: nowrap; }
html.gs-playing .stb-total { padding-inline: 4px; }
html.gs-playing .stb-total__label { font-size: .65rem; white-space: nowrap; }
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .stb-actions .btn#roll-btn { font-size: .75rem; white-space: nowrap; }
  html.gs-playing .stb-hint { max-width: 640px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .stb-hint {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .stb-dice-mode { margin-bottom: 4px; }
}
