body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #f3f4f6;
  color: #1f2937;
  margin: 0;
  padding: 2rem;
  display: flex;
  justify-content: center;
}

.game-container {
  max-width: 1000px;
  width: 100%;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
  box-sizing: border-box; /* paddingを含めて幅を計算 */
}

h1 {
  text-align: center;
  color: #111827;
}

.alert {
  background-color: #fee2e2;
  color: #991b1b;
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  text-align: center;
}

.success {
  background-color: #d1fae5;
  color: #065f46;
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 2rem;
  text-align: center;
}

/* --- フォーム周りの修正（スマホでも綺麗に並ぶようにflexを調整） --- */
.guess-form {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 2rem;
  gap: 0.5rem;
  flex-wrap: wrap; /* スマホで幅が足りない時は折り返す */
}

/* Railsのform_withが生成する<form>タグ自体を横並びに */
.guess-form form {
  display: flex;
  flex: 1;
  min-width: 250px;
}

/* 独立したReveal Answerボタン（button_to）の形を整える */
.guess-form form.button_to {
  flex: 0 1 auto;
}
.guess-form form.button_to .btn {
  border-radius: 4px; /* 単独のボタンなので角を丸める */
  width: 100%;
}

.input-field {
  padding: 0.75rem;
  font-size: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px 0 0 8px;
  flex: 1; /* width: 300pxを廃止し、余白を埋めるように変更 */
  min-width: 0; /* flexbox内で縮めるようにする */
  outline: none;
  transition: all 0.3s ease;
}

.input-field:focus {
  border-color: #8b5cf6;
  background: #ffffff;
  box-shadow: 
    -4px 0px 10px rgba(59, 130, 246, 0.4), 
    4px 0px 10px rgba(139, 92, 246, 0.4);
}

.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: bold;
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  color: white;
  border: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap; /* ボタンの文字を折り返さない */
}

.success .btn, .action-buttons .btn {
  border-radius: 8px;
  margin-top: 10px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px -2px rgba(59, 130, 246, 0.4);
}

.hint-btn {
  background-color: #34495e;
  border: 1px solid #2c3e50;
  padding: 10px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.2s;
  width: 100%;
  box-sizing: border-box;
}

.hint-btn:hover {
  color: white;
  background-color: #1f2937;
  transform: translateY(-2px);
}

.hint-btn.revealed {
  background-color: #f1c40f;
  color: #333;
  cursor: default;
  transform: none;
}

/* --- グリッド（表）周りの修正 --- */
.guesses-container {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.guesses-header, .guess-row {
  display: grid;
  /* 画面幅に合わせて伸縮しつつ、中の文字数で幅が変わらないように minmax(0, fr) を使う */
  grid-template-columns: minmax(0, 1fr) repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
}

.header-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  text-align: center;
  padding: 0.5rem;
  background-color: #e5e7eb;
  border-radius: 4px;
  font-size: 0.875rem;
  min-height: 25px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.guess-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0.5rem;
  border-radius: 4px;
  font-weight: bold;
  text-align: center;
  font-size: 0.875rem;
  word-break: break-all;
  overflow-wrap: anywhere;
  min-width: 0;
  min-height: 25px;
}

.guess-cell.match {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}

.guess-cell.mismatch {
  background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
  color: white;
}

/* ツールチップ */
.tooltip-container {
  position: relative;
}
.tooltip-container::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: #fff;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, bottom 0.2s;
  pointer-events: none;
}
.tooltip-container:hover::after {
  opacity: 1;
  visibility: visible;
  bottom: 120%;
}
.tooltip-container:disabled:hover::after {
  display: none;
}


