:root {
  --bg: #FFFFFF;
  --surface: #F1F3F4;
  --surface-hover: #E8EAED;
  --text: #000000;
  --text-secondary: #5F6368;
  --border: #E5E7EB;
  --accent: #1A73E8;
  --accent-soft: #E8F0FE;
  --der: #1A73E8;
  --die: #C5221F;
  --das: #188038;
  --danger: #C5221F;
  --ok: #188038;
  --warn: #B06000;
  --radius: 12px;
  --font-sans: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0F0F0F;
    --surface: #1E1F20;
    --surface-hover: #2A2B2D;
    --text: #F1F3F4;
    --text-secondary: #9AA0A6;
    --border: #2D2E30;
    --accent: #8AB4F8;
    --accent-soft: rgba(138, 180, 248, 0.14);
    --der: #8AB4F8;
    --die: #F28B82;
    --das: #81C995;
    --danger: #F28B82;
    --ok: #81C995;
    --warn: #FDD663;
  }
}

:root[data-theme="dark"] {
  --bg: #0F0F0F;
  --surface: #1E1F20;
  --surface-hover: #2A2B2D;
  --text: #F1F3F4;
  --text-secondary: #9AA0A6;
  --border: #2D2E30;
  --accent: #8AB4F8;
  --accent-soft: rgba(138, 180, 248, 0.14);
  --der: #8AB4F8;
  --die: #F28B82;
  --das: #81C995;
  --danger: #F28B82;
  --ok: #81C995;
  --warn: #FDD663;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-variant-numeric: lining-nums proportional-nums;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  background: var(--bg);
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* 顶部搜索栏 */
.topbar {
  position: relative;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 10px 0 12px;
  background: var(--surface);
  border-radius: 12px;
}

.search-icon {
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
}

#search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  outline: none;
}

#search-input::placeholder {
  color: var(--text-secondary);
}

#search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--surface-hover);
}

.suggest-box {
  position: absolute;
  left: 14px;
  right: 14px;
  top: calc(100% - 2px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 55vh;
  overflow-y: auto;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.10);
  z-index: 30;
}

.suggest-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.suggest-item:last-child {
  border-bottom: none;
}

.suggest-item:active {
  background: var(--surface);
}

.suggest-word {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.suggest-summary {
  flex: 1;
  min-width: 0;
  text-align: right;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 三性极简圆点 */
.gender-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gender-dot.m { background: var(--der); }
.gender-dot.f { background: var(--die); }
.gender-dot.n { background: var(--das); }

/* 主内容区 */
.main-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 28px;
}

.view.hidden {
  display: none;
}

/* 首页空态 */
.home-idle {
  padding-top: 12px;
}

.brand-mark {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 6px 2px 18px;
}

.brand-title {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 2px 10px;
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  padding: 4px 6px;
  cursor: pointer;
}

.history-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  cursor: pointer;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:active {
  background: var(--surface-hover);
}

.history-mode {
  font-size: 12px;
  color: var(--text-secondary);
}

.empty-hint {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  padding: 14px 2px;
}

/* 结果卡片 */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.hint-banner {
  padding: 10px 14px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px;
  color: var(--text-secondary);
}

.hint-banner strong {
  color: var(--text);
  font-weight: 600;
}

.entry-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.entry-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.entry-word {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.article-tag {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.pos-pill {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
}

.entry-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
}

.action-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.entry-meta {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.ipa-text {
  font-family: "Helvetica Neue", Arial, sans-serif;
  margin-right: 10px;
}

.gloss-list {
  margin: 12px 0 0;
  padding-left: 18px;
  font-size: 15px;
  line-height: 1.65;
}

.gloss-list li {
  margin-bottom: 4px;
}

.en-glosses {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.sub-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sub-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.example-item {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.55;
}

.example-tr {
  font-size: 13px;
  color: var(--text-secondary);
}

.word-token {
  cursor: pointer;
  border-radius: 3px;
}

.word-token:hover {
  background: var(--accent-soft);
}

details.forms-details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  list-style: none;
  padding: 2px 0;
}

.forms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.form-cell {
  background: var(--surface);
  padding: 8px 10px;
  border-radius: 8px;
}

.form-label {
  font-size: 11px;
  color: var(--text-secondary);
}

.form-val {
  font-size: 14px;
  font-weight: 500;
  margin-top: 2px;
}

/* AI 卡片 */
.ai-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.ai-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.ai-source {
  font-size: 12px;
  color: var(--text-secondary);
}

.ai-body {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
}

.ai-body h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 14px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.ai-body h3:first-child {
  margin-top: 2px;
}

.ai-body p {
  margin: 6px 0;
}

.ai-body ul, .ai-body ol {
  margin: 6px 0;
  padding-left: 18px;
}

.ai-body li {
  margin-bottom: 4px;
}

.ai-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 4px;
}

.ai-cursor::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--accent);
  margin-left: 3px;
  vertical-align: text-bottom;
  animation: blink 0.9s infinite;
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.followup-bar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.followup-bar input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.followup-thread {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.followup-q {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.photo-preview {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

/* 按钮与表单 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

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

.btn.ghost {
  background: var(--surface);
  border-color: transparent;
}

.btn:active {
  opacity: 0.85;
}

/* 生词本与复习 */
.subtabs {
  display: flex;
  gap: 8px;
  padding-top: calc(4px + env(safe-area-inset-top));
  margin-bottom: 14px;
}

.subtab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.subtab.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.due-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
}

.vocab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  background: var(--surface);
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}

.vocab-row-main {
  min-width: 0;
  flex: 1;
}

.vocab-row-word {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 16px;
  font-weight: 600;
}

.vocab-row-zh {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.review-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 20px;
  text-align: center;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.review-word {
  font-size: 30px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.review-answer {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  width: 100%;
  text-align: left;
  font-size: 15px;
  line-height: 1.6;
}

.rate-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.rate-btn {
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

/* 设置页 */
.settings-container {
  padding-top: calc(4px + env(safe-area-inset-top));
}

.page-title {
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 14px 2px;
}

.settings-card {
  margin-bottom: 12px;
}

.card-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  padding: 3px;
  border-radius: 10px;
  gap: 3px;
  margin-bottom: 12px;
}

.segmented button {
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.field-group {
  margin-bottom: 12px;
}

.field-group.compact {
  margin-bottom: 0;
}

.field-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field-group input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.pwd-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pwd-wrap input {
  flex: 1;
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.status-line {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-line.ok { color: var(--ok); }
.status-line.err { color: var(--danger); }

.row-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.row-title {
  font-size: 15px;
  font-weight: 500;
}

.row-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: var(--surface-hover);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.18s;
}

.switch:checked {
  background: var(--accent);
}

.switch:checked::after {
  transform: translateX(18px);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.meta-lines {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.guide-list {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* 底部 3-Tab */
.tabbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 46px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

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

/* 访问口令门禁 */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 340px;
  padding: 24px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

.auth-card input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

/* 模型候选小标签 */
.model-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.model-chip {
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.model-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
