/* ==========================================================================
   数独求解器 — 样式（主站新拟态风格 + 三态主题，自包含）
   ========================================================================== */

:root {
  /* 浅色（默认） */
  --bg: #e6e9f0;
  --bg-deep: #dfe3ec;
  --text: #4b4f5c;
  --text2: #8a8fa3;
  --accent: #6c7cff;
  --accent-deep: #4a5bd6;
  --neu-dark: #c8cdd9;
  --neu-light: #ffffff;
  --radius: 18px;
  --radius-lg: 24px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --shadow-dark: 8px 8px 20px var(--neu-dark), -8px -8px 20px var(--neu-light);
  --shadow-inset: inset 4px 4px 8px var(--neu-dark), inset -4px -4px 8px var(--neu-light);
  --shadow-sm: 4px 4px 10px var(--neu-dark), -4px -4px 10px var(--neu-light);
  --grid-line: #c3c9d6;
  --grid-strong: #8a92a8;
  --warn-bg: rgba(255, 193, 7, .22);
  --ok: #2e9e6b;
  --err: #d9534f;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #22252e;
    --bg-deep: #1b1e26;
    --text: #d4d8e2;
    --text2: #8b91a3;
    --accent: #8f9dff;
    --accent-deep: #aab5ff;
    --neu-dark: #14161c;
    --neu-light: #343949;
    --grid-line: #3a4050;
    --grid-strong: #6a7390;
    --warn-bg: rgba(255, 193, 7, .18);
  }
}
:root[data-theme="dark"] {
  --bg: #22252e;
  --bg-deep: #1b1e26;
  --text: #d4d8e2;
  --text2: #8b91a3;
  --accent: #8f9dff;
  --accent-deep: #aab5ff;
  --neu-dark: #14161c;
  --neu-light: #343949;
  --grid-line: #3a4050;
  --grid-strong: #6a7390;
  --warn-bg: rgba(255, 193, 7, .18);
}
:root[data-theme="light"] {
  --bg: #e6e9f0;
  --bg-deep: #dfe3ec;
  --text: #4b4f5c;
  --text2: #8a8fa3;
  --accent: #6c7cff;
  --accent-deep: #4a5bd6;
  --neu-dark: #c8cdd9;
  --neu-light: #ffffff;
  --grid-line: #c3c9d6;
  --grid-strong: #8a92a8;
  --warn-bg: rgba(255, 193, 7, .22);
}

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

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100vh;
  transition: background-color .3s ease, color .3s ease;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; }

/* ---------- 页头 ---------- */
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 8px 0 20px; }
.head h1 { font-size: 24px; font-weight: 700; letter-spacing: .5px; }
.head .sub { font-size: 13px; color: var(--text2); margin-top: 2px; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border: none; border-radius: 50%;
  background: var(--bg); color: var(--text); font-size: 20px; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: box-shadow .15s ease, transform .15s ease;
}
.icon-btn:active { box-shadow: var(--shadow-inset); transform: scale(.97); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dark);
  padding: 18px;
  margin-bottom: 18px;
}
.card-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.step-no {
  flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  color: #fff; font-size: 14px; display: inline-flex; align-items: center; justify-content: center;
}
.title-hint { font-weight: 400; font-size: 12.5px; color: var(--text2); }
.hl-sample { background: var(--warn-bg); border-radius: 4px; padding: 0 4px; }

/* ---------- 模式切换 ---------- */
.mode-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.mode-btn {
  border: none; border-radius: 999px; padding: 8px 18px; font-size: 14px; cursor: pointer;
  background: var(--bg); color: var(--text2); box-shadow: var(--shadow-sm);
  transition: all .15s ease; font-family: inherit;
}
.mode-btn.active { box-shadow: var(--shadow-inset); color: var(--accent); font-weight: 600; }
.mode-hint { font-size: 12.5px; color: var(--text2); }

