:root {
  color-scheme: light;
  --bg: #eef4ff;
  --bg-accent: #dbeafe;
  --card: rgba(255, 255, 255, 0.86);
  --card-strong: #ffffff;
  --text: #172033;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --success: #16a34a;
  --danger: #ef4444;
  --shadow: 0 24px 70px rgba(37, 99, 235, 0.16);
  --radius: 28px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 10% 10%, rgba(96, 165, 250, 0.34), transparent 30vw),
    radial-gradient(circle at 88% 0%, rgba(129, 140, 248, 0.25), transparent 28vw),
    linear-gradient(135deg, #f8fbff 0%, var(--bg) 52%, #e0ecff 100%);
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 22px;
  align-items: stretch;
  margin-bottom: 18px;
}

.hero > div,
.control-panel,
.game-shell {
  border: 1px solid rgba(148, 163, 184, 0.26);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero > div:first-child {
  min-height: 220px;
  padding: clamp(24px, 4vw, 46px);
  border-radius: var(--radius);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.6rem, 8vw, 5.4rem);
  line-height: 0.95;
  letter-spacing: -0.07em;
}

.intro {
  max-width: 620px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.3vw, 1.18rem);
  line-height: 1.75;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius);
}

.stat-card {
  display: grid;
  align-content: center;
  min-height: 96px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.72);
}

.stat-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.stat-card strong {
  margin-top: 8px;
  color: var(--text);
  font-size: clamp(1.55rem, 4vw, 2.2rem);
  line-height: 1;
}

.control-panel {
  display: flex;
  gap: 14px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding: 14px;
  border-radius: 24px;
}

.size-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.size-btn,
.primary-btn,
.danger-btn {
  min-height: 46px;
  border-radius: 999px;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.size-btn {
  padding: 0 18px;
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.size-btn.is-active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.28);
}

.primary-btn {
  padding: 0 22px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.3);
}

.danger-btn {
  padding: 0 18px;
  color: #b91c1c;
  background: #fee2e2;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.size-btn:active,
.primary-btn:active,
.danger-btn:active,
.cell:active {
  transform: scale(0.97);
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(300px, 680px) minmax(240px, 1fr);
  gap: clamp(18px, 3vw, 30px);
  align-items: start;
  padding: clamp(14px, 3vw, 28px);
  border-radius: var(--radius);
}

.grid {
  --size: 4;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  gap: clamp(8px, 1.8vw, 14px);
  width: min(100%, 78vh, 680px);
  margin: 0 auto;
  padding: clamp(8px, 1.8vw, 16px);
  border-radius: 24px;
  background: rgba(219, 234, 254, 0.68);
}

.cell {
  aspect-ratio: 1;
  border: 1px solid rgba(37, 99, 235, 0.12);
  border-radius: clamp(14px, 2.6vw, 24px);
  color: var(--text);
  background: var(--card-strong);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.08);
  font-size: clamp(1.45rem, 8vw / var(--size), 3.25rem);
  font-weight: 900;
  line-height: 1;
  transition: transform 140ms ease, background 180ms ease, opacity 180ms ease, color 180ms ease;
  touch-action: manipulation;
}

@media (hover: hover) {
  .cell:hover {
    transform: translateY(-2px);
  }
}

.cell.is-found {
  color: #fff;
  background: linear-gradient(135deg, var(--success), #22c55e);
  opacity: 0.48;
  pointer-events: none;
}

.cell.is-wrong {
  animation: shake 230ms ease;
  color: #fff;
  background: var(--danger);
}

.tip-card {
  padding: clamp(20px, 3vw, 30px);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
}

.tip-card h2 {
  margin: 0 0 14px;
  font-size: 1.18rem;
}

.tip-card ul {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 1.2em;
  color: var(--muted);
  line-height: 1.7;
}

.dialog {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.44);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.dialog.is-open {
  opacity: 1;
  pointer-events: auto;
}

.dialog-card {
  width: min(420px, 100%);
  padding: clamp(24px, 6vw, 38px);
  border-radius: 30px;
  background: #fff;
  box-shadow: 0 26px 80px rgba(15, 23, 42, 0.28);
  text-align: center;
}

.dialog-card h2 {
  margin: 0;
  font-size: 2rem;
}

.dialog-card p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.7;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (max-width: 820px) {
  body {
    padding-inline: 12px;
  }

  .hero,
  .game-shell {
    grid-template-columns: 1fr;
  }

  .hero > div:first-child {
    min-height: auto;
  }

  .control-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .size-picker {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .size-btn,
  .primary-btn,
  .danger-btn {
    width: 100%;
    padding-inline: 10px;
  }

  .action-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .grid {
    width: min(100%, 94vw);
    gap: clamp(6px, 2vw, 10px);
  }
}

@media (max-width: 520px) {
  .stats-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
  }

  .stat-card {
    min-height: 78px;
    padding: 14px;
    border-radius: 18px;
  }

  .game-shell {
    padding: 10px;
  }

  .grid {
    gap: 4px;
    padding: 6px;
  }

  .size-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cell {
    border-radius: clamp(10px, 4vw, 16px);
    font-size: clamp(1.05rem, 18vw / var(--size), 2.2rem);
  }
}

@media (max-width: 360px) {
  body {
    padding-inline: 6px;
  }

  .game-shell {
    padding: 6px;
  }

  .grid {
    gap: 3px;
    padding: 4px;
  }
}
