/* ==============================================================
   杀手数独 · 游戏专属样式
   选择器统一以 .g-killersudoku 前缀限定
   ============================================================== */

.g-killersudoku {
  --ks-line: rgba(255, 255, 255, 0.075);
  --ks-strong: rgba(255, 255, 255, 0.24);
  --ks-cage: rgba(170, 196, 255, 0.88);
  gap: 10px;
}

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

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

.ks-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;
}
.ks-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);
}

.ks-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(--ks-line);
  border-bottom: 1px solid var(--ks-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;
}
.ks-cell:nth-child(9n) { border-right-color: transparent; }
.ks-cell:nth-child(n + 73) { border-bottom-color: transparent; }
.ks-cell:focus { outline: none; }

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

/* 虚线笼边界（SVG 覆盖层） */
.ks-cages {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  overflow: visible;
}
.ks-cages path {
  fill: none;
  stroke: var(--ks-cage);
  stroke-width: 0.04;
  stroke-dasharray: 0.105 0.075;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 笼角标 */
.ks-sum {
  position: absolute;
  top: 1px;
  left: 3px;
  z-index: 4;
  font-size: min(2.5vw, 10.5px);
  line-height: 1;
  font-weight: 700;
  color: #8fa6d8;
  letter-spacing: 0.01em;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.ks-sum.on { color: var(--accent); }
.ks-sum.over { color: #ff7b88; }

/* 数字 */
.ks-cell .ks-v {
  position: relative;
  z-index: 1;
  margin-top: 3px;
  font-size: min(5vw, 21px);
  font-weight: 600;
  line-height: 1;
  color: #a9bcff;
}
.ks-cell.given .ks-v { color: #eef2fa; font-weight: 700; }
.ks-cell.val .ks-v { color: #b8c8ff; }

/* 选中 / 同行列宫 / 同数字 / 同笼 */
.ks-cell.peer { background: rgba(255, 255, 255, 0.045); }
.ks-cell.same { background: color-mix(in srgb, var(--accent) 13%, transparent); }
.ks-cell.cage-sel { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.ks-cell.sel { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.ks-cell.sel::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent);
  border-radius: 5px;
  pointer-events: none;
  z-index: 5;
}
.ks-cell.last { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.ks-cell.over { background: rgba(255, 92, 108, 0.055); }

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

/* 笔记 3x3 */
.ks-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.2vw, 9.5px);
  line-height: 1;
  pointer-events: none;
}
.ks-notes i {
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
}
.ks-cell.note .ks-notes { display: grid; }
.ks-cell.note .ks-v { display: none; }

/* 暂停遮罩 */
.ks-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: ksFade 0.18s ease both;
}
.ks-pause-t { font-size: 15px; font-weight: 700; letter-spacing: 0.08em; }

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

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

/* ------------------------------ 笼和状态条 ------------------------------ */

.ks-cagebar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-height: 30px;
  padding: 0 11px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 11.5px;
  color: var(--dim);
  transition: border-color 0.15s, background 0.15s;
}
.ks-cagebar .ks-cage-v {
  margin-left: auto;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.ks-cagebar .ks-cage-s {
  min-width: 40px;
  text-align: right;
  font-size: 10.5px;
  color: var(--faint);
}
.ks-cagebar.over {
  border-color: color-mix(in srgb, var(--err) 50%, transparent);
  background: color-mix(in srgb, var(--err) 10%, transparent);
}
.ks-cagebar.over .ks-cage-t,
.ks-cagebar.over .ks-cage-v { color: #ff8a94; }

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

.ks-tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: none;
}
.ks-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;
}
.ks-tool:active { transform: scale(0.96); background: var(--surface-2); }
.ks-tool.on {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 48%, transparent);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}
.ks-tool-i { display: inline-flex; width: 17px; height: 17px; flex: none; }
.ks-tool-i svg { width: 17px; height: 17px; }

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

.ks-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  flex: none;
}
.ks-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;
}
.ks-key:active { transform: scale(0.95); background: var(--surface-3); }
.ks-key.done { opacity: 0.32; }
.ks-key-v {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.ks-key .ks-remain {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 8.5px;
  font-weight: 600;
  color: var(--faint);
  line-height: 1;
}
.ks-key.erase .ks-key-v { font-size: 12.5px; font-weight: 600; color: var(--dim); }
.ks-key.erase { border-style: dashed; }

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

.ks-start { gap: 12px; }
.ks-startp { display: flex; flex-direction: column; }
.ks-start .seg-item { min-height: 42px; font-size: 13px; }
.ks-desc {
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--faint);
  letter-spacing: 0.01em;
}
.ks-bestlist { display: flex; flex-direction: column; margin-top: 2px; }
.ks-brow {
  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;
}
.ks-brow:last-child { border-bottom: 0; }
.ks-brow .n { font-size: 12.5px; color: var(--dim); }
.ks-brow .b { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ks-brow .c { font-size: 10.5px; color: var(--faint); min-width: 36px; text-align: right; }
.ks-brow.cur { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.ks-brow.cur .n { color: var(--text); font-weight: 600; }
.ks-start-btn { margin-top: 14px; min-height: 46px; }
.ks-foot { margin-top: auto; padding-top: 8px; text-align: center; font-size: 11px; }

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

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

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

.ks-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: ksUp 0.32s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}
.ks-result-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.ks-result-k {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: 0.04em;
}
.ks-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  flex: none;
}
.ks-result-time {
  margin-top: 3px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.ks-result-meta {
  text-align: right;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.ks-best { color: var(--dim); }
.ks-best.new { color: var(--ok); font-weight: 700; }
.ks-result .btn-row { gap: 8px; }
.ks-result-sub { display: flex; gap: 8px; }
.ks-result-sub .btn { flex: 1; }

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

@keyframes ksSpin { to { transform: rotate(360deg); } }
@keyframes ksFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ksUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

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

@media (max-height: 710px) {
  .g-killersudoku { gap: 8px; }
  .ks-tool { min-height: 38px; }
  .ks-key { min-height: 44px; }
  .ks-pad { gap: 6px; }
  .ks-hud { min-height: 26px; }
  .ks-cagebar { min-height: 27px; }
  .ks-result { padding: 11px var(--pad) 12px; gap: 9px; }
  .ks-result-time { font-size: 26px; }
  .ks-start { gap: 10px; }
  .ks-start .panel { padding: 12px; }
  .ks-brow { padding: 5px 2px; }
  .ks-start-btn { margin-top: 10px; }
  .ks-foot { display: none; }
}

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

@media (prefers-reduced-motion: reduce) {
  .ks-spinner { animation-duration: 2s; }
  .ks-result { animation: none; }
}
