/* ================================
   グローバル設定
   ================================ */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #5338e8 0, #3b028c 60%, #3903fb 70%);
  color: #f5f5f5;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden {
  display: none !important;
}

/* ================================
   対戦画面 共通
   ================================ */

#info {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  margin: 8px 0 4px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 10px;
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.7),
    inset 0 0 8px rgba(255, 255, 255, 0.08);
}

#turn,
#score {
  font-size: 14px;
}

#main {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  max-width: 1100px;
  padding: 4px 4px 24px;
}

/* 盤エリア */
#board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* ================================
   オセロ盤
   ================================ */

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(440px, 70vmin);
  height: min(440px, 70vmin);
  background: radial-gradient(circle at top, #234c38, #07130f 65%);
  border-radius: 18px;
  padding: 8px;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.95),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  position: relative;
}

/* 各マス */
.cell {
  position: relative;
  border-radius: 6px;
  background: radial-gradient(circle at 30% 20%, #3e7a56, #13422c 70%);
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ハイライト：マス中央に白い小さな光点 */
.cell.highlight::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.45),
    rgba(255, 255, 255, 0)
  );
  opacity: 0.45;
  pointer-events: none;
}

/* クリック時のフラッシュ */
.cell.flash {
  animation: cellFlash 0.25s ease-out;
}

@keyframes cellFlash {
  0%   { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.9); }
  100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

/* 石 */
.stone {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* 黒石 */
.stone.black {
  background: radial-gradient(circle at 30% 20%, #444, #000);
}

/* 白石 */
.stone.white {
  background: radial-gradient(circle at 30% 20%, #fff, #ccc);
}

/* 石がポンっと現れる */
.stone.appear {
  animation: stoneAppear 0.18s ease-out;
}

@keyframes stoneAppear {
  0%   { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}

/* ひっくり返る */
.stone.flip {
  animation: stoneFlip 0.25s ease-out;
}

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

/* ================================
   プレイヤー情報（上下バー）
   ================================ */

.player-info {
  width: min(440px, 70vmin);
  max-width: 100%;
  padding: 4px 8px 6px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 12px;
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  display: flex;
  gap: 8px;
  position: relative;
  z-index: 1;
}
/* Back to Title (local match only) */
.back-to-title-button{
  margin-top: 8px;
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.45);
  color: rgba(255,255,255,0.9);
  cursor: pointer;
}

.back-to-title-button:hover{
  background: rgba(0,0,0,0.6);
}

.back-to-title-button.hidden{
  display: none;
}
.player-info-opponent {
  justify-content: flex-end;
  align-items: flex-start;
}

.player-info-self {
  justify-content: flex-start;
  align-items: flex-start;
}

/* アバター＋色石縦並び */
.avatar-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.avatar {
  width: 80px;
  height: 80px;
  border-radius: 16px;
  object-fit: cover;
  border: 2px solid rgba(255, 215, 0, 0.9);
  box-shadow:
    0 0 16px rgba(0,0,0,0.8),
    0 0 4px rgba(255,255,255,0.4);
}

/* Add: Prevent avatar from shrinking / shifting for opponent */
#opponent-info .avatar-column {
  flex: 0 0 auto;
  order: 2;          /* right */
  align-items: center;
}

/* ランク別アバター枠色 */
.avatar.rank-bronze {
  border-color: #cd7f32;
}
.avatar.rank-silver {
  border-color: #c0c0c0;
}
.avatar.rank-gold {
  border-color: #ffd700;
}
.avatar.rank-platinum {
  border-color: #e5e4e2;
}
.avatar.rank-diamond {
  border-color: #5ce1e6;
}

.color-stone-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-stone {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
}

.color-stone.stone-black {
  background: radial-gradient(circle at 30% 20%, #444, #000);
}

.color-stone.stone-white {
  background: radial-gradient(circle at 30% 20%, #fff, #ccc);
}

.stone-count {
  font-size: 0.9rem;
  color: #f5f5f5;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}

/* テキスト＋チャットブロック */
.player-chat-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#opponent-info .player-chat-wrapper {
  align-items: flex-start;
  justify-content: flex-start;
  flex: 1;
  min-width: 0;
  order: 1;          /* left */
}

.player-text-row {
  font-size: 12px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================================
   チャット吹き出し
   ================================ */

.chat-bubble {
  position: relative;
  display: inline-block;
  max-width: 260px;
  padding: 4px 8px;
  margin: 2px 0 2px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.85);
  font-size: 12px;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  color: #f5f5f5;
  word-wrap: break-word;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* 表示アニメーション */
.chat-bubble.show {
  animation: bubbleFade 3s forwards;
}

@keyframes bubbleFade {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }
  10% {
    opacity: 1;
    transform: translateY(0);
  }
  80% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-4px);
  }
}

/* 相手側 */
.player-info-opponent .chat-bubble {
  align-self: flex-end;
}

.player-info-opponent .chat-bubble::after {
  content: "";
  position: absolute;
  right: -8px;
  top: 8px;
  border-width: 6px 0 6px 8px;
  border-style: solid;
  border-color: transparent transparent transparent rgba(0, 0, 0, 0.85);
}

/* 自分側 */
.player-info-self .chat-bubble::after {
  content: "";
  position: absolute;
  left: -8px;
  top: 8px;
  border-width: 6px 8px 6px 0;
  border-style: solid;
  border-color: transparent rgba(0, 0, 0, 0.85) transparent transparent;
}

/* ================================
   チャット入力フォーム & 自分のコントロール
   ================================ */

.chat-form-inline {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.chat-form-inline input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.5);
  color: #f5f5f5;
  outline: none;
}

.chat-form-inline input[type="text"]:focus {
  box-shadow: 0 0 0 1px rgba(255, 215, 0, 0.7);
}

.chat-form-inline button {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 215, 0, 0.7);
  background: linear-gradient(135deg, #f4d574, #e6ae2d);
  color: #3d2c0a;
  cursor: pointer;
  font-weight: 600;
}

/* 自分側のコントロール（降参・音） */
.player-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
  flex-wrap: wrap;
}

