/* ============================================================
   LLM Translator — 樣式表
   設計風格：深色毛玻璃 (Dark Glassmorphism)
   RWD 斷點：768px（行動裝置堆疊佈局）
   ============================================================ */

/* ---------- CSS 變數（設計系統） ---------- */
:root {
  /* 主色調 */
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: rgba(30, 30, 55, 0.65);
  --bg-card-hover: rgba(40, 40, 70, 0.75);

  /* 強調色 — 漸層 */
  --accent-start: #6c63ff;
  --accent-end: #3b82f6;
  --accent-gradient: linear-gradient(135deg, var(--accent-start), var(--accent-end));

  /* 文字色 */
  --text-primary: #eaeaf5;
  --text-secondary: #9a9ab5;
  --text-placeholder: #5a5a7a;

  /* 邊框 */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(108, 99, 255, 0.35);

  /* 圓角 */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  /* 陰影 */
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.45);
  --shadow-btn: 0 4px 14px rgba(108, 99, 255, 0.35);

  /* 過渡 */
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;

  /* 字型 */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---------- Reset & Global ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  /* 微妙的背景漸層 */
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(108, 99, 255, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(59, 130, 246, 0.06) 0%, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 頂部導覽列 ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(15, 15, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon {
  font-size: 28px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
}

.model-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color var(--transition-fast);
  outline: none;
  min-height: 44px;
}

.model-select:focus {
  border-color: var(--accent-start);
}

.model-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ---------- 主翻譯區域 ---------- */
.translator-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

.translator-container {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
  max-width: 1100px;
}

/* ---------- 面板共用 ---------- */
.panel {
  flex: 1;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

.panel:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
}

.panel-source {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.panel-target {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lang-select {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  outline: none;
  min-height: 44px;
}

.lang-select:focus {
  border-color: var(--accent-start);
  background: rgba(108, 99, 255, 0.08);
}

.lang-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.char-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* ---------- 文字輸入區 ---------- */
.panel-body {
  flex: 1;
  position: relative;
}

.text-area {
  width: 100%;
  min-height: 200px;
  background: transparent;
  color: var(--text-primary);
  border: none;
  outline: none;
  font-family: var(--font-family);
  font-size: 1rem;
  line-height: 1.65;
  resize: vertical;
  padding: 4px 0;
}

.text-area::placeholder {
  color: var(--text-placeholder);
}

/* 清除按鈕 */
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.clear-btn {
  position: absolute;
  top: 0;
  right: 0;
}

.copy-btn .material-symbols-rounded {
  font-size: 20px;
}

/* ---------- 翻譯按鈕 ---------- */
.panel-footer {
  display: flex;
  justify-content: flex-end;
}

.translate-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
  min-height: 48px;
}

.translate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(108, 99, 255, 0.5);
}

.translate-btn:active:not(:disabled) {
  transform: translateY(0);
}

.translate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-icon {
  font-size: 20px;
}

/* 載入中旋轉動畫 */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- 交換按鈕 ---------- */
.swap-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 0 4px;
}

.swap-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}

.swap-btn:hover {
  background: var(--accent-gradient);
  border-color: transparent;
  transform: rotate(180deg);
}

.swap-btn .material-symbols-rounded {
  font-size: 26px;
  transition: transform var(--transition-fast);
}

/* ---------- 錯誤提示 ---------- */
.error-toast {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 20px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  color: #f87171;
  font-size: 0.9rem;
  animation: fadeSlideIn 0.3s ease;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- 底部 ---------- */
.app-footer {
  text-align: center;
  padding: 16px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-subtle);
}

/* ============================================================
   RWD — 行動裝置（≤768px）
   ============================================================ */
@media (max-width: 768px) {
  .app-header {
    padding: 12px 16px;
  }

  .app-title {
    font-size: 1.05rem;
  }

  .model-label-text {
    display: none; /* 手機版隱藏「模型」文字，只留圖示 */
  }

  .translator-main {
    padding: 20px 12px;
    justify-content: flex-start;
  }

  /* 切換為上下佈局 */
  .translator-container {
    flex-direction: column;
    gap: 0;
  }

  .panel-source {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .panel-target {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-left: 1px solid var(--border-subtle);
    border-top: none;
  }

  .panel {
    padding: 16px;
  }

  .text-area {
    min-height: 140px;
  }

  /* Swap 按鈕旋轉 90° */
  .swap-wrapper {
    padding: 0;
    margin: -22px auto;
  }

  .swap-btn .material-symbols-rounded {
    transform: rotate(90deg);
  }

  .swap-btn:hover .material-symbols-rounded {
    transform: rotate(90deg);
  }

  /* 翻譯按鈕全寬 */
  .panel-footer {
    justify-content: stretch;
  }

  .translate-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================================
   成功複製反饋動畫
   ============================================================ */
.copy-btn.copied .material-symbols-rounded::after {
  content: '✓';
}

/* ============================================================
   焦點環（輔助功能）
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--accent-start);
  outline-offset: 2px;
}

/* ============================================================
   滾動條自訂（Webkit）
   ============================================================ */
.text-area::-webkit-scrollbar {
  width: 6px;
}

.text-area::-webkit-scrollbar-track {
  background: transparent;
}

.text-area::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.text-area::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}
