/* css/code-block.css */

/* 程式碼區塊容器 */
.code-block-wrapper {
  position: relative;
  margin: 1.5rem 0;
  animation: fadeInUp 0.6s ease forwards; /* 從 base.css 移來 */
  opacity: 0;
}

/* 程式碼區塊樣式 */
.code-block {
  background: #1e1e1e; /* 預設為深色模式的背景 */
  border: 1px solid #333; /* 預設為深色模式的邊框 */
  border-radius: 8px;
  padding: 0;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.85rem;
  overflow-x: auto;
  position: relative;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.code-block:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* 程式碼區塊頂部裝飾條 */
.code-block::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(180deg, #3c3c3c 0%, #2d2d2d 100%); /* 預設為深色模式的裝飾條 */
  border-bottom: 1px solid #444; /* 預設為深色模式的裝飾條邊框 */
  border-radius: 8px 8px 0 0;
}

/* 程式碼區塊頂部紅黃綠圓點 */
.code-block::after {
  content: '';
  position: absolute;
  top: 12px;
  left: 12px;
  width: 12px;
  height: 12px;
  background: #ff5f57;
  border-radius: 50%;
  box-shadow:
    20px 0 0 #ffbd2e,
    40px 0 0 #28ca42;
}

/* 終端機標題 */
.terminal-title {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  color: #d4d4d4; /* 預設為深色模式的文字顏色 */
  font-size: 0.75rem;
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
  opacity: 0.8;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* 程式碼內容樣式 */
.code-block code {
  display: block;
  white-space: pre;
  color: #d4d4d4; /* 預設為深色模式的程式碼顏色 */
  padding: 48px 16px 16px 16px;
  line-height: 1.5;
  background: transparent;
}

/* 複製按鈕樣式 */
.copy-button {
  position: absolute;
  top: 6px;
  right: 12px;
  background-color: rgba(100, 100, 100, 0.2); /* 預設為深色模式的背景 */
  color: #d4d4d4; /* 預設為深色模式的圖標/文字顏色 */
  border: 1px solid rgba(255, 255, 255, 0.1); /* 預設為深色模式的邊框 */
  border-radius: 4px;
  width: 50px;
  height: 24px;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 2;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.copy-button svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.copy-button:hover {
  background-color: rgba(255, 255, 255, 0.1); /* 深色模式 hover 背景 */
  color: #fff; /* 深色模式 hover 圖標/文字顏色 */
  border-color: rgba(255, 255, 255, 0.2); /* 深色模式 hover 邊框 */
}

.copy-button:active {
  transform: translateY(1px);
}

/* 淺色主題下的程式碼區塊樣式 */
[data-theme="light"] .code-block {
  background: var(--code-bg-light, #f7fafc); /* 使用 CSS 變數，並提供備用值 */
  border-color: var(--border-light, rgba(102, 126, 234, 0.2));
}

[data-theme="light"] .code-block::before {
  background: linear-gradient(180deg, #e1e4e8 0%, #d1d5da 100%);
  border-bottom-color: #d1d5da;
}

[data-theme="light"] .code-block code {
  color: var(--text-light, #2d3748);
}

[data-theme="light"] .terminal-title {
  color: var(--text-light, #2d3748);
}

[data-theme="light"] .copy-button {
  background-color: rgba(0, 0, 0, 0.1);
  color: var(--text-light, #2d3748);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .copy-button:hover {
  background-color: rgba(0, 0, 0, 0.15);
  border-color: rgba(0, 0, 0, 0.2);
}

/* 響應式調整 (從 base.css 移來，並針對 code-block 相關元素) */
@media (max-width: 768px) {
  .code-block {
    font-size: 0.8rem;
    padding: 0;
  }

  .code-block code {
    padding: 40px 12px 12px 12px;
  }

  .copy-button {
    top: 4px;
    right: 8px;
    width: 45px;
    height: 22px;
  }

  .copy-button svg {
    width: 10px;
    height: 10px;
  }
}

/* 淡入動畫 (已在 .code-block-wrapper 中定義) */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}