/* ニム固有スタイル */

.nim-settings {
  margin: 4px 0 16px;
}

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

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

.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: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

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

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

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

.nim-status__text {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.95rem;
  font-weight: 600;
}

.nim-status__remaining {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.85rem;
  font-weight: 600;
}

.nim-status__remaining strong {
  color: var(--md-sys-color-on-surface);
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.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: #15803d;
}

.status-pill.is-lose {
  background: color-mix(in srgb, #f43f5e 16%, var(--md-sys-color-surface));
  color: #be123c;
}

.nim-result {
  max-width: min(100%, 560px);
  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;
}

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

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

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

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

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

/* 盤面 */

.nim-stage {
  max-width: min(100%, 560px);
  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);
}

.nim-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nim-heap {
  --chip-light: #a5f3fc;
  --chip-base: #06b6d4;
  --chip-glow: rgba(34, 211, 238, 0.45);
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 16px;
  background: rgba(10, 20, 42, 0.55);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.nim-heap:nth-child(2) {
  --chip-light: #bfdbfe;
  --chip-base: #3b82f6;
  --chip-glow: rgba(96, 165, 250, 0.45);
}

.nim-heap:nth-child(3) {
  --chip-light: #c7d2fe;
  --chip-base: #6366f1;
  --chip-glow: rgba(129, 140, 248, 0.45);
}

.nim-heap:nth-child(4) {
  --chip-light: #e9d5ff;
  --chip-base: #a855f7;
  --chip-glow: rgba(192, 132, 252, 0.45);
}

.nim-heap.is-selected {
  border-color: rgba(244, 114, 182, 0.75);
  box-shadow: 0 0 0 1px rgba(244, 114, 182, 0.35), 0 0 16px rgba(244, 114, 182, 0.2);
}

.nim-heap.is-last--cpu:not(.is-selected) {
  border-color: rgba(192, 132, 252, 0.55);
}

.nim-heap.is-last--player:not(.is-selected) {
  border-color: rgba(34, 211, 238, 0.5);
}

.nim-heap__head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.nim-heap__name {
  color: rgba(226, 232, 240, 0.78);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.nim-heap__count {
  color: #e2e8f0;
  font-size: 0.8rem;
  font-weight: 600;
}

.nim-heap__count strong {
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.nim-heap__note {
  color: rgba(226, 232, 240, 0.72);
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.nim-heap.is-last--cpu .nim-heap__note {
  color: #d8b4fe;
}

.nim-heap.is-last--player .nim-heap__note {
  color: #67e8f9;
}

.nim-heap.is-empty .nim-heap__count {
  color: rgba(226, 232, 240, 0.5);
}

.nim-heap__chips {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 46px));
  gap: 8px;
  align-items: center;
  min-height: 46px;
}

.nim-heap__empty {
  grid-column: 1 / -1;
  color: rgba(226, 232, 240, 0.45);
  font-size: 0.85rem;
  font-weight: 600;
}

.nim-chip {
  appearance: none;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.55), transparent 42%),
    linear-gradient(145deg, var(--chip-light), var(--chip-base));
  box-shadow:
    inset 0 -3px 6px rgba(2, 6, 23, 0.35),
    0 0 6px var(--chip-glow);
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.nim-chip:disabled {
  cursor: default;
}

.nim-chip:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow:
    inset 0 -3px 6px rgba(2, 6, 23, 0.3),
    0 0 12px var(--chip-glow);
}

.nim-chip:focus-visible {
  outline: 2px solid #fef08a;
  outline-offset: 2px;
}

.nim-chip.is-take {
  border: 2px dashed #f9a8d4;
  background: color-mix(in srgb, var(--chip-base) 28%, transparent);
  box-shadow: 0 0 12px rgba(244, 114, 182, 0.55);
}

.nim-chip.is-take:not(:disabled):hover {
  background: color-mix(in srgb, var(--chip-base) 40%, transparent);
  box-shadow: 0 0 14px rgba(244, 114, 182, 0.7);
}

.nim-chip--ghost {
  border: 2px dashed rgba(148, 163, 184, 0.35);
  background: transparent;
  box-shadow: none;
  cursor: default;
}

.nim-selection {
  min-height: 48px;
  margin: 14px 0 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.8);
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
}

.nim-selection.is-active {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 16px;
  border-color: rgba(244, 114, 182, 0.55);
  color: #e2e8f0;
  font-size: 0.95rem;
}

