/* オレンジテーマ（デフォルト） - より落ち着いた色合いに調整 */
:root {
  --background: linear-gradient(135deg, #f8e5ca 0%, #f5bea3 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --text-color: #333;
  --accent-color: #e67e22;
  --accent-light: #f39c12;
  --accent-ultra-light: rgba(243, 156, 18, 0.1);
  --border-color: rgba(243, 156, 18, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.1);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(255, 255, 255, 0.97);
  --input-border: #e0e0e0;
  --input-bg: #ffffff;
  --stats-highlight: rgba(255, 255, 255, 0.7);
  --scrollbar-track: rgba(255, 255, 255, 0.5);
  --scrollbar-thumb: #f39c12;
  --stats-bg: rgba(243, 156, 18, 0.08);
  --footer-bg: #2c3e50;
  --footer-text: #ecf0f1;
}

/* オレンジテーマ（ダークモード） */
body.dark-theme {
  --background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  --card-bg: rgba(30, 39, 46, 0.95);
  --text-color: #f5f6fa;
  --accent-color: #f39c12;
  --accent-light: #e67e22;
  --accent-ultra-light: rgba(230, 126, 34, 0.1);
  --border-color: rgba(230, 126, 34, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.25);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(30, 39, 46, 0.97);
  --input-border: #576574;
  --input-bg: #1e2734;
  --stats-highlight: rgba(30, 39, 46, 0.7);
  --scrollbar-track: rgba(30, 39, 46, 0.5);
  --scrollbar-thumb: #e67e22;
  --stats-bg: rgba(230, 126, 34, 0.1);
  --footer-bg: #1a2530;
  --footer-text: #ecf0f1;
}

/* ブルーテーマ */
body.blue-theme {
  --background: linear-gradient(135deg, #e0f7fa 0%, #b3e5fc 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --text-color: #2d3436;
  --accent-color: #2980b9;
  --accent-light: #3498db;
  --accent-ultra-light: rgba(52, 152, 219, 0.1);
  --border-color: rgba(52, 152, 219, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.1);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(255, 255, 255, 0.97);
  --input-border: #e0e0e0;
  --input-bg: #ffffff;
  --stats-highlight: rgba(255, 255, 255, 0.7);
  --scrollbar-track: rgba(255, 255, 255, 0.5);
  --scrollbar-thumb: #3498db;
  --stats-bg: rgba(52, 152, 219, 0.08);
  --footer-bg: #2c3e50;
  --footer-text: #ecf0f1;
}

/* ブルーテーマ（ダークモード） */
body.blue-theme.dark-theme {
  --background: linear-gradient(135deg, #0f2027 0%, #203a43 100%);
  --card-bg: rgba(30, 39, 46, 0.95);
  --text-color: #f5f6fa;
  --accent-color: #3498db;
  --accent-light: #2980b9;
  --accent-ultra-light: rgba(41, 128, 185, 0.1);
  --border-color: rgba(41, 128, 185, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.25);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(30, 39, 46, 0.97);
  --input-border: #576574;
  --input-bg: #1e2734;
  --stats-highlight: rgba(30, 39, 46, 0.7);
  --scrollbar-track: rgba(30, 39, 46, 0.5);
  --scrollbar-thumb: #2980b9;
  --stats-bg: rgba(41, 128, 185, 0.1);
  --footer-bg: #1a2530;
  --footer-text: #ecf0f1;
}

/* グリーンテーマ */
body.green-theme {
  --background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --text-color: #2d3436;
  --accent-color: #27ae60;
  --accent-light: #2ecc71;
  --accent-ultra-light: rgba(46, 204, 113, 0.1);
  --border-color: rgba(46, 204, 113, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.1);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(255, 255, 255, 0.97);
  --input-border: #e0e0e0;
  --input-bg: #ffffff;
  --stats-highlight: rgba(255, 255, 255, 0.7);
  --scrollbar-track: rgba(255, 255, 255, 0.5);
  --scrollbar-thumb: #2ecc71;
  --stats-bg: rgba(46, 204, 113, 0.08);
  --footer-bg: #2c3e50;
  --footer-text: #ecf0f1;
}

/* グリーンテーマ（ダークモード） */
body.green-theme.dark-theme {
  --background: linear-gradient(135deg, #134e5e 0%, #1a6c56 100%);
  --card-bg: rgba(30, 39, 46, 0.95);
  --text-color: #f5f6fa;
  --accent-color: #2ecc71;
  --accent-light: #27ae60;
  --accent-ultra-light: rgba(39, 174, 96, 0.1);
  --border-color: rgba(39, 174, 96, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.25);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(30, 39, 46, 0.97);
  --input-border: #576574;
  --input-bg: #1e2734;
  --stats-highlight: rgba(30, 39, 46, 0.7);
  --scrollbar-track: rgba(30, 39, 46, 0.5);
  --scrollbar-thumb: #27ae60;
  --stats-bg: rgba(39, 174, 96, 0.1);
  --footer-bg: #1a2530;
  --footer-text: #ecf0f1;
}

/* パープルテーマ */
body.purple-theme {
  --background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --text-color: #2d3436;
  --accent-color: #8e44ad;
  --accent-light: #9b59b6;
  --accent-ultra-light: rgba(155, 89, 182, 0.1);
  --border-color: rgba(155, 89, 182, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.1);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(255, 255, 255, 0.97);
  --input-border: #e0e0e0;
  --input-bg: #ffffff;
  --stats-highlight: rgba(255, 255, 255, 0.7);
  --scrollbar-track: rgba(255, 255, 255, 0.5);
  --scrollbar-thumb: #9b59b6;
  --stats-bg: rgba(155, 89, 182, 0.08);
  --footer-bg: #2c3e50;
  --footer-text: #ecf0f1;
}

/* パープルテーマ（ダークモード） */
body.purple-theme.dark-theme {
  --background: linear-gradient(135deg, #17132a 0%, #302b63 100%);
  --card-bg: rgba(30, 39, 46, 0.95);
  --text-color: #f5f6fa;
  --accent-color: #9b59b6;
  --accent-light: #8e44ad;
  --accent-ultra-light: rgba(142, 68, 173, 0.1);
  --border-color: rgba(142, 68, 173, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.25);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(30, 39, 46, 0.97);
  --input-border: #576574;
  --input-bg: #1e2734;
  --stats-highlight: rgba(30, 39, 46, 0.7);
  --scrollbar-track: rgba(30, 39, 46, 0.5);
  --scrollbar-thumb: #8e44ad;
  --stats-bg: rgba(142, 68, 173, 0.1);
  --footer-bg: #1a2530;
  --footer-text: #ecf0f1;
}

/* レッドテーマ */
body.red-theme {
  --background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --text-color: #2d3436;
  --accent-color: #c0392b;
  --accent-light: #e74c3c;
  --accent-ultra-light: rgba(231, 76, 60, 0.1);
  --border-color: rgba(231, 76, 60, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.1);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(255, 255, 255, 0.97);
  --input-border: #e0e0e0;
  --input-bg: #ffffff;
  --stats-highlight: rgba(255, 255, 255, 0.7);
  --scrollbar-track: rgba(255, 255, 255, 0.5);
  --scrollbar-thumb: #e74c3c;
  --stats-bg: rgba(231, 76, 60, 0.08);
  --footer-bg: #2c3e50;
  --footer-text: #ecf0f1;
}

/* レッドテーマ（ダークモード） */
body.red-theme.dark-theme {
  --background: linear-gradient(135deg, #3d0000 0%, #5a0000 100%);
  --card-bg: rgba(30, 39, 46, 0.95);
  --text-color: #f5f6fa;
  --accent-color: #e74c3c;
  --accent-light: #c0392b;
  --accent-ultra-light: rgba(192, 57, 43, 0.1);
  --border-color: rgba(192, 57, 43, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.25);
  --delete-color: #e74c3c;
  --delete-hover: #c0392b;
  --header-bg: rgba(30, 39, 46, 0.97);
  --input-border: #576574;
  --input-bg: #1e2734;
  --stats-highlight: rgba(30, 39, 46, 0.7);
  --scrollbar-track: rgba(30, 39, 46, 0.5);
  --scrollbar-thumb: #c0392b;
  --stats-bg: rgba(192, 57, 43, 0.1);
  --footer-bg: #1a2530;
  --footer-text: #ecf0f1;
}

/* 基本的なスタイル */
body {
  font-family: 'Noto Sans JP', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--background);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  padding-top: 0;
  overflow-x: hidden;
  width: 100%;
  color: var(--text-color);
  transition: background 0.3s ease, color 0.3s ease;
}

/* ヘッダー部分の改善 */
header {
  width: 100%;
  background-color: var(--header-bg);
  box-shadow: 0 4px 20px var(--shadow-color);
  margin-bottom: 30px;
  text-align: center;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border-color);
}

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

.logo-area {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

header h1 {
  color: var(--accent-color);
  margin: 0;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: color 0.3s ease;
  display: flex;
  align-items: center;
}

header h1 i {
  margin-right: 10px;
  font-size: 1.6rem;
}

.tagline {
  margin: 5px 0 0;
  color: var(--text-color);
  opacity: 0.7;
  font-size: 0.9rem;
  font-weight: 300;
}

.controls-container {
  background-color: var(--header-bg);
  padding: 10px 20px 15px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 15px;
  flex-wrap: wrap;
  padding: 0 15px;
  max-width: 800px;
  width: 100%;
}

button {
  background-color: var(--accent-light);
  color: white;
  border: none;
  border-radius: 5px;
  padding: 10px 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 5px var(--shadow-color);
}

button:hover {
  background-color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--shadow-color);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px var(--shadow-color);
}

button i {
  margin-right: 6px;
}

.btn-primary {
  background-color: var(--accent-color);
  padding: 10px 18px;
  font-weight: 600;
}

.btn-primary:hover {
  background-color: var(--accent-light);
}

/* テーマコントロール */
.theme-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.language-toggle {
  background-color: var(--accent-light);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 5px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 5px var(--shadow-color);
}

.language-toggle:hover {
  background-color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--shadow-color);
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--accent-light);
}

.theme-toggle i {
  margin: 0;
}

/* テーマセレクタースタイル */
.theme-selector {
  position: relative;
}

.theme-menu-btn {
  background-color: var(--accent-light);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 5px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 5px var(--shadow-color);
}

.theme-menu-btn:hover {
  background-color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--shadow-color);
}

.dropdown-arrow {
  font-size: 0.7rem;
  margin-left: 3px;
  transition: transform 0.3s ease;
}

.theme-menu {
  position: absolute;
  top: 100%;
  right: 0;
  width: 160px;
  background-color: var(--card-bg);
  box-shadow: 0 5px 15px var(--shadow-color);
  border-radius: 5px;
  margin-top: 5px;
  overflow: hidden;
  display: none;
  z-index: 1000;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

.theme-menu.active {
  display: block;
  animation: fadeInMenu 0.3s ease forwards;
}

.theme-option {
  padding: 10px 15px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-color);
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-option:hover {
  background-color: var(--accent-ultra-light);
  color: var(--accent-color);
}

.theme-option.active {
  background-color: var(--accent-ultra-light);
  color: var(--accent-color);
  font-weight: bold;
}

@keyframes fadeInMenu {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.utility-btn {
  background-color: var(--card-bg);
  color: var(--accent-color);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  font-size: 0.9rem;
}

.utility-btn:hover {
  background-color: var(--accent-ultra-light);
}

/* 総合計の統計情報 */
.total-stats {
  background-color: var(--card-bg);
  margin: 0 auto;
  padding: 12px 25px;
  border-radius: 5px;
  display: flex;
  justify-content: center;
  gap: 40px;
  box-shadow: 0 2px 8px var(--shadow-color);
  max-width: 500px;
  width: 100%;
  border: 1px solid var(--border-color);
}

.total-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-color);
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 5px;
}

.total-count {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent-color);
  background-color: var(--stats-highlight);
  padding: 2px 10px;
  border-radius: 5px;
  min-width: 50px;
  text-align: center;
}