.player-controls button,
.player-controls label {
  font-size: 12px;
}

/* 通報ボタン */
.report-button {
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 99, 132, 0.8);
  background: rgba(255, 99, 132, 0.15);
  color: #ffb3c1;
  cursor: pointer;
  line-height: 1.2;
  vertical-align: middle;
}

/* ================================
   再戦オーバーレイ（シンプル版）
   ================================ */

#rematch-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

#rematch-dialog {
  min-width: 260px;
  max-width: 90vw;
  padding: 16px 18px 14px;
  background: radial-gradient(circle at top, #1b2729 0, #050808 70%);
  border-radius: 12px;
  box-shadow:
    0 14px 30px rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(255, 255, 255, 0.12);
  color: #f5f5f5;
  text-align: center;
}

#rematch-result-text {
  white-space: pre-line;
  font-size: 14px;
  margin-bottom: 10px;
}

.rematch-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.rematch-buttons button {
  min-width: 100px;
}

/* ================================
   年齢確認オーバーレイ
   ================================ */

#age-check-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

.age-check-dialog {
  width: min(340px, 90vw);
  padding: 16px 18px 18px;
  background: #111827;
  border-radius: 12px;
  box-shadow:
    0 14px 30px rgba(0,0,0,0.9),
    0 0 0 1px rgba(255,255,255,0.12);
  color: #e5e7eb;
  text-align: left;
  font-size: 14px;
}

.age-check-title {
  font-weight: bold;
  margin-bottom: 8px;
}

.age-check-buttons {
  display: flex;
  margin-top: 12px;
  gap: 8px;
  justify-content: flex-end;
}

.age-check-buttons button {
  padding: 4px 12px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 215, 0, 0.7);
  background: linear-gradient(135deg, #f4d574, #e6ae2d);
  color: #3d2c0a;
  cursor: pointer;
}

/* ================================
   タイトル画面 (title.html)
   ================================ */

#title-screen {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 32px;
  text-align: center;
  background: #000; /* タイトル画面は黒背景にする */
}

/* タイトルロゴ＋左右の石 */
.title-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.title-stone {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.8),
    0 0 4px rgba(255, 255, 255, 0.3);
}

.title-stone-black {
  background: radial-gradient(circle at 30% 20%, #444, #000);
}

.title-stone-white {
  background: radial-gradient(circle at 30% 20%, #fff, #ccc);
}

.game-title {
  font-size: clamp(28px, 5vw, 40px);
  letter-spacing: 0.18em;
  margin-bottom: 8px;
  text-transform: uppercase;
  color: #ffffff;
  text-shadow:
    0 0 18px rgba(0,0,0,0.9),
    0 0 8px rgba(255,255,255,0.4);
}

.game-subtitle {
  font-size: 14px;
  color: #d3e1ff;
  margin-bottom: 24px;
}

/* タイトル画面のボタン */
.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.title-button {
  padding: 10px 10px;
  font-size: 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 215, 0, 0.8);
  background: linear-gradient(135deg, #f4d574, #e6ae2d);
  color: #3d2c0a;
  cursor: pointer;
  font-weight: 600;
  box-shadow:
    0 8px 16px rgba(0, 0, 0, 0.75),
    0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* タイトル画面の言語選択など */
.title-footer {
  margin-top: 12px;
  font-size: 11px;
  color: #d1d5db;
}

/* タイトル画面の利用規約リンク */
#title-legal-links a {
  color: #9ca3ff;
  text-decoration: underline;
  margin: 0 6px;
  font-size: 11px;
}

/* 対戦画面では全文リンクを非表示にしておく */
#legal-links,
#legal-overlay {
  display: none !important;
}


#matchingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
}

