/* ===== 基础 ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f4f1ea;
  --bg-card: #fffdf7;
  --text-main: #2f2b26;
  --text-soft: #8a8278;
  --accent: #6b5b95;
  --accent-hover: #584a7d;
  --border: #e2dccf;
  --tooltip-bg: #2f2b26;
  --tooltip-text: #f6f2e9;
}

html {
  font-size: 16px;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-main);
  line-height: 1.7;
  min-height: 100vh;
}

.view {
  max-width: 840px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

[hidden] {
  display: none !important;
}

/* ===== 头部 ===== */
.app-header {
  text-align: center;
  margin-bottom: 28px;
}

.app-title {
  font-size: 1.9rem;
  letter-spacing: 1px;
  color: var(--accent);
}

.app-subtitle {
  margin-top: 6px;
  color: var(--text-soft);
  font-size: 0.95rem;
}

/* ===== 编辑区 ===== */
.editor {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 2px 10px rgba(47, 43, 38, 0.06);
}

.text-input {
  width: 100%;
  min-height: 320px;
  padding: 14px 16px;
  font-size: 1.05rem;
  line-height: 1.8;
  font-family: Georgia, "Times New Roman", "Songti SC", serif;
  color: var(--text-main);
  background: #fffefa;
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(107, 91, 149, 0.14);
}

.editor-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
}

.word-count {
  color: var(--text-soft);
  font-size: 0.88rem;
}

/* ===== 按钮 ===== */
.btn {
  border: none;
  cursor: pointer;
  border-radius: 8px;
  font-size: 1rem;
  padding: 10px 22px;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
}

.btn-ghost:hover {
  background: rgba(107, 91, 149, 0.08);
}

/* ===== 示例提示 ===== */
.demo-tip {
  margin-top: 24px;
  text-align: center;
  color: var(--text-soft);
  font-size: 0.9rem;
}

.demo-tip h2 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--text-soft);
  font-weight: 500;
}

/* ===== 阅读视图 ===== */
.read-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}

.read-hint {
  color: var(--text-soft);
  font-size: 0.88rem;
}

.reading-area {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 30px;
  font-family: Georgia, "Times New Roman", "Songti SC", serif;
  font-size: 1.12rem;
  line-height: 2;
  letter-spacing: 0.2px;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 2px 10px rgba(47, 43, 38, 0.06);
}

.reading-area p {
  margin-bottom: 1.1em;
}

.reading-area p:last-child {
  margin-bottom: 0;
}

/* ===== 可点击单词 ===== */
.word {
  cursor: pointer;
  border-radius: 3px;
  padding: 0 1px;
  transition: background 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: rgba(107, 91, 149, 0.12);
}

.word:hover {
  background: #e8e0f2;
  box-shadow: 0 0 0 2px #e8e0f2;
}

.word.active {
  background: #d9cdf0;
  box-shadow: 0 0 0 2px #d9cdf0;
}

/* ===== 释义气泡 ===== */
.tooltip {
  position: fixed;
  z-index: 100;
  max-width: min(420px, calc(100vw - 32px));
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  animation: tooltip-in 0.14s ease-out;
}

@keyframes tooltip-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 100%;
  border: 7px solid transparent;
  border-top-color: var(--tooltip-bg);
}

.tooltip-word {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: #f6d47f;
}

.tooltip-phonetic {
  font-size: 0.85rem;
  color: #c9c2b4;
  margin-top: 2px;
}

.tooltip-pos {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.72rem;
  color: #f6d47f;
  border: 1px solid rgba(246, 212, 127, 0.5);
  border-radius: 4px;
  padding: 1px 6px;
}

.tooltip-def {
  margin-top: 8px;
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--tooltip-text);
}

.tooltip-source {
  margin-top: 8px;
  font-size: 0.72rem;
  color: #8f887c;
}

.tooltip-def.error {
  color: #f0a9a9;
}

.tooltip-def.loading {
  color: #c9c2b4;
}

/* ===== 响应式 ===== */
@media (max-width: 640px) {
  .view {
    padding: 20px 12px 48px;
  }

  .app-title {
    font-size: 1.5rem;
  }

  .text-input {
    min-height: 240px;
    font-size: 1rem;
  }

  .reading-area {
    padding: 18px 16px;
    font-size: 1.05rem;
  }

  .read-header {
    flex-direction: column;
    gap: 10px;
  }

  .read-actions {
    width: 100%;
  }
}

/* ===== 新增功能样式 ===== */
.read-actions {
  display: flex;
  gap: 10px;
}

.translation-result {
  margin-top: 24px;
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 1.05rem;
  line-height: 1.9;
  color: var(--text-main);
  box-shadow: 0 2px 10px rgba(47, 43, 38, 0.06);
}

.translation-result h3 {
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--accent);
  font-weight: 600;
}

.translation-result p {
  margin-bottom: 1em;
}

.translation-result p:last-child {
  margin-bottom: 0;
}

.translation-result .trans-loading,
.translation-result .trans-error {
  color: var(--text-soft);
  font-size: 0.95rem;
}

.translation-result .trans-error {
  color: #b5503c;
}

@media (max-width: 640px) {
  .translation-result {
    padding: 16px;
    font-size: 1rem;
  }
}

/* ===== 逐段对照样式 ===== */
.trans-pair {
  margin-bottom: 1.5em;
}

.trans-pair p {
  margin-bottom: 0;
}

.trans-en {
  font-size: 1em;
  line-height: 1.9;
  color: var(--text-main);
}

.trans-zh {
  margin-top: 6px;
  padding-left: 1.1em;
  border-left: 2px solid var(--border);
  font-size: 0.93em;
  line-height: 1.9;
  color: #555;
}
