:root {
  color-scheme: dark;
  --bg: #121317;
  --panel: #2d373e;
  --line: rgba(255, 255, 255, 0.22);
  --text: #fff7e7;
  --muted: #d4e0e6;
  --gold: #f3ca63;
  --green: #69d08c;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(240, 200, 106, 0.25), transparent 30%),
    radial-gradient(circle at 80% 8%, rgba(105, 208, 140, 0.24), transparent 34%),
    linear-gradient(135deg, #182224, #11181a);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

.shell {
  width: min(1060px, 100vw);
  height: min(800px, 100dvh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.topbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(150px, auto) auto auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(45, 55, 62, 0.96);
}

.topbar span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.topbar strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(22px, 4vw, 32px);
}

.best-box strong {
  color: var(--green);
  font-size: clamp(18px, 2.4vw, 24px);
  white-space: nowrap;
}

button {
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--gold);
  color: #171717;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.06);
}

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(105, 208, 140, 0.18), transparent 34%),
    linear-gradient(145deg, #4a6d66, #31534d);
  box-shadow: 0 22px 60px rgba(0,0,0,.28);
}

.game-board {
  width: auto;
  height: min(430px, calc(100% - 28px));
  aspect-ratio: 10 / 8;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  grid-auto-flow: row;
  grid-auto-columns: 0;
  grid-auto-rows: 0;
  gap: 7px;
  max-width: calc(100% - 40px);
  margin: auto;
  padding: 0;
  touch-action: none;
}

.tile {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,.82), rgba(255,255,255,.58));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  color: #171717;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", Arial, sans-serif;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1;
}

.tile.selected {
  border-color: #fff7c8;
  background: linear-gradient(180deg, #ffe38d, #f0c86a);
  box-shadow: 0 0 0 3px rgba(255, 247, 200, 0.28);
}

.tile.hinted {
  border-color: #d5ffe6;
  background: linear-gradient(180deg, #a9ffd0, #57d98b);
  box-shadow: 0 0 0 3px rgba(105, 208, 140, 0.34);
}

.tile.empty {
  visibility: hidden;
  pointer-events: none;
}

.result-modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 16, 0.48);
  padding: 20px;
}

.result-modal.hidden {
  display: none;
}

.result-card {
  width: min(340px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(255, 226, 122, 0.52);
  border-radius: 8px;
  background: rgba(24, 31, 35, 0.98);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  text-align: center;
}

.result-card strong {
  color: var(--gold);
  font-size: 28px;
}

.result-stats {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(255,255,255,.1);
  color: var(--text);
  font: inherit;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--gold);
}

.cheat-panel {
  position: fixed;
  right: 18px;
  top: 18px;
  z-index: 20;
  width: min(360px, calc(100vw - 24px));
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(255, 226, 122, 0.48);
  border-radius: 8px;
  background: rgba(24, 31, 35, 0.98);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
}

.cheat-panel.hidden {
  display: none;
}

.cheat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cheat-head strong {
  color: var(--gold);
}

.cheat-head button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 22px;
}

.cheat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.cheat-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.cheat-grid label:nth-child(3),
.cheat-check {
  grid-column: 1 / -1;
}

.cheat-grid span,
.cheat-panel small {
  color: var(--muted);
  font-size: 12px;
}

.cheat-check {
  display: flex !important;
  align-items: center;
  grid-template-columns: none;
}

.cheat-check input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--green);
}

.cheat-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.cheat-actions button {
  padding: 0 10px;
}

@media (max-width: 680px) {
  body { overflow: auto; }
  .shell { height: auto; min-height: 100dvh; }
  .topbar { grid-template-columns: repeat(2, 1fr); }
  .board-wrap { min-height: 560px; }
  .cheat-panel {
    right: 12px;
    top: 12px;
  }
  .cheat-grid,
  .cheat-actions {
    grid-template-columns: 1fr;
  }
}
