/* ベーススタイル */
body {
  font-family:
    "Inter", "Segoe UI", "BIZ UDPGothic", "メイリオ", Meiryo, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f0f2f5; /* 明るいグレーの背景 */
  background-image: url("sumo_background.png");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: #333;
  line-height: 1.6;
}

/* スクレイパー警告バナー */
.scraper-warning {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #ff6b6b, #ee5a5a);
  color: white;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  animation: warningPulse 2s infinite;
}

.scraper-warning .warning-icon {
  font-size: 1.3em;
}

.scraper-warning .warning-text {
  font-size: 1em;
}

.scraper-warning .cooldown-timer {
  font-size: 0.9em;
  opacity: 0.9;
}

@keyframes warningPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.85;
  }
}

/* 全体コンテナ */
.container {
  max-width: 1200px;
  margin: 30px auto;
  padding: 30px;
  background-color: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1 {
  color: #2c3e50;
  text-align: center;
  margin-bottom: 30px;
  font-size: 2.2em;
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* コントロール部分 */
.controls {
  text-align: center;
  margin-bottom: 30px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 15px;
}

.controls label {
  font-weight: 600;
  color: #555;
  font-size: 1.05em;
}

.controls select {
  padding: 10px 15px;
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  font-size: 1em;
  min-width: 220px;
  background-color: #fdfefe;
  appearance: none; /* デフォルトの矢印を非表示に */
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23666666%22%20d%3D%22M287%2C146.2L146.2%2C287l-140.8-140.8L0%2C146.2l146.2%2C146.2L292.4%2C146.2L287%2C146.2z%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.controls select:focus {
  border-color: #4a90e2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
  outline: none;
}

.controls button {
  padding: 10px 25px;
  background-color: #4a90e2; /* 青系のアクセントカラー */
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.05em;
  font-weight: 600;
  transition:
    background-color 0.3s ease,
    transform 0.2s ease;
  box-shadow: 0 4px 10px rgba(74, 144, 226, 0.2);
}

.controls button:hover {
  background-color: #357bd8;
  transform: translateY(-2px);
}

.controls button:disabled {
  background-color: #b0c4de;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* 力士検索 */
.search-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input-wrapper {
  position: relative;
}

.search-input-wrapper input {
  padding: 10px 15px;
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  font-size: 1em;
  min-width: 180px;
  background-color: #fdfefe;
  transition: all 0.3s ease;
}

.search-input-wrapper input:focus {
  border-color: #4a90e2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
  outline: none;
}

.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  background-color: #fff;
  border: 1px solid #dcdfe6;
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  max-height: 250px;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
  display: none;
}

.search-suggestions.active {
  display: block;
}

.search-suggestions li {
  padding: 10px 15px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  border-bottom: 1px solid #f0f0f0;
}

.search-suggestions li:last-child {
  border-bottom: none;
}

.search-suggestions li:hover,
.search-suggestions li.selected {
  background-color: #e8f4fd;
}

.search-suggestions .rikishi-name {
  font-weight: 600;
  color: #333;
}

.search-suggestions .stable-name {
  font-size: 0.85em;
  color: #666;
  margin-left: 8px;
}

.search-suggestions .no-results {
  padding: 10px 15px;
  color: #888;
  font-style: italic;
}

.status-message {
  text-align: center;
  font-weight: 600;
  padding: 8px 15px;
  border-radius: 6px;
  display: inline-block;
}
.status-message.success {
  color: #28a745;
  background-color: #e6ffe6;
  border: 1px solid #28a745;
}
.status-message.error {
  color: #dc3545;
  background-color: #ffe6e6;
  border: 1px solid #dc3545;
}

/* テーブルコンテナ */
#table-container {
  overflow-x: auto; /* 横スクロールを可能にする */
  margin-top: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

/* テーブル */
table {
  width: 100%;
  border-collapse: separate; /* border-spacingを可能にするため */
  border-spacing: 0; /* 罫線の隙間をなくす */
  background-color: transparent;
  min-width: 600px; /* テーブルが小さくなりすぎないように */
}

th,
td {
  padding: 12px 8px;
  border-bottom: 1px solid #e0e6ed; /* 控えめな罫線 */
  text-align: center;
  vertical-align: middle;
  white-space: nowrap; /* テキストが改行されないように */
  box-sizing: border-box; /* widthにpaddingを含める */
}

th {
  background-color: rgba(248, 250, 255, 0.85); /* ヘッダーの背景色 */
  color: #444;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 10;
  border-top: 1px solid #e0e6ed; /* 上部の罫線 */
}

th:first-child,
td:first-child {
  text-align: center;
  padding: 4px;
}

/* 固定列 - 推し列（1列目） */
td:first-child,
th:first-child {
  position: sticky;
  left: 0;
  background-color: rgba(253, 254, 254, 0.85);
  z-index: 12;
  min-width: 36px;
  width: 36px;
  max-width: 36px;
}

/* 力士名列（2列目） */
td:nth-child(2),
th:nth-child(2) {
  position: sticky;
  left: 36px;
  background-color: rgba(253, 254, 254, 0.85);
  z-index: 11;
  min-width: 55px;
  width: 55px;
  max-width: 55px;
  text-align: left;
  padding-left: 8px;
  white-space: normal;
  word-break: break-all;
}

/* 番付列（3列目） */
td:nth-child(3),
th:nth-child(3) {
  position: sticky;
  left: 86px;
  background-color: rgba(253, 254, 254, 0.85);
  z-index: 12;
  min-width: 40px;
  width: 40px;
  max-width: 40px;
}

/* 勝敗列（4列目） */
td:nth-child(4),
th:nth-child(4) {
  position: sticky;
  left: 126px;
  background-color: rgba(253, 254, 254, 0.85);
  z-index: 10;
  box-shadow: 3px 0 6px rgba(0, 0, 0, 0.08);
  border-right: 1px solid #e0e6ed;
  min-width: 40px;
  width: 40px;
  max-width: 40px;
}

/* 日付列（5列目以降）の固定幅 - デフォルトは未確定（対戦相手あり）用 */
td:nth-child(n + 5),
th:nth-child(n + 5) {
  min-width: 50px;
  width: 50px;
  max-width: 50px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 日付列（確定済み：すべて勝敗が決まっている）用の狭い幅 */
.day-column-decided {
  min-width: 30px !important;
  width: 30px !important;
  max-width: 30px !important;
}

/* 固定列のヘッダーが重なる部分の調整 */
th:first-child {
  z-index: 14;
}
th:nth-child(2) {
  z-index: 13;
}
th:nth-child(3) {
  z-index: 12;
}
th:nth-child(4) {
  z-index: 12;
}

/* テーブルボディの最後の行の下線はなし */
tbody tr:last-child td {
  border-bottom: none;
}

/* ===================== */
/* 推しボタンのスタイル */
/* ===================== */

.th-oshi {
  font-size: 0.75em;
  color: #888;
}

.td-oshi {
  padding: 2px 4px !important;
}

.favorite-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2em;
  color: #ccc;
  transition: all 0.2s ease;
  padding: 4px 6px;
  border-radius: 4px;
}

.favorite-btn:hover {
  color: #ffc107;
  background-color: rgba(255, 193, 7, 0.1);
  transform: scale(1.15);
}

.favorite-btn.active {
  color: #ffc107;
  text-shadow: 0 0 3px rgba(255, 193, 7, 0.5);
}

.favorite-btn.active:hover {
  color: #e0a800;
}

/* 推し部屋オプションのスタイル */
.oshi-heya-option {
  font-weight: bold;
  color: #ffc107;
  background-color: #fff8e1;
}

/* 勝敗結果の背景色 */
.result-win {
  background-color: #e8fcf0; /* 薄い緑 */
  color: #2c3e50;
  font-weight: bold;
}
.result-loss {
  background-color: #fcf0f0; /* 薄い赤 */
  color: #2c3e50;
  font-weight: bold;
}
.result-pending {
  background-color: #fff8e6; /* 薄いオレンジ */
  color: #856404;
}
.result-none {
  background-color: #e0e0e0; /* グレー */
  color: #888;
}

/* 勝敗数のスタイル */
.win-loss-record {
  font-size: 0.85em;
  color: #333;
  font-weight: bold;
}

/* 勝敗数の背景色クラス */
.record-winning {
  background-color: #e8fcf0; /* 勝越しと同じ */
}
.record-losing {
  background-color: #fcf0f0; /* 負け越しと同じ */
}
.record-tied {
  background-color: #f0f2f5; /* 背景色に合わせる */
}

/* 勝ち越し・負け越しの背景色（力士名セル用） */
.rikishi-kachikoshi {
  background-color: #d4edda !important; /* 落ち着いた深緑 */
  border-left: 4px solid #28a745 !important;
}
.rikishi-makekoshi {
  background-color: #f8d7da !important; /* 落ち着いた深紅 */
  border-left: 4px solid #dc3545 !important;
}

/* 番付ツールチップのスタイル */
.rank-tooltip {
  cursor: default;
  border-bottom: 1px dotted #aeb0b7; /* ドット線 */
  display: inline-block;
}

.rank-tooltip:hover {
  border-bottom-color: #4a90e2;
}

/* 勝敗セルのツールチップ */
.result-tooltip {
  cursor: default;
  display: inline-block;
  width: 100%;
}

.result-tooltip:hover {
  opacity: 0.8;
}

/* ローディング/エラーメッセージ */
.loading,
.error {
  text-align: center;
  padding: 30px;
  font-size: 1.1em;
  font-weight: 500;
  color: #777;
  animation: pulse 1.5s infinite alternate; /* ローディングアニメーション */
}

.error {
  color: #c0392b;
  animation: shake 0.5s;
}

@keyframes pulse {
  from {
    opacity: 0.7;
  }
  to {
    opacity: 1;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(-5px);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translateX(5px);
  }
}

/* 最終スクレイプ時刻表示 */
.scrape-timestamp {
  text-align: right;
  font-size: 0.75em;
  color: #999;
  padding: 0 4px 4px;
}

/* ===== スマートフォン向けのスタイル (最大幅768px) ===== */
@media (max-width: 768px) {
  body {
    font-size: 0.9em; /* スマートフォンでの全体的なフォントサイズ調整 */
  }

  .container {
    margin: 10px;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05); /* シャドウを少し抑える */
  }

  h1 {
    font-size: 1.6em; /* タイトルを小さく */
    margin-bottom: 20px;
  }

  .controls {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
  }

  .controls label {
    font-size: 0.85em;
    white-space: nowrap;
  }

  /* 力士検索は1行目に表示 */
  .search-container {
    width: 100%;
    justify-content: center;
  }

  .search-container input {
    flex: 1;
    min-width: 120px;
  }

  /* 部屋選択行をコンパクトに */
  .controls select {
    flex: 1;
    min-width: 100px;
    max-width: 180px;
    font-size: 0.85em;
    padding: 8px 10px;
  }

  .controls button {
    min-width: unset;
    font-size: 0.85em;
    padding: 8px 12px;
    white-space: nowrap;
  }

  .status-message {
    font-size: 0.75em;
    padding: 4px 8px;
    white-space: nowrap;
  }

  /* テーブルのスタイル調整 */
  #table-container {
    border-radius: 6px;
  }

  table {
    min-width: unset; /* スマートフォンでは最小幅の制約をなくす */
    width: 100%; /* 親コンテナの幅に合わせる */
  }

  th,
  td {
    padding: 8px 5px; /* パディングを小さく */
    font-size: 0.8em; /* フォントサイズを小さく */
    white-space: normal; /* セル内で改行を許可 */
    word-break: break-word; /* 単語の途中で改行 */
    box-sizing: border-box; /* widthにpaddingを含める */
  }

  /* 固定列の調整 - 推し列（1列目） */
  td:first-child,
  th:first-child {
    position: sticky !important;
    left: 0 !important;
    min-width: 30px !important;
    width: 30px !important;
    max-width: 30px !important;
    padding: 2px !important;
    background-color: #fdfefe;
    z-index: 15;
  }

  /* 力士名列（2列目） */
  td:nth-child(2),
  th:nth-child(2) {
    position: sticky !important;
    min-width: 50px !important;
    width: 50px !important;
    max-width: 50px !important;
    left: 30px !important;
    padding-left: 4px !important;
    background-color: #fdfefe;
    z-index: 14;
  }

  /* 番付列（3列目） */
  td:nth-child(3),
  th:nth-child(3) {
    position: sticky !important;
    min-width: 40px !important;
    width: 40px !important;
    max-width: 40px !important;
    left: 80px !important;
    background-color: #fdfefe;
    z-index: 13;
  }

  /* 勝敗列（4列目） */
  td:nth-child(4),
  th:nth-child(4) {
    position: sticky !important;
    min-width: 30px !important;
    width: 30px !important;
    max-width: 30px !important;
    left: 120px !important;
    background-color: #fdfefe;
    z-index: 12;
    box-shadow: 3px 0 6px rgba(0, 0, 0, 0.08);
    border-right: 1px solid #e0e6ed;
  }

  /* 推しボタンを小さく */
  .favorite-btn {
    font-size: 1em;
    padding: 2px 4px;
  }

  /* ローディング/エラーメッセージ */
  .loading,
  .error {
    padding: 20px;
    font-size: 1em;
  }
}

/* さらに小さな画面（例：iPhone SEなどの古いモデル）向けの調整 */
@media (max-width: 480px) {
  .container {
    margin: 5px;
    padding: 10px;
  }
  h1 {
    font-size: 1.4em;
  }
  th,
  td {
    padding: 6px 3px;
    font-size: 0.75em;
  }

  /* 推し列（1列目） */
  td:first-child,
  th:first-child {
    min-width: 26px;
    width: 26px;
    max-width: 26px;
    left: 0;
  }

  /* 力士名列（2列目） */
  td:nth-child(2),
  th:nth-child(2) {
    left: 26px;
    min-width: 45px;
    width: 45px;
    max-width: 45px;
  }

  /* 番付列（3列目） */
  td:nth-child(3),
  th:nth-child(3) {
    left: 71px;
    min-width: 35px;
    width: 35px;
    max-width: 35px;
  }

  /* 勝敗列（4列目） */
  td:nth-child(4),
  th:nth-child(4) {
    left: 106px;
    min-width: 35px;
    width: 35px;
    max-width: 35px;
    box-shadow: 3px 0 6px rgba(0, 0, 0, 0.08);
    border-right: 1px solid #e0e6ed;
  }

  .status-message {
    font-size: 0.85em;
    padding: 5px 8px;
  }

  .favorite-btn {
    font-size: 0.9em;
    padding: 1px 2px;
  }
}