.nim-selection strong {
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.nim-selection__take strong {
  color: #f9a8d4;
}

.nim-selection__keep strong {
  color: #67e8f9;
}

.nim-actions {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.nim-actions .btn {
  width: 100%;
  min-height: 48px;
}

.nim-actions .btn:disabled {
  opacity: 0.32;
  filter: grayscale(0.7);
}

.nim-guide {
  max-width: min(100%, 560px);
  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%, 560px);
  margin: 14px auto 0;
}

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

  .nim-status {
    padding: 10px 12px;
  }
}

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

  .nim-board {
    gap: 8px;
  }

  .nim-heap {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    padding: 8px 6px 10px;
  }

  .nim-heap__head {
    padding-inline: 4px;
  }

  .nim-actions {
    grid-template-columns: 1fr 1fr;
  }

  .nim-actions .btn {
    padding-inline: 8px;
    white-space: nowrap;
  }

  .nim-heap__head {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
  }

  .nim-heap__count strong {
    font-size: 1.15rem;
  }

  .nim-heap__chips {
    gap: 4px;
    min-height: 0;
  }

  .option-tabs {
    gap: 6px;
  }

  .option-tab {
    padding: 8px 4px;
  }
}

/* 共通画面を再利用し、石の山だけ固有のレイアウトを保つ。 */
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 { width: 100%; max-width: 640px; flex: none; }
html.gs-playing .gs-bar { gap: 10px; }
html.gs-playing .nim-settings { flex: 1; min-width: 0; margin: 0; }
html.gs-playing .nim-settings .field-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
html.gs-playing .option-tabs { max-width: none; }
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 .status-pill { padding: 0; background: 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 .nim-status__text { flex: none; height: 1.5em; margin: 0 0 10px; line-height: 1.5; text-align: center; color: var(--play-text); font-size: .8125rem; }
html.gs-playing .nim-board-wrap { position: relative; flex: none; width: 100%; max-width: 560px; }
html.gs-playing .nim-stage { max-width: none; margin: 0; padding: 12px; }
html.gs-playing .nim-heap { height: 84px; min-height: 84px; }
html.gs-playing .nim-heap__head { min-height: 48px; }
html.gs-playing .nim-selection { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 12px; height: 70px; padding: 6px; font-size: .8125rem; }
html.gs-playing .nim-actions .btn--secondary { border: 1px solid var(--play-border); background: var(--play-hud-bg); color: var(--play-text); box-shadow: none; }
html.gs-playing .nim-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 .nim-result { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 0; background: rgba(8, 15, 31, .96); border: 1px solid var(--play-border); color: var(--play-text); }
html.gs-playing .nim-result__detail { color: var(--play-text-muted); }
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: 18px; }
  html.gs-playing .game-controls { margin-top: 24px; }
}
@media (max-width: 480px) {
  html.gs-playing .nim-stage { padding: 8px; }
  html.gs-playing .nim-heap { height: 64px; min-height: 64px; padding: 6px; gap: 4px; }
  html.gs-playing .nim-heap__head { min-height: 22px; }
  html.gs-playing .nim-board { gap: 6px; }
  html.gs-playing .nim-selection { margin-top: 8px; }
  html.gs-playing .nim-actions { margin-top: 8px; }
  html.gs-playing .option-tab small { font-size: .6rem; }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel { display: grid; grid-template-columns: minmax(200px, 250px) minmax(0, 360px); grid-template-areas: "bar board" "hud board" "status board" "controls board"; gap: 6px 16px; align-content: start; justify-content: center; }
  html.gs-playing .gs-bar { grid-area: bar; }
  html.gs-playing .gs-hud { grid-area: hud; }
  html.gs-playing .nim-status__text { grid-area: status; }
  html.gs-playing .game-controls { grid-area: controls; }
  html.gs-playing .nim-board-wrap { grid-area: board; }
  html.gs-playing .nim-stage { padding: 6px; }
  html.gs-playing .nim-heap { grid-template-columns: 76px minmax(0, 1fr); height: 48px; min-height: 48px; padding: 4px; gap: 4px; }
  html.gs-playing .nim-heap__head { min-height: 32px; flex-direction: row; flex-wrap: wrap; gap: 0 4px; }
  html.gs-playing .nim-heap__note { font-size: .6rem; }
  html.gs-playing .nim-heap__chips { min-height: 0; gap: 4px; }
  html.gs-playing .nim-board { gap: 4px; }
  html.gs-playing .nim-selection { height: 56px; margin-top: 6px; }
  html.gs-playing .nim-actions { margin-top: 6px; }
}
@media (max-width: 480px) and (max-height: 600px) {
  html.gs-playing .nim-status__text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  html.gs-playing .nim-heap { grid-template-columns: 64px minmax(0, 1fr); height: 50px; min-height: 50px; padding: 4px; }
  html.gs-playing .nim-heap__head { gap: 0 4px; }
  html.gs-playing .nim-heap__note { font-size: .6rem; white-space: normal; }
  html.gs-playing .nim-selection { height: 60px; }
  html.gs-playing .game-controls { margin-top: 6px; }
}
@media (max-width: 360px) {
  html.gs-playing .option-tab { padding-inline: 2px; font-size: .6875rem; white-space: nowrap; }
  html.gs-playing .option-tab small { font-size: .5625rem; }
}
