/* ==============================================================
   数独 · 游戏专属样式
   选择器统一以 .g-sudoku 前缀限定，避免影响其他游戏
   ============================================================== */

.g-sudoku {
  --sd-line: rgba(255, 255, 255, 0.075);
  --sd-line-strong: rgba(255, 255, 255, 0.24);
  gap: 10px;
}

/* ------------------------------ 棋盘 ------------------------------ */

.g-sudoku .sd-board-holder {
  position: relative;
  width: min(100%, 480px);
  width: min(100%, 480px, calc(100dvh - 330px));
  margin: 0 auto;
  flex: none;
}

.g-sudoku .sd-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.018));
  box-shadow: 0 22px 48px -28px rgba(0, 0, 0, 0.92), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  touch-action: manipulation;
  transition: box-shadow 0.35s ease;
}

.g-sudoku .sd-board.done {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 45%, transparent),
    0 22px 48px -28px rgba(0, 0, 0, 0.92);
}

.g-sudoku .sd-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  border-right: 1px solid var(--sd-line);
  border-bottom: 1px solid var(--sd-line);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  transition: background 0.12s ease;
  touch-action: manipulation;
  overflow: hidden;
}
.g-sudoku .sd-cell:nth-child(9n) { border-right-color: transparent; }
.g-sudoku .sd-cell:nth-child(n + 73) { border-bottom-color: transparent; }

.g-sudoku .sd-cells .sd-cell:focus,
.g-sudoku .sd-cell:focus { outline: none; }