#matchingOverlay.hidden {
  display: none;
}

.matching-card {
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 24px 28px;
  border-radius: 16px;
  text-align: center;
  width: 280px;
}

.spinner {
  margin: 16px auto;
  width: 36px;
  height: 36px;
  border: 4px solid #555;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ================================
   スマホ向け調整
   ================================ */

@media (max-width: 900px) {
  #main {
    flex-direction: column;
    align-items: center;
    padding: 0 6px 18px;
    margin: 6px auto 18px;
    gap: 10px;
  }

  .board {
    width: min(92vw, 480px);
    height: min(92vw, 480px);
    padding: 8px;
    border-radius: 16px;
  }

  .avatar {
    width: 72px;
    height: 72px;
  }

  .player-info {
    width: min(92vw, 480px);
  }
}
/* opponent bar – mirror local layout */
#opponent-info {
  display: flex;
  flex-direction: row;
  align-items: flex-start;      /* top align */
  justify-content: space-between;
  gap: 8px;
}

/* 相手側のテキストブロックを左詰め＆上詰め */
#opponent-info .player-chat-wrapper {
  align-items: flex-start;
  justify-content: flex-start;
  flex: 1;
  min-width: 0;
  order: 1;          /* left */
}

/* opponent meta row – same as local */
#opponent-info .player-text-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;

  margin-top: 0;
  margin-bottom: 2px;

  font-size: 12px;
  line-height: 1.2;

  white-space: nowrap;
}

#opponent-info .player-text-row > * {
  flex: 0 0 auto;
}

#opponent-info .player-name,
#opponent-info .player-role,
#opponent-info .player-rank,
#opponent-info .player-rating {
  white-space: nowrap;
}

/* 通報ボタンは行内で小さく保つ */
#opponent-info .report-button {
  margin-left: 2px;
}

/* opponent clock stays beside avatar, not in text flow */
#opponent-info .clock {
  margin-left: 6px;
}

/* ===== Board disabled UX ===== */
.board-disabled #board {
  opacity: 0.55;
  filter: grayscale(40%);
  pointer-events: none; /* 念のため */
}

.board-disabled .cell.highlight {
  opacity: 0; /* ハイライトを完全に消す */
}
/* ================================
   UI polish pack (Title + Buttons)
   ================================ */

:root{
  --ui-panel: rgba(0,0,0,0.58);
  --ui-panel-strong: rgba(0,0,0,0.74);
  --ui-border: rgba(255,255,255,0.14);
  --ui-text: rgba(255,255,255,0.92);
  --ui-muted: rgba(255,255,255,0.75);
  --ui-accent: #ffd56a;
  --ui-accent2:#ffb84a;
}

/* Title background (deep) */
#title-screen{
  background:
    radial-gradient(900px 520px at 50% 0%, rgba(255,213,106,0.12) 0%, rgba(255,213,106,0) 60%),
    radial-gradient(1100px 780px at 50% -10%, rgba(58,43,220,0.55) 0%, rgba(58,43,220,0) 70%),
    linear-gradient(180deg, #04050b 0%, #0b0f1a 55%, #120a2e 100%) !important;
}

.title-container{
  width: min(560px, 92vw);
  padding: 16px 14px 18px;
  border-radius: 18px;
  background: var(--ui-panel);
  border: 1px solid var(--ui-border);
  box-shadow: 0 14px 30px rgba(0,0,0,0.75);
}

.lang-switch-bar{
  display:flex;
  justify-content:center;
  gap:8px;
  margin-bottom:12px;
  flex-wrap:wrap;
}

.lang-btn{
  padding:6px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,0.18);
  background:rgba(0,0,0,0.35);
  color:var(--ui-muted);
  cursor:pointer;
  font-size:12px;
  box-shadow:0 8px 16px rgba(0,0,0,0.35);
}
.lang-btn:hover{ color:var(--ui-text); border-color:rgba(255,255,255,0.28); }

