:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --phonetic-color: #b45309;
  --error: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --card-bg: #1f232b;
    --text: #e7e9ee;
    --muted: #9aa1ac;
    --border: #2c313a;
    --accent: #4d8dff;
    --accent-contrast: #0b0f16;
    --phonetic-color: #f2b04f;
    --error: #f87171;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.app-header h1 {
  font-size: 24px;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
}

.voice-pref {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.voice-pref .field-label {
  margin: 0;
}

#voice-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  max-width: 180px;
}

#voice-preview-btn {
  padding: 5px 12px;
  font-size: 13px;
}

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.field-label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
}

textarea#input-text {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  font-family: inherit;
}

textarea#input-text:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 16px;
}

.accent-choice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.accent-choice .field-label {
  margin-bottom: 0;
}

.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
}

.primary-btn, .secondary-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

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

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

.status {
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 0;
}

.status.error {
  color: var(--error);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.result-content {
  font-size: 18px;
  line-height: 2.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.result-content ruby {
  margin: 0 1px;
  ruby-position: under;
}

.result-content rt {
  font-size: 13px;
  color: var(--phonetic-color);
  font-family: "Doulos SIL", "Charis SIL", Georgia, serif;
  user-select: none;
}

.hidden {
  display: none;
}

/* 图片标注 */
.image-dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 28px 16px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  background: var(--bg);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.image-dropzone:hover,
.image-dropzone:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.image-dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
}

.image-dropzone-hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.image-preview {
  max-width: 100%;
  max-height: 240px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.image-preview.hidden {
  display: none;
}

a.secondary-btn {
  text-decoration: none;
  display: inline-block;
}

a.secondary-btn.hidden {
  display: none;
}

.image-result-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

#image-result {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
}

.image-word-hitbox {
  position: absolute;
  cursor: pointer;
  border-radius: 3px;
}

.image-word-hitbox:hover {
  background: rgba(37, 99, 235, 0.16);
  outline: 1px solid rgba(37, 99, 235, 0.4);
}

.hint-text {
  color: var(--muted);
  font-size: 12.5px;
  margin: 10px 0 0;
}

/* 标签页导航 */
.tab-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab-btn {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.tab-count {
  font-size: 12px;
  opacity: 0.85;
}

/* 单词交互提示 */
.result-content .word {
  cursor: context-menu;
  border-radius: 4px;
}

.result-content .word:hover {
  background: rgba(37, 99, 235, 0.12);
}

/* 右键上下文菜单 */
.word-context-menu {
  position: fixed;
  z-index: 1000;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 160px;
}

.word-context-menu.hidden {
  display: none;
}

.word-context-menu button {
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
}

.word-context-menu button:hover {
  background: rgba(37, 99, 235, 0.12);
}

/* 提示 toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

/* 生词本 / 易错词本 列表 */
.book-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.book-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 20px 0;
  text-align: center;
}

.book-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.book-card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.book-card-word {
  font-size: 18px;
  font-weight: 700;
}

.speak-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 28px;
  height: 28px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.speak-btn:hover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.1);
}

.book-card-phonetic {
  color: var(--phonetic-color);
  font-family: "Doulos SIL", "Charis SIL", Georgia, serif;
  font-size: 14px;
}

.book-card-tag {
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 1px 8px;
}

.book-card-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.book-card-body {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
}

.book-card-pos {
  font-weight: 600;
  color: var(--accent);
  margin-right: 6px;
}

.book-card-phrases {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.book-card-phrases b {
  color: var(--text);
}

.book-card-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
}

.book-card-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.book-card-actions button:hover {
  color: var(--error);
  border-color: var(--error);
}

.file-warning {
  background: #fff7e6;
  border: 1px solid #f0b429;
  color: #7a4a00;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 20px;
}

.file-warning code {
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

@media (prefers-color-scheme: dark) {
  .file-warning {
    background: #3a2e10;
    border-color: #a87a1f;
    color: #f2c46d;
  }
  .file-warning code {
    background: rgba(255, 255, 255, 0.12);
  }
}

.site-footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer .footer-sep {
  margin: 0 6px;
}

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .panel {
    border: none;
    padding: 0;
    box-shadow: none;
  }
  .result-content { font-size: 16px; }
}