/* 3x3 宫粗线 */
.g-sudoku .sd-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.g-sudoku .sd-lines i {
  position: absolute;
  background: var(--sd-line-strong);
}
.g-sudoku .sd-lines i.v { top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.g-sudoku .sd-lines i.h { left: 0; right: 0; height: 2px; margin-top: -1px; }
.g-sudoku .sd-lines i.v1 { left: 33.3333%; }
.g-sudoku .sd-lines i.v2 { left: 66.6667%; }
.g-sudoku .sd-lines i.h1 { top: 33.3333%; }
.g-sudoku .sd-lines i.h2 { top: 66.6667%; }

/* 数字 */
.g-sudoku .sd-v {
  font-size: min(5.4vw, 26px);
  font-weight: 600;
  line-height: 1;
  color: #a9bcff;
  letter-spacing: 0;
}
.g-sudoku .sd-cell.given .sd-v { color: #eef2fa; font-weight: 700; }
.g-sudoku .sd-cell.val .sd-v { color: #9db4ff; }

/* 选中 / 同行列宫 / 同数字 */
.g-sudoku .sd-cell.peer { background: rgba(255, 255, 255, 0.05); }
.g-sudoku .sd-cell.same { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.g-sudoku .sd-cell.sel { background: color-mix(in srgb, var(--accent) 28%, transparent); }
.g-sudoku .sd-cell.sel::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent);
  border-radius: 5px;
  pointer-events: none;
  z-index: 3;
}
.g-sudoku .sd-cell.last { background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* 冲突 */
.g-sudoku .sd-cell.conflict { background: rgba(255, 92, 108, 0.16); }
.g-sudoku .sd-cell.conflict .sd-v { color: #ff6b7a; }
.g-sudoku .sd-cell.sel.conflict { background: rgba(255, 92, 108, 0.26); }
.g-sudoku .sd-cell.sel.conflict .sd-v { color: #ffa3ac; }

/* 笔记 3x3 */
.g-sudoku .sd-notes {
  position: absolute;
  inset: 1px;
  display: none;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  color: #8b96ad;
  font-size: min(2.3vw, 10.5px);
  line-height: 1;
  pointer-events: none;
}
.g-sudoku .sd-notes i {
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
}
.g-sudoku .sd-cell.note .sd-notes { display: grid; }
.g-sudoku .sd-cell.note .sd-v { display: none; }
.g-sudoku .sd-cell.readonly,
.g-sudoku .sd-board.readonly .sd-cell { cursor: default; }

/* 暂停遮罩 */
.g-sudoku .sd-pause-mask {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 14px;
  background: rgba(8, 11, 18, 0.86);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: sdFade 0.18s ease both;
}
.g-sudoku .sd-pause-t { font-size: 15px; font-weight: 700; letter-spacing: 0.08em; }
.g-sudoku .sd-pause-sub { text-align: center; }

/* ------------------------------ 顶部状态 ------------------------------ */

.g-sudoku .sd-hud {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}
.g-sudoku .sd-hud .badge { font-size: 11px; padding: 4px 10px; }
.g-sudoku .sd-hints {
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.g-sudoku .sd-time {
  margin-left: auto;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* ------------------------------ 工具行 ------------------------------ */

.g-sudoku .sd-tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: none;
}
.g-sudoku .sd-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--dim);
  font-size: 12.5px;
  font-weight: 600;
  transition: transform 0.08s, background 0.15s, color 0.15s, border-color 0.15s;
  touch-action: manipulation;
}
.g-sudoku .sd-tool:active { transform: scale(0.96); background: var(--surface-2); }
.g-sudoku .sd-tool.on {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 48%, transparent);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}
.g-sudoku .sd-tool-i {
  display: inline-flex;
  width: 17px;
  height: 17px;
  flex: none;
}
.g-sudoku .sd-tool-i svg { width: 17px; height: 17px; }

/* ------------------------------ 数字键盘 ------------------------------ */

.g-sudoku .sd-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  flex: none;
}
.g-sudoku .sd-key {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  transition: transform 0.08s, background 0.12s, border-color 0.12s, opacity 0.15s;
  touch-action: manipulation;
}
.g-sudoku .sd-key:active { transform: scale(0.95); background: var(--surface-3); }
.g-sudoku .sd-key.on {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.g-sudoku .sd-key.done { opacity: 0.32; }
.g-sudoku .sd-key-v {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.g-sudoku .sd-key .sd-remain {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 8.5px;
  font-weight: 600;
  color: var(--faint);
  line-height: 1;
}
.g-sudoku .sd-key.erase .sd-key-v { font-size: 12.5px; font-weight: 600; color: var(--dim); }
.g-sudoku .sd-key.erase { border-style: dashed; }

/* ------------------------------ 开始页 ------------------------------ */

.g-sudoku.sd-start { gap: 12px; }
.g-sudoku .sd-start-btn { margin-top: 12px; }
.g-sudoku.sd-start .seg-item { min-height: 42px; font-size: 13px; }
.g-sudoku .btn.sm { min-height: 40px; }
.g-sudoku .sd-foot {
  margin-top: auto;
  padding-top: 10px;
  text-align: center;
  font-size: 11px;
}

.g-sudoku .sd-resume {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
  background: linear-gradient(155deg,
      color-mix(in srgb, var(--accent) 13%, transparent),
      rgba(255, 255, 255, 0.022));
  padding: 13px var(--pad);
}
.g-sudoku .sd-resume-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.g-sudoku .sd-resume-t { font-size: 13.5px; font-weight: 700; }
.g-sudoku .sd-resume-sub {
  font-size: 11.5px;
  color: var(--dim);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.g-sudoku .sd-resume-btns { margin-top: 10px; }

.g-sudoku .sd-dinfo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
  font-size: 11.5px;
  line-height: 1.5;
}
.g-sudoku .sd-dinfo-i { display: inline-flex; align-items: baseline; gap: 3px; }
.g-sudoku .sd-dinfo b { color: var(--text); font-weight: 700; }

.g-sudoku .sd-dlist { display: flex; flex-direction: column; }
.g-sudoku .sd-drow {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
  border-radius: 8px;
}
.g-sudoku .sd-drow:last-child { border-bottom: 0; }
.g-sudoku .sd-drow .n { font-size: 12.5px; color: var(--dim); }
.g-sudoku .sd-drow .b {
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.g-sudoku .sd-drow .c {
  font-size: 11px;
  color: var(--faint);
  min-width: 44px;
  text-align: right;
}
.g-sudoku .sd-drow.head { padding-bottom: 4px; }
.g-sudoku .sd-drow.head .n,
.g-sudoku .sd-drow.head .b,
.g-sudoku .sd-drow.head .c { font-size: 10.5px; font-weight: 600; color: var(--faint); }
.g-sudoku .sd-drow.cur { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.g-sudoku .sd-drow.cur .n { color: var(--text); font-weight: 600; }

/* ------------------------------ 生成中 ------------------------------ */

.g-sudoku.sd-genwrap {
  align-items: center;
  justify-content: center;
}
.g-sudoku .sd-gen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 26px;
  text-align: center;
}
.g-sudoku .sd-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.13);
  border-top-color: var(--accent);
  animation: sdSpin 0.8s linear infinite;
}
.g-sudoku .sd-gen-t { font-size: 14px; font-weight: 700; letter-spacing: 0.04em; }

/* ------------------------------ 结算 ------------------------------ */

.g-sudoku .sd-result {
  flex: none;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--ok) 32%, var(--line));
  background: linear-gradient(165deg,
      color-mix(in srgb, var(--ok) 11%, transparent),
      rgba(255, 255, 255, 0.02));
  padding: 13px var(--pad) 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  animation: sdUp 0.32s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}
.g-sudoku .sd-result-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.g-sudoku .sd-result-k {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: 0.04em;
}
.g-sudoku .sd-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  flex: none;
}
.g-sudoku .sd-result-time {
  margin-top: 3px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.g-sudoku .sd-result-meta {
  text-align: right;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.g-sudoku .sd-best { color: var(--dim); }
.g-sudoku .sd-best.new { color: var(--ok); font-weight: 700; }
.g-sudoku .sd-result .btn-row { gap: 8px; }
.g-sudoku .sd-result-sub { display: flex; gap: 8px; }
.g-sudoku .sd-result-sub .btn { flex: 1; }

/* ------------------------------ 历史 ------------------------------ */

.g-sudoku .sd-hist-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 4px;
}
.g-sudoku .sd-hist {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  touch-action: manipulation;
}
.g-sudoku .sd-hist:active { transform: scale(0.985); background: var(--surface-2); border-color: var(--line-2); }
.g-sudoku .sd-hist-badge {
  flex: none;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 7px;
  padding: 3px 7px;
  line-height: 1.3;
}
.g-sudoku .sd-hist-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.g-sudoku .sd-hist-date {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.g-sudoku .sd-hist-sub { font-size: 10.5px; color: var(--faint); }
.g-sudoku .sd-hist-time {
  flex: none;
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.g-sudoku .sd-hist-chev { flex: none; color: var(--faint); display: inline-flex; }

.g-sudoku .sd-empty {
  margin-top: 18px;
  padding: 26px 16px;
  border-radius: var(--radius);
  border: 1px dashed var(--line-2);
  background: var(--surface);
  text-align: center;
}
.g-sudoku .sd-empty-t { font-size: 13px; font-weight: 700; color: var(--dim); margin-bottom: 6px; }

/* ------------------------------ 回放 ------------------------------ */

.g-sudoku.sd-replay { gap: 12px; }
.g-sudoku .sd-replay-ctrl {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.g-sudoku .sd-replay-btns {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 8px;
}
.g-sudoku .sd-replay-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}
.g-sudoku .sd-replay-progress .progress { flex: 1; }
.g-sudoku .sd-replay-count {
  flex: none;
  min-width: 66px;
  text-align: right;
  font-size: 11.5px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------ 动画 ------------------------------ */

@keyframes sdSpin { to { transform: rotate(360deg); } }
@keyframes sdFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sdUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------ 小屏 / 矮屏适配 ------------------------------ */

@media (max-height: 710px) {
  .g-sudoku { gap: 8px; }
  .g-sudoku .sd-tool { min-height: 38px; }
  .g-sudoku .sd-key { min-height: 44px; }
  .g-sudoku .sd-pad { gap: 6px; }
  .g-sudoku .sd-hud { min-height: 26px; }
  .g-sudoku .sd-result { padding: 11px var(--pad) 12px; gap: 9px; }
  .g-sudoku .sd-result-time { font-size: 26px; }
  /* 矮屏开始页再压缩，保证 360x640 首屏可见开始/历史按钮 */
  .g-sudoku.sd-start { gap: 10px; }
  .g-sudoku.sd-start .panel { padding: 12px; }
  .g-sudoku.sd-start .sd-drow { padding: 5px 2px; }
  .g-sudoku.sd-start .sd-start-btn { margin-top: 8px; }
  .g-sudoku.sd-start .sd-foot { display: none; }
}

@media (max-width: 365px) {
  .g-sudoku { gap: 8px; }
  .g-sudoku .sd-key { min-height: 45px; }
  .g-sudoku .sd-tool { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .g-sudoku .sd-spinner { animation-duration: 2s; }
}
