/* ========== 瑞安话速查 · 移动端优先响应式样式 ========== */

:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --ink: #2a251e;
  --ink-soft: #575043;
  --muted: #8d8475;
  --line: #e7e0d3;
  --accent: #b4402e;
  --accent-dark: #932f20;
  --accent-soft: #f8eae6;
  --teal: #2f7568;
  --teal-soft: #e6f1ee;
  --gold: #b57f22;
  --gold-soft: #f8efdc;
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(60, 45, 30, 0.07);
  --tabbar-h: 58px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code {
  background: #efe9dd;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.9em;
  color: var(--accent-dark);
}

/* ---------- 头部 ---------- */
.app-header {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  padding: 18px 16px 16px;
  box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: 1px; }
.subtitle { margin: 2px 0 0; font-size: 13px; opacity: 0.85; }

/* ---------- 主区域 ---------- */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
}

.view { animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 搜索栏 / 筛选 ---------- */
.search-bar { display: flex; gap: 8px; }
.search-bar .input { flex: 1; }

.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 6px;
  flex-wrap: wrap;
}
.filter-hint { font-size: 12.5px; color: var(--muted); }

.input, .select, textarea.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px; /* >=16px 防止 iOS 聚焦缩放 */
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(180, 64, 46, 0.12);
}
.select { width: auto; padding-right: 28px; cursor: pointer; }
textarea.input { resize: vertical; min-height: 72px; }
.input-sm { min-height: 38px; font-size: 14px; }
.select-sm { min-height: 38px; font-size: 14px; }

/* ---------- 按钮 ---------- */
.btn-primary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, opacity .15s, border-color .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-primary:disabled { background: #cfb6af; cursor: not-allowed; }
.btn-ghost {
  background: var(--surface);
  color: var(--ink-soft);
  border-color: var(--line);
  font-weight: 500;
}
.btn-ghost:active { background: #f0ebe2; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 9px; }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 17px;
  color: var(--muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}
.icon-btn:active { background: #f0ebe2; }

/* ---------- 提示横幅 ---------- */
.banner {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.5;
}
.banner-convert { background: var(--teal-soft); color: var(--teal); }
.banner-warn { background: var(--gold-soft); color: var(--gold); margin-top: 8px; }
.banner-warn button {
  border: none; background: none; padding: 0;
  color: var(--accent); font-weight: 600;
  font-size: 13.5px; cursor: pointer; text-decoration: underline;
}
.result-meta {
  margin: 10px 2px 8px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.cache-tag {
  background: var(--gold-soft);
  color: var(--gold);
  border-radius: 5px;
  padding: 0 6px;
  font-size: 11.5px;
}

/* ---------- 结果卡片 ---------- */
.result-groups { display: flex; flex-direction: column; gap: 16px; }
.group-title {
  margin: 4px 2px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.group-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.group-title .count {
  background: #ece5d8;
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 0 7px;
  font-size: 11.5px;
  font-weight: 500;
}

.word-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  margin-bottom: 9px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color .15s;
}
.word-card:active { border-color: var(--accent); }
.wc-mandarin { font-size: 17.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.wc-dialect { margin-top: 4px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.wc-chars { font-size: 16px; color: var(--accent-dark); font-weight: 600; }
.wc-pinyin { font-size: 14px; color: var(--teal); font-style: italic; }
.wc-note { margin-top: 5px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 6px;
  padding: 1px 8px;
  vertical-align: middle;
}
.wc-actions { display: flex; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.wc-actions .btn-ghost { min-height: 34px; padding: 0 14px; font-size: 13px; }
.btn-danger { color: var(--danger) !important; }

.state-hint {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 44px 20px;
  line-height: 1.8;
}
.state-error {
  text-align: center;
  color: var(--danger);
  font-size: 14px;
  padding: 30px 20px;
}
.state-error button { margin-top: 10px; }
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.pager { text-align: center; margin-top: 14px; }

/* ---------- 卡片容器 / 表单 ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title { margin: 0 0 10px; font-size: 16px; }
.form-stack { display: flex; flex-direction: column; gap: 11px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: var(--ink-soft); font-weight: 500; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form .input-sm { flex: 1; min-width: 90px; }
.input-with-action { display: flex; gap: 8px; }
.input-with-action .input { flex: 1; }

.admin-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.admin-toolbar .spacer { flex: 1; }
.import-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-label { position: relative; overflow: hidden; }
.import-tip { margin: 9px 0 0; line-height: 1.7; }
.import-tip a { color: var(--accent); }

/* ---------- 音字表 ---------- */
.convert-result {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
}
.convert-result .cr-pinyin { font-size: 18px; color: var(--teal); font-weight: 600; font-style: italic; word-break: break-all; }
.unknown-chips { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  background: var(--gold-soft);
  color: var(--gold);
  border-radius: 7px;
  padding: 2px 9px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  font-family: inherit;
}
.char-list { display: flex; flex-direction: column; gap: 7px; }
.char-row {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.char-hanzi { font-size: 18px; font-weight: 700; min-width: 28px; text-align: center; }
.char-arrow { color: var(--muted); }
.char-pinyin { color: var(--teal); font-style: italic; flex: 1; word-break: break-all; }
.char-row .btn-sm { min-height: 32px; padding: 0 10px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(35, 28, 20, 0.48);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: maskIn .15s ease;
}
@keyframes maskIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: sheetUp .22s ease;
}
.sheet { border-radius: 18px 18px 0 0; }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.modal-actions .btn-primary { min-width: 92px; }

.detail-body .dt-mandarin { font-size: 24px; font-weight: 700; }
.detail-body .dt-row { margin-top: 12px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.detail-body .dt-label { color: var(--muted); font-size: 13px; min-width: 64px; }
.detail-body .dt-chars { font-size: 19px; color: var(--accent-dark); font-weight: 600; }
.detail-body .dt-pinyin { font-size: 17px; color: var(--teal); font-style: italic; }
.detail-body .dt-note { background: var(--bg); border-radius: 10px; padding: 10px 12px; color: var(--ink-soft); font-size: 14px; }
.detail-body .dt-meta { font-size: 12.5px; color: var(--muted); margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 18px);
  transform: translateX(-50%);
  background: rgba(42, 37, 30, 0.94);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 200;
  max-width: 88vw;
  text-align: center;
  animation: toastIn .2s ease;
}
.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--teal); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 底部 Tab ---------- */
.tabbar {
  order: 2;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
}
.tab {
  flex: 1;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-weight: 500;
}
.tab.active { color: var(--accent); font-weight: 700; }
.tab.active::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 30px; height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}
.app-header { order: 0; }
.app-main { order: 3; }

/* ========== PC / 宽屏适配 ========== */
@media (min-width: 768px) {
  .app-header { padding: 22px 24px 20px; text-align: center; }
  .brand h1 { font-size: 24px; }
  .tabbar {
    order: 1;
    position: static;
    height: auto;
    border-top: none;
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
  }
  .tab {
    flex: 0 1 auto;
    padding: 0 22px;
    min-height: 50px;
    font-size: 15px;
  }
  .tab.active::before {
    top: auto; bottom: 0;
    border-radius: 3px 3px 0 0;
  }
  .app-main {
    order: 2;
    padding: 22px 16px 40px;
  }
  .modal-mask { align-items: center; }
  .sheet {
    border-radius: var(--radius);
    padding: 20px 22px;
  }
  @keyframes sheetUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
  .toast { bottom: 28px; }
  .word-card:hover { border-color: #dcc9c2; }
}
