:root {
  --primary-color: #2563eb;
  --secondary-color: #1e40af;
  --background-color: #f3f4f6;
  --text-color: #1f2937;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding: 20px;
  background-color: var(--background-color);
  color: var(--text-color);
}

/* containerのパディングを調整 */
.container {
  max-width: 950px;
  margin: 0 auto;
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

h1 {
  text-align: center;
  color: var(--primary-color);
  margin-bottom: 30px;
}

.controls {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  align-items: center;
  justify-content: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
}

.letters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.letter-btn {
  padding: 8px;
  border: 2px solid var(--primary-color);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 1.2em;
  transition: all 0.3s ease;
}

.letter-btn.selected {
  background: var(--primary-color);
  color: white;
}

.letter-btn.playing {
  background: var(--secondary-color);
  color: white;
  animation: pulse 1s infinite;
}

input[type="number"] {
  width: 60px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

input[type="range"] {
  width: 150px;
}

select {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: white;
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 10px;
}

.char-tab {
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  color: #6b7280;
  border-bottom: 2px solid transparent;
  transition: all 0.3s ease;
}

.char-tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.controls {
  margin-bottom: 30px;
}

/* 数字用のセクション用スタイル追加 */
.section-divider {
  border-top: 1px solid #e5e7eb;
  margin: 20px 0;
  padding-top: 20px;
}

.section-label {
  color: var(--text-color);
  font-weight: bold;
  margin-bottom: 10px;
}

/* 共通のボタンスタイル */
.morse-btn,
.morse-label {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 45px;
  padding: 0 15px;
  border: 2px solid var(--primary-color);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 1.2em;
  transition: all 0.3s ease;
  box-sizing: border-box;
  width: 120px; /* 固定幅を設定 */
  margin: 0;
}

.morse-btn:hover {
  background: var(--primary-color);
  color: white;
}

.morse-btn:disabled {
  border-color: #ccc;
  color: #ccc;
  cursor: not-allowed;
  background: white;
}

/* トグルボタンのコンテナ */
.morse-toggle {
  display: flex;
  height: 45px;
  margin: 0;
  width: 120px; /* morse-btnと同じ幅に設定 */
}

.morse-toggle input {
  display: none;
}

/* 選択状態 */
.morse-toggle input:checked + .morse-label {
  background: var(--primary-color);
  color: white;
}

/* ボタンコントロール全体のコンテナ */
.button-controls {
  margin: 20px 0;
  display: flex;
  justify-content: center;
  width: 100%;
}

/* ボタングループのベーススタイル */
.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: stretch;
  max-width: 800px; /* コンテナの最大幅を設定 */
  margin: 0 auto;
}

.morse-toggle.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* 無効化された.morse-toggleの中の要素のスタイル */
.morse-toggle.disabled input[type="checkbox"],
.morse-toggle.disabled .morse-label {
  cursor: not-allowed;
}

.footer {
  text-align: center;
  margin-top: 30px;
  padding: 20px;
  color: #666;
  border-top: 1px solid #eee;
}

.footer-content {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.footer-info {
  text-align: left;
}

.footer-info p {
  margin: 5px 0;
}

.footer-links {
  display: flex;
  gap: 15px;
  align-items: center;
}

.footer-links a {
  color: #3498db;
  text-decoration: none;
  font-size: 0.9em;
}

.footer-links a:hover {
  text-decoration: underline;
  color: #2980b9;
}

.footer-divider {
  color: #ccc;
}

/* ヘッダー部分のスタイル */
.header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 30px;
}

.header h1 {
  margin: 0; /* h1のデフォルトマージンを削除 */
  text-align: center;
  grid-column: 2;
}

.manual-link {
  grid-column: 3;
  text-align: right;
}

/* マニュアルリンクのスタイル */
.manual-link a {
  display: inline-block;
  padding: 8px 16px;
  background-color: #3498db;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.9em;
}

.manual-link a:hover {
  background-color: #2980b9;
}

.affiliate-links-container {
  width: 100%;
  display: flex;
  justify-content: center;
  border-top: 1px solid #eee;
  padding-top:20px;
}

.affiliate-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, 292px);
  column-gap: 20px;
  row-gap: 0px;
  justify-content: center;
  width: 100%;
}

#reset-btn {
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}

#reset-btn.touch-active {
  background-color: var(--primary-color);
  color: white;
}

.speed-control-container.disabled {
  opacity: 0.6;
  pointer-events: none;
}

/* レスポンシブ対応 */
@media (max-width: 599px) {
  body {
    padding: 0px;
  }

  .container {
    padding: 20px; /* スマホでのパディングを減らす */
  }

  .header {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .header h1 {
    grid-column: 1;
    font-size: 1.6em;
  }

  .manual-link {
    grid-column: 1;
    text-align: center;
  }

  .footer-content {
    flex-direction: column;
    text-align: center;
  }

  .footer-info {
    text-align: center;
  }

  .footer-links {
    justify-content: center;
  }

  .controls {
    flex-direction: column;
    align-items: center;
  }

  .control-group {
    justify-content: space-between;
  }

  .button-group {
    flex-direction: column;
    align-items: center;
  }

  .morse-btn,
  .morse-label,
  .morse-toggle {
    width: 200px; /* より小さい画面では大きめのボタン */
  }

  .affiliate-links {
    grid-template-columns: 300px;
    row-gap: 0px;
  }

  .affiliate-links > table {
    margin: 0 auto; /* テーブルを中央寄せ */
    width: 280px;  /* 幅を固定 */
  }
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
  .button-group {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .morse-btn,
  .morse-label,
  .morse-toggle {
    width: 120px; /* モバイルでも固定幅を維持 */
  }

  /* トグルボタンのコンテナ */
  .morse-toggle {
    flex: 0 0 auto; /* 追加: フレックスアイテムのサイズを固定 */
  }
}