.mode-buttons{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:8px;
  margin:6px 0 2px;
}

#title-screen .start-button{
  width: 320px;
  max-width: 320px;
  padding:8px 12px;
  border-radius:10px;
  font-size:13px;
  line-height:1.15;
  border:1px solid rgba(255,255,255,0.14);
  background:linear-gradient(135deg, rgba(255,213,106,0.95), rgba(255,184,74,0.92));
  color:#2b1c06;
  font-weight:800;
  letter-spacing:0.02em;
  cursor:pointer;
  box-shadow:0 10px 22px rgba(0,0,0,0.55);
  transition:transform .08s ease, filter .08s ease;
}
#title-screen .start-button:hover{ filter:brightness(1.02); }
#title-screen .start-button:active{ transform:translateY(1px); }


#ai-difficulty-wrap{
  width: min(360px, 88vw);
}

.settings-select{
  padding:6px 10px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,0.18);
  background:rgba(0,0,0,0.35);
  color:var(--ui-text);
  outline:none;
}
.settings-select:focus{ box-shadow:0 0 0 2px rgba(255,213,106,0.35); }

@keyframes titleGlow{
  0%{ text-shadow:0 0 18px rgba(0,0,0,0.9), 0 0 8px rgba(255,255,255,0.35); }
  50%{ text-shadow:0 0 22px rgba(0,0,0,0.9), 0 0 12px rgba(255,213,106,0.35); }
  100%{ text-shadow:0 0 18px rgba(0,0,0,0.9), 0 0 8px rgba(255,255,255,0.35); }
}
.game-title{ animation:titleGlow 3.5s ease-in-out infinite; }

/* Online block note: match panel */
.title-block-note{
  background: var(--ui-panel-strong) !important;
  border: 1px solid var(--ui-border) !important;
}
/* ===== Fix: prevent black buttons on title / online select ===== */

/* Title screen main buttons */
#title-screen button{
  background: linear-gradient(135deg, #f4d574, #e6ae2d);
  color: #3d2c0a;
}

/* Online mode overlay buttons (Casual / Ranked / Cancel) */
#online-mode-overlay button,
#online-mode-dialog button{
  background: linear-gradient(135deg, #f4d574, #e6ae2d);
  color: #3d2c0a;
  border: 1px solid rgba(255, 215, 0, 0.8);
}



/* Disabled buttons should look intentionally disabled, not broken */
#title-screen button:disabled,
#online-mode-overlay button:disabled,
#online-mode-dialog button:disabled{
  background: linear-gradient(135deg, #9ca3af, #6b7280);
  color: #1f2937;
  opacity: 0.7;
  cursor: not-allowed;
}

/* ================================
   Last move marker (minimal)
   ================================ */

/* last-move が付いたセルだけ position 基準にする（他に影響させない） */
.cell.last-move{
  position: relative;
}

/* Premium ring (safe CSS) */
@keyframes lastMoveGlow {
  0%   { opacity: 0.70; box-shadow: 0 0 10px rgba(255, 213, 106, 0.18), 0 0 0 1px rgba(0,0,0,0.35) inset; }
  50%  { opacity: 0.98; box-shadow: 0 0 16px rgba(255, 213, 106, 0.28), 0 0 28px rgba(255, 184, 74, 0.14), 0 0 0 1px rgba(0,0,0,0.35) inset; }
  100% { opacity: 0.70; box-shadow: 0 0 10px rgba(255, 213, 106, 0.18), 0 0 0 1px rgba(0,0,0,0.35) inset; }
}

.cell.last-move::before{
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 10px;
  pointer-events: none;
  z-index: 3;

  /* Metallic feel via layered borders */
  border: 2px solid rgba(255, 213, 106, 0.92);
  outline: 1px solid rgba(255, 244, 215, 0.28);
  outline-offset: -4px;

  background: linear-gradient(135deg,
    rgba(255, 255, 255, 0.10),
    rgba(255, 213, 106, 0.08),
    rgba(255, 184, 74, 0.05));

  animation: lastMoveGlow 1.7s ease-in-out infinite;
}
.title-screen{
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
}

.title-card{
  width: min(90vw, 420px);
  padding: 24px 20px;
  border-radius: 16px;
  background: rgba(20,20,20,0.9);
  text-align: center;
}

.game-title{
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 0.08em;
}

.subtitle{
  margin: 0 0 18px;
  opacity: 0.8;
}

.start-btn{
  width: 100%;
  padding: 14px 16px;
  font-size: 18px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
}

.title-actions{
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.link-btn{
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2);
  background: transparent;
  cursor: pointer;
}