/* ベースレイアウト */
body {
  font-family: sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f5f7fa;
  color: #333;
}

header {
  background-color: #1e88e5;
  color: white;
  padding: 1rem;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-content > div {
  text-align: center;
  flex: 1;
}

.header-content h1 {
  margin: 0.5rem 0;
}

.header-content p {
  margin: 0.5rem 0;
}

main {
  padding: 2rem;
  max-width: 1200px;  /* ← 900px → 1200px に拡張 */
  margin: auto;
}

section {
  margin-bottom: 2rem;
}

label {
  font-weight: bold;
  margin-right: 0.5rem;
}

/* テキスト入力とモールス入力のラベルのスタイル */
label[for="textInput"], label[for="morseInput"] {
  display: inline-block;
  vertical-align: middle;
  align-self: flex-start;
  line-height: 1.5;
}

/* 入力欄とボタンの横並び配置 */
.input-with-button {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.input-with-button label {
  flex-shrink: 0;
  margin-top: 0.8rem;
}

.input-with-button textarea {
  flex: 1;
}

.input-with-button button {
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 0.4rem;
}

input[type="text"] {
  padding: 0.5rem;
  font-size: 1rem;
  width: 60%;
  max-width: 300px;
}

textarea#morseInput, textarea#inputText {
  width: 80%;
  max-width: 600px;
  font-size: 1.1rem;
  padding: 0.6rem;
  resize: vertical;
  min-height: 32px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-family: inherit;
  vertical-align: middle;
}

textarea#morseInput {
  font-family: monospace;
}

.input-hint {
  font-size: 0.85rem;
  color: #666;
  margin: 0.3rem 0 1rem 0;
  font-style: italic;
}

.morse-input-buttons {
  margin: 0.5rem 0;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.morse-char-btn {
  padding: 0.4rem 0.8rem;
  font-size: 1rem;
  background-color: #f5f5f5;
  color: #333;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
  font-family: monospace;
  min-width: 60px;
}

.morse-char-btn:hover {
  background-color: #e0e0e0;
  border-color: #999;
}

.morse-char-btn:active {
  background-color: #d0d0d0;
  transform: translateY(1px);
}

.morse-input-buttons .sample-button {
  margin-left: 1rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  background-color: #e8f5e8;
  color: #2e7d32;
  border: 1px solid #4caf50;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
  font-weight: 500;
  font-family: inherit;
}

.morse-input-buttons .sample-button:hover {
  background-color: #c8e6c9;
  border-color: #388e3c;
}

.morse-input-buttons .sample-button:active {
  background-color: #a5d6a7;
  transform: translateY(1px);
}

button {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  margin-left: 0.5rem;
  cursor: pointer;
  background-color: #42a5f5;
  color: white;
  border: none;
  border-radius: 4px;
}

button:hover {
  background-color: #1e88e5;
}

#tree-container {
  margin-top: 1rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 1rem;
  background-color: #fff;
  overflow-x: auto;
}

.tree-scroll-wrapper {
  overflow-x: auto;
  margin-top: 1rem;
}

/* footer */
footer {
  text-align: center;
  padding: 1rem;
  background-color: #e0e0e0;
  font-size: 0.9rem;
  margin-top: 2rem;
}

.footer a {
  color: #1e88e5;
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* タブUI */
.tab-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 2px solid #1e88e5;
}


.tab-button {
  padding: 0.8rem 1.5rem;
  background-color: #e0e0e0;
  border: 1px solid #ccc;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: bold;
  margin-right: 0.2rem;
  transition: background-color 0.2s;
}

.tab-button:hover {
  background-color: #f0f0f0;
}

.tab-button.active {
  background-color: #ffffff;
  color: #1e88e5;
  border-color: #1e88e5;
  border-bottom: 2px solid #ffffff;
  margin-bottom: -2px;
  z-index: 1;
  position: relative;
}

/* タブコンテンツ */
.tab-content {
  max-width: 1400px;
  margin: auto;
  display: none;
}

.tab-content.active {
  display: block;
  background-color: #ffffff;
  border: 2px solid #1e88e5;
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  min-height: 400px;
}


/* モーダル */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal[style*="display: block"] {
  display: flex !important;
}

.modal-content {
  background-color: #fff;
  padding: 0;
  border-radius: 8px;
  max-width: 800px;
  width: 95%;
  max-height: 90vh;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  position: relative;
  display: flex;
  flex-direction: column;
}

.modal-content h2 {
  background-color: #1e88e5;
  color: white;
  margin: 0;
  padding: 1.5rem 2rem;
  border-radius: 8px 8px 0 0;
  position: sticky;
  top: 0;
  z-index: 1;
}

.help-content {
  padding: 2rem;
  overflow-y: auto;
  flex: 1;
  line-height: 1.6;
}

.help-content h3 {
  color: #1e88e5;
  margin-top: 2rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e3f2fd;
}

.help-content h4 {
  color: #424242;
  margin-top: 1.5rem;
  margin-bottom: 0.8rem;
}

.help-content ul, .help-content ol {
  margin-left: 1.5rem;
  margin-bottom: 1rem;
}

.help-content li {
  margin-bottom: 0.5rem;
}

.help-content p {
  margin-bottom: 1rem;
}

