:root {
  --paper: #f6f4ef;
  --card: #ffffff;
  --ink: #2b2a27;
  --ink-soft: #6b6861;
  --line: #e7e2d8;
  --accent: #c8442f;
  --accent-soft: #f6e3dc;
  --green: #2e9e6b;
  --orange: #e08a2e;
  --red: #d9534f;
  --shadow: 0 6px 24px rgba(60, 45, 30, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* 关键：强制 hidden 属性生效，避免被 .modal/.loading-overlay 的 display:flex 覆盖 */
[hidden] { display: none !important; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

/* 顶部 */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}
.logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(200, 68, 47, 0.28);
}
.header-text h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 1px;
}
.header-text p {
  color: var(--ink-soft);
  font-size: 14px;
  margin-top: 4px;
}

/* 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

/* 上传区 */
.drop-zone {
  border: 2px dashed #d9d2c3;
  border-radius: 14px;
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: all .2s ease;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.drop-icon { font-size: 42px; margin-bottom: 10px; }
.drop-title { font-size: 16px; font-weight: 600; }
.drop-title .link { color: var(--accent); }
.drop-sub { color: var(--ink-soft); font-size: 13px; margin-top: 8px; }

/* 设置栏 */
.settings-card { display: flex; flex-direction: column; gap: 18px; }
.setting-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.setting-label { font-size: 14px; color: var(--ink-soft); min-width: 72px; }

.template-preview { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.template-thumb {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 4px;
}

.font-select {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 180px;
  height: 6px;
  border-radius: 999px;
  background: #e9e2d6;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.setting-value { font-size: 14px; font-weight: 600; min-width: 40px; }

/* 识别结果 */
.recog-box { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.recog-char {
  width: 96px;
  height: 96px;
  border: 2px solid var(--accent-soft);
  background: var(--paper);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 60px;
  font-family: "楷体", "KaiTi", "STKaiti", serif;
  color: var(--ink);
}
.recog-right { flex: 1; min-width: 220px; }
.recog-line {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
.recog-label { color: var(--ink-soft); font-size: 13px; }
.recog-value { font-weight: 600; font-size: 15px; }
.confidence-track {
  height: 8px;
  background: #efeae0;
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}
.confidence-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .4s ease, background .4s ease;
}
.recog-hint { font-size: 13px; color: var(--orange); min-height: 18px; }

.cand-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.cand-label { font-size: 13px; color: var(--ink-soft); flex-shrink: 0; }
.cand-list { display: flex; gap: 8px; flex-wrap: wrap; }
.cand-btn {
  min-width: 44px;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: #fff;
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.cand-btn:active { background: var(--accent); color: #fff; }

.manual-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.char-input {
  flex: 1;
  min-width: 160px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 18px;
  text-align: center;
}
.char-input:focus { outline: none; border-color: var(--accent); }

.btn {
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 15px;
  min-height: 44px;
  transition: all .15s ease;
  background: #fff;
  color: var(--ink);
}
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #b23a27; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* 并排对比 */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.compare-item { text-align: center; }
.compare-item canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.compare-item figcaption { margin-top: 10px; }
.tag {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.tag-hand { background: #eef2fb; color: #3f5aa6; }
.tag-std { background: var(--accent-soft); color: var(--accent); }

.download-row {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.footer {
  text-align: center;
  color: #a39d90;
  font-size: 12px;
  margin-top: 8px;
}

/* 加载遮罩 */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 34, 28, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.loading-box {
  background: #fff;
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  min-width: 300px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #eee3d8;
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: var(--ink); margin-bottom: 14px; }
.loading-track {
  height: 6px;
  background: #efeae0;
  border-radius: 999px;
  overflow: hidden;
}
.loading-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .3s ease;
}

@media (max-width: 560px) {
  .compare-grid { grid-template-columns: 1fr; }
  .page { padding: 20px 12px 48px; }
  .header { margin-bottom: 20px; }
  .header-text h1 { font-size: 22px; }
  .card { padding: 16px; border-radius: 14px; }
  .drop-zone { padding: 36px 18px; }
  .char-input { font-size: 18px; min-height: 46px; }
  .btn { flex: 1; min-width: 120px; }
  .download-row .btn { flex: 1 1 auto; }
  input[type="range"] { width: 140px; }
}

/* ===== 登录状态 ===== */
.auth-area {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.auth-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== 保存状态 ===== */
.save-status {
  margin-top: 10px;
  font-size: 13px;
  min-height: 18px;
  color: var(--ink-soft);
}
.save-status.ok { color: var(--green); }
.save-status.fail { color: var(--red); }

/* ===== 我的记录 ===== */
.records-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.records-header h3 { font-size: 16px; font-weight: 700; }
.records-list { display: flex; flex-direction: column; gap: 8px; }
.records-empty { color: var(--ink-soft); font-size: 14px; padding: 12px 0; text-align: center; }
.record-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.record-char {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-family: "楷体", "KaiTi", "STKaiti", serif;
  color: var(--ink);
  background: var(--paper);
  border-radius: 10px;
}
.record-meta { flex: 1; min-width: 0; }
.record-time { font-size: 13px; color: var(--ink-soft); }
.record-conf { font-size: 12px; color: #a39d90; margin-top: 2px; }
.record-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ===== 弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(40, 34, 28, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 16px 50px rgba(0,0,0,.25);
  text-align: center;
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.modal-sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 18px; line-height: 1.5; }
.login-step { display: flex; flex-direction: column; gap: 10px; }
.login-input {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  text-align: center;
}
.login-input:focus { outline: none; border-color: var(--accent); }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 10px 0; }
.modal-close { margin-top: 8px; width: 100%; }

/* 记录详情弹窗 */
.record-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.record-img-item { text-align: center; }
.record-img-item img {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-height: 120px;
  object-fit: contain;
}
.record-img-item figcaption { margin-top: 6px; }

@media (max-width: 560px) {
  .auth-name { max-width: 80px; }
  .record-imgs { grid-template-columns: 1fr; }
}
