/* 数独 · 主题与组件样式
   深浅色由 <html data-theme="dark|light"> 控制，默认深色 */

:root,
[data-theme="dark"] {
  --bg: #16130f;
  --surface: #221c16;
  --surface-2: #2a231b;
  --line: #332b22;
  --line-strong: #7d6549;
  --ink: #e6dbc9;
  --ink-soft: #9b8f7e;
  --accent: #f0b45c;
  --sel: #3a2e1f;
  --peer: #241e18;
  --bad: #e8705f;
  --bad-bg: #3a2320;
  --bad-sel: #452823;
  --shadow: 0 0 0 1px rgba(240, 180, 92, .06), 0 18px 40px -20px rgba(0, 0, 0, .9);
  --chip-on-bg: rgba(240, 180, 92, .08);
  --chip-on-line: rgba(240, 180, 92, .5);
}

[data-theme="light"] {
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f4f2ec;
  --line: #e6e2da;
  --line-strong: #a89d8b;
  --ink: #2b2723;
  --ink-soft: #8a8279;
  --accent: #2f6fd0;
  --sel: #e8f0fd;
  --peer: #f3f1ec;
  --bad: #d64545;
  --bad-bg: #fbeceb;
  --bad-sel: #f7dedd;
  --shadow: 0 0 0 1px rgba(0, 0, 0, .03), 0 14px 30px -18px rgba(0, 0, 0, .28);
  --chip-on-bg: rgba(47, 111, 208, .08);
  --chip-on-line: rgba(47, 111, 208, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent }
html, body { margin: 0; min-height: 100% }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex; justify-content: center;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  transition: background .2s, color .2s;
}
.wrap { width: 100%; max-width: 440px }

/* 顶栏 */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px }
.brand { min-width: 0 }
h1 { font-size: 18px; font-weight: 500; margin: 0; letter-spacing: .04em }
.sub { font-size: 12px; color: var(--ink-soft); margin-top: 3px; letter-spacing: .02em }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none }
#sound-toggle svg { display: block }
#sound-toggle svg.ico-off { display: none }
#sound-toggle[data-muted="1"] svg.ico-on { display: none }
#sound-toggle[data-muted="1"] svg.ico-off { display: block }
#sound-toggle[data-muted="1"] { opacity: .6 }
.icon-btn {
  flex: none; width: 38px; height: 38px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink-soft); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; padding: 0;
}
.icon-btn:active { transform: scale(.94) }
.icon-btn:hover { color: var(--accent); border-color: var(--chip-on-line) }

/* 盘面 */
#board {
  display: grid;
  background: var(--line-strong);
  border: 2px solid var(--line-strong);
  border-radius: 10px; overflow: hidden;
  touch-action: manipulation;
  box-shadow: var(--shadow);
}
.cell {
  aspect-ratio: 1;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--cell-font, 26px);
  font-weight: 400; font-variant-numeric: tabular-nums;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  user-select: none; position: relative; cursor: pointer;
  transition: background .15s;
}
.cell.box-r { border-right: 2px solid var(--line-strong) }
.cell.box-b { border-bottom: 2px solid var(--line-strong) }
.cell.right-edge { border-right: 0 }
.cell.bottom-edge { border-bottom: 0 }
.cell.peer { background: var(--peer) }
.cell.sel { background: var(--sel) }
.cell.user { color: var(--accent); font-weight: 500 }
.cell.bad { color: var(--bad); background: var(--bad-bg) }
.cell.sel.bad { background: var(--bad-sel) }
.cell.pop { animation: breathe .3s ease-out }
@keyframes breathe {
  from { opacity: .45; transform: scale(.94) }
  to { opacity: 1; transform: scale(1) }
}
.cell.locked { cursor: default }

/* 数字键盘 */
#pad {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 8px; margin-top: 16px;
}
.key {
  aspect-ratio: 1.15;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface-2); color: var(--ink);
  font-size: 22px; font-weight: 400; cursor: pointer;
  font-family: inherit; transition: all .12s;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.key:active { background: var(--sel); color: var(--accent); transform: scale(.97) }
.key:disabled { opacity: .25; cursor: default }
.key.two-digit { font-size: 17px; letter-spacing: -.02em }

/* 操作 */
.actions { display: flex; gap: 8px; margin-top: 10px }
.act {
  flex: 1; min-height: 44px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-soft);
  border-radius: 11px; font-size: 14px; cursor: pointer; font-family: inherit;
  transition: all .12s;
}
.act:active { background: var(--surface-2) }

/* 底部切换：尺寸 + 难度 */
.picker { margin-top: 18px }
.picker-label {
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-soft); opacity: .7; margin-bottom: 7px;
}
.chips { display: grid; gap: 7px }
.chips.sizes { grid-template-columns: repeat(5, 1fr) }
.chips.levels { grid-template-columns: repeat(3, 1fr); margin-top: 7px }
.chip {
  min-height: 40px; border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--ink-soft);
  font-size: 14px; cursor: pointer; font-family: inherit;
  transition: all .14s; padding: 0 2px;
  font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] {
  border-color: var(--chip-on-line); color: var(--accent);
  background: var(--chip-on-bg); font-weight: 500;
}
.chip:disabled { opacity: .3; cursor: not-allowed }

/* 提示条 */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line-strong);
  font-size: 14px; padding: 11px 20px; border-radius: 999px;
  opacity: 0; transition: all .3s; pointer-events: none; white-space: nowrap;
  z-index: 20;
}
#toast.on { opacity: 1; transform: translate(-50%, 0) }

/* 页面底部 */
footer {
  margin-top: 22px; text-align: center;
  font-size: 12px; color: var(--ink-soft); line-height: 1.9;
}
footer .dim { opacity: .65 }
footer a { color: var(--ink-soft); text-decoration: underline; text-underline-offset: 2px }
footer a:hover { color: var(--accent) }

/* 内容页 */
.doc { line-height: 1.85; font-size: 15px }
.doc h2 {
  font-size: 16px; font-weight: 600; margin: 28px 0 10px;
  padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
.doc h2:first-of-type { margin-top: 18px }
.doc h3 { font-size: 14px; font-weight: 600; margin: 20px 0 6px; color: var(--accent) }
.doc p { margin: 10px 0; color: var(--ink); opacity: .92 }
.doc ul, .doc ol { margin: 10px 0; padding-left: 22px }
.doc li { margin: 6px 0; opacity: .92 }
.doc code {
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 5px; font-size: 13px;
}
.doc .note {
  background: var(--surface-2); border-left: 2px solid var(--accent);
  padding: 12px 14px; border-radius: 0 8px 8px 0; margin: 16px 0;
  font-size: 14px; opacity: .95;
}
.doc table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 14px }
.doc th, .doc td { border: 1px solid var(--line); padding: 8px 10px; text-align: left }
.doc th { background: var(--surface-2); font-weight: 600; font-size: 13px }
.back {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 28px; font-size: 14px; color: var(--accent);
  text-decoration: none;
}
.back:hover { text-decoration: underline }