.close-button {
  position: absolute;
  top: 1.5rem;
  right: 2rem;
  font-size: 1.8rem;
  font-weight: bold;
  color: white;
  cursor: pointer;
  z-index: 2;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.close-button:hover {
  opacity: 1;
}

.hidden {
  display: none;
}

.help-icon-button {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid white;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.help-icon-button:hover {
  background-color: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.help-icon-button:active {
  transform: scale(0.95);
}

/* Morse table layout */
.morse-table-wrapper {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 1.5rem;
  overflow-x: scroll;       /* 常に表示 */
  padding: 1rem 0;
  max-width: none;          /* 幅制限を解除 */
}

.tab-content#tab-table {
  overflow-x: visible;       /* wrapperの外で切れないように */
}

body {
  overflow-x: hidden;        /* 全体スクロールは防止（任意） */
}

.morse-table-group {
  flex: 0 0 280px;
  vertical-align: top;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 1rem;
  background-color: #fff;
}

.morse-table-group h3 {
  margin-top: 0;
  text-align: center;
  font-size: 1.1rem;
}

.morse-table {
  width: 100%;
  border-collapse: collapse;
}

.morse-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid #eee;
  text-align: center;
  white-space: nowrap; /* 改行禁止：記号の表示崩れ防止 */
}

@media screen and (max-width: 768px) {
  .morse-table-wrapper {
    flex-wrap: wrap;
  }
  .morse-table-group {
    flex: 1 1 100%;
  }
}

#studyResult {
  background-color: #ffffff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 1rem;
  margin-top: 1rem;
  font-size: 1rem;
  line-height: 1.6;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

#studyResult p {
  margin: 0.5rem 0;
}

.tree-node.highlight circle {
  fill: #ffecb3;
  stroke: #f57c00;
  stroke-width: 2;
}

#tree-container-study {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 1rem;
  background-color: #fff;
  overflow-x: auto;
}

#tree-container-study svg {
  display: block;
  margin: 0 auto;
}

.tree-node.highlight circle {
  fill: #ffecb3;
  stroke: #f57c00;
  stroke-width: 2;
}

line.highlight {
  stroke: #f57c00;
  stroke-width: 3;
}

/* エンコード結果表示 */
.morse-result-container {
  background-color: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 1.5rem;
  margin-top: 1rem;
}

.morse-code-display {
  font-size: 1.5rem;
  font-family: monospace;
  background-color: #fff;
  border: 2px solid #1e88e5;
  border-radius: 4px;
  padding: 1rem;
  margin: 1rem 0;
  text-align: center;
  letter-spacing: 0.3rem;
  color: #1e88e5;
  font-weight: bold;
  position: relative;
}

.copy-button {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  background-color: #42a5f5;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
  font-weight: normal;
  letter-spacing: normal;
}

.copy-button:hover {
  background-color: #1e88e5;
}

.copy-button:active {
  background-color: #1565c0;
  transform: translateY(1px);
}

.morse-encode-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.morse-encode-table th,
.morse-encode-table td {
  padding: 0.5rem;
  border: 1px solid #ddd;
  text-align: center;
}

.morse-encode-table th {
  background-color: #e3f2fd;
  font-weight: bold;
}

.morse-encode-table td {
  font-family: monospace;
  font-size: 1.1rem;
}

details {
  margin-top: 1rem;
}

summary {
  cursor: pointer;
  padding: 0.5rem;
  background-color: #e3f2fd;
  border-radius: 4px;
  font-weight: bold;
  user-select: none;
}

summary:hover {
  background-color: #bbdefb;
}

/* エラーメッセージ */
#encodeError, #decodeError {
  margin-top: 0.5rem;
}

.error-message {
  color: #d32f2f;
  background-color: #ffebee;
  border: 1px solid #ef5350;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  margin: 0;
  font-size: 0.9rem;
}

/* デコード結果表示 */
.decode-result-container {
  background-color: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 1.5rem;
  margin-top: 1rem;
}

.decoded-text-display {
  font-size: 1.8rem;
  font-family: serif;
  background-color: #fff;
  border: 2px solid #2e7d32;
  border-radius: 4px;
  padding: 1rem;
  margin: 1rem 0;
  text-align: center;
  letter-spacing: 0.1rem;
  color: #2e7d32;
  font-weight: bold;
}

.morse-decode-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.morse-decode-table th,
.morse-decode-table td {
  padding: 0.5rem;
  border: 1px solid #ddd;
  text-align: center;
}

.morse-decode-table th {
  background-color: #e8f5e8;
  font-weight: bold;
}

.morse-decode-table td:first-child {
  font-family: monospace;
  font-size: 1.1rem;
}

#tree-container-decode {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 1rem;
  background-color: #fff;
  overflow-x: auto;
}

/* トースト通知 */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: #4caf50;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 10000;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
  font-size: 0.9rem;
  font-weight: 500;
  max-width: 300px;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

@media (max-width: 768px) {
  .toast {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
    text-align: center;
  }
}

/* === 学習モード用サブタブ UI === */
.subtab-buttons {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 1px solid #007acc;
}

.subtab-button {
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  font-weight: bold;
  color: #444;
  transition: background-color 0.2s;
  margin-right: 0.2rem;
}

.subtab-button:hover {
  background-color: #e0e0e0;
}

.subtab-button.active {
  background-color: #ffffff;
  color: #007acc;
  border-color: #007acc;
  border-bottom: 1px solid #ffffff;
  margin-bottom: -1px;
  z-index: 1;
  position: relative;
}

.subtab-content {
  display: none;
  background-color: #ffffff;
  border: 1px solid #007acc;
  border-top: none;
  border-radius: 0 0 6px 6px;
  padding: 1.5rem;
  margin-top: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.subtab-content.active {
  display: block;
}