/* =========================================
   スマホ用レスポンシブ設定 (画面幅 768px 以下)
   【カード型折りたたみレイアウト版】
========================================= */
@media (max-width: 768px) {
  body {
    padding: 0.5rem;
  }

  .game-container {
    padding: 1rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .guess-form form {
    min-width: 100%;
  }

  #reveal-btn {
    width: 100%;
  }

  /* --- ここからが折りたたみの魔法 --- */
  
  /* 横スクロールを廃止し、3列のグリッドに変更 */
  .guesses-header, .guess-row {
    grid-template-columns: repeat(3, minmax(0, 1fr)); /* スマホでは3列にする（文字数での伸縮防止） */
    gap: 4px; /* 隙間を少し狭く */
  }

  /* 行と行の区切りを分かりやすくする */
  .guess-row {
    margin-top: 1rem;
    border-top: 3px solid #d1d5db; /* 各予想の上に太めの線を引く */
    padding-top: 1rem;
  }



  /* スマホ画面に合わせて文字サイズや余白を小さく調整 */
  .header-cell, .guess-cell {
    font-size: 0.75rem; /* 小さめの文字にして画面に収める */
    padding: 0.5rem 0.2rem;
  }
}

/* =========================================
   Menu / Difficulty Selection Screen
========================================= */

.menu-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 3rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.menu-header {
  text-align: center;
  margin-bottom: 3rem;
}

.glow-text {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 2rem;
  margin-bottom: 2rem;
  animation: pulse-glow 3s infinite alternate;
}

.back-btn {
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  color: #6b7280;
  text-decoration: none;
  font-weight: bold;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.back-btn:hover {
  color: #3b82f6;
}

@keyframes pulse-glow {
  from { text-shadow: 0 0 10px rgba(59, 130, 246, 0.2); }
  to { text-shadow: 0 0 20px rgba(139, 92, 246, 0.5); }
}

.subtitle {
  color: #6b7280;
  font-size: 1.2rem;
  margin: 0;
}

.difficulty-grid {
  width: 100%;
}

.difficulty-form {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  width: 100%;
}

.diff-card {
  display: flex;
  align-items: center;
  padding: 1.2rem 2rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: left;
  position: relative;
  overflow: hidden;
  width: 100%;
}

.diff-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.1);
}

.diff-icon {
  font-size: 2.5rem;
  margin-right: 1.5rem;
}

.diff-content h3 {
  margin: 0 0 0.2rem 0;
  font-size: 1.4rem;
  color: #1f2937;
  font-weight: 700;
}

.diff-content p {
  margin: 0;
  color: #6b7280;
  font-size: 0.95rem;
}

/* Card Specific Styling */
.diff-card.easy { border-left: 5px solid #10b981; }
.diff-card.easy:hover { background: linear-gradient(90deg, rgba(16,185,129,0.1) 0%, rgba(255,255,255,0.8) 100%); }

.diff-card.normal { border-left: 5px solid #3b82f6; }
.diff-card.normal:hover { background: linear-gradient(90deg, rgba(59,130,246,0.1) 0%, rgba(255,255,255,0.8) 100%); }

.diff-card.hard { border-left: 5px solid #f59e0b; }
.diff-card.hard:hover { background: linear-gradient(90deg, rgba(245,158,11,0.1) 0%, rgba(255,255,255,0.8) 100%); }

.diff-card.very-hard { border-left: 5px solid #ef4444; }
.diff-card.very-hard:hover { background: linear-gradient(90deg, rgba(239,68,68,0.1) 0%, rgba(255,255,255,0.8) 100%); }

.diff-card.extreme { border-left: 5px solid #8b5cf6; }
.diff-card.extreme:hover { background: linear-gradient(90deg, rgba(139,92,246,0.1) 0%, rgba(255,255,255,0.8) 100%); }
/* Autocomplete Custom UI */
.autocomplete-container {
  position: relative;
  flex: 1;
  display: flex;
}

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

.autocomplete-items li {
  padding: 12px 15px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  color: #333;
  font-size: 1rem;
}

.autocomplete-items li:last-child {
  border-bottom: none;
}

.autocomplete-items li:hover {
  background-color: #f3f4f6;
}
