html {
  font-size: 100%;
}

body {
  font-family: 'Noto Serif JP', serif;
  font-size: 1rem;
  margin: 0 auto;
  max-width: 1200px;
  background: #fff;
  line-height: 1.8;
}

/* デスクトップ以上 */
header, footer {
  background: #f0f0f0;
  padding: 1em;
  text-align: center;
}

/* ヘッダーのリンク（装飾なし） */
header a {
  color: inherit;
  text-decoration: none;
}

header a:hover {
  opacity: 0.8;
}

nav {
  background: #333;
  padding: 0.5em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5em;
}

nav a {
  color: #fff;
  text-decoration: none;
}

.nav-left, .nav-center, .nav-right {
  display: flex;
  align-items: center;
}

.nav-left {
  flex: 0 0 auto;
  gap: 0.5em;
}

.nav-center {
  flex: 1;
  max-width: 300px;
}

.nav-right {
  flex: 0 0 auto;
}

nav a {
  color: #fff;
  margin: 0 1em;
  text-decoration: none;
}

.nav-left, .nav-center, .nav-right {
  display: flex;
  align-items: center;
}

.nav-left {
  flex: 1;
}

.nav-center {
  flex: 0 1 400px;
}

.nav-right {
  flex: 1;
  justify-content: flex-end;
}

#container {
  display: flex;
}

#sidebar {
  width: 200px;
  background: #f9f9f9;
  padding: 1em;
  border-right: 1px solid #ccc;
  font-size: 0.95rem;
}

/* サイドバーのコメント時刻表示 */
#sidebar .comment-time {
    display: block;
    color: #999;
    font-size: 0.85em;
    margin-top: 0.2rem;
}

#sidebar h3 {
    margin-top: 1.5rem;
}

#sidebar h3:first-child {
    margin-top: 0;
}

#content {
  flex: 1;
  padding: 2em;
}

/* コンテンツ内の画像を適切に表示 */
#content img {
  max-width: 100%;
  height: auto;
}

textarea {
  width: 100%;
  height: 300px;
  font-family: monospace;
}

input[type="text"] {
  padding: 0.5em;
  font-size: 1em;
}

.login-form {
  max-width: 400px;
  margin: 2em auto;
  padding: 2em;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.login-form input {
  width: 100%;
  padding: 0.5em;
  margin: 0.5em 0;
}

.login-form button {
  width: 100%;
  padding: 0.7em;
  background: #333;
  color: #fff;
  border: none;
  cursor: pointer;
}

.error {
  color: red;
  padding: 0.5em;
  background: #ffe6e6;
  border-radius: 3px;
}

.user-info {
  color: #fff;
  font-size: 0.9em;
}

.button-group {
  display: flex;
  gap: 1em;
  margin-top: 1em;
}

.button-group button {
  padding: 0.7em 1.5em;
  cursor: pointer;
}

.btn-save {
  background: #333;
  color: #fff;
  border: none;
}

.btn-delete {
  background: #dc3545;
  color: #fff;
  border: none;
}

.btn-delete:hover {
  background: #c82333;
}

.tags {
  margin: 1em 0;
}

.tag {
  display: inline-block;
  background: #e0e0e0;
  padding: 0.3em 0.7em;
  margin: 0.2em;
  border-radius: 3px;
  text-decoration: none;
  color: #333;
  font-size: 0.9em;
}

.tag:hover {
  background: #d0d0d0;
}

.tag-input-hint {
  color: #666;
  font-size: 0.9em;
  margin-top: 0.3em;
}

.search-results {
  margin: 1em 0;
}

.search-results li {
  margin: 0.5em 0;
}

#sidebar h3 {
  margin-top: 1.5em;
  font-size: 1em;
}

#sidebar h3:first-child {
  margin-top: 0;
}

#sidebar ul {
  padding-left: 1.2em;
}

h3 {
  border-top: solid 3px #e0e0e0;
}

#wiki-main-logo {
  width: 2em;
}

/* 検索フォーム */
.search-form {
  display: flex;
  width: 100%;
  gap: 0.5em;
}

