:root {
  --bg: #f5efe4;
  --bg-soft: #ebe3d2;
  --bg-deep: #e0d4ba;
  --felt: #5b9b76;
  --felt-light: #7ab592;
  --felt-deep: #3d7256;
  --frame: #4a3220;
  --frame-light: #6b4828;
  --ink: #2a2218;
  --ink-soft: #5a4e3a;
  --ink-mute: #8a7d65;
  --accent: #d96f57;
  --accent-deep: #c45a44;
  --line: rgba(42, 34, 24, 0.12);
  --header-bg: #2c3e50;
}

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

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Zen Maru Gothic', 'Hiragino Kaku Gothic ProN', 'メイリオ', sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(91, 155, 118, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 50% 100%, rgba(217, 111, 87, 0.08) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ============ サイトヘッダー（あそぶネット枠） ============ */
.site-header {
  position: relative;
  z-index: 3;
  background-color: var(--header-bg);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.back-link {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: white;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.9rem;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.back-link:hover, .back-link:focus-visible {
  background: rgba(255,255,255,0.12);
  outline: none;
}

.site-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* ============ メインステージ ============ */
.stage {
  position: relative;
  z-index: 2;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 20px 32px;
  display: flex;
  flex-direction: column;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.title {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
}

.title .dot-b, .title .dot-w {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.title .dot-b {
  background: radial-gradient(circle at 30% 30%, #4a4036, #050302);
}

.title .dot-w {
  background: radial-gradient(circle at 30% 30%, #fff, #d8cfb9);
  border: 1px solid rgba(0,0,0,0.1);
}

/* ============ モード切替 ============ */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  background: var(--bg-soft);
  border-radius: 16px;
  padding: 6px;
}

.mode-tab {
  padding: 14px 12px;
  background: transparent;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-mute);
  cursor: pointer;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.mode-tab:hover:not(.active) {
  color: var(--ink-soft);
}

.mode-tab.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(42, 34, 24, 0.08);
}

.mode-tab .emoji { font-size: 20px; }

/* ============ CPU難易度 ============ */
.difficulty-select {
  background: white;
  border-radius: 16px;
  padding: 14px 12px;
  margin-bottom: 14px;
  border: 2px solid var(--bg-deep);
}

.difficulty-label,
.color-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 10px;
  text-align: center;
}

.difficulty-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.diff-btn {
  padding: 10px 4px;
  background: var(--bg-soft);
  border: 2px solid transparent;
  border-radius: 12px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-mute);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.diff-btn .face { font-size: 22px; }

.diff-btn:hover:not(.active) {
  background: var(--bg-deep);
}

.diff-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: scale(1.05);
}

/* ============ 石の色選択 ============ */
.color-select {
  background: white;
  border-radius: 16px;
  padding: 14px 12px;
  margin-bottom: 18px;
  border: 2px solid var(--bg-deep);
}

.color-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.color-btn {
  padding: 10px 4px;
  background: var(--bg-soft);
  border: 2px solid transparent;
  border-radius: 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-mute);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.color-btn:hover:not(.active) {
  background: var(--bg-deep);
}

.color-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: scale(1.04);
}

.color-sample {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.color-sample.black {
  background: radial-gradient(circle at 32% 28%, #5a4f42 0%, #2a2218 35%, #050302 80%);
}

.color-sample.white {
  background: radial-gradient(circle at 32% 28%, #ffffff 0%, #f5ecd7 50%, #ddd0a8 100%);
  border: 1px solid rgba(0,0,0,0.1);
}

.color-sample.random {
  background: linear-gradient(135deg, #fff 0%, #fff 50%, #2a2218 50%, #2a2218 100%);
  font-size: 16px;
}

/* ============ ターン表示 ============ */
.turn-banner {
  text-align: center;
  margin-bottom: 14px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-soft);
  min-height: 24px;
}

.turn-banner .player-color {
  color: var(--ink);
  font-weight: 900;
  font-size: 18px;
}

/* ============ スコア ============ */
.vs-area {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.player-card {
  background: white;
  border-radius: 16px;
  padding: 14px 12px;
  text-align: center;
  border: 3px solid transparent;
  transition: all 0.3s;
  position: relative;
}

.player-card.active {
  border-color: var(--accent);
  box-shadow: 0 6px 20px rgba(217, 111, 87, 0.25);
  transform: translateY(-2px);
}

.player-card.active::before {
  content: attr(data-active-label);
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: 0.05em;
}

.player-stone-big {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  margin: 0 auto 6px;
}

.player-stone-big.black {
  background: radial-gradient(circle at 32% 28%, #5a4f42 0%, #2a2218 35%, #050302 80%);
  box-shadow:
    inset -2px -2px 4px rgba(255, 240, 200, 0.06),
    0 3px 6px rgba(0, 0, 0, 0.25);
}

.player-stone-big.white {
  background: radial-gradient(circle at 32% 28%, #ffffff 0%, #f5ecd7 50%, #ddd0a8 100%);
  box-shadow:
    inset -2px -2px 4px rgba(120, 100, 70, 0.2),
    0 3px 6px rgba(0, 0, 0, 0.2);
}

.player-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}

.player-score {
  font-family: 'Fraunces', serif;
  font-size: 32px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}

.vs-mark {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 22px;
  color: var(--ink-mute);
  font-weight: 500;
}

/* ============ 盤面 ============ */
.board-container {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  margin-bottom: 24px;
}

.board-frame {
  position: absolute;
  inset: -14px;
  background: linear-gradient(135deg, var(--frame-light) 0%, var(--frame) 50%, var(--frame-light) 100%);
  border-radius: 12px;
  box-shadow:
    0 8px 24px rgba(42, 34, 24, 0.25),
    0 2px 6px rgba(42, 34, 24, 0.15);
}

.board-frame::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(255, 230, 180, 0.2);
  border-radius: 6px;
}

.board {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, var(--felt-light) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, var(--felt-deep) 0%, transparent 60%),
    linear-gradient(135deg, var(--felt) 0%, var(--felt-deep) 100%);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
}

.board-grid {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.board-grid svg { width: 100%; height: 100%; }

.cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  z-index: 4;
}

.cell {
  position: relative;
  cursor: default;
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
}

.cell.legal { cursor: pointer; }

.cell.legal:hover .hint {
  background: rgba(255, 255, 255, 0.6);
}

.cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
  border-radius: 4px;
}

.stone {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  z-index: 5;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.stone.black {
  background:
    radial-gradient(circle at 32% 28%, #5a4f42 0%, #2a2218 30%, #0a0805 70%, #000 100%);
  box-shadow:
    inset -2px -3px 6px rgba(255, 240, 200, 0.05),
    0 3px 6px rgba(0, 0, 0, 0.5),
    0 1px 2px rgba(0, 0, 0, 0.3);
}

.stone.white {
  background:
    radial-gradient(circle at 32% 28%, #ffffff 0%, #f5ecd7 45%, #ddd0a8 90%, #c4b88a 100%);
  box-shadow:
    inset -2px -3px 6px rgba(120, 100, 70, 0.3),
    0 3px 6px rgba(0, 0, 0, 0.4),
    0 1px 2px rgba(0, 0, 0, 0.2);
}

.stone.flipping {
  animation: flip 0.45s cubic-bezier(0.4, 0.0, 0.2, 1);
}

@keyframes flip {
  0%   { transform: rotateY(0deg); }
  50%  { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

.stone.placing {
  animation: place 0.3s ease-out;
}

@keyframes place {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.stone.last::after {
  content: '';
  position: absolute;
  inset: 25%;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(217, 111, 87, 0.6);
}

.hint {
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  border: 2px dashed rgba(255, 255, 255, 0.7);
  z-index: 4;
  pointer-events: none;
  animation: hintBounce 1.6s ease-in-out infinite;
}

@keyframes hintBounce {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.15); opacity: 1; }
}

/* ============ アクション ============ */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.action-btn {
  padding: 16px 8px;
  background: white;
  border: 2px solid var(--bg-deep);
  border-radius: 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.action-btn:hover:not(:disabled) {
  background: var(--bg-soft);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(42, 34, 24, 0.1);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.action-btn .emoji { font-size: 26px; }

.action-btn.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.action-btn.primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

/* ============ ゲーム説明（SEO） ============ */
.game-info {
  margin-top: 28px;
  background: white;
  border-radius: 16px;
  padding: 18px 18px;
  border: 2px solid var(--bg-deep);
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-soft);
}

.game-info h2 {
  font-size: 16px;
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 8px;
}

.game-info h3 {
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  margin: 12px 0 6px;
}

.game-info p { margin-bottom: 4px; }

.game-info ul {
  padding-left: 18px;
}

.game-info li { margin-bottom: 4px; }

/* ============ モーダル ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(42, 34, 24, 0.55);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease-out;
}

.modal-panel {
  position: relative;
  background: white;
  border-radius: 24px;
  padding: 24px 22px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 12px 48px rgba(0,0,0,0.3);
  animation: popIn 0.25s cubic-bezier(0.4, 0.0, 0.2, 1);
  text-align: center;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 14px;
}

.modal-list {
  text-align: left;
  font-size: 14px;
  color: var(--ink-soft);
  padding-left: 22px;
  margin-bottom: 18px;
  line-height: 1.7;
}

.modal-list li { margin-bottom: 4px; }

.result-emoji {
  font-size: 56px;
  margin: 4px 0 8px;
}

.result-text {
  font-size: 22px;
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 16px;
}

.result-score {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: var(--bg-soft);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 20px;
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 600;
}

.result-score > div {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.result-score .player-stone-big {
  width: 32px;
  height: 32px;
  margin: 0;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal-btn {
  padding: 12px 16px;
  background: var(--bg-soft);
  border: 2px solid var(--bg-deep);
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s;
}

.modal-btn:hover {
  background: var(--bg-deep);
}

.modal-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.modal-btn.primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

/* ============ サイトフッター ============ */
.site-footer {
  position: relative;
  z-index: 3;
  background-color: var(--header-bg);
  color: white;
  text-align: center;
  padding: 14px 0;
  margin-top: 12px;
  font-size: 0.8rem;
}

/* ============ レスポンシブ ============ */
@media (max-width: 480px) {
  .stage { padding: 16px 12px 24px; }
  .title { font-size: 26px; }
  .player-name { font-size: 13px; }
  .player-score { font-size: 28px; }
  .action-btn { font-size: 13px; padding: 14px 6px; }
  .action-btn .emoji { font-size: 22px; }
  .diff-btn { font-size: 10px; }
  .diff-btn .face { font-size: 20px; }
  .color-btn { font-size: 11px; }
  .back-link { font-size: 0.85rem; }
  .site-name { font-size: 1rem; }
  .modal-panel { padding: 20px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .hint { animation: none; }
  .stone.flipping, .stone.placing { animation: none; }
  .modal-backdrop, .modal-panel { animation: none; }
}