/* ---------- 上传区 ---------- */
.dropzone {
  border: 2px dashed var(--grid-line); border-radius: var(--radius);
  padding: 30px 16px; text-align: center; cursor: pointer; outline: none;
  transition: border-color .15s ease, background-color .15s ease;
}
.dropzone:hover, .dropzone:focus, .dropzone.dragover { border-color: var(--accent); background: rgba(108, 124, 255, .06); }
.dz-icon { width: 40px; height: 40px; color: var(--text2); margin-bottom: 8px; }
.dz-text { font-size: 15px; }
.dz-sub { font-size: 12px; color: var(--text2); margin-top: 6px; }

/* ---------- 预览与校正 ---------- */
.preview-box {
  border-radius: var(--radius); overflow: hidden; background: var(--bg-deep);
  box-shadow: var(--shadow-inset); padding: 8px; margin-bottom: 14px;
}
#previewCanvas { display: block; width: 100%; height: auto; border-radius: 12px; touch-action: none; cursor: crosshair; }

/* ---------- 按钮 ---------- */
.btn-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn {
  border: none; border-radius: 999px; padding: 10px 22px; font-size: 14.5px; cursor: pointer;
  background: var(--bg); color: var(--text); box-shadow: var(--shadow-sm); font-family: inherit;
  transition: all .15s ease;
}
.btn:hover { color: var(--accent); }
.btn:active { box-shadow: var(--shadow-inset); transform: scale(.98); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 4px 4px 12px rgba(108, 124, 255, .35); }
.btn.primary:hover { background: var(--accent-deep); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.inline-note { font-size: 12.5px; color: var(--text2); }
.inline-note.ok { color: var(--ok); }
.inline-note.err { color: var(--err); }

/* ---------- 数独网格 ---------- */
.sgrid {
  display: grid; grid-template-columns: repeat(9, 1fr);
  border: 3px solid var(--grid-strong); border-radius: 10px; overflow: hidden;
  background: var(--bg); margin-bottom: 14px;
}
.sgrid .cell {
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line);
  font-size: clamp(16px, 5vw, 24px); line-height: 1; min-width: 0;
}
.sgrid .cell:nth-child(3n) { border-right: 2px solid var(--grid-strong); }
.sgrid .cell:nth-child(9n) { border-right: none; }
.sgrid .cell:nth-child(n+19):nth-child(-n+27),
.sgrid .cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--grid-strong); }
.sgrid .cell:nth-child(n+73) { border-bottom: none; }
.sgrid input {
  width: 100%; height: 100%; border: none; outline: none; background: transparent;
  text-align: center; font: inherit; color: var(--text); font-family: var(--mono);
  padding: 0; border-radius: 0; -moz-appearance: textfield;
}
.sgrid input:focus { background: rgba(108, 124, 255, .16); }
.sgrid input.low-conf { background: var(--warn-bg); }
.sgrid.readonly .cell.given { font-weight: 600; color: var(--text); }
.sgrid.readonly .cell.solved { font-weight: 700; color: var(--accent); }
.sgrid .cell { font-family: var(--mono); }
.legend { display: inline-block; margin-left: 10px; font-size: 12.5px; font-weight: 600; }
.legend.given { color: var(--text); }
.legend.solved { color: var(--accent); }

/* ---------- 状态与进度 ---------- */
.status { margin: 0 0 18px; padding: 12px 16px; border-radius: var(--radius); background: var(--bg); box-shadow: var(--shadow-sm); }
.status-text { font-size: 13.5px; color: var(--text2); }
.status-text.err { color: var(--err); }
.status-text.ok { color: var(--ok); }
.progress { height: 6px; border-radius: 3px; background: var(--bg-deep); overflow: hidden; margin-bottom: 8px; box-shadow: var(--shadow-inset); }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .15s ease; }

/* ---------- 页脚 ---------- */
.foot { text-align: center; font-size: 12.5px; color: var(--text2); margin-top: 8px; }
.foot a { color: var(--text2); text-decoration: none; }
.foot a:hover { color: var(--accent); }
.foot .sep { margin: 0 6px; }

/* ---------- 移动端 ---------- */
@media (max-width: 480px) {
  .wrap { padding: 12px 10px 32px; }
  .card { padding: 14px; border-radius: var(--radius); }
  .head h1 { font-size: 20px; }
  .btn { padding: 9px 16px; font-size: 14px; }
  .dropzone { padding: 22px 10px; }
  .dz-icon { width: 32px; height: 32px; }
}