.search-input {
  flex: 1;
  padding: 0.5em;
  border: none;
  border-radius: 3px;
  font-size: 0.9em;
}

.search-button {
  padding: 0.5em 1em;
  background: #555;
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.9em;
  white-space: nowrap;
}

.search-button:hover {
  background: #666;
}

/* 検索トグルボタン（デフォルトは非表示） */
.search-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.3em;
}

/* 検索閉じるボタン（デフォルトは非表示） */
.search-close {
  display: none;
  background: #000;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  padding: 0.5em 0.8em;
  border-radius: 3px;
  min-width: 44px;
  height: 44px;
  line-height: 1;
}

.search-close:hover {
  background: #c82333;
}

.search-close:active {
  background: #bd2130;
}

/* 検索結果 */
.search-result-item {
  margin: 1.5em 0;
  padding: 1em;
  border-left: 3px solid #333;
  background: #f9f9f9;
}

.search-result-item h3 {
  margin: 0 0 0.5em 0;
  border: none;
}

.search-result-item h3 a {
  color: #0066cc;
  text-decoration: none;
}

.search-result-item h3 a:hover {
  text-decoration: underline;
}

.search-snippet {
  margin: 0.5em 0;
  line-height: 1.6;
  color: #333;
}

.search-snippet mark {
  background: #ffff00;
  padding: 0 0.2em;
  font-weight: bold;
}

.search-meta {
  color: #666;
  font-size: 0.85em;
}

.material-symbols-outlined {
  line-height: 1;
  vertical-align: middle;
}

/* コメント機能のスタイル */
.comments-section {
    margin-top: 2rem;
    padding-top: 1rem;
    /*border-top: 2px solid #e0e0e0;*/
}

.comments-section h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.comments-list {
    margin-bottom: 2rem;
}

.comment-item {
    background-color: #f9f9f9;
    border-left: 3px solid #4CAF50;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.comment-header strong {
    color: #2c3e50;
}

.comment-header small {
    color: #7f8c8d;
}

.btn-delete-comment {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 0.5rem;
    margin-left: auto;
}

.btn-delete-comment:hover {
    color: #c0392b;
}

.comment-body {
    color: #34495e;
    line-height: 1.6;
}

.comment-form {
    background-color: #f5f5f5;
    padding: 1.5rem;
    border-radius: 4px;
    margin-top: 1.5rem;
}

.comment-form h4 {
    margin-top: 0;
    margin-bottom: 1rem;
}

.comment-form input[type="text"],
.comment-form textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
}

.comment-form textarea {
    resize: vertical;
    font-family: inherit;
}

