:root {
  color-scheme: dark;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: #050713;
  color: #f3f5ff;
  --panel: rgba(18, 23, 54, 0.92);
  --line: rgba(130, 146, 255, 0.25);
  --muted: #aab1d4;
  --accent: #7c8cff;
  --cyan: #55d9ff;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  padding: 18px;
  background:
    radial-gradient(circle at 18% 12%, rgba(76, 64, 180, 0.24), transparent 30%),
    radial-gradient(circle at 85% 88%, rgba(0, 174, 255, 0.13), transparent 32%),
    #050713;
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.game-shell {
  width: min(1180px, 100%);
  min-height: calc(100vh - 36px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(9, 12, 30, 0.82);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  display: grid;
  grid-template-rows: auto auto minmax(420px, 1fr) auto;
}

.game-header,
.settings,
.game-footer {
  position: relative;
  z-index: 2;
  background: var(--panel);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, #846dff, #40c7ff);
  box-shadow: 0 8px 24px rgba(87, 115, 255, 0.35);
  font-size: 24px;
}
.brand h1 { margin: 0; font-size: clamp(19px, 2.2vw, 28px); letter-spacing: .04em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.stats { display: flex; gap: 10px; }
.stat {
  min-width: 104px;
  padding: 8px 14px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(7, 10, 28, 0.56);
}
.stat span { display: block; margin-bottom: 2px; color: var(--muted); font-size: 12px; }
.stat strong { color: var(--cyan); font-size: 21px; font-variant-numeric: tabular-nums; }

.settings {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 13px 20px;
  padding: 13px 24px;
  border-bottom: 1px solid var(--line);
}

.field { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.stepper { display: flex; align-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; }
.stepper button {
  width: 34px;
  height: 32px;
  border: 0;
  background: #252c60;
  color: white;
  cursor: pointer;
}
.stepper button:hover:not(:disabled) { background: #38439a; }
.stepper output { min-width: 70px; text-align: center; color: #ffe58c; font-variant-numeric: tabular-nums; }

.check-field { display: flex; align-items: center; gap: 8px; min-height: 34px; cursor: pointer; }
.check-field input { width: 17px; height: 17px; accent-color: var(--accent); }
.setting-actions { display: flex; gap: 8px; margin-left: auto; }

.button {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 14px;
  color: white;
  cursor: pointer;
}
.button.secondary { border-color: var(--line); background: #252c60; }
.button.secondary:hover:not(:disabled) { background: #343d86; }
.button.danger { border-color: rgba(255, 112, 133, .42); background: rgba(137, 32, 59, .82); }
.button.danger:hover:not(:disabled) { background: #b02f50; }
.button.primary {
  min-width: 150px;
  padding: 12px 22px;
  background: linear-gradient(135deg, #765eff, #19bde4);
  box-shadow: 0 9px 28px rgba(78, 105, 255, .4);
  font-weight: 700;
}
.button.primary:hover { filter: brightness(1.12); transform: translateY(-1px); }
button:focus-visible, input:focus-visible, canvas:focus-visible { outline: 3px solid rgba(85, 217, 255, .7); outline-offset: 2px; }
button:disabled, input:disabled { opacity: .45; cursor: not-allowed; }

.play-area { position: relative; min-height: 420px; overflow: hidden; background: #080a1e; }
#game-canvas { display: block; width: 100%; height: 100%; min-height: 420px; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 4, 17, .73);
  backdrop-filter: blur(5px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s ease, visibility .18s ease;
}
.overlay.visible { opacity: 1; visibility: visible; }
.overlay-card { max-width: 520px; text-align: center; }
.eyebrow { margin: 0 0 8px; color: #7fe9ff; text-transform: uppercase; letter-spacing: .18em; font-size: 12px; }
.overlay h2 { margin: 0 0 12px; font-size: clamp(27px, 4.5vw, 48px); }
.overlay #overlay-message { margin: 0 auto 23px; color: #c2c8e7; line-height: 1.7; }
.shortcut { margin: 18px 0 0; color: #8e96be; font-size: 12px; }

.wrong-flash {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  padding: 8px 15px;
  border-radius: 9px;
  background: rgba(149, 20, 52, .82);
  color: #fff;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.9);
  pointer-events: none;
}
.wrong-flash.show { animation: wrong .38s ease; }
@keyframes wrong { 0% { opacity: 0; } 25% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; } }

.game-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 760px) {
  body { padding: 0; }
  .game-shell { min-height: 100vh; border: 0; border-radius: 0; grid-template-rows: auto auto minmax(400px, 1fr) auto; }
  .game-header { align-items: flex-start; padding: 14px; }
  .brand p { display: none; }
  .stats { gap: 5px; }
  .stat { min-width: 66px; padding: 7px; }
  .stat strong { font-size: 17px; }
  .settings { padding: 11px 14px; gap: 10px 14px; }
  .setting-actions { width: 100%; margin-left: 0; }
  .setting-actions .button { flex: 1; }
  .game-footer { padding: 9px 14px; }
  .game-footer span:last-child { display: none; }
}

@media (max-width: 520px) {
  .game-header { display: block; }
  .stats { margin-top: 12px; }
  .stat { flex: 1; }
  .settings .field { flex: 1 1 42%; }
  .stepper { width: 100%; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