/* テキストエリアのコンテナ */
.container {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 25px;
  width: max-content;
  padding: 25px;
  overflow-x: auto;
  max-width: 92vw;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-light) transparent;
}

/* テキストエリアのスタイル */
.text-area {
  background-color: var(--card-bg);
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--shadow-color);
  min-width: 320px;
  max-width: none;
  display: flex;
  flex-direction: column;
  width: auto;
  transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
  border: 1px solid var(--border-color);
  position: relative;
}

.text-area:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px var(--shadow-color);
}

.text-area-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  width: 100%;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
  transition: border-color 0.3s ease;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-buttons {
  display: flex;
  gap: 8px;
}

.text-area-header h3 {
  margin: 0;
  color: var(--accent-color);
  font-size: 1.2rem;
  font-weight: 600;
  transition: color 0.3s ease;
}

.drag-handle {
  width: 20px;
  height: 20px;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity 0.3s ease;
  color: var(--text-color);
}

.drag-handle:hover {
  opacity: 1;
}

.drag-handle:active {
  cursor: grabbing;
}

/* ボタンスタイル */
.search-btn,
.copy-btn {
  background-color: var(--accent-ultra-light);
  color: var(--accent-color);
  width: 32px;
  height: 32px;
  border-radius: 4px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-btn i,
.copy-btn i {
  margin: 0;
  font-size: 0.9rem;
}

.remove-btn {
  background-color: var(--delete-color);
  width: 32px;
  height: 32px;
  border-radius: 4px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}

.remove-btn i {
  margin: 0;
  font-size: 0.9rem;
}

.remove-btn:hover {
  background-color: var(--delete-hover);
  opacity: 1;
}

/* 検索と置換コンテナ */
.search-replace-container {
  background-color: var(--stats-bg);
  border-radius: 5px;
  padding: 15px;
  margin-bottom: 15px;
  display: none;
  position: relative;
  border: 1px solid var(--border-color);
  animation: fadeInSearch 0.3s ease;
}

@keyframes fadeInSearch {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.search-replace-container.active {
  display: block;
}

.search-box, .replace-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.replace-box {
  margin-bottom: 0;
}

.search-input, .replace-input {
  flex-grow: 1;
  padding: 8px 12px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  font-size: 0.9rem;
  background-color: var(--input-bg);
  color: var(--text-color);
  transition: border-color 0.3s ease;
}

.search-input:focus, .replace-input:focus {
  border-color: var(--accent-color);
  outline: none;
}

.replace-buttons {
  display: flex;
  gap: 5px;
}

.find-btn, .replace-btn, .replace-all-btn {
  padding: 6px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.close-search-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background-color: var(--delete-color);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
}

.close-search-btn i {
  margin: 0;
  font-size: 0.7rem;
}

/* テキストエリア */
textarea {
  width: 100%;
  resize: both;
  border: 1px solid var(--input-border);
  border-radius: 5px;
  padding: 12px;
  font-size: 16px;
  outline: none;
  min-height: 160px;
  min-width: 280px;
  max-width: none;
  margin-bottom: 15px;
  box-sizing: border-box;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
  font-family: 'Noto Sans JP', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.5;
  background-color: var(--input-bg);
  color: var(--text-color);
}

textarea:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 8px var(--border-color);
}

/* 統計情報のスタイル改善 */
.text-stats {
  width: 100%;
  box-sizing: border-box;
  background-color: var(--stats-bg);
  border-radius: 5px;
  padding: 15px;
  margin-top: 5px;
  transition: background-color 0.3s ease;
  border: 1px solid var(--border-color);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px;
  transition: background-color 0.3s ease;
}

.stat-icon {
  color: var(--accent-color);
  font-size: 0.9rem;
  width: 16px;
  text-align: center;
}

.stat-label {
  flex-grow: 1;
  text-align: left;
  font-size: 0.85rem;
  white-space: nowrap;
}

.stat-value {
  font-weight: 600;
  color: var(--accent-color);
  background-color: var(--stats-highlight);
  padding: 2px 8px;
  border-radius: 4px;
  min-width: 30px;
  text-align: center;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.unit {
  margin-left: 2px;
  color: var(--text-color);
  opacity: 0.8;
  font-size: 0.8rem;
}

/* フッター */
footer {
  margin-top: auto;
  width: 100%;
  background-color: var(--footer-bg);
  color: var(--footer-text);
  padding: 30px 0;
}

.creator-info {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.creator-profile {
  display: flex;
  align-items: center;
  gap: 20px;
  background-color: rgba(255, 255, 255, 0.1);
  padding: 20px 30px;
  border-radius: 8px;
  max-width: 500px;
  width: 100%;
}

.profile-image {
  font-size: 3rem;
  color: var(--accent-light);
}

.profile-details {
  flex-grow: 1;
}

.profile-details h3 {
  margin: 0 0 5px;
  font-size: 1.3rem;
  color: white;
}

.company, .title {
  margin: 0;
  opacity: 0.8;
  font-size: 0.9rem;
}

.profile-link {
  display: inline-block;
  margin-top: 10px;
  color: var(--accent-light);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.3s ease;
}

.profile-link:hover {
  color: white;
}

.copyright {
  font-size: 0.8rem;
  opacity: 0.7;
  text-align: center;
  margin-top: 10px;
}

/* アニメーション効果 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.text-area.new {
  animation: fadeIn 0.5s ease forwards;
}

.text-area.removing {
  animation: fadeOut 0.3s ease forwards;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
  .header-top {
    flex-direction: column;
    padding: 10px 15px;
    gap: 10px;
  }

  .logo-area {
    align-items: center;
    text-align: center;
  }

  .container {
    padding: 15px;
    gap: 20px;
  }

  .text-area {
    min-width: 280px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .text-stats {
    grid-template-columns: 1fr;
  }

  .total-stats {
    flex-direction: column;
    gap: 5px;
    padding: 10px 15px;
  }

  .controls {
    gap: 8px;
  }

  button {
    padding: 8px 12px;
    font-size: 0.85rem;
  }

  .creator-profile {
    flex-direction: column;
    text-align: center;
    padding: 15px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 10px;
  }

  .text-area {
    padding: 15px;
  }

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

  button {
    width: 100%;
    max-width: 250px;
    justify-content: center;
  }

  .theme-controls {
    width: 100%;
    justify-content: center;
    margin-top: 10px;
  }
}

/* スクロールバーのスタイル */
.container::-webkit-scrollbar {
  height: 8px;
}

.container::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 5px;
}

.container::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 5px;
}

/* テキストエリアのリサイズハンドルを調整 */
textarea::-webkit-resizer {
  border-width: 8px;
  border-style: solid;
  border-color: transparent var(--accent-light) var(--accent-light) transparent;
  background-color: transparent;
}

/* ドラッグプレビューのスタイルを追加 */
.drag-clone {
  position: fixed;
  z-index: 1001;
  border: 2px dashed var(--accent-color);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.drop-target {
  border: 2px dashed var(--accent-light);
}

/* ドラッグ＆ドロップの初期化 */
function initDragAndDrop() {
  const container = document.getElementById('textAreasContainer');
  const textAreas = container.querySelectorAll('.text-area');

  textAreas.forEach(textArea => {
    const handle = textArea.querySelector('.drag-handle');

    handle.addEventListener('mousedown', function(e) {
      e.preventDefault();

      // ドラッグ用のクラスを追加
      textArea.classList.add('dragging');

      // ドラッグプレビューのクローンを作成
      const clone = textArea.cloneNode(true);
      clone.classList.add('drag-clone');
      clone.style.opacity = '0.6';
      clone.style.pointerEvents = 'none';
      document.body.appendChild(clone);

      // マウス座標の初期位置
      const startX = e.clientX;
      const startY = e.clientY;
      const startLeft = textArea.offsetLeft;
      const startTop = textArea.offsetTop;
      const initialScroll = container.scrollLeft;

      // ドラッグ中の処理
      function onMouseMove(e) {
        const dx = e.clientX - startX;

        // クローンの位置を更新
        clone.style.position = 'fixed';
        clone.style.zIndex = 1000;
        clone.style.left = `${e.clientX - 100}px`;
        clone.style.top = `${e.clientY - 30}px`;
        clone.style.width = `${textArea.offsetWidth}px`;

        // 元のテキストエリアを半透明に
        textArea.style.opacity = '0.4';

        // ドロップターゲットの検出
        const target = getDropTarget(e.clientX, textArea);

        // ドロップ可能領域の表示
        clearDropTargets();
        if (target) {
          target.classList.add('drop-target');

          // スクロール制御（端に来たらスクロール）
          const containerRect = container.getBoundingClientRect();
          if (e.clientX > containerRect.right - 100) {
            container.scrollLeft += 10;
          } else if (e.clientX < containerRect.left + 100) {
            container.scrollLeft -= 10;
          }
        }
      }

      // マウスアップ時の処理
      function onMouseUp(e) {
        document.removeEventListener('mousemove', onMouseMove);
        document.removeEventListener('mouseup', onMouseUp);

        // クローンを削除
        if (document.body.contains(clone)) {
          document.body.removeChild(clone);
        }

        textArea.classList.remove('dragging');
        textArea.style.opacity = '';

        // ドロップ先の処理
        const target = getDropTarget(e.clientX, textArea);
        if (target) {
          // アニメーション付きでドロップ
          const targetRect = target.getBoundingClientRect();
          const currentRect = textArea.getBoundingClientRect();

          textArea.style.transition = 'transform 0.3s ease';

          // ドロップ先の前に挿入
          container.insertBefore(textArea, target);
          renumberTextAreas();

          // アニメーション終了後にスタイルをリセット
          setTimeout(() => {
            textArea.style.transition = '';
          }, 300);
        }

        clearDropTargets();
      }

      document.addEventListener('mousemove', onMouseMove);
      document.addEventListener('mouseup', onMouseUp);
    });
  });
}

// ドロップターゲットを取得する関数（仮実装）
function getDropTarget(clientX, textArea) {
  const container = document.getElementById('textAreasContainer');
  const textAreas = container.querySelectorAll('.text-area');

  for (let i = 0; i < textAreas.length; i++) {
    const target = textAreas[i];
    const rect = target.getBoundingClientRect();

    if (target !== textArea && clientX > rect.left && clientX < rect.right) {
      return target;
    }
  }
  return null;
}

// ドロップターゲットのクラスをクリアする関数
function clearDropTargets() {
  const container = document.getElementById('textAreasContainer');
  const textAreas = container.querySelectorAll('.text-area');
  textAreas.forEach(textArea => textArea.classList.remove('drop-target'));
}

// テキストエリアの番号を振り直す関数（仮実装）
function renumberTextAreas() {
  const container = document.getElementById('textAreasContainer');
  const textAreas = container.querySelectorAll('.text-area');
  textAreas.forEach((textArea, index) => {
    textArea.querySelector('h3').textContent = `テキストエリア ${index + 1}`;
  });
}

// 初期化処理
window.addEventListener('load', () => {
  initDragAndDrop();
});