/* 四目並べ固有スタイル */

.cf-settings {
  margin-top: 4px;
}

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

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

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

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

.cf-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  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);
}

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

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

.cf-score {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.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, #e879f9 20%, var(--md-sys-color-surface));
  color: #a21caf;
}

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

.status-pill.is-draw {
  background: color-mix(in srgb, #64748b 16%, var(--md-sys-color-surface));
  color: #475569;
}

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

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

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

.cf-result.is-draw {
  border: 1px solid color-mix(in srgb, #64748b 34%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, #64748b 10%, var(--md-sys-color-surface));
}

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

.cf-result__detail {
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9rem;
}

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

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

.cf-board-wrap {
  --cf-player: #22d3ee;
  --cf-player-deep: #0891b2;
  --cf-cpu: #e879f9;
  --cf-cpu-deep: #c026d3;
  --cf-frame: #38bdf8;
  --cf-slot: #0b1630;
  --cf-board-bg: linear-gradient(160deg, #14284f 0%, #0d1a36 55%, #0a1428 100%);
  display: flex;
  justify-content: center;
  margin: 0 auto 12px;
  max-width: min(100%, 420px);
}

.cf-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
  width: 100%;
  padding: 12px;
  border: 2px solid color-mix(in srgb, var(--cf-frame) 70%, #ffffff);
  border-radius: 18px;
  background:
    radial-gradient(circle at 18% 8%, rgba(56, 189, 248, 0.22), transparent 42%),
    radial-gradient(circle at 88% 92%, rgba(232, 121, 249, 0.18), transparent 46%),
    var(--cf-board-bg);
  box-shadow:
    0 0 0 1px rgba(56, 189, 248, 0.25),
    0 12px 28px rgba(8, 20, 48, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.cf-board.is-locked .cf-column:not(.is-disabled) {
  cursor: default;
}

.cf-column {
  appearance: none;
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 5px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  min-width: 0;
  border-radius: 10px;
  transition: background-color 0.12s ease, box-shadow 0.12s ease;
}

.cf-column:hover:not(.is-disabled),
.cf-column.is-hover:not(.is-disabled) {
  background: rgba(56, 189, 248, 0.08);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.28);
}

.cf-column.is-disabled {
  cursor: not-allowed;
}

.cf-column:focus-visible {
  outline: 2px solid var(--cf-frame);
  outline-offset: 2px;
}

.cf-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.06), transparent 45%),
    var(--cf-slot);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.45),
    inset 0 -1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.cf-disc {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  display: block;
}

.cf-disc--player {
  background:
    radial-gradient(circle at 32% 28%, #a5f3fc 0%, var(--cf-player) 42%, var(--cf-player-deep) 100%);
  box-shadow:
    0 0 10px rgba(34, 211, 238, 0.55),
    inset 0 -3px 6px rgba(8, 145, 178, 0.45);
}

.cf-disc--player::after {
  content: "";
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
}

.cf-disc--cpu {
  background:
    radial-gradient(circle at 32% 28%, #f5d0fe 0%, var(--cf-cpu) 42%, var(--cf-cpu-deep) 100%);
  box-shadow:
    0 0 10px rgba(232, 121, 249, 0.55),
    inset 0 -3px 6px rgba(192, 38, 211, 0.45);
}

.cf-disc--cpu::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 3px;
  box-sizing: border-box;
}

.cf-disc--preview {
  background: rgba(34, 211, 238, 0.22);
  border: 2px dashed rgba(34, 211, 238, 0.7);
  box-shadow: none;
  opacity: 0.9;
}

.cf-cell.is-win .cf-disc {
  transform: scale(1.08);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.85),
    0 0 18px rgba(250, 204, 21, 0.95),
    0 0 28px rgba(34, 211, 238, 0.55);
  animation: cf-win-pulse 1s ease-in-out infinite alternate;
}

.cf-disc.is-dropping {
  animation: cf-drop 220ms cubic-bezier(0.2, 0.75, 0.25, 1) both;
}

@keyframes cf-drop {
  from {
    transform: translateY(var(--drop-from, -400%));
  }
  to {
    transform: translateY(0);
  }
}

@keyframes cf-win-pulse {
  from {
    filter: brightness(1.05);
  }
  to {
    filter: brightness(1.28);
  }
}

.cf-guide {
  margin: 0 0 14px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.875rem;
  line-height: 1.55;
  text-align: center;
}

.cf-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 18px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.82rem;
  font-weight: 600;
}

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

