:root {
  --bg: #eef4ff;
  --card: rgba(255, 255, 255, 0.88);
  --line: rgba(148, 163, 184, 0.35);
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --danger: #ef4444;
  --success: #16a34a;
  --shadow: 0 18px 45px rgba(37, 99, 235, 0.15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: max(14px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 8%, rgba(96, 165, 250, 0.25), transparent 30vw),
    linear-gradient(135deg, #f8fbff 0%, var(--bg) 55%, #e3edff 100%);
}

.app {
  width: min(980px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.hero,
.panel,
.controls,
.board-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

.intro {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.back-link {
  text-decoration: none;
  color: var(--primary);
  font-weight: 700;
}

.panel {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  border-radius: 12px;
  background: white;
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  font-size: 20px;
}

.controls {
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

label { font-weight: 700; }

select,
button {
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: white;
  color: var(--text);
  padding: 0 12px;
  font: inherit;
}

button {
  cursor: pointer;
  background: var(--primary);
  color: white;
  border: 0;
  font-weight: 700;
}

button:active { transform: scale(.98); }

.message {
  width: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.message.is-danger { color: var(--danger); }
.message.is-success { color: var(--success); }

.board-wrap {
  padding: 10px;
}

.board {
  display: grid;
  gap: 8px;
}

.tile {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  background: white;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.13);
  font-size: clamp(18px, 4vw, 28px);
  display: grid;
  place-items: center;
  user-select: none;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.tile:hover { transform: translateY(-2px); }

.tile.is-selected {
  box-shadow: 0 0 0 2px #f59e0b inset, 0 8px 20px rgba(245, 158, 11, 0.3);
}

.tile.is-bad {
  box-shadow: 0 0 0 2px #ef4444 inset, 0 8px 20px rgba(239, 68, 68, 0.25);
}

.tile.is-hint {
  box-shadow: 0 0 0 2px #22c55e inset, 0 8px 20px rgba(34, 197, 94, 0.3);
}

.tile.is-cleared {
  opacity: 0;
  pointer-events: none;
  transform: scale(.8);
}

.dialog {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(15, 23, 42, 0.45);
  padding: 16px;
}

.dialog.is-open { display: grid; }

.dialog-card {
  width: min(360px, 100%);
  border-radius: 18px;
  background: white;
  padding: 20px;
  text-align: center;
}

.dialog-card h2 { margin: 0 0 8px; }
.dialog-card p { margin: 0 0 14px; color: var(--muted); }

@media (max-width: 768px) {
  .hero { flex-direction: column; }
  .panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .controls > * { flex: 1 1 auto; }
  .controls label { flex: 0 0 auto; }
  select { min-width: 130px; }
}
