:root {
  --bg-page: #0f172a;
  --bg-card: #1e293b;
  --bg-cell: #0f172a;
  --bg-cell-hover: #1e293b;
  --border-subtle: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  /* プレイヤー ◯ (Blue / Cyan) */
  --o-primary: #38bdf8;
  --o-bg: rgba(56, 189, 248, 0.14);
  --o-piece-bg: linear-gradient(145deg, #0284c7, #0369a1);
  --o-piece-border: #7dd3fc;
  --o-glow: rgba(56, 189, 248, 0.45);

  /* プレイヤー ☓ (Rose / Coral) */
  --x-primary: #fb7185;
  --x-bg: rgba(251, 113, 133, 0.14);
  --x-piece-bg: linear-gradient(145deg, #e11d48, #be123c);
  --x-piece-border: #fda4af;
  --x-glow: rgba(251, 113, 133, 0.45);

  /* ハイライト */
  --select-ring: #facc15;
  --valid-target: rgba(74, 222, 128, 0.22);
  --valid-border: #4ade80;
  --win-bg: rgba(250, 204, 21, 0.22);
  --win-border: #facc15;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 20px 16px;
}

.app-container {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ヘッダー */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--bg-card);
  padding: 14px 20px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
}

.title-group h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.title-en {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--o-primary);
  letter-spacing: 0.05em;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.reset-btn {
  background: #334155;
  color: var(--text-main);
  border: 1px solid #475569;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.reset-btn:hover {
  background: #475569;
  border-color: #64748b;
}

.reset-btn:active {
  transform: scale(0.97);
}

/* モード＆難易度選択バー */
.mode-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--bg-card);
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
}

.mode-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-group.hidden {
  display: none;
}

.mode-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.segmented-control {
  display: inline-flex;
  background: #0f172a;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  gap: 2px;
}

.seg-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn:hover {
  color: var(--text-main);
}

.seg-btn.active {
  background: #334155;
  color: var(--text-main);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

/* ステータスバナー */
.status-banner {
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: 14px;
  padding: 14px 20px;
  text-align: center;
  transition: border-color 0.25s ease, background-color 0.25s ease;
}

.status-banner.turn-o {
  border-color: var(--o-primary);
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.12), var(--bg-card));
}

.status-banner.turn-x {
  border-color: var(--x-primary);
  background: linear-gradient(180deg, rgba(251, 113, 133, 0.12), var(--bg-card));
}

.status-banner.game-over {
  border-color: var(--win-border);
  background: linear-gradient(180deg, rgba(250, 204, 21, 0.18), var(--bg-card));
}

.turn-order-badge {
  display: inline-block;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.65);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 6px;
  border: 1px solid var(--border-subtle);
}

