:root {
  --bg: #0f1720;
  --panel: #ffffff;
  --ink: #1f2d3d;
  --muted: #64748b;
  --line: #d7e0ea;
  --accent: #e8f0fb;
  --accent-ink: #29415f;
  --warm: #fdf0db;
  --warm-ink: #7a4a0c;
  --warm-line: #e7c89a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 30% 0%, #1d2b3a 0%, var(--bg) 55%);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
}

.app {
  max-width: 780px;
  margin: 0 auto;
  padding: 18px 18px 34px;
}

.head h1 {
  margin: 6px 0 14px;
  font-size: 22px;
  color: #e8eef6;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.head .sub {
  margin-left: 10px;
  font-size: 12px;
  font-weight: 400;
  color: #8ea3ba;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.notice {
  margin: 0 0 14px;
  padding: 14px 16px;
  background: #fff5f5;
  border: 1px solid #f3c2c2;
  border-left: 5px solid #c2410c;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}

.notice p {
  margin: 0;
  color: #7f1d1d;
  font-size: 14px;
  line-height: 1.75;
  font-weight: 600;
  letter-spacing: .2px;
}

.field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #9fb3c8;
}

select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><polyline points='7,10 12,15 17,10' fill='none' stroke='%235b7391' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/></svg>") no-repeat right 6px center;
  color: var(--accent-ink);
  font: inherit;
  font-size: 14px;
  padding: 9px 30px 9px 12px;
  cursor: pointer;
}

select:hover { border-color: #8fb0d9; }
select:focus-visible { outline: 2px solid #7296c8; outline-offset: 1px; }

.btn {
  border: 1px solid #c5d4e7;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 14px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}

.btn:hover { background: #d5e3f5; border-color: #a9c0dd; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }

.btn.accent {
  background: var(--warm);
  color: var(--warm-ink);
  border-color: var(--warm-line);
}

.btn.accent:hover { background: #fbe4c4; }

.board-wrap { margin: 4px 0 12px; }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #d5dde8;
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  touch-action: manipulation;
  user-select: none;
}

.board.dragging { outline: 3px dashed #7aa7e0; outline-offset: -6px; }

.drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7c90;
  font-size: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}

.board.empty .drop-hint { opacity: 1; }

.tile {
  position: absolute;
  top: 0;
  left: 0;
  background-repeat: no-repeat;
  background-color: #f7fafc;
  border-radius: 3px;
  transition: transform .13s cubic-bezier(.33, 1, .68, 1), box-shadow .15s, filter .15s;
  will-change: transform;
  cursor: pointer;
}

/* 格子少的时候给一点缝方便看边界，10 阶这种密的时候就留干净 */
.board.seams .tile {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}

.board.n4 .tile, .board.n5 .tile, .board.n10 .tile { border-radius: 2px; }

.tile:hover { filter: brightness(1.06); }

.tile.selected {
  box-shadow: inset 0 0 0 3px #3b82f6, 0 0 0 2px rgba(59, 130, 246, .35);
}

.tile.hint::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 3px solid #f59e0b;
  border-radius: 5px;
  background: rgba(245, 158, 11, .16);
  animation: pulse .9s ease-in-out infinite;
}

.tile.solved-pop { animation: pop .4s ease; }

@keyframes pulse {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

@keyframes pop {
  0% { transform-origin: center; }
  50% { filter: brightness(1.35); }
  100% { filter: brightness(1); }
}

.board.solved::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  animation: flash .62s ease-out forwards;
  pointer-events: none;
}

@keyframes flash {
  0% { opacity: 0; }
  35% { opacity: .55; }
  100% { opacity: 0; }
}

.status {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.pill {
  background: #edf2f7;
  color: #34465e;
  border-radius: 9px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
}

.pill b { font-weight: 700; }

.switch {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 500;
}

.message {
  min-height: 20px;
  margin: 2px 2px 12px;
  font-size: 13px;
  color: #9fb3c8;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 22, .62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.modal[hidden] { display: none; }

.modal-body {
  background: #f5f8fc;
  border-radius: 14px;
  padding: 18px;
  width: min(460px, 100%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .4);
}

.modal-body h2 {
  margin: 0 0 12px;
  font-size: 16px;
  color: #34465e;
}

.modal-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.modal-body th, .modal-body td {
  border-bottom: 1px solid #e2e9f2;
  padding: 7px 6px;
  text-align: center;
  color: #1f2937;
}

.modal-body th {
  color: #34465e;
  font-weight: 600;
  background: #e8eff8;
}

.modal-body th:first-child { border-radius: 6px 0 0 6px; }
.modal-body th:last-child { border-radius: 0 6px 6px 0; }

.modal-tip {
  margin: 10px 0 14px;
  font-size: 12px;
  color: #64748b;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

@media (max-width: 560px) {
  .app { padding: 12px 12px 26px; }
  .head h1 { font-size: 19px; }
  .head .sub { display: none; }
  .notice { padding: 12px 12px; }
  .notice p { font-size: 13px; line-height: 1.7; }
  .actions { grid-template-columns: repeat(2, 1fr); }
  .status { flex-wrap: wrap; }
  .switch { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .tile.hint::after { animation: none; opacity: 1; }
  .board.solved::after { animation: none; opacity: 0; }
}