.btn-comment {
    background-color: #4CAF50;
    color: white;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

.btn-comment:hover {
    background-color: #45a049;
}

/* エラーメッセージ */
.error-messages {
    background-color: #fee;
    border: 1px solid #fcc;
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.error-messages .error {
    color: #c00;
    margin: 0.5rem 0;
}

.error-messages .error:first-child {
    margin-top: 0;
}

.error-messages .error:last-child {
    margin-bottom: 0;
}

/* スマホ対応 - 最後に配置して優先度を確保 */
@media (max-width: 768px) {
  /* Firefoxでの横スクロール問題を解決 */
  html, body {
    overflow-x: hidden;
    width: 100%;
  }
  
  body {
    max-width: 100%;
    margin: 0;
    font-size: 1.125rem;
    line-height: 1.9;
  }
  
  /* ナビゲーションをコンパクトに */
  nav {
    padding: 0.4em;
    gap: 0.3em;
  }
  
  nav a {
    font-size: 1.3rem;
    padding: 0.3em;
    white-space: nowrap;
  }
  
  .nav-left {
    gap: 0.5em;
  }
  
  .nav-center {
    flex: 1;
    max-width: none;
  }
  
  /* スマホでは検索トグルボタンを表示 */
  .search-toggle {
    display: block;
  }
  
  /* デフォルトで検索フォームを非表示 */
  .search-form {
    display: none;
    width: 100%;
  }
  
  /* 検索フォームがアクティブな時 */
  .search-form.active {
    display: flex;
    align-items: center;
    gap: 0.5em;
  }
  
  .search-form.active .search-input {
    flex: 1;
    font-size: 1rem;
    padding: 0.6em;
    box-sizing: border-box;
  }
  
  .search-form.active .search-close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  
  /* 検索ボタンは常に非表示 */
  .search-button {
    display: none;
  }
  
  /* コンテンツ内の画像を画面に収める */
  #content img {
    max-width: 100%;
    height: auto;
    display: block;
  }
  
  /* コンテナを縦並びに - これが重要！ */
  #container {
    flex-direction: column !important;
    width: 100%;
  }
  
  /* サイドバーを下に配置し、幅を100%に */
  #sidebar {
    width: 100% !important;
    order: 2;
    border-right: none;
    border-top: 2px solid #ccc;
    padding: 1.5em;
    box-sizing: border-box;
  }
  
  /* メインコンテンツ */
  #content {
    order: 1;
    padding: 1.5em;
    font-size: 1.125rem;
    width: 100%;
    box-sizing: border-box;
  }
  
  /* 見出しのサイズ調整 */
  #content h2 {
    font-size: 1.5rem;
    margin: 0.8em 0;
  }
  
  #content h3 {
    font-size: 1.25rem;
  }
  
  /* ナビゲーションを1段に - 横スクロール可能に */
  nav {
    flex-direction: row;
    gap: 0;
    padding: 0.5em;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  nav a {
    padding: 0.5em;
    display: inline-block;
    font-size: 0.85rem;
    white-space: nowrap;
  }
  
  .nav-left, .nav-center, .nav-right {
    flex-shrink: 0;
    gap: 0.2em;
  }
  
  .nav-left {
    flex: 0 0 auto;
  }
  
  .nav-center {
    flex: 0 0 auto;
    max-width: 180px;
    min-width: 150px;
  }
  
  .nav-right {
    flex: 0 0 auto;
    margin-left: auto;
  }
  
  .user-info {
    font-size: 0.8em;
  }
  
  /* 検索フォームをコンパクトに */
  .search-form {
    gap: 0.2em;
  }
  
  .search-input {
    font-size: 0.85rem;
    padding: 0.5em;
  }
  
  .search-button {
    font-size: 0.85rem;
    padding: 0.5em 0.7em;
  }
  
  /* サイドバーのリンクもタップしやすく */
  #sidebar a {
    display: block;
    padding: 0.6em 0.3em;
    line-height: 1.6;
  }
  
  #sidebar ul {
    padding-left: 0.5em;
  }
  
  #sidebar li {
    margin: 0.5em 0;
  }
  
  /* タグを大きく */
  .tag {
    font-size: 1rem;
    padding: 0.5em 1em;
    margin: 0.3em;
  }
  
  /* テキストエリアとボタン */
  textarea {
    font-size: 1rem;
    padding: 0.5em;
    box-sizing: border-box;
  }
  
  input[type="text"] {
    font-size: 1rem;
    padding: 0.7em;
    box-sizing: border-box;
  }
  
  button, .button-group button {
    font-size: 1rem;
    padding: 0.8em 1.5em;
    min-height: 44px;
  }
  
  /* ヘッダー・フッター */
  header, footer {
    padding: 1.2em;
    font-size: 1rem;
  }
  
  header h1 {
    font-size: 1.3rem;
  }
  
  #wiki-main-logo {
    width: 1.5em;
  }
  
  /* ログインフォーム */
  .login-form {
    margin: 1em;
    padding: 1.5em;
  }
  
  /* 検索結果 */
  .search-result-item {
    padding: 1em;
    margin: 1em 0;
  }
  .youtube-embed {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 のアスペクト比 */
    height: 0;
    overflow: hidden;
  }

  .youtube-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
  }
  .comment-item {
    padding: 0.75rem;
  }

  .comment-form {
    padding: 1rem;
  }
}