.status-main {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.status-sub {
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* メインレイアウト */
.game-main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 820px) {
  .game-main {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .player-panel {
    width: 100%;
    max-width: 420px;
  }
}

/* プレイヤー持ちコマパネル */
.player-panel {
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: 14px;
  padding: 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.player-panel.active-turn.player-o {
  border-color: var(--o-primary);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.18);
}

.player-panel.active-turn.player-x {
  border-color: var(--x-primary);
  box-shadow: 0 0 18px rgba(251, 113, 133, 0.18);
}

.player-panel.inactive-turn {
  opacity: 0.72;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.player-Identity {
  display: flex;
  align-items: center;
  gap: 8px;
}

.symbol-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1rem;
}

.symbol-o {
  background: var(--o-bg);
  color: var(--o-primary);
  border: 1px solid var(--o-primary);
}

.symbol-x {
  background: var(--x-bg);
  color: var(--x-primary);
  border: 1px solid var(--x-primary);
}

.player-name {
  font-weight: 700;
  font-size: 1rem;
}

.order-tag {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: #334155;
  color: #e2e8f0;
}

.hand-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.hand-pieces {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

@media (max-width: 820px) {
  .hand-pieces {
    flex-direction: row;
    justify-content: space-around;
    flex-wrap: wrap;
  }
}

.hand-slot {
  width: 100%;
  min-height: 76px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px dashed var(--border-subtle);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
}

@media (max-width: 820px) {
  .hand-slot {
    width: auto;
    min-width: 72px;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 8px;
  }
}

.slot-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.slot-size-name {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--text-main);
}

.slot-size-rank {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.hand-slot.used {
  opacity: 0.35;
}

.used-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 4px 8px;
}

/* 3x3 盤面 */
.board-section {
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(3, 124px);
  grid-template-rows: repeat(3, 124px);
  gap: 10px;
  background: var(--bg-card);
  padding: 14px;
  border-radius: 18px;
  border: 2px solid var(--border-subtle);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

@media (max-width: 460px) {
  .board-grid {
    grid-template-columns: repeat(3, 96px);
    grid-template-rows: repeat(3, 96px);
    gap: 8px;
    padding: 10px;
  }
}

.board-cell {
  background: var(--bg-cell);
  border: 2px solid var(--border-subtle);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

/* 直前の着手ハイライト（移動元・移動先） */
.board-cell.last-move-from {
  border-color: rgba(148, 163, 184, 0.65);
  border-style: dotted;
}

.board-cell.last-move-to {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.22);
}

/* 移動可能なマスのハイライト */
.board-cell.valid-target {
  background: var(--valid-target);
  border-color: var(--valid-border);
  border-style: dashed;
  cursor: pointer;
}

.board-cell.valid-target:hover {
  background: rgba(74, 222, 128, 0.34);
  transform: scale(1.02);
}

/* 勝利ラインのハイライト */
.board-cell.winning-cell {
  background: var(--win-bg);
  border-color: var(--win-border);
  box-shadow: inset 0 0 16px rgba(250, 204, 21, 0.35);
}

/* コマ共通スタイル */
.piece {
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  line-height: 1;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, outline 0.15s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
}

.piece.owner-O {
  background: var(--o-piece-bg);
  border: 3px solid var(--o-piece-border);
  color: #ffffff;
}

.piece.owner-X {
  background: var(--x-piece-bg);
  border: 3px solid var(--x-piece-border);
  color: #ffffff;
}

.piece.selectable {
  cursor: pointer;
}

.piece.selectable:hover {
  transform: scale(1.06);
}

.piece.selected {
  outline: 4px solid var(--select-ring);
  outline-offset: 3px;
  transform: scale(1.08);
  box-shadow: 0 0 20px rgba(250, 204, 21, 0.75);
  z-index: 2;
}

/* 5段階のサイズ設定 (XL > L > M > S > XS) */
.piece.size-XL {
  width: 98px;
  height: 98px;
}
.piece.size-L {
  width: 80px;
  height: 80px;
}
.piece.size-M {
  width: 64px;
  height: 64px;
}
.piece.size-S {
  width: 50px;
  height: 50px;
}
.piece.size-XS {
  width: 38px;
  height: 38px;
}

/* 手元スロット内のXL/Lは少しコンパクトに収める */
.hand-slot .piece.size-XL {
  width: 68px;
  height: 68px;
}
.hand-slot .piece.size-L {
  width: 58px;
  height: 58px;
}
.hand-slot .piece.size-M {
  width: 50px;
  height: 50px;
}
.hand-slot .piece.size-S {
  width: 42px;
  height: 42px;
}
.hand-slot .piece.size-XS {
  width: 34px;
  height: 34px;
}

@media (max-width: 460px) {
  .board-cell .piece.size-XL {
    width: 78px;
    height: 78px;
  }
  .board-cell .piece.size-L {
    width: 66px;
    height: 66px;
  }
  .board-cell .piece.size-M {
    width: 54px;
    height: 54px;
  }
  .board-cell .piece.size-S {
    width: 42px;
    height: 42px;
  }
  .board-cell .piece.size-XS {
    width: 32px;
    height: 32px;
  }
}

.piece-symbol {
  font-size: 1.2em;
  letter-spacing: -0.03em;
}

.piece.size-XL .piece-symbol {
  font-size: 1.65rem;
}
.piece.size-L .piece-symbol {
  font-size: 1.35rem;
}
.piece.size-M .piece-symbol {
  font-size: 1.1rem;
}
.piece.size-S .piece-symbol {
  font-size: 0.92rem;
}
.piece.size-XS .piece-symbol {
  font-size: 0.75rem;
}

.piece-size-badge {
  font-size: 0.7rem;
  font-weight: 800;
  margin-top: 2px;
  background: rgba(15, 23, 42, 0.55);
  padding: 1px 5px;
  border-radius: 4px;
}

.piece.size-S .piece-size-badge,
.piece.size-XS .piece-size-badge {
  font-size: 0.58rem;
  padding: 0 3px;
  margin-top: 0;
}

/* ルール説明フッター */
.rules-summary {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.rules-summary summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text-main);
}

.rules-summary ul {
  margin-top: 10px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  line-height: 1.5;
}

.rules-summary code {
  background: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
  color: #e2e8f0;
}
