/* 基礎樣式 */
body {
  width: 100vw;
  height: 100%;
  overflow-x: hidden;
  margin: 0;
  padding: 20px;
  font-family: Arial, sans-serif;
  background-color: #f4f4f4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

h2 {
  color: #333;
  font-size: 24px;
  margin-top: 10px;
  margin-bottom: 20px;
  text-align: center;
}

/* 主容器 - 左右分割 */
.main-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

/* 左側編輯區容器 */
.left-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 右側預覽區容器 */
.right-section {
  position: sticky;
  top: 20px;
}

/* 文字輸入區 */
.textarea-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
}

textarea {
  overflow-y: auto;
  width: 100%;
  height: 320px;
  font-size: 17px;
  line-height: 1.6;
  border: none;
  border-radius: 15px;
  padding: 15px;
  background-color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  resize: none;
  font-family: Arial, sans-serif;
  box-sizing: border-box;
}

textarea:focus {
  outline: none;
  box-shadow: 0 2px 10px rgba(0, 123, 255, 0.2);
}

#charCount {
  position: absolute;
  bottom: 10px;
  right: 15px;
  font-size: 14px;
  color: #666;
  font-family: Arial, sans-serif;
  font-style: italic;
}

#charCount.exceed {
  color: red;
  font-weight: bold;
}

/* 按鈕樣式 */
button {
  width: 100%;
  max-width: 100%;
  padding: 14px;
  font-size: 16px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  margin: 0;
  display: block;
  transition: all 0.3s;
}

.convert-btn {
  color: white;
  transition: background-color 0.3s;
}

.convert-btn.blue {
  background-color: #007bff;
}

.convert-btn.orange {
  background-color: #ff9800;
}

.convert-btn.after {
  background-color: #28a745;
}

button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

/* 統計分析區 */
.analysis-container {
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  padding: 20px;
  width: 100%;
  max-width: 100%;
  margin: 0;
  text-align: left;
}

.analysis-container h3 {
  font-size: 18px;
  margin-bottom: 15px;
  color: #444;
  border-bottom: 1px solid #ccc;
  padding-bottom: 6px;
}

.analysis-container div {
  margin-bottom: 10px;
  font-size: 15px;
  color: #222;
  font-family: Arial, sans-serif;
}

/* 圖片上傳區 */
.image-upload-container {
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  padding: 20px;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

.image-upload-container h3 {
  font-size: 18px;
  margin-bottom: 15px;
  color: #444;
  border-bottom: 1px solid #ccc;
  padding-bottom: 6px;
}

.upload-btn {
  width: 100%;
  padding: 12px;
  background-color: #6c757d;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.3s;
}

.upload-btn:hover {
  background-color: #5a6268;
  transform: translateY(-1px);
}

.upload-hint {
  font-size: 13px;
  color: #666;
  text-align: center;
  margin-top: 8px;
}

/* 圖片預覽網格 */
.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-top: 15px;
}

.image-preview-item {
  position: relative;
  width: 100%;
  padding-bottom: 100%;
  background: #f0f0f0;
  border-radius: 8px;
  overflow: hidden;
}

.image-preview-item img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-remove-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-remove-btn:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* 預覽區的圖片顯示 */
.preview-images {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  border-radius: 8px;
  overflow: hidden;
}

.preview-images.single {
  grid-template-columns: 1fr;
}

.preview-images.two {
  grid-template-columns: repeat(2, 1fr);
}

.preview-images.three {
  grid-template-columns: repeat(2, 1fr);
}

.preview-images.three .preview-image-item:first-child {
  grid-column: 1 / -1;
}

.preview-images.four {
  grid-template-columns: repeat(2, 1fr);
}

.preview-image-item {
  position: relative;
  width: 100%;
  padding-bottom: 100%;
  background: #f0f0f0;
  overflow: hidden;
}

.preview-image-item img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-image-more {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
}

/* Threads 預覽區 */
.preview-section {
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  padding: 20px;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

.preview-section h3 {
  font-size: 18px;
  margin-bottom: 20px;
  color: #444;
  text-align: center;
  border-bottom: 1px solid #ccc;
  padding-bottom: 10px;
}

/* 手機模擬器 */
.phone-mockup {
  background: #000;
  border-radius: 35px;
  padding: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 355px;
  margin: 0 auto;
}

.phone-screen {
  background: #fff;
  border-radius: 28px;
  overflow: hidden;
  height: 700px;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Threads 標題列 */
.threads-header {
  background: #fff;
  padding: 12px 15px;
  border-bottom: 1px solid #efefef;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.threads-logo {
  font-size: 20px;
  font-weight: 700;
  color: #000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.settings-icon {
  font-size: 20px;
}

/* Threads 貼文區 */
.threads-post {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px;
  background: #fff;
}

.post-header {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
  align-items: center;
  justify-content: flex-start;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  flex-shrink: 0;
  font-size: 15px;
}

.post-info {
  flex: 0 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
}

.username {
  font-weight: 600;
  font-size: 15px;
  color: #000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.2;
  white-space: nowrap;
  text-align: left;
}

.post-content {
  font-size: 15px;
  line-height: 1.4;
  color: #000;
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: normal;
  overflow-wrap: break-word;
  margin-top: 4px;
  font-family: Arial, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, sans-serif;
  text-align: left;
  padding-right: 4px;
  min-height: 20px;
  max-width: 100%;
}

/* 貼文互動按鈕 */
.post-actions {
  display: flex;
  gap: 15px;
  margin-top: 12px;
  padding-top: 8px;
}

.action-btn {
  font-size: 18px;
  color: #666;
  cursor: pointer;
  background: none;
  border: none;
  padding: 5px;
  width: auto;
  margin: 0;
}

.action-btn:hover {
  opacity: 0.7;
  transform: scale(1.1);
}

/* 提示訊息 */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #28a745;
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: all 0.3s;
  z-index: 1000;
  font-size: 14px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 滾動條樣式 */
.threads-post::-webkit-scrollbar {
  width: 5px;
}

.threads-post::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.threads-post::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.threads-post::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* 響應式設計 - 平板及手機 */
@media (max-width: 968px) {
  .main-container {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .right-section {
    position: static;
  }

  h2 {
    font-size: 20px;
  }
}

/* 響應式設計 - 手機 */
@media (max-width: 600px) {
  body {
    padding: 15px;
  }

  h2 {
    font-size: 18px;
  }

  textarea {
    height: 250px;
    font-size: 16px;
  }

  .phone-mockup {
    max-width: 100%;
    width: 335px;
  }

  .phone-screen {
    height: 600px;
  }

  button {
    font-size: 15px;
    padding: 12px;
  }
  
  .preview-section {
    padding: 15px;
  }

  .analysis-container {
    padding: 15px;
  }
}
