/**
 * style.css - Upper Hand 全体レイアウト・UIコンポーネント
 * 
 * ライト/ダークテーマ対応、和モダンと北欧テーブルトップの配色
 */

:root {
  /* デフォルト: 温もりある白木と白磁調のライトテーマ */
  --bg-gradient: radial-gradient(circle at 50% 15%, #faf8f5 0%, #ede8e1 100%);
  --panel-bg: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(120, 100, 80, 0.12);
  --panel-shadow: 0 12px 32px rgba(60, 45, 30, 0.08);

  --text-main: #1c1917;
  --text-muted: #78716c;
  --text-accent: #b91c1c;

  --brand-grad: linear-gradient(135deg, #292524 30%, #57534e 100%);
  --btn-bg: rgba(120, 100, 80, 0.06);
  --btn-hover: rgba(120, 100, 80, 0.12);
  --btn-border: rgba(120, 100, 80, 0.15);

  --p1-active-border: #78716c;
  --p1-active-glow: rgba(120, 113, 108, 0.25);
  --p2-active-border: #1c1917;
  --p2-active-glow: rgba(28, 25, 23, 0.35);

  --select-bg: #ffffff;
  --select-color: #1c1917;
  --modal-bg: #ffffff;
  --modal-text: #292524;
  --modal-border: rgba(120, 100, 80, 0.15);
  --rule-bg: rgba(185, 28, 28, 0.06);

  --font-main: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
  /* 重厚なウォールナット調のダークテーマ */
  --bg-gradient: radial-gradient(circle at 50% 15%, #201d1a 0%, #110f0d 100%);
  --panel-bg: rgba(28, 25, 23, 0.85);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);

  --text-main: #f5f5f4;
  --text-muted: #a8a29e;
  --text-accent: #f87171;

  --brand-grad: linear-gradient(135deg, #ffffff 40%, #a8a29e 100%);
  --btn-bg: rgba(255, 255, 255, 0.06);
  --btn-hover: rgba(255, 255, 255, 0.12);
  --btn-border: rgba(255, 255, 255, 0.08);

  --p1-active-border: #d6d3d1;
  --p1-active-glow: rgba(214, 211, 209, 0.3);
  --p2-active-border: #78716c;
  --p2-active-glow: rgba(120, 113, 108, 0.35);

  --select-bg: #1c1917;
  --select-color: #f5f5f4;
  --modal-bg: #1c1917;
  --modal-text: #d6d3d1;
  --modal-border: rgba(255, 255, 255, 0.12);
  --rule-bg: rgba(248, 113, 113, 0.08);
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ヘッダー */
.app-header {
  width: 100%;
  max-width: 840px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--brand-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ボタン共通 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 10px;
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  backdrop-filter: blur(8px);
}

.btn:hover:not(:disabled) {
  background: var(--btn-hover);
  border-color: rgba(125, 110, 95, 0.3);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-icon-only {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
}

/* メインコンテナ */
.main-content {
  width: 100%;
  max-width: 840px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 0 16px 24px;
}

/* 対戦ステータスパネル */
.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 520px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 12px 20px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(12px);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-radius: 12px;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.player-card.active-turn {
  background: rgba(125, 110, 95, 0.08);
}

#p1-card.active-turn {
  border-color: var(--p1-active-border);
  box-shadow: 0 0 16px var(--p1-active-glow);
}

#p2-card.active-turn {
  border-color: var(--p2-active-border);
  box-shadow: 0 0 16px var(--p2-active-glow);
}

.ball-indicator {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

/* プレイヤーインジケーターは石のテーマ設定と完全連動 */
.p1-ball-style {
  background: var(--ball-p1-bg);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
  border: var(--ball-p1-border);
}

.p2-ball-style {
  background: var(--ball-p2-bg);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
  border: var(--ball-p2-border);
}

.player-info {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.player-count {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.match-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.ai-thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-accent);
  opacity: 0;
  transition: opacity 0.2s;
}

.ai-thinking-dot.thinking {
  opacity: 1;
  animation: pulse-dot 0.8s infinite alternate;
}

@keyframes pulse-dot {
  from { transform: scale(0.8); opacity: 0.4; }
  to { transform: scale(1.6); opacity: 1; }
}

/* ツールバー */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.select-group {
  display: flex;
  align-items: center;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  padding: 0 8px;
  height: 38px;
}

select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  padding: 4px 6px;
}

select option {
  background: var(--select-bg);
  color: var(--select-color);
}

/* モーダル */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
  transform: translateY(12px);
  transition: transform 0.25s ease;
}

.modal-overlay.show .modal-card {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--modal-text);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rule-highlight {
  background: var(--rule-bg);
  border-left: 3px solid var(--text-accent);
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
}

/* オンライン対戦モーダル */
.online-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.online-section.hidden {
  display: none !important;
}

.btn-online-primary {
  width: 100%;
  justify-content: center;
  background: var(--text-main);
  color: var(--modal-bg);
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn-online-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.online-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin: 4px 0;
}

.online-divider::before,
.online-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--modal-border);
}

.online-divider span {
  padding: 0 10px;
}

.join-box {
  display: flex;
  gap: 8px;
}

.room-code-input {
  flex: 1;
  background: var(--btn-bg);
  border: 1.5px solid var(--modal-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: 'JetBrains Mono', monospace, sans-serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 4px;
  text-align: center;
  color: var(--modal-text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.room-code-input:focus {
  border-color: var(--text-accent);
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12);
}

.room-code-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--btn-bg);
  border: 1.5px solid var(--modal-border);
  border-radius: 16px;
  padding: 16px 20px;
}

.room-code-text {
  font-family: 'JetBrains Mono', monospace, sans-serif;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--modal-text);
}

.status-pulse-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-muted);
  padding: 8px 0;
}

.status-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-accent);
  animation: pulse-dot 1.5s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% {
    transform: scale(0.85);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.25);
    opacity: 1;
    box-shadow: 0 0 8px var(--text-accent);
  }
}

.online-error-msg {
  color: var(--text-accent);
  font-size: 14px;
  text-align: center;
  padding: 8px 0;
}