.cf-legend__swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cf-legend__swatch--player {
  background: radial-gradient(circle at 32% 28%, #a5f3fc, #22d3ee 55%, #0891b2);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.45);
}

.cf-legend__swatch--cpu {
  background: radial-gradient(circle at 32% 28%, #f5d0fe, #e879f9 55%, #c026d3);
  box-shadow: 0 0 8px rgba(232, 121, 249, 0.45);
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .cf-board-wrap {
    max-width: 100%;
  }

  .cf-board {
    gap: 4px;
    padding: 10px;
    border-radius: 14px;
  }

  .cf-column {
    gap: 4px;
  }

  .cf-status {
    flex-direction: column;
    align-items: stretch;
  }

  .cf-score {
    text-align: center;
  }

  .option-tab {
    min-height: 44px;
    font-size: 0.82rem;
  }
}

@media (max-width: 380px) {
  .cf-board {
    gap: 3px;
    padding: 8px;
  }

  .cf-column {
    gap: 3px;
  }

  .cf-disc--player::after,
  .cf-disc--cpu::after {
    border-width: 1.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cf-disc.is-dropping,
  .cf-cell.is-win .cf-disc,
  .cf-result {
    animation: none;
  }
}

/* 共通の背景・ボタンを使い、対戦設定と盤面を中央にまとめる。 */
html.gs-playing .game-panel {
  --md-sys-color-on-surface: var(--play-text);
  --md-sys-color-on-surface-variant: var(--play-text-muted);
  --md-sys-color-outline-variant: var(--play-border);
  --md-sys-color-surface: var(--play-hud-bg);
  --cf-chrome: 260px;
  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 .cf-settings { grid-area: settings; margin: 0 0 10px; }
html.gs-playing .option-tabs { gap: 6px; }
html.gs-playing .option-tab {
  min-height: 44px;
  padding: 4px;
  gap: 0;
  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: .625rem; }
html.gs-playing .option-tab:hover { 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 .cf-status {
  grid-area: status;
  width: 100%;
  margin: 0 0 14px;
  padding: 8px;
  gap: 8px;
  flex-wrap: nowrap;
  flex-direction: row;
  background: color-mix(in srgb, var(--play-hud-bg) 88%, transparent);
}
html.gs-playing .cf-status__main { flex: 1; flex-direction: column; align-items: center; gap: 4px; }
html.gs-playing .cf-status__text { font-size: .75rem; line-height: 1.5; min-height: 3em; text-align: center; }
html.gs-playing .cf-score {
  flex: 1;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 8px;
  border-left: 1px solid var(--play-border);
  font-size: .6875rem;
  white-space: normal;
  text-align: center;
}
html.gs-playing .status-pill.is-player { color: #67e8f9; }
html.gs-playing .status-pill.is-cpu { color: #f0abfc; }
html.gs-playing .status-pill.is-win { color: #6ee7b7; }
html.gs-playing .status-pill.is-lose { color: #fca5a5; }
html.gs-playing .status-pill.is-draw { color: var(--play-text-muted); }

html.gs-playing .cf-board-wrap {
  grid-area: board;
  position: relative;
  justify-self: center;
  width: min(100%, max(180px, (100dvh - var(--cf-chrome)) * 7 / 6), 560px);
  max-width: 100%;
  margin: 0 0 14px;
}
html.gs-playing .cf-board { border-color: var(--play-border); }
html.gs-playing .cf-result {
  position: absolute;
  inset: 0;
  z-index: 2;
  height: fit-content;
  max-height: 100%;
  overflow-y: auto;
  margin: auto;
  background: var(--play-hud-bg);
  border: 1px solid var(--play-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
html.gs-playing .cf-result__title { color: var(--play-text); }
html.gs-playing .cf-result.is-win .cf-result__title { color: #6ee7b7; }
html.gs-playing .cf-result.is-lose .cf-result__title { color: #fca5a5; }
html.gs-playing .game-panel .game-controls {
  grid-area: controls;
  justify-content: center;
  margin: 0;
}
html.gs-playing .cf-field .field-label,
html.gs-playing .cf-legend,
html.gs-playing .cf-guide {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .game-panel {
    --cf-chrome: 340px;
    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 .cf-settings { margin-bottom: 28px; }
  html.gs-playing .cf-status,
  html.gs-playing .cf-board-wrap { margin-bottom: 24px; }
  html.gs-playing .cf-board-wrap { max-width: 640px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel {
    --cf-chrome: 40px;
    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 .game-controls { grid-area: bar; justify-self: end; margin-bottom: 10px; }
  html.gs-playing .cf-board-wrap { align-self: center; margin: 0; }
}
