:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232735;
  --border: #2a2d3a;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }

/* ヘッダー */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}
.logo span { color: var(--primary); }

nav { display: flex; gap: 0.5rem; align-items: center; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--border); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* コンテナ */
.container { max-width: 800px; margin: 0 auto; padding: 1.5rem 1rem; }
.page-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.25rem; }

/* セクション見出し */
.section-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1.5rem 0 0.75rem;
  font-weight: 600;
}
.section-title:first-child { margin-top: 0; }

/* 試合カード */
.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
}
.match-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.match-card.live { border-color: rgba(239, 68, 68, 0.5); }

.match-info { flex: 1; min-width: 0; }
.match-teams {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.match-vs { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }
.match-meta {
  display: flex; gap: 0.6rem; font-size: 0.8rem;
  color: var(--text-muted); flex-wrap: wrap;
}

/* バッジ */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-live {
  background: rgba(239, 68, 68, 0.15); color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.badge-live::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
.badge-scheduled {
  background: rgba(59, 130, 246, 0.15); color: var(--primary);
  border: 1px solid rgba(59, 130, 246, 0.3);
}
.badge-pre {
  background: rgba(245, 158, 11, 0.15); color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-ended {
  background: rgba(100, 116, 139, 0.15); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-competition {
  background: rgba(245, 158, 11, 0.15); color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* 試合詳細・チャット */
.match-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  text-align: center;
}
.match-header h1 {
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}
.match-header .meta {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

/* スコア表示 */
.match-score {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 1rem;
  margin: 0.75rem 0 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-radius: 12px;
}
.score-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}
.score-team-name {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
}
.score-num {
  font-size: 2.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.score-divider {
  font-size: 1.5rem;
  color: var(--text-muted);
  font-weight: 600;
  align-self: center;
  margin-bottom: 0.1rem;
}
.score-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  margin-top: 0.4rem;
}
.score-toggle input { cursor: pointer; }

/* ゴール通知トースト */
.goal-toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-30px);
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  padding: 1.25rem 2rem;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(239, 68, 68, 0.4);
  font-weight: 800;
  text-align: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
.goal-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.goal-toast .goal-label {
  font-size: 1.5rem;
  letter-spacing: 0.1em;
  text-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.goal-toast .goal-team {
  font-size: 1.1rem;
  margin-top: 0.2rem;
}
.goal-toast .goal-scorer {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-top: 0.15rem;
}

/* もっと古いコメントを読むボタン */
.load-more-btn {
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  margin-bottom: 0.5rem;
  transition: all 0.15s;
}
.load-more-btn:hover { background: var(--surface-2); color: var(--text); }
.load-more-btn:disabled { opacity: 0.5; cursor: wait; }

/* コメント欄 */
.comments-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  height: 60vh;
  overflow-y: auto;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.comment {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity:0; transform: translateY(4px); } to { opacity:1; transform: none; } }
.comment-num {
  font-size: 0.72rem;
  color: var(--text-muted);
  min-width: 2.2rem;
  padding-top: 0.15rem;
  font-variant-numeric: tabular-nums;
}
.comment-body { flex: 1; min-width: 0; }
.comment-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}
.comment-meta .username {
  color: var(--primary);
  font-weight: 600;
  margin-right: 0.5rem;
}
.comment-text {
  font-size: 0.92rem;
  line-height: 1.5;
  word-break: break-word;
}

/* コメント投稿フォーム */
.comment-form {
  display: flex;
  gap: 0.5rem;
}
.comment-form input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.875rem;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.comment-form input:focus { border-color: var(--primary); }

/* ラグ設定バー */
.lag-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.lag-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.lag-presets {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  flex-wrap: wrap;
}
.lag-preset {
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.lag-preset:hover { background: var(--border); color: var(--text); }
.lag-preset.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
#lag-custom {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  color: var(--text);
  font-size: 0.8rem;
  outline: none;
  color-scheme: dark;
  width: 5.5rem;
}
#lag-custom:focus { border-color: var(--primary); }

.comment-sync {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 0.2rem;
  border-radius: 4px;
  margin-left: 0.25rem;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.comment-sync:hover {
  opacity: 1;
  color: var(--primary);
}

/* ステータス表示 */
.status-bar-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: stretch;
}
.status-bar {
  flex: 1;
  text-align: center;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--surface-2);
  color: var(--text-muted);
}
.status-bar.connected { color: var(--success); }
.status-bar.error { color: var(--danger); }

.presence-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.presence-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

/* フィルター */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 0.35rem 0.9rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn.active, .filter-btn:hover {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

/* ログインプロンプト */
.login-prompt {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* スクロールバー */
.comments-box::-webkit-scrollbar { width: 4px; }
.comments-box::-webkit-scrollbar-track { background: transparent; }
.comments-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* カウントダウン */
.countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.countdown-soon {
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.1);
}
.countdown-live {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
}

/* アイコンボタン */
.icon-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

/* モーダル */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2rem 1rem;
  z-index: 500;
  overflow-y: auto;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem 1.75rem;
  max-width: 540px;
  width: 100%;
  position: relative;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  margin: auto 0;
}
.modal h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
}
.modal h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 1.2rem 0 0.4rem;
  color: var(--primary);
}
.modal p, .modal ol, .modal ul {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text);
}
.modal .modal-lead {
  color: var(--text-muted);
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.modal ol, .modal ul { padding-left: 1.4rem; }
.modal ol li, .modal ul li { margin-bottom: 0.3rem; }
.modal .modal-foot {
  margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border);
  font-size: 0.82rem; color: var(--text-muted);
}
.modal-close {
  position: absolute;
  top: 0.6rem; right: 0.6rem;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--text); background: var(--border); }

/* フッター */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--primary); }
.site-footer .dot { margin: 0 0.5rem; opacity: 0.5; }

@media (max-width: 600px) {
  header { padding: 0 0.75rem; }
  .container { padding: 1rem 0.75rem; }
  .comments-box { height: 55vh; }
  .match-card { padding: 0.85rem 1rem; }
  .match-teams { font-size: 0.95rem; }
}